P loop confusion

Can someone help me with my p loop i cant find out what im doing wrong the code is below

int tilterPControl = ButtonR1 + 100(-1(Lift.rotation(degrees)/1.58));

Lift.spin(fwd,100,tilterPControl);

The errors are here

called object type ‘int’ is not a function or function pointer
no matching member function for call to ‘spin’

What is the range of values for ‘buttonR1’? If its boolean then you are trying to add a double and a bool which won’t work

the R1 value is supposed to be the input but i don’t really understand how to write a p loop in vexcode so that’s why i am confused on how to write it

And I haven’t found any resources on how to write it in vexcode

Which is why I sent the link in the other thread. Try something like this:

Double power;
If(buttonpressing){
power = (target - current)*constant);
}
Else{
Power = 0;
}

well i looked into it and that’s similar to what i wrote its just that part of code that is having the issue

this is how mine is set up below

if(Controller.ButtonR1.pressing()) {
int LiftPControl = Lift + 100(-1(Lift.rotation(rev)/1.58));
Lift.spin(fwd,100,LiftPControl);
}
else if(Controller.ButtonR2.pressing()) {
Lift.spin(vex::directionType::rev, 200, vex::velocityUnits::pct);
} else {
Lift.stop(vex::hold);
}

For the first Lift.spin line, LiftPControl should go in the second parameter and pct/rpm should be in the 3rd parameter

Ok 1 of the 2 problems solved now this line still has an error:
int LiftPControl = Lift + 100(-1(Lift.rotation(rev)/1.58));

The error states that the called object type ‘int’ is not a function or function pointer and the red area on the code is at the start of the 2nd parenthesis

What is “Lift” in your code

the lift is just the tray lift motor

Lift doesn’t mean anything by itself so it is producing an error in your code, try removing it

still the same error

int LiftPControl = (-1(Lift.rotation(rev)/1.58));
----------------------- ^
the arrow is where the error is

Ok it worked thank you so much there is just little to no reference on p loops for vexcode and i really appreciate your help

introduction_to_pid_controllers_ed2.pdf (400.2 KB)

P loops isnt only specific to VexCode so that’s why there’s nothing in VexCode that references P loops. The PDF I uploaded is one of my favorite documents for learning P loops (and PID)

The problem here was that when you tried to do implicit multiplication without the * symbol, the compiler interpreted that as you calling a function, as that is the same syntax as you would use to call a function that was named “100”

1 Like

well yea but i didnt find an exact way on how to set it up

Here’s also a link to a post that contains code with a p loop

1 Like