Go to Post I have a pair of lucky safety glasses too. When I wear them I never get stuff in my eye. I swear.... - vivek16 [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 Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 08-02-2015, 17:32
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,544
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: remainder function

Quote:
Originally Posted by Ether View Post
Joe, is the MathUtils.IEEEremainder() method available in 2015 FRC Java, now that the runtime engine has changed? If so, does it produce the exact same results?


It's in Math, rather then the squawk MathUtils workaround, but it still works.

Code:
x: 179.0 rem y: 360 result: 179.0
x: 180.0 rem y: 360 result: 180.0
x: 181.0 rem y: 360 result: -179.0
x: 359.0 rem y: 360 result: -1.0
x: 721.0 rem y: 360 result: 1.0
x: -1.0 rem y: 360 result: -1.0
x: -179.0 rem y: 360 result: -179.0
x: -180.0 rem y: 360 result: -180.0
x: -359.0 rem y: 360 result: 1.0
x: -361.0 rem y: 360 result: -1.0
x: -721.0 rem y: 360 result: -1.0
Reply With Quote
  #2   Spotlight this post!  
Unread 08-02-2015, 19:00
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 7,995
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: remainder function

Quote:
Originally Posted by Joe Ross View Post

It's in Math, rather then the squawk MathUtils workaround, but it still works.

Thanks Joe.

For those of you reading this thread for the first time, Math.IEEEremainder(angle,360.0) can be used to convert any angle (in degrees) to the range -180 to 180.

This can be very useful when working with the gyro.

Let's say you want to find the shortest angular error between your joystick direction angle and the gyro angle. This can be accomplished in one clean line of code as follows:

angle_error = Math.IEEEremainder(joystick-gyro,360.0);

There's no need for conditional logic. It cleanly handles all input angle ranges for joystick and gyro, including angles greater than 360 degrees and less than -360 degrees.

The above assumes that gyro and joystick share the same zero and measurement direction.


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 19:09.

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