pxt-ev3/docs/tutorials/city-shaper/robot-2.md
Peli de Halleux 5314515619
Crane mission (#907)
* dummy page

* robot 1 lesson

* added lesson 2

* added mission 2

* added link
2019-09-06 16:10:33 -07:00

3.2 KiB

Robot 2 Lesson

Step 1 Build Your Driving Base Robot @unplugged

Build the robot driving base:

EV3 Driving Base

If clicking the above image doesn't open the instructions, right-click on the image and choose "Save link as..." to download the PDF.

Step 2 Show an image and move @fullscreen

Add the blocks to show an image and move the motors B+C for 1 rotation.

brick.showMood(moods.neutral)
motors.largeBC.steer(0, 50, 1, MoveUnit.Rotations)

Step 6 Brick button @fullscreen

Let's change the code so that your robot moves when the UP button is pressed. Add a ||brick:on button enter|| block and move the ||motors:steer motors|| under it. After downloading your code, press UP to move the robot.

brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
    motors.largeBC.steer(0, 50, 1, MoveUnit.Rotations)
})
brick.showMood(moods.neutral)

Step 6 Braking @fullscreen

When the motors are done turning, the robot keeps on moving for a short distance. Turn on the brakes, so that your robot stops immediately. Drag a ||motors:set brake|| block into the ||loops:on start|| and set it ON to the BC motors.

brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
    motors.largeBC.steer(0, 50, 1, MoveUnit.Rotations)
})
brick.showMood(moods.neutral)
motors.largeBC.setBrake(true)

Step 8 Left and Right turn @fullscreen

Let's make the robot turn to the left when the LEFT button is pressed on the brick (and same for the right button). Add a ||steer motors|| and change the turn ratio to go left.

brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
    motors.largeBC.steer(-50, 50, 1, MoveUnit.Rotations)
})
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
    motors.largeBC.steer(50, 50, 1, MoveUnit.Rotations)
})

Step 9 Backwards @fullscreen

Let's make the robot turn to the right when the RIGHT button is pressed on the brick. Add a ||steer motors|| and change the speed to be negative. This will make the motor go backwards.

brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
    motors.largeBC.steer(0, -50, 1, MoveUnit.Rotations)
})

Step 10 Add a Ultrasonic sensor @fullscreen

Add a Ultrasonic sensor to your driving base.

EV3 Driving Base with Ultrasonic Sensor

If clicking the above images don't open the instructions, right-click on the image and choose "Save link as..." to download the PDF.

Step 11 @fullscreen

Create a program that moves the Driving Base and makes it stop 6 cm from the Cuboid.

brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
    motors.largeBC.steer(0, 50)
    pauseUntil(() => sensors.ultrasonic4.distance() < 6)
    motors.largeBC.stop()
})

Try sending your robot towards a wall!