View Single Post
  #2   Spotlight this post!  
Unread Today, 02:01
mikets's Avatar
mikets mikets is online now
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 681
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Can I use gyro to drive straight in teleop period?

It would be very helpful with encoders but it is possible to do it without. Consider the differential of the two tank sticks is directly proportional to the turning rate of the robot. The bigger the difference, the faster the robot should turn. And the turning rate of the robot is the raw output of the gyro (rotational velocity). So in theory, you can do this:
Code:
double drivePower = (leftStick + rightStick)/2.0;
double stickDifferential = leftStick - rightStick;
double motorDifferential = Kp*(stickDifferential - gyro.getScaledRotationRate());
leftMotor.set(drivePower + motorDifferential);
rightMotor.set(drivePower - motorDifferential);
Note: this is pseudocode, not real code. It is intending to demonstrate the concept. If stickDifferential is zero, that means you want to go straight. If the gyro rotation rate is zero, that means your robot is going straight. Then motorDifferential is zero. If stickDifferential is zero but the robot is turning left, then gyro rotation rate is negative, then motorDifferential will be a positive number. Then the left motor will get more power than the right thus correcting the left drift. Does that make sense?
__________________

Last edited by mikets : Today at 02:54.
Reply With Quote