My team is trying to make a Velocity-controlled Drive Train using PID systems; what we’ve done is created two separate PID subsystems and controllers, one for the Left Motor/Encoder and one for the Right Motor/Encoder. We then created two PID-Commands, one for the Left Side and one for the Right Side. These commands are called from a Command Group called TankDrive; the purpose is to call our Xbox axis values from the Command Group and pass them to the commands, so we can easily use the Group on non-test robots.
We plan to extend this to Arcade Drive, which is why we chose this structure; it minimizes the number of Commands we have to create, and is more easily ported to other bots.
The code for the Group looks something like this:
#include “TankDrive.h”
#include “…/Robot.h”
#include “LeftMotor.h”
#include “RightMotor.h”
TankDrive::TankDrive() {
double left = Robot:: oi->getXbox->getRawAxis(1); //Getting left axis’ Y
double right = Robot:: oi->getXbox->getRawAxis(3); //Getting right axis’ Y
AddParallel(new LeftMotor(left));
AddParallel(new RightMotor(right));
}
While the code for the Commands both look something like this:
#include “LeftMotor.h”
#include “…/Robot.h”
LeftMotor::LeftMotor(double point) {
Requires(Robot::leftPID);
setpoint = point; //setpoint defined in header
}
…
LeftMotor::Execute() {
Robot::leftPID->SetSetpoint(setpoint);
}
LeftMotor::IsFinished() {
return fabs(Robot::leftPID->getSetpoint() - Robot::leftPID->getPosition()) < 0.1;
}
The Command Group thus gets the value of the Xbox axes, sends them to the commands, and the command keeps resetting the setpoint so the velocity is controlled. However, when we upload this to the CRIO we get a fatal error, and we’ve narrowed it down to the actual calling of the Xbox axis in TankDrive::TankDrive()… when we call it in LeftMotor::Execute(), everything works fine.
My question is if there is anything we can do to make it work in the Command Group, or if we are going to have to call the Xbox in the commands themselves?