LabVIEW

cancel
Showing results for
Search instead for
Did you mean:

Solved!
Go to solution

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

If you do not mind me asking, which motor and drive system are you using?

Message 31 of 67
(874 Views)

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

@XM43 wrote:

If you do not mind me asking, which motor and drive system are you using?

Delta asda-a2 AC servo motor.

I use with internal parameter and PR mode.

Message 32 of 67
(870 Views)

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

@constructionworker wrote:

Is a CW(10) command the same as a CCW(-10) command?
-No.absolutely

So yes? I.e. implicit, a +10 is a CW and a -10 is CCW.

In my example code, you enter the "go to position" and it will go from the current position to the new absolute position. Right after the value has been changed, the "move!" indicator tells what the remaining relative movement should be (positive or negative, whatever is shorter).

I think we are going in circles!

Message 33 of 67
(864 Views)

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

Hi worker,

@constructionworker wrote:

the motor moves as we listed above.

If the motor is in the "10 Degrees" position and you send it the command "340", what will happen?

answer:

• The motor will move in the CW direction 130 and reach 140 degrees and stop.

If the motor is in the "10 Degrees" position and you send it the command "-340", what will happen?

answer:

• if the motor is at 10 degrees CW
• when position -340 is sent to the motor
• the motor will reverse a total of 150 degrees in the CCW direction
• and reach -140 degrees.

Why does the motor move 130 degrees when you command to go 340 degrees?

Why does the motor move 150 degrees when you command 340?

Where do these numbers come from?

In the other message you basically stated "absolute position" commands when the motor goes to +-20 degrees...

You really need to explain this problem much better!

Best regards,
GerdW

using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 34 of 67
(852 Views)

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

@constructionworker wrote:

Also, have you looked at the last example I shared? In that example, there is no problem in the 1st round in the rotations between 0 and -360(CW) or between 0 and -360(CCW).sometimes it needs to go to the 2nd lap in order to take the shortest route to the given position in the CCW direction or CW direction.By round 2 here I mean 360+N or -360-N

You need to be more specific (link?) because the code posted here (your last example) is just plain silly, with code such as the following. The comparison makes no difference: There is no wait in the loop! Why? The diagram is maximized to the screen, very annoying to stare at 90% whitespace! Why?

Also explain what a "round" and "lap" is, etc. What exactly are you entering and in what order. What do you see and what do you expect to see instead. Step-by-step!!!

Message 35 of 67
(849 Views)

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

@GerdW wrote:

Hi worker,

@constructionworker wrote:

the motor moves as we listed above.

If the motor is in the "10 Degrees" position and you send it the command "340", what will happen?

answer:

• The motor will move in the CW direction 130 and reach 140 degrees and stop.

If the motor is in the "10 Degrees" position and you send it the command "-340", what will happen?

answer:

• if the motor is at 10 degrees CW
• when position -340 is sent to the motor
• the motor will reverse a total of 150 degrees in the CCW direction
• and reach -140 degrees.

Why does the motor move 130 degrees when you command to go 340 degrees?

Why does the motor move 150 degrees when you command 340?

Where do these numbers come from?

In the other message you basically stated "absolute position" commands when the motor goes to +-20 degrees...

You really need to explain this problem much better!

Believe me, I started to write the more numbers incorrectly because of dealing with numbers. I'm very very sorry.

correction:

If the motor is in the "10 Degrees" position and you send it the command "340", what will happen?

answer:

• The motor will move in the CW direction 330 and reach 340 degrees and stop.

If the motor is in the "10 Degrees" position and you send it the command "-340", what will happen?

answer:

• if the motor is at 10 degrees CW
• when position -340 is sent to the motor
• the motor will reverse a total of 350 degrees in the CCW direction
• and reach -340 degrees.
Message 36 of 67
(839 Views)

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

@constructionworker wrote:
• and reach -340 degrees.

There are no negative degrees in your position indicator.

Message 37 of 67
(830 Views)

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

@altenbach wrote:

@constructionworker wrote:
• and reach -340 degrees.

There are no negative degrees in your position indicator.

Yes, because I will be constantly entering positive values between 0-360 from the numerical control.
However, the values that will go to the motor can be negative or positive. A value should be sent to the motor by calculating the shortest path to reach the degree entered from the "numerical control" according to the current degree of the motor. This can be + or - degrees.

Message 38 of 67
(818 Views)

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

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

Message 39 of 67
(801 Views)

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

@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

Ugh.  This was my first thought from post 1, but I couldn't believe that was what this was all about.

Bill

(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 40 of 67
(791 Views)