Robotics and Mechatronics Systems Engineering - University of
Robotics and Mechatronics
-
Upload
vaughan-moody -
Category
Documents
-
view
42 -
download
1
description
Transcript of Robotics and Mechatronics
Robotics and Mechatronics
Motor Encoder Usage
nMotorEncoder
• What does nMotorEncoder do?• What are the steps to using nMotorEncoder?
Using nMotorEncoderTarget
4. Watch the motor run state.
3. Turn Motors on Forward
2. Specify Target
1. Reset Encoders
nMotorEncoder[motorB] = 0;
nMotorEncoderTarget[motorB] = 720;
motor[motorB] = 50;
while(nMotorRunState[motorB] != runStateIdle)
{
}
nMotorRunState
"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.
nMotorRunState – Watches the Motor’s “state” (is it on or off?)
nMotorRunState[motorD] = runStateRunning;
nMotorRunState[motorD] = runStateHoldPosition;
nMotorRunState[motorD] = runStateIdle;
while(nMotorRunState[motorB] != runStateIdle){}
Idle loopwhile(nMotorRunState[motorB] != runStateIdle){}
What is an idle loop?
nMotorTargetEncoder
Variables
Variables
Variables
Variable Types
Variable Names
Variable Rules
Variable Examples
Lets Use a Variable in a ProgramHow 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!