Skip to content
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 13 commits into from
Dec 30, 2023
6 changes: 3 additions & 3 deletions examples/autoaim/CMakeLists.txt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why commented out

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@

project(example_autoaim ASM C CXX)

irm_add_arm_executable(${PROJECT_NAME}
TARGET DJI_Board_TypeC
SOURCES main.cc)
#irm_add_arm_executable(${PROJECT_NAME}
# TARGET DJI_Board_TypeC
# SOURCES main.cc)
4 changes: 2 additions & 2 deletions examples/autoaim/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "gimbal.h"
#include "rgb.h"
#include "bsp_gpio.h"
#include "autoaim_protocol.h"
#include "minipc_protocol.h"
#include "filtering.h"
#include "i2c.h"
#include "bsp_imu.h"
Expand Down Expand Up @@ -305,4 +305,4 @@ void RM_RTOS_Default_Task(const void* args) {
control::MotorCANBase::TransmitOutput(motors, 2);
osDelay(10);
}
}
}
27 changes: 25 additions & 2 deletions examples/minipc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,30 @@ irm_add_arm_executable(${PROJECT_NAME}
TARGET DJI_Board_TypeA
SOURCES typeA.cc)

irm_add_arm_executable(${PROJECT_NAME}_typeC
irm_add_arm_executable(${PROJECT_NAME}_stresstesttypec
TARGET DJI_Board_TypeC
SOURCES typeC.cc)
SOURCES StressTestTypeC.cc)

irm_add_arm_executable(${PROJECT_NAME}_pingpongtest
TARGET DJI_Board_TypeC
SOURCES PingpongTest.cc)

irm_add_arm_executable(${PROJECT_NAME}_modifiedpingpongtest
TARGET DJI_Board_TypeC
SOURCES PingpongTestPlus.cc)

irm_add_arm_executable(${PROJECT_NAME}_motor
TARGET DJI_Board_TypeA
SOURCES MotorTest.cc)

irm_add_arm_executable(${PROJECT_NAME}_latency
TARGET DJI_Board_TypeC
SOURCES LatencyTest.cc)

irm_add_arm_executable(${PROJECT_NAME}_color
TARGET DJI_Board_TypeC
SOURCES ColorTest.cc)

irm_add_arm_executable(${PROJECT_NAME}_chassis
TARGET DJI_Board_TypeC
SOURCES ChassisTest.cc)
101 changes: 101 additions & 0 deletions examples/minipc/ChassisTest.cc
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);
}
}
92 changes: 92 additions & 0 deletions examples/minipc/ColorTest.cc
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);
}
}
92 changes: 92 additions & 0 deletions examples/minipc/LatencyTest.cc
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);
}
}
Loading
Loading