Go to Post ...trapping Chuck Norris is worth infinity, Dave, Dean, and Woodie are 500 apiece, and trapping Andy Baker is worth double infinity - EricH [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rating: Thread Rating: 13 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 08-02-2015, 10:13
SteveS's Avatar
SteveS SteveS is offline
Registered User
FRC #2594
 
Join Date: Jan 2015
Rookie Year: 2007
Location: Idaho
Posts: 5
SteveS is an unknown quantity at this point
WPILib Mecanum Drive, PID and drift

This is the first year that we are using C++ and also the first year for a mecanum drive. For ease of learning we are using the WPILib RobotDrive::Mecanum_Cartesian() with the gyro input. We have done pretty good reducing the drift of the gyro. However, when we try to drive straight forward, our robot drifts to the right. Mechanical has done quite a bit of work on the gear boxes and swapped motors and controllers, and the problem persists.

The thought has been to add a PID loop to lock on the angle, but we can not find a way to do this with the WPILib. I also can not find the source code for the library to see if this is possible, or even a really good description of how the code is actually supposed to work. We just don't have the time at this point to write our own mecanum routines.

Has anyone ran into this problem and found any solutions? Also, does anyone know if the WPILib source code is available?
Reply With Quote
  #2   Spotlight this post!  
Unread 08-02-2015, 10:43
RufflesRidge RufflesRidge is offline
Registered User
no team
 
Join Date: Jan 2012
Location: USA
Posts: 987
RufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant future
Re: WPILib Mecanum Drive, PID and drift

Source code can be found here (see the note on the project home page): https://usfirst.collab.net/sf/projects/wpilib/

One, often used, way of implementing a rotation PID using a gyro is to put it between the joystick and the rotation input of the RobotDrive mecanum method. Use the joystick to command changes in the angular setpoint and use the output of the PID as the rotation input of the mecanum drive method.
Reply With Quote
  #3   Spotlight this post!  
Unread 08-02-2015, 10:49
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,015
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: WPILib Mecanum Drive, PID and drift

Quote:
Originally Posted by SteveS View Post
when we try to drive straight forward, our robot drifts to the right.
Do you mean like this? or like this? A gyro can be used to correct the second one, but the first one not so much.

Make sure you calibrate your motor controllers so that there is no unintended strafe or rotate command being given when you are trying to drive straight.

Try temporarily zeroing-out the strafe and rotate commands in software so that you can command a truly pure forward command and see if that affects the vehicle behavior. If it does, it may mean you are getting unintended strafe and/or rotate command when you don't want it. If so, you could add deadband, or change the driver interface to separate the commands.


Attached Thumbnails
Click image for larger version

Name:	strafe drift.jpg
Views:	79
Size:	92.1 KB
ID:	18217  Click image for larger version

Name:	rotate drift.jpg
Views:	67
Size:	136.0 KB
ID:	18218  

Last edited by Ether : 08-02-2015 at 10:56.
Reply With Quote
  #4   Spotlight this post!  
Unread 08-02-2015, 10:50
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: WPILib Mecanum Drive, PID and drift

Using Mecanum_Cartesian() with the gyro input is intended to give you field-centric driving. The joystick commands are rotated to reflect the current heading of the robot. What would normally be "straight forward" becomes "down field". If your robot drifts to the right, it means the gyro angle is measuring the robot as facing a little to the left of where it was facing when the gyro was calibrated on powerup.

If you don't want field-centric motion control, don't use the gyro input that way.
Reply With Quote
  #5   Spotlight this post!  
Unread 08-02-2015, 11:51
SteveS's Avatar
SteveS SteveS is offline
Registered User
FRC #2594
 
Join Date: Jan 2015
Rookie Year: 2007
Location: Idaho
Posts: 5
SteveS is an unknown quantity at this point
Re: WPILib Mecanum Drive, PID and drift

Quote:
Originally Posted by RufflesRidge View Post
Source code can be found here (see the note on the project home page): https://usfirst.collab.net/sf/projects/wpilib/

One, often used, way of implementing a rotation PID using a gyro is to put it between the joystick and the rotation input of the RobotDrive mecanum method. Use the joystick to command changes in the angular setpoint and use the output of the PID as the rotation input of the mecanum drive method.

Thank you for the source code link!

As I understand the PIDController class, the output (Joystick class) must have a PIDOutput member or derived from that class. Joystick has neither. How would you implement that?
Reply With Quote
  #6   Spotlight this post!  
Unread 08-02-2015, 18:21
FleventyFive FleventyFive is offline
Registered User
FRC #4118
 
Join Date: Sep 2014
Location: Gainesville, FL
Posts: 23
FleventyFive is on a distinguished road
Re: WPILib Mecanum Drive, PID and drift

Quote:
Originally Posted by SteveS View Post
As I understand the PIDController class, the output (Joystick class) must have a PIDOutput member or derived from that class. Joystick has neither. How would you implement that?
You could use the Gyro as the input for the PID loop, with Motors as the output, and use the Joystick to set the goal (setpoint) of the loop. It is kind of confusing because really each wheel would need its own PID controller, unless you create a PIDsubsystem which allows you to define what you do with the input and outputs.

My team also has drift when strafing and we're trying to correct it with PID loops using encoders as the input, but selecting gains, etc is difficult expecially if you do not have extended periods of time with the robot to test (because other people are working on it).

Last edited by FleventyFive : 08-02-2015 at 18:22. Reason: to sound not like nigerian
Reply With Quote
  #7   Spotlight this post!  
Unread 08-02-2015, 19:09
SteveS's Avatar
SteveS SteveS is offline
Registered User
FRC #2594
 
Join Date: Jan 2015
Rookie Year: 2007
Location: Idaho
Posts: 5
SteveS is an unknown quantity at this point
Re: WPILib Mecanum Drive, PID and drift

Thanks to everyone for the help. We have some things to check out tomorrow.
Reply With Quote
  #8   Spotlight this post!  
Unread 08-02-2015, 19:54
RufflesRidge RufflesRidge is offline
Registered User
no team
 
Join Date: Jan 2012
Location: USA
Posts: 987
RufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant future
Re: WPILib Mecanum Drive, PID and drift

Quote:
Originally Posted by SteveS View Post
As I understand the PIDController class, the output (Joystick class) must have a PIDOutput member or derived from that class. Joystick has neither. How would you implement that?
Create a class implementing PIDOutput that does what you want.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 02:59.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi