08-09-2019 04:56 PM
Thank will try as soon as I can. The EMG sensor I didn't mention is connected to analogue pin 0 while the gyroscope is analogue 4 and 5. What you mentioned before about the VI's blocking might be the case that the EMG VI interferes with the other strangely.
The event driven case structure after I posted I realised the problem and and that work perfectly fine. The only issue now is when adding the analogue read to the either VI version it messes up the other graphs for the gyroscope and load cell. This might be silly to say but I assume the for loop method for the servo motor mention requires this to be outside the while loop of the system? Or would this cause a data flow problem?
I am sure I had mine look the same at one point as the picture you posted but I will try it again I might has missed something.
08-09-2019 10:40 PM
@ARD1996 wrote:
The event driven case structure after I posted I realised the problem and and that work perfectly fine.
Which "Event Driven Case Structure"? I saw a case structure with an enum, but no Event Structure.
@ARD1996 wrote:
I assume the for loop method for the servo motor mention requires this to be outside the while loop of the system? Or would this cause a data flow problem?
I realise now that the suggestion will require additional synchronisation, so it's a little more complicated. My apologies for not posting a fuller example. I'll try and explain in a bit more detail, and hopefully you can indicate/tell me which is most appropriate for your situation. It may be that the best thing is to ignore the suggested idea, given that you said it's working now.
Your code is currently all inside the same While loop. This means that each iteration of the While Loop, all of the code runs one time. You make a single call to "Servo Set Pulse Width", a single call to each of Read.vi, Analog Read.vi and Custom Command.vi. (It's possible some of those are only in your latest code, which doesn't show the Case Structure in the same way around the Servo motor, but instead has something like limited bounds and oscillation between the two?)
If you use a For loop as I showed (by the way, I forgot to add the Wait (ms) node - you still need this if you want to slow them down) then each iteration of the For loop, there will be a single call to the Servo Set Pulse Width VI, which will change the pulse width. Given that the current behaviour is to do that once per iteration of the While loop, you'd want them to be syncronised. If you place the For Loop inside the While loop, it will go through the entire list of values each iteration. Probably not what you want. On the other hand, if you place the For Loop outside and next to the While loop, there won't be any timing relation between them. This means they will change at different speeds - perhaps also not what you want.
How many iterations does your While Loop run for? In the latest "Gyroscope Load Cell and Servo Dynamic 2.vi" I suspect the number is quite large and the loop rate is fairly quick.
In the older "Gyroscope Load Cell and Servo.vi" I'd guess it's very slow and runs only a small number of iterations. Is this correct?
If so, the best solution is probably to replace the While loop in "Gyroscope Load Cell and Servo.vi" with a For loop, and then put the array of servo values outside as shown above. This will limit the number of iterations to the number of values. Other operations (Custom Command, Read) will run the same number of times, once per servo value.
If you want to (especially in the other example) run multiple reads per servo change (and you want a static list, not the adaptive bounding algorithm you're using now) you could consider reading about the Producer/Consumer architecture and splitting into multiple While/For loops.
Understand that the crucial difference is that you choose a While loop when you don't know how many times it should run in advance, and a For loop when you do (this can include a number that is "known" before the start of a For loop, but not known to you when you program it, for example "once for every element of this array, which has a size determined at run time based on something else that I don't know (e.g. user input)".
The while loop is more "over and over again, until this thing happens (or stops happening)" - a Stop button being a common example.
Hopefully this is helpful and not just more confusion each post... 🙂
08-10-2019 07:16 AM
I will read into what you suggested further thank you. The ideal end state of both Vi’s is to have the EMG, gyroscope/accelerometer and load cell continuously running hence the while loop while the servo motor runs. The data gathered by the end should be synchronised in time. For example what the load cell, gyroscope, EMG and servo angle was at a given point in time. The static Vi should only run through all the angles once with it returning to 0 angle (1000) at the end. This is why there is another 1000 at the end. For reasons of safety all devices should be stopped at anytime. The reason for two VI if not mentioned prior is two separate experiments. Any suggestions will be appreciated. This is my first custom made VI ever so sorry if some questions have been silly. I have only learned Labview in one week In February of this year. That producer/consumer architecture wasn’t covered.
08-10-2019
08:42 AM
- last edited on
05-13-2025
01:27 PM
by
Content Cleaner
@ARD1996 wrote:
I will read into what you suggested further thank you. The ideal end state of both Vi’s is to have the EMG, gyroscope/accelerometer and load cell continuously running hence the while loop while the servo motor runs. The data gathered by the end should be synchronised in time. For example what the load cell, gyroscope, EMG and servo angle was at a given point in time. The static Vi should only run through all the angles once with it returning to 0 angle (1000) at the end. This is why there is another 1000 at the end.
I understand. Yes - sampling them all in the same loop is probably the simplest way to do this. However, you might prefer a For loop to a While loop (at least in the static case), since you know all of the samples you want to take. For the dynamic case, probably a While loop is the appropriate choice. Take care (in both cases) to avoid conflicting Wait functions or unexpected pausing caused by non-reentrant VIs.
@ARD1996 wrote:
For reasons of safety all devices should be stopped at anytime.
This is a common but sometimes complicated issue. In particular, since you have a Wait function in your loop, you won't easily be able to immediately stop. A possible solution to this is an Event Driven Queued Message Handler or Event Driven Producer/Consumer. Basically the idea is you have one loop that does all of the changing of servo position and measurements, and another loop that controls the first loop's iterations by sending it data to change. Every time the first loop (consumer) receives data from the second loop (producer) it goes to the next iteration. You can place an Event Structure in the second (producer) loop to allow a "stop" button type of action, which then can "immediately" stop the system.
@ARD1996 wrote:
This is my first custom made VI ever so sorry if some questions have been silly. I have only learned Labview in one week In February of this year. That producer/consumer architecture wasn’t covered.
Please don't worry about this - Producer/Consumer is often not one of the first things that new LabVIEW programmers learn (although I think it's perhaps one of the most useful - State Machine is I think usually given as the first "architecture" type application but I didn't learn to create a state machine until I took the CLD exam). Your questions haven't been silly at all, and you've provided code and examples, along with some description of the problems you're having and have tried to make progress based on responses written here.
One resource that you may have access to (if you have SSP for your licencing) is the online training videos/courses at http://sine.ni.com/myni/self-paced-training/app/main.xhtml (that's a link to the inside of the training system, you'll have to probably be prompted to log in if you open it). The Core 1-3 courses are I think probably the best for a general introduction and increasingly advanced training with LabVIEW. Core 1+2 are particularly good for learning to program in LabVIEW.
08-12-2019 10:32 AM
New problem the EMG, load cell and gyroscope work at the same time howeever the servo refuses to work at the same time. This is the dynamic version of the servo. Before adding the final sequence the other three devices work perfectly. Any edits are welcome. I have tried two ways to add the final sequence and neither has worked. Once I get this the static version should work.