Skip to content

Commit

Permalink
sensors: add new channels to support sensor fusion
Browse files Browse the repository at this point in the history
Add three new channels and relative data:

    - SENSOR_CHAN_GAME_ROTATION_VECTOR

      The "game rotation vector" reports the four components x/y/z/w
      (quaternions) of the unit vector representing a 3D spatial
      rotation or orientation.

    - SENSOR_CHAN_GRAVITY_VECTOR

      The "gravity vector" reports the three axis x/y/z of the gravity
      vector separated from the linear acceleration components.
      The measurement unit is m/s^2.

    - SENSOR_CHAN_GBIAS_XYZ

      The "gbias" reports the gyroscope offset x/y/z components.
      The measurement unit is radians/s.

Signed-off-by: Armando Visconti <[email protected]>
  • Loading branch information
avisconti committed Dec 29, 2024
1 parent 8d96df7 commit c4712e4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/zephyr/drivers/sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ enum sensor_channel {
SENSOR_CHAN_GAUGE_DESIRED_VOLTAGE,
/** Desired charging current in mA */
SENSOR_CHAN_GAUGE_DESIRED_CHARGING_CURRENT,
/** Game Rotation Vector (unit quaternion components X/Y/Z/W) */
SENSOR_CHAN_GAME_ROTATION_VECTOR,
/** Gravity Vector (X/Y/Z components in m/s^2) */
SENSOR_CHAN_GRAVITY_VECTOR,
/** Gyroscope bias (X/Y/Z components in radians/s) */
SENSOR_CHAN_GBIAS_XYZ,

/** All channels. */
SENSOR_CHAN_ALL,
Expand Down
32 changes: 32 additions & 0 deletions include/zephyr/drivers/sensor_data_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,38 @@ struct sensor_three_axis_data {
PRIq_arg((data_).readings[(readings_offset_)].y, 6, (data_).shift), \
PRIq_arg((data_).readings[(readings_offset_)].z, 6, (data_).shift)

/**
* Data for a sensor channel which reports game rotation vector data. This is used by:
* - :c:enum:`SENSOR_CHAN_GAME_ROTATION_VECTOR`
*/
struct sensor_game_rotation_vector_data {
struct sensor_data_header header;
int8_t shift;
struct sensor_game_rotation_vector_sample_data {
uint32_t timestamp_delta;
union {
q31_t values[4];
q31_t v[4];
struct {
q31_t x;
q31_t y;
q31_t z;
q31_t w;
};
};
} readings[1];
};

#define PRIsensor_game_rotation_vector_data PRIu64 \
"ns, (%" PRIq(6) ", %" PRIq(6) ", %" PRIq(6) ", %" PRIq(6) ")"

#define PRIsensor_game_rotation_vector_data_arg(data_, readings_offset_) \
(data_).header.base_timestamp_ns + (data_).readings[(readings_offset_)].timestamp_delta, \
PRIq_arg((data_).readings[(readings_offset_)].x, 6, (data_).shift), \
PRIq_arg((data_).readings[(readings_offset_)].y, 6, (data_).shift), \
PRIq_arg((data_).readings[(readings_offset_)].z, 6, (data_).shift), \
PRIq_arg((data_).readings[(readings_offset_)].w, 6, (data_).shift)

/**
* Data from a sensor where we only care about an event occurring. This is used to report triggers.
*/
Expand Down

0 comments on commit c4712e4

Please sign in to comment.