Reverted Accelerometer and Gyro displays to throttled display (10hz)

Also made accelerometer threshold for drift calibration more lenient for very noisy accelerometers.

The testcontroller tool could eventually be used to come up with a better way to profile an IMU's "stationary" noise so that this threshold can be as tight as necessary for the sake of automatic drift calibration.

(thanks @HilariousCow!)
This commit is contained in:
Sam Lantinga
2025-06-16 11:14:22 -07:00
parent b833c618a9
commit f62c982bcf
3 changed files with 27 additions and 26 deletions

View File

@@ -147,7 +147,7 @@ typedef struct
Uint64 gyro_packet_number;
Uint64 accelerometer_packet_number;
/* When both gyro and accelerometer events have been processed, we can increment this and use it to calculate polling rate over time.*/
Uint64 imu_packet_counter;
Uint64 imu_packet_counter;
Uint64 starting_time_stamp_ns; /* Use this to help estimate how many packets are received over a duration */
Uint16 imu_estimated_sensor_rate; /* in Hz, used to estimate how many packets are received over a duration */
@@ -244,7 +244,7 @@ void SampleGyroPacketForDrift( IMUState *imustate )
if (imustate->gyro_drift_sample_count >= SDL_GAMEPAD_IMU_MIN_GYRO_DRIFT_SAMPLE_COUNT) {
FinalizeDriftSolution(imustate);
}
}
}
}
void ApplyDriftSolution(float *gyro_data, const float *drift_solution)
@@ -1409,24 +1409,26 @@ static void UpdateGamepadOrientation( Uint64 delta_time_ns )
static void HandleGamepadSensorEvent( SDL_Event* event )
{
if (!controller)
return;
if (controller->id != event->gsensor.which)
if (!controller) {
return;
}
if (controller->id != event->gsensor.which) {
return;
}
if (event->gsensor.sensor == SDL_SENSOR_GYRO) {
HandleGamepadGyroEvent(event);
} else if (event->gsensor.sensor == SDL_SENSOR_ACCEL) {
HandleGamepadAccelerometerEvent(event);
}
}
/*
This is where we can update the quaternion because we need to have a drift solution, which requires both
accelerometer and gyro events are received before progressing.
*/
if ( controller->imu_state->accelerometer_packet_number == controller->imu_state->gyro_packet_number ) {
EstimatePacketRate();
Uint64 sensorTimeStampDelta_ns = event->gsensor.sensor_timestamp - controller->imu_state->last_sensor_time_stamp_ns ;
UpdateGamepadOrientation(sensorTimeStampDelta_ns);
@@ -2071,7 +2073,7 @@ SDL_AppResult SDLCALL SDL_AppEvent(void *appstate, SDL_Event *event)
event->gsensor.data[1],
event->gsensor.data[2],
event->gsensor.sensor_timestamp);
#endif /* VERBOSE_SENSORS */
HandleGamepadSensorEvent(event);
break;