Michigan State University Alumn
Robotics | Sensor Fusion | CNCs | Speakers | Woodworking
ROS2 driver for Bosch BNO055 using UART or I2C
Home Page: https://flynneva.github.io/bno055/
License: BSD 3-Clause "New" or "Revised" License
Hey,
given the following structure on my Raspberry Pi 4b running Ubuntu 20.04 Server
myworkspace
└── install
└── log
└── build
└── src
└── bno055
and
cd $myworkspace
source /opt/ros/foxy/setup.bash
colcon build --packages-select bno055
source install/local_setup.bash
ros2 run bno055 bno055 --ros-args --params-file ./src/bno055/bno055/params/bno055_params.yaml
gives me the following error
Traceback (most recent call last):
File "myworkspace/install/bno055/lib/bno055/bno055", line 11, in <module>
load_entry_point('bno055==0.3.0', 'console_scripts', 'bno055')()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 490, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2854, in load_entry_point
return ep.load()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2445, in load
return self.resolve()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2451, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "myworkspace/install/bno055/lib/python3.8/site-packages/bno055/bno055.py", line 37, in <module>
from bno055.sensor.SensorService import SensorService
File "myworkspace/install/bno055/lib/python3.8/site-packages/bno055/sensor/SensorService.py", line 43, in <module>
from example_interfaces.srv import Trigger
ModuleNotFoundError: No module named 'example_interfaces'
Could someone replicate the error? Any advice? example_interfaces
is a standard ROS2 package given by the ROS2 developers, e.g. used in their tutorials, too: see Writing A Simple Py Service And Client.
The bno055/package.xml
looks fine, including as <exec_depend>example_interfaces</exec_depend>
, which I would normally do as <depend>example_interfaces</depend>
, but colcon says it's redundant.
Raspberry Pi Zero 2 W and Pi 3B
Ubuntu 22.04
Ros Humble
Using I2C the topic hz only reaches 48Hz, when set to 100. Can this be improved? With a Pi 5 it reaches 100hz.
Is it possible to retrieve a calibration file and upload it to the IMU every time we start the device again ?
Like in this ros driver section 6
This will generate a calibration file that will be used by the driver.
Thank you !
Hello,
I see that the orientation quaternion output of imu is not normalized : it looks like there is a factor 2**14 applied.
output of ros2 topic echo /bno055/imu
:
header:
stamp:
sec: 0
nanosec: 0
frame_id: bno055
orientation:
x: 535.0
y: -275.0
z: 4725.0
w: -15676.0
orientation_covariance:
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
angular_velocity:
x: -0.07777777777777778
y: -0.027777777777777776
z: -0.2688888888888889
angular_velocity_covariance:
- -1.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
linear_acceleration:
x: 0.061
y: -0.059
z: -0.03
linear_acceleration_covariance:
- -1.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
Is that normal?
Doesn't it cause problem when using with other ROS2 nodes ?
Thank you !
Hello friends. I have read IMU values, however in some case, i want to reset these values to 0. How to make this.
And anyone can explain for me the means of this when i run the service ? what is the purpose of this?
ros2 service call /bno055/calibration_request example_interfaces/srv/Trigger
waiting for service to become available...
requester: making request: example_interfaces.srv.Trigger_Request()
response:
example_interfaces.srv.Trigger_Response(success=True, message="{'accel_offset': {'x': 65516, 'y': 165, 'z': 65512}, 'accel_radius': 1000, 'mag_offset': {'x': 65459, 'y': 65184, 'z': 65400}, 'mag_radius': 702, 'gyro_offset': {'x': 0, 'y': 0, 'z': 1}}")
Thanks
BNO055 sends back BUS_OVER_RUN_ERROR (0x07) over UART.
This seems to be a known issue when performing regular sensor data queries using UART: https://community.bosch-sensortec.com/t5/MEMS-sensors-forum/BNO55-0x07-error-UART/td-p/14765
Therefor this project is currently logging a regular warning regarding this issue:
[WARN] [1610880440.010281061] [bno055]: Receiving sensor data failed with TransmissionException:"READ-request failed with error code 0x7"
If a project does not depend on a strict cyclic sensor data update, it can just ignore the warning. The data will be there for the next query cycle.
As the severity seems to be very low, should we disable the warning logging to prevent console / log pollution?
poetry provides some benefits for managing dependencies and could be used to improve this project
We tried a view BNO055 driver for ROS2 and found a bug in all of them. To adhere to REP 103 the messages have to use SI units.
In this package there are two problems:
1000
where it has to be 100
μT
and not T
the factor hast to be 16000000
and not 16
The linear_acceleration
scale factor is set to 1000
, but has to be 100
.
From the BNO055 Data Sheet:
Unit | Representation |
---|---|
m/s² | 1 m/s² = 100 LSB |
mg | 1 mg = 1 LSB |
Unit | Representation |
---|---|
μT | 1 μT = 16 LSB |
In the end, we decided to use the ros2_bno055_driver from RoverRobotics-archive, because we only have an RPi4 and python is not that performant. Here are our fixes RoverRobotics-archive/ros2_bno055_driver#6. But because this is the upstream repository of ros-foxy-bno055
, it would be beneficial for other to fix it here as well.
add full support to the i2c class. @whatis777's contributions have set us up nicely for this...just need to implement now I think.
looks like someone wrote a cpp ros1 package that already does this...should be able to learn from a lot of the logic:
https://discourse.ros.org/t/new-bno055-i2c-driver-for-ros/7940
Starting >>> bno055
/home/ubuntu/.local/lib/python3.8/site-packages/setuptools/dist.py:717: UserWarning: Usage of dash-separated 'script-dir' will not be supported in future versions. Please use the underscore name 'script_dir' instead
warnings.warn(
/home/ubuntu/.local/lib/python3.8/site-packages/setuptools/dist.py:717: UserWarning: Usage of dash-separated 'install-scripts' will not be supported in future versions. Please use the underscore name 'install_scripts' instead
I believe setup.cfg
should us underscores
[develop]
script_dir=$base/lib/bno055
[install]
install_scripts=$base/lib/bno055
Thanks for implementing I2C!
While testing it - here are the issues.
mkdir -p ~/bno055_ws/src
cd ~/bno055_ws/src/
git clone https://github.com/flynneva/bno055.git
cd ..
colcon build
vi ~/bno055_ws/src/bno055/bno055/params/bno055_params_i2c.yaml - change i2c_bus to 1. Use i2cdetect -y 1
sudo pip3 install smbus
source ~/bno055_ws/install/setup.bash
ros2 run bno055 bno055 --ros-args --params-file ~/bno055_ws/src/bno055/bno055/params/bno055_params_i2c.yaml
Issues:
[INFO] [1673704231.527974952] [bno055]: Initializing parameters
[INFO] [1673704231.595604396] [bno055]: Parameters set to:
[INFO] [1673704231.600864898] [bno055]: ros_topic_prefix: "bno055/"
[INFO] [1673704231.605883787] [bno055]: connection_type: "i2c"
[INFO] [1673704231.611069341] [bno055]: frame_id: "bno055"
[INFO] [1673704231.615995938] [bno055]: data_query_frequency: "100"
[INFO] [1673704231.620986284] [bno055]: calib_status_frequency: "0.1"
[INFO] [1673704231.625980225] [bno055]: operation_mode: "12"
[INFO] [1673704231.630957863] [bno055]: placement_axis_remap: "P2"
[INFO] [1673704231.635912116] [bno055]: acc_factor: "100.0"
[INFO] [1673704231.641059389] [bno055]: mag_factor: "16000000.0"
[INFO] [1673704231.646096194] [bno055]: gyr_factor: "900.0"
[INFO] [1673704231.651560445] [bno055]: set_offsets: "False"
[INFO] [1673704231.656551052] [bno055]: offset_acc: "[65516, 165, 65512]"
[INFO] [1673704231.661637753] [bno055]: radius_acc: "1000"
[INFO] [1673704231.666519402] [bno055]: offset_mag: "[65460, 65182, 637]"
[INFO] [1673704231.671388499] [bno055]: radius_mag: "0"
[INFO] [1673704231.676251398] [bno055]: offset_gyr: "[2, 65535, 65535]"
[INFO] [1673704231.681657785] [bno055]: variance_acc: "[0.017, 0.017, 0.017]"
[INFO] [1673704231.686587142] [bno055]: variance_angular_vel: "[0.04, 0.04, 0.04]"
[INFO] [1673704231.691538791] [bno055]: variance_orientation: "[0.0159, 0.0159, 0.0159]"
[INFO] [1673704231.696669450] [bno055]: variance_mag: "[0.0, 0.0, 0.0]"
[INFO] [1673704231.702505471] [bno055]: ROS node shutdown
[INFO] [1673704231.707485557] [bno055]: No timers to shutdown
Traceback (most recent call last):
File "/home/ros/bno055_ws/install/bno055/lib/bno055/bno055", line 33, in
sys.exit(load_entry_point('bno055===0.4.0.', 'console_scripts', 'bno055')())
File "/home/ros/bno055_ws/install/bno055/lib/python3.10/site-packages/bno055/bno055.py", line 94, in main
node.setup()
File "/home/ros/bno055_ws/install/bno055/lib/python3.10/site-packages/bno055/bno055.py", line 70, in setup
self.param.i2c_bus.value,
AttributeError: 'NodeParameters' object has no attribute 'i2c_bus'
[ros2run]: Process exited with failure 1
ros@turtle:~/bno055_ws$ ros2 run bno055 bno055 --ros-args --params-file ~/bno055_ws/src/bno055/bno055/params/bno055_params_i2c.yaml
[INFO] [1673705369.207049590] [bno055]: Initializing parameters
[INFO] [1673705369.276023821] [bno055]: Parameters set to:
[INFO] [1673705369.280943023] [bno055]: ros_topic_prefix: "bno055/"
[INFO] [1673705369.286472482] [bno055]: connection_type: "i2c"
[INFO] [1673705369.292932198] [bno055]: frame_id: "bno055"
[INFO] [1673705369.302135290] [bno055]: data_query_frequency: "100"
[INFO] [1673705369.308729381] [bno055]: calib_status_frequency: "0.1"
[INFO] [1673705369.314610350] [bno055]: operation_mode: "12"
[INFO] [1673705369.320466214] [bno055]: placement_axis_remap: "P2"
[INFO] [1673705369.328608372] [bno055]: acc_factor: "100.0"
[INFO] [1673705369.336255116] [bno055]: mag_factor: "16000000.0"
[INFO] [1673705369.341144056] [bno055]: gyr_factor: "900.0"
[INFO] [1673705369.346109664] [bno055]: set_offsets: "False"
[INFO] [1673705369.351926934] [bno055]: offset_acc: "[65516, 165, 65512]"
[INFO] [1673705369.358342120] [bno055]: radius_acc: "1000"
[INFO] [1673705369.363342050] [bno055]: offset_mag: "[65460, 65182, 637]"
[INFO] [1673705369.368165418] [bno055]: radius_mag: "0"
[INFO] [1673705369.373985866] [bno055]: offset_gyr: "[2, 65535, 65535]"
[INFO] [1673705369.381897139] [bno055]: variance_acc: "[0.017, 0.017, 0.017]"
[INFO] [1673705369.389718570] [bno055]: variance_angular_vel: "[0.04, 0.04, 0.04]"
[INFO] [1673705369.396823284] [bno055]: variance_orientation: "[0.0159, 0.0159, 0.0159]"
[INFO] [1673705369.403196854] [bno055]: variance_mag: "[0.0, 0.0, 0.0]"
[INFO] [1673705369.467421364] [bno055]: Configuring device...
[INFO] [1673705369.475430866] [bno055]: Current sensor offsets:
[INFO] [1673705369.485973172] [bno055]: Accel offsets (x y z): 136 40 65371
[INFO] [1673705369.493317729] [bno055]: Accel radius: 33768
[INFO] [1673705369.499668956] [bno055]: Mag offsets (x y z): 128 0 0
[INFO] [1673705369.504602168] [bno055]: Mag radius: 128
[INFO] [1673705369.509957669] [bno055]: Gyro offsets (x y z): 129 1 0
[INFO] [1673705369.514781766] [bno055]: Setting device_mode to 12
[INFO] [1673705369.520585339] [bno055]: Bosch BNO055 IMU configuration complete.
[WARN] [1673705369.550428149] [bno055]: Receiving sensor data failed with ZeroDivisionError:"float division by zero"
[WARN] [1673705369.571708020] [bno055]: Receiving sensor data failed with ZeroDivisionError:"float division by zero"
[WARN] [1673705369.593917524] [bno055]: Receiving sensor data failed with ZeroDivisionError:"float division by zero"
Hope this helps.
First of all, many thanks for this repo!
I was trying to set the sensor into IMU
mode with the config file, but it was still functioning in absolute mode.
Then I've taken a look at the code and it turns out that setting operation_mode
is hard-coded to NDOF.
# Set Device to NDOF mode
# data fusion for gyroscope, acceleration sensor and magnetometer enabled
# absolute orientation
if not (self.con.transmit(registers.BNO055_OPR_MODE_ADDR, 1, bytes([registers.OPERATION_MODE_NDOF]))):
self.node.get_logger().warn('Unable to set IMU operation mode into operation mode.')
P.S. I could change it myself and send a PR, just let me know.
There is no locking in I2C implementation. It is an issue if there are several I2C devices and parallel processes. Every I2C read operation contains two independent syscalls. I suggest calling "fcntl.flock". Unfortunately, SMBus package does not provide direct access to I2C file descriptor. Can we use SMBus2 package?
Hello Evan, I have successfully cloned this repository and data is being published. I want to use this in LIO-SAM algorithm but before that I need to calibrate it.
So I have calibrated data separately, I want to ask how can I use this data in your code or were can I add that so that whenever I start your code I get calibrated data.
Or can you suggest me any other way for getting calibrated data directly from your algorithm.
Thank you.
Thanks for your great contribution with an updated ROS2 driver.
Unfortunately it seems the output topic does not contain valid covariance values?
This makes merging this imu's data in a robot_localization node impossible...
Would it be possible to add this?
plugged into a bno055 hitlego cp2104 into USB to uart converter into the USB port into a USB device.
/dev/ttyUSB0 does exist but i needed to delete brltty
I get the error message on both that the device is not connected even when 5volts are going through the device it is also cool at this time with about 1.5v being dropped after passing through the device.
Thank you for your work.
Are you planning to make it work using i2c connection?
Tried using the module and I'm getting the following error:
[bno055]: Communication error: module 'bno055.registers' has no attribute 'START_BYTE_WR'
Looking at registers.py file it indeed does not contain a declaration for START_BYTE_WR
(or READ
also used by Connector.py
) ?
Seems it got removed here so I'm not sure how it's still supposed to work?
Reverted to an older commit and now it runs but now I'm stuck at Configuring device...
but I guess this could be an issue on my end.
[INFO] [1636574878.842770372] [bno055]: Initializing parameters
[INFO] [1636574878.854439565] [bno055]: Parameters set to:
[INFO] [1636574878.856625748] [bno055]: ros_topic_prefix: "bno055/"
[INFO] [1636574878.858723302] [bno055]: connection_type: "uart"
[INFO] [1636574878.860794226] [bno055]: uart_port: "/dev/serial1"
[INFO] [1636574878.862778039] [bno055]: uart_baudrate: "115200"
[INFO] [1636574878.864799852] [bno055]: uart_timeout: "0.1"
[INFO] [1636574878.866828146] [bno055]: frame_id: "imu"
[INFO] [1636574878.868809385] [bno055]: data_query_frequency: "100"
[INFO] [1636574878.870805976] [bno055]: calib_status_frequency: "0.1"
[INFO] [1636574878.872801919] [bno055]: operation_mode: "12"
[INFO] [1636574878.874782028] [bno055]: placement_axis_remap: "P0"
[INFO] [1636574878.876822175] [bno055]: acc_offset: "[65516, 165, 65512]"
[INFO] [1636574878.878812747] [bno055]: mag_offset: "[65460, 65182, 637]"
[INFO] [1636574878.880806115] [bno055]: gyr_offset: "[2, 65535, 65535]"
[INFO] [1636574878.883295502] [bno055]: Opening serial port: "/dev/serial1"...
[INFO] [1636574878.905222001] [bno055]: Configuring device...
running the sensor on ros2-foxy i got this error for all covariance fields:
Receiving sensor data failed with AssertionError:"The 'orientation_covariance' field must be a set or sequence with length 9 and each value of type 'float'"
# TODO: make this an option to publish? imu_raw_msg.orientation_covariance = [ self.param.variance_orientation, 0 , 0, 0, self.param.variance_orientation, 0, 0, 0, self.param.variance_orientation ]
this must be corrected to for all variance msgs:
xx = self.param.variance_orientation.value[0] # struct.unpack('!f', bytes.fromhex(str(self.param.variance_orientation)))[0] yy = self.param.variance_orientation.value[1] # struct.unpack('!f', bytes.fromhex(str(self.param.variance_orientation)))[0] zz = self.param.variance_orientation.value[0] # struct.unpack('!f', bytes.fromhex(str(self.param.variance_orientation)))[0] imu_raw_msg.orientation_covariance = [ xx, 0.0 , 0.0, 0.0, yy, 0.0, 0.0, 0.0, zz ]
Using i2c connection to bno055: After colcon build & source . install/setup.bash, execution error
ubuntu@rp4-ub22h-mt:/bno055_ws$ ros2 launch bno055 bno055.launch.py config:=bno055_params_i2c.yaml/bno055_ws$
[INFO] [launch]: All log files can be found below /home/ubuntu/.ros/log/2024-04-09-20-10-01-391230-rp4-ub22h-mt-4494
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [bno055-1]: process started with pid [4495]
[bno055-1] Traceback (most recent call last):
[bno055-1] File "/home/ubuntu/bno055_ws/install/bno055/lib/bno055/bno055", line 33, in
.
.
[bno055-1] File "/home/ubuntu/bno055_ws/build/bno055/bno055/connectors/uart.py", line 33, in
[bno055-1] import serial
[bno055-1] ModuleNotFoundError: No module named 'serial'
[ERROR] [bno055-1]: process has died [pid 4495, exit code 1, cmd '/home/ubuntu/bno055_ws/install/bno055/lib/bno055/bno055 --ros-args --params-file /home/ubuntu/bno055_ws/install/bno055/share/bno055/config/bno055_params.yaml'].
ubuntu@rp4-ub22h-mt:
Seems config i2c parameter file is ignored and the default serial params yaml is used.
Pi 3B and Zero 2 W
Ubuntu 22.04
Ros Humble
ros2 run bno055 bno055 --ros-args --params-file ./ros2_ws/src/bno055/bno055/params/bno055_params.yaml
[INFO] [1718869957.803336347] [bno055]: Initializing parameters
[INFO] [1718869957.893408861] [bno055]: Parameters set to:
[INFO] [1718869957.902802641] [bno055]: ros_topic_prefix: "bno055/"
[INFO] [1718869957.911990745] [bno055]: connection_type: "uart"
[INFO] [1718869957.921358327] [bno055]: uart_port: "/dev/ttyS0"
[INFO] [1718869957.930839241] [bno055]: uart_baudrate: "115200"
[INFO] [1718869957.940737392] [bno055]: uart_timeout: "0.1"
[INFO] [1718869957.950334712] [bno055]: frame_id: "bno055"
[INFO] [1718869957.959898542] [bno055]: data_query_frequency: "100"
[INFO] [1718869957.969348571] [bno055]: calib_status_frequency: "0.1"
[INFO] [1718869957.978788548] [bno055]: operation_mode: "12"
[INFO] [1718869957.988214047] [bno055]: placement_axis_remap: "P2"
[INFO] [1718869957.998071520] [bno055]: acc_factor: "100.0"
[INFO] [1718869958.007484883] [bno055]: mag_factor: "16000000.0"
[INFO] [1718869958.017044026] [bno055]: gyr_factor: "900.0"
[INFO] [1718869958.026273640] [bno055]: grav_factor: "100.0"
[INFO] [1718869958.035527890] [bno055]: set_offsets: "False"
[INFO] [1718869958.044982086] [bno055]: offset_acc: "[65516, 165, 65512]"
[INFO] [1718869958.054401907] [bno055]: radius_acc: "1000"
[INFO] [1718869958.064082663] [bno055]: offset_mag: "[65460, 65182, 637]"
[INFO] [1718869958.073658004] [bno055]: radius_mag: "0"
[INFO] [1718869958.083114283] [bno055]: offset_gyr: "[2, 65535, 65535]"
[INFO] [1718869958.092448792] [bno055]: variance_acc: "[0.017, 0.017, 0.017]"
[INFO] [1718869958.101737417] [bno055]: variance_angular_vel: "[0.04, 0.04, 0.04]"
[INFO] [1718869958.111175467] [bno055]: variance_orientation: "[0.0159, 0.0159, 0.0159]"
[INFO] [1718869958.120579038] [bno055]: variance_mag: "[0.0, 0.0, 0.0]"
[INFO] [1718869958.131411400] [bno055]: Opening serial port: "/dev/ttyS0"...
[INFO] [1718869958.226212471] [bno055]: Configuring device...
[ERROR] [1718869958.336322639] [bno055]: Communication error: Wrong READ-request response header 0xdb
[ERROR] [1718869958.346387663] [bno055]: Shutting down ROS node...
[INFO] [1718869958.357300962] [bno055]: ROS node shutdown
[INFO] [1718869958.366553909] [bno055]: No timers to shutdown
[ros2run]: Process exited with failure 1
Any help would be appreciated.
we should probably move towards a composable node rather than the current structure.
read more here:
https://index.ros.org/doc/ros2/Tutorials/Composition/
Hello! I have tried to calibrate my bno055 device, but the system is always wait for service, also I didn't see the srv folder in the repo, is that in another package? Thx.
See if switching to pydantic for some of the classes could help us at all. Maybe use some validators as well
Hello,
I have bumped into the following issue when trying to connect to the BNO055. I made sure it properly works beforehand by using a small Arduino snippet and it does.
I get the following message when running the node configured with the yaml file.
CP2104 and connections work properly and the tty/USB0 port is properly attached:
I am using Ubuntu 22.04 with ROS2 Humble and all the libraries required to run the driver are installed.
The only parameter changed is the baudrate due to my requirements:
Has anyone bumped into this issue before? Any advice on how to proceed? The response header 0xff does not give me enough information to deal with it.
During my tests using the BNO055, I noticed that when I change the register to select the output data units (UNIT_SEL - 0x3B), the data published in the topics remains with same units (i.e., when I change the bit4 of the register the temperature published should change from Celsius to Fahrenheit, but it stays publishing in the same unit).
bno055/bno055/sensor/SensorService.py
Line 93 in 45e1ff1
I was changing the register in this part of the code, am I changing it on the wrong place?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.