IPC Module - Accelerometer Service
This page contains documentation of the accelerometer part of IMU API.
According to the interface description, the values in the
a_ipc_msg_accelerometer_publish_ind comes as an array of bytes. To be able to read
out the actual values, these bytes need to be re-composed to an
accelerometer_sample struct:
struct accelerometer_sample {
int16_t x;
int16_t y;
int16_t z;
int16_t pad;
int64_t ts;
} __attribute__ ((__packed__));
Accelerometer sample units: - x, y and z are reported in 100x m/s^2 - Equivalent unit: cm/s^2 (centi-meter per second squared)
Here is an example of how to do this:
static void handle_publish_ind(a_ipc_msg* message)
{
struct accelerometer_sample {
int16_t x;
int16_t y;
int16_t z;
int16_t pad;
int64_t ts;
} __attribute__ ((__packed__));
struct accelerometer_sample* samples = (struct accelerometer_sample*)
message->accelerometer_publish_ind.sample_buffer.value;
int number_of_samples =
message->accelerometer_publish_ind.sample_buffer.length /
sizeof(struct accelerometer_sample);
for (int i = 0; i < number_of_samples; i++)
{
printf("Received values (sample %d of %d):\n", i + 1, number_of_samples);
printf("x: %i\n", samples[i].x);
printf("y: %i\n", samples[i].y);
printf("z: %i\n", samples[i].z);
printf("time stamp: %lu\n", samples[i].ts);
}
exit_main_loop_with_return_code(0);
}
Messages
Enums
- enum accelerometer_result
Result codes
Constant
Value
Description
OK
0
OK
ERROR
1
Error
- enum accelerometer_data_profile
Accelerometer data profile.
Constant
Value
Description
FINE_MOTION
0
Data profile 1 (default). Prioritizes measurement precision with low noise and high stability. Uses a lower full-scale range and stronger filtering; intended for fine motion tracking and applications requiring maximum signal detail at the cost of responsiveness and increased susceptibility to vibration.
BALANCED
1
Data profile 2 (balanced). General-purpose configuration offering a solid compromise between resolution, responsiveness, and dynamic range. Suitable for a wide variety of environments and motion types.
ROBUST
2
Data profile 3 (high range). Optimized for large shocks, fast rotations, and high-dynamic motion. Uses an extended full-scale range; intended to avoid saturation in harsh or demanding environments at the cost of increased noise and reduced resolution.
- enum accelerometer_wakeup_profile
Accelerometer wakeup profile.
Constant
Value
Description
BALANCED
0
Wakeup profile 1 (default). General-purpose setting which is suitable in a wide-range of situations. Good compromise between responsiveness and avoiding false wake-ups from vibration.
SENSITIVE
1
Wakeup profile 2 (sensitive). High sensitivity intended to wake on light handling and small bumps.
IMPACT
2
Wakeup profile 3 (impact). Lower sensitivity focused on stronger shocks/bumps. More resistant to continuous vibration; intended to reduce false wake-ups in vibration-rich environments.