Pneumatics in program

Our pneumatics work one time but then they wont move?

I’m sorry, could you clarify the question a bit?

1 Like

Did you put it in the loop of driver control? Your question doesn’t have a lot of information I can use to help. If you code share your code that would great.

The piston moves once and then no matter what button we press it doesn’t move

Can you post the code you’re using to do that (making sure to surround it with the code markers so it formats properly)? There’s likely a simple solution, but more information is needed in order for folks to be able to help out.

2 Likes
while(1) {

	bool isPressed = MasterController.get_digital_new_press(E_CONTROLLER_DIGITAL_B);
	//bool isPressed2 = MasterController.get_digital_new_press(E_CONTROLLER_DIGITAL_B);

	if(isPressed && pneumatic_value % 2 == 0) {

		pneumatic_lift.set_value(false);
		//screen::print(TEXT_LARGE, 1, "0");
		screen::print(TEXT_LARGE, 1, "%d", count);
		pneumatic_value++;
		count++;

	} else if(isPressed && pneumatic_value % 2 == 1) {

		pneumatic_lift.set_value(true);
		//screen::print(TEXT_LARGE, 1, "1");
		screen::print(TEXT_LARGE, 1, "%d", count);
		pneumatic_value++;
		count++;

Presumably there’s nothing of consequence after the last line of the ‘else if’ block, since I see no closing braces or anything. Also, assuming you have initialized your values to some know state.

The structure of what you’re trying to do here is a bit awkward, and I would recommend instead doing modulo math, that you just set your value to a 0 or 1, or 1 or 2, and just switch back and forth for your ‘pneumatic_value’ instead of relentlessly incrementing. Depending on what the type is for ‘pneumatic_value’ you run a (small) risk of eventually hitting the max value and wrapping around. Setting back and forth between two known value is more straightforward and less awkward for what is effectively a state machine.

Further question: what behavior are you seeing on the display? Are you seeing the printouts and the piston just isn’t actuating? Are you seeing no printouts? As much information as you can relay that’s relevant helps identify the problem that much faster.

1 Like

Also, consider instead:
if(isPressed && ((pneumatic_value % 2) == 0))
as this forces the compiler to evaluate those things in that order. Things should evaluate properly, and I don’t think I’ve personally observed an issue with the Vex compiler doing things out of prescribed order, but it is something I have seen with other compilers. Being explicit with parentheses is always a code legibility thing for me, as it lets me understand exactly what the programmer intended as far as order of operations.

1 Like

there are no printouts

So, put a printout before the pneumatic actuation to ensure your printouts are working as expected, or before the while loop entry. If it’s not hitting your printout, then it would lead me to expect that something in the penumatic_lift.set_value(false) is not returning back from the call for some reason.

How do you have the pneumatic_lift device configured for the robot, as far as device type?

1 Like

Can you please post the entire code? ctrl+a, ctrl+c, and then ctrl+v into VEX Forum. The code as posted will compile errors, and it’s possible the issue is outside of what you’ve posted.

2 Likes

Why doesn’t he just use a Boolean? It would probably be easier to read pistonextended = true than pistonextended = 1, and I don’t think there’d be any code he’d need to pass an integer as a parameter. It also means he doesn’t have to worry about him accidentally setting the value to something else and ruining his code.

2 Likes

Plus, then to toggle it, you just have to say pistonExtended = !pistonExtended; instead of

if (pistonExtended == 0) pistonExtended = 1;
else if (pistonExtend == 1) pistonExtended = 0;
else print("Error!");
3 Likes

Write this function first

bool pistonExtend = false;
void piston(){
pistonExtend = !pistonExtend;
pneumatic_lift.set_value(pistonExtend);
}

in driver control:

void driverControl(){
while(1){
    if(MasterController.get_digital_new_press(E_CONTROLLER_DIGITAL_B)){
           piston();
        }
   }
}
1 Like

… and while you push the button, the cylinder will go inandoutandinandoutandinand. You would need to add, theButtonWasBeingPushedLastTimeWeChecked.

bool extended = false;
void cylinder() {
  extended = !extended;
  pnuematic_lift.set_value(extended);
}

bool buttonWasPressedLastTime = false;
while (true) {
  if (MasterController.get_digital_new_press(E_CONTROLLER_DIGITAL_B)) {
    if (!buttonWasPressedLastTime) cylinder();
    buttonWasPressedLastTime = true;
  }
  else buttonWasPressedLastTime = false;
}

I’m not saying this code will work; you’ll have to understand it and decide if you think it would work. Don’t use it if you don’t understand it, or when it breaks, you won’t be able to fix it.

1 Like

Actually, get_digital_new_press(void*) is equal to pressed(void*) in vex code pro. So this wouldn’t be a problem.

1 Like