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: 

PWM control for servo

Hey guys. 

I am making a Labview VI that control's servo, by comparing onboard acclerometer readings.  A set profile(in excel) will be used and compared against an onboard acclerometer's z-axis reading's.  When the acclerometer reading's are above or below the expected value the servo will get a signal to adjust manually, this will be done by a Case structure. 

My question is about comparing the reading's.  Can anyone point out how can I get labview to compare excel readings against onboard readings? 

The image below shows a block diagram of what I am trying to obtain.  The end result is to try and alter thrust on board a rocket.  We will be using a Myrio which was donated for this project.

 

 

 

thrust1.png

 

 

Any advice is much appriciated!

Caleb

 

 

 

 

 

 

 

 

Thanks

Caleb

0 Kudos
Message 1 of 9
(3,177 Views)

Hi Caleb,

 

As you are using myRIO, You might want to have a look at this youtube video link: http://www.youtube.com/watch?v=BuREWnD6Eno

 

There is a section in the video regarding file I/O. In function palette, there is a function for you to read data out of the file. You can start from reading something from the file.

 

Hope this help

 

Best regards,

TuiTui

0 Kudos
Message 2 of 9
(3,139 Views)

Hey cwatts26,

 

I'm not sure if I completely understand what you mean by compare the values. Are you not sure how to acquire the onboard readings into a usable form in LabVIEW? For the Excel data, you can use VIs in the File I/O category to read values in from your Excel document. From there, you would simply compare the values using boolean logic as usual. Is this the type of comparison you are referring to, or is there more to it?

 

Regards,

 

Ryan

Ryan P.
CLA
0 Kudos
Message 3 of 9
(3,120 Views)

I understand I currently don't have the excel data on me, but I am just experimenting with the code.

But anytime I add a comparator it won't hook up with a case structure.

 

case.png

0 Kudos
Message 4 of 9
(3,084 Views)

Hey cwatts26,

 

That's because in the above screenshot you are comparing an array of values to a single value, which produces an array of booleans as a result. A case structure cannot have an array as an input to it's "?" terminal. You can add a For Loop to auto-index and compare the Excel values one at a time, or you can index the resultant boolean array to get the individual results which can be used with a case structure.

 

I hope this helps.

 

Regards,

 

Ryan

Ryan P.
CLA
0 Kudos
Message 5 of 9
(3,068 Views)

Ultimately I will be comparing an input to a spreadsheet file.  Is a for Loop the best way to do this?
I would like something similar as shown below, but it should be important to note that in the end the input is adjusted for cailberating of a acclerometer.









error.png

0 Kudos
Message 6 of 9
(3,041 Views)

Are you trying to compare the analog value AI0 to every value in the spreasheet by looking to see if AI0 is greater than all of the values in the spreadsheet? Essentially, do want code that generates a FALSE if all the values in the spreadsheet are less than the AI0, but generates a TRUE if only one is greater? If so, here's how I would acheive that:

 

Boolean comparison example.png

Ryan P.
CLA
0 Kudos
Message 7 of 9
(3,030 Views)

Preferably the spreadsheet will have different value's in each cell. 
The input from the analog port at any given time will match with the corresponding cell, as in:

 

Cell 1 compared to

Analog input at that time

 

Cell 2 compared to

Analog input at that time

 

And then depending on compareson a PWM signal will be sent out to operate a servo or not.  As stated eariler after the comparison I can use a case study as a generator of the PWM, it's just the comparison i'm kinda confused about.  I will definitely try that later in the week when I get the chance.  I do appriciate it!

 

 

0 Kudos
Message 8 of 9
(3,013 Views)

Based on your updated description, I think that this may be what you are looking for. The For Loop reads data from the Excel sheet one at a time because of the Auto-Indexing Tunnel. It is then compared to the current Analog value (just replace my Analog In with your DAQ Assistant Express VI). Based on whether or not it is FALSE or not, the servo will or won't be updated. The Wait (ms) function in the corner controls how fast the values are compared and the servo gets updated since it pauses each loop interation for the displayed period of time in milliseconds.

 

Boolean comparison example.png

Ryan P.
CLA
0 Kudos
Message 9 of 9
(2,983 Views)