Hi! I'm trying to develop a sketch for an Arduino Nano 33 BLE that sends absolute orientation information over BLE. The goal is to control a wand-type object in a Unity game. I want to achieve a similar controlling capability of a VR controller basically.
I tried using the atan2 methods to calculate roll, pitch, and yaw after reading from the gyroscope, magnetometer and accelerator, but the data was choppy, noisy, and I had a similar issue as someone else posted in the forum where when I performed a pitch motion, the yaw value also increased, skewing the rotation.
I tried using the Madgwick library to calculate and send quaternion values. I also performed hard iron calibration and, in my sketch, subtracted those biases. With the quaternion values applied to the game object in Unity, I was having a different problem; the orientation values were just not accurate, and I was getting a constant gliding on different directions, but definitely constant. So it wasn't choppy, but it just wasn't really responsive.
Since I need precise absolute orientation to control the wand-type object, what library is best? Is there something I'm not considering or something I'm doing wrong? I appreciate the help.
This is the excerpt of the code where I'm calculating orientation:
void loop()
{
unsigned long now = millis();
if (now - lastUpdate >= interval) {
lastUpdate = now;
// Reading value from Accelerometer, Gyroscope and Magnetometer in order to determine absolute orientation
if (IMU.accelerationAvailable()) {
IMU.readAcceleration(ax, ay, az);
}
if (IMU.gyroscopeAvailable()) {
IMU.readGyroscope(gx, gy, gz);
}
if (IMU.magneticFieldAvailable()) {
IMU.readMagneticField(mx, my, mz);
}
// Convert gyroscope units from degrees/sec to radians/sec (required by filter)
gx *= PI / 180.0;
gy *= PI / 180.0;
gz *= PI / 180.0;
// Subtract bias from magnetometer
// This bias was calculated with a different script
mx -= 9.455;
my -= 9.54;
mz -= -33.835;
// Update Madgwick filter
filter.update(gx, gy, gz, ax, ay, az, mx, my, mz);
// Get quaternion components
filter.getQuaternion(qx, qy, qz, qw);
// Sending information over BLE
}