Start a new topic

0-360 step calculations

 Hello. I am trying to make a gauge to run 0  to 360 degrees in various step width. All i cannot figure out is transition from 0 point to 360 and opposite. Something like this does not work  

 

 

z0.val=po.val
if(po.val<10)
{
  va0.val=10-po.val
  po.val=360-va0.val
}

 I would be happy if someone could explain, what way to do it. Thank you.

 


  • +/- 1 stepwidth 1
  • +/- 2 stepwidth 2
  • +/- 3 stepwidth 3
  • +/- 4 stepwidth 4
  • ...

Say in +1 case it is fine:

 

po.val=po.val+1
if(po.val>=360)
{
  po.val=0
}

 but if say po.val is 355 and step is 10, how to get po.val=5 on next click?

 

class project?

No. I am trying to make controls for rotary table with stepper motor.

 


va0.val = po.val + step    //step can be positive or negative
while(va0.val<0)
{
va0.val=va0.val+360
}
while(va0.val>0)
{
va0.val=va0.val-360
}
po.val=va0.val

 

Not working. "Parse: Assingnment operation failed." Seen that few times today. :(

 

Did you create a variable va0 ?

Did you replace "step" by a numeric value?


Symbolic code is not for copy and paste, it's for giving an idea how things can work if correctly implemented and should serve as a base for your own code.


Thus, the first line (va0.val = po.val + step) would have to be written (spaces are not allowed) like: va0.val=po.val+step

 I have tried on a clean template.

HMI
(8.81 KB)

Okay.  One has to be observant on this one.


Gauge has a range of ... 0 to 360 ... it goes around in a circle. 

There is no 361, 362, or 363 degrees.

There is no -1, -2, -3 degrees

Really, there shouldn't be a 360 degrees - but there is.


So your right side evaluation needs to be made with a variable independent of the gauge in FULL before being assigned to z0.val

Otherwise when you try to assign z0 a -1 it is invalid - hence Parse: Assignment operation failed.

 Regardless if you would like to correct this in a subsequent operation.


SOLUTION:


Variable Component .objname step

Timer Component .objname tm0 .tim 50 .en 1

Gauge Component .objname z0


Timer Event code

 

sys0+=step.val
if(sys0<0)
{
  sys0+=360
}else
{
  sys0%=360
}
z0.val=sys0

 

Set step.val to whatever step width desired

 negative for CCW rotation, positive CW rotation, zero No rotation

page
(2.29 KB)
Thank you, this works. Can you please explain, what is difference in using sys instead of variable?

 

 

va0.val+=step.val
if(va0.val<0)
{
  va0.val+=360
}else
{
  va0.val%=360
}
z0.val=va0.val

 

Difference is if I have to create a Variable Component named va0 or not.