Open TCIII opened 3 months ago
A recommended solution for the Remote I/O error that occurs when attempting to access the AK8963 magnetometer on the mpu9250 imu/magnetometer module is to use the imusensor library in place of the mpu9250-jmdev library,
Additionally, an in-depth tutorial for using the imusensor library with the RPi and the mpu9250 imu/magnetometer can be found here.
Error free access to both the mpu6050 imu and the AK8963 magnetometer when using the imusensor library was validated using the following code snippet:
import os
import sys
import time
import smbus
from imusensor.MPU9250 import MPU9250
address = 0x68
bus = smbus.SMBus(1)
imu = MPU9250.MPU9250(bus, address)
imu.begin()
while True:
imu.readSensor()
imu.computeOrientation()
print ("Accel x: {0} ; Accel y : {1} ; Accel z : {2}".format(imu.AccelVals[0], imu.AccelVals[1], imu.AccelVals[2]))
print ("Gyro x: {0} ; Gyro y : {1} ; Gyro z : {2}".format(imu.GyroVals[0], imu.GyroVals[1], imu.GyroVals[2]))
print ("Mag x: {0} ; Mag y : {1} ; Mag z : {2}".format(imu.MagVals[0], imu.MagVals[1], imu.MagVals[2]))
print ("roll: {0} ; pitch : {1} ; yaw : {2}".format(imu.roll, imu.pitch, imu.yaw))
time.sleep(0.1)
I did have to install the easydict
module, which was not mentioned in the prerequisites, to get the python code to run.
When running this code snippet the CLI displayed uncalibrated imu and magnetometer values without an I/O error. To use the imusensor library with the Donkey Car imu.py part will require a rewrite of the mpu9250 def to remove references to the mpu9250-jmdev library and replace them with the imusensor library.
TCIII
Hardware: RPi 4B 4GB OS: Bullseye DC: v5.0.dev3 MPU: mpu9250 on Robo HAT MM1 at hex address 0x69
IMU configuration in myconfig.py:
Result when running
manage.py drive
from the CLI:Since the mpu9250 is a combination of the mpu6050 imu and the the AK8963 magnetometer, using the mpu6050-raspberrypi library in place of the mpu9250-jmdev library allows error free access to only the mpu6050 imu.
TCIII