Thread: Example code
View Single Post
  #5   Spotlight this post!  
Unread 14-03-2006, 14:59
TubaMorg TubaMorg is offline
Programmermechanicalelect ricalcoach
AKA: Dan
FRC #1480 (Robatos Locos)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Houston
Posts: 450
TubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond repute
Re: Example code

Aha! Well that's a different story and pretty ez to do. There's a variety of ways to implement it but a simple way is to first figure out how many counts your sensor returns per inch (or foot or cm or whatever units you are using) then use this:

Code:
void driveTo ( double distance )
{
      double d = 0; 
      int speed = 0;

      d = GetGTSensor ( GTS_DIG_IO ) ;
      d = d/ GEAR_COUNT_PER_INCH  ;
      while ( d < distance )
      {
            if ( (distance - d) < 12 )
            {
                  speed = 127 + (distance - d) ;
            }
            else
            {
                  speed = 175 ;
            }
            drivePID ( 127, speed ) ;
            d = GetGTSensor ( GTS_DIG_IO ) ;
            d = d/ GEAR_COUNT_PER_INCH  ;
      }
      PresetGTSensor ( GTS_DIG_IO , 0 ) ;
      Drive ( 127, 0 ) ;
}
Notes: This hasn't really been tested yet so there is no guarantee. It is very simplified, so accuracy probably isn't that great. However, as you wanted, notice the PresetGTSensor line, which resets your GTS back to zero. Just drag the Gear Tooth Sensor over and use the preset option. The input is distance that you want to travel (in inches) it drives an arbitrary speed (I chose 175) until the distance left is < 12 inches then slows down proportional to the distance left. drivePID is a function we have that aids in control by keeping the robot driving straight. So this function stays locked up in the while loop until the distance traveled (d) is equal to or greater than the desired distance (distance). The Drive (127,0) call is an EasyC function to stop the robot when the distance is achieved. (Again not tested, so if you use this, feedback would be appreciated!

Last edited by TubaMorg : 14-03-2006 at 15:05.