The IMU (inertial measurement unit) allows a robot to orient in its environment by perceiving YPR, i.e. Yaw, Pitch and Roll rotations, typically along the robot's z, y, and x axes, respectively. The IMU also allows perception of acceleration in the framework of the IMU itself (Real x, y and z directions) or in the framework on the robot's environment (World x, y, and z directions). Depending on the robot, the main uses of the IMU are for navigation (get/maintain robot movement heading using Yaw) and balancing (feedback/correction using Pitch and Roll).
For most wheeled robots, stability is not a factor so the IMU is used for navigation. However, for legged robots like the Nybble and Bittle quadrapeds, stability can be a concern so the IMU can be used for balancing but navigation with the IMU can also be important.
I mention this because I recently did a code review of OpenCatEsp32 and discovered that the current code uses one bool variable, gyroBalanceQ, as both the on/off switch for reading of IMU data for any purpose and the on/off switch for using such IMU data to balance the robot. I like the balance capability but sometimes I want to turn it off but not lose access to the IMU data for navigation. I therefore made some code changes in my forked repo of OpenCatEsp32.
First I added a new bool variable in the global variables section of OpenCat.h, just under bool gyroBalanceQ:
bool imuDataReadQ = true;
Next, I modified readEnvironment() in io.h:
if (gyroBalanceQ && !(frame % imuSkip))
was changed to...
if (imuDataReadQ && !(frame % imuSkip))
And that is it! As long as imuDataReadQ is true, you will have IMU data, regardless of balancing being on or off. One could also add some more code to change imuDataReadQ programatically but that doesn't fit my current use cases.
Since I believe this is generally useful, I will do a pull request from my fork into the Petoi OpenCatEsp32 repo for consideration. In the meantime, you can make changes to your own code in this way if you want this capability now.
P.S. The same is true for the OpenCat repo except readEnvironment() is in imu.h. I am not using that repo so I will leave such changes there for others to make.
P.P.S. I had not previously seen the use of a "Q" suffix in a bool variable name to indicate interrogative code reading syntax (as in a Question mark). I am more of an "isSometingTrue" code reading syntax person but I rather like the use of "Q" in that way!
Edit:
I change the bool name from ImuDataReadQ to imuDataReadQ to conform to the preference for camelCase in OpenCat32 rather than PascalCase (though, being a public variable, an argument could be made for PascalCase which is commonly used for public method and property names - not the same, I know but the same concept! 😀 )
Thanks for your suggestion. I think the three boolean vars will all be useful. Because turning off the IMU reading completely can reduce the calculation and accelerate the motion loops. It may be useful in some extreme cases. So I'll probably extend the condition chain.
I learned the Q suffix of a boolean function from the Wolfram Language or the Mathematica.