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

I am still trying to wrap my head around it as your (OP) comments are confusing. Can you give a set of values?

 

Currrent Position(Abs) , Target Position(Abs), Command Position to Servo (Abs)

0, 15, 15

15, .....

 

 

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 11 of 67
(1,231 Views)

See if this can give you some ideas....

 

(Of course you can skip the animation and go directly to the "Move!", but then you won't be able to tell what it does.... 😄 Also note that except for the stop condition, there is nothing green at all!)

 

Try it out....

 

I am using integers because stepper motors typically have discrete steps. While the angles can be floating points, the rest of the calculations should be done in stepper units. You can easily convert based on steps/revolution.

 

 

altenbach_0-1663723251845.png

 

0 Kudos
Message 12 of 67
(1,222 Views)

@Jay14159265 wrote:


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? 

 


If the engine is at 0 position, if I want it to reach 270 degrees according to the compass logic, -90 degrees should be sent because the shortest path is -90 degrees, but if I send (+270) degrees, it will still go to 270 degrees, but it will have come a long way.

 

  wrote:

I am still trying to wrap my head around it as your (OP) comments are confusing. Can you give a set of values?

 

Currrent Position(Abs) , Target Position(Abs), Command Position to Servo (Abs)

0, 15, 15

15, .....


It can move the motor with absolute position in CW or CCW direction. For example, if I send 10, if I write 10 degrees 150 degrees, it goes to 150 degrees using CW direction.

if I type -10 it goes to -10 degrees in CCW direction. If I type -250, it goes to -250 degrees.

 

 

I have given some examples in the picture below, I hope I have been able to explain.

Nt6VS.png

 wrote:

See if this can give you some ideas....

 

(Of course you can skip the animation and go directly to the "Move!", but then you won't be able to tell what it does.... 🙂

 

 Also note that except for the stop condition, there is nothing green at all!)

 

Try it out....

 

I am using integers because stepper motors typically have discrete steps. While the angles can be floating points, the rest of the calculations should be done in stepper units. You can easily convert based on steps/revolution.




My main problem here is if the motor has moved in the CW direction, for example, if it has reached 100 degrees, if I write -100 to the motor again, it will turn to -100 degrees in the CCW direction. That is, it moves with absolute positioning information, not incremental steps like a typical stepper motor.

 

 

Thanks for your answers. It's my fault I didn't put the picture description. I think I can explain the situation a little more in the picture above.

0 Kudos
Message 13 of 67
(1,197 Views)

Here is my solution... without bells and whistles

Move.png

 

 

EDIT... didn't read all the new stuff ...  missed the part for cw ccw and absolute position .. 😉

so a little addon: cw or ccw needs to be checked 😉 , the actual command needs to be build anyway 🙂

move2.png

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 14 of 67
(1,194 Views)

@altenbach wrote:

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.



You're right, it would require another mod 360 after the subtraction. The first two mod 360's are probably redundant after that.

wiebeCARYA_0-1663745281462.png

 

0 Kudos
Message 15 of 67
(1,189 Views)


@Henrik_Volkers wrote:

Here is my solution... without bells and whistles

 

 

 

EDIT... didn't read all the new stuff ...  missed the part for cw ccw and absolute position .. 😉

so a little addon: cw or ccw needs to be checked 😉 , the actual command needs to be build anyway 🙂

 


I tested this, but as I explained in the previous message, if -125 is sent to the motor, the motor will start from 0 and go to -125 degrees in the CCW direction, which corresponds to 235 degrees when compared to the compass logic.

No matter how many turns the motor turns, it should go to 235 degrees with compass logic.
According to the current position of the motor, the degree to which the motor should go is 235, but maybe -125 should be sent so that the motor reaches 235 degrees.
Maybe it is 235 degrees for the motor to go, but it is necessary to write 235 for the motor to turn 235 degrees.
maybe the motor should go to 235 degrees, but for the motor to go to 235 degrees, (360+235)595 should be written. It just depends on the current position of the motor (whether it has moved in CCW or CW) and the shortest path.

0 Kudos
Message 16 of 67
(1,180 Views)

Here's my attempt. The idea is that you just calculate the increment between the current and new angle, going CCW if the difference is >180. You can select relative or absolute angle. (LV2016 vi attached).

StepperMotorExample.png

Basjong53_0-1663751207725.png

 

This way you can write CurrentAngle+Increment to your stepper motor.

0 Kudos
Message 17 of 67
(1,165 Views)

@Basjong53 wrote:

Here's my attempt. The idea is that you just calculate the increment between the current and new angle, going CCW if the difference is >180. You can select relative or absolute angle. (LV2016 vi attached).

 

 

 

This way you can write CurrentAngle+Increment to your stepper motor.


Thanks for your effort.

Here, as in previous posts, there is an issue with incremental positioning. So there is no absolute position that we can send directly to the motor. Whereas the motor must go to an absolute position.

0 Kudos
Message 18 of 67
(1,158 Views)

It's still not clear to me what you mean by the absolute position of the motor. Is this position restricted to 0-360? Or can it go beyond? 

When you start the motor and the software, the angle is 0. If you just store all the increments of my example, you know the position of the motor. Let's say you move 200 degrees, 3 times, that's 600 degrees. Is it sufficient to send 600 to the motor?

0 Kudos
Message 19 of 67
(1,142 Views)

Well, I thought for a minute I had managed to decipher what the request was, but apparently not.   Let me try to restate my present best guess:

 

It sounds like the motor controller is a little bit stupid and has a faulty method for travelling to the requested destination.  It *will* arrive at the correct absolute angle that you requested, but it may take the long way around to get there.  So you want to intervene and (sometimes) add or subtract 360 from the target position, forcing the stupid controller to take the shorter path.

    If I understand right, the controller's problem is that it uses the sign of the commanded position to determine which direction to travel.  The table below lays out what I'm supposing your controller would want to do, and how you would want to intervene to do a smarter thing.

 

Start Pos Original Cmd Pos Controller Motion Modified Cmd Pos Controller Motion
330 30 CW 60 deg 30 CW 60 deg
30 300 CW 270 deg -60 CCW 90 deg
300 -30 CCW 330 deg 330 CW 30 deg
330 240 CW 270 deg -120 CCW 90 deg
240 -60 CCW 300 deg 300 CW 60 deg
300 -180 CCW 120 deg -180 CCW 120 deg

 

If this is an incorrect understanding, please lay out a similar sequence of commanded positions to help define:

A. Which direction and how far the motor would move if you didn't modify the command

B. How you *want* the motor to move instead

C. What command position you would need to send to make the motor move the way you want

 

And please don't use examples where the motor starts from 0 position!  It becomes ambiguous whether your subsequent talk about degrees refer to a *position* or a *relative distance*.   Also, please make a special effort to be really clear about whether you are describing what DOES happen vs. what you WANT to happen.  As I read back through the thread, I often found it hard to tell b/c different msgs seemed to contradict one another.  Probably some were describing what DOES happen while others were describing what you WANT, but I'm not entirely sure which is which.

 

 

-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 20 of 67
(1,130 Views)