LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Simple Angle Conversion

Solved!
Go to solution

I cannot think this morning... what I need is super simple I feel like, but I can't figure out an easy way to implement it. Please halp.

 

 

Inputs: angles c and d:
current angle = c
desired angle = d

Output: angle z that is closest angle to c but is also in the set {d, d+-360, d+-720, ...}

 

examples:

c=0
d=270
z=-90


c=765
d=0
z=720

 

c=-361

d=-1

z=-361

 

c=0

d=3,602

z=2

Redhawk
Test Engineer at Moog Inc.

Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.

0 Kudos
Message 1 of 13
(1,886 Views)

Hi Andrew,

 


@FireFist-Redhawk wrote:

inputs: angles c and d:
current angle=c
desired angle = d

output: angle z that is closest angle
examples:

c=765
d=0
z=720


Please explain this example!

Why should z be 720° when c=765° (=720°+45°) and d=0°???

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 13
(1,867 Views)

Hi GerdW,

 

I'm not sure I understand you're query. If my current angle shows 765, and I want to go to 0 (same place for me as +-360,+-720), then z is 720 because its the member of that set whose value is closest to my current angle, 765.

Redhawk
Test Engineer at Moog Inc.

Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.

0 Kudos
Message 3 of 13
(1,859 Views)

That description was initially a comment label in LV, I went back and cleaned it up to possibly get rid of the confusion, and added a couple more examples.

Redhawk
Test Engineer at Moog Inc.

Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.

0 Kudos
Message 4 of 13
(1,853 Views)

I think this does everything you need.

 

The idea here is to find the differences and keep that difference in a shift register.  Add (or subtract) 360 until the absolute value of the difference is greater.  The previous value is therefore the closest value.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 5 of 13
(1,846 Views)

Can you explain it graphically instead?

0 Kudos
Message 6 of 13
(1,843 Views)

Hi Andrew,

 

please explain this one:

 

c=0
d=3,602
z=2

Edit:

I think I get this one - decimal separator confusion. I'm used to commas instead of points…

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 13
(1,835 Views)
Solution
Accepted by topic author FireFist-Redhawk

Let's say

 

e=(c-d)

 

and z'=(z-d)

 

then, you are looking for a z' in {..., -720, 360, 0, 360, 720,...} for which the difference to e is minimal.

 

Dividing e by 360 using the quotient & remainder VI gives a quotient which, multiplied with 360 again, is the next lower multible of 360 to e. If the remainder is >180, add 360 to get the nearest value. This is z'. Add d to get z.

 

In LabVIEW:

 

cd.png

 

 

 

EDIT:


c=0

d=3,602

z=2


 

z must be in {..., d-360, d, d+360,...}, so it must be d=3,602 to be next to c....

Message 8 of 13
(1,818 Views)

@crossrulz wrote:

I think this does everything you need.


That's very dangerous code because it will run forever if any of the inputs is NaN. 😮 Maybe you want to reverse some logic so it stops on FALSE instead.

 

(I am pretty sure there is a loop-free solution ;))

0 Kudos
Message 9 of 13
(1,810 Views)

@altenbach wrote:

Can you explain it graphically instead?


I think we all have the idea at this point but it took me a few mins to make, so may as well post.

 

FireFist-Redhawk_0-1594918933172.png

 

 

Redhawk
Test Engineer at Moog Inc.

Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.

0 Kudos
Message 10 of 13
(1,760 Views)