Yamei Liao: looking for Gigglebot code example
Click here to see all the updates
Here are some example code I found of how to make a gigglebot to move around. We may use it as reference to work around with our own gigglebot.
Code to make the bot driving around
- Driving
FORWARD OR BACKWARD FOR 2 SECONDS EACH
input.onButtonPressed(Button.A, () => {
gigglebot.driveMillisec(gigglebotWhichDriveDirection.Forward, 2000)
gigglebot.driveMillisec(gigglebotWhichDriveDirection.Backward, 2000)
})
- Turning
Turning happens around a wheel, we may can apply this code into our gigglebot let them to avoid each other.
Turning will have the GiggleBot make a sharp turn around on of its wheel.
E.G. TURN RIGHT FOR A SECOND
gigglebot.turnMillisec(gigglebotWhichTurnDirection.Right, 1000)
- spinning
when drawing because turns will be around the pen instead of around a wheel this spin block is useful
gigglebot.spinMillisec(gigglebotWhichTurnDirection.Left, 1000)
steering
we can also use the following code to steer the gigglebot
With steering you control how much turning each wheel can do.
E.G. THE ROBOT WILL TURN TOWARDS THE RIGHT, DOING A CURVE AROUND AN OBJECT. THE FIRST NUMBER IS PERCENT-BASED. WITH A VALUE OF 0, THE ROBOT WILL NOT TURN AT ALL. WITH A VALUE OF 100, YOU WILL GET THE SAME BEHAVIOR AS THE TURN BLOCK.
gigglebot.steerMillisec(20, gigglebotWhichTurnDirection.Right, 1000)
Code for moving without time constraint
You can have blocks to drive, turn, spin, and steer, which are not time limited. That way, you can decide when to interrupt the GiggleBot. Maybe it gets dark, or there’s an obstacle ahead.
- Drive #drivestraight
gigglebot.driveStraight(gigglebotWhichDriveDirection.Forward)
- Turn #turn
gigglebot.turn(gigglebotWhichTurnDirection.Right)
- Spin #gigglebotspin
gigglebot.gigglebotSpin(gigglebotWhichTurnDirection.Right)
- Steer #steer
gigglebot.steer(20, gigglebotWhichTurnDirection.Right)
- STOP #stop
When using blocks that do not have a time limit to them, you will need to stop the robot yourself.
gigglebot.stop()
- Setting the speed #setspeed
You can set the motors to five different speeds, from slowest to fastest. You can either set one motor, or both at the same time. Be careful, if you set the motors to different speeds, it will not drive straight.
gigglebot.setSpeed(gigglebotWhichMotor.Both, gigglebotWhichSpeed.Slowest)