9b52a9ec64
- Delete modules/master_machine/ (old seasky protocol vision module) - Rename modules/opencv/ → modules/master_machine/ - Rename opencv.h/c → master_machine.h/c - Remove master_process.h include from robot_def.h and ins_task.c - Remove VisionSetAltitude() call from ins_task.c (send not needed) - Update all #include paths and CMakeLists.txt
76 lines
2.0 KiB
C
76 lines
2.0 KiB
C
#include "master_machine.h"
|
|
|
|
VisionData_t vision_data;
|
|
|
|
static USARTInstance *cv_usart_instance;
|
|
static DaemonInstance *vision_daemon_instance;
|
|
|
|
static uint8_t calc_checksum(uint8_t *buf, uint8_t len)
|
|
{
|
|
uint8_t sum = 0;
|
|
for (uint8_t i = 0; i < len - 1; i++)
|
|
sum += buf[i];
|
|
return sum;
|
|
}
|
|
|
|
static void DecodeVision()
|
|
{
|
|
DaemonReload(vision_daemon_instance);
|
|
|
|
static uint32_t counter;
|
|
float dt = DWT_GetDeltaT(&counter);
|
|
vision_data.frequency = 1.0f / dt;
|
|
|
|
uint8_t *buf = cv_usart_instance->recv_buff;
|
|
uint16_t len = cv_usart_instance->recv_buff_size;
|
|
uint8_t sof = buf[0];
|
|
|
|
if (sof == VISION_SOF_AUTO && len == VISION_AUTO_LEN)
|
|
{
|
|
if (calc_checksum(buf, VISION_AUTO_LEN) != buf[VISION_AUTO_LEN - 1])
|
|
return;
|
|
memcpy(&vision_data.error_x, buf + 1, 4);
|
|
memcpy(&vision_data.error_y, buf + 5, 4);
|
|
vision_data.auto_updated = 1;
|
|
}
|
|
else if (sof == VISION_SOF_MANUAL && len == VISION_MANUAL_LEN)
|
|
{
|
|
if (calc_checksum(buf, VISION_MANUAL_LEN) != buf[VISION_MANUAL_LEN - 1])
|
|
return;
|
|
vision_data.zero_force = buf[1];
|
|
memcpy(&vision_data.yaw_ref, buf + 2, 4);
|
|
memcpy(&vision_data.pitch_ref, buf + 6, 4);
|
|
vision_data.manual_updated = 1;
|
|
}
|
|
else if (sof == VISION_SOF_CMD && len == VISION_CMD_LEN)
|
|
{
|
|
if (calc_checksum(buf, VISION_CMD_LEN) != buf[VISION_CMD_LEN - 1])
|
|
return;
|
|
vision_data.cmd = buf[1];
|
|
vision_data.cmd_pending = 1;
|
|
}
|
|
}
|
|
|
|
static void VisionOfflineCallback(void *id)
|
|
{
|
|
(void)id;
|
|
USARTServiceInit(cv_usart_instance);
|
|
}
|
|
|
|
void Vision_Uart_Init(UART_HandleTypeDef *_handle)
|
|
{
|
|
USART_Init_Config_s conf = {
|
|
.module_callback = DecodeVision,
|
|
.recv_buff_size = 64,
|
|
.usart_handle = _handle,
|
|
};
|
|
cv_usart_instance = USARTRegister(&conf);
|
|
|
|
Daemon_Init_Config_s daemon_conf = {
|
|
.callback = NULL,
|
|
.owner_id = NULL,
|
|
.reload_count = 10,
|
|
};
|
|
vision_daemon_instance = DaemonRegister(&daemon_conf);
|
|
}
|