# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## Algorithm that can calculate the shortest path between 0-360 degrees for an AC servo motor.

hello everyone,

This is a difficult algorithm, I must say at first. At least it is for me.
I have an AC servo motor. I calculated one complete revolution of the motor and mapped it between 0-360 degrees.The motor goes to the given position in the -/+ direction.

If I give -/+ values between 0 and 360 degrees to the motor  after mapping, it will act accordingly.
For example:
If I give -20 degrees the Motor will move in CCW direction and go up to 20 degrees.
If I give +20 degrees, the motor goes 20 degrees to the right.
Note: Here it goes to the absolute position of the digit sent.

The situation I want to create and have a problem with is as follows.
No matter how many turns the motor turns, it should go to the real compass position entered between 0-360 degrees and calculate the shortest path with compass logic.

It's just a question of creating algorithms.

Below is an example that is causing the problem I created.

Can anyone help with this?

Any opinion given is worthy of respect.

Message 1 of 67
(1,031 Views)

## Re: Algorithm that can calculate the shortest path between 0-360 degrees for an AC servo motor.

@constructionworker wrote:

For example:
If I give -20 degrees the Motor will move in CCW direction and go up to 20 degrees.
If I give +20 degrees, the motor goes 20 degrees to the right.
Note: Here it goes to the absolute position of the digit sent.

That's quite confusing...

CCW is one direction, to the right the other (CW?). I'd stick with CCW and CW, to the left\right is ambiguous with angles (unless you specify if the bottom or top goes to the left\right).

This calculates the difference between the 2 angles, and gives the shortest dAngle to that position.

Message 2 of 67
(1,025 Views)

## Re: Algorithm that can calculate the shortest path between 0-360 degrees for an AC servo motor.

Yes, let me explain the situation again in some detail, as sticking to the CW and CCW would be a bit more confusing.
This is the AC servo I am currently using. The motor moves with absolute position information.
If I send a 20 degree rotation position pulse to the motor it will rotate 20 degrees in the "CW" direction. And again if I send -10 it will return and after reaching 0 it will turn in CCW direction and it will actually go to -10' which corresponds to 350 degrees.
What I want to create is to write numbers between 0-360 degrees, but it doesn't matter whether - position or + position goes to the motor, what matters is that it goes to real compass degrees.

The example you gave does not meet the situation I described above.
because it sends a positive number again after it passes -179 degrees.If I send 180 degrees to the motor after -170, -179 degrees, the motor will return from the CCW position it went to, and after reaching the 0 position, it will go 180 degrees in the CW direction.

I hope I explained well.

Message 3 of 67
(993 Views)

## Re: Algorithm that can calculate the shortest path between 0-360 degrees for an AC servo motor.

Your example does not make a lot of sense, especially since you are using a greedy loop and only one indicator and one control.

You need a control for the desired new position

You need an indicator (or control when testing) for the current position. (In real life, the current position is given by the hardware)

You need an indicator that shows the +/- angle required to go to the desired position.

I am sure that you can start with Wiebe's example and get it to do what you want with a few tweaks. I am sure you don't need that birds nest of code of your original.

Message 4 of 67
(987 Views)

## Re: Algorithm that can calculate the shortest path between 0-360 degrees for an AC servo motor.

@constructionworker wrote:

Yes, let me explain the situation again in some detail, as sticking to the CW and CCW would be a bit more confusing.
This is the AC servo I am currently using. The motor moves with absolute position information.
If I send a 20 degree rotation position pulse to the motor it will rotate 20 degrees in the "CW" direction. And again if I send -10 it will return and after reaching 0 it will turn in CCW direction and it will actually go to -10' which corresponds to 350 degrees.
What I want to create is to write numbers between 0-360 degrees, but it doesn't matter whether - position or + position goes to the motor, what matters is that it goes to real compass degrees.

If you just want to convert an angle, + or - to a 0-360 deg. angle, simply do the modulus 360...

Message 5 of 67
(961 Views)

## Re: Algorithm that can calculate the shortest path between 0-360 degrees for an AC servo motor.

@constructionworker wrote:

Yes, let me explain the situation again in some detail, as sticking to the CW and CCW would be a bit more confusing.
This is the AC servo I am currently using. The motor moves with absolute position information.
If I send a 20 degree rotation position pulse to the motor it will rotate 20 degrees in the "CW" direction. And again if I send -10 it will return and after reaching 0 it will turn in CCW direction and it will actually go to -10' which corresponds to 350 degrees.
What I want to create is to write numbers between 0-360 degrees, but it doesn't matter whether - position or + position goes to the motor, what matters is that it goes to real compass degrees.

The example you gave does not meet the situation I described above.
because it sends a positive number again after it passes -179 degrees.If I send 180 degrees to the motor after -170, -179 degrees, the motor will return from the CCW position it went to, and after reaching the 0 position, it will go 180 degrees in the CW direction.

I hope I explained well.

Maybe this is what you are looking for, give it a try . Thanks to  for most of the code.

______________________________________________________________
Have a pleasant day and be sure to learn Python for success and prosperity.
Message 6 of 67
(938 Views)