Skip to content

Commit d775e3d

Browse files
ismolyakovIvan SmolyakovIvan SmolyakovIvan SmolyakovRReichert
authored
Add compensated IMU message [AP-1475] (#1446)
# Description Adding a new MSG_IMU_COMP according to the corresponding design doc. <img width="938" alt="Screenshot 2024-10-01 at 8 57 33 PM" src="https://github.com/user-attachments/assets/796be85d-99e9-46df-a9c3-420895d042c7"> # API compatibility No, this is a new message ## API compatibility plan n/a # JIRA Reference https://swift-nav.atlassian.net/browse/AP-1475 --------- Co-authored-by: Ivan Smolyakov <[email protected]> Co-authored-by: Ivan Smolyakov <[email protected]> Co-authored-by: Ivan Smolyakov <[email protected]> Co-authored-by: Rodrigo Reichert <[email protected]>
1 parent 4ca4b5c commit d775e3d

File tree

42 files changed

+3124
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3124
-3
lines changed

c/include/libsbp/cpp/message_traits.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3527,6 +3527,39 @@ struct MessageTraits<sbp_msg_imu_aux_t> {
35273527
}
35283528
};
35293529

3530+
template <>
3531+
struct MessageTraits<sbp_msg_imu_comp_t> {
3532+
static constexpr sbp_msg_type_t id = SbpMsgImuComp;
3533+
static constexpr const char *name = "MSG_IMU_COMP";
3534+
static const sbp_msg_imu_comp_t &get(const sbp_msg_t &msg) {
3535+
return msg.imu_comp;
3536+
}
3537+
static sbp_msg_imu_comp_t &get(sbp_msg_t &msg) { return msg.imu_comp; }
3538+
static void to_sbp_msg(const sbp_msg_imu_comp_t &msg, sbp_msg_t *sbp_msg) {
3539+
sbp_msg->imu_comp = msg;
3540+
}
3541+
static sbp_msg_t to_sbp_msg(const sbp_msg_imu_comp_t &msg) {
3542+
sbp_msg_t sbp_msg;
3543+
sbp_msg.imu_comp = msg;
3544+
return sbp_msg;
3545+
}
3546+
static s8 send(sbp_state_t *state, u16 sender_id,
3547+
const sbp_msg_imu_comp_t &msg, sbp_write_fn_t write) {
3548+
return sbp_msg_imu_comp_send(state, sender_id, &msg, write);
3549+
}
3550+
static s8 encode(uint8_t *buf, uint8_t len, uint8_t *n_written,
3551+
const sbp_msg_imu_comp_t &msg) {
3552+
return sbp_msg_imu_comp_encode(buf, len, n_written, &msg);
3553+
}
3554+
static s8 decode(const uint8_t *buf, uint8_t len, uint8_t *n_read,
3555+
sbp_msg_imu_comp_t *msg) {
3556+
return sbp_msg_imu_comp_decode(buf, len, n_read, msg);
3557+
}
3558+
static size_t encoded_len(const sbp_msg_imu_comp_t &msg) {
3559+
return sbp_msg_imu_comp_encoded_len(&msg);
3560+
}
3561+
};
3562+
35303563
template <>
35313564
struct MessageTraits<sbp_msg_imu_raw_t> {
35323565
static constexpr sbp_msg_type_t id = SbpMsgImuRaw;

c/include/libsbp/imu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#ifndef LIBSBP_IMU_MESSAGES_H
1919
#define LIBSBP_IMU_MESSAGES_H
2020
#include <libsbp/imu/MSG_IMU_AUX.h>
21+
#include <libsbp/imu/MSG_IMU_COMP.h>
2122
#include <libsbp/imu/MSG_IMU_RAW.h>
2223

2324
#endif /* LIBSBP_IMU_MESSAGES_H */

c/include/libsbp/imu/MSG_IMU_COMP.h

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
/*
2+
* Copyright (C) 2015-2021 Swift Navigation Inc.
3+
* Contact: https://support.swiftnav.com
4+
*
5+
* This source is subject to the license found in the file 'LICENSE' which must
6+
* be distributed together with this source. All other rights reserved.
7+
*
8+
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
9+
* EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
10+
* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
11+
*/
12+
13+
/*****************************************************************************
14+
* Automatically generated from yaml/swiftnav/sbp/imu.yaml
15+
* with generate.py. Please do not hand edit!
16+
*****************************************************************************/
17+
18+
#ifndef LIBSBP_IMU_MSG_IMU_COMP_H
19+
#define LIBSBP_IMU_MSG_IMU_COMP_H
20+
21+
#include <math.h>
22+
#include <stdarg.h>
23+
#include <stdbool.h>
24+
#include <stddef.h>
25+
#include <stdint.h>
26+
#include <string.h>
27+
28+
#include <libsbp/common.h>
29+
#include <libsbp/imu_macros.h>
30+
#include <libsbp/string/sbp_string.h>
31+
32+
#ifdef __cplusplus
33+
extern "C" {
34+
#endif
35+
36+
/******************************************************************************
37+
*
38+
* SBP_MSG_IMU_COMP
39+
*
40+
*****************************************************************************/
41+
/** Compensated IMU data
42+
*
43+
* Data from the Inertial Measurement Unit, containing accelerometer and
44+
* gyroscope readings compensated for estimated errors and constant physical
45+
* effects. The output is valid for inertially referenced center of navigation
46+
* (IMU body frame) represented in vehicle body frame.
47+
*/
48+
typedef struct {
49+
/**
50+
* Microseconds since reference epoch [microseconds]
51+
*/
52+
u64 time;
53+
54+
/**
55+
* Contains the applied compensation parameters and time synchronization mode
56+
*/
57+
u16 flags;
58+
59+
/**
60+
* Compensated acceleration X axis [1e-6 m/s^2]
61+
*/
62+
s32 acc_comp_x;
63+
64+
/**
65+
* Compensated acceleration Y axis [1e-6 m/s^2]
66+
*/
67+
s32 acc_comp_y;
68+
69+
/**
70+
* Compensated acceleration Z axis [1e-6 m/s^2]
71+
*/
72+
s32 acc_comp_z;
73+
74+
/**
75+
* Compensated angular rate X axis [1e-6 deg/s]
76+
*/
77+
s32 gyr_comp_x;
78+
79+
/**
80+
* Compensated angular rate Y axis [1e-6 deg/s]
81+
*/
82+
s32 gyr_comp_y;
83+
84+
/**
85+
* Compensated angular rate Z axis [1e-6 deg/s]
86+
*/
87+
s32 gyr_comp_z;
88+
} sbp_msg_imu_comp_t;
89+
90+
/**
91+
* Get encoded size of an instance of sbp_msg_imu_comp_t
92+
*
93+
* @param msg sbp_msg_imu_comp_t instance
94+
* @return Length of on-wire representation
95+
*/
96+
static inline size_t sbp_msg_imu_comp_encoded_len(
97+
const sbp_msg_imu_comp_t *msg) {
98+
(void)msg;
99+
return SBP_MSG_IMU_COMP_ENCODED_LEN;
100+
}
101+
102+
/**
103+
* Encode an instance of sbp_msg_imu_comp_t to wire representation
104+
*
105+
* This function encodes the given instance in to the user provided buffer. The
106+
* buffer provided to this function must be large enough to store the encoded
107+
* message otherwise it will return SBP_ENCODE_ERROR without writing anything to
108+
* the buffer.
109+
*
110+
* Specify the length of the destination buffer in the \p len parameter. If
111+
* non-null the number of bytes written to the buffer will be returned in \p
112+
* n_written.
113+
*
114+
* @param buf Destination buffer
115+
* @param len Length of \p buf
116+
* @param n_written If not null, on success will be set to the number of bytes
117+
* written to \p buf
118+
* @param msg Instance of sbp_msg_imu_comp_t to encode
119+
* @return SBP_OK on success, or other libsbp error code
120+
*/
121+
SBP_EXPORT s8 sbp_msg_imu_comp_encode(uint8_t *buf, uint8_t len,
122+
uint8_t *n_written,
123+
const sbp_msg_imu_comp_t *msg);
124+
125+
/**
126+
* Decode an instance of sbp_msg_imu_comp_t from wire representation
127+
*
128+
* This function decodes the wire representation of a sbp_msg_imu_comp_t message
129+
* to the given instance. The caller must specify the length of the buffer in
130+
* the \p len parameter. If non-null the number of bytes read from the buffer
131+
* will be returned in \p n_read.
132+
*
133+
* @param buf Wire representation of the sbp_msg_imu_comp_t instance
134+
* @param len Length of \p buf
135+
* @param n_read If not null, on success will be set to the number of bytes read
136+
* from \p buf
137+
* @param msg Destination
138+
* @return SBP_OK on success, or other libsbp error code
139+
*/
140+
SBP_EXPORT s8 sbp_msg_imu_comp_decode(const uint8_t *buf, uint8_t len,
141+
uint8_t *n_read, sbp_msg_imu_comp_t *msg);
142+
/**
143+
* Send an instance of sbp_msg_imu_comp_t with the given write function
144+
*
145+
* An equivalent of #sbp_message_send which operates specifically on
146+
* sbp_msg_imu_comp_t
147+
*
148+
* The given message will be encoded to wire representation and passed in to the
149+
* given write function callback. The write callback will be called several
150+
* times for each invocation of this function.
151+
*
152+
* @param s SBP state
153+
* @param sender_id SBP sender id
154+
* @param msg Message to send
155+
* @param write Write function
156+
* @return SBP_OK on success, or other libsbp error code
157+
*/
158+
SBP_EXPORT s8 sbp_msg_imu_comp_send(sbp_state_t *s, u16 sender_id,
159+
const sbp_msg_imu_comp_t *msg,
160+
sbp_write_fn_t write);
161+
162+
/**
163+
* Compare two instances of sbp_msg_imu_comp_t
164+
*
165+
* The two instances will be compared and a value returned consistent with the
166+
* return codes of comparison functions from the C standard library
167+
*
168+
* 0 will be returned if \p a and \p b are considered equal
169+
* A value less than 0 will be returned if \p a is considered to be less than \p
170+
* b A value greater than 0 will be returned if \p b is considered to be greater
171+
* than \p b
172+
*
173+
* @param a sbp_msg_imu_comp_t instance
174+
* @param b sbp_msg_imu_comp_t instance
175+
* @return 0, <0, >0
176+
*/
177+
SBP_EXPORT int sbp_msg_imu_comp_cmp(const sbp_msg_imu_comp_t *a,
178+
const sbp_msg_imu_comp_t *b);
179+
180+
#ifdef __cplusplus
181+
}
182+
183+
static inline bool operator==(const sbp_msg_imu_comp_t &lhs,
184+
const sbp_msg_imu_comp_t &rhs) {
185+
return sbp_msg_imu_comp_cmp(&lhs, &rhs) == 0;
186+
}
187+
188+
static inline bool operator!=(const sbp_msg_imu_comp_t &lhs,
189+
const sbp_msg_imu_comp_t &rhs) {
190+
return sbp_msg_imu_comp_cmp(&lhs, &rhs) != 0;
191+
}
192+
193+
static inline bool operator<(const sbp_msg_imu_comp_t &lhs,
194+
const sbp_msg_imu_comp_t &rhs) {
195+
return sbp_msg_imu_comp_cmp(&lhs, &rhs) < 0;
196+
}
197+
198+
static inline bool operator<=(const sbp_msg_imu_comp_t &lhs,
199+
const sbp_msg_imu_comp_t &rhs) {
200+
return sbp_msg_imu_comp_cmp(&lhs, &rhs) <= 0;
201+
}
202+
203+
static inline bool operator>(const sbp_msg_imu_comp_t &lhs,
204+
const sbp_msg_imu_comp_t &rhs) {
205+
return sbp_msg_imu_comp_cmp(&lhs, &rhs) > 0;
206+
}
207+
208+
static inline bool operator>=(const sbp_msg_imu_comp_t &lhs,
209+
const sbp_msg_imu_comp_t &rhs) {
210+
return sbp_msg_imu_comp_cmp(&lhs, &rhs) >= 0;
211+
}
212+
213+
#endif // ifdef __cplusplus
214+
215+
#endif /* LIBSBP_IMU_MSG_IMU_COMP_H */

c/include/libsbp/imu_macros.h

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,97 @@
129129
*/
130130
#define SBP_MSG_IMU_AUX_ENCODED_LEN 4u
131131

132+
#define SBP_IMU_COMP_GYROSCOPEERRORSCOMPENSATED_MASK (0x1u)
133+
#define SBP_IMU_COMP_GYROSCOPEERRORSCOMPENSATED_SHIFT (6u)
134+
#define SBP_IMU_COMP_GYROSCOPEERRORSCOMPENSATED_GET(flags) \
135+
((u16)((u16)((flags) >> SBP_IMU_COMP_GYROSCOPEERRORSCOMPENSATED_SHIFT) & \
136+
SBP_IMU_COMP_GYROSCOPEERRORSCOMPENSATED_MASK))
137+
#define SBP_IMU_COMP_GYROSCOPEERRORSCOMPENSATED_SET(flags, val) \
138+
do { \
139+
(flags) = (u16)( \
140+
(flags & (~(SBP_IMU_COMP_GYROSCOPEERRORSCOMPENSATED_MASK \
141+
<< SBP_IMU_COMP_GYROSCOPEERRORSCOMPENSATED_SHIFT))) | \
142+
(((val) & (SBP_IMU_COMP_GYROSCOPEERRORSCOMPENSATED_MASK)) \
143+
<< (SBP_IMU_COMP_GYROSCOPEERRORSCOMPENSATED_SHIFT))); \
144+
} while (0)
145+
146+
#define SBP_IMU_COMP_ACCELEROMETERERRORSCOMPENSATED_MASK (0x1u)
147+
#define SBP_IMU_COMP_ACCELEROMETERERRORSCOMPENSATED_SHIFT (5u)
148+
#define SBP_IMU_COMP_ACCELEROMETERERRORSCOMPENSATED_GET(flags) \
149+
((u16)((u16)((flags) >> SBP_IMU_COMP_ACCELEROMETERERRORSCOMPENSATED_SHIFT) & \
150+
SBP_IMU_COMP_ACCELEROMETERERRORSCOMPENSATED_MASK))
151+
#define SBP_IMU_COMP_ACCELEROMETERERRORSCOMPENSATED_SET(flags, val) \
152+
do { \
153+
(flags) = (u16)( \
154+
(flags & (~(SBP_IMU_COMP_ACCELEROMETERERRORSCOMPENSATED_MASK \
155+
<< SBP_IMU_COMP_ACCELEROMETERERRORSCOMPENSATED_SHIFT))) | \
156+
(((val) & (SBP_IMU_COMP_ACCELEROMETERERRORSCOMPENSATED_MASK)) \
157+
<< (SBP_IMU_COMP_ACCELEROMETERERRORSCOMPENSATED_SHIFT))); \
158+
} while (0)
159+
160+
#define SBP_IMU_COMP_CORIOLISEFFECTCOMPENSATED_MASK (0x1u)
161+
#define SBP_IMU_COMP_CORIOLISEFFECTCOMPENSATED_SHIFT (4u)
162+
#define SBP_IMU_COMP_CORIOLISEFFECTCOMPENSATED_GET(flags) \
163+
((u16)((u16)((flags) >> SBP_IMU_COMP_CORIOLISEFFECTCOMPENSATED_SHIFT) & \
164+
SBP_IMU_COMP_CORIOLISEFFECTCOMPENSATED_MASK))
165+
#define SBP_IMU_COMP_CORIOLISEFFECTCOMPENSATED_SET(flags, val) \
166+
do { \
167+
(flags) = \
168+
(u16)((flags & (~(SBP_IMU_COMP_CORIOLISEFFECTCOMPENSATED_MASK \
169+
<< SBP_IMU_COMP_CORIOLISEFFECTCOMPENSATED_SHIFT))) | \
170+
(((val) & (SBP_IMU_COMP_CORIOLISEFFECTCOMPENSATED_MASK)) \
171+
<< (SBP_IMU_COMP_CORIOLISEFFECTCOMPENSATED_SHIFT))); \
172+
} while (0)
173+
174+
#define SBP_IMU_COMP_EARTHRORATIONRATECOMPENSATED_MASK (0x1u)
175+
#define SBP_IMU_COMP_EARTHRORATIONRATECOMPENSATED_SHIFT (3u)
176+
#define SBP_IMU_COMP_EARTHRORATIONRATECOMPENSATED_GET(flags) \
177+
((u16)((u16)((flags) >> SBP_IMU_COMP_EARTHRORATIONRATECOMPENSATED_SHIFT) & \
178+
SBP_IMU_COMP_EARTHRORATIONRATECOMPENSATED_MASK))
179+
#define SBP_IMU_COMP_EARTHRORATIONRATECOMPENSATED_SET(flags, val) \
180+
do { \
181+
(flags) = (u16)( \
182+
(flags & (~(SBP_IMU_COMP_EARTHRORATIONRATECOMPENSATED_MASK \
183+
<< SBP_IMU_COMP_EARTHRORATIONRATECOMPENSATED_SHIFT))) | \
184+
(((val) & (SBP_IMU_COMP_EARTHRORATIONRATECOMPENSATED_MASK)) \
185+
<< (SBP_IMU_COMP_EARTHRORATIONRATECOMPENSATED_SHIFT))); \
186+
} while (0)
187+
188+
#define SBP_IMU_COMP_EARTHGRAVITYCOMPENSATED_MASK (0x1u)
189+
#define SBP_IMU_COMP_EARTHGRAVITYCOMPENSATED_SHIFT (2u)
190+
#define SBP_IMU_COMP_EARTHGRAVITYCOMPENSATED_GET(flags) \
191+
((u16)((u16)((flags) >> SBP_IMU_COMP_EARTHGRAVITYCOMPENSATED_SHIFT) & \
192+
SBP_IMU_COMP_EARTHGRAVITYCOMPENSATED_MASK))
193+
#define SBP_IMU_COMP_EARTHGRAVITYCOMPENSATED_SET(flags, val) \
194+
do { \
195+
(flags) = \
196+
(u16)((flags & (~(SBP_IMU_COMP_EARTHGRAVITYCOMPENSATED_MASK \
197+
<< SBP_IMU_COMP_EARTHGRAVITYCOMPENSATED_SHIFT))) | \
198+
(((val) & (SBP_IMU_COMP_EARTHGRAVITYCOMPENSATED_MASK)) \
199+
<< (SBP_IMU_COMP_EARTHGRAVITYCOMPENSATED_SHIFT))); \
200+
} while (0)
201+
202+
#define SBP_IMU_COMP_TIME_STATUS_MASK (0x3u)
203+
#define SBP_IMU_COMP_TIME_STATUS_SHIFT (0u)
204+
#define SBP_IMU_COMP_TIME_STATUS_GET(flags) \
205+
((u16)((u16)((flags) >> SBP_IMU_COMP_TIME_STATUS_SHIFT) & \
206+
SBP_IMU_COMP_TIME_STATUS_MASK))
207+
#define SBP_IMU_COMP_TIME_STATUS_SET(flags, val) \
208+
do { \
209+
(flags) = (u16)((flags & (~(SBP_IMU_COMP_TIME_STATUS_MASK \
210+
<< SBP_IMU_COMP_TIME_STATUS_SHIFT))) | \
211+
(((val) & (SBP_IMU_COMP_TIME_STATUS_MASK)) \
212+
<< (SBP_IMU_COMP_TIME_STATUS_SHIFT))); \
213+
} while (0)
214+
215+
#define SBP_IMU_COMP_TIME_STATUS_REFERENCE_EPOCH_IS_START_OF_CURRENT_GPS_WEEK \
216+
(0)
217+
#define SBP_IMU_COMP_TIME_STATUS_REFERENCE_EPOCH_IS_TIME_OF_SYSTEM_STARTUP (1)
218+
#define SBP_IMU_COMP_TIME_STATUS_REFERENCE_EPOCH_IS_UNKNOWN (2)
219+
#define SBP_IMU_COMP_TIME_STATUS_REFERENCE_EPOCH_IS_LAST_PPS (3)
220+
/**
221+
* Encoded length of sbp_msg_imu_comp_t
222+
*/
223+
#define SBP_MSG_IMU_COMP_ENCODED_LEN 34u
224+
132225
#endif /* LIBSBP_IMU_MACROS_H */

0 commit comments

Comments
 (0)