Two large motors’ movements are coordinated to drive a robot by using the Move Steering and Move Tank blocks. These blocks can be configured to make a robot drive in any direction or spin on the spot. Move Steering controls the robot based on a steering direction and Move Tanks uses the motors’ power level.
- [Voiceover] With one motor moving my robot turns around in circles. I could put down another large motor block to move the other motor. I run this, but my robot is now doing an awkward waddle. Why is that? Dataflow Execution will only move one motor at a time. Since I have to wait for the previous block to finish before running the next one. I need to wait to move both motors at the same time to make my robot move forward.
Move Steering and Move Tank are blocks designed to do exactly that. I'll replace the two large motor blocks with the Move Steering block. This block has the exact same modes as the single large motor block and the same inputs but with an added steering input which indicates the steering direction. This is the direction the robot will move as a whole if the motors are placed one on either side of the brick as with the tracker robot shown here. The Move Steering block will operate the same way as turning the steering wheel in a car.
By default, it is set to drive the robot straight forward. But, by using the slider, I can specify any sort of arc or turn I would want the robot to do. A positive number indicates a right turn and a negative number is a left turn. I'll set this back to straight. Since I am controlling two motors, I need to specify the motors are connected to ports B and C. When my robot is facing forward, the motor on the left should come first in the selector.
In this picture, with the motors positioned in this way, relative to one another, the forward direction is in the direction of the arrow. Therefore, the motor on the left is connected to port B. I run the program and now my robot moves forward in a straight line. To move directly backwards, I change the power level to a negative value and run the program again.
Similar to driving a car, when a robot turns, even slightly, one motor will turn more than the other. So, when I specify the robot to move in an arc, and for 180 degrees, the motor that's moving faster will be used to measure the number of degrees. Before I run, I'll reset my port view. I run this code, and in the port view, I look at the value of the two motors in degrees. I see one has moved more than the other. If the turn was very sharp, one of the motors will actually be reversed to achieve the action.
The Move Tank block is also used to move two motors at the same time. But, I don't specify a steering direction. Instead, I control the power levels for each motor directly. Again, the ports are determined the same way as with the Move Steering block, with the left motor first which is port B in my setup. The first power level belongs to the motor on the left, and the second power level is for the right motor. To go straight, I set the power levels for both motors to be the same as seen here.
To make an arced turn, set the power level for the motor that's going to be on the outside of the turn higher. So, turning right needs the left motor to have a higher power level. I'll set the left motor power level to 100, and the right power level to 25. The number of rotations is set to one, and this block will end when the faster motor has moved exactly one rotation which in this case is the left motor.
I run the code, and my motor makes a smooth curved turn. For turning on the spot, I want the power levels for both motors to be equal but opposite. So, I'll set my left motors power level to negative 75, and the right motors power level to 75. I run my program again and I see my robot spinning in place. Move Tank gives me much more accurate turns which is good in tight spots, but it also takes more time to determine the correct power levels to achieve the turn.
Coordinating two motors to get the movement you want from your robot can be tricky but the Move Steering and the Move Tank make this quick and easy.
Learn how to unpack the hardware, connect to the programming interface, run prebuilt programs, and control the motors and sensors. Chapter 6, "Adding Flow to a Program," covers advanced programming topics such as transferring data between blocks, using variables to store temporary data, programming conditional logic, and looping actions to run again and again. By the end of the course, you'll have the skills to bring your own robotic creations to life.
- Installing the LEGO Mindstorms software
- Exploring the programming interface
- Connecting to the EV3 brick
- Downloading and running prebuilt programs
- Coordinating motor movement
- Calibrating the sensors
- Transferring data with data wires
- Adding logic with switch blocks
- Looping actions
- Troubleshooting problems with LEGO Mindstorms
- Broadcasting sounds and displaying images
- Updating LEGO Mindstorms