Motor Movement Commands

1 minutes
Share the link to this page
Copied
  Completed
In this lesson, we'll look at the commands that make motors spin and stop. We'll set the brakeMode and spin up multiple motors and so on. //Motor Movements task main() { //Drive FWD and Reverse forward(2, rotations, 50); backward(2, rotations, 50); //Turn Left and Right turnLeft(1, rotations, 50); turnRight(1, rotations, 50); //Move Arm Up and Down moveMotor(armMotor, 1, rotations, 50); moveMotor(armMotor, 1, rotations, -50); //Open and Close the Claw moveMotor(clawMotor, 0.5, rotations, -50); moveMotor(clawMotor, 0.5, rotations, 50); }

Transcript

Now we get to the second set of commands, the motor commands are a bit more complicated. They allow us to specify which motor we want to spend, and to use sensor values to control the motors. The reset motor encoder command is used to reset the motor encoder to zero if you need to do that later in the program after the motor has moved. When measuring how far a robot has traveled, we usually check one of the motor encoders so choose either the left or the right drive motor. The set motor command allows us to choose a motor and set the speed for it to spin that. By making the speed setting negative we can spin it in the opposite direction.

The set multiple motors command allows us to control up to four motors, making them run in the same direction at the same speed. This command is little strange because for some reason the speed parameter is first and the other command speed is always the last parameter. All the stop motor commands allow you to choose a motor or motors to stop. Usually we'll use a white hand tool or other similar command that allows us to get a sensor reading before we stop the motors.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.