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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sinusoidal motion to servo

Hello everyone!

I am absolute beginner in LabVIEW and I have to write program, that will generate sinusoidal motion in servo drive. I am using circular motion formula:

 

x(t) = A * cos(w*t)

 

where "A" is Amplitude and "w" is angular velocity w = 2*pi/T

 

"T" and "A" are my variables that I will be changing in my program.

 

My task is quite complex, but firstly I would like to start from the most basic thing. I made cosine function and connected it to VI that is contacting with servo by VISA (this VI is not mine, but is from older project and it suits also to mine). Result of function is my velocity of driver shaft, that is changing concontinuously.

 

When I am giving constant value as a velocity, it works, but when I am connecting my cosine function, from which I wolud like to gather values of velocity, it doesn't work. What am I doing wrong? I am thinking that I should discretize function, because driver cannot process this constantly changing information about velocity, but I don't know how.

This version, with constant velocity, is working

skrin2.jpg

And this, with my functions, doesn't work

skrin1.jpg

0 Kudos
Message 1 of 8
(1,647 Views)

Hi Piotr,

 


@jeandebrem wrote:

When I am giving constant value as a velocity, it works, but when I am connecting my cosine function, from which I wolud like to gather values of velocity, it doesn't work. What am I doing wrong? I am thinking that I should discretize function, because driver cannot process this constantly changing information about velocity, but I don't know how.


What did you wrong?

Two main errors:

  • attaching just images of part of your code instead of attaching (real) code!
  • don't obeying the basic LabVIEW mantra of "THINK DATAFLOW!"

 


@jeandebrem wrote:

I am absolute beginner in LabVIEW and I have to write program,


So you did notice those "Training resources" as offered at the top of the LabVIEW board?

You carefully took the beginner courses and learned about "THINK DATAFLOW!"?

 


@jeandebrem wrote:

And this, with my functions, doesn't work


What does "doesn't work" mean? Do you get any error messages? Do you kill LabVIEW? Or do you get a BSOD?

 

The shown code will work and does work - exactly as you programmed it! As soon as you press that "stop" button in the while loop the current cosine value will be output to your motor driver: it's all dictated by "THINK DATAFLOW!"…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 8
(1,616 Views)


What does "doesn't work" mean? Do you get any error messages? Do you kill LabVIEW? Or do you get a BSOD?


I get literally nothing. Motor is not moving. I only get function on graph.

 

 

The shown code will work and does work - exactly as you programmed it! As soon as you press that "stop" button in the while loop the current cosine value will be output to your motor driver: it's all dictated by "THINK DATAFLOW!"…


 The problem is, that when I press stop button, nothing is happening.

 

0 Kudos
Message 3 of 8
(1,611 Views)


What did you wrong?

Two main errors:

  • attaching just images of part of your code instead of attaching (real) code!

Here you are!

0 Kudos
Message 4 of 8
(1,607 Views)

Hi jean,

 


@jeandebrem wrote:
I get literally nothing. Motor is not moving. I only get function on graph.

Because that is what you have programmed! You can easily check that using highlight execution debugging!

Inside the loop you only generate a plot for your graph - nothing else: now you wonder why nothing else is happening as long as that loop is iterating???

 


@jeandebrem wrote:
The problem is, that when I press stop button, nothing is happening.

When you press the "stop" button which is located inside the loop then the loop stops and a command is sent to your motor. There has to be some kind of motor driver reaction!

Again you can easily check this behaviour using highlight execution debugging!!!

 

You also should learn to create more cleaned up code:

(It's also annoying to set frontpanel and blockdiagram to fullscreen windows!)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 8
(1,604 Views)

Ok, thank you, now I understand what I have done wrong.

0 Kudos
Message 6 of 8
(1,526 Views)

I've made two while loops with local variables (my subVI, which is computing and sending velocity) and later I've put all program (my VI) in loop. Effect was interesting. First time, when I was turning on motor, program was working properly and was sending appropriate movement&velocity to the motor. When I was changing something in code (i.e. amplitude of function) program didn't work. Next day story was the same. First turning on program was good, but later it didn't work at all. Sending data from subVI is blocked, as we can see by highlight execution.

What is wrong? It's strange that program is working good and after few minutes is not working for rest of a day.

SubVI.jpgVI.jpg

 

Maybe I should make a queue?

Download All
0 Kudos
Message 7 of 8
(1,479 Views)

Hi Jean,

 


@jeandebrem wrote:

What is wrong? It's strange that program is working good and after few minutes is not working for rest of a day.

Maybe I should make a queue?


There is so much wrong:

  • using a while loop when you know the (max) number of iterations before starting the loop
  • using a while loop when it is set to iterate just once
  • using a loop with a shift register to concatenate a string array
  • using a case structure to negate the error status when you can switch the stop condition of the loop
  • splitting a string when you can swap the bytes in a word
  • best of all: reading the local before the loop and wondering when the value doesn't change in the loop… (THINK DATAFLOW!)

 

See this:

Many, but not all problems are solved:

  • How and where do you initialize the serial port?
  • Why do you read the same number of bytes as you write to the port?
  • Using a wait between VISAWrite and VISARead most often is wrong, there surely is a protocol you have to follow…
  • Why do you convert "wynik" to U16 when its value is in the range -20…+20? Why not use a signed integer?
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 8
(1,307 Views)