From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Motion Control and Motor Drives

cancel
Showing results for 
Search instead for 
Did you mean: 

Motion Control With myRIO?

Hello,

 

I would like to control the position of servo motor with a myRIO. Specifically, I would like to move the motor through a trajectory. What is the best way to do this?

 

Here is how I am currently doing it (below, and code attached), using a myRIO. Two independent while loops are running. The top one reads a *.txt file called Trajectory.txt (on the myRIO), which contains a column vector with positions at which I'd like the motor to move. Currently, Trajectory.txt is a sinusoid of amplitude 1 and period 1000 samples. Each time the loop runs, it loads the next entry in Trajectory.txt and sends the value to the DesiredPosition variable.

 

The second while loop reads the DesiredPosition variable, compares it to the encoder-measured position, performs PID control on the resulting error, then sends the signal to my motor's amplifier via an analog output.

 

My motor executes the trajectory, but the motion is extremely rough. I can feel and hear the shaft vibrate as each new position is loaded.  Although I would like the top while loop to run at 1kHz, it seems that it can't run faster than 53Hz. If I could run it faster, my motor could probably low-pass filter the signal and the motion would be smoother. Would anyone suggest a better strategy?

 

Thanks,

Matthew

 

screenshot_for_forum.png

0 Kudos
Message 1 of 3
(5,261 Views)

As somewhere to start, open the file once when you initialize and pass the contents into the while loop.  Right now you're re-loading the file in every loop iteration, which is going to be pretty slow.

Tom L.
0 Kudos
Message 2 of 3
(5,258 Views)

would you please send the Trajectory.txt file ?

0 Kudos
Message 3 of 3
(2,501 Views)