Motion Control and Motor Drives

cancel
Showing results for 
Search instead for 
Did you mean: 

comparison of target and actual position with NI Motion

Hi everybody,
 
I drive a stepper motor with NI Motion. The user can enter a number of steps as the target position of the motor at the front panel, which is connected to the corresponding VI in the block diagram ("target position"). As I don't only want to stop the motor (when it made the desired steps), but als the measurements within another while loop, I tried to compare the target position with the output of the actual position (NI Motion VI) and wired the result to a local variable, which stops the two while loops when it's true.
It works perfectly for a desired move of 45° or 90° (rotation of motor, corresponding number of steps is calculated within the program), but if I want the motor to rotate 30° or 75° or anything else, the motor stops, but not the other while loop (measurements). Does anybody have an idea why?
I don't have any feedback from the motor, so the actual position is only calculated I guess. But why does it work with 45° and 90° and doesn't work with any other number of degrees?
 
Looking forward to your answer! Maybe there is another way to handle this.
 
Thanks!
Steffi
0 Kudos
Message 1 of 6
(4,081 Views)
Could you please post your code? Otherwise I don't have a clue what's going on.

Thanks,

Jochen
National Instruments
0 Kudos
Message 2 of 6
(4,080 Views)

I will post it tomorrow!

 

Thanks!

0 Kudos
Message 3 of 6
(4,072 Views)
Hi Jochen,
 
her is the code. I only attached the motor drive loop, but the "Position erreicht" LED is connected via a local varibale to the other loops. I'm sure that the error is within this VI because in case of example 30° the LED isn't on, which should be the case!
 
Maybe you have an idea!
 
Thanks
0 Kudos
Message 4 of 6
(4,063 Views)
Thank you for the code. The explanation for your problem is quite simple.
You use the "=" function to compare a DBL value with an I32 value. Doing this is very dangerous as there is a chance that because of rounding and the limited accuracy of floating point values result in some differences in the least significant digits. Thus the "=" function never becomes true.

In the case of 30° in fact you compare -6800,000000000000900000 to -6800 and the loop never stops.

There are several ways to solve this issue. Here are some examples:
  1. convert the DBL value to I32 before the comparison
  2. don't use the "=" function but use the In Range function. For a motion system this might be an even better option as it allows you to define a deadband around your target position which could help to cope with mechanical inaccuracies. But of course it depends on your application and the stepper mode (open loop or closed loop) if this makes sense or not.
                                     

I hope this helps,

Jochen

Message Edited by Jochen on 07-04-2007 10:03 AM

Message 5 of 6
(4,062 Views)
This was really stupid of me... THANK YOU!!!: )
0 Kudos
Message 6 of 6
(4,057 Views)