Go to Post Come on, Dave! We need more lyrics! (I'll bring you fresh KK doughnuts at VCU's regional! :D ) - Squirrelrock [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

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 20-02-2004, 18:41
CharlieWilken CharlieWilken is offline
Registered User
#0634 (Robowolves)
 
Join Date: Jan 2002
Location: Van Nuys, CA
Posts: 46
CharlieWilken is an unknown quantity at this point
turn left stop and actuate - autonomous

We need help with code in autonomous. We want our robot to turn (left or right) stop and then actuate a relay and move a speed controller motor. We need to know how to make the code and where to put it in the default code.

Thanks team 634
  #2   Spotlight this post!  
Unread 20-02-2004, 21:37
mtrawls's Avatar
mtrawls mtrawls is offline
I am JVN! (John von Neumann)
#0122 (NASA Knights)
Team Role: Programmer
 
Join Date: Mar 2003
Location: Hampton, VA
Posts: 295
mtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to behold
Send a message via AIM to mtrawls
Re: turn left stop and actuate - autonomous

Quote:
Originally Posted by CharlieWilken
We need help with code in autonomous. We want our robot to turn (left or right) stop and then actuate a relay and move a speed controller motor. We need to know how to make the code and where to put it in the default code.

Thanks team 634
Look in the file user_routines_fast.c and look for User_Autonomous_Code(). You will put your code here. I suggest implementing a simple state machine, e.g.:

Code:
switch (auton_state) {
  case TURN:
  {
  // put code to turn in desired direction here
  // change state when you are done turning
  // you'll know this either by a pre-determined time,
  // a gyro reading/accumulation, or an encoder system
  break;
  }
  case ACTUATE:
  {
  // put code here to actuate the relay/move motor
   break;
  }
  ...
  default:
  { // either you have a default condition, or this should print an error
  }
}
You can add as many states as suits your pleasure -- this makes it easy to change how you do the auton mode quickly. Make sure you change the state to the next one once you are done with the current. A little more details/more info on what you want/your robot would help to elicit a more specific response ... but this should get you started.
  #3   Spotlight this post!  
Unread 21-02-2004, 07:38
Ryan M. Ryan M. is offline
Programming User
FRC #1317 (Digital Fusion)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Ohio
Posts: 1,508
Ryan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud of
Re: turn left stop and actuate - autonomous

Quote:
Originally Posted by mtrawls
Look in the file user_routines_fast.c and look for User_Autonomous_Code(). You will put your code here. I suggest implementing a simple state machine, e.g.:

Code:
switch (auton_state) {
  case TURN:
  {
  // put code to turn in desired direction here
  // change state when you are done turning
  // you'll know this either by a pre-determined time,
  // a gyro reading/accumulation, or an encoder system
  break;
  }
  case ACTUATE:
  {
  // put code here to actuate the relay/move motor
   break;
  }
  ...
  default:
  { // either you have a default condition, or this should print an error
  }
}
You can add as many states as suits your pleasure -- this makes it easy to change how you do the auton mode quickly. Make sure you change the state to the next one once you are done with the current. A little more details/more info on what you want/your robot would help to elicit a more specific response ... but this should get you started.
Yeah, that is te basic idea. You would have a static variable at the top of that function named something appropriate like, say, state that is initailized to zero. Like this:
Code:
// this is just after the function header
static unsigned char state = 0;
In your states you would then increment it when the condition for a state being done is satisfied. I.E.:
Code:
switch(state)
{
    case 0: // This is your turn state
        if(supposed to turn left) // This would be however you can tell whether you are supposed to turn left or right
        {
            // So, we turn left however you do that
        }
        else
        {
            // This is where you turn right
        }

        // now we check to see if we can go to the next state
        if(done turning condition) // This is your encoders or whatever you use to tell if you've turned far enough
             state++; // Go to the next state
        break;

    case 1: // Next state
        // Same idea for a long as you want
        break;

    default:
        // If you reach here something went wrong
}
So, the idea is that you increment a state variable when you are done with a state.

PS Just as a side note, I have my defaults in my various switches calling a function named stupid(). All it does is printf() Stupid! and calls itself until it crashes. Anyways, that was kind of random.
__________________

  #4   Spotlight this post!  
Unread 21-02-2004, 14:02
mtrawls's Avatar
mtrawls mtrawls is offline
I am JVN! (John von Neumann)
#0122 (NASA Knights)
Team Role: Programmer
 
Join Date: Mar 2003
Location: Hampton, VA
Posts: 295
mtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to behold
Send a message via AIM to mtrawls
Re: turn left stop and actuate - autonomous

Quote:
Originally Posted by Texan
Yeah, that is te basic idea. You would have a static variable at the top of that function named something appropriate like, say, state that is initailized to zero. Like this:
Code:
// this is just after the function header
static unsigned char state = 0;
In your states you would then increment it when the condition for a state being done is satisfied. I.E.:
Code:
switch(state)
{
    case 0: // This is your turn state
        if(supposed to turn left) // This would be however you can tell whether you are supposed to turn left or right
        {
            // So, we turn left however you do that
        }
        else
        {
            // This is where you turn right
        }

        // now we check to see if we can go to the next state
        if(done turning condition) // This is your encoders or whatever you use to tell if you've turned far enough
             state++; // Go to the next state
        break;

    case 1: // Next state
        // Same idea for a long as you want
        break;

    default:
        // If you reach here something went wrong
}
So, the idea is that you increment a state variable when you are done with a state.

PS Just as a side note, I have my defaults in my various switches calling a function named stupid(). All it does is printf() Stupid! and calls itself until it crashes. Anyways, that was kind of random.
Might I suggest using an enum or define statements to name the states. state = 3.14159 is a bit more esoteric than #define AT_TARGET 3.14159 and then saying state = AT_TARGET (a bit less demanding on programmer's all-too-vexed memory too). This also helps because you don't always want to say sate++ -- for example, in my code I have a state to turn left and another to turn right, and it all depends on which sensor sees it; so there is an if statement assigning state a different value based on the condition.
Closed Thread


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


All times are GMT -5. The time now is 03:06.

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