5 #include "../../include/commands/DriveRobotCommand.h" 11 this->duration_ms = duration_ms;
13 double leftMotorRPM = rotationRate * (radius + drivetrainDiameter/2) * 60.0 / (3.14159 * wheelDiameter);
14 double rightMotorRPM = rotationRate * (radius - drivetrainDiameter/2) * 60.0 / (3.14159 * wheelDiameter);
15 int leftMotorDirection = leftMotorRPM < 0 ? BACKWARD_DIRECTION : FORWARD_DIRECTION;
16 int rightMotorDirection = rightMotorRPM < 0 ? BACKWARD_DIRECTION : FORWARD_DIRECTION;
26 this->leftMotorCommand =
new DriveMotorRPM(comm, H_LEFT_MOTOR, leftEncoder, fabs(leftMotorRPM), leftMotorDirection);
27 this->rightMotorCommand =
new DriveMotorRPM(comm, H_RIGHT_MOTOR, rightEncoder, fabs(rightMotorRPM), rightMotorDirection);
30 DriveRobotCommand::~DriveRobotCommand() {
38 gettimeofday(&tp, NULL);
39 long long currentTime = (
long long) tp.tv_sec * 1000L + tp.tv_usec / 1000;
42 if(this->endTime == -1L) {
43 this->endTime = currentTime + this->duration_ms;
47 this->leftMotorCommand->
execute();
48 this->rightMotorCommand->
execute();
50 if(currentTime >= endTime) {
60 this->leftMotorCommand->
cancel();
61 this->rightMotorCommand->
cancel();
DriveRobotCommand(Communicator *comm, EncoderSensor *leftEncoder, EncoderSensor *rightEncoder, double radius, double rotationRate, int duration_ms, double wheelDiameter, double drivetrainDiameter)
bool cleanup(bool canceled) override