![]() |
JAVA code to drive straight using H-drive
We are a second year team and are using 6" omni wheels in an H-drive configuration for the first time. Our robot tends to veer left when we are trying to drive straight ahead during auto and teleop, and I was wondering if anyone would be willing to share any code ideas that would help with this issue. We have a gyro as well, but not sure how to effectively utilize it for this purpose. We have already tried making sure the gear boxes that are attached to CIM motors are as identical as possible.
Go robots! Thank you!! |
Re: JAVA code to drive straight using H-drive
FIRST gave an example on their docs as to how you can accomplish driving straight using a gyro. However, just be wary that gyros don't always work as well as you want it to.
http://wpilib.screenstepslive.com/s/...ving-direction |
Re: JAVA code to drive straight using H-drive
The usual way to ensure you're driving straight is to put encoders on your wheel gearboxes, and get both sides going at the same speed. As long as the wheels don't slip, you can make this work by creating a PID on each axle based on speed, and set the target speed from your joysticks rather than the voltage. If you have time to do this, this is the better solution.
However, you probably don't have time, and you already have a gyroscope. During teleop, you're probably better off letting the driver compensate, unless you really do have a "directly forward" control (which means, among other things, not arcade or tank controls). If you do have a "directly forward", do the same as for autonomous below. Autonomous: First, calibrate the gyroscope to determine the value received when the robot is not rotating. Then, as you're driving forward (or reverse), periodically check the rotation rate. If you are rotating to the left, decrease the right voltage a bit (or increase the left). Likewise, if you are rotating right, decrease the left voltage speed a bit. As you drive, continue the decrease/increase until the rotation rate is the desired value of zero. As noted above, a gyroscope won't pinpoint you in an exact spot, but it may get you close enough so that you can use other sensors (rangefinders, touch sensors, etc) to get exactly where you want to be. BTW, we've lost three analog KoP gyroscopes in the past year, two during this year's build season. If you can't get things working with the gyroscope, try checking it with a voltmeter or reading the values from it directly to verify that the hardware is still working. |
Re: JAVA code to drive straight using H-drive
Thank you for the suggestions! We did put encoders on both gearboxes before we bagged up, but we weren't sure how to use them with PIDs. Any tips on setting the constant values if we try using velocity? Will that work in auto since the robot would not be getting input from a joystick?
I'm a little confused about how to control the voltages independently for each axis because we use arcade drive. Is there another drive class that would work better for this task? We will check the gyro when we unbag - thank you for that tip! |
Re: JAVA code to drive straight using H-drive
Quote:
|
Re: JAVA code to drive straight using H-drive
Quote:
Quote:
|
Re: JAVA code to drive straight using H-drive
Quote:
Quote:
|
Re: JAVA code to drive straight using H-drive
This is our auto drive straight command for our robot this year.
We are using command based programming and java. We used the RobotBuilder "PIDCommand" as a template that we modified to what you see below. It drives forward at a set speed and maintains an angle using values from encoders on each side of the drivetrain. We have removed some parts of the code as they are specific to our robot. Hopefully this is of use to you. Quote:
|
Re: JAVA code to drive straight using H-drive
Quote:
|
Re: JAVA code to drive straight using H-drive
Quote:
|
Re: JAVA code to drive straight using H-drive
Quote:
It was most likely some kind of short, but we have a cover on the gyro as well as a mounting plate, and Cable Magics on all the 3-pin roboRIO ports. |
Re: JAVA code to drive straight using H-drive
@Joe can you share the getDegreesFromEncoderValues method? That is the part we are having trouble with.
Quote:
|
Re: JAVA code to drive straight using H-drive
sure
Quote:
|
Re: JAVA code to drive straight using H-drive
Quote:
|
Re: JAVA code to drive straight using H-drive
Quote:
Code:
double robotArcLength = (leftDistance-rightDistance)/2; |
Re: JAVA code to drive straight using H-drive
Quote:
arc_length=(Left-Right)/2 arc_radius = trackwidth/2 arc_angle = arc_length/arc_radius = arc_length/(trackwidth/2) = 2*arc_length/trackwith convert to degrees: 2*arc_length/trackwith * (180/pi) = 360*arc_length/(trackwidth*pi) |
| All times are GMT -5. The time now is 12:03. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi