LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

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

Solved!
Go to solution

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.

0 Kudos
Message 1 of 67
(508 Views)

@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.

 

Motor direction.png

0 Kudos
Message 2 of 67
(502 Views)

Thanks for your reply  


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.

0 Kudos
Message 3 of 67
(470 Views)

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.

Your loop needs a wait.

 

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.

 

 

 

0 Kudos
Message 4 of 67
(464 Views)

@constructionworker wrote:

Thanks for your reply  


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...

0 Kudos
Message 5 of 67
(438 Views)

@constructionworker wrote:

Thanks for your reply  


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. 

snip.png

 

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

wiebe@CARYA wrote:

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

Careful there. The difference can be anywhere between -359 and +359.

 


 

0 Kudos
Message 7 of 67
(410 Views)

 


@altenbach wrote:

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.

Your loop needs a wait.

 

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.

 

 

 


Thanks for everyone's reply.
Actually, I'm sure there is no need for this bird's nest, but I have tried every possible way. I probably tried 200 algorithm methods, but I couldn't get exactly what I wanted 🙂

 

 Jay14159265

I have examined and tested the example you have created here, but here it sends the engine how far it needs to move from the normal position. What is required is absolute position information to the engine.
This is what I tried to explain above. So if I send -350 to the motor, the motor goes to -350 degrees in the CCW direction and stops. The motor is doing absolute positioning.

 

constructionworker_0-1663706180247.png

The main problem here is not the difference, I need to send the location directly.

 

I've been testing it thoroughly but couldn't find a way. That's why I can't answer very quickly.

0 Kudos
Message 8 of 67
(379 Views)

As wiebe already answered back in msg #5, the modulus function can be used to map any positive or negative value into your desired compass degree range [0,360).  

 

Kevin_Price_0-1663712223150.png

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW?

(Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).



0 Kudos
Message 9 of 67
(356 Views)

@constructionworker wrote:

 Jay14159265

I have examined and tested the example you have created here, but here it sends the engine how far it needs to move from the normal position. What is required is absolute position information to the engine.
This is what I tried to explain above. So if I send -350 to the motor, the motor goes to -350 degrees in the CCW direction and stops. The motor is doing absolute positioning.

 

 


So now I am confused, if the servo is at 0deg and you want it to go to 270deg do you send it 270 or -90, or something else? 

______________________________________________________________
Have a pleasant day and be sure to learn Python for success and prosperity.
0 Kudos
Message 10 of 67
(348 Views)