Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   NavX MXP Continuous Angle to Calculate Derivative (http://www.chiefdelphi.com/forums/showthread.php?t=148388)

Richard100 22-05-2016 13:41

Re: NavX MXP Continuous Angle to Calculate Derivative
 
Quote:

Originally Posted by Ether (Post 1588889)
Look at the Endnote at the bottom of the last page.



The Endnote LV code you reference is functionally equivalent to shortest_angle = (present-previous) - 360*floor(0.5+(present-previous)/360); provided here ...
Quote:

Originally Posted by Ether (Post 1586175)

If your language does not support IEEERemainder, you can use this one-line function instead:
Code:

shortest_angle = (present-previous) - 360*floor(0.5+(present-previous)/360);

Both can be written in LV by building up the function from other primitive programming functions (as you depict in the endnote image).

What I wanted to know was whether LabVIEW has IEEERemainder as a programming function (call it Rem). There is a Mod (%) function (known in LV as Quotient & Remainder), but of course Rem and Mod differ in how they internally round, which is what makes Rem useful here.

Same question as you asked here, only for the LabVIEW language. Equivalent to asking: Can it be done in LabVIEW "... with one line of code".

Any LabVIEW experts know? If not, might this be in the development pipeline?

Richard100 22-05-2016 15:53

Re: NavX MXP Continuous Angle to Calculate Derivative
 
Quote:

Originally Posted by Ether (Post 1588891)
You don't need an accumulator when using a gyro if all you care about is your heading.

Not finding this to be very clear either. We're likely discussing different aspects of the problem.

Quote:

Originally Posted by Ether (Post 1588891)

It's not clear what you're saying here.

Ok. The OP's framing of the problem:

Quote:

Originally Posted by lethc (Post 1586089)
Currently both getAngle() and getYaw() are not continuous, and their ranges are [0, 360] and [-180, 180] respectively, so at the point where the robot crosses the threshold of a range the values jump ~360 degrees ...

Does anyone have any ideas on how I would get a continuous angle heading ...?

Proposed solution:

Quote:

Originally Posted by Ether (Post 1586175)
what you want is the shortest angle from the previous reading to the present reading, with the correct sign. The IEEERemainder function1 does this with one line of code:
Code:

shortest_angle = IEEERemainder(present-previous,360);
C# and Java both support IEEERemainder.


If your language does not support IEEERemainder, you can use this one-line function instead:
Code:

shortest_angle = (present-previous) - 360*floor(0.5+(present-previous)/360);

Proposed solution amendment:

Quote:

Originally Posted by Richard100 (Post 1588888)
Note that if one is streaming readings from an angular position sensor (such as a gyro or IMU), one would need to add an accumulator to this shortest_angle function to continually maintain angular position.

If the OP streamed a series of sensor readings, range constrained as [0,360], into a function

Code:

shortest_angle = (present-previous) - 360*floor(0.5+(present-previous)/360)
the resulting output would need to be accumulated to maintain position. Say robot yaw initializes at 0 degrees, moves clockwise over time to 15 degrees, then counter-clockwise to 350 degrees, as reported by the range constrained sensor. Consider:

Code:

Iteration      Previous        Present        Pres-Prev      Function      Accum
1                0                0                0              0              0
2                0              5                5              5              5
3                5                10                5                5              10
4                10                15                5                5              15
5                15                10              -5              -5              10
6                10                350                340              -20              -10

Rather than using what the OP started with, a Present value exhibiting the range-constrained discontinuity, it sounds like the OP needs the accumulated function result.

I'm interpreting the OPs desire for a function that converts his range-constrained sensor output to a non-range-constrained one. Your IEEERemainder function, with an accumulator, accomplishes this.

Ether 22-05-2016 16:35

Re: NavX MXP Continuous Angle to Calculate Derivative
 
Quote:

Originally Posted by Richard100 (Post 1589003)
Not finding this to be very clear either. We're likely discussing different aspects of the problem.


I am discussing the solution to this aspect of the OP's original framing of the problem (see bolded portion):
Quote:

Originally Posted by lethc (Post 1586089)
Does anyone have any ideas on how I would get a continuous angle heading from the NavX? I.E. one that doesn't jump from 360 to 0 instantly, because that messes up the derivative calculation

You don't need a continuous angle to do a simple difference calculation (which is what I anticipated the OP was really wanting).

The IEEERemainder gives you that answer:

Quote:

Originally Posted by Ether (Post 1586175)
what you want is the shortest angle from the previous reading to the present reading, with the correct sign. The IEEERemainder function1 does this with one line of code:
Code:

shortest_angle = IEEERemainder(present-previous,360);

Quote:

Originally Posted by lethc (Post 1586223)
Just tried this out and it works perfectly. Thank you for your help.



Richard100 22-05-2016 19:50

Re: NavX MXP Continuous Angle to Calculate Derivative
 
Thanks for taking time to walk through this! The distinction you reference clears up the differing perspectives / solution space.

Alan Anderson 22-05-2016 20:25

Re: NavX MXP Continuous Angle to Calculate Derivative
 
Quote:

Originally Posted by Richard100 (Post 1588980)
Same question as you asked here, only for the LabVIEW language. Equivalent to asking: Can it be done in LabVIEW "... with one line of code".

Any LabVIEW experts know? If not, might this be in the development pipeline?

You can do a "line of code" in LabVIEW by putting it in a Formula Node. It's exactly like writing an expression in C.

tr6scott 12-06-2016 12:29

Re: NavX MXP Continuous Angle to Calculate Derivative
 
2 Attachment(s)
Labview Subvi implementation of this attached.
Tested with the data set published, and checked results.
Sorry, not a LV guru, so did not take the time create input matrix and results.
(started too, but I knew there was a much simpler way than the way I was doing it.)

Thanks, we struggled with the gyro rollover in the past and this implementation seems to solve all of the issues we have tried to conditionally fix in the past.

Thanks Ether.


All times are GMT -5. The time now is 00:46.

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