|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Re: NavX MXP Continuous Angle to Calculate Derivative
Quote:
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. Also be aware that the function is sensitive to sampling rate. This is because a late sample might allow a current position (the 'present' variable) to get more than 180 degrees away the previous position (the 'previous' variable). If this happens then the shortest angle will switch to the other side of the cycle. If you've ever noticed movies where wagon or car wheels appear to be moving backwards then you've seen this aliasing effect (this can happen to your sensor, too). To avoid this, ensure the iteration period is at least shorter than (1 / 2*RPS), where RPS is the maximum revolutions per second expected from the sensor reading stream. For example, if your robot maximum yaw rotation rate is 1000 deg/sec, you must iterate the function no slower than every 180 ms ... (someone check my math). This is likely not a problem for most FRC robots, as yaw rates don't normally get that high (ours don't get much higher than 500 deg/sec), and computational iteration rates are probably much faster - but one should be aware of the constraint. You might try the function on a robot mechanism that rotates much faster and wonder why your code is suddenly unreliable. If the sensor readings are noisy, this will further erode the sampling margin. If the peak noise level in degrees is 'n', then the sampling constraint becomes: Loop Period < (180 - 2*n)/(360 * RPS) Of course, excessive noise should be remedied (fixing the root cause). One should just keep in mind that it's good practice to maintain healthy margin for practical issues like noise, and in fact whether your loop can always be trusted to occur on schedule. The exploit of the shortest directional path property of the IEEERemainder function is quite clever for dealing with these orientation discontinuities. I wasn't aware of it until Ether pointed it out - (thank you Ether). It doesn't appear that LabVIEW has this function (although easy enough to build from primitives) ... unless I'm just not finding it - anyone know for sure? |
|
#2
|
||||
|
||||
|
Re: NavX MXP Continuous Angle to Calculate Derivative
Quote:
|
|
#3
|
|||
|
|||
|
Re: NavX MXP Continuous Angle to Calculate Derivative
Quote:
Quote:
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? |
|
#4
|
||||
|
||||
|
Re: NavX MXP Continuous Angle to Calculate Derivative
Quote:
You don't need an accumulator when using a gyro if all you care about is your heading. The desired heading and the gyro angle do not have a range constraint in this case. For example, the gyro angle could be 721 degrees and the desired heading could be -1 degree. The function would return -2 degrees as the shortest angle, which is the value you want. |
|
#5
|
||||
|
||||
|
Re: NavX MXP Continuous Angle to Calculate Derivative
Quote:
Ok. The OP's framing of the problem: Quote:
Quote:
Quote:
Code:
shortest_angle = (present-previous) - 360*floor(0.5+(present-previous)/360) 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 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. |
|
#6
|
||||
|
||||
|
Re: NavX MXP Continuous Angle to Calculate Derivative
Quote:
I am discussing the solution to this aspect of the OP's original framing of the problem (see bolded portion): Quote:
The IEEERemainder gives you that answer: Quote:
Quote:
|
|
#7
|
|||
|
|||
|
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.
|
|
#8
|
|||||
|
|||||
|
Re: NavX MXP Continuous Angle to Calculate Derivative
Quote:
|
|
#9
|
||||
|
||||
|
Re: NavX MXP Continuous Angle to Calculate Derivative
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. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|