86 lines
2.8 KiB
C
86 lines
2.8 KiB
C
#include "app_tasks.h"
|
|
#include "cmsis_os.h"
|
|
#include "FreeRTOS.h"
|
|
#include "task.h"
|
|
#include "c_comm.h"
|
|
#include "robot_typedef.h"
|
|
#include "robot_param.h"
|
|
#if defined(ROBOT_TYPE_GIMBAL)
|
|
#include "robot_cmd_task.h"
|
|
#include "gimbal.h"
|
|
#include "attitude.h"
|
|
#elif defined(ROBOT_TYPE_CHASSIS)
|
|
#include "chassis.h"
|
|
#endif
|
|
|
|
#if defined(ROBOT_TYPE_GIMBAL)
|
|
/*
|
|
*函数简介:打包合并后的键鼠12字节报文
|
|
*参数说明:输出12字节键鼠缓冲区
|
|
*返回类型:无
|
|
*备注:直接使用robot_cmd_task生成的keyboard_merged,保证云台与底盘键鼠来源一致
|
|
*/
|
|
static void c_comm_pack_kb(uint8_t kb[12])
|
|
{
|
|
kb[0] = (uint8_t)(keyboard_merged.mouse_rl & 0xFF);
|
|
kb[1] = (uint8_t)((uint16_t)keyboard_merged.mouse_rl >> 8);
|
|
kb[2] = (uint8_t)(keyboard_merged.mouse_du & 0xFF);
|
|
kb[3] = (uint8_t)((uint16_t)keyboard_merged.mouse_du >> 8);
|
|
kb[4] = (uint8_t)(keyboard_merged.mouse_wheel & 0xFF);
|
|
kb[5] = (uint8_t)((uint16_t)keyboard_merged.mouse_wheel >> 8);
|
|
kb[6] = keyboard_merged.mouse_key_l;
|
|
kb[7] = keyboard_merged.mouse_key_r;
|
|
kb[8] = (uint8_t)(keyboard_merged.key_w | (keyboard_merged.key_s << 1) |
|
|
(keyboard_merged.key_a << 2) | (keyboard_merged.key_d << 3) |
|
|
(keyboard_merged.key_shift << 4) | (keyboard_merged.key_ctrl << 5) |
|
|
(keyboard_merged.key_q << 6) | (keyboard_merged.key_e << 7));
|
|
kb[9] = (uint8_t)(keyboard_merged.key_alpha1 | (keyboard_merged.key_alpha2 << 1));
|
|
kb[10] = 0;
|
|
kb[11] = 0;
|
|
}
|
|
#endif
|
|
|
|
/*
|
|
*函数简介:板间通讯周期发送任务(2ms)
|
|
*参数说明:FreeRTOS任务参数(未使用)
|
|
*返回类型:无
|
|
*备注:云台板发0x149/0x189/0x1B9/0x1A9,底盘板回传0x019
|
|
*/
|
|
void c_comm_task(void const * argument)
|
|
{
|
|
TickType_t last_wake = xTaskGetTickCount();
|
|
|
|
(void)argument;
|
|
|
|
while (!app_ready)
|
|
osDelay(2);
|
|
|
|
for (;;)
|
|
{
|
|
#if defined(ROBOT_TYPE_GIMBAL)
|
|
uint8_t kb[12];
|
|
const int8_t enc = gimbal_encoder_ccw();
|
|
uint8_t flags = att_ready;
|
|
|
|
c_comm_pack_kb(kb);
|
|
c_comm_master_send(keyboard_merged_online, kb, gimbal_motor_offline(), cmd_robot.spin_flag);
|
|
|
|
c_comm_master_send_ui(-att_deg_roll,
|
|
(float)motor_friction_l.fdb.rotor_speed,
|
|
(float)motor_friction_r.fdb.rotor_speed,
|
|
cmd_robot.spin_flag);//发送0x1B9自定义UI数据
|
|
|
|
if (enc > 0)
|
|
flags |= 0x02U;//bit1=编码器增向CCW
|
|
if (enc != 0)
|
|
flags |= 0x04U;//bit2=编码器方向有效
|
|
c_comm_master_send_attitude(att_deg_yaw, flags);//发送0x1A9姿态帧
|
|
#elif defined(ROBOT_TYPE_CHASSIS)
|
|
c_comm_slave_send(chassis_motor_offline());//回传0x019发射机构状态与故障位
|
|
#endif
|
|
|
|
monitor_heartbeat(HB_CCOMM);
|
|
vTaskDelayUntil(&last_wake, pdMS_TO_TICKS(2));
|
|
}
|
|
}
|