Skip to content

Commit

Permalink
Merge pull request #17 from CleoQc/master
Browse files Browse the repository at this point in the history
Some help files changes
  • Loading branch information
CleoQc authored Sep 4, 2018
2 parents 02e17d9 + 53dc55d commit 40162d9
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 37 deletions.
149 changes: 115 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions gigglebot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Binary file modified icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pxt.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gigglebot",
"version": "v1.0.0",
"version": "v1.0.1",
"dependencies": {
"core": "*",
"distanceSensor": "github:dexterind/pxt-distancesensor#v0.0.1"
Expand Down

0 comments on commit 40162d9

Please sign in to comment.