bno055: C port; C++ wraps C

The API has been changed in some cases - see the apichanges.md
document.

In addition, this driver uses a new upm_vectortypes.i SWIG interface
file to provide a mechanism for methods that return a vector of floats
and ints instead of a pointer to an array.

This works much nicer than C array pointers, and results in Python/JS/Java
code that looks much more "natural" to the language in use.

The Python, JS, and Java examples have been changed to use these
methods.  Support for the "old" C-style pointer methods are still
provided for backward compatibility with existing code.

As an example - to retrieve the x, y, and z data for Euler Angles from
the bno055, the original python code would look something like:

       ...
       x = sensorObj.new_floatp()
       y = sensorObj.new_floatp()
       z = sensorObj.new_floatp()
       ...
       sensor.getEulerAngles(x, y, z)
       ...
       print("Euler: Heading:", sensorObj.floatp_value(x), end=' ')
       print(" Roll:", sensorObj.floatp_value(y), end=' ')
       ...

Now the equivalent code is simply:

       floatData = sensor.getEulerAngles()
       print("Euler: Heading:", floatData[0], ...
       print(" Roll:", floatData[1], end=' ')
       ...

Additionally, interrupt handling for Java is now implemented
completely in the C++ header file now rather than the .cxx file, so no
special SWIG processing is required anymore. See Issue #518 .

Signed-off-by: Jon Trulson <jtrulson@ics.com>
This commit is contained in:
Jon Trulson
2017-03-07 12:43:44 -07:00
parent 2bdde21a2f
commit d4b536b593
16 changed files with 3382 additions and 2155 deletions

View File

@ -1,6 +1,8 @@
#!/usr/bin/python
# Author: Jon Trulson <jtrulson@ics.com>
# Copyright (c) 2016 Intel Corporation.
# Copyright (c) 2016-2017 Intel Corporation.
#
# The MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
@ -32,7 +34,8 @@ def main():
sensor = sensorObj.BNO055()
## Exit handlers ##
# This function stops python from printing a stacktrace when you hit control-C
# This function stops python from printing a stacktrace when you
# hit control-C
def SIGINTHandler(signum, frame):
raise SystemExit
@ -45,16 +48,6 @@ def main():
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)
mag = sensorObj.new_intp()
acc = sensorObj.new_intp()
gyr = sensorObj.new_intp()
syst = sensorObj.new_intp()
w = sensorObj.new_floatp()
x = sensorObj.new_floatp()
y = sensorObj.new_floatp()
z = sensorObj.new_floatp()
print("First we need to calibrate. 4 numbers will be output every")
print("second for each sensor. 0 means uncalibrated, and 3 means")
print("fully calibrated.")
@ -63,44 +56,54 @@ def main():
print()
while (not sensor.isFullyCalibrated()):
sensor.getCalibrationStatus(mag, acc, gyr, syst)
print("Magnetometer:", sensorObj.intp_value(mag), end=' ')
print(" Accelerometer:", sensorObj.intp_value(acc), end=' ')
print(" Gyroscope:", sensorObj.intp_value(gyr), end=' ')
print(" System:", sensorObj.intp_value(syst), end=' ')
intData = sensor.getCalibrationStatus()
print("Magnetometer:", intData[0], end=' ')
print(" Accelerometer:", intData[1], end=' ')
print(" Gyroscope:", intData[2], end=' ')
print(" System:", intData[3])
time.sleep(1)
print()
print("Calibration complete.")
print()
# example - read calibration data, sleep and then write it
# print("Reading calibration data....")
# byteData = sensor.readCalibrationData()
# print("Read data successfully.")
# print("Writing calibration data...")
# time.sleep(1)
# sensor.writeCalibrationData(byteData)
# print("Success!")
# time.sleep(3)
# now output various fusion data every 250 milliseconds
while (True):
sensor.update()
sensor.getEulerAngles(x, y, z)
print("Euler: Heading:", sensorObj.floatp_value(x), end=' ')
print(" Roll:", sensorObj.floatp_value(y), end=' ')
print(" Pitch:", sensorObj.floatp_value(z), end=' ')
floatData = sensor.getEulerAngles()
print("Euler: Heading:", floatData[0], end=' ')
print(" Roll:", floatData[1], end=' ')
print(" Pitch:", floatData[2], end=' ')
print(" degrees")
sensor.getQuaternions(w, x, y, z)
print("Quaternion: W:", sensorObj.floatp_value(w), end=' ')
print(" X:", sensorObj.floatp_value(x), end=' ')
print(" Y:", sensorObj.floatp_value(y), end=' ')
print(" Z:", sensorObj.floatp_value(z))
floatData = sensor.getQuaternions()
print("Quaternion: W:", floatData[0], end=' ')
print(" X:", floatData[1], end=' ')
print(" Y:", floatData[2], end=' ')
print(" Z:", floatData[3])
sensor.getLinearAcceleration(x, y, z)
print("Linear Acceleration: X:", sensorObj.floatp_value(x), end=' ')
print(" Y:", sensorObj.floatp_value(y), end=' ')
print(" Z:", sensorObj.floatp_value(z), end=' ')
floatData = sensor.getLinearAcceleration()
print("Linear Acceleration: X:", floatData[0], end=' ')
print(" Y:", floatData[1], end=' ')
print(" Z:", floatData[2], end=' ')
print(" m/s^2")
sensor.getGravityVectors(x, y, z)
print("Gravity Vector: X:", sensorObj.floatp_value(x), end=' ')
print(" Y:", sensorObj.floatp_value(y), end=' ')
print(" Z:", sensorObj.floatp_value(z), end=' ')
floatData = sensor.getGravityVectors()
print("Gravity Vector: X:", floatData[0], end=' ')
print(" Y:", floatData[1], end=' ')
print(" Z:", floatData[2], end=' ')
print(" m/s^2")
print()