Obtaining orientation from an IMU

I’m wanting to obtain the real time orientation of an object. How do I obtain this?

Currently I have the Wifi Uno Rev 2 with the LSM6DS3TR IMU. Though I can obtain other equipment if needed.

1 Like

Couple of quick questions.

What is the object that we are tracking?
Will the object be stationary in space while it’s rotating or is carried around?
Does the object have room on the inside which could house the LSM6DS3TR IMU?

1 Like

Hi Mitchell,

Another couple of questions.

What do you mean by real-time orientation? Is it just the angle that the object is being held at or also a distance from where it was picked up?

A bit more general information about your project will help a ton!

1 Like

Thanks Mixmusix

The thigh of a person while walking, so the object will move in space as well as rotating. The IMU would be on the persons thigh so not technically inside

1 Like

Just the angle will be sufficient. I want to assess the orientation of someone’s thigh in real time (flexion/extension, abduction/adduction, internal rotation/external rotation.

1 Like

Have a look at this library by adafruit that interfaces between the arduino and the lsm6ds3trc

You’ll also need some code to calculate the 3d distance travel between each loop. I’d recommend a crude linear algebra approach.

struct GVec {
   float x;
   float y;
   float z;

  float dist(GVec v) {
    float dx = x - v.x;
    float dy = y - v.y;
    float dz = z - v.z;
    return (float) Math.sqrt(dx*dx + dy*dy + dz*dz);

//Init a global vector.
GVec cacheVector;
/* SETUP REQUIRED! See Library Documentation */
void setup{// CODE GOES HERE!}

void loop() {
  // Get a new normalized sensor event
  sensors_event_t accel;
  sensors_event_t gyro;
  sensors_event_t temp;
  lsm6ds3trc.getEvent(&accel, &gyro, &temp);

  /* Calculate the distance traveled form last loop in radians */
  GVec vzero;
  vzero.x = gyro.gyro.x;
  vzero.y = gyro.gyro.y;
  vzero.z = gyro.gyro.z;
  cacheVector = vzero;

Hi Mitchell,

An IMU seems like the intuitive answer but a poteniometer is also an option: Core Electronics on Instagram: "We caught Liam trying to turn himself into a cyborg after playing too much Cyberpunk 2077. Only a few pots, a Pico and some Feetech servos and he's already claiming he can talk to the toaster. Head the link in bio to grab yourself some servos and get in on the craze."

There is definitely a scale of accuracy and timelyness when using an IMU, the method PIx used is very fast to compute but doesnt account for gyro drift.
Using the accelerometer is also fast but cannot easily reject fast movements or vibrations.

Sensor fusion through the use of a Kalman filter will be a bit slower to compute (still close enough to real time for the movements of a human) and help with the issues above.



Ooooo yeah good point.

Hi Mitchell
Maybe I’m missing something here, but if you want the orientation of an object in real time without drift error then a 3D magnetometer sensor would seem to be the most appropriate. Core sell various magnetometers, some with onboard accelerometers, gyroscopes and onboard processing included.

1 Like

Here’s an example of an IMU that does the fusion itself and has a visualiser.
I’ve linked our store page and Adafruit’s page. There is a comprehensive setup guide in there for a few different processors.

1 Like

How do I apply the Kalman Filter in the code. What would be an estimate of the delay using the Kalman Filter?

1 Like

Great, thanks. An IMU that does the fusion itself will be the best option.

There are some discussion posts about drift over time causing significantly inaccurate measures with this sensor. Are there other options that are more accurate?

There will always be some element of drift that creeps into sensors. Long term the goal is to minimise it.
Some things to consider, in no particular order, would be:

  • Testing the sensors regularly
  • Keeping the environment they’re in while in use consistent (This is one that may cause you issues)
  • Redundancy can help pick up on drift while still providing some source of data
  • Implementing filters in your code (I can see references to a Kalman filter, there are libraries for these readily available online, I recommend plotting your raw and filtered data together while you tune it)
  • The effect of batteries on the magnetometers magnetic field should also be considered, I can see this is where some people are having difficulties with drift. If you are tracking some ones thigh, if they place the battery in their pocket you shouldn’t have any issues.

Another thing to consider is if you are tracking movement long enough for drift to be an issue. This is where testing is needed.

I am pretty sure I have given you some more questions than answers here but hopefully this helps.