Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Gyro Turning in Auto Mode (http://www.chiefdelphi.com/forums/showthread.php?t=134970)

tomy 02-20-2015 01:15 PM

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;
                        }
                }
        }


GeeTwo 02-20-2015 03:21 PM

Re: Gyro Turning in Auto Mode
 
Quote:

Originally Posted by tomy (Post 1447677)
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;
                        }
                }
        }


The first thing I notice is that you're resetting the gyro in the method. Unless you're using sampleRobot, the gyro will get reset again and again.

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.

tomy 02-20-2015 03:31 PM

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);
}

Then as soon as the the gyro hit 70 degrees it would stop moving. If the robot rotated to fast, which it is, it would not be able to correct itself.

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);

The robot rotated the wrong way.

Alan Anderson 02-20-2015 04:06 PM

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.

GeeTwo 02-20-2015 05:32 PM

Re: Gyro Turning in Auto Mode
 
Quote:

Originally Posted by tomy (Post 1447677)
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.

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?


All times are GMT -5. The time now is 10:08 AM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi