LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

loop rate problem and low response with (LINX + Arduino)

i created VI to read date from Gyro MPU 6050 by using Arduino and LINX and you know if i am using (dt) = 6 ms i will obtain loop rate 166 Hz but when i run the VI i got problem with loop speed during work i got loop rate (50 Hz) Although i used (dt) = 6 ms .

and after i added servo and PID controller i got loop rate (23 Hz) Although i used (dt) = 6 ms 

Untitled.png

 

and This makes the program less responsive and therefore  the control does not work properly

please if you have solution or you can help me to solve this problem, i attached here the first VI which read date from Gyro MPU 6050

0 Kudos
Message 1 of 4
(4,679 Views)

Please follow the Producer Consumer design pattern with User events. That will allow your UI to be responsive even if your task is running at a lower rate. As you are having multiple task which takes time to execute, single loop may not work. 

 

Click here to get to know about producer consumer design pattern. 

0 Kudos
Message 2 of 4
(4,637 Views)

thank you for your help me ....

i understood you , but in my case i want work with the same rate with all my actions 

for examples i want work with loop rate 150 Hz for produce data and PID control and after that with send the data to motors .

and the other part you can see the VI file which i attached here , i have just produce data from Gyroscope sensor why the frequency fall from 166 Hz to 60 Hz  

0 Kudos
Message 3 of 4
(4,606 Views)

I'm not sure as I am not having the same hardware with me, Mostly I feel that the read time of your Gyroscope is more than that of the Wait time of the loop, so the wait time VI is not affecting the loop rate. 

Imagine a situation that you have kept a wait time VI with 6 ms delay, so you expect a loop rate of 166.66 Hz. Now, your code inside the loop (reading gyroscope) takes 16 ms to execute, so the loop rate you will get is 62.5 Hz.

I suggest you to make a trial and find out that how long it takes for your API read tasks to complete.

 

As you want to keep all process in a same rate, you can keep them in a single loop, but Producer consumer design pattern with event will make sure that your UI responds faster. You don’t need to run the UI in the same loop rate with other tasks, UI events are asynchronous so it’s better not to poll them and wait for the event using the event structure.

 

Also note that if you have 10 tasks to be done, to achieve a faster loop rate in the second loop, you need to keep them in parallel.

0 Kudos
Message 4 of 4
(4,587 Views)