This is our first time using this sensor…
What would be the simplest way to program for the following:
We just need to tell if we are leaning side to side on 1 axis.
I suggest you look at the ADXL345 I2C Accelerometer example project to get started.
To measure your tilt, read the horizontal (either X or Y) and vertical (Z) acceleration axes and feed them into a rectangular-to-polar coordinate conversion function. The angle output will tell you which direction is “up” according to gravity.
Here is a follow-up question.
The WPI accelerometer icons found in LabVIEW under the WPI library is for an analog accelerometer (example under analog section of FRC examples). Is that using the gyroscope used as an accelerometer? If so, how is it wired?
The A…345 accelerometer is a digital device. The example for the A…345 worked for me, but I’m not clear about how to bring the driver code for that into the project.
I’m not sure if I need to pursue wiring an analog accelerometer to use the LabVIEW stuff that is readily available, or if I should stick the A…345 digital accelerometer and figure out how to import the drivers into the project.
Thank you,
Tim
The Kit of Parts came with an analog-output accelerometer for a couple of years. That’s what those functions support.
The A…345 accelerometer is a digital device. The example for the A…345 worked for me, but I’m not clear about how to bring the driver code for that into the project.
I can’t find the instructions for integrating the I2C Accelerometer example, but here’s how I did it:
- Open the ADXL345 I2C Accelerometer.lvproj
example. - Expand the RT CompactRIO Target
subtree. - Right-click the ADXL345 I2C Accelerometer.vi
and choose Save As… from the menu. - Select Duplicate hierarchy to new location
and click the Continue… button. - Navigate to the folder containing your robot project and click the Current Folder
button. - Open your robot project (you can close the example first if you want to).
- Right-click RT CompactRIO Target
and choose Add >> Folder (snapshot)… - Select the ADXL345 I2C Accelerometer Folder
and click the Current Folder button.
Now you can copy the functions you want to use from the newly added ADXL345 I2C Accelerometer.vi into Begin, Teleop, Periodic Tasks, Finish, etc. Once you’ve placed them where you want them, you should remove ADXL345 I2C Accelerometer.vi from your project by right-clicking it and choosing Remove from Project.
You can also drag a vi from the Drivers folder into any vi you want to use it in, or use the Select a VI… option from the functions menu to find and place them.