Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement device driver for BNO055 9DOF sensor #14956

Closed
wants to merge 3 commits into from

Conversation

Achilleshiel
Copy link

Contribution description

Driver for the BOSCH BNO055 IMU-sensor. This sensor has an internal MCU that does a lot of automatic sensor fusion magic for you.
I added some conversion functions for the float values as some sensor fusion outputs are only usefull when they are specified as floats. However, one can still read the raw integer data. And depending on the setting it can easily be scaled to SI-units.

The driver has read functions for:

  • Euler Angle rotation
  • Quaternion rotation
  • Linear Acceleration (removed the gravitational acceleration from data output)
  • Gravity Vector (outputs only gravitational acceleration)
  • Acceleration
  • Angular rate
  • Magnetic field strength

It can also select units for:

  • Acceleration: m/s^2 or mg (9.81mm/s^2)
  • Magnetic Field strength: μT
  • Euler Angles: Degrees or Radians
  • Angular Rate: Degree/s or Radians/s

Testing procedure

I made a testing-program that reads and prints all the sensor values.

Issues/PRs references

--

@benpicco benpicco added Area: drivers Area: Device drivers Type: new feature The issue requests / The PR implemements a new feature for RIOT labels Sep 6, 2020
@benpicco benpicco added this to In progress in New Drivers via automation Sep 11, 2020
@benpicco benpicco moved this from Waiting for Author to Waiting for Maintainer in New Drivers Sep 11, 2020
@fjmolinas
Copy link
Contributor

Hi @Achilleshiel thanks a lot for the contribution and welcome to RIOT!

I took a quick glimpse at the code, looks good, I'll take a more detailed look tomorrow. Travis pointed out a couple of nitpicks though. Also AFAIK SAUL integration seems to be missing in this PR, there is some general information in http://riot-os.org/api/driver-guide.html. Do you think you would be able to implement that? Let me know if you need some help with that or figuring out travis!

BTW do you have some test output you can show? I don't have the driver to test it but I can trust your test results!

@Achilleshiel
Copy link
Author

Hi @fjmolinas,

I think I have statisfied Travis now. Except that I have to squash this PR at some point =)
I will have a look into the SAUL-part in the weekend. If I have any questions I will let you know.

The output of my test:

2020-09-22 20:13:21,549 # main(): This is RIOT! (Version: 2020.10-devel-1434-gace4-bno055)
2020-09-22 20:13:22,551 # Test for BNO055 device
2020-09-22 20:13:22,556 # Initialize BNO055
2020-09-22 20:13:22,557 # Initialized succesfull
2020-09-22 20:13:23,571 # Quaternions: 0.872803 + -0.274353i + -0.403625j +-0.002441k
2020-09-22 20:13:23,572 # Euler rotation: Heading: 0.006, Roll 0.798, Pitch 0.751
2020-09-22 20:13:23,577 # Gravitation Vector: x: 6.92, y: -4.67, z:5.13
2020-09-22 20:13:23,583 # Linear Acceleration: x: -0.04, y: 0.12, z:0.13
2020-09-22 20:13:23,588 # Magnetometer: x: -20.50, y: 28.69, z:-4.69
2020-09-22 20:13:23,589 # Accelerometer: x: 6.85, y: -4.54, z:5.28
2020-09-22 20:13:23,601 # Gyroscope: x: 0.01, y: 0.05, z:-0.02
2020-09-22 20:13:24,603 # Quaternions: 0.874329 + -0.271790i + -0.402161j +-0.002686k
2020-09-22 20:13:24,609 # Euler rotation: Heading: 0.006, Roll 0.796, Pitch 0.743
2020-09-22 20:13:24,615 # Gravitation Vector: x: 6.90, y: -4.63, z:5.18
2020-09-22 20:13:24,621 # Linear Acceleration: x: -0.14, y: 0.18, z:0.03
2020-09-22 20:13:24,633 # Magnetometer: x: -21.56, y: 29.06, z:-4.69
2020-09-22 20:13:24,633 # Accelerometer: x: 6.83, y: -4.49, z:5.32
2020-09-22 20:13:24,638 # Gyroscope: x: -0.01, y: 0.03, z:-0.02
2020-09-22 20:13:25,122 # Exiting Pyterm

Copy link
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks almost good.

We recently updated the device driver implementation guide to encourage the use of errno codes instead of custom return codes. I won't insist on this point but if you feel like it and want to update this part, that would be nice.
Another thing that would be nice to add is a basic README for the test application.

drivers/bno055/include/bno055_params.h Outdated Show resolved Hide resolved
drivers/include/bno055.h Outdated Show resolved Hide resolved
drivers/include/bno055.h Outdated Show resolved Hide resolved
tests/driver_bno055/main.c Outdated Show resolved Hide resolved
tests/driver_bno055/main.c Outdated Show resolved Hide resolved
Comment on lines +104 to +113
/**
* @brief Status and error return codes
*/
enum {
BNO055_OK = 0, /**< exit without error */
BNO055_NOBUS = ENXIO, /**< cannot connect to module on i2c bus */
BNO055_NODEV = ENODEV, /**< cannot read any data from module */
BNO055_NORW = EIO, /**< cannot read data from module */
BNO055_NOTREADY = EBUSY, /**< no new data ready for reading */
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole enum should be removed and the errno codes directly returned in the implementation. The doxygen documentation also needs to be adapted.

Comment on lines +96 to +105
#define BNO055_DIV_SCALE_ACC_MSS (100.0) /**> Acceleration Raw to m/s2 scaling */
#define BNO055_DIV_SCALE_ACC_G (1.0) /**> Acceleration Raw to g (9.81m/s2) scaling */
#define BNO055_DIV_SCALE_GYR_RPS (900.0) /**> Gyroscope Raw to rad/s scaling */
#define BNO055_DIV_SCALE_GYR_DPS (16.0) /**> Gyroscope Raw to deg/s scaling */
#define BNO055_DIV_SCALE_EUL_RAD (900.0) /**> Euler Data Raw to rad scaling */
#define BNO055_DIV_SCALE_EUL_DEG (16) /**> Euler Data Raw to deg scaling */
#define BNO055_DIV_SCALE_QUAT_UN (16384.0) /**> Quaternion data Raw to 0..1 (unit less) scaling */
#define BNO055_DIV_SCALE_TEMP_DC (1.0) /**> Temperature Data Raw to Celsius scaling */
#define BNO055_DIV_SCALE_TEMP_DF (0.5) /**> Temperature Data Raw to Fahrenheid scaling */
#define BNO055_DIV_SCALE_MAG (16.0) /**> Magnetometer Data Raw to microtesla scaling */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#define BNO055_DIV_SCALE_ACC_MSS (100.0) /**> Acceleration Raw to m/s2 scaling */
#define BNO055_DIV_SCALE_ACC_G (1.0) /**> Acceleration Raw to g (9.81m/s2) scaling */
#define BNO055_DIV_SCALE_GYR_RPS (900.0) /**> Gyroscope Raw to rad/s scaling */
#define BNO055_DIV_SCALE_GYR_DPS (16.0) /**> Gyroscope Raw to deg/s scaling */
#define BNO055_DIV_SCALE_EUL_RAD (900.0) /**> Euler Data Raw to rad scaling */
#define BNO055_DIV_SCALE_EUL_DEG (16) /**> Euler Data Raw to deg scaling */
#define BNO055_DIV_SCALE_QUAT_UN (16384.0) /**> Quaternion data Raw to 0..1 (unit less) scaling */
#define BNO055_DIV_SCALE_TEMP_DC (1.0) /**> Temperature Data Raw to Celsius scaling */
#define BNO055_DIV_SCALE_TEMP_DF (0.5) /**> Temperature Data Raw to Fahrenheid scaling */
#define BNO055_DIV_SCALE_MAG (16.0) /**> Magnetometer Data Raw to microtesla scaling */
#define BNO055_DIV_SCALE_ACC_MSS (100.0f) /**> Acceleration Raw to m/s2 scaling */
#define BNO055_DIV_SCALE_ACC_G (1.0f) /**> Acceleration Raw to g (9.81m/s2) scaling */
#define BNO055_DIV_SCALE_GYR_RPS (900.0f) /**> Gyroscope Raw to rad/s scaling */
#define BNO055_DIV_SCALE_GYR_DPS (16.0f) /**> Gyroscope Raw to deg/s scaling */
#define BNO055_DIV_SCALE_EUL_RAD (900.0f) /**> Euler Data Raw to rad scaling */
#define BNO055_DIV_SCALE_EUL_DEG (16f) /**> Euler Data Raw to deg scaling */
#define BNO055_DIV_SCALE_QUAT_UN (16384.0f) /**> Quaternion data Raw to 0..1 (unit less) scaling */
#define BNO055_DIV_SCALE_TEMP_DC (1.0f) /**> Temperature Data Raw to Celsius scaling */
#define BNO055_DIV_SCALE_TEMP_DF (0.5f) /**> Temperature Data Raw to Fahrenheid scaling */
#define BNO055_DIV_SCALE_MAG (16.0f) /**> Magnetometer Data Raw to microtesla scaling */

Comment on lines +334 to +344
/**
* @brief change the current I2C register page
*
* @param[in] dev device descriptor of IMU
* @param[in] page desired page number (0 or 1)
*
* @retval BNO055_OK on success
* @retval BNO055_NOREAD if reading mag data is not possible
* @retval BNO055_NOTRDY if no new data is available
*/
int bno055_set_page(const bno055_t *dev, uint8_t page);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that something that should be exposed to the user?

* @ingroup drivers_saul
* @brief Device driver for the Bosch BNO055 9-axis sensor
*
* This driver provides @ref drivers_saul capabilities.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't provide a bno055_saul.c for that 😉

* @name BNO055 chip id registers and who am I values
* @{
*/
#define BNO055_REG_CHIPID (0x00U) /**> chip id register */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#define BNO055_REG_CHIPID (0x00U) /**> chip id register */
#define BNO055_REG_CHIPID (0x00U) /**< chip id register */

This doxygen issue is present all over the place.
In current master:

$ git grep "/\*\*>" | wc -l
0
git grep "/\*\*<" | wc -l
373126

@benpicco benpicco moved this from Waiting for Maintainer to Waiting for Author in New Drivers Jan 29, 2021
@stale
Copy link

stale bot commented Jun 2, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Jun 2, 2021
@fjmolinas
Copy link
Contributor

@Achilleshiel there seems to be very little missing here, any chance you can take a look at the missing comments?

@stale stale bot removed the State: stale State: The issue / PR has no activity for >185 days label Jun 3, 2021
@MrKevinWeiss MrKevinWeiss added this to the Release 2021.07 milestone Jun 21, 2021
@MrKevinWeiss MrKevinWeiss removed this from the Release 2021.07 milestone Jul 15, 2021
@stale
Copy link

stale bot commented Mar 2, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Mar 2, 2022
@stale stale bot closed this Apr 16, 2022
New Drivers automation moved this from Waiting for Author to Done Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: drivers Area: Device drivers State: stale State: The issue / PR has no activity for >185 days Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
New Drivers
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants