|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Gyro Turning in Auto Mode
We trying to manipulate the kp so that we turn slow at the beginning then increase the speed of rotation when we approach the angle we want. It works kinda of just spins way to fast at the beginning of the rotate. Suggestions?
Code:
if(stage_one_complete){
gyro.Reset();
while(IsAutonomous() && IsEnabled() ){
float angle = gyro.GetAngle();
if(angle > + 70){
kp = 0.005;
}else if(angle < + 70){
kp = 0.02;
}
myRobot.MecanumDrive_Cartesian( 0, 0, ((angle + 82) * kp), 0);
timer ++;
Wait (0.004);
if(timer > 400){
myRobot.MecanumDrive_Cartesian(0, 0, 0, 0);
stage_one_complete = false;
stage_two_complete = true;
break;
}
}
}
|
|
#2
|
|||||
|
|||||
|
Re: Gyro Turning in Auto Mode
Quote:
Also, in the first if statement, you did not cover the angle == 70 case; you'd probably be better off with a simple else. You also give it a larger number at the beginning, which is what I would expect that you want, but does not agree with the description at the top. Try changing the > to a < in the if and see if that's what you wanted. |
|
#3
|
|||
|
|||
|
Re: Gyro Turning in Auto Mode
Yes we are using a sampleRobot. The code works just not as expected. We want to have to robot turn and correct itself. If we were to put an else code something like:
Code:
else if (angle == 70) {
myRobot.MecanumDrive_Cartesian(0, 0, 0, 0);
}
We are trying to make the robot correct itself because the robot turns to fast. That's the point of changing the KP. If the angle is high KP should be low such that the robot turns slow. As the angle approaches the set angle we change KP to a bigger number such that the robot moves fast enough to turn it. Also to note when we rotate the robot it returns a negative value. If we were to say: Code:
if(angle > - 70){
kp = 0.005;
}else if(angle < - 70){
kp = 0.02;
}
myRobot.MecanumDrive_Cartesian( 0, 0, ((angle - 82) * kp), 0);
Last edited by tomy : 20-02-2015 at 15:37. |
|
#4
|
|||||
|
|||||
|
Re: Gyro Turning in Auto Mode
It sounds like you might get what you want if you just limit the maximum turn rate. Compute Kp * angle and clip it at 0.6, or 0.4, or whatever works for you.
If you are having problems with the turn command not being enough to get the heading all the way to the target, you could add some Integral to the equation of control. That's what it's for. |
|
#5
|
|||||
|
|||||
|
Re: Gyro Turning in Auto Mode
I still can't quite figure out what you're trying to accomplish. You want to creep up on the angle until you're almost there, then gun it (and, if you do it right, force an overshoot of the target)? Or are you trying to correct for something else?
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|