Skip to content

Commit

Permalink
Merge pull request #25 from CleoQc/master
Browse files Browse the repository at this point in the history
swap icon names. Use Math.idiv
  • Loading branch information
CleoQc authored Oct 9, 2018
2 parents 73c7447 + d089f20 commit bc3a17a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 28 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ 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 turn 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.
With steering you control how much turning each wheel can do.
In this example, 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.
```blocks
gigglebot.steerMillisec(50, gigglebotWhichTurnDirection.Right, 1000)
gigglebot.steerMillisec(20, gigglebotWhichTurnDirection.Right, 1000)
```
### 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.
Expand Down
37 changes: 12 additions & 25 deletions gigglebot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,11 @@ namespace gigglebot {
let correctedMotorPowerLeft = motorPowerLeft
let correctedMotorPowerRight = motorPowerRight
if (dir == gigglebotWhichTurnDirection.Left) {
correctedMotorPowerLeft = motorPowerLeft - (motorPowerLeft * percent) / 100
correctedMotorPowerRight = motorPowerRight + (motorPowerRight * percent) / 100
correctedMotorPowerLeft = motorPowerLeft - Math.idiv(motorPowerLeft * percent, 100)
correctedMotorPowerRight = motorPowerRight + Math.idiv(motorPowerRight * percent, 100)
} else {
correctedMotorPowerLeft = motorPowerLeft + (motorPowerLeft * percent) / 100
correctedMotorPowerRight = motorPowerRight - (motorPowerRight * percent) / 100
correctedMotorPowerLeft = motorPowerLeft + Math.idiv(motorPowerLeft * percent, 100)
correctedMotorPowerRight = motorPowerRight - Math.idiv(motorPowerRight * percent, 100)
}
motorPowerAssignBoth(correctedMotorPowerLeft, correctedMotorPowerRight)
}
Expand Down Expand Up @@ -406,16 +406,16 @@ namespace gigglebot {
// apply trim
if (trimRight != 0 && motor != gigglebotWhichMotor.Left) {
if (speed > 0) {
motorPowerRight = currentMotorPower - (trimRight * currentMotorPower / 100);
motorPowerRight = currentMotorPower - Math.idiv(trimRight * currentMotorPower, 100);
} else {
motorPowerRight = currentMotorPower + (trimRight * currentMotorPower / 100);
motorPowerRight = currentMotorPower + Math.idiv(trimRight * currentMotorPower, 100);
}
}
if (trimLeft != 0 && motor != gigglebotWhichMotor.Right) {
if (speed > 0) {
motorPowerLeft = currentMotorPower - (trimLeft * currentMotorPower / 100);
motorPowerLeft = currentMotorPower - Math.idiv(trimLeft * currentMotorPower, 100);
} else {
motorPowerLeft = currentMotorPower + (trimLeft * currentMotorPower / 100);
motorPowerLeft = currentMotorPower + Math.idiv(trimLeft * currentMotorPower, 100);
}
}
}
Expand Down Expand Up @@ -495,28 +495,15 @@ namespace gigglebot {
export function lightFollow() {
let diff = 20
let current_lights = gigglebot.lightSensorsRaw()
// serial.writeNumbers(current_lights)
if (current_lights[0] < 10 && current_lights[1] < 10) {
}
else if (current_lights[0] > current_lights[1] + diff) {
// it's brighter to the right
// lights.smileShow(NeoPixelColors.Black)
// lights.whichEye(gigglebotWhichEye.Right).setPixelColor(0, neopixel.colors(NeoPixelColors.Yellow))
// lights.whichEye(gigglebotWhichEye.Left).setPixelColor(0, neopixel.colors(NeoPixelColors.Black))
// lights.whichEye(gigglebotWhichEye.Both).show()
gigglebot.turn(gigglebotWhichTurnDirection.Right)
} else if (current_lights[1] > current_lights[0] + diff) {
// it's brighter to the left
// lights.smileShow(NeoPixelColors.Black)
// lights.whichEye(gigglebotWhichEye.Left).setPixelColor(0, neopixel.colors(NeoPixelColors.Yellow))
// lights.whichEye(gigglebotWhichEye.Right).setPixelColor(0, neopixel.colors(NeoPixelColors.Black))
// lights.whichEye(gigglebotWhichEye.Both).show()
gigglebot.turn(gigglebotWhichTurnDirection.Left)
} else {
// lights.whichEye(gigglebotWhichEye.Left).setPixelColor(0, neopixel.colors(NeoPixelColors.Violet))
// lights.whichEye(gigglebotWhichEye.Right).setPixelColor(0, neopixel.colors(NeoPixelColors.Violet))
// lights.whichEye(gigglebotWhichEye.Both).show()
// lights.smileRainbow()
gigglebot.driveStraight(gigglebotWhichDriveDirection.Forward)
}
basic.pause(100)
Expand Down Expand Up @@ -647,14 +634,14 @@ namespace gigglebot {
trimLeft = 0
}
if (motorPowerLeft > 0){
motorPowerLeft = currentMotorPower - (trimLeft * currentMotorPower / 100)
motorPowerLeft = currentMotorPower - Math.idiv(trimLeft * currentMotorPower, 100)
} else {
motorPowerLeft = currentMotorPower + (trimLeft * currentMotorPower / 100)
motorPowerLeft = currentMotorPower + Math.idiv(trimLeft * currentMotorPower, 100)
}
if (motorPowerRight > 0) {
motorPowerRight = currentMotorPower - (trimRight * currentMotorPower / 100)
motorPowerRight = currentMotorPower - Math.idiv(trimRight * currentMotorPower, 100)
} else {
motorPowerRight = currentMotorPower + (trimRight * currentMotorPower / 100)
motorPowerRight = currentMotorPower + Math.idiv(trimRight * currentMotorPower, 100)
}
}

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.
Binary file renamed icon2.png → icon_old.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": "1.0.5",
"version": "1.0.6",
"dependencies": {
"core": "*",
"distanceSensor": "github:dexterind/pxt-distancesensor#v0.0.1"
Expand Down

0 comments on commit bc3a17a

Please sign in to comment.