Difference between revisions of "FTC Move a Distance 20230919"

From wikidb
Jump to: navigation, search
(Created page with "= Lab 2: Move a Distance = == 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...")
 
(References)
Line 68: Line 68:
 
*[https://ftc-tricks.com/dc-motors/ DC Motors]
 
*[https://ftc-tricks.com/dc-motors/ DC Motors]
 
*[https://stemrobotics.cs.pdx.edu/node/4746.html Using Encoders]
 
*[https://stemrobotics.cs.pdx.edu/node/4746.html Using Encoders]
 +
 +
== Enum Constant Detail ==
 +
 +
Enum Constant Detail
 +
 +
RUN_WITHOUT_ENCODER
 +
public static final DcMotor.RunMode RUN_WITHOUT_ENCODER
 +
The motor is simply to run at whatever velocity is achieved by apply a particular power level to the motor.
 +
RUN_USING_ENCODER
 +
public static final DcMotor.RunMode RUN_USING_ENCODER
 +
The motor is to do its best to run at targeted velocity. An encoder must be affixed to the motor in order to use this mode. This is a PID mode.
 +
RUN_TO_POSITION
 +
public static final DcMotor.RunMode RUN_TO_POSITION
 +
The motor is to attempt to rotate in whatever direction is necessary to cause the encoder reading to advance or retreat from its current setting to the setting which has been provided through the setTargetPosition() method. An encoder must be affixed to this motor in order to use this mode. This is a PID mode.
 +
STOP_AND_RESET_ENCODER
 +
public static final DcMotor.RunMode STOP_AND_RESET_ENCODER
 +
The motor is to set the current encoder position to zero. In contrast to RUN_TO_POSITION, the motor is not rotated in order to achieve this; rather, the current rotational position of the motor is simply reinterpreted as the new zero value. However, as a side effect of placing a motor in this mode, power is removed from the motor, causing it to stop, though it is unspecified whether the motor enters brake or float mode. Further, it should be noted that setting a motor toSTOP_AND_RESET_ENCODER may or may not be a transient state: motors connected to some motor controllers will remain in this mode until explicitly transitioned to a different one, while motors connected to other motor controllers will automatically transition to a different mode after the reset of the encoder is complete.
 +
RUN_WITHOUT_ENCODERS
 +
@Deprecated
 +
public static final DcMotor.RunMode RUN_WITHOUT_ENCODERS
 +
Deprecated. Use RUN_WITHOUT_ENCODER instead
 +
RUN_USING_ENCODERS
 +
@Deprecated
 +
public static final DcMotor.RunMode RUN_USING_ENCODERS
 +
Deprecated. Use RUN_USING_ENCODER instead
 +
RESET_ENCODERS
 +
@Deprecated
 +
public static final DcMotor.RunMode RESET_ENCODERS
 +
Deprecated. Use STOP_AND_RESET_ENCODER instead

Revision as of 08:53, 19 September 2023

Lab 2: Move a Distance

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.

Check Points

Start with the TestMotorEpp.java program and add the follow enhancements. The following program will show you where to make the changes for each check point.

  1. Add telemetry
    while (opModeIsActive() && myLeftMotor.isBusy())
    {
        telemetry.addData("position ", myLeftMotor.getCurrentPosition());
        telemetry.update();
    }
        

    Test and demonstrate to the instructor

  2. Reset the position counter
    myLeftMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
      

    Test and demonstrate to the instructor

  3. Turn the motor until the encoder reads the target position. Be sure to set the target position before you set run to position.
    myLeftMotor.setTargetPosition(1000);
      

    Test and demonstrate to the instructor

  4. Put the left motor in run to position mode.
    myLeftMotor.setMode(DcMotor.RunMode.RUN_TO_POSITION);
      

    Test and demonstrate to the instructor

  5. Set target to computed distance
    Demonstrate to the instructor that you can make the robot drive 24 inches.
  6. Update the comments
    Add your names as the programers who have enhanced this program. Describe what you did in a few words.

Incremental Development

We just demonstrated Incremental Development. We made a small change, built and tested our program to make sure it still worked. There are many ways of getting into trouble when writing a program. One is to start with a working program, make a lot of changes and end up with a non-working program with no idea what you did to break it. Incremental development help to keep us from getting into this trouble.

References

Enum Constant Detail

Enum Constant Detail

RUN_WITHOUT_ENCODER public static final DcMotor.RunMode RUN_WITHOUT_ENCODER The motor is simply to run at whatever velocity is achieved by apply a particular power level to the motor. RUN_USING_ENCODER public static final DcMotor.RunMode RUN_USING_ENCODER The motor is to do its best to run at targeted velocity. An encoder must be affixed to the motor in order to use this mode. This is a PID mode. RUN_TO_POSITION public static final DcMotor.RunMode RUN_TO_POSITION The motor is to attempt to rotate in whatever direction is necessary to cause the encoder reading to advance or retreat from its current setting to the setting which has been provided through the setTargetPosition() method. An encoder must be affixed to this motor in order to use this mode. This is a PID mode. STOP_AND_RESET_ENCODER public static final DcMotor.RunMode STOP_AND_RESET_ENCODER The motor is to set the current encoder position to zero. In contrast to RUN_TO_POSITION, the motor is not rotated in order to achieve this; rather, the current rotational position of the motor is simply reinterpreted as the new zero value. However, as a side effect of placing a motor in this mode, power is removed from the motor, causing it to stop, though it is unspecified whether the motor enters brake or float mode. Further, it should be noted that setting a motor toSTOP_AND_RESET_ENCODER may or may not be a transient state: motors connected to some motor controllers will remain in this mode until explicitly transitioned to a different one, while motors connected to other motor controllers will automatically transition to a different mode after the reset of the encoder is complete. RUN_WITHOUT_ENCODERS @Deprecated public static final DcMotor.RunMode RUN_WITHOUT_ENCODERS Deprecated. Use RUN_WITHOUT_ENCODER instead RUN_USING_ENCODERS @Deprecated public static final DcMotor.RunMode RUN_USING_ENCODERS Deprecated. Use RUN_USING_ENCODER instead RESET_ENCODERS @Deprecated public static final DcMotor.RunMode RESET_ENCODERS Deprecated. Use STOP_AND_RESET_ENCODER instead