I'm just modifying the code I wrote for a practice bot. I want to replace the joystick x&y variables with the x&y variables being sent from processing. I understand the the workstation, I just don't know how to setup up the connection between the cRIO and
PROCESSING , and how to separate a comma-delimited string and make those values.
This is my original code that i'm modifying:
Code:
#include "WPILib.h"
class Stan : public IterativeRobot {
Jaguar *leftFront;
Jaguar *leftRear;
Jaguar *rightFront;
Jaguar *rightRear;
Joystick *driveStick;
Encoder *leftEncoder;
Encoder *rightEncoder;
Solenoid *shifter;
Gyro *moeGyro;
Compressor *moeCompressor;
DriverStation *ds;
DriverStationLCD *dsLCD;
int teleopLoop;
int disabledLoop;
int autoLoop;
public:
Stan(void) {
leftFront = new Jaguar(1);
leftRear = new Jaguar(2);
rightFront = new Jaguar(3);
rightRear = new Jaguar(4);
driveStick = new Joystick(1);
leftEncoder = new Encoder(1,2,true,Encoder::k1X);
rightEncoder = new Encoder(3,4,false,Encoder::k1X);
moeGyro = new Gyro(1);
moeCompressor = new Compressor(7,1);
ds = DriverStation::GetInstance();
dsLCD = DriverStationLCD::GetInstance();
}
void RobotInit(void) {
leftEncoder->Start();
rightEncoder->Start();
moeCompressor->Start();
shifter->Set(false);
}
void DisabledInit(void) {
disabledLoop = 0;
}
void TeleopInit(void) {
teleopLoop = 0;
}
void AutonomousInit(void) {
autoLoop = 0;
leftEncoder->Reset();
rightEncoder->Reset();
moeGyro->Reset();
}
void DisablePeriodic(void) {
disabledLoop = disabledLoop +1;
}
void TeleopPeriodic(void) {
teleopLoop++;
float X = driveStick->GetX();
float Y = driveStick->GetY();
if (X<0.1 && X>0.1) X = 0.0;
if (Y<0.1 && Y>0.1) Y=0.0;
X = Y + X;
Y = X - Y;
moeDrive(X, Y);
controlShifter();
int leftDist = leftEncoder->GetRaw();
if (teleopLoop % 10==0) {
dsLCD->Printf(DriverStationLCD::kUser_Line1, 1, "L = %d", leftDist);
dsLCD->UpdateLCD();
}
}
void AutonomousPeriodic(void) {
autoLoop++;
if (ds->GetDigitalIn(1)) {
autoLoop++;
}
}
void controlShifter(void) {
if (driveStick->GetTrigger()) {
shifter->Set(true);
}
else {
shifter->Set(false);
}
}
void moeDrive(float leftSpeed, float rightSpeed) {
if (leftSpeed > 1.0) leftSpeed = 1.0;
else if (leftSpeed < -1.0) leftSpeed = -1.0;
if (rightSpeed > 1.0) rightSpeed = 1.0;
else if (rightSpeed < -1.0) rightSpeed = -1.0;
leftFront->Set(leftSpeed);
leftRear->Set(leftSpeed);
rightFront->Set(rightSpeed);
rightRear->Set(rightSpeed);
}
};
START_ROBOT_CLASS(Stan);