-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSerialMuxChannels.h
More file actions
250 lines (201 loc) · 9.26 KB
/
SerialMuxChannels.h
File metadata and controls
250 lines (201 loc) · 9.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/* MIT License
*
* Copyright (c) 2023 - 2026 Andreas Merkle <web@blue-andi.de>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/*******************************************************************************
DESCRIPTION
*******************************************************************************/
/**
* @file
* @brief Channel structure definition for the SerialMuxProt.
* @author Gabryel Reyes <gabryelrdiaz@gmail.com>
*
* @addtogroup Application
*
* @{
*/
#ifndef SERIAL_MUX_CHANNELS_H_
#define SERIAL_MUX_CHANNELS_H_
/******************************************************************************
* Includes
*****************************************************************************/
#include <Arduino.h>
#include <SerialMuxProtServer.hpp>
/******************************************************************************
* Macros
*****************************************************************************/
/** Maximum number of SerialMuxProt Channels. */
#define MAX_CHANNELS (10U)
/** Name of Channel to send Commands to. */
#define COMMAND_CHANNEL_NAME "CMD"
/** DLC of Command Channel. */
#define COMMAND_CHANNEL_DLC (sizeof(Command))
/** Name of Channel to receive Command Responses from. */
#define COMMAND_RESPONSE_CHANNEL_NAME "CMD_RSP"
/** DLC of Command Response Channel. */
#define COMMAND_RESPONSE_CHANNEL_DLC (sizeof(CommandResponse))
/** Name of Channel to send Motor Speed Setpoints to. */
#define MOTOR_SPEED_SETPOINT_CHANNEL_NAME "MOTOR_SET"
/** DLC of Motor Speed Setpoint Channel */
#define MOTOR_SPEED_SETPOINT_CHANNEL_DLC (sizeof(MotorSpeed))
/** Name of the Channel to send Robot Speed Setpoints to. */
#define ROBOT_SPEED_SETPOINT_CHANNEL_NAME "ROBOT_SET"
/** DLC of Robot Speed Setpoint Channel */
#define ROBOT_SPEED_SETPOINT_CHANNEL_DLC (sizeof(RobotSpeed))
/** Name of Channel to receive Current Vehicle Data from. */
#define CURRENT_VEHICLE_DATA_CHANNEL_NAME "CURR_DATA"
/** DLC of Current Vehicle Data Channel */
#define CURRENT_VEHICLE_DATA_CHANNEL_DLC (sizeof(VehicleData))
/** Name of Channel to send system status to. */
#define STATUS_CHANNEL_NAME "STATUS"
/** DLC of Status Channel */
#define STATUS_CHANNEL_DLC (sizeof(Status))
/** Name of the Channel to receive Line Sensor Data from. */
#define LINE_SENSOR_CHANNEL_NAME "LINE_SENS"
/** DLC of Line Sensor Channel */
#define LINE_SENSOR_CHANNEL_DLC (sizeof(LineSensorData))
/******************************************************************************
* Types and Classes
*****************************************************************************/
/** SerialMuxProt Server with fixed template argument. */
typedef SerialMuxProtServer<MAX_CHANNELS> SMPServer;
/** Channel payload constants. */
namespace SMPChannelPayload
{
/** Remote control commands. */
typedef enum : uint8_t
{
CMD_ID_IDLE = 0, /**< Nothing to do. */
CMD_ID_START_LINE_SENSOR_CALIB, /**< Start line sensor calibration. */
CMD_ID_START_MOTOR_SPEED_CALIB, /**< Start motor speed calibration. */
CMD_ID_REINIT_BOARD, /**< Re-initialize the board. Required for webots simulation. */
CMD_ID_GET_MAX_SPEED, /**< Get maximum speed. */
CMD_ID_START_DRIVING, /**< Start driving. */
CMD_ID_SET_INIT_POS /**< Set initial position. */
} CmdId; /**< Command ID */
/** Remote control command responses. */
typedef enum : uint8_t
{
RSP_ID_OK = 0, /**< Command successful executed. */
RSP_ID_PENDING, /**< Command is pending. */
RSP_ID_ERROR /**< Command failed. */
} RspId; /**< Response ID */
/** Status flags. */
typedef enum : uint8_t
{
STATUS_FLAG_OK = 0, /**< Everything is fine. */
STATUS_FLAG_ERROR /**< Something is wrong. */
} Status; /**< Status flag */
/**
* Range in which a detected object may be.
* Equivalent to the brightness levels.
* Values estimated from user's guide.
*/
typedef enum : uint8_t
{
RANGE_NO_OBJECT = 0U, /**< No object detected */
RANGE_25_30, /**< Object detected in range 25 to 30 cm */
RANGE_20_25, /**< Object detected in range 20 to 25 cm */
RANGE_15_20, /**< Object detected in range 15 to 20 cm */
RANGE_10_15, /**< Object detected in range 10 to 15 cm */
RANGE_5_10, /**< Object detected in range 5 to 10 cm */
RANGE_0_5 /**< Object detected in range 0 to 5 cm */
} Range; /**< Proximity Sensor Ranges */
} /* namespace SMPChannelPayload */
/** Struct of the "Command" channel payload. */
typedef struct _Command
{
SMPChannelPayload::CmdId commandId; /**< Command ID */
/** Command payload. */
union
{
/** Init data command payload. */
struct
{
int32_t xPos; /**< X position [mm]. */
int32_t yPos; /**< Y position [mm]. */
int32_t orientation; /**< Orientation [mrad]. */
};
};
} __attribute__((packed)) Command;
static_assert(sizeof(Command) <= MAX_DATA_LEN,
"Command struct size must be less than or equal to MAX_DATA_LEN to fit in the SerialMuxProt frame.");
/** Struct of the "Command Response" channel payload. */
typedef struct _CommandResponse
{
SMPChannelPayload::CmdId commandId; /**< Command ID */
SMPChannelPayload::RspId responseId; /**< Response to the command */
/** Response Payload. */
union
{
int32_t maxMotorSpeed; /**< Max speed [mm/s]. */
};
} __attribute__((packed)) CommandResponse;
static_assert(sizeof(CommandResponse) <= MAX_DATA_LEN,
"CommandResponse struct size must be less than or equal to MAX_DATA_LEN to fit in the SerialMuxProt frame.");
/** Struct of the "Motor Speed Setpoints" channel payload. */
typedef struct _MotorSpeed
{
int32_t left; /**< Left motor speed [mm/s] */
int32_t right; /**< Right motor speed [mm/s] */
} __attribute__((packed)) MotorSpeed;
static_assert(sizeof(MotorSpeed) <= MAX_DATA_LEN,
"MotorSpeed struct size must be less than or equal to MAX_DATA_LEN to fit in the SerialMuxProt frame.");
/** Struct of the "Robot Speed Setpoints" channel payload. */
typedef struct _RobotSpeed
{
int32_t linearCenter; /**< Linear speed of the vehicle center. [mm/s] */
int32_t angular; /**< Angular speed. [mrad/s] */
} __attribute__((packed)) RobotSpeed;
static_assert(sizeof(RobotSpeed) <= MAX_DATA_LEN,
"RobotSpeed struct size must be less than or equal to MAX_DATA_LEN to fit in the SerialMuxProt frame.");
/** Struct of the "Current Vehicle Data" channel payload. */
typedef struct _VehicleData
{
int32_t xPos; /**< X position [mm]. */
int32_t yPos; /**< Y position [mm]. */
int32_t orientation; /**< Orientation [mrad]. */
int32_t left; /**< Left motor speed [mm/s]. */
int32_t right; /**< Right motor speed [mm/s]. */
int32_t center; /**< Center speed [mm/s]. */
SMPChannelPayload::Range proximity; /**< Range at which object is found [range]. */
} __attribute__((packed)) VehicleData;
static_assert(sizeof(VehicleData) <= MAX_DATA_LEN,
"VehicleData struct size must be less than or equal to MAX_DATA_LEN to fit in the SerialMuxProt frame.");
/** Struct of the "Status" channel payload. */
typedef struct _Status
{
SMPChannelPayload::Status status; /**< Status */
} __attribute__((packed)) Status;
static_assert(sizeof(Status) <= MAX_DATA_LEN,
"Status struct size must be less than or equal to MAX_DATA_LEN to fit in the SerialMuxProt frame.");
/** Struct of the "Line Sensor" channel payload. */
typedef struct _LineSensorData
{
uint16_t lineSensorData[5U]; /**< Line sensor data [digits] normalized to max 1000 digits. */
} __attribute__((packed)) LineSensorData;
static_assert(sizeof(LineSensorData) <= MAX_DATA_LEN,
"LineSensorData struct size must be less than or equal to MAX_DATA_LEN to fit in the SerialMuxProt frame.");
/******************************************************************************
* Functions
*****************************************************************************/
#endif /* SERIAL_MUX_CHANNELS_H_ */
/** @} */