Not seeing PCT

void usercontrol(void) {
int LASpeedPCT=50;
int RASpeedPCT=50;
int LISpeedPCT=100;
int RISpeedPCT=100;
int PuncherSpeedPCT=20;
int RRSpeedPCT=100;
int RFSpeedPCT=100;
int LRSpeeedPCT=100;
int LFSpeedPCT=100;

while (true) {

  int RRSpeed = Controller1.Axis3.position();
int RFSpeed = Controller1.Axis3.position();
int LRSpeed = Controller1.Axis2.position();
int LFSpeed = Controller1.Axis2.position();
1 Like

It is not recognizing the RRSpeedPCT variable

Could you post where RRSpeedPCT is referenced within the code? If this is your entire code, then you never actually reference RRSpeedPCT.

It says the RRSpeed variable is undefined. This is to drive with joysticks.

void usercontrol(void) {
int LASpeedPCT=50;
int RASpeedPCT=50;
int LISpeedPCT=100;
int RISpeedPCT=100;
int PuncherSpeedPCT=20;

while (true) {

  int RRSpeed = Controller1.Axis3.position();
int RFSpeed = Controller1.Axis3.position();
int LRSpeed = Controller1.Axis2.position();
int LFSpeed = Controller1.Axis2.position();
if(Controller1.ButtonL2.pressing()) {
  LA.spin(directionType::fwd, LASpeedPCT, velocityUnits::pct);
  RA.spin(directionType::fwd, RASpeedPCT, velocityUnits::pct );
}
else if(Controller1.ButtonL1.pressing()) {
  LA.spin(directionType::rev, LASpeedPCT, velocityUnits::pct);
  RA.spin(directionType::rev, RASpeedPCT, velocityUnits::pct);
}

else{
  LA.stop(brakeType::hold);
  RA.stop(brakeType::hold);
}

if(Controller1.ButtonR2.pressing()) {
  RI.spin(directionType::fwd, RISpeedPCT, velocityUnits::pct);
  LI.spin(directionType::fwd, LISpeedPCT, velocityUnits::pct);

}

else if(Controller1.ButtonR1.pressing()) {
  RI.spin(directionType::rev, RISpeedPCT, velocityUnits::pct);
  LI.spin(directionType::rev, LISpeedPCT, velocityUnits::pct);
}

else{
  LI.stop(brakeType::hold);
  RI.stop(brakeType::hold);
}

if(Controller1.ButtonUp.pressing()) {
  Puncher.spin(directionType::fwd, PuncherSpeedPCT, velocityUnits::pct);
}

else if(Controller1.ButtonDown.pressing()) {
  Puncher.spin(directionType::rev, PuncherSpeedPCT, velocityUnits::pct);
}

else{
  Puncher.stop(brakeType::hold);
}

wait(20, msec); // Sleep the task for a short amount of time to
                // prevent wasted resources.

}
}

Where do you use RRSpeed? I see where it is defined but not where you use it.

The Axis Values. I got rid of the PCT

Oh, you want to drive with Joysticks? In that case, just defining an integer for the speed shouldn’t automatically generate code for the joysticks. Instead, assuming you want a tank drive, I would personally go something along the lines of

int RSpeed = Controller1.Axis3.position();
int LSpeed = Controller1.Axis2.position(); //you don’t need each individual motor to be a variable if you just reference the same variable for both wheels on one side of a drive train.
RF.spin(directionType::fwd, RSpeed, velocityUnits::pct);
RR.spin(directionType::fwd, RSpeed, velocityUnits::pct);
LF.spin(directionType::fwd, LSpeed, velocityUnits::pct);
LR.spin(directionType::fwd, LSpeed, velocityUnits::pct);

But yeah, if there is an error, which line is it on?

1 Like

Do you have a screenshot of the error?
When you use
int RRSpeed = Controller1.Axis3.position();
It should not be producing a variable is undefined error if you call it in the while loop. It should only be an error when you call the variable outside the while(true) loop

1 Like

It works thank you very much

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.