diff --git a/README.md b/README.md index a6ef064..63888c9 100644 --- a/README.md +++ b/README.md @@ -4,55 +4,136 @@ For more information: https://www.gigglebot.io/pages/program-the-gigglebot-robot ## Example Usage -### Driving around +### Driving around #driveMillisec To drive forward and back for 2 seconds each: -![Makecode for forward and back](https://raw.githubusercontent.com/DexterInd/pxt-giggle/master/images/forward_backward_2sec.png) +``` +input.onButtonPressed(Button.A, () => { + gigglebot.driveMillisec(gigglebotWhichDriveDirection.Forward, 2000) + gigglebot.driveMillisec(gigglebotWhichDriveDirection.Backward, 2000) +}) +``` ### Turning, Spinning and Steering -Turning happens around a wheel, it's a nice way of going around an obstacle. -Spinning happens on the spot, useful when drawing -Steering is up to you, you can use it to orbit around a "sun" - -![Turning, Spinning and Steering](https://raw.githubusercontent.com/DexterInd/pxt-giggle/master/images/turning_spinning_steering.png) - -### Following a line -The GiggleBot comes with two line sensors that allows it to follow either a thin line or a thick line. The thin line is thin enough to fit between the two sensors, while the thick line is thick enough that both sensors will fit within the line. - -![Follow a thick line](https://raw.githubusercontent.com/DexterInd/pxt-gigglebot/master/images/follow_line.png) - -### Reading the line sensors +#### Turning happens around a wheel, it's a nice way of going around an obstacle. #turnMillisec +Turning will have the GiggleBot make a sharp turn around one of its wheel. +This block will get the GiggleBot to turn right for a full second. +``` +gigglebot.turnMillisec(gigglebotWhichTurnDirection.Right, 1000) +``` +#### Spinning happens on the spot, useful when drawing. #spinMillisec +Using the spin block is useful when drawing because the turns will be around the pen, instead of around a wheel. That way, you can get good corners when drawing. + +``` +gigglebot.SpinMillisec(gigglebotWhichTurnDirection.Left, 1000) +``` + +#### Steering is up to you, you can use it to orbit around a "sun". #steerMillisec +With steering you control how much turning each wheel can do. In this example, the robot will halfway to 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(50, gigglebotWhichTurnDirection.Right, 1000) +``` +### Moving without time constraint #drivestraight #turn #gigglebotspin #steer +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. + +``` +gigglebot.driveStraight(gigglebotWhichDriveDirection.Forward) +``` +``` +gigglebot.turn(gigglebotWhichTurnDirection.Right) +``` +``` +gigglebot.gigglebotSpin(gigglebotWhichTurnDirection.Right) +``` +``` +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) +``` + +### Following a line #linefollow +The GiggleBot comes with two line sensors that allows it to follow either a thick line or a thin line. The thick line is thick enough that both sensors will attempt to be over the line , while the thin line is thin enough to fit between the two sensors,and each sensor will attempt to avoid the line. + +``` +gigglebot.lineFollow(gigglebotLineType.Thick) +``` + +### Reading the line sensors #linereadsensor You can also access the line sensors values directly. This allows you to write a line follower logic that is tailored to your specific needs. -![Read Line Sensor Value](https://raw.githubusercontent.com/DexterInd/pxt-gigglebot/master/images/line_sensor_value.png) +``` +basic.showNumber(gigglebot.lineReadSensor(gigglebotWhichTurnDirection.Right)) +``` + +You can use the following code as the basis for your own line follower. First, detect what are good values for detecting your line, then code the appropriate movements. +``` +basic.forever(() => { + if (gigglebot.lineReadSensor(gigglebotWhichTurnDirection.Right) < 200) { + basic.showIcon(IconNames.Yes) + } else { + basic.showIcon(IconNames.Asleep) + } +}) +``` ### Following a light -The GiggleBot comes with two light sensors that allows it to follow a light, a little bit like a cat would. Shine a flashlight onto one eye will get the GiggleBot to turn in that direction. - -![Follow Light](https://raw.githubusercontent.com/DexterInd/pxt-gigglebot/master/images/follow_light.png) +The GiggleBot comes with two light sensors that allows it to follow a spotlight, a little bit like a cat would. Shining a flashlight onto one eye will get the GiggleBot to turn in that direction. +``` +input.onButtonPressed(Button.A, () => { + gigglebot.lightFollow() +}) +``` ### Reading the light sensor values You can also read the light sensors values directly in order to implement a different behaviour, like having the GiggleBot fall asleep when it gets dark, and wake up when there's light. -![Falls Asleep when dark](https://raw.githubusercontent.com/DexterInd/pxt-gigglebot/master/images/light_sensor_falls_asleep.png) - - -### Using the distance sensor -This piece of code will start the Gigglebot forward when button A is pressed. At all times, the distance sensor displays the distance to an obstacle onto the smile and will stop the Gigglebot if the obstacle is closer than 10 cm. - -![Distance sensor](https://raw.githubusercontent.com/DexterInd/pxt-giggle/master/images/distance_sensor.png) - -### To use a second micro:bit as a remote control - -Use a second micro:bit as a remote control for your Gigglebot. On this micro:bit, put the following code: -![Remote Control](https://raw.githubusercontent.com/DexterInd/pxt-giggle/master/images/microbit_controller.png) - -On your gigglebot, put this code: - -![Remote Controlled Gigglebot](https://raw.githubusercontent.com/DexterInd/pxt-giggle/master/images/gigglebot_controlled.png) +``` +basic.forever(() => { + if (gigglebot.lightReadSensor(gigglebotWhichTurnDirection.Right) < 200) { + basic.showIcon(IconNames.Asleep) + } else { + basic.showIcon(IconNames.Happy) + } +}) +``` + + +## SERVO MOTORS #servomove +The GiggleBot comes with two servo connectors. What will you do with them? You can control them one by one, both together (in synchro), or both mirrored, depending on how they are positioned on the robot. +``` +gigglebot.servoMove(gigglebotServoAction.Right, 90) +``` + +### Using the distance sensor #distancesensortestforobstacle #distancesensorreadrangecontinuous + +You can add a distance sensor to the robot. This distance sensor is not ultrasonic, but laser-based. + +The following code will start the Gigglebot forward when button A is pressed. At all times, the distance sensor displays the distance to an obstacle onto the smile and will stop the Gigglebot if the obstacle is closer than 10 cm. +''' +input.onButtonPressed(Button.A, function () { + gigglebot.driveStraight(gigglebotWhichDriveDirection.Forward) +}) +basic.forever(function () { + lights.smileShowGraph(gigglebot.distanceSensorReadRangeContinuous(), 300) + if (gigglebot.distanceSensorTestForObstacle(gigglebotInequality.Closer, 100)) { + gigglebot.stop() + } +}) +''' ## Supported targets diff --git a/gigglebot.ts b/gigglebot.ts index 569832c..8a3603b 100644 --- a/gigglebot.ts +++ b/gigglebot.ts @@ -107,7 +107,7 @@ enum gigglebotInequality { //% weight=99 color=#46BFB1 icon="\uf0d1" -//% groups='["other", "Servo", "LineFollower", "LightSensors", "DistanceSensor","OnBoardSensors", "Voltage", "Firmware"]' +//% groups='["other", "LineFollower", "LightSensors", "Servo", "DistanceSensor","OnBoardSensors", "Voltage", "Firmware"]' namespace gigglebot { /** * Basic drive and sensor functionalities for GiggleBot @@ -279,7 +279,7 @@ namespace gigglebot { //% blockId="gigglebotSpinMillisec" block="spin %turn_dir|for %delay|ms" //% weight=98 //% delay.min=0 - export function SpinMillisec(turn_dir: gigglebotWhichTurnDirection, delay: number) { + export function spinMillisec(turn_dir: gigglebotWhichTurnDirection, delay: number) { if (delay < 0) delay = 0 gigglebotSpin(turn_dir) basic.pause(delay) diff --git a/icon.png b/icon.png index 975efce..f067c36 100644 Binary files a/icon.png and b/icon.png differ diff --git a/pxt.json b/pxt.json index d3af88e..d78e6d0 100644 --- a/pxt.json +++ b/pxt.json @@ -1,6 +1,6 @@ { "name": "gigglebot", - "version": "v1.0.0", + "version": "v1.0.1", "dependencies": { "core": "*", "distanceSensor": "github:dexterind/pxt-distancesensor#v0.0.1"