|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
navX MXP without PID control
Is it possible to use gyro with navX to rotate to a certain angle without using PID control?
|
|
#2
|
||||
|
||||
|
Re: navX MXP without PID control
Quote:
|
|
#3
|
||||
|
||||
|
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.
|
|
#4
|
|||
|
|||
|
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); } } |
|
#5
|
|||
|
|||
|
Re: navX MXP without PID control
samfruth, what you said makes sense I'll try something like that.
|
|
#6
|
|||
|
|||
|
Re: navX MXP without PID control
Quote:
|
|
#7
|
|||
|
|||
|
Re: navX MXP without PID control
Quote:
Is there a reason you don't want to use PID? The WPILib PIDController is very capable and pretty easy to use. |
|
#8
|
||||
|
||||
|
Re: navX MXP without PID control
That is exactly what it is.
|
|
#9
|
||||
|
||||
|
Re: navX MXP without PID control
Quote:
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. |
|
#10
|
||||
|
||||
|
Re: navX MXP without PID control
Quote:
Quote:
Code:
angle_error = desired_angle - gyro_reading; shortest_angle = angle_error - 360*floor(0.5+angle_error/360); Code:
shortest_angle = Math.IEEEremainder(desired_angle-gyro_reading,360.0); 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 : 08-03-2016 at 13:48. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|