Hi ,
Here's some updates and news from FIRST® Tech Challenge.
In this week's blast:
💻 Tech Tip of the Week
Tech Tip of the Week
This week’s Tip of the Week is the first in a series for all you who love diving deep into the FIRST Tech Challenge SDK and exploring interesting lesser-known behaviors of well-known interfaces. Today we’re talking about motor modes. The REV Robotics documentation for encoder feedback has a really good description of the four primary run modes, namely:
- DcMotor.RunMode.STOP_AND_RESET_ENCODER mode
- DcMotor.RunMode.RUN_WITHOUT_ENCODER mode
- DcMotor.RunMode.RUN_USING_ENCODER mode
- DcMotor.RunMode.RUN_TO_POSITION mode
The first two modes do exactly as their names suggest.
STOP_AND_RESET_ENCODER stops the motors and resets the running encoder count to zero.
RUN_WITHOUT_ENCODER more or less blindly controls the motor power using a calculated percentage of the available battery power through the motor’s .setPower() method.
The last two modes are a bit more interesting. These two modes use a feature of the Control/Expansion hub firmware to externally (from robot code) control the motors. Using this feature you can do a lot more with the motors such as set the maximum velocity of the motor (nominally in encoder-ticks-per-second) using the .setVelocity() method, and change the actual PIDF algorithm being used by the motor mode (using the .setPIDFCoefficients() methods). Because these two motor modes rely on knowing specific motor characteristics, it’s VERY important to set the correct motor type for the motor in the Robot Configuration!
Finally, one final note about RUN_TO_POSITION. When setting a Power or a Velocity for the motor in RUN_TO_POSITION mode, the value is intended to be unsigned. When using RUN_WITHOUT_ENCODER and RUN_USING_ENCODER the sign of the value of the Power or Velocity denotes direction; positive values mean run the motor “forwards” and negative values mean run the motor “backwards.” However, with RUN_TO_POSITION, the current encoder value and target encoder position are already known by the time you're setting the Power or Velocity - and thanks to the motor setting in the Robot Configuration it knows everything about the motor - therefore the controller already knows which direction to run the motor and does not need a signed value indicating direction.