Go to Post While [a college FIRST competition] would be pretty fun, I think that you'll see this build season that mentoring is a heck of a lot of fun too. (except when the kids pretend to cut their fingers off to see your reaction) - Beth Sweet [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 08-03-2016, 13:33
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 7,986
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 : 08-03-2016 at 13:48.
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 09:34.

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