- Motor 1 (
ArmNeo1
): Left motor (Master) - Motor 2 (
ArmNeo2
): Right motor (Follower) - Motors are set to brake mode to avoid uncontrolled movements when the power is off.
Encoder Initialization
The DutyCycleEncoder
tracks the position of the arm:
The encoder is used to measure the arm’s position and is configured with an offset to correct for initial alignment issues.
Movement Control
Direct Motor Control
move(double percentSpeed)
: Directly sets motor speed.up(double percentSpeed)
: Moves the arm up if it hasn’t reached the upper limit.down(double percentSpeed)
: Moves the arm down if it hasn’t reached the lower limit.
Soft Limits
Soft limits prevent the arm from moving outside the desired range:
Position Control
PID Control
A PID controller is used to hold the arm at a specific position. The constants for the PID loop are initialized as follows:
Feedforward Control
The feedforward controller is responsible for ensuring smooth motion, compensating for gravity and inertia:
Key Methods
move(double percentSpeed)
Sets the motor speed directly, allowing for manual control of the arm’s motion.
up(double percentSpeed)
Moves the arm upward while checking for the soft upper limit.
down(double percentSpeed)
Moves the arm downward while checking for the soft lower limit.
hold()
Maintains the arm at its current position using the PID controller:
getArmPos()
Returns the current arm position from the encoder.
Telemetry
The subsystem uses the SmartDashboard
to display telemetry data:
- Arm Position:
SmartDashboard.putNumber("arm//ArmEncoder", position);
Constants
The constants for this subsystem are defined in ArmConstants
for easy modification:
Periodic Functions
periodic()
This method updates the arm’s position every scheduler run and displays the data on the SmartDashboard.
Future Enhancements
- Integrate more sophisticated motion planning (e.g., trajectory following).
- Tune the PID and Feedforward controllers for more precise arm control.
- Implement additional soft limit protections for motor safety.
This documentation is structured to give an overview of the arm subsystem, explain key components like motor control and feedback systems, and describe methods in detail.