![]() |
Getting Gyro Working w/ Mecanum Drive
Although our season is over, the programming team is still tasked with completing several things before the start of the next season. One of the more difficult things (and something I struggled with implementing) during the build season was using a gyro to help the drivers. This is the code I've come up with so far, but I only included the drive code, nothing else:
Code:
teleopPeriodic(){ |
Re: Getting Gyro Working w/ Mecanum Drive
Quote:
If your goal is to use the gyro to provide a field-centric driver interface, that's already part of the Java WPILib: Code:
... Or if your goal is to make the bot drive straight when the driver is commanding zero rotation, you could do something like this: http://www.chiefdelphi.com/forums/at...4&d=1420598437 ...Or here's an interesting optional (button-press selectable) driver interface mode for mec that your drivers might like: Quote:
|
Re: Getting Gyro Working w/ Mecanum Drive
Quote:
Wait so I can just do RobotMap.robotDrive.mecanumDrive_Cartesian(OI.joys tick0.getX(), OI.joystick0.getY(), OI.joystick0.getZ(), RobotMap.driveGyro.getAngle()); in my teleopPeriodic and it'll do corrections for me? So if I'm driving w/o rotating it'll auto correct for me? |
Re: Getting Gyro Working w/ Mecanum Drive
Quote:
Quote:
If you want the vehicle not to rotate when the driver rotate command is zero, you could do something like this: Quote:
|
Re: Getting Gyro Working w/ Mecanum Drive
Quote:
|
Re: Getting Gyro Working w/ Mecanum Drive
Quote:
Check out some of these links. |
Re: Getting Gyro Working w/ Mecanum Drive
I think I'm confused about what field-centric really is. To my understanding it's positioning based on the layout of the field. Could someone explain this to me?
|
Re: Getting Gyro Working w/ Mecanum Drive
1 Attachment(s)
|
Re: Getting Gyro Working w/ Mecanum Drive
Oh I see. That is not what I'm trying to accomplish. I am trying to get the robot not to rotate when the driver rotate command is zero. How do you accomplish this in Java, not in Labview?
|
Re: Getting Gyro Working w/ Mecanum Drive
Quote:
Quote:
|
Re: Getting Gyro Working w/ Mecanum Drive
Quote:
|
Re: Getting Gyro Working w/ Mecanum Drive
Quote:
|
Re: Getting Gyro Working w/ Mecanum Drive
Quote:
|
Re: Getting Gyro Working w/ Mecanum Drive
I recommend using one of the WPIlib MecanumDrive methods, and just make corrections to the "twist" input when you want to go straight based on the error. Do not use the fourth "gyroscope" input to MecanumDrive_cartesian; this is only used for "field coordinates".
The correction could be a full PID, but because of the amount of friction in a mecanum drive system, you should be able to get away with a simple proportional correction; D will be mechanical, and I is usually not needed when seeking a position. To do this, you will need to create a numeric variable to hold the desired heading, say azi. In your joystick-reading loop:
|
Re: Getting Gyro Working w/ Mecanum Drive
How do I set the robotdrive to the MecanumDrive method?
Quote:
|
Re: Getting Gyro Working w/ Mecanum Drive
Quote:
|
Re: Getting Gyro Working w/ Mecanum Drive
Quote:
Code:
RobotMap.driveRobotDrive41.mecanumDrive_Cartesian(OI.joystick0.getX(), OI.joystick0.getY(), OI.joystick0.getZ(), 0); |
Re: Getting Gyro Working w/ Mecanum Drive
Quote:
Quote:
Quote:
Quote:
|
Re: Getting Gyro Working w/ Mecanum Drive
The code is not particularly well documented, but here's the code we used this year:
https://github.com/CopperBots/Copper...obot.java#L632 We pass in the rotation joystick value that has already been deadband'ed. If the joystick is at zero rotation, we use a proportional controller to keep the robot straight. If the joystick is not at zero, we update the current heading of the robot and pass the joystick value back to the drive system unchanged. We also have the option to disable gyro mode at any time in case something goes wrong like a bad calibration, or a loose cable. There is also an option to update the kP value from the smart dashboard and some diagnostic information sent back to help troubleshoot when things go wrong. |
Re: Getting Gyro Working w/ Mecanum Drive
Well what I'm asking is what do I put in for the fourth parameter, because I have to put something in it.
Quote:
|
Re: Getting Gyro Working w/ Mecanum Drive
Thanks, this helps a BUNCH! The problem is mixing mecanum drive with your code
Quote:
|
Re: Getting Gyro Working w/ Mecanum Drive
Quote:
|
Re: Getting Gyro Working w/ Mecanum Drive
Quote:
Code:
public void mecanumDrive_Cartesian(double x, double y, double rotation, double gyroAngle) {Now look at the WPILib code for rotateVector(): Code:
/** |
Re: Getting Gyro Working w/ Mecanum Drive
Thank you Ether, that helps tons.
Quote:
|
Re: Getting Gyro Working w/ Mecanum Drive
Do you think this will work? (I only included the drive code)
Code:
public void teleopInit(){ |
Re: Getting Gyro Working w/ Mecanum Drive
I believe I have gotten gyro code to work! It is a little tricky while strafing, but for every other use it works great, and it really does help limit the turning while strafing according to our driver. So here you go, FYI: I only included code related to the driving, don't replace whole sections with this code:
Code:
One thing I might try to do in the future is make the correction only read [-180,180] because when we set our heading to 0, we could rotate around 3-4 times and instead of going to the nearest "0" it would rotate back the exact amount. The reason this could help is that if the game is in a year with a goal, you could press a button and the robot would rotate to face the goal exactly, but this wouldn't work if maybe you had spun around several times before. Thanks to: GeeTwo, Ether, and dawonn |
| All times are GMT -5. The time now is 11:13. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi