Gyro for driving straight

Can somebody please provide me with a basic example of how to use a gyro with tank drive to drive straight for a defined encoder distance during autonomous.

Examples will be easier to provide if you let us know what language you are coding in.

The basic approach it to add the gyro provided angle, time some gain factor, to one side of the drive and subtract it from the other.

Psuedo code:

L = L+(Gyro*gain1)
R = R-(Gyro*gain1)

Gain1 is adjusted high enought to correct drift, but low enough to prevent oscillation.

No disrespect but this is the NI LabView forum so I would assume the OP would like a LabView example.

It’s a lot easier to do with Arcade Drive.

Reset the encoder and the gyro before you start moving. Use the gyro angle (multiplied by an empirically determined gain value) as the X axis “turn” input. Put the Gyro Get and the Arcade Drive blocks in a while loop that terminates when the encoder reaches the desired value.

We have a gyro on our robot and we mainly use it for auto. We had it do what you wanted, granted it is a mecanum drive but we found it actually slowed us down a lot. I’m not our programmer so i can’t help with the program, but i would think about what you really want it for so you don’t waste your time. Just my advice. They are wonderful for the right situation. Ours wasn’t, but yours might be.

No disrespect taken.

I have seen a LOT of posts in incorrect forums and did not want to assume, thus the request.

Try searching for 1986 Team Titanium’s 2013 Code here on CD. Their 2013 autonomous is a great example of exactly what you’re wanting here (and it worked every time).

The “gain” other posters are talking about is calculated with PID and it takes some fine tuning. Tank drive would take a lot more math and headache to get right and you wouldn’t have as much control over the turn. Like Alan said, I’d stick with Arcade for this Autonomous if I were you.

EDIT: this is one example of what you’re looking for

Hello,

If I simply wanted to turn right 60 degrees in autonomous, could I put the arcade drive vi in a while loop and tell it to turn right until the Get Angle vi >= 60?

The idea is to drive for a time, turn 60 degrees to the right, drive some more, and shoot. I wanted to use a flat sequence structure (film strip) with a while loop in the frame that does the 60 degree turn. Would this work?

Thanks!

PS: We don’t have encoders.

If I simply wanted to turn right 60 degrees in autonomous, could I put the arcade drive vi in a while loop and tell it to turn right until the Get Angle vi >= 60?

To follow up on this - yes, it does seem to work. I’m not sure if it is the absolute *best * way to do this but it does work. I am using a test bed right now, so I assume the angle will have to be tuned to a little less than the desired 60 degrees to account for robot momentum.