Skip to content

Commit ecafc3c

Browse files
delta-12KushalP17
andauthored
Sensor (#35)
* Sd 184 check protocol version on receive (#21) * SD-184 & SD-182 & SD-183 Check version and Error Checking based on observed send receive behavior * SD-184,182,183 fixed static analysis checks oopsy * SD-184, SD-183, SD-182 Fixed Flush Buffer Errors * SD-182-4 fixed unit tests for Versioning Errors * SD-184 Thorough Error Checking and Flushing * SD-184 Fixed buffer init redund & added socket closed check * SD-184 final socket closed check * SD-184 Fix Flush Buffer Break condition * SD-184 Check protocol version and return Version error if not match * SD-184 Fix Error Nesting, Cannot see ISO msg on mine but should be fix * SD-212 Added Encoder Config Message (#22) * SD-260 Fixed Switch Case Copy Mistake (#23) * SD-265 provide default implementation for listener callbacks virtual destructor (#25) * SD-242 C Test Mocks and Workaround for No Operator== for PB objects * SD-242 Finally Added Mocks to C Tests Plus fixed some spacing * SD-242 A way to check non operator== object fields * SD-281 arming message (#26) * SD-281 switch mode message to arm message * SD-281 update c library * SD-281 update c++ library * SD-281 update tests * SD-281 uncrustify * SD-287 Config Log Message Ready (#27) * SD-287 Config Log Message Ready * SD-287 Remove Comments * SD-327 Look at those quats (#28) * SD-331 change servo config duty cycles to percents (#29) * Sd 336 wheel speed & steering pid config (#30) * SD-336 Wheel Speed PID & Steering Control PID Configs * SD-336 almost forgot to uncrustify * SD-343 PID Enables (#31) * SD-347 AQ msg (#33) * SD-352 Add temp to AQ msg (#34) * relative move message * talk and hear relative move --------- Co-authored-by: Kushal Parekh <98786169+KushalP17@users.noreply.github.com>
1 parent 4e4796f commit ecafc3c

21 files changed

Lines changed: 1602 additions & 314 deletions

README.md

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,23 @@ CAVEMAN controller message protocol
1111
1. Version refers to the communication version that packet adheres to, starting from V1 represented as 0x01
1212
2. ID refers to the specific message being sent by the packet. Here is a list of the currently supported messages.
1313

14-
| ID | Name | Descriptor |
15-
| ---- | --------------- | ---------------------------------------------------------------------- |
16-
| 0x01 | Ooga | CAVeTalk Ping Message, should receive "Booga" back from the controller |
17-
| 0x02 | Movement | Describes the Speed [m/s] & Turn Rate of the Rover [rad/s] |
18-
| 0x03 | Camera Movement | Describes the Camera Pan [radians] and Tilt Servo Angles [radians] |
19-
| 0x04 | Lights | Toggles the Onboard Headlights |
20-
| 0x05 | Mode | Switches between Manual Driving Mode and Autonomous Driving Mode |
21-
| 0x06 | Odometry | Describes the 3 relative acceleration axes [m/s^2], 3 gyroscopic axes [rad/s], and 4 encoder values for each wheel [rad/s] |
22-
| 0x07 | Logging | Send String Messages Between Devices |
23-
| 0x08 | Configuration - Servos - Wheels | Send Wheel Servo Configuration Parameters Between Devices |
24-
| 0x09 | Configuration - Servos - Cams | Send Camera Servo Configuration Parameters Between Devices |
25-
| 0x0A | Configuration - Motors | Send Motor Configuration Parameters Between Devices |
26-
| 0x0B | Configuration - Encoders | Send Encoder Configuration Parameters Between Devices |
14+
| ID | Name | Descriptor |
15+
| ---- | ------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
16+
| 0x01 | Ooga | CAVeTalk Ping Message, should receive "Booga" back from the controller |
17+
| 0x02 | Movement | Describes the Speed [m/s] & Turn Rate of the Rover [rad/s] |
18+
| 0x03 | Camera Movement | Describes the Camera Pan [radians] and Tilt Servo Angles [radians] |
19+
| 0x04 | Lights | Toggles the Onboard Headlights |
20+
| 0x05 | Arm | Enable or disable driving and steering |
21+
| 0x06 | Odometry | Describes the 3 relative acceleration axes [m/s^2], 3 gyroscopic axes [rad/s], 4 unit quaternion positions and 4 encoder values for each wheel [rad/s] |
22+
| 0x07 | Logging | Send String Messages Between Devices |
23+
| 0x08 | Configuration - Servos - Wheels | Send Wheel Servo Configuration Parameters Between Devices |
24+
| 0x09 | Configuration - Servos - Cams | Send Camera Servo Configuration Parameters Between Devices |
25+
| 0x0A | Configuration - Motors | Send Motor Configuration Parameters Between Devices |
26+
| 0x0B | Configuration - Encoders | Send Encoder Configuration Parameters Between Devices |
27+
| 0x0C | Configuration - Log | Send Log Verbosity Configuration Between Devices |
28+
| 0x0D | Configuration - Wheel Speed PID | Send PID Tuning Parameters for Rover Wheel Speed |
29+
| 0x0E | Configuration - Turn Rate PID | Send PID Tuning Parameters for Rover Turn Rate |
30+
| 0x0F | Air Quality Readings | Send Air Quality measurements like dust and gas content |
2731

2832
3. Length refers to the length of the packet in bytes
2933
4. Payload refers to the main piece of information sent in the packet
@@ -37,80 +41,85 @@ CAVEMAN controller message protocol
3741
When building the C version of this library and/or using this library on an embedded system, follow these steps to setup Protobufs:
3842

3943
1. Initialize and update submodules
40-
44+
4145
`git submodule update --init --recursive `
42-
46+
4347
- Use this command to see the progress of each submodule pull
44-
48+
4549
`git submodule update --init --recursive --progress`
4650

4751
2. Make the script to generate the Protobuf payloads for C with `nanopb` executable.
48-
52+
4953
`chmod +x tools/nanopb/generate.sh`
5054

5155
3. Run the `generate` script to generate the Protobuf payloads for C with `nanopb`. This step requires Python3 to be installed.
52-
56+
5357
`./tools/nanopb/generate.sh`
5458

5559
### C++
5660

5761
When building the C++ version of this library, follow these steps to setup Protobufs:
5862

5963
1. Initialize and update submodules
60-
64+
6165
`git submodule update --init --recursive`
62-
66+
6367
- Use this command to see the progress of each submodule pull
64-
68+
6569
`git submodule update --init --recursive --progress`
6670

6771
2. Navigate to the `protobuf` directory
68-
72+
6973
`cd external/protobuf`
7074

7175
3. Configure CMake build
72-
76+
7377
`cmake -S . -B _build -DCMAKE_INSTALL_PREFIX=_build/protobuf-install -DCMAKE_CXX_STANDARD=20 -G Ninja -DCMAKE_BUILD_TYPE=Release -Dprotobuf_BUILD_TESTS=OFF -DABSL_PROPAGATE_CXX_STD=ON`
7478

7579
4. Build `protobufs`
76-
80+
7781
`cmake --build _build --config Release`
7882

7983
5. Install `protobufs` in `external/protobufs/_build/protobuf-install`
80-
84+
8185
`cmake --build _build -t install`
8286

8387
## Build
8488

8589
Prerequisites
90+
8691
- CMake >= 3.30
92+
8793
- Ninja
94+
8895
- C compiler that supports at least C11
96+
8997
- C++ compiler that supports at least C++20
98+
9099
- Python3 >= 3.9 with python3-venv installed
91-
- Gcovr (optional)
92100

101+
- Gcovr (optional)
93102
1. Setup Protobufs for the version(s) of the library being built. See [Protobufs](#protobufs).
94103

95104
2. See the `docs` directory for how to perform static analysis and code formatting. **You must set up Cppcheck and Uncrustify before configuring CMake.**
96105

97106
3. Configure CMake.
98-
107+
99108
`cmake -B build -G Ninja` or `cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCAVETALK_BUILD_TESTS=ON` to build with tests
100109

101110
4. Run the static analysis and code formatting tools.
102-
111+
103112
- Cppcheck: `cmake --build build -t cppcheck`
104113
- Uncrustify: `cmake --build build -t uncrustify`
105114

106115
5. Build the project.
107-
116+
108117
`cmake --build build`
109118

110119
6. If the project was configured to build tests, run the tests.
111-
120+
112121
`cmake --build build -t test`
113122

114123
7. If the project was configured to build tests and Gcovr is installed, generate a coverage report. The coverage report can be found in the `build` directory at `coverage.html`.
115-
124+
116125
`cmake --build build -t coverage-no-test` or `cmake --build build -t coverage` to run the tests and generate the coverage report in a single command

docs/Add_Messages.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ Use the other files as reference but here are the minimum requirements:
2929
double min_angle_radian = 1;
3030
double max_angle_radian = 2;
3131
double center_angle_radian = 3;
32-
double min_duty_cycle_microseconds = 4;
33-
double max_duty_cycle_microseconds = 5;
34-
double center_duty_cycle_microseconds = 6;
32+
double min_duty_cycle_percentage = 4;
33+
double max_duty_cycle_percentage = 5;
34+
double center_duty_cycle_percentage = 6;
3535
}
3636
3737
message ConfigServoWheels {
@@ -65,9 +65,11 @@ It'd be best to initialize the new protobuf message using the build directions i
6565
#### `cave_talk.h`
6666
---
6767
68-
- Add a function pointer callback to `CaveTalk_ListenCallbacks_t`
68+
- If the function establishes a new typedef struct, include the message's `.pb.h` header file
69+
- Add a function pointer callback to `CaveTalk_ListenCallbacks_t` struct
6970
- Output: `void`
7071
- Input: `output params`
72+
- Add callback field for `kCaveTalk_ListenCallbacksNull`
7173
- Add a `CaveTalk_Speak______` function
7274
- Output: `CaveTalk_Error_t`
7375
- Input: `"handle" ptr`, `output params`
@@ -93,6 +95,7 @@ It'd be best to initialize the new protobuf message using the build directions i
9395
#### `cave_talk.h`
9496
---
9597
98+
- If the message adds a new Class for a message field, add the message's `.pb.h` file
9699
- Add ListenerCallback virtual function for message
97100
- Output: `void`
98101
- Input: `output params`
@@ -126,6 +129,6 @@ Good tests have these qualities:
126129
- Tests foreseeable edge cases
127130
- Tests odd input values
128131
- Utilizes Mock functions where possible
129-
- If values cannot be checked directly through tests, leave a comment where a breakpoint could be used to see values
132+
- Use the Assert Workaround for New Protobuf-Generated Objects without operator==
130133
131134

docs/cppcheck.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ To setup Cppcheck in a local repository, follow these steps:
2222

2323
Cppcheck can now be run from the repository root with `cmake --build build -t cppcheck` assuming CMake has been configured with build directory `build`.
2424

25-
To enable the pre-commit hook that automatically runs Cppcheck before each commit, run `git config core.hooksPath tools/hooks`. Note: This pre-commit hooks may also run other checks.
25+
To enable the pre-commit hook that automatically runs Cppcheck before each commit, run `git config core.hooksPath tools/hooks`. Note: This pre-commit hooks may also run other checks.
26+
27+
Cppcheck outputs to `build/cppcheck_report.xml` for debugging failed checks

lib/c++/inc/cave_talk.h

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@
66
#include <memory>
77
#include <vector>
88

9-
#include "ooga_booga.pb.h"
10-
#include "config_servo.pb.h"
9+
#include "air_quality.pb.h"
10+
#include "config_encoder.pb.h"
11+
#include "config_log.pb.h"
1112
#include "config_motor.pb.h"
12-
#include "odometry.pb.h"
13+
#include "config_pid.pb.h"
14+
#include "config_servo.pb.h"
1315
#include "log.pb.h"
16+
#include "odometry.pb.h"
17+
#include "ooga_booga.pb.h"
18+
#include "relative_move.pb.h"
1419

1520
#include "cave_talk_link.h"
1621
#include "cave_talk_types.h"
@@ -21,17 +26,23 @@ namespace cave_talk
2126
class ListenerCallbacks
2227
{
2328
public:
24-
virtual ~ListenerCallbacks() = 0;
25-
virtual void HearOogaBooga(const Say ooga_booga) = 0;
26-
virtual void HearMovement(const CaveTalk_MetersPerSecond_t speed, const CaveTalk_RadiansPerSecond_t turn_rate) = 0;
27-
virtual void HearCameraMovement(const CaveTalk_Radian_t pan, const CaveTalk_Radian_t tilt) = 0;
28-
virtual void HearLights(const bool headlights) = 0;
29-
virtual void HearMode(const bool manual) = 0;
30-
virtual void HearOdometry(const Imu &IMU, const Encoder &encoder_wheel_0, const Encoder &encoder_wheel_1, const Encoder &encoder_wheel_2, const Encoder &encoder_wheel_3) = 0;
31-
virtual void HearLog(const char *const log) = 0;
32-
virtual void HearConfigServoWheels(const Servo &servo_wheel_0, const Servo &servo_wheel_1, const Servo &servo_wheel_2, const Servo &servo_wheel_3) = 0;
33-
virtual void HearConfigServoCams(const Servo &servo_cam_pan, const Servo &servo_cam_tilt) = 0;
34-
virtual void HearConfigMotor(const Motor &motor_wheel_0, const Motor &motor_wheel_1, const Motor &motor_wheel_2, const Motor &motor_wheel_3) = 0;
29+
virtual ~ListenerCallbacks() = 0;
30+
virtual void HearOogaBooga(const Say ooga_booga) = 0;
31+
virtual void HearMovement(const CaveTalk_MetersPerSecond_t speed, const CaveTalk_RadiansPerSecond_t turn_rate) = 0;
32+
virtual void HearCameraMovement(const CaveTalk_Radian_t pan, const CaveTalk_Radian_t tilt) = 0;
33+
virtual void HearLights(const bool headlights) = 0;
34+
virtual void HearArm(const bool arm) = 0;
35+
virtual void HearOdometry(const Imu &IMU, const Encoder &encoder_wheel_0, const Encoder &encoder_wheel_1, const Encoder &encoder_wheel_2, const Encoder &encoder_wheel_3) = 0;
36+
virtual void HearLog(const char *const log) = 0;
37+
virtual void HearConfigServoWheels(const Servo &servo_wheel_0, const Servo &servo_wheel_1, const Servo &servo_wheel_2, const Servo &servo_wheel_3) = 0;
38+
virtual void HearConfigServoCams(const Servo &servo_cam_pan, const Servo &servo_cam_tilt) = 0;
39+
virtual void HearConfigMotor(const Motor &motor_wheel_0, const Motor &motor_wheel_1, const Motor &motor_wheel_2, const Motor &motor_wheel_3) = 0;
40+
virtual void HearConfigEncoder(const ConfigEncoder &encoder_wheel_0, const ConfigEncoder &encoder_wheel_1, const ConfigEncoder &encoder_wheel_2, const ConfigEncoder &encoder_wheel_3) = 0;
41+
virtual void HearConfigLog(const LogLevel log_level) = 0;
42+
virtual void HearConfigWheelSpeedControl(const PID &wheel_0_params, const PID &wheel_1_params, const PID &wheel_2_params, const PID &wheel_3_params, const bool enabled) = 0;
43+
virtual void HearConfigSteeringControl(const PID &turn_rate_params, const bool enabled) = 0;
44+
virtual void HearAirQuality(const uint32_t dust_ug_per_m3, const uint32_t gas_ppm, const double temperature_celsius) = 0;
45+
virtual void HearRelativeMove(const RelativeMoveType type, const CaveTalk_Meter_t position, const CaveTalk_Radian_t pose) = 0;
3546
};
3647

3748
class Listener
@@ -50,12 +61,18 @@ class Listener
5061
CaveTalk_Error_t HandleMovement(const CaveTalk_Length_t length) const;
5162
CaveTalk_Error_t HandleCameraMovement(const CaveTalk_Length_t length) const;
5263
CaveTalk_Error_t HandleLights(const CaveTalk_Length_t length) const;
53-
CaveTalk_Error_t HandleMode(const CaveTalk_Length_t length) const;
54-
CaveTalk_Error_t HandleLog(const CaveTalk_Length_t length) const;
64+
CaveTalk_Error_t HandleArm(const CaveTalk_Length_t length) const;
5565
CaveTalk_Error_t HandleOdometry(const CaveTalk_Length_t length) const;
66+
CaveTalk_Error_t HandleLog(const CaveTalk_Length_t length) const;
5667
CaveTalk_Error_t HandleConfigServoWheels(const CaveTalk_Length_t length) const;
5768
CaveTalk_Error_t HandleConfigServoCams(const CaveTalk_Length_t length) const;
5869
CaveTalk_Error_t HandleConfigMotor(const CaveTalk_Length_t length) const;
70+
CaveTalk_Error_t HandleConfigEncoder(const CaveTalk_Length_t length) const;
71+
CaveTalk_Error_t HandleConfigLog(const CaveTalk_Length_t length) const;
72+
CaveTalk_Error_t HandleConfigWheelSpeedControl(const CaveTalk_Length_t length) const;
73+
CaveTalk_Error_t HandleConfigSteeringControl(const CaveTalk_Length_t length) const;
74+
CaveTalk_Error_t HandleAirQuality(const CaveTalk_Length_t length) const;
75+
CaveTalk_Error_t HandleRelativeMove(CaveTalk_Length_t length) const;
5976
CaveTalk_LinkHandle_t link_handle_;
6077
std::shared_ptr<ListenerCallbacks> listener_callbacks_;
6178
std::array<uint8_t, CAVE_TALK_MAX_PAYLOAD_SIZE> buffer_;
@@ -73,12 +90,18 @@ class Talker
7390
CaveTalk_Error_t SpeakMovement(const CaveTalk_MetersPerSecond_t speed, const CaveTalk_RadiansPerSecond_t turn_rate);
7491
CaveTalk_Error_t SpeakCameraMovement(const CaveTalk_Radian_t pan, const CaveTalk_Radian_t tilt);
7592
CaveTalk_Error_t SpeakLights(const bool headlights);
76-
CaveTalk_Error_t SpeakMode(const bool manual);
77-
CaveTalk_Error_t SpeakLog(const char *const log);
93+
CaveTalk_Error_t SpeakArm(const bool arm);
7894
CaveTalk_Error_t SpeakOdometry(const Imu &IMU, const Encoder &encoder_wheel_0, const Encoder &encoder_wheel_1, const Encoder &encoder_wheel_2, const Encoder &encoder_wheel_3);
95+
CaveTalk_Error_t SpeakLog(const char *const log);
7996
CaveTalk_Error_t SpeakConfigServoWheels(const Servo &servo_wheel_0, const Servo &servo_wheel_1, const Servo &servo_wheel_2, const Servo &servo_wheel_3);
8097
CaveTalk_Error_t SpeakConfigServoCams(const Servo &servo_cam_pan, const Servo &servo_cam_tilt);
8198
CaveTalk_Error_t SpeakConfigMotor(const Motor &motor_wheel_0, const Motor &motor_wheel_1, const Motor &motor_wheel_2, const Motor &motor_wheel_3);
99+
CaveTalk_Error_t SpeakConfigEncoder(const ConfigEncoder &encoder_wheel_0, const ConfigEncoder &encoder_wheel_1, const ConfigEncoder &encoder_wheel_2, const ConfigEncoder &encoder_wheel_3);
100+
CaveTalk_Error_t SpeakConfigLog(const LogLevel log_level);
101+
CaveTalk_Error_t SpeakConfigWheelSpeedControl(const PID &wheel_0_params, const PID &wheel_1_params, const PID &wheel_2_params, const PID &wheel_3_params, const bool enabled);
102+
CaveTalk_Error_t SpeakConfigSteeringControl(const PID &turn_rate_params, const bool enabled);
103+
CaveTalk_Error_t SpeakAirQuality(const uint32_t dust_ug_per_m3, const uint32_t gas_ppm, const double temperature_celsius);
104+
CaveTalk_Error_t SpeakRelativeMove(const RelativeMoveType type, const CaveTalk_Meter_t position, const CaveTalk_Radian_t pose);
82105

83106
private:
84107
CaveTalk_LinkHandle_t link_handle_;

0 commit comments

Comments
 (0)