VEX C++ Programming Pneumatics

void usercontrol( void ) {
//

int LiftLSpeedPCT = 100;
int LiftRSpeedPCT = 100;

while (1){
//tank controls
BackR.spin(directionType::fwd, (Controller1.Axis2.value()), vex::velocityUnits::pct);
BackL.spin(directionType::fwd, (Controller1.Axis3.value()), vex::velocityUnits::pct);
FrontL.spin(directionType::fwd, (Controller1.Axis3.value()), vex::velocityUnits::pct);
FrontR.spin(directionType::fwd, (Controller1.Axis2.value()), vex::velocityUnits::pct);

  digital_out dig1 = digital_out( Brain.ThreeWirePort.Port[7] );

while(1) {
if( Controller1.ButtonR1.pressing() ) {
dig1.set( true );
}
else {
dig1.set( false );
}

this_thread::sleep_for(10);

}
}

 //lIFT Control
  if(Controller1.ButtonL1.pressing()) {
      LiftL.spin(vex::directionType::fwd, LiftLSpeedPCT, vex::velocityUnits::pct);
      LiftR.spin(vex::directionType::rev, LiftRSpeedPCT, vex::velocityUnits::pct);
  }
  else if(Controller1.ButtonL2.pressing()) {
      LiftL.spin(vex::directionType::rev, LiftLSpeedPCT, vex::velocityUnits::pct);
      LiftR.spin(vex::directionType::fwd, LiftRSpeedPCT, vex::velocityUnits::pct);
  }
  else {
      LiftL.stop(vex::brakeType::coast);
      LiftR.stop(vex::brakeType::coast);
    }   

vex::task::sleep(20); //Sleep the task for a short amount of time to prevent wasted resources. 

}

1 Like

this is my code and its not letting me control the bot whats wroooong

This right here is an infinite loop. the rest of your code is not executing. It’s already in a while loop, so you shouldn’t need another one for this if statement.

Additionally, your ‘LIFT CONTROL’ is outside the scope of your larger, still infinite, while loop. That code also needs to be in the loop to run

void usercontrol( void ) {
//

int LiftLSpeedPCT = 100;
int LiftRSpeedPCT = 100;

while (1){
//tank controls
BackR.spin(directionType::fwd, (Controller1.Axis2.value()), vex::velocityUnits::pct);
BackL.spin(directionType::fwd, (Controller1.Axis3.value()), vex::velocityUnits::pct);
FrontL.spin(directionType::fwd, (Controller1.Axis3.value()), vex::velocityUnits::pct);
FrontR.spin(directionType::fwd, (Controller1.Axis2.value()), vex::velocityUnits::pct);

  digital_out dig1 = digital_out( Brain.ThreeWirePort.Port[7] );

if( Controller1.ButtonR1.pressing() ) {
  dig1.set( true );
}
else {
  dig1.set( false );
}

this_thread::sleep_for(10);
  
 
  if(Controller1.ButtonL1.pressing()) {
      LiftL.spin(vex::directionType::fwd, LiftLSpeedPCT, vex::velocityUnits::pct);
      LiftR.spin(vex::directionType::rev, LiftRSpeedPCT, vex::velocityUnits::pct);
  }
  else if(Controller1.ButtonL2.pressing()) {
      LiftL.spin(vex::directionType::rev, LiftLSpeedPCT, vex::velocityUnits::pct);
      LiftR.spin(vex::directionType::fwd, LiftRSpeedPCT, vex::velocityUnits::pct);
  }
  else {
      LiftL.stop(vex::brakeType::coast);
      LiftR.stop(vex::brakeType::coast);
    }   

vex::task::sleep(20); //Sleep the task for a short amount of time to prevent wasted resources. 

}
}

last question would this work is there any problem, i cant test on my bot till next week thats why im asking

I don’t see any issues with it :smile:

how would this be programmed in autonomous

The same way as before, but with time and placement instead of button presses. Below is how I’d turn it on for 1.5 seconds and then turn it off.

dig1.set( true );
Task::sleep(1500);
dig1.set( false );

it dont work man it says unclear use of “dig1”

Did you define dig1?

how? im sorry i just started coding
please include an example

nevermind bro i figured it out but thanks XD

1 Like

how can i move the solenoids out and in

Um you replied to the post that includes an exact answer. Also you may be confusing solenoids with the pneumatic cylinders. Solenoids are the controllers for pneumatic cylinders. they are the gates for air to flow through in order to open and close the cylinder.

yea i wanna make the cylinder go in and out using a controller i cant seem to make it work
in vexcode text

Posts automatically lock after a year, right? Did you just stop this thread from getting locked by 2 hours?

If you want some help, you’re going to need to post what you have in your code currently.

3 Likes

Do you think you could send yours for me to examine? That would be much appreciated!

Is this some sort of compition to keep this thread unlocked for as long as possible?

3 Likes

I have never used Vex V5 Pro or C++ at all. I just got pneumatics and so a was wondering if you could you show me a video and a photo of your code. I have been trying to figure out how to use pneumatics for our auto.

I wouldn’t say it is. There is some pretty useful info here :wink: