-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add minipc protocol 2.0 #66
Merged
Merged
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7485c7a
Break Send() into Pack() for each message type
AzulRadio b01f544
add function headers and helpers for Pack()
AzulRadio eed4e22
lossless float transmission
AzulRadio 2b2b557
data parse rewrite
AzulRadio 7a07240
modify typeC example
AzulRadio a1cb494
rename autoaim_protocol as minipc_protocol; add more comments.
AzulRadio fb453f2
add send example and motor example
AzulRadio 98994bc
fix compiler error
AzulRadio cd9dcc5
Added Some tests
rickxu2 c0c9626
changed latency test; modified stress test
rickxu2 3e3f13a
remove original pingpong test; merge 3 latency tests into 1
AzulRadio 2e4f935
edit some comments as review suggests
AzulRadio fedf2a3
some final tweaks on tests
rickxu2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/**************************************************************************** | ||
* * | ||
* Copyright (C) 2023 RoboMaster. * | ||
* Illini RoboMaster @ University of Illinois at Urbana-Champaign * | ||
* * | ||
* This program is free software: you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation, either version 3 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
* This program is distributed in the hope that it will be useful, * | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
* GNU General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU General Public License * | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. * | ||
* * | ||
****************************************************************************/ | ||
|
||
#include "main.h" | ||
|
||
#include <cstring> | ||
#include <memory> | ||
|
||
#include "bsp_gpio.h" | ||
#include "bsp_print.h" | ||
#include "bsp_uart.h" | ||
#include "cmsis_os.h" | ||
#include "minipc_protocol.h" | ||
#include "rgb.h" | ||
|
||
#define RX_SIGNAL (1 << 0) | ||
|
||
extern osThreadId_t defaultTaskHandle; | ||
|
||
static display::RGB* led = nullptr; | ||
|
||
class CustomUART : public bsp::UART { | ||
public: | ||
using bsp::UART::UART; | ||
|
||
protected: | ||
/* notify application when rx data is pending read */ | ||
void RxCompleteCallback() override final { osThreadFlagsSet(defaultTaskHandle, RX_SIGNAL); } | ||
}; | ||
|
||
void RM_RTOS_Init(void) { | ||
led = new display::RGB(&htim5, 3, 2, 1, 1000000); | ||
} | ||
|
||
void RM_RTOS_Default_Task(const void* argument) { | ||
UNUSED(argument); | ||
|
||
auto uart = std::make_unique<CustomUART>(&huart1); // see cmake for which uart | ||
uart->SetupRx(50); | ||
uart->SetupTx(50); | ||
|
||
auto minipc_session = communication::MinipcPort(); | ||
|
||
communication::chassis_data_t chassis_data; | ||
|
||
const communication::status_data_t* status_data; | ||
|
||
chassis_data.vx = 0; | ||
chassis_data.vy = 0; | ||
chassis_data.vw = 0; | ||
|
||
|
||
uint8_t packet_to_send[minipc_session.MAX_PACKET_LENGTH]; | ||
uint8_t *data; | ||
int32_t length; | ||
|
||
while (true) { | ||
/* wait until rx data is available */ | ||
//led->Display(0xFF0000FF); | ||
|
||
// Latency test. Use with communication/communicator.py in iRM_Vision_2023 repo | ||
// In the communicator.py, need to set testing = Test.LATENCY for this test | ||
|
||
// Wait until first packet from minipc. | ||
uint32_t flags = osThreadFlagsWait(RX_SIGNAL, osFlagsWaitAll, osWaitForever); | ||
if (flags & RX_SIGNAL) { | ||
length = uart->Read(&data); | ||
minipc_session.ParseUartBuffer(data, length); | ||
status_data = minipc_session.GetStatus(); | ||
if (status_data->vx == 10){ | ||
chassis_data.vx = 9; | ||
} | ||
if (status_data->vy == 11){ | ||
chassis_data.vy = 8; | ||
} | ||
if (status_data->vw == 12){ | ||
chassis_data.vw = 7; | ||
} | ||
minipc_session.Pack(packet_to_send, (void*)&chassis_data, communication::CHASSIS_CMD_ID); | ||
uart->Write(packet_to_send, minipc_session.GetPacketLen(communication::CHASSIS_CMD_ID)); | ||
} | ||
osDelay(10); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/**************************************************************************** | ||
* * | ||
* Copyright (C) 2023 RoboMaster. * | ||
* Illini RoboMaster @ University of Illinois at Urbana-Champaign * | ||
* * | ||
* This program is free software: you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation, either version 3 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
* This program is distributed in the hope that it will be useful, * | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
* GNU General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU General Public License * | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. * | ||
* * | ||
****************************************************************************/ | ||
|
||
#include "main.h" | ||
|
||
#include <cstring> | ||
#include <memory> | ||
|
||
#include "bsp_gpio.h" | ||
#include "bsp_print.h" | ||
#include "bsp_uart.h" | ||
#include "cmsis_os.h" | ||
#include "minipc_protocol.h" | ||
#include "rgb.h" | ||
|
||
#define RX_SIGNAL (1 << 0) | ||
|
||
extern osThreadId_t defaultTaskHandle; | ||
|
||
static display::RGB* led = nullptr; | ||
|
||
class CustomUART : public bsp::UART { | ||
public: | ||
using bsp::UART::UART; | ||
|
||
protected: | ||
/* notify application when rx data is pending read */ | ||
void RxCompleteCallback() override final { osThreadFlagsSet(defaultTaskHandle, RX_SIGNAL); } | ||
}; | ||
|
||
void RM_RTOS_Init(void) { | ||
led = new display::RGB(&htim5, 3, 2, 1, 1000000); | ||
} | ||
|
||
void RM_RTOS_Default_Task(const void* argument) { | ||
UNUSED(argument); | ||
|
||
auto uart = std::make_unique<CustomUART>(&huart1); // see cmake for which uart | ||
uart->SetupRx(50); | ||
uart->SetupTx(50); | ||
|
||
auto minipc_session = communication::MinipcPort(); | ||
|
||
communication::color_data_t color_data; | ||
|
||
const communication::status_data_t* status_data; | ||
|
||
color_data.my_color = 0; | ||
|
||
uint8_t packet_to_send[minipc_session.MAX_PACKET_LENGTH]; | ||
uint8_t *data; | ||
int32_t length; | ||
|
||
while (true) { | ||
/* wait until rx data is available */ | ||
//led->Display(0xFF0000FF); | ||
|
||
// Latency test. Use with communication/communicator.py in iRM_Vision_2023 repo | ||
// In the communicator.py, need to set testing = Test.LATENCY for this test | ||
|
||
// Wait until first packet from minipc. | ||
uint32_t flags = osThreadFlagsWait(RX_SIGNAL, osFlagsWaitAll, osWaitForever); | ||
if (flags & RX_SIGNAL) { | ||
length = uart->Read(&data); | ||
minipc_session.ParseUartBuffer(data, length); | ||
status_data = minipc_session.GetStatus(); | ||
if (status_data->my_color == 0){ | ||
color_data.my_color = 0; | ||
} | ||
minipc_session.Pack(packet_to_send, (void*)&color_data, communication::COLOR_CMD_ID); | ||
uart->Write(packet_to_send, minipc_session.GetPacketLen(communication::COLOR_CMD_ID)); | ||
} | ||
osDelay(10); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/**************************************************************************** | ||
* * | ||
* Copyright (C) 2023 RoboMaster. * | ||
* Illini RoboMaster @ University of Illinois at Urbana-Champaign * | ||
* * | ||
* This program is free software: you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation, either version 3 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
* This program is distributed in the hope that it will be useful, * | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
* GNU General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU General Public License * | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. * | ||
* * | ||
****************************************************************************/ | ||
|
||
#include "main.h" | ||
|
||
#include <cstring> | ||
#include <memory> | ||
|
||
#include "bsp_gpio.h" | ||
#include "bsp_print.h" | ||
#include "bsp_uart.h" | ||
#include "cmsis_os.h" | ||
#include "minipc_protocol.h" | ||
#include "rgb.h" | ||
|
||
#define RX_SIGNAL (1 << 0) | ||
|
||
extern osThreadId_t defaultTaskHandle; | ||
|
||
static display::RGB* led = nullptr; | ||
|
||
class CustomUART : public bsp::UART { | ||
public: | ||
using bsp::UART::UART; | ||
|
||
protected: | ||
/* notify application when rx data is pending read */ | ||
void RxCompleteCallback() override final { osThreadFlagsSet(defaultTaskHandle, RX_SIGNAL); } | ||
}; | ||
|
||
void RM_RTOS_Init(void) { | ||
led = new display::RGB(&htim5, 3, 2, 1, 1000000); | ||
} | ||
|
||
void RM_RTOS_Default_Task(const void* argument) { | ||
UNUSED(argument); | ||
|
||
auto uart = std::make_unique<CustomUART>(&huart1); // see cmake for which uart | ||
uart->SetupRx(50); | ||
uart->SetupTx(50); | ||
|
||
auto minipc_session = communication::MinipcPort(); | ||
|
||
communication::chassis_data_t chassis_data; // this has to be the data type that has the maximum size | ||
|
||
const communication::status_data_t* status_data; | ||
|
||
chassis_data.vx = 0.0; | ||
chassis_data.vy = 0.0; | ||
chassis_data.vw = 0.0; | ||
|
||
uint8_t packet_to_send[minipc_session.MAX_PACKET_LENGTH]; | ||
uint8_t *data; | ||
int32_t length; | ||
|
||
while (true) { | ||
/* wait until rx data is available */ | ||
//led->Display(0xFF0000FF); | ||
|
||
// Latency test. Use with communication/communicator.py in iRM_Vision_2023 repo | ||
// In the communicator.py, need to set testing = Test.LATENCY for this test | ||
|
||
// Wait until first packet from minipc. | ||
uint32_t flags = osThreadFlagsWait(RX_SIGNAL, osFlagsWaitAll, osWaitForever); | ||
if (flags & RX_SIGNAL) { | ||
length = uart->Read(&data); | ||
minipc_session.ParseUartBuffer(data, length); | ||
status_data = minipc_session.GetStatus(); | ||
chassis_data.vx = status_data->vx; | ||
minipc_session.Pack(packet_to_send, (void*)&chassis_data, communication::CHASSIS_CMD_ID); | ||
uart->Write(packet_to_send, minipc_session.GetPacketLen(communication::CHASSIS_CMD_ID)); | ||
} | ||
osDelay(10); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why commented out