diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..b68a9e4 --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,32 @@ +name: Generate Documentation + +on: + push: + branches: + - main +jobs: + generate_docs: + runs-on: [ubuntu-latest] + steps: + - name: setup directories + run: mkdir -p ~/ros_ws/src/bno055 + - name: checkout + uses: actions/checkout@v2 + with: + path: ~/ros_ws/src/bno055 + - name: setup ROS environment + uses: flynneva/setup-ros@master + with: + use-ros2-testing: true + required-ros-distributions: rolling + - name: build documentation + uses: ammaraskar/sphinx-action@master + with: + docs-folder: "~/ros_ws/src/bno055/docs/" + pre-build-command: "apt-get update -y && pip3 install -r ~/ros_ws/src/bno055/requirements.txt && pip3 install sphinxcontrib-napoleon" + build-command: '"source /opt/ros/rolling/setup.bash" && "sphinx-build -b html . ./html/"' + - name: deploy + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ~/ros_ws/src/bno055/docs/html/ diff --git a/.gitignore b/.gitignore index f830815..362817b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /bno055.iml /venv .vscode/ +docs/html diff --git a/bno055/bno055.py b/bno055/bno055.py index a8a470b..d69ec64 100755 --- a/bno055/bno055.py +++ b/bno055/bno055.py @@ -40,7 +40,13 @@ class Bno055Node(Node): - """ROS2 Node for interfacing Bosch Bno055 IMU sensor.""" + """ + ROS2 Node for interfacing Bosch Bno055 IMU sensor. + + :param Node: ROS2 Node Class to initialize from + :type Node: ROS2 Node + :raises NotImplementedError: Indicates feature/function is not implemented yet. + """ sensor = None param = None diff --git a/bno055/registers.py b/bno055/registers.py index 7243b0d..e5e213b 100644 --- a/bno055/registers.py +++ b/bno055/registers.py @@ -27,75 +27,214 @@ # POSSIBILITY OF SUCH DAMAGE. -# BOSCH BNO055 IMU Registers map and other information -# Page 0 registers -CHIP_ID = 0x00 -PAGE_ID = 0x07 -ACCEL_DATA = 0x08 -MAG_DATA = 0x0e -GYRO_DATA = 0x14 -FUSED_EULER = 0x1a -FUSED_QUAT = 0x20 -LIA_DATA = 0x28 -GRAVITY_DATA = 0x2e -TEMP_DATA = 0x34 -CALIB_STAT = 0x35 -SYS_STATUS = 0x39 -SYS_ERR = 0x3a -UNIT_SEL = 0x3b -OPER_MODE = 0x3d -PWR_MODE = 0x3e -SYS_TRIGGER = 0x3f -TEMP_SOURCE = 0x440 -AXIS_MAP_CONFIG = 0x41 -AXIS_MAP_SIGN = 0x42 - -ACC_OFFSET = 0x55 -MAG_OFFSET = 0x5b -GYR_OFFSET = 0x61 -ACC_RADIUS = 0x68 -MAG_RADIUS = 0x69 - -# Page 1 registers -ACC_CONFIG = 0x08 -MAG_CONFIG = 0x09 -GYR_CONFIG0 = 0x0a -GYR_CONFIG1 = 0x0b - -# Operation modes -OPER_MODE_CONFIG = 0x00 -OPER_MODE_ACCONLY = 0x01 -OPER_MODE_MAGONLY = 0x02 -OPER_MODE_GYROONLY = 0x03 -OPER_MODE_ACCMAG = 0x04 -OPER_MODE_ACCGYRO = 0x05 -OPER_MODE_MAGGYRO = 0x06 -OPER_MODE_AMG = 0x07 -OPER_MODE_IMU = 0x08 -OPER_MODE_COMPASS = 0x09 -OPER_MODE_M4G = 0x0a -OPER_MODE_NDOF_FMC_OFF = 0x0b -OPER_MODE_NDOF = 0x0C - -# Power modes -PWR_MODE_NORMAL = 0x00 -PWR_MODE_LOW = 0x01 -PWR_MODE_SUSPEND = 0x02 - -# Communication constants -BNO055_ID = 0xa0 -START_BYTE_WR = 0xaa -START_BYTE_RESP = 0xbb -START_BYTE_ERROR_RESP = 0xee -READ = 0x01 -WRITE = 0x00 - -# Default calibration values (taken from desk test approximation.) [x y z] -# Signed hex 16 bit representation - -# +/- 2000 units (at max 2G) (1 unit = 1 mg = 1 LSB = 0.01 m/s2) +# Adafruit BNO055 Absolute Orientation Sensor Library +# Copyright (c) 2015 Adafruit Industries +# Author: Tony DiCola +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + + +#: I2C addresses +BNO055_ADDRESS_A = 0x28 +BNO055_ADDRESS_B = 0x29 +BNO055_ID = 0xA0 + +#: Page id register definition +BNO055_PAGE_ID_ADDR = 0X07 + +#: PAGE0 REGISTER DEFINITION START +BNO055_CHIP_ID_ADDR = 0x00 +BNO055_ACCEL_REV_ID_ADDR = 0x01 +BNO055_MAG_REV_ID_ADDR = 0x02 +BNO055_GYRO_REV_ID_ADDR = 0x03 +BNO055_SW_REV_ID_LSB_ADDR = 0x04 +BNO055_SW_REV_ID_MSB_ADDR = 0x05 +BNO055_BL_REV_ID_ADDR = 0X06 + +#: Accel data register +BNO055_ACCEL_DATA_X_LSB_ADDR = 0X08 +BNO055_ACCEL_DATA_X_MSB_ADDR = 0X09 +BNO055_ACCEL_DATA_Y_LSB_ADDR = 0X0A +BNO055_ACCEL_DATA_Y_MSB_ADDR = 0X0B +BNO055_ACCEL_DATA_Z_LSB_ADDR = 0X0C +BNO055_ACCEL_DATA_Z_MSB_ADDR = 0X0D + +#: Mag data register +BNO055_MAG_DATA_X_LSB_ADDR = 0X0E +BNO055_MAG_DATA_X_MSB_ADDR = 0X0F +BNO055_MAG_DATA_Y_LSB_ADDR = 0X10 +BNO055_MAG_DATA_Y_MSB_ADDR = 0X11 +BNO055_MAG_DATA_Z_LSB_ADDR = 0X12 +BNO055_MAG_DATA_Z_MSB_ADDR = 0X13 + +#: Gyro data registers +BNO055_GYRO_DATA_X_LSB_ADDR = 0X14 +BNO055_GYRO_DATA_X_MSB_ADDR = 0X15 +BNO055_GYRO_DATA_Y_LSB_ADDR = 0X16 +BNO055_GYRO_DATA_Y_MSB_ADDR = 0X17 +BNO055_GYRO_DATA_Z_LSB_ADDR = 0X18 +BNO055_GYRO_DATA_Z_MSB_ADDR = 0X19 + +#: Euler data registers +BNO055_EULER_H_LSB_ADDR = 0X1A +BNO055_EULER_H_MSB_ADDR = 0X1B +BNO055_EULER_R_LSB_ADDR = 0X1C +BNO055_EULER_R_MSB_ADDR = 0X1D +BNO055_EULER_P_LSB_ADDR = 0X1E +BNO055_EULER_P_MSB_ADDR = 0X1F + +#: Quaternion data registers +BNO055_QUATERNION_DATA_W_LSB_ADDR = 0X20 +BNO055_QUATERNION_DATA_W_MSB_ADDR = 0X21 +BNO055_QUATERNION_DATA_X_LSB_ADDR = 0X22 +BNO055_QUATERNION_DATA_X_MSB_ADDR = 0X23 +BNO055_QUATERNION_DATA_Y_LSB_ADDR = 0X24 +BNO055_QUATERNION_DATA_Y_MSB_ADDR = 0X25 +BNO055_QUATERNION_DATA_Z_LSB_ADDR = 0X26 +BNO055_QUATERNION_DATA_Z_MSB_ADDR = 0X27 + +#: Linear acceleration data registers +BNO055_LINEAR_ACCEL_DATA_X_LSB_ADDR = 0X28 +BNO055_LINEAR_ACCEL_DATA_X_MSB_ADDR = 0X29 +BNO055_LINEAR_ACCEL_DATA_Y_LSB_ADDR = 0X2A +BNO055_LINEAR_ACCEL_DATA_Y_MSB_ADDR = 0X2B +BNO055_LINEAR_ACCEL_DATA_Z_LSB_ADDR = 0X2C +BNO055_LINEAR_ACCEL_DATA_Z_MSB_ADDR = 0X2D + +#: Gravity data registers +BNO055_GRAVITY_DATA_X_LSB_ADDR = 0X2E +BNO055_GRAVITY_DATA_X_MSB_ADDR = 0X2F +BNO055_GRAVITY_DATA_Y_LSB_ADDR = 0X30 +BNO055_GRAVITY_DATA_Y_MSB_ADDR = 0X31 +BNO055_GRAVITY_DATA_Z_LSB_ADDR = 0X32 +BNO055_GRAVITY_DATA_Z_MSB_ADDR = 0X33 + +#: Temperature data register +BNO055_TEMP_ADDR = 0X34 + +#: Status registers +BNO055_CALIB_STAT_ADDR = 0X35 +BNO055_SELFTEST_RESULT_ADDR = 0X36 +BNO055_INTR_STAT_ADDR = 0X37 + +BNO055_SYS_CLK_STAT_ADDR = 0X38 +BNO055_SYS_STAT_ADDR = 0X39 +BNO055_SYS_ERR_ADDR = 0X3A + +#: Unit selection register +BNO055_UNIT_SEL_ADDR = 0X3B +BNO055_DATA_SELECT_ADDR = 0X3C + +#: Mode registers +BNO055_OPR_MODE_ADDR = 0X3D +BNO055_PWR_MODE_ADDR = 0X3E + +BNO055_SYS_TRIGGER_ADDR = 0X3F +BNO055_TEMP_SOURCE_ADDR = 0X40 + +#: Axis remap registers +BNO055_AXIS_MAP_CONFIG_ADDR = 0X41 +BNO055_AXIS_MAP_SIGN_ADDR = 0X42 + +#: Axis remap values +AXIS_REMAP_X = 0x00 +AXIS_REMAP_Y = 0x01 +AXIS_REMAP_Z = 0x02 +AXIS_REMAP_POSITIVE = 0x00 +AXIS_REMAP_NEGATIVE = 0x01 + +#: SIC registers +BNO055_SIC_MATRIX_0_LSB_ADDR = 0X43 +BNO055_SIC_MATRIX_0_MSB_ADDR = 0X44 +BNO055_SIC_MATRIX_1_LSB_ADDR = 0X45 +BNO055_SIC_MATRIX_1_MSB_ADDR = 0X46 +BNO055_SIC_MATRIX_2_LSB_ADDR = 0X47 +BNO055_SIC_MATRIX_2_MSB_ADDR = 0X48 +BNO055_SIC_MATRIX_3_LSB_ADDR = 0X49 +BNO055_SIC_MATRIX_3_MSB_ADDR = 0X4A +BNO055_SIC_MATRIX_4_LSB_ADDR = 0X4B +BNO055_SIC_MATRIX_4_MSB_ADDR = 0X4C +BNO055_SIC_MATRIX_5_LSB_ADDR = 0X4D +BNO055_SIC_MATRIX_5_MSB_ADDR = 0X4E +BNO055_SIC_MATRIX_6_LSB_ADDR = 0X4F +BNO055_SIC_MATRIX_6_MSB_ADDR = 0X50 +BNO055_SIC_MATRIX_7_LSB_ADDR = 0X51 +BNO055_SIC_MATRIX_7_MSB_ADDR = 0X52 +BNO055_SIC_MATRIX_8_LSB_ADDR = 0X53 +BNO055_SIC_MATRIX_8_MSB_ADDR = 0X54 + +#: Accelerometer Offset registers +ACCEL_OFFSET_X_LSB_ADDR = 0X55 +ACCEL_OFFSET_X_MSB_ADDR = 0X56 +ACCEL_OFFSET_Y_LSB_ADDR = 0X57 +ACCEL_OFFSET_Y_MSB_ADDR = 0X58 +ACCEL_OFFSET_Z_LSB_ADDR = 0X59 +ACCEL_OFFSET_Z_MSB_ADDR = 0X5A + +#: Magnetometer Offset registers +MAG_OFFSET_X_LSB_ADDR = 0X5B +MAG_OFFSET_X_MSB_ADDR = 0X5C +MAG_OFFSET_Y_LSB_ADDR = 0X5D +MAG_OFFSET_Y_MSB_ADDR = 0X5E +MAG_OFFSET_Z_LSB_ADDR = 0X5F +MAG_OFFSET_Z_MSB_ADDR = 0X60 + +#: Gyroscope Offset register s +GYRO_OFFSET_X_LSB_ADDR = 0X61 +GYRO_OFFSET_X_MSB_ADDR = 0X62 +GYRO_OFFSET_Y_LSB_ADDR = 0X63 +GYRO_OFFSET_Y_MSB_ADDR = 0X64 +GYRO_OFFSET_Z_LSB_ADDR = 0X65 +GYRO_OFFSET_Z_MSB_ADDR = 0X66 + +#: Radius registers +ACCEL_RADIUS_LSB_ADDR = 0X67 +ACCEL_RADIUS_MSB_ADDR = 0X68 +MAG_RADIUS_LSB_ADDR = 0X69 +MAG_RADIUS_MSB_ADDR = 0X6A + +#: Power modes +POWER_MODE_NORMAL = 0X00 +POWER_MODE_LOWPOWER = 0X01 +POWER_MODE_SUSPEND = 0X02 + +#: Operation mode settings +OPERATION_MODE_CONFIG = 0X00 +OPERATION_MODE_ACCONLY = 0X01 +OPERATION_MODE_MAGONLY = 0X02 +OPERATION_MODE_GYRONLY = 0X03 +OPERATION_MODE_ACCMAG = 0X04 +OPERATION_MODE_ACCGYRO = 0X05 +OPERATION_MODE_MAGGYRO = 0X06 +OPERATION_MODE_AMG = 0X07 +OPERATION_MODE_IMUPLUS = 0X08 +OPERATION_MODE_COMPASS = 0X09 +OPERATION_MODE_M4G = 0X0A +OPERATION_MODE_NDOF_FMC_OFF = 0X0B +OPERATION_MODE_NDOF = 0X0C + +#: Default calibration values (taken from desk test approximation.) [x y z] +#: Signed hex 16 bit representation + +#: +/- 2000 units (at max 2G) (1 unit = 1 mg = 1 LSB = 0.01 m/s2) ACC_OFFSET_DEFAULT = [0xFFEC, 0x00A5, 0xFFE8] -# +/- 6400 units (1 unit = 1/16 uT) +#: +/- 6400 units (1 unit = 1/16 uT) MAG_OFFSET_DEFAULT = [0xFFB4, 0xFE9E, 0x027D] -# +/- 2000 units up to 32000 (dps range dependent) (1 unit = 1/16 dps) +#: +/- 2000 units up to 32000 (dps range dependent) (1 unit = 1/16 dps) GYR_OFFSET_DEFAULT = [0x0002, 0xFFFF, 0xFFFF] diff --git a/bno055/sensor/SensorService.py b/bno055/sensor/SensorService.py index 1459a44..4fdf3fd 100644 --- a/bno055/sensor/SensorService.py +++ b/bno055/sensor/SensorService.py @@ -64,7 +64,7 @@ def configure(self): """Configure the IMU sensor hardware.""" self.node.get_logger().info('Configuring device...') try: - data = self.con.receive(registers.CHIP_ID, 1) + data = self.con.receive(registers.BNO055_CHIP_ID_ADDR, 1) if data[0] != registers.BNO055_ID: raise IOError('Device ID=%s is incorrect' % data) # print("device sent ", binascii.hexlify(data)) @@ -75,19 +75,19 @@ def configure(self): sys.exit(1) # IMU connected => apply IMU Configuration: - if not (self.con.transmit(registers.OPER_MODE, 1, bytes([registers.OPER_MODE_CONFIG]))): + if not (self.con.transmit(registers.BNO055_OPR_MODE_ADDR, 1, bytes([registers.OPERATION_MODE_CONFIG]))): self.node.get_logger().warn('Unable to set IMU into config mode.') - if not (self.con.transmit(registers.PWR_MODE, 1, bytes([registers.PWR_MODE_NORMAL]))): + if not (self.con.transmit(registers.BNO055_PWR_MODE_ADDR, 1, bytes([registers.POWER_MODE_NORMAL]))): self.node.get_logger().warn('Unable to set IMU normal power mode.') - if not (self.con.transmit(registers.PAGE_ID, 1, bytes([0x00]))): + if not (self.con.transmit(registers.BNO055_PAGE_ID_ADDR, 1, bytes([0x00]))): self.node.get_logger().warn('Unable to set IMU register page 0.') - if not (self.con.transmit(registers.SYS_TRIGGER, 1, bytes([0x00]))): + if not (self.con.transmit(registers.BNO055_SYS_TRIGGER_ADDR, 1, bytes([0x00]))): self.node.get_logger().warn('Unable to start IMU.') - if not (self.con.transmit(registers.UNIT_SEL, 1, bytes([0x83]))): + if not (self.con.transmit(registers.BNO055_UNIT_SEL_ADDR, 1, bytes([0x83]))): self.node.get_logger().warn('Unable to set IMU units.') # The sensor placement configuration (Axis remapping) defines the @@ -103,14 +103,14 @@ def configure(self): 'P6': bytes(b'\x21\x07'), 'P7': bytes(b'\x24\x05') } - if not (self.con.transmit(registers.AXIS_MAP_CONFIG, 2, + if not (self.con.transmit(registers.BNO055_AXIS_MAP_CONFIG_ADDR, 2, mount_positions[self.param.placement_axis_remap.value])): self.node.get_logger().warn('Unable to set sensor placement configuration.') # Set Device to NDOF mode # data fusion for gyroscope, acceleration sensor and magnetometer enabled # absolute orientation - if not (self.con.transmit(registers.OPER_MODE, 1, bytes([registers.OPER_MODE_NDOF]))): + 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.') self.node.get_logger().info('Bosch BNO055 IMU configuration complete.') @@ -129,7 +129,7 @@ def get_sensor_data(self): gyr_fact = 900.0 # read from sensor - buf = self.con.receive(registers.ACCEL_DATA, 45) + buf = self.con.receive(registers.BNO055_ACCEL_DATA_X_LSB_ADDR, 45) # Publish raw data # TODO: convert rcl Clock time to ros time? # imu_raw_msg.header.stamp = node.get_clock().now() @@ -216,7 +216,7 @@ def get_calib_status(self): Quality scale: 0 = bad, 3 = best """ - calib_status = self.con.receive(registers.CALIB_STAT, 1) + calib_status = self.con.receive(registers.BNO055_CALIB_STAT_ADDR, 1) sys = (calib_status[0] >> 6) & 0x03 gyro = (calib_status[0] >> 4) & 0x03 accel = (calib_status[0] >> 2) & 0x03 @@ -232,7 +232,7 @@ def get_calib_status(self): def get_calib_offsets(self): """Read all calibration offsets and print to screen.""" - accel_offset_read = self.con.receive(registers.ACC_OFFSET, 6) + accel_offset_read = self.con.receive(registers.ACCEL_OFFSET_X_LSB_ADDR, 6) accel_offset_read_x = (accel_offset_read[1] << 8) | accel_offset_read[ 0] # Combine MSB and LSB registers into one decimal accel_offset_read_y = (accel_offset_read[3] << 8) | accel_offset_read[ @@ -240,7 +240,7 @@ def get_calib_offsets(self): accel_offset_read_z = (accel_offset_read[5] << 8) | accel_offset_read[ 4] # Combine MSB and LSB registers into one decimal - mag_offset_read = self.con.receive(registers.MAG_OFFSET, 6) + mag_offset_read = self.con.receive(registers.MAG_OFFSET_X_LSB_ADDR, 6) mag_offset_read_x = (mag_offset_read[1] << 8) | mag_offset_read[ 0] # Combine MSB and LSB registers into one decimal mag_offset_read_y = (mag_offset_read[3] << 8) | mag_offset_read[ @@ -248,7 +248,7 @@ def get_calib_offsets(self): mag_offset_read_z = (mag_offset_read[5] << 8) | mag_offset_read[ 4] # Combine MSB and LSB registers into one decimal - gyro_offset_read = self.con.receive(registers.GYR_OFFSET, 6) + gyro_offset_read = self.con.receive(registers.GYRO_OFFSET_X_LSB_ADDR, 6) gyro_offset_read_x = (gyro_offset_read[1] << 8) | gyro_offset_read[ 0] # Combine MSB and LSB registers into one decimal gyro_offset_read_y = (gyro_offset_read[3] << 8) | gyro_offset_read[ @@ -283,32 +283,32 @@ def set_calib_offsets(self, acc_offset, mag_offset, gyr_offset): :param gyr_offset: """ # Must switch to config mode to write out - if not (self.con.transmit(registers.OPER_MODE, 1, bytes([registers.OPER_MODE_CONFIG]))): + if not (self.con.transmit(registers.BNO055_OPR_MODE_ADDR, 1, bytes([registers.OPERATION_MODE_CONFIG]))): self.node.get_logger().error('Unable to set IMU into config mode') time.sleep(0.025) # Seems to only work when writing 1 register at a time try: - self.con.transmit(registers.ACC_OFFSET, 1, bytes([acc_offset[0] & 0xFF])) - self.con.transmit(registers.ACC_OFFSET + 1, 1, bytes([(acc_offset[0] >> 8) & 0xFF])) - self.con.transmit(registers.ACC_OFFSET + 2, 1, bytes([acc_offset[1] & 0xFF])) - self.con.transmit(registers.ACC_OFFSET + 3, 1, bytes([(acc_offset[1] >> 8) & 0xFF])) - self.con.transmit(registers.ACC_OFFSET + 4, 1, bytes([acc_offset[2] & 0xFF])) - self.con.transmit(registers.ACC_OFFSET + 5, 1, bytes([(acc_offset[2] >> 8) & 0xFF])) - - self.con.transmit(registers.MAG_OFFSET, 1, bytes([mag_offset[0] & 0xFF])) - self.con.transmit(registers.MAG_OFFSET + 1, 1, bytes([(mag_offset[0] >> 8) & 0xFF])) - self.con.transmit(registers.MAG_OFFSET + 2, 1, bytes([mag_offset[1] & 0xFF])) - self.con.transmit(registers.MAG_OFFSET + 3, 1, bytes([(mag_offset[1] >> 8) & 0xFF])) - self.con.transmit(registers.MAG_OFFSET + 4, 1, bytes([mag_offset[2] & 0xFF])) - self.con.transmit(registers.MAG_OFFSET + 5, 1, bytes([(mag_offset[2] >> 8) & 0xFF])) - - self.con.transmit(registers.GYR_OFFSET, 1, bytes([gyr_offset[0] & 0xFF])) - self.con.transmit(registers.GYR_OFFSET + 1, 1, bytes([(gyr_offset[0] >> 8) & 0xFF])) - self.con.transmit(registers.GYR_OFFSET + 2, 1, bytes([gyr_offset[1] & 0xFF])) - self.con.transmit(registers.GYR_OFFSET + 3, 1, bytes([(gyr_offset[1] >> 8) & 0xFF])) - self.con.transmit(registers.GYR_OFFSET + 4, 1, bytes([gyr_offset[2] & 0xFF])) - self.con.transmit(registers.GYR_OFFSET + 5, 1, bytes([(gyr_offset[2] >> 8) & 0xFF])) + self.con.transmit(registers.ACCEL_OFFSET_X_LSB_ADDR, 1, bytes([acc_offset[0] & 0xFF])) + self.con.transmit(registers.ACCEL_OFFSET_X_MSB_ADDR, 1, bytes([(acc_offset[0] >> 8) & 0xFF])) + self.con.transmit(registers.ACCEL_OFFSET_Y_LSB_ADDR, 1, bytes([acc_offset[1] & 0xFF])) + self.con.transmit(registers.ACCEL_OFFSET_Y_MSB_ADDR, 1, bytes([(acc_offset[1] >> 8) & 0xFF])) + self.con.transmit(registers.ACCEL_OFFSET_Z_LSB_ADDR, 1, bytes([acc_offset[2] & 0xFF])) + self.con.transmit(registers.ACCEL_OFFSET_Z_MSB_ADDR, 1, bytes([(acc_offset[2] >> 8) & 0xFF])) + + self.con.transmit(registers.MAG_OFFSET_X_LSB_ADDR, 1, bytes([mag_offset[0] & 0xFF])) + self.con.transmit(registers.MAG_OFFSET_X_MSB_ADDR, 1, bytes([(mag_offset[0] >> 8) & 0xFF])) + self.con.transmit(registers.MAG_OFFSET_Y_LSB_ADDR, 1, bytes([mag_offset[1] & 0xFF])) + self.con.transmit(registers.MAG_OFFSET_Y_MSB_ADDR, 1, bytes([(mag_offset[1] >> 8) & 0xFF])) + self.con.transmit(registers.MAG_OFFSET_Z_LSB_ADDR, 1, bytes([mag_offset[2] & 0xFF])) + self.con.transmit(registers.MAG_OFFSET_Z_MSB_ADDR, 1, bytes([(mag_offset[2] >> 8) & 0xFF])) + + self.con.transmit(registers.GYRO_OFFSET_X_LSB_ADDR, 1, bytes([gyr_offset[0] & 0xFF])) + self.con.transmit(registers.GYRO_OFFSET_X_MSB_ADDR, 1, bytes([(gyr_offset[0] >> 8) & 0xFF])) + self.con.transmit(registers.GYRO_OFFSET_Y_LSB_ADDR, 1, bytes([gyr_offset[1] & 0xFF])) + self.con.transmit(registers.GYRO_OFFSET_Y_MSB_ADDR, 1, bytes([(gyr_offset[1] >> 8) & 0xFF])) + self.con.transmit(registers.GYRO_OFFSET_Z_LSB_ADDR, 1, bytes([gyr_offset[2] & 0xFF])) + self.con.transmit(registers.GYRO_OFFSET_Z_MSB_ADDR, 1, bytes([(gyr_offset[2] >> 8) & 0xFF])) return True except Exception: # noqa: B902 return False diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..5128596 --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,19 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/bno055.rst b/docs/bno055.rst new file mode 100644 index 0000000..179e031 --- /dev/null +++ b/docs/bno055.rst @@ -0,0 +1,7 @@ +bno055 +==================================== + +TEST + +.. automodule:: bno055.bno055 + :members: diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..9b7cf7e --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,183 @@ +# -*- coding: utf-8 -*- +# +# Configuration file for the Sphinx documentation builder. +# +# This file does only contain a selection of the most common options. For a +# full list see the documentation: +# http://www.sphinx-doc.org/en/master/config + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +import os +import sys +sys.path.insert(0, os.path.abspath('../')) + +print(os.path.abspath('../')) + +# -- Project information ----------------------------------------------------- + +project = 'bno055' +copyright = '2021, Evan Flynn, Manfred Novotny' +author = 'Evan Flynn, Manfred Novotny' + +# The short X.Y version +version = '' +# The full version, including alpha/beta/rc tags +release = '0.1.1' + + +# -- General configuration --------------------------------------------------- + +# If your documentation needs a minimal Sphinx version, state it here. +# +# needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + 'sphinx.ext.autodoc', + 'sphinx.ext.autosummary', + 'sphinx.ext.coverage', + 'sphinx.ext.imgmath', + 'sphinx.ext.viewcode', + 'sphinx.ext.githubpages', +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# +# source_suffix = ['.rst', '.md'] +source_suffix = '.rst' + +# The master toctree document. +master_doc = 'index' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = 'en' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = None + + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = 'alabaster' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +# +# html_theme_options = {} + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +# html_static_path = ['_static'] + +# Custom sidebar templates, must be a dictionary that maps document names +# to template names. +# +# The default sidebars (for documents that don't match any pattern) are +# defined by theme itself. Builtin themes are using these templates by +# default: ``['localtoc.html', 'relations.html', 'sourcelink.html', +# 'searchbox.html']``. +# +# html_sidebars = {} + + +# -- Options for HTMLHelp output --------------------------------------------- + +# Output file base name for HTML help builder. +htmlhelp_basename = 'bno055doc' + + +# -- Options for LaTeX output ------------------------------------------------ + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + (master_doc, 'bno055.tex', 'bno055 Documentation', + 'Evan Flynn, Manfred Novotny', 'manual'), +] + + +# -- Options for manual page output ------------------------------------------ + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + (master_doc, 'bno055', 'bno055 Documentation', + [author], 1) +] + + +# -- Options for Texinfo output ---------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + (master_doc, 'bno055', 'bno055 Documentation', + author, 'bno055', 'One line description of project.', + 'Miscellaneous'), +] + + +# -- Options for Epub output ------------------------------------------------- + +# Bibliographic Dublin Core info. +epub_title = project + +# The unique identifier of the text. This can be a ISBN number +# or the project homepage. +# +# epub_identifier = '' + +# A unique identification for the text. +# +# epub_uid = '' + +# A list of files that should not be packed into the epub file. +epub_exclude_files = ['search.html'] + + +# -- Extension configuration ------------------------------------------------- diff --git a/docs/connectors.rst b/docs/connectors.rst new file mode 100644 index 0000000..6f6dd46 --- /dev/null +++ b/docs/connectors.rst @@ -0,0 +1,15 @@ +connectors +==================================== + +.. automodule:: bno055.connectors.Connector + :members: + :show-inheritance: + +.. automodule:: bno055.connectors.uart + :members: + :show-inheritance: + +.. automodule:: bno055.connectors.i2c + :members: + :show-inheritance: + diff --git a/docs/error_handling.rst b/docs/error_handling.rst new file mode 100644 index 0000000..77d3883 --- /dev/null +++ b/docs/error_handling.rst @@ -0,0 +1,5 @@ +error_handling +==================================== + +.. automodule:: bno055.error_handling.exceptions + :members: diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..be7eefb --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,27 @@ +.. bno055 documentation master file, created by + sphinx-quickstart on Mon Feb 8 19:58:23 2021. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome +================================== + +A ROS2 driver for the sensor IMU Bosch BNO055. + +.. toctree:: + :maxdepth: 4 + :caption: Contents: + + bno055 + connectors + error_handling + params + sensor + registers + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..27f573b --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +if "%1" == "" goto help + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% + +:end +popd diff --git a/docs/params.rst b/docs/params.rst new file mode 100644 index 0000000..8a8b3d0 --- /dev/null +++ b/docs/params.rst @@ -0,0 +1,5 @@ +params +==================================== + +.. automodule:: bno055.params.NodeParameters + :members: diff --git a/docs/registers.rst b/docs/registers.rst new file mode 100644 index 0000000..4b16bcb --- /dev/null +++ b/docs/registers.rst @@ -0,0 +1,5 @@ +registers +==================================== + +.. automodule:: bno055.registers + :members: diff --git a/docs/sensor.rst b/docs/sensor.rst new file mode 100644 index 0000000..a1003f1 --- /dev/null +++ b/docs/sensor.rst @@ -0,0 +1,5 @@ +sensor +==================================== + +.. automodule:: bno055.sensor.SensorService + :members: diff --git a/requirements.txt b/requirements.txt index 47aa445..7326add 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,4 @@ # Automatically generated by https://github.com/damnever/pigar. -# bno055/bno055.py: 42 -#serial == 0.0.97 - -# bno055/setup.py: 1 -#setuptools == 45.2.0 +# bno055/bno055/connectors/uart.py: 36 +pyserial == 3.4