sparkfun / SparkFun_ICM-20948_ArduinoLibrary

Arduino support for ICM_20948 w/ portable C backbone
Other
168 stars 72 forks source link

How to handle physical orientation of ICM20948 when calculating Roll and Pitch used for leveling #66

Closed Bascy closed 3 years ago

Bascy commented 3 years ago

We are creating a device based on a ESP32 and an ICM20948, using 4 actuators to physically level out platforms.

The actuators are activated based on the Roll and Pitch that is calculated from the output of the ICM20948. For the calculation of the Roll and Pitch, we "borrowed" code from the internet (https://en.wikipedia.org/w/index.php?title=Conversion_between_quaternions_and_Euler_angles&section=8#Source_code_2 ), incoorporated in the examples by @PaulZC as I understand)

We are technically schooled but no mathematicians and do not really understand what it's doing ... but its working :)

The actuators are on a well known location on the platform, so we know that if i.e. Roll = 10 that we need to extend the forward and backward actuators on the right of the platform to get the Roll to become smaller.

The problem now arrises that the way that our device is mounted on the platform can vary between installations, the ICM will not always be mounted parallel to the top surface of the platform, but can be mounted in any orientation (we can assume that it will only be 90degree rotations, so the Roll or Pitch axis can point forward, left, backwrd, right, up or down in regards to the platform.)

Our question is how can we add a configuration specifiying the mounted orientation, and (more importantly) use that configuration to get the right Roll and Pitch angles of the platform to steer the correct actuators.

Any help or reference to other sources would be welcome.

Thanks!

PaulZC commented 3 years ago

Hi @Bascy ,

This question is a little off topic. We use GitHub issues to address problems / bugs in the library itself. For more general questions, the best place to ask them is the IMU Forum.

But, to point you in the right direction, you will need to re-map the sensor data to match your frame of reference. The BNO080 has this feature built-in:

image

Sadly, on the ICM-20948, you will need to do it manually. I'm not sure if you will find it easier to work with Quaternions to do the re-mapping, or use some form of matrix multiply.

Don't forget that the magnetometer is 'inverted' compared to the accel and gyros:

image

Best wishes, Paul