FTC Motor Encoders 20200304
From wikidb
Motor Encoder Demo
Why
- Where am I? is a key question a robot must know to get some things done.
- Odometry is the use of sensor data to estimate a robot's position: Odometry from Wikipedia.
- An encoder is an example sensor that can be used to answer that question: Encoder from Wikipedia.
- Dead reckoning is figuring out where you are based on where you were and your estimate on how far you moved in some direction: Dead Reckoning from Wiipedia.
Demo Code
Exercise
- Exercise 1: Load the DriverForwardWithEncoderEpp Op Mode into Android Studio and execute it..
Motor Encoders
REV Motor Drive Characteristics
- MiniBot Hardware Kit REV-45-1171
- Core Hex Motor REV-41-1300
- Free Speed 125 RPM
- Gear Ratio: 72:1
- Encoder Counts per Revolution at the motor: 4 counts/revolution REV-41-1336]
- Encoder Counts per Revolution at the output (wheels): _________
- Gears - not relevant
- 72 Tooth Plastic Gear REV-41-1336
- 90 Tooth Plastic Gear REV-41-1337
- Encoder Counts per Revolution at the wheels: _________
- Wheels
- 90mm Traction Wheel REV-41-1354
- Counts per mm: _________
Exercise
- Exercise 2: Verify the Counts per mm above with a physical test.
Encoder Diagram
FTC Motor Object Structure
References
Motor Class Specs
- DcMotorSimple extends HardwareDevice
- getPower -- 64 bit double
- setPower -- 64 bit double
- ...
DcMotor extends DcMotorSimple
- getMode
- getPowerFloat -- 32 bit float
- getTargetPosiition -- encoder value
- isBusy
- setMode
- setPowerFloat -- 32 bit float
- setTargetPosition -- encoder value
- ...
- DcMotorEx extends DcMotor
- getCurrent
- getPIDCoefficients
- getTargetPositionTolerance
- getVelocity -- ticks per second and angle unitis
- isOverCurrent
- setPIDCoefficients
- setVelocity -- ticks per second and angle units
- ...
Exercise
- Exercise 3: Change the DriveForwardWithEncoder to use Velocity control for both wheels instead of Power control. How does the robots move characteristics change? eg
- Did the robot drive in a straighter line using the setVelocity than the setPower example?
- Did the robot start out moving straight at the very beginning?
- Did the robot stop gradually or abruptly when its target distance was reached?
- How would you improve the robot's performance?
Spoiler Alert
- DriveForwardWithEncoderEppGio.java - The team's colaborative solution
- Key changes
- import DcMotorEx
- leftMotor and rightMotor change to type DcMotorEx
- type cast for the hardwareMap.dcMotor.get
- change setPower to setVelocity
- remove setting rightMotor to RUN_WITHOUT_ENCODER run mode
- Key changes
- DriveForwardWithEncoderSpeed.java - Ed's solution
- Key changes - same as above pluss
- Use this hardwareMap statement
- Key changes - same as above pluss
rightMotor = hardwareMap.get(DcMotorEx.class,"myRightMotor");
DcMotor and DcMotorEx differences
- DcMotor is designed for Modern Robotics / HiTechnic motor controllers
- DcMotor is designed for the Control Hub and Expansion Hub
- Reference: DcMotor vs. DcMotorEx
References
- REV Encoders
- REV Using Encoders - Motor Modes
- [https://docs.revrobotics.com/rev-control-system/programming/hello-robot-autonomous-robot/robot-nav-onbot-java/autonomous-navigation-onbot Encoder Navigation - OnBot
- For Java code see: "Setting Velocity" subsection in the program "HelloWorld_EncoderAuton".
- In is also described in a subsection "Turning the Divetrain Using RUN_TO_POSITION"
- There is also an earlier sections called "Moving to a Target Distance."
Robot HW Architecture
- Proportional Integral Derivative from Wikipedia If you don't want to dig into the mathematics, look at the PID methods in the DcMotorEx class (getPIDCoefficients and setPIDCoefficients).