IMU Data Freezes in Main Loop but Works Inside Class Function – What's Causing This?

TouristGuest

New member
I'm working with a Vector VN100 IMU using an object-oriented approach on the platform IO, and I'd appreciate some suggestions regarding an issue I'm encountering.

Here's the flow of my program:
  • Serial Communication Initialization: The IMU class is initialized with a default baud rate. After flushing old messages from the IMU buffer, the baud rate is increased for faster communication.
  • Timer Setup: A timer is configured to send data requests to the IMU at a frequency of 100Hz.
  • Data Requesting Mechanism: The program alternates between requesting raw IMU data (accelerometer, gyroscope, etc.) and quaternion data (orientation).
  • Data Reception and Parsing: When data is received from the IMU, it parses the strings to extract values like accelerometer readings, gyro data, and quaternion components. All data is saved in a global structure.
The problem: When I print the data inside the object definition file using ``Serial.print()``, it works correctly and updates in real-time. However, when I attempt the same in the main loop by calling the exact same method, the data gets printed but doesn't update.

Any suggestions on how to resolve this would be greatly appreciated.

For example:

C++:
// This is OK, getData() also calls printData() method
void loop() {
    // Print IMU Data
    imu = imuSensor->getData();
}

// This print but data is not being updated
void loop() {
    // Print IMU Data
    imu = imuSensor->getData();

    Serial.println(imu.accelX, 6); Serial.print(",");
}
 
Would need to see some more code to work it out.

My guess is the data is not being saved to the global struct correctly. When your printing in getdata your printing a local copy of the values
 
Thank you so much I fixed it. Basically I found out the VN100 Rugged is using ASCII Serial - which can be easily interrupted by the main loop. By implementing isolation using timers I got everything fixed>
 
Back
Top