Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   How to end an auto mode after gyro gets out of deadband (http://www.chiefdelphi.com/forums/showthread.php?t=46619)

kiettyyyy 20-04-2006 02:01

Re: How to end an auto mode after gyro gets out of deadband
 
Thanks for all the replies..

We know how to write a PID loop but, thats not what were looking for. What im actually trying to do is to totally kill the autonomous mode after the gyro gets out of the deadband in code, but once it goes back into the dead band, the code was once again running. I need to stop the bot once it gets out of the dead band and make sure its going to not re execute while its back into the deadband.

Getting it still??
Heres what I have in my code so far.

Code:


        autoCalculator++;
        gyroTimer++; // this will rollover every ~1000 seconds

        if(gyroTimer == 1)
        {
                // start a gyro bias calculation
                Start_Gyro_Bias_Calc();
        }

        if(gyroTimer == 2)
        {
                // terminate the gyro bias calculation
                Stop_Gyro_Bias_Calc();

                // reset the gyro heading angle
                Reset_Gyro_Angle();

                printf("Done\r");
        }


        //        if(i >= 30 && j >= 65)
        if(gyroTimer >= 3)
        {
                temp_gyro_bias = Get_Gyro_Bias();
                temp_gyro_rate = Get_Gyro_Rate();
                temp_gyro_angle = Get_Gyro_Angle();
                printf("Gyro Angle: %d\r\n", (int)temp_gyro_angle);
                //i = 0;

        }

        // AUTONO STUFF GOES HERE!!       
                                        gyroAuto = temp_gyro_angle;
                                gyroAutoCalc = temp_gyro_angle - gyroAuto;
                               
                                if(ActivateGyro == 1)
                                {
                                        if(setauto == !2 && gyroAuto < 24 && gyroAuto > -24)
                                        {
                                                setauto = 1;
                                        }
                                        else
                                        {
                                                setauto = 2;
                                        }
                                }
                                else
                                {
                                        setauto = 1;
                                }

When it goes into setauto = 2, the bot stops. But why would it re execute?

Alan Anderson 20-04-2006 07:42

Re: How to end an auto mode after gyro gets out of deadband
 
Quote:

Originally Posted by kiettyyyy
Code:

if(setauto == !2...

I didn't look closely at the rest of the logic, but this line is wrong. You probably mean
Code:

if(setauto != 2...

EricS-Team180 20-04-2006 07:59

Re: How to end an auto mode after gyro gets out of deadband
 
How's 'bout something like this:

Code:

  .
  .
  .
  static unsigned char LatchEndAuto = 0;  /* ...or declare it global */
  int gyroThreshold = 24  ; /* ...or whatever */

  if( !LatchEndAuto)
  {
      if ( (gyroauto < -gyroThreshold) ||
          (gyroauto > gyroThreshold )  )
          LatchEndAuto = 1 ;
  }
    .
    .
    .

  /* put this at the end of your auto code */
    if(LatchEndAuto)
  {
      LeftSideChassisPWM  =  127 ;
      RightSideChassisPWM =  127 ;
  }

Eric


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

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