View Single Post
  #2   Spotlight this post!  
Unread 24-01-2013, 18:58
BradAMiller BradAMiller is offline
Registered User
AKA: Brad
#0190 ( Gompei and the Herd)
Team Role: Mentor
 
Join Date: Mar 2004
Location: Worcester, MA
Posts: 588
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: Gyro not sending values?

One thing you might try is to put the robot in Test mode from the DriverStation and verify that you are getting expected values for the gyro. It should show you the headings it is returning as you grab the robot and rotate it. Verify that the gyro sensitivity parameter is correct - if you look at the Gyro.h header file there is a parameter for this. The default is kDefaultVoltsPerDegreePerSecond = 0.007. Make sure that this matches the gyro that you are using.

Unrelated to the gyro problem, to make the driving easier, you might consider using the RobotDrive object instead of having separate speed controllers. The RobotDrive object in WPILib takes 2 or 4 drive speed controllers and supplies a number of methods to operate on them. It was designed to do exactly what you want to do.

While the code shown below is completely untested and it's possible that some of the parameters are not quite right, you can look at the samples and get the idea from this.

So you can replace this code:
Code:
	Jaguar frontRight; // robot drive system
	Jaguar frontLeft;
	Jaguar backLeft;
	Jaguar backRight;
with something like this:
Code:
        RobotDrive drive;
Then instead of having the separate controllers:
Code:
		frontRight(1),	// these must be initialized in the same order
		frontLeft(2),	// as they are declared above.
		backLeft(3),
		backRight(4),
you have something that looks like this:
Code:
                drive(1, 2, 3, 4),
Once you've defined the RobotDrive object it becomes easy to operate the robot so this code:
Code:
	void motorDrive(float speed)//Positive is forward; Negative is backwards
	{
		frontRight.Set(speed);
		frontLeft.Set(-speed);
		backLeft.Set(-speed);
		backRight.Set(speed);	
	}
	
	void motorTurn(float speed)//Positive is right; Negative is left
	{
		frontRight.Set(-speed);
		frontLeft.Set(-speed);
		backLeft.Set(-speed);
		backRight.Set(-speed);
	}
can be written like this:
Code:
        void motorDrive(float speed) {
                drive.Arcade(speed, 0.0);  // for forward speed and 0 turn
        }

        void motorTurn(float speed) {
                drive.Arcade(0.0, speed); // for 0 forward speed and "speed" turn
        }
and for OperatorControl, the RobotDrive object helps again by letting you do this:
Code:
                drive.Arcade(driveStick); // it automatically does the arcade driving stuff
and the last piece for driving straight using the gyro can be done using proportional control. That is taking the gyro heading and mapping it to a turn rate. If the heading goes negative, you turn one way, and if it goes positive, you turn the other way. So you can do something like this:
Code:
void gyroDrive(float speed, float time) {
	timer.Reset();
	timer.Start();
	while( timer.Get() < time)
	{
              // in this example kP is a constant that maps the gyro headings
              // into turn rates. The greater the deviation from 0 degrees 
              // (straight) the faster the turn. the turn rates range from
              // -1 to 1 and the gyro headings are in degrees so they
              // need to be scaled.
	      drive.Arcade(speed, gyro.GetAngle() * kP);
	}
}
Producing turn rates that are proportional to the amount the robot is off of the 0 degree heading. Be careful that the correction is going in the right direction, that is kP will certainly be between 0 and 1 to scale down the headings but it might also be negative if the turns that need to be made are opposite the gyro angles.

If you look here: http://wpilib.screenstepslive.com/s/...-robot-project it shows some of these concepts.

Hope this helps.

Brad
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute
Reply With Quote