Skip to content

Instantly share code, notes, and snippets.

@daisycamber
Created October 1, 2020 18:19
Show Gist options
  • Save daisycamber/5b4881e801d1b71c20d78d05eeb62d2d to your computer and use it in GitHub Desktop.
Save daisycamber/5b4881e801d1b71c20d78d05eeb62d2d to your computer and use it in GitHub Desktop.
Sphero random movement with collision detection
async function onCollision() {
stopRoll();
setMainLed({ r: 255, g: 0, b: 0 });
await setHeading(getRandomInt(0,359));
await delay(0.5);
setMainLed({ r: 255, g: 22, b: 255 });
setSpeed(100);
}
registerEvent(EventType.onCollision, onCollision);
async function startProgram() {
setMainLed({
r: getRandomInt(0,255),
g: getRandomInt(0,255),
b: getRandomInt(0,255)
});
//setHeading(getRandomInt(0,359));
maxRoll = 20;
while(true){
setStabilization(true);
setSpeed(30);
await delay(3);
or = getOrientation();
while(or.pitch < maxRoll && or.yaw < maxRoll && or.roll < maxRoll ){
await delay(0.1);
or = getOrientation();
}
setSpeed(0);
setStabilization(true);
setHeading(getRandomInt(0,359));
await delay(1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment