I’m trying to code something in LabView which takes the data from the Ultrasonic Rangefinder and spits out the distance in the dashboard. Now, I’ve currently got this…
In this, I’m getting the Refnum registry (which I assume is already defined somewhere, but I might be wrong), and getting the range in inches. If I want to pump the distance output from Get Range to the dashboard, how would I go about doing that?
I’ve made a Case Structure and placed the code inside of it. When button 2 on either Joystick 1 or 2 is depressed, it runs the code which should send out a ping and range it into inches. My question remains - How can I send the readout from Get Range into the Dashboard? And is my code correct? I might be going about this in the wrong way.
A reference won’t be in the registry until you put it there. That’s what happens in the Begin vi. Open the sensor and use a Refnum Set to give it a name.
Are you using the rangefinder from the Kit of Parts? The most straightforward way to read it is using an Analog channel. I think the Ultrasonic Get Range function you’re using is for the SRF04 part, a different style of ultrasonic sensor. Look at the examples for the MB1010 instead.
Yes, I am using the MB1010. I was just taking a look at the included example code about 10 minutes ago, and saw that there are major differences between what this years KOP had and what they are using…
EDIT - When you say look at the examples for the MB1010, do you mean the code they’ve got on their website or somewhere within LabView’s various examples ?
And if I wanted to import the example code into the example teleop.vi, could I just copy/paste the code in, and put it within a while loop which becomes true when a button on the joystick is pressed? (thus ranging once and displaying one distance in the dashboard)?
Both of the examples give you a continuously updating sensor value that you can read at any time. The digital connection is theoretically less susceptible to electrical noise within the robot. The analog connection might be preferable if you want to use the digital inputs for other sensors. It is also possible to do some more complicated wiring to the digital connections that lets you choose when to activate the sensor, which cuts down on interference if multiple sonar rangefinders are in use at the same time.
For a “ping on demand”, you’ll need to read up on the MB1010 documentation and find out how to control it with that level of detail. Displaying things on the dashboard is another topic entirely, and I should probably come up with a good instructional document – once I figure out a better way to do it than the manual synchronization of clusters that I used last year.
In general, applying the examples to a robot project is a matter of putting everything to the left of the example’s while loop into Begin, putting everything inside the while loop into Teleop (or Periodic Tasks), and everything after the loop into Finish. Use a RefNum Registry Set in Begin to save the reference for later retrieval with a RefNum Registry Get. For some of the examples, you might want to look up the documentation for the “Data Operations” item on front panel controls, specifically the “Make Current Value Default” command.
The analog example actually has some things inside the while loop that probably belong in Begin. The digital example is much more straightforward to put into a robot project.
The major recommendation I would make is that instead of reading the data from the sensor the build dashboard data vi as shown, I would read the data where you want it (either teleop or periodic tasks) and save it in a global variable, and then read the global variable in the build dashboard data vi.
I read and tried to follow the tutorial from NI step by step, but left more confused than when I began. Then, I went through tutorial 7 from LabView’s Getting Started Window. Now I feel that I have a grasp on what’s going on.
Great news! I was able to properly code in the rangefinder!
Now, one final question. I read somewhere that there should only be one Set High(/Low) User Data Priority per vi? If this is so, how would I integrate the Gyro, Accelerometer, Rangefinder, and Potentiometer in with each other ?