robotics and mechatronics

15
Robotics and Mechatronics Motor Encoder Usage

Upload: vaughan-moody

Post on 03-Jan-2016

42 views

Category:

Documents


1 download

DESCRIPTION

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;. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Robotics and Mechatronics

Robotics and Mechatronics

Motor Encoder Usage

Page 2: Robotics and Mechatronics

nMotorEncoder

• What does nMotorEncoder do?• What are the steps to using nMotorEncoder?

Page 3: Robotics and Mechatronics

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)

{

}

Page 4: Robotics and Mechatronics

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){}

Page 5: Robotics and Mechatronics

Idle loopwhile(nMotorRunState[motorB] != runStateIdle){}

What is an idle loop?

Page 6: Robotics and Mechatronics

nMotorTargetEncoder

Page 7: Robotics and Mechatronics

Variables

Page 8: Robotics and Mechatronics

Variables

Page 9: Robotics and Mechatronics

Variables

Page 10: Robotics and Mechatronics

Variable Types

Page 11: Robotics and Mechatronics

Variable Names

Page 12: Robotics and Mechatronics

Variable Rules

Page 13: Robotics and Mechatronics

Variable Examples

Page 14: Robotics and Mechatronics

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)

Page 15: Robotics and Mechatronics

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!