Skip to content

Commit

Permalink
communication example
Browse files Browse the repository at this point in the history
  • Loading branch information
AzulRadio committed Feb 22, 2022
1 parent f285b1f commit b1b71c0
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

add_subdirectory(buzzer)
add_subdirectory(chassis)
add_subdirectory(communication)
add_subdirectory(dbus)
add_subdirectory(eigen)
add_subdirectory(gimbal)
Expand Down
26 changes: 26 additions & 0 deletions examples/communication/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ---------------------------------------------------------------------- #
# #
# Copyright (C) 2022 #
# 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/>. #
# #
# ---------------------------------------------------------------------- #

project(example_communication ASM C CXX)

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

107 changes: 107 additions & 0 deletions examples/communication/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/****************************************************************************
* *
* Copyright (C) 2022 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 "bsp_gpio.h"
#include "bsp_print.h"
#include "bsp_uart.h"
#include "cmsis_os.h"
#include "main.h"
#include "protocol.h"

#define RX_SIGNAL (1 << 0)

extern osThreadId_t defaultTaskHandle;

const osThreadAttr_t clientTaskAttribute = {.name = "clientTask",
.attr_bits = osThreadDetached,
.cb_mem = nullptr,
.cb_size = 0,
.stack_mem = nullptr,
.stack_size = 128 * 4,
.priority = (osPriority_t)osPriorityNormal,
.tz_module = 0,
.reserved = 0};
osThreadId_t clientTaskHandle;

class CustomUART : public bsp::UART {
public:
using bsp::UART::UART;

protected:
/* notify application when rx data is pending read */
void RxCompleteCallback() final { osThreadFlagsSet(clientTaskHandle, RX_SIGNAL); }
};

static communication::Host* host = nullptr;
static CustomUART* host_uart = nullptr;
static bsp::GPIO *gpio_red, *gpio_green;

void clientTask(void* arg) {
UNUSED(arg);
uint32_t length;
uint8_t* data;

while (true) {
/* wait until rx data is available */
uint32_t flags = osThreadFlagsWait(RX_SIGNAL, osFlagsWaitAll, osWaitForever);
if (flags & RX_SIGNAL) { // unnecessary check
/* time the non-blocking rx / tx calls (should be <= 1 osTick) */
length = host_uart->Read(&data);
host->Receive(communication::package_t{data, (int)length});
gpio_green->Low();
osDelay(200);
gpio_green->High();
}
}
}

void RM_RTOS_Init(void) {
print_use_uart(&huart8);

host_uart = new CustomUART(&huart6);
host_uart->SetupRx(300);
host_uart->SetupTx(300);

host = new communication::Host;

gpio_red = new bsp::GPIO(LED_RED_GPIO_Port, LED_RED_Pin);
gpio_green = new bsp::GPIO(LED_GREEN_GPIO_Port, LED_GREEN_Pin);
gpio_red->High();
gpio_green->High();
}

void RM_RTOS_Threads_Init(void) {
clientTaskHandle = osThreadNew(clientTask, nullptr, &clientTaskAttribute);
}

void RM_RTOS_Default_Task(const void* argument) {
UNUSED(argument);

while (true) {
set_cursor(0, 0);
clear_screen();
print("%c\n", host->pack.chars[0]);
//print("%s\n", host->target_angle.pitch);
//print("%s\n", host->target_angle.yaw);
//print("%s\n", host->no_target_flag.dummy);
//print("%s\n", host->shoot_cmd.dummy);
osDelay(500);
}
}
4 changes: 2 additions & 2 deletions vehicles/Sentry/rm_rtos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ void RM_RTOS_Default_Task(const void* args) {
UNUSED(args);
control::MotorCANBase* motors[] = {pitch_motor, yaw_motor, load_motor};
control::gimbal_data_t gimbal_data = gimbal->GetData();
bsp::GPIO laser(LASER_GPIO_Port, LASER_Pin);
laser.High();
//bsp::GPIO laser(LASER_GPIO_Port, LASER_Pin);
//laser.High();

bool load = false;
bool abs_mode = true;
Expand Down

0 comments on commit b1b71c0

Please sign in to comment.