Quote:
Originally Posted by Ether
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
It's not clear what you're saying here.
|
Ok. The OP's framing of the problem:
Quote:
Originally Posted by lethc
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
what you want is the shortest angle from the previous reading to the present reading, with the correct sign. The IEEERemainder function 1 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
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.