340 likes | 1.15k Views
Robotics and Mechatronics. Motor Encoder Usage. nMotorEncoder. What does nMotorEncoder do? What are the steps to using nMotorEncoder?. Using nMotorEncoderTarget. 1. Reset Encoders. nMotorEncoder [motorB] = 0;. 2. Specify Target. nMotorEncoderTarget [motorB] = 720;.
E N D
Robotics and Mechatronics Motor Encoder Usage
nMotorEncoder • What does nMotorEncoder do? • What are the steps to using nMotorEncoder?
Using nMotorEncoderTarget 1. Reset Encoders nMotorEncoder[motorB]= 0; 2. Specify Target nMotorEncoderTarget[motorB] = 720; 3. Turn Motors on Forward motor[motorB] = 50; 4. Watch the motor run state. while(nMotorRunState[motorB] != runStateIdle) { }
nMotorRunState nMotorRunState – Watches the Motor’s “state” (is it on or off?) nMotorRunState[motorD] = runStateRunning; nMotorRunState[motorD] = runStateHoldPosition; nMotorRunState[motorD] = runStateIdle; "nMotorRunState“ is a special function that allows us to watch the state of the motor so that we know when it is running, when it is slowing down and when it is stopped. while(nMotorRunState[motorB] != runStateIdle){}
Idle loop while(nMotorRunState[motorB] != runStateIdle){} What is an idle loop?
Lets Use a Variable in a Program How many encoder counts does a motor moving at • Quarter power in two seconds count? • Half power in two seconds count? • Three quarter power in two seconds count? • Full power in two seconds count? • Is there a proportional relationship? • Declare the following variables: • encodercount; • motorpower = 50; • motortime = 2000; Hints: In order to continually increment encodercount you will need to place it in a loop. You will need to use a timer. While Make sure that your debugger is set to continuous. You will need to add time at the end of the program to be able to see the value of encodercount… So what will that mean to your motors. (next slide)
Pseudocode for variable problem • Declare variables • Assign value to variables • Zero out the encoders • Reset the timer • Place condition in a loop • While timer < motortime • Don’t forget to increment encodercount inside the loop!