View Single Post
  #4   Spotlight this post!  
Unread 04-02-2008, 07:32
BradAMiller BradAMiller is offline
Registered User
AKA: Brad
#0190 ( Gompei and the Herd)
Team Role: Mentor
 
Join Date: Mar 2004
Location: Worcester, MA
Posts: 592
BradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant future
Re: Integration of Gyro with Easy-C Pro

If you are using WPILib or easyC the code to do all those calculations and the timing for sampling is built in. Here's a complete sample WPILib program that will enable a robot to drive in a straight line. This uses a set of Drive functions that can be included with easyC by doing an "Import Library..." operation.
Code:
#include "BuiltIns.h"

/*
* Sample program to have the robot drive in a straight line using
* the kit gyro sensor (connected to analog port 1).
*/

void main(void)
{
}

void IO_Initialization(void)
{
    SetCompetitionMode(1);   // set to competition mode
}

void Initialize(void)
{
    InitGyro(1);             // initialize gyro on port 1
    TwoWheelDrive(2,1);      // Setup 2 motor drive robot (ports 1 & 2)
}

void Autonomous(void)
{
    int heading;
    StartGyro(1);             // start gyro sampling
    while (1)
    {
        heading = GetGyroAngle(1); // get the current heading
        Drive(80, heading/2); // turn towards the error
    }
}
This should be close to what you need - it depends on the direction of rotation of your wheels. The InitGyro, StartGyro, and GetGyroAngle functions in easyC all come from the Gyro block - there are buttons to indicate which one you want. The Gyro type can also be set with the Gyro block.
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute