Compare commits

2 Commits

Author SHA1 Message Date
Stefano Calabretti 400513c97c Update README 2022-05-31 10:16:35 +02:00
Stefano Calabretti e2fcbf4154 new steering ids (#14)
* odometry id

* new steering ids

* Update gitignore

Co-authored-by: aesthetic-sofa <71275573+aesthetic-sofa@users.noreply.github.com>
2022-05-17 14:29:09 +02:00
2 changed files with 83 additions and 2 deletions
+21 -1
View File
@@ -126,8 +126,28 @@ enum MmrCanMessageId {
MMR_CAN_MESSAGE_ID_D_SPEED_ODOMETRY, MMR_CAN_MESSAGE_ID_D_SPEED_ODOMETRY,
// !DRIVE // !DRIVE
// ECU_BOSCH // ECU_BOSCH
MMR_CAN_MESSAGE_ID_ECU_BOSCH_ = 192, MMR_CAN_MESSAGE_ID_ECU_BOSCH_SPEED = 192,
MMR_CAN_MESSAGE_ID_ECU_BOSCH_GEAR,
MMR_CAN_MESSAGE_ID_ECU_BOSCH_RPM,
MMR_CAN_MESSAGE_ID_ECU_BOSCH_THROTTLE,
MMR_CAN_MESSAGE_ID_ECU_BOSCH_TEMP_OIL,
MMR_CAN_MESSAGE_ID_ECU_BOSCH_TEMP_WATER,
MMR_CAN_MESSAGE_ID_ECU_BOSCH_TORQUE,
// !ECU_BOSCH // !ECU_BOSCH
// CONTROL_SIGNAL
MMR_CAN_MESSAGE_ID_CS_CLUTCH_SIGNAL = 224,
MMR_CAN_MESSAGE_ID_CS_CLUTCH_FEEDBACK,
// !CONTROL_SIGNAL
// STEERING
MMR_CAN_MESSAGE_ID_ST_PROPORTIONAL_ERROR_LEFT_X = 256,
MMR_CAN_MESSAGE_ID_ST_PROPORTIONAL_ERROR_RIGHT_X,
MMR_CAN_MESSAGE_ID_ST_PROPORTIONAL_ODOMETRY_MIN_SPEED_LEFT_X,
MMR_CAN_MESSAGE_ID_ST_PROPORTIONAL_ODOMETRY_MIN_SPEED_LEFT_Y,
MMR_CAN_MESSAGE_ID_ST_PROPORTIONAL_ODOMETRY_MIN_SPEED_RIGHT_X,
MMR_CAN_MESSAGE_ID_ST_PROPORTIONAL_ODOMETRY_MIN_SPEED_RIGHT_Y,
MMR_CAN_MESSAGE_ID_ST_PROPORTIONAL_ODOMETRY_MAX_SPEED_LEFT_Y,
MMR_CAN_MESSAGE_ID_ST_PROPORTIONAL_ODOMETRY_MAX_SPEED_RIGHT_Y,
// !STEERING
}; };
#endif // !INC_MMR_CAN_MESSAGE_ID_H_ #endif // !INC_MMR_CAN_MESSAGE_ID_H_
+62 -1
View File
@@ -4,7 +4,7 @@ You can add this library to your project by either cloning it or adding it as a
--- ---
### Add as a submodule (recommended) ## Add as a submodule (recommended)
To **add mmr_can as a submodule**, go into your project folder and run To **add mmr_can as a submodule**, go into your project folder and run
``` ```
git submodule add https://github.com/mmr-driverless/mmr_can.git Drivers/MMR_CAN git submodule add https://github.com/mmr-driverless/mmr_can.git Drivers/MMR_CAN
@@ -16,3 +16,64 @@ mmr_can will be cloned inside the `Drivers` folder
After adding the submodule, right click on your project's name from within the STM32CubeIDE, then `Properties (last option) > C/C++ General > Paths and Symbols` After adding the submodule, right click on your project's name from within the STM32CubeIDE, then `Properties (last option) > C/C++ General > Paths and Symbols`
You'll see a list of directories on the right, click on `Add`, then type `Drivers/MMR_CAN/Inc` and press enter You'll see a list of directories on the right, click on `Add`, then type `Drivers/MMR_CAN/Inc` and press enter
# Examples
## Setup
Configure the CAN peripheral in the _.ioc_ file, then call the following initialization function
inside _main_.
```c
#include "mmr_can.h"
int main() {
// MX_CAN_INIT()...
if (MMR_CAN_BasicSetupAndStart(&hcan) != HAK_OK) {
Error_Handler();
}
// while (1) {...
}
```
## Sending a message
```c
void sendAMessage() {
// my_data_type data = something;
uint16_t data = 123;
MmrCanPacket packet = {
.data = (uint8_t*)(&data),
.length = sizeof(data),
.header.messageId = MMR_CAN_MESSAGE_ID_<ID>,
};
if (MMR_CAN_Send(&hcan, packet) != HAL_OK) {
; // Error
}
}
```
## Receiving a message
```c
void receiveAMessage() {
CanRxBuffer buffer = {};
MmrCanMessage message = {
.store = buffer,
};
MmrResult result = MMR_CAN_TryReceive(&hcan, &message);
if (result == MMR_RESULT_ERROR) {
; // Error
}
else if (result == MMR_RESULT_PENDING) {
return;
}
if (message.header.messageId == MMR_CAN_MESSAGE_ID<TARGET_ID>) {
uint16_t data = *(uint16_t*)buffer;
}
}
```