Positioning the AC servo from 0 to 360 degrees to return to the shortest path

Viewed 40

I am doing absolute positioning using AC servo.I calculated how many steps of pulse are needed for a full rotation of the servo and converted it to degrees between 0-360. For the current situation. For example, if the motor is in the zero position, if I give a position in the CW direction. It goes to that degree in the CW direction. There is no problem here. If the motor is in the 0 position, if I give a negative position, it moves in the CCW direction. If the motor has moved in the CCW (negative position) direction, if I give a positive position, it will return to the position where it went in the negative direction and switch to the positive position.The method I want to create here is to go to the position given between 0 and 360 from the nearest path, regardless of the negative or positive direction of the motor. It is completely similar to the logic of a compass, but it has to take the closest path to the given location.I'm trying a few ways, but I can't calculate the shortest path. I tried to explain a little in the picture below. enter image description here Can anyone help with this?

1 Answers

If X and Y are numbers of degrees from 0 to 360 (measuring clockwise from an origin), then Y−X is the number of degrees to go clockwise from X to get to Y. That may be a positive number or a negative number (or zero), indicating clockwise or counterclockwise. If −180 ≤ Y−X ≤ +180, then it is making a turn of less than half a circle, so use it. Otherwise, if Y−X < −180, use Y−X+360, or, if +180 < Y−X, use Y−X−360.

Related