Example Code

Using LabVIEW to read data from the Sparkfun Razor 9DoF IMU

Code and Documents

Attachment

An Inertial Measurement Unit(IMU) is used in the industry on vehicles such as airplanes, unmanned aerial vehicles (UAVs), and mini-subs.  An IMU contains a combination of accelerometers and rate gyros to return data such as the vehicles roll, pitch, and yaw.  IMUs can range from the very low cost to those ranging in the thousands of dollars.

Sparkfun Electronics, and online seller of Open Source hardware for hobbyists, produces a lowcost IMU, called the Sparkfun Razor 9DoF IMU. Hobbyists work through the power of the community to create code and support the hardware.  Once programmed correctly through the open source Arduino Software, this IMU outputs its roll, pitch, and yaw data via Serial.

This example code shows how to read the serial data from the Sparkfun 9DoF IMU via the serial COM port on a Windows PC.  The data read is then decoded and the roll, pitch, and yaw data is displayed on separate Waveform Chart indicators on the LabVIEW Front Panel.  The code primarily consists of using NI-Serial and NI-VISA for reading the serial output from the IMU, and String Manipulation VI's are used for decoding the data and extracting the roll, pitch, and yaw.

The example code assumes that you are using the 9 Degrees of Freedom - Razor IMU - AHRS compatible, sku: SEN-09623

The example code assumes that you have programmed the IMU using the Arduino Code SF9DOF_AHRS_1_1.zip

The decoding SubVI has been tested to work with data that has been acquired through the serial port of a cRIO as well, under Real-time.  The Main VI must be modified to for correct operation under Real-time.

IMUsnippet00.png

George T.
Senior Applications Engineer
National Instruments UK and Ireland

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Sze Pei
Member
Member
on

Do you have a front panel for this ?

MasterSTU
Member
Member
on

What would you have to change to make this work for Real Time?

gt3000
NI Employee (retired)
on

This would work out of the box running on Real-Time, however, your application will have less elements of Real-time.  In an ideal world, a Real-time system will not include elements that makes the code execute at a different rate each time it iterates.  For example, a User Interface that accepts mouse-clicks or updates graphs intensly will add jitter to the total execution of your code.  This effectively makes your application less 'Real-time'.  If the jitter is acceptable in your application, then you don't have to change much.  However, a developer who is concerned about jitter will use the example above to do the work of calculating Roll, Pitch, Yaw, but display it on a Front Panel of another VI, which is running in Windows.  The Windows VI (Host) will communicate with Real-time VI (Target) via some communication mechanism, like Network Published Shared Variables or Network Streams (LV 2010 or greater). 

If the concepts above are unfamiliar to you, consider sitting some training either at your local branch of NI, or by downloading the course material found here: http://www.ni.com/white-paper/9988/en/

Chapters 1, 2 and 5 should be a good start.

The course above is the older version, but the content is still valuable.  If you hold a valid serial number of NI software, or if your company or academic institution have volume licenses, you can access later versions of course material via the new 'Self-paced Online Training' (SPOT) scheme, found by signing in at http://ni.com/self-paced-training.

George T.
Senior Applications Engineer
National Instruments UK and Ireland
jmflorez
Member
Member
on

If someone wants to make it work with the new firmwareof the AHRS v.1.4.2 available here, you just need to change the string !ANG: to #YPR= in the decoding SubVI and change the order in the IMU data Cluster to Yaw, Pitch, Roll.

kho10
Member
Member
on

Hi,

I am using the new firmware of the AHRS v1.4.2 code and have been successfuly in using your LabView code with the new firmware. However, we changed the IMU to output both the calibrated data from the sensors (magnetometer, gyroscope, and accelerometer) as well as the yaw, pitch, and roll. After we changed the arduino code to output these values, we keep getting an overrun error code 1073807252 at VISA Read in Labview. Sometimes it will occur and sometimes it won't. I believe the port is reading too slow because of the change we made. How do you make the port read faster? I am unfamiliar with how to match serial port settings between LabView and the IMU and hope you can help!

gt3000
NI Employee (retired)
on

The VISA Read in this example is set to read 100 bytes.  For my personal use, this seemed suitable because I was reading less than 100 characters (bytes), and I wanted a fixed read.  A better solution for most LabVIEW uses is to read all bytes which are in the serial buffer.  There is a built in feature for the NI VISA API which allows you to read 'Bytes at port' which is then fed into the VISA Read, rather than the constant of '100' that I had used.

Help file link: VISA Bytes at Serial Port

This should help because I believe that error code is associated with not reading quickly enough, which means that your buffer at the serial port overflows.

Modify the Top Level VI to look something like this:

2014-04-22 16_46_10-Mail - Inbox - IBM Lotus Notes.png

If you find this doesn't solve the issue, then it might be related to your actual serial port.  I recommend using a search engine, like Google, to search that error code, to find many forum posts at forums.ni.com which related to the error, which offer more advice on optimizing your Windows settings.

George T.
Senior Applications Engineer
National Instruments UK and Ireland
rjbgreen107
Member
Member
on

Should this work with the SEN-10736 IMU (newer version)? To my knowledge, the only difference between these models is that the SEN-10736 replaces the two on-board gyros with a single, triple-axis gyro

infos2017
Member
Member
on

hello,

do you connect the 9dof razor card directly to your pc with usb connection?

or dou you use arduino card?

in your programm do you use the 3 magnetometers?

i have to do a school work where i need to use magnetometers...

best regards

martin

infos2017
Member
Member
on

Can you send me your labview programm?

i have same error in labview: " error 1073807339 occured at VISA read".

thanks

infos2017
Member
Member
on

hi,

yes i have done the modification , no more error 1073807339 but i can not receive the roll, pitch and yaw angles.

what do you think?

lewisastbury
Member
Member
on

Hi, i know this post is a few years old now but it is a very helpfull example for the job i am currently doing. My question is, this emaple uses the Sparkfun Razor 9Dof IMU, my projet uses an Intel Edison Stacked with the Sparkfunbase Block and the Sparkfun 9Dof board for Intel Edison, using your example it reads through the com port but displays 0.00 for the roll pitch and yaw, do you have any explanations or advice?

 

Thanks, Lewis.

Contributors