diff --git a/docs/static/tutorials/turn-with-gyro.png b/docs/static/tutorials/turn-with-gyro.png new file mode 100644 index 00000000..e804ad0c Binary files /dev/null and b/docs/static/tutorials/turn-with-gyro.png differ diff --git a/docs/tutorials/city-shaper.md b/docs/tutorials/city-shaper.md index 84fd618e..b9c9c9e0 100644 --- a/docs/tutorials/city-shaper.md +++ b/docs/tutorials/city-shaper.md @@ -27,7 +27,7 @@ }, { "name": "Turn with Gyro", "description": "Use the gyro for precise turns.", - "youTubeId": "pTRAs1we51Y" + "youTubeId": "I7ncuXAfBwk" }, { "name": "Moving with Gyro", "description": "Use the gyro for correct the robot trajectory.", diff --git a/docs/tutorials/gyro.md b/docs/tutorials/gyro.md index 0b26e03c..c49a75f8 100644 --- a/docs/tutorials/gyro.md +++ b/docs/tutorials/gyro.md @@ -9,6 +9,12 @@ "cardType": "tutorial", "url":"/tutorials/calibrate-gyro", "imageUrl":"/static/tutorials/calibrate-gyro.png" +}, { + "name": "Turn", + "description": "Use the gyro to turn precisely", + "cardType": "tutorial", + "url":"/tutorials/turn-with-gyro", + "imageUrl":"/static/tutorials/turn-with-gyro.png" }, { "name": "Move Straight", "description": "Use the gyro to correct the trajectory of the robot", diff --git a/docs/tutorials/turn-with-gyro.md b/docs/tutorials/turn-with-gyro.md new file mode 100644 index 00000000..de57e4d4 --- /dev/null +++ b/docs/tutorials/turn-with-gyro.md @@ -0,0 +1,43 @@ +# Turn With Gyro + +## Introduction @fullscreen + +Use the gyro to measure how much the robot is turning, regardless if your wheels are slipping. + +## Step 1 Calibrate + +Add the ``||sensors:calibrate gyro||`` block to make sure your gyro is ready to use. + +```blocks +sensors.gyro2.calibrate() +``` + +## Step 2 Turn + +Use motor blocks to make the robot turn. Don't go too fast! + +```blocks +sensors.gyro2.calibrate() +motors.largeBC.steer(200, 20) +``` + +## Step 3 Pause for turn + +Use the ``||sensors:pause until rotated||`` block to wait until the desired amount of rotation has occured. + +```blocks +sensors.gyro2.calibrate() +motors.largeBC.steer(200, 20) +sensors.gyro2.pauseUntilRotated(90) +``` + +## Step 4 Stop + +Stop the motors! + +```blocks +sensors.gyro2.calibrate() +motors.largeBC.steer(200, 20) +sensors.gyro2.pauseUntilRotated(90) +motors.stopAll() +``` \ No newline at end of file diff --git a/libs/gyro-sensor/gyro.ts b/libs/gyro-sensor/gyro.ts index 008ad911..208a748f 100644 --- a/libs/gyro-sensor/gyro.ts +++ b/libs/gyro-sensor/gyro.ts @@ -229,14 +229,15 @@ namespace sensors { /** * Pauses the program until the gyro detected * that the angle changed by the desired amount of degrees. - * @param degrees the degrees to turn + * @param degrees the degrees to turn */ //% help=sensors/gyro/pause-until-rotated - //% block="pause **gyro** %this|until rotated %degrees|degrees" + //% block="pause until **gyro** %this|rotated %degrees=rotationPicker|degrees" //% blockId=gyroPauseUntilRotated //% parts="gyroscope" //% blockNamespace=sensors //% this.fieldEditor="ports" + //% degrees.defl=90 //% weight=63 //% group="Gyro Sensor" pauseUntilRotated(degrees: number, timeOut?: number): void { @@ -281,4 +282,17 @@ namespace sensors { //% fixedInstance whenUsed block="4" jres=icons.port4 export const gyro4: GyroSensor = new GyroSensor(4) + + /** + * Get the rotation angle field editor + * @param degrees angle in degrees, eg: 90 + */ + //% blockId=rotationPicker block="%degrees" + //% blockHidden=true shim=TD_ID + //% colorSecondary="#FFFFFF" + //% degrees.fieldEditor="numberdropdown" degrees.fieldOptions.decompileLiterals=true + //% degrees.fieldOptions.data='[["30", 30], ["45", 45], ["60", 60], ["90", 90], ["180", 180], ["-30", -30], ["-45", -45], ["-60", -60], ["-90", -90], ["-180", -180]]' + export function __rotationPicker(degrees: number): number { + return degrees; + } } diff --git a/targetconfig.json b/targetconfig.json index 15b5b064..07522040 100644 --- a/targetconfig.json +++ b/targetconfig.json @@ -18,7 +18,7 @@ "Touch Sensor Tutorials": "tutorials/touch-sensor", "Color Sensor Tutorials": "tutorials/color-sensor", "Ultrasonic Sensor Tutorials": "tutorials/ultrasonic-sensor", - "Gyro Sensor Tutorials": "tutorials/gyro", + "Gyro Tutorials": "tutorials/gyro", "Infrared Sensor Tutorials": "tutorials/infrared-sensor", "FLL / City Shaper": "tutorials/city-shaper", "Design Engineering": "design-engineering",