I am using command based for the first time and having trouble know where to place certain code. I keep getting errors that I cannot resolve.
Here is the code that I am trying to place in the Command Base structure. Can someone help as to where it should go? And if there is additional steps with it?
//drive train in motor init
m_leftMainMotor = new CANSparkMax(leftMainID, MotorType.kBrushless);
m_leftFollowMotor1 = new CANSparkMax(leftFollow1ID, MotorType.kBrushless);
m_leftFollowMotor2 = new CANSparkMax(leftFollow2ID, MotorType.kBrushless);
m_rightMainMotor = new CANSparkMax(rightMainID, MotorType.kBrushless);
m_rightFollowMotor1 = new CANSparkMax(rightFollow1ID, MotorType.kBrushless);
m_rightFollowMotor2 = new CANSparkMax(rightFollow2ID, MotorType.kBrushless);
//factory default
m_leftMainMotor.restoreFactoryDefaults();
m_leftFollowMotor1.restoreFactoryDefaults();
m_leftFollowMotor2.restoreFactoryDefaults();
m_rightMainMotor.restoreFactoryDefaults();
m_rightFollowMotor1.restoreFactoryDefaults();
m_rightFollowMotor2.restoreFactoryDefaults();
//current limit
m_leftMainMotor.setSmartCurrentLimit(40);
m_leftFollowMotor1.setSmartCurrentLimit(40);
m_leftFollowMotor2.setSmartCurrentLimit(40);
m_rightMainMotor.setSmartCurrentLimit(40);
m_rightFollowMotor1.setSmartCurrentLimit(40);
m_rightFollowMotor2.setSmartCurrentLimit(40);
//follow method & drive
m_leftFollowMotor1.follow(m_leftMainMotor);
m_leftFollowMotor2.follow(m_leftMainMotor);
m_rightFollowMotor1.follow(m_rightMainMotor);
m_rightFollowMotor2.follow(m_rightMainMotor);
//differential drive
m_myRobot = new DifferentialDrive(m_rightMainMotor, m_leftMainMotor);
As for your specific question, Command Based is split up into 4 main pieces. With two being explicit classes in your code, and two being concepts. One of these concepts is the Subsystem, which defines the interface to your physical robot hardware. So anything relating to the motors, relays, pneumatics, sensors, ect. directly should go in a subsystem, in this case a Drivetrain subsystem or similarly named.
The other concept is Commands, which is where you tell your subsystems to actually DO things. The two “explicit” ones are the Constants and the RobotContainer. Constants is where you put your “hard” numbers, like port numbers, can IDs, setpoints, ect. It can be very beneficial to have all of these in one place and named so that looking at code later, your numbers all have names instead of wondering what the random 137.2 means in your PID output adjustment code or something. The RobotContainer on the other hand is where everything comes together. Its where you instantiate your subsystems, controllers, and buttons/triggers on those controllers. Then you assign those buttons to commands, which in turn manipulate subsystems.