How do I make my tray angle move slower as it moves closer to stacked, or for us, 1.62 revolutions?
This is kind of what i want:
when TrayAngle turns > 1.2 {
TrayAngle.setVelocity(20,pct)
}
How do I make my tray angle move slower as it moves closer to stacked, or for us, 1.62 revolutions?
This is kind of what i want:
when TrayAngle turns > 1.2 {
TrayAngle.setVelocity(20,pct)
}
you could use a p loop.
int error = 0;
double kP = 0.5;
int main = (){
error = desiredAngle - tilterAngle;
int motorPower = error * kP
Tilter.spin(forward, motorPower, voltageUnits::volt);
};
you would tune your kP value to your liking. should work well.
What’s kP?
its your p value. stands for proportional I believe. what it does is make your tray slow down as it approaches your desired angle.
Wait, do I take out the () after the int main?
you shouldn’t I don’t think… not a master coder here, just went off memory. it won’t work if you just copy-paste. you have to have your variables at the top of your code, and the p loop should be inside your control loop.
It shows as an error
Could you provide an example with example numbers and stuff?
not sure what you want. just take the variables, put them in front of your control loops, then take the p loop and put it inside your control loop.
post your code here so I can show you where to put things if you’re still confused
You have your main function running under a controller feedback. Not only that, but error is continual update that responds to motor feedback. You need to put the algorithm in a while loop and put the whole thing in a separate function. Your main should really only contain functions for the sake of simplicity and efficency.
The code should look more like:
void tilterMacro(){
int error = 0, motorPower = 0;
double Kp = .5;
while(trayAngle < target){
error = target - trayAngle;
Tilter.spin(forward, motorPower, voltageUnits::volt);
delay(20);
}
}
int main(){
if(buttonPressed())
tilterMacro();
}
This will not necessarily work for the Vexcode API, I just used the above code and fit it under better formatting that will work mathematically and semantically.
do i just leave it called trayAngle and target? I’m sorry if I sound stupid
no, trayAngle and target are just placeholders for you to put your real values. the names are self-explanatory.
whats up with the error?
once again sorry if i sound stupid
no offense, but you seem to lack a common knowledge of c++ syntax. for example, you can’t be putting your functions inside your control loop. I’d suggest you spend some time learning the proper structuring and syntax of c++, or else you will have a lot of struggles like this. give me a minute to try to make this as simple as I can.
@Xenon27 Thanks for taking the time but I figured it out, sorry for all the inconviniences I have caused you.
//your P value for your p loop. you will need to adjust this for it to work well with your robot.
double kP = 0.5;
//your desired tray angle. you will need to change this to the angle that your tilter motor needs to be at for your tray to be vertical.
int desiredTrayAngle = 500;
//don't touch this variable.
int error = 0;
//this is your driver control function. it should already exist in your program, you shouldn't have to create it.
void usercontrol(void){
//your while loop. this should also be there already.
while(true){
if( you are pressing the button you want ){
error = desiredTrayAngle - TilterMotor.rotations(degrees);
double motorPower = error * kP;
TilterMotor.spin(forward, motorPower, voltageUnits::volt);
}
};
};
no worries, glad you figured it out.
I agree with @Xenon27, our current programmer took the first several meetings this year just to learn the syntax and the read up the documentation from PROS. Once we finished building, he could be more efficient in coding after taking the time to learn since he had little experience with c++ or c.