nRF Connect SDK API 3.3.99
Loading...
Searching...
No Matches
accel_to_angle.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2026 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
7#ifndef ACCEL_TO_ANGLE_H_
8#define ACCEL_TO_ANGLE_H_
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14#include <zephyr/drivers/sensor.h>
15
27#define ACCEL_TO_ANGLE_AXIS_NUM 3
28
42#define ACCEL_TO_ANGLE_CTX_DEFINE(_instance_name, _filter) \
43 struct accel_to_angle_ctx _instance_name = { \
44 .filter = _filter, \
45 .pr_last = {0}, \
46 .pr_diff = {0}, \
47 }
48
62#define ACCEL_TO_ANGLE_FILTER_DEFINE(_instance_name, _ctx, _process_request, _clean_request) \
63 struct accel_to_angle_filter _instance_name = { \
64 .ctx = _ctx, \
65 .data_process_request = _process_request, \
66 .data_clean_request = _clean_request \
67 }
68
72 float x;
73
75 float y;
76
78 float z;
79};
80
84 float pitch;
85
87 float roll;
88};
89
102 void *ctx;
103
113 void (*data_process_request)(void *filter_ctx, struct accel_to_angle_accel_data *data);
114
123 void (*data_clean_request)(void *filter_ctx);
124};
125
143
171 struct accel_to_angle_filter *filter);
172
200 const struct sensor_value vals[ACCEL_TO_ANGLE_AXIS_NUM],
201 struct accel_to_angle_pr_data *pr);
202
224 const struct accel_to_angle_pr_data *pr_threshold_deg,
225 const uint8_t axis_threshold_num);
226
244
247#ifdef __cplusplus
248}
249#endif
250
251#endif /* ACCEL_TO_ANGLE_H_ */
#define ACCEL_TO_ANGLE_AXIS_NUM
Definition accel_to_angle.h:27
int accel_to_angle_calc(struct accel_to_angle_ctx *ctx, const struct sensor_value vals[3], struct accel_to_angle_pr_data *pr)
Calculate pitch and roll angles from accelerometer data.
int accel_to_angle_state_clean(struct accel_to_angle_ctx *ctx)
Clean the internal state of the context instance.
bool accel_to_angle_diff_check(struct accel_to_angle_ctx *ctx, const struct accel_to_angle_pr_data *pr_threshold_deg, const uint8_t axis_threshold_num)
Check for significant rotation change.
int accel_to_angle_filter_set(struct accel_to_angle_ctx *ctx, struct accel_to_angle_filter *filter)
Set a filter.
float x
Acceleration along the X axis in G units.
Definition accel_to_angle.h:72
float y
Acceleration along the Y axis in G units.
Definition accel_to_angle.h:75
float z
Acceleration along the Z axis in G units.
Definition accel_to_angle.h:78
Accelerometer data from 3 axes from the sensor.
Definition accel_to_angle.h:70
struct accel_to_angle_pr_data pr_diff
Cumulative difference between pitch and roll data calculations.
Definition accel_to_angle.h:141
struct accel_to_angle_filter * filter
Pointer to the filter instance.
Definition accel_to_angle.h:135
struct accel_to_angle_pr_data pr_last
Last pitch and roll data.
Definition accel_to_angle.h:138
Descriptor of the library context instance.
Definition accel_to_angle.h:133
void * ctx
Pointer to the filter context.
Definition accel_to_angle.h:102
void(* data_process_request)(void *filter_ctx, struct accel_to_angle_accel_data *data)
Data process request callback.
Definition accel_to_angle.h:113
void(* data_clean_request)(void *filter_ctx)
Data clean request callback.
Definition accel_to_angle.h:123
Descriptor of the filter instance.
Definition accel_to_angle.h:100
float pitch
Pitch angle in degrees.
Definition accel_to_angle.h:84
float roll
Roll angle in degrees.
Definition accel_to_angle.h:87
Pitch and roll data calculated from accelerometer data.
Definition accel_to_angle.h:82