I obtain the heading or yaw angle from a source which I am not allowed to modify, but when the angle goes more than +180 or -180, it interchanges either from 180 to -180 or the other way around. Any suggestion on how to overcome this drastic angle changes will be appreciated.

Here is the plot of angle changes over time,

enter image description here

Update after @Chuc comment, Here is what I feel like desired behaviour

enter image description here

  • $\begingroup$ +180 and -180 are both valid heading angles. What problem are you having? If it's a large delta between measured angles at subsequent timesteps, then you may want to add a conditional check to any calculation you're doing. E.g. 179 -> -179 is a difference of 2, not 358. $\endgroup$ – doggie_breath Oct 27 '20 at 13:16
  • $\begingroup$ Welcome to Robotics, GPrathap. It would help if you could explain how this is negatively affecting you and what you would like the alternative to be. If, for example, you want angles to be 0 to 360 instead of -180 to +180 then you'll still wind up with a jump when the angle wraps. If there's a particular (inverse) trig function that's giving you trouble we might be able to recommend an alternative, etc., but as it stands I think the best anyone can say is that you'll always wind up with a jump discontinuity. $\endgroup$ – Chuck Oct 27 '20 at 13:33
  • $\begingroup$ @Chuck thank you for your reply, I send this yaw angle to control a quadcopter; when angle goes from -180 to 180 quadrotor just rotate. I want to avoid this. How actually approach this? $\endgroup$ – GPrathap Oct 27 '20 at 20:00
  • $\begingroup$ @GPrathap - What is the problem you are having with using a -180 to +180 reference? What is the alternative you would like to use? You could easily add 360 to any negative values, but then you have a 0-360 heading instead of a -180 to +180 heading; there's still a discontinuity. Are you using a reference that is also +/- 180? It's hard to give you meaningful help without knowing why specifically the +/- 180 feedback is giving you trouble. $\endgroup$ – Chuck Oct 27 '20 at 20:24
  • $\begingroup$ @Chunk thank you again. I updated assuming that's what I feel like desired yaw angle $\endgroup$ – GPrathap Oct 27 '20 at 20:45

Based on your comment:

if I am able to get 0 to 2pi, would be enough as well.

The following code will do it:

modifiedHeading = SensorOutput();
if(modifiedHeading < 0)
    modifiedHeading += 360f;

But, as I've mentioned previously, you still have the jump discontinuity, but you've moved it from the 359/1 degree range from the 179/-179 degree range.

  • $\begingroup$ Thanks for your help, I tried this as well, seems to be I am trying something not possible :( $\endgroup$ – GPrathap Oct 28 '20 at 18:46
  • $\begingroup$ @GPrathap - I've said it many times now - what are you trying to do? You finally said 0 to 2pi works, and the code I gave above does exactly that. If there's something else you'd like to do then it might also be possible, but you need to be explicit with what you're wanting the output to be. $\endgroup$ – Chuck Oct 28 '20 at 18:57
  • $\begingroup$ Sure, I will check properly and formulate as another question. Thanks for your help $\endgroup$ – GPrathap Oct 28 '20 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.