Go to Post FRANK, YOU'RE THE MAN. - Libby K [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Spotlight this post!  
Unread 07-12-2006, 20:39
EHaskins EHaskins is offline
Needs to change his user title.
AKA: Eric Haskins
no team (CARD #6 (SCOE))
Team Role: College Student
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Elkhorn, WI USA
Posts: 998
EHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond repute
Send a message via MSN to EHaskins
Re: Auto mode... need help

The easiest way to do this is to increment a variable every time you get new data from the master processor.

Default Autonomous:
Code:
  while (autonomous_mode)   /* DO NOT CHANGE! */
  {
    if (statusflag.NEW_SPI_DATA)      /* 26.2ms loop area */
    {
        Getdata(&rxdata);   /* DO NOT DELETE, or you will be stuck here forever! */

        /* Add your own autonomous code here. */

        Generate_Pwms(pwm13,pwm14,pwm15,pwm16);

        Putdata(&txdata);   /* DO NOT DELETE, or you will get no PWM outputs! */
    }
  }
The first thing you need to do is create a static variable to use as a counter.

Code:
static int i;
Then you need to increment the variable. The easiest way to do this is to increment the counter each time you get new data.

Code:
  while (autonomous_mode)   /* DO NOT CHANGE! */
  {
    if (statusflag.NEW_SPI_DATA)      /* 26.2ms loop area */
    {
        Getdata(&rxdata);   /* DO NOT DELETE, or you will be stuck here forever! */

        i++; // this will increment the 'i' variable by 1.

        /* Add your own autonomous code here. */

        Generate_Pwms(pwm13,pwm14,pwm15,pwm16);

        Putdata(&txdata);   /* DO NOT DELETE, or you will get no PWM outputs! */
    }
  }
Now you can calculate the time by multiplying the time span(26.2) by the number if times(i) to get the actual time.

Code:
int time;

  while (autonomous_mode)   /* DO NOT CHANGE! */
  {
    if (statusflag.NEW_SPI_DATA)      /* 26.2ms loop area */
    {
        Getdata(&rxdata);   /* DO NOT DELETE, or you will be stuck here forever! */
        i++; // this will increment the 'i' variable by 1.
        time =  (i * 262)/2500 // if you avoid the decimal, by multiplying the time span by 10, your code will execute faster because it will not use a floatig points.
        // I divide the time(in 10000enths of a second) by 2500 so I get a result in 1/4 of a second

        Generate_Pwms(pwm13,pwm14,pwm15,pwm16);

        Putdata(&txdata);   /* DO NOT DELETE, or you will get no PWM outputs! */
    }
  }
Example code to drive forward 1 second, then reverse for 1 second.

Code:
int time;

  while (autonomous_mode)   /* DO NOT CHANGE! */
  {
    if (statusflag.NEW_SPI_DATA)      /* 26.2ms loop area */
    {
        Getdata(&rxdata);   /* DO NOT DELETE, or you will be stuck here forever! */
        i++; // this will increment the 'i' variable by 1.
        time =  (i * 262)/2500 // if you avoid the decimal, by multiplying the time span by 10, your code will execute faster because it will not use a floatig points.
        // I divide the time(in 10000enths of a second) by 2500 so I get a result in 1/4 of a second

        //drive code\\
        if (time < 4) pwm01 = pwm02 = 255; //forward
        else if(time < 8) pwm01 = pwm02 = 0; //reverse
        else if(time > 8) pwm01 = pwm02 = 127;//stop

        Generate_Pwms(pwm13,pwm14,pwm15,pwm16);

        Putdata(&txdata);   /* DO NOT DELETE, or you will get no PWM outputs! */
    }
  }
I think that is what your looking for.

Hope this helps, and sorry for the long post.
__________________
Eric Haskins KC9JVH
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
10 ball auto mode nuggetsyl Scouting 22 27-02-2006 20:39
Sending variables to Auto Mode Adrien Programming 4 19-02-2006 21:51
auto mode nuggetsyl General Forum 12 13-02-2006 19:45
Auto mode help..... Moloch Programming 2 18-02-2005 09:18
Auto. mode!!! skitz547 Rules/Strategy 1 09-03-2003 22:37


All times are GMT -5. The time now is 20:44.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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