@Bob_Schor wrote:

You are confounding "position" and what I will call "pseudo-velocity". Position, as you have defined it with your circular disk label 360, 10, 20, ... 340, 350 (going clockwise) are the __only__ possible "positions" (well, there's an ambiguity, as Position 0 = Position 360 -- another way to define "Position" is "Angle clockwise from straight up mod 360", so one complete clockwise revolution = 360° = 0° (because 360 mod 360 = 0). Let's define "Rotate CW from X by Y" as (X + Y) mod 360, and "Rotate CCW from X by Y" as (X - Y) mod 360. So if you start at 10 and rotate CCW by 50, you get to (10 - 50) mod 360 = 320. __You can (by definition) never get to a negative position__ because Position is always 0 .. 360.

So take any two positions, A and B. Start at A and make a single Rotation (of some amount) to get to B. If you are going Clockwise, you need to move by Ycw such that B = A + Ycw, or Ycw = (B - A) mod 360, and if CCW, B = A - Yccw, or Yccw = (A - B) mod 360. Choose the direction that has the smaller value (they'll both be non-negative, of course).

Example -- you are at 15, and want to go to 50. Ycw = (50 - 15) mod 360 = 35. Yccw = (15 - 50) mod 360 = 325. Go CW (because 35 < 325). [Notice that Ycw + Yccw will always be 0 mod 360].

Another example -- you are at 15, and want to go to 350. Ycw = (350 - 15) mod 360 = 335. Yccw = (15 - 350) mod 360 = 25. Go CCW (because 25 < 335).

Bob Schor

I have to say it again

- I will enter values between 0-360 from numerical control. However, negative degrees can be sent to the motor depending on the degree the motor stands.

-Yes, 0=360 degrees. In other words, if we start the motor from 0 and move forward, when I finally reach 360 degrees, the motor comes back to the same place.

Example -- you are at 15, and want to go to 50. Ycw = (50 - 15) mod 360 = 35. Yccw = (15 - 50) mod 360 = 325. Go CW (because 35 < 325). [Notice that Ycw + Yccw will always be 0 mod 360].

- I think there is another misunderstanding.The values that the user will enter from the "numeric control" should actually be between 0-359.99. This is because 0==360.

-if I apply the example of Ycw = (50 - 15) mod 360 = 35.

This means:

I'm CW 10 degrees and I want to go 50 degrees. If I write 35 degrees, the motor goes to 35 degrees. Not 50 degrees.

If I apply the example here. Yccw = (15 - 50) mod 360 = 325

This means:

-The motor is now at 15 degrees CW.

-and I'm sending positive 325 degrees to the motor.

-The motor will have used a long way in the CW direction. And it will reach 325 degrees.