Go to Post This web site is a service by our team to the FIRST Community to foster interest and growth in Engineering, the FIRST Competition and Education of youth for the careers of tomorrow. - Mike Martus [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 03-08-2016, 09:38 AM
sagrossm sagrossm is offline
Registered User
AKA: Sam
FRC #5712 (Hemlock's Gray Matter)
Team Role: Mentor
 
Join Date: Feb 2016
Rookie Year: 2016
Location: Hemlock, MI
Posts: 13
sagrossm is a name known to allsagrossm is a name known to allsagrossm is a name known to allsagrossm is a name known to allsagrossm is a name known to allsagrossm is a name known to all
navX MXP without PID control

Is it possible to use gyro with navX to rotate to a certain angle without using PID control?
Reply With Quote
  #2   Spotlight this post!  
Unread 03-08-2016, 09:51 AM
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 7,997
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: navX MXP without PID control

Quote:
Originally Posted by sagrossm View Post
Is it possible to use gyro with navX to rotate to a certain angle without using PID control?
Sure. You can use any form of closed-loop control that you like. It doesn't have to be PID.


Reply With Quote
  #3   Spotlight this post!  
Unread 03-08-2016, 09:54 AM
samfruth's Avatar
samfruth samfruth is offline
Registered User
FRC #1710 (Ravonics Revolution)
Team Role: Driver
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Olathe, Kansas
Posts: 132
samfruth will become famous soon enough
Re: navX MXP without PID control

Yes. And IMO PID isn't actually the best option when rotating to an angle. PID is good for maintaining something like flow rate or temperature over time. What we have done in the past is take the error (or difference between current yaw and desired yaw) and feed that number through as our motor power after it has been either divided or multiplied by some number to make it be in range of 1 to -1 as the motors only operate on those values. Its definitely rudimentary but it gets the job done with some tweaking.
__________________



I kind of know programming
Reply With Quote
  #4   Spotlight this post!  
Unread 03-08-2016, 10:12 AM
sagrossm sagrossm is offline
Registered User
AKA: Sam
FRC #5712 (Hemlock's Gray Matter)
Team Role: Mentor
 
Join Date: Feb 2016
Rookie Year: 2016
Location: Hemlock, MI
Posts: 13
sagrossm is a name known to allsagrossm is a name known to allsagrossm is a name known to allsagrossm is a name known to allsagrossm is a name known to allsagrossm is a name known to all
Re: navX MXP without PID control

Ok, we've been trying to implement it and it's just been really inconsistent (usually turning too far). Looked online for help and I can only find examples with PID, that's why I made that assumption. So is there anything I can do to make it more accurate and reduce error? This is a button that we have:

if((driveStick.getRawButton(12) == true)) {

if(gyro.getYaw() > -140){
leftFront.set(0.3);
leftRear.set(0.3);
rightFront(-0.3);
rightRear.set(-0.3);
}

else if(gyro.getYaw() <= -140){
leftFront.set(0.0);
leftRear.set(0.0);
rightFront(0.0);
rightRear.set(0.0);
}
}
Reply With Quote
  #5   Spotlight this post!  
Unread 03-08-2016, 10:14 AM
sagrossm sagrossm is offline
Registered User
AKA: Sam
FRC #5712 (Hemlock's Gray Matter)
Team Role: Mentor
 
Join Date: Feb 2016
Rookie Year: 2016
Location: Hemlock, MI
Posts: 13
sagrossm is a name known to allsagrossm is a name known to allsagrossm is a name known to allsagrossm is a name known to allsagrossm is a name known to allsagrossm is a name known to all
Re: navX MXP without PID control

samfruth, what you said makes sense I'll try something like that.
Reply With Quote
  #6   Spotlight this post!  
Unread 03-08-2016, 10:17 AM
Jefferson Jefferson is offline
Registered User
AKA: Jeff Clements
FRC #0016 (Bomb Squad)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Mountain Home, AR
Posts: 257
Jefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant future
Re: navX MXP without PID control

Quote:
Originally Posted by samfruth View Post
Yes. And IMO PID isn't actually the best option when rotating to an angle. PID is good for maintaining something like flow rate or temperature over time. What we have done in the past is take the error (or difference between current yaw and desired yaw) and feed that number through as our motor power after it has been either divided or multiplied by some number to make it be in range of 1 to -1 as the motors only operate on those values. Its definitely rudimentary but it gets the job done with some tweaking.
Can you explain how what you're doing is different than just proportional control, i.e. I, D, and F gains are zero.
Reply With Quote
  #7   Spotlight this post!  
Unread 03-08-2016, 10:26 AM
Jefferson Jefferson is offline
Registered User
AKA: Jeff Clements
FRC #0016 (Bomb Squad)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Mountain Home, AR
Posts: 257
Jefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant future
Re: navX MXP without PID control

Quote:
Originally Posted by sagrossm View Post
Ok, we've been trying to implement it and it's just been really inconsistent (usually turning too far). Looked online for help and I can only find examples with PID, that's why I made that assumption. So is there anything I can do to make it more accurate and reduce error? This is a button that we have:

if((driveStick.getRawButton(12) == true)) {

if(gyro.getYaw() > -140){
leftFront.set(0.3);
leftRear.set(0.3);
rightFront(-0.3);
rightRear.set(-0.3);
}

else if(gyro.getYaw() <= -140){
leftFront.set(0.0);
leftRear.set(0.0);
rightFront(0.0);
rightRear.set(0.0);
}
}
I've not had good luck with very basic control methods like you've described, usually because of overshoot. I've found the D parameter to be necessary to slow the rotation as your robot picks up rotational speed during the turn.
Is there a reason you don't want to use PID? The WPILib PIDController is very capable and pretty easy to use.
Reply With Quote
  #8   Spotlight this post!  
Unread 03-08-2016, 12:14 PM
samfruth's Avatar
samfruth samfruth is offline
Registered User
FRC #1710 (Ravonics Revolution)
Team Role: Driver
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Olathe, Kansas
Posts: 132
samfruth will become famous soon enough
Re: navX MXP without PID control

Quote:
Originally Posted by Jefferson View Post
Can you explain how what you're doing is different than just proportional control, i.e. I, D, and F gains are zero.
That is exactly what it is.
__________________



I kind of know programming
Reply With Quote
  #9   Spotlight this post!  
Unread 03-08-2016, 12:55 PM
dougwilliams's Avatar
dougwilliams dougwilliams is offline
Engineer - Controls, Electronics
FRC #2053 (TigerTronics)
Team Role: Mentor
 
Join Date: May 2013
Rookie Year: 2013
Location: Vestal, NY
Posts: 109
dougwilliams is on a distinguished road
Re: navX MXP without PID control

Quote:
Originally Posted by sagrossm View Post
Ok, we've been trying to implement it and it's just been really inconsistent (usually turning too far). Looked online for help and I can only find examples with PID, that's why I made that assumption. So is there anything I can do to make it more accurate and reduce error? This is a button that we have:

if((driveStick.getRawButton(12) == true)) {

if(gyro.getYaw() > -140){
leftFront.set(0.3);
leftRear.set(0.3);
rightFront(-0.3);
rightRear.set(-0.3);
}

else if(gyro.getYaw() <= -140){
leftFront.set(0.0);
leftRear.set(0.0);
rightFront(0.0);
rightRear.set(0.0);
}
}


We take an easy piecewise linear approach when rotating to angle using the NavX yaw as the input. We had a lot of overshoot with pure proportional, so we set angle limits similar to what you are doing and set a speed. If it needs to rotate more than 90 degrees it can be set to rotate at full speed. When it has 45 degrees left to rotate it needs to be scaled down to .4 speed. Once you are within 20 degrees the rotational speed needs to be scaled down to only .2. There is a lot of robot inertia in the spin - and that needs to be accounted for. (All those numbers are made up, but the idea is roughly what we implement).

This way was an easier first step rather than explaining a full PID loop and how to implement that in software. Most students are able to read the code and understand what it's doing.



Also - looking at your code - do the angles work in that scenario? What angle are you trying to rotate to? Maybe to zero - but then when you are less than -140 degrees it stops. That seems backwards to me.

And I think in the NavX 180 and -180 are the same position, and you need t account for that in your math.
Reply With Quote
  #10   Spotlight this post!  
Unread 03-08-2016, 01:33 PM
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 7,997
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: navX MXP without PID control

Quote:
Originally Posted by dougwilliams View Post
We take an easy piecewise linear approach ... If it needs to rotate more than 90 degrees it can be set to rotate at full speed. When it has 45 degrees left to rotate it needs to be scaled down to .4 speed. Once you are within 20 degrees the rotational speed needs to be scaled down to only .2
Yes an approach like that can be quite effective in many situations.

Quote:
Also - looking at your code - do the angles work in that scenario? What angle are you trying to rotate to? Maybe to zero - but then when you are less than -140 degrees it stops. That seems backwards to me.

And I think in the NavX 180 and -180 are the same position, and you need t account for that in your math.
The gyro_reading and your desired_angle need to share the same zero position, and rotation direction. Given that, it's simple to compute the shortest angle to your destination:

Code:
angle_error = desired_angle - gyro_reading;
shortest_angle = angle_error - 360*floor(0.5+angle_error/360);
If your compiler supports the REMAINDER function "x REM y" per IEC 60559 as specified on Page 235 Section 7.12.10.2 of ISO/IEC 9899:TC3 (which java does I believe), then the following single line of code should work:

Code:
shortest_angle = Math.IEEEremainder(desired_angle-gyro_reading,360.0);
The above works regardless of the range of either the desired_angle or the gyro_reading (as long as they share the same zero and rotation direction, as mentioned above).

So for example if your desired_angle is -3 degrees and the gyro is reading 359 degrees, the shortest angle will be -2 degrees.





Last edited by Ether : 03-08-2016 at 01:48 PM.
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 07:54 AM.

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