#include "frc/motorcontrol/Spark.h"
#include "Constants.h" // (If using)
// DriveConstants references a “Constants.h” file located in
// In this case, we reference LEFT_LEADER_ID or LEFT_FOLLOWER_ID to determine motor IDs
// While useful, this is not required, and these can be replaced by integer values
// For reference, here are the default values mentioned in this project:
// LEFT_LEADER_ID = 1
// LEFT_FOLLOWER_ID = 2
// RIGHT_LEADER_ID = 3
// RIGHT_FOLLOWER_ID = 4
// ASK A MENTOR/TEAM MEMBER WHAT THESE VALUES ARE, AS THEY MAY LIKELY BE DIFFERENT ON YOUR ROBOT
// Define the motor
frc::Spark leftLeader {DriveConstants::LEFT_LEADER_ID};
- Checkpoint 1
All of the motors on the drivetrain have been established according to existing ID, motor type, motor specifications, etc. (Reference other members/teams for this info!)
// DifferentialDrive is just tank/arcade drive made for you automatically!
frc::DifferentialDrive drive{
[&](double output) { leftLeader.Set(output); },
[&](double output) { rightLeader.Set(output); }
};
// Use driveArcade() or driveTank() to move. (Pick 1)
bool squareInputs = false; // Reduces the sensitivity of controls at low input values
// Tank Drive
double leftSpeed = 0;
double rightSpeed = 0;
drive.TankDrive(leftSpeed, rightSpeed, squareInputs);
// Arcade Drive
double driveSpeed = 0;
double turnSpeed = 0;
drive.ArcadeDrive(driveSpeed, turnSpeed, squareInputs);
// Note that there may be a few other drive styles, such as CurvatureDrive()
- Checkpoint 2
Have all motors moving upon request, making sure each ID is matched to the correct motor.
// DifferentialDrive is just tank/arcade drive made for you automatically!
drive = new DifferentialDrive(leftLeader, rightLeader);
// Use driveArcade() or driveTank() to move. (Pick 1)
boolean squareInputs = false; // Reduces the sensitivity of controls at low input values
// Tank Drive
double leftSpeed = 0;
double rightSpeed = 0;
drive.tankDrive(leftSpeed, rightSpeed, squareInputs);
// Arcade Drive
double driveSpeed = 0;
double turnSpeed = 0;
drive.arcadeDrive(driveSpeed, turnSpeed, squareInputs);
// Note that there may be a few other drive styles, such as curvatureDrive()
- Checkpoint 3
Have the drivetrain moving upon request in the correct directions, and get ready to replace some code in step 4!
/* Robot.cpp */
// A function called every 20 ms during Autonomous
void Robot::AutonomousPeriodic() {
// Run code that runs the motors
leftLeader.Set(0.5);
rightLeader.Set(0.5);
}
void Robot::TeleopInit() {
// Run code that stops the motors to prevent overlap
leftLeader.StopMotor();
rightLeader.StopMotor();
}
- Checkpoint 4
Test the auto, and be sure to test both alliance permutations. If we move in the right direction, success!