增加了daemon模块

This commit is contained in:
NeoZng 2022-12-08 17:36:12 +08:00
parent f043d5e265
commit c1a22e6f68
12 changed files with 157 additions and 106 deletions

View File

@ -28,7 +28,7 @@
#include "ins_task.h"
#include "motor_task.h"
#include "led_task.h"
#include "monitor.h"
#include "daemon.h"
#include "robot.h"
/* USER CODE END Includes */
@ -60,8 +60,11 @@ void StartINSTASK(void const * argument);
void StartMOTORTASK(void const * argument);
void StartDAEMONTASK(void const* argument);
void StartROBOTTASK(void const* argument);
/* USER CODE END FunctionPrototypes */
void StartDefaultTask(void const * argument);
@ -122,6 +125,9 @@ void MX_FREERTOS_Init(void) {
osThreadDef(motortask, StartMOTORTASK, osPriorityNormal, 0, 256);
defaultTaskHandle = osThreadCreate(osThread(motortask), NULL);
osThreadDef(daemontask, StartDAEMONTASK, osPriorityNormal, 0, 512);
defaultTaskHandle = osThreadCreate(osThread(daemontask), NULL);
osThreadDef(robottask, StartROBOTTASK, osPriorityNormal, 0, 2048);
defaultTaskHandle = osThreadCreate(osThread(robottask), NULL);
@ -176,6 +182,16 @@ void StartMOTORTASK(void const * argument)
}
}
void StartDAEMONTASK(void const * argument)
{
while (1)
{
//500Hz
DaemonTask();
osDelay(10);
}
}
void StartROBOTTASK(void const * argument)
{
while (1)

View File

@ -132,7 +132,7 @@ modules/remote/remote_control.c \
modules/super_cap/super_cap.c \
modules/can_comm/can_comm.c \
modules/message_center/message_center.c \
modules/monitor/monitor.c \
modules/daemon/daemon.c \
modules/vofa/vofa.c \
application/gimbal/gimbal.c \
application/chassis/chassis.c \
@ -230,7 +230,7 @@ C_INCLUDES = \
-Imodules/super_cap \
-Imodules/can_comm \
-Imodules/message_center \
-Imodules/monitor \
-Imodules/daemon \
-Imodules/vofa \
-Imodules/

View File

@ -20,14 +20,14 @@
#### bsp_buzzer
需要和**monitor**模块配合。
需要和**daemon**模块配合。
- [ ] 增加错误或异常提示音
- [ ] 增加功能提示音
#### bsp_led
需要和**monitor**模块配合。这同时会影响到module层的led_task放在这一并解决。
需要和**daemon**模块配合。这同时会影响到module层的led_task放在这一并解决。
- [ ] 增加错误或异常流水灯
- [ ] 增加功能点灯
@ -81,11 +81,11 @@
- [ ] 编写舵机模块
#### ==monitor==
#### ==daemon==
应用和模块监视功能用于提供掉线和异常检测与应对机制和底层的buzzer、led、oled等配合提供快速的问题定位。
- [ ] 编写monitor
- [ ] 编写daemon
#### LKMotor

View File

@ -57,12 +57,9 @@ static float vt_lf, vt_rf, vt_lb, vt_rb; // 底盘速度解算后的临时输出
void ChassisInit()
{
// 左前轮
Motor_Init_Config_s left_foward_config = {
.can_init_config = {
.can_handle = &hcan2,
.tx_id = 1,
},
// 四个轮子的参数一样,改tx_id和反转标志位即可
Motor_Init_Config_s chassis_motor_config = {
.can_init_config.can_handle=&hcan2,
.controller_param_init_config = {
.speed_PID = {
@ -76,80 +73,24 @@ void ChassisInit()
.speed_feedback_source = MOTOR_FEED,
.outer_loop_type = SPEED_LOOP,
.close_loop_type = SPEED_LOOP | CURRENT_LOOP,
.reverse_flag = MOTOR_DIRECTION_REVERSE,
},
.motor_type = M3508};
// 右前轮
Motor_Init_Config_s right_foward_config = {
.can_init_config = {
.can_handle = &hcan2,
.tx_id = 2,
},
.controller_param_init_config = {
.speed_PID = {
},
.current_PID = {
},
},
.controller_setting_init_config = {
.angle_feedback_source = MOTOR_FEED,
.speed_feedback_source = MOTOR_FEED,
.outer_loop_type = SPEED_LOOP,
.close_loop_type = SPEED_LOOP | CURRENT_LOOP,
.reverse_flag = MOTOR_DIRECTION_REVERSE,
},
.motor_type = M3508};
// 左后轮
Motor_Init_Config_s left_back_config = {
.can_init_config = {
.can_handle = &hcan2,
.tx_id = 3,
},
.controller_param_init_config = {
.speed_PID = {
},
.current_PID = {
},
},
.controller_setting_init_config = {
.angle_feedback_source = MOTOR_FEED,
.speed_feedback_source = MOTOR_FEED,
.outer_loop_type = SPEED_LOOP,
.close_loop_type = SPEED_LOOP | CURRENT_LOOP,
.reverse_flag = MOTOR_DIRECTION_REVERSE,
},
.motor_type = M3508};
// 右后轮
Motor_Init_Config_s right_back_config = {
.can_init_config = {
.can_handle = &hcan2,
.tx_id = 4,
},
.controller_param_init_config = {
.speed_PID = {
},
.current_PID = {
},
},
.controller_setting_init_config = {
.angle_feedback_source = MOTOR_FEED,
.speed_feedback_source = MOTOR_FEED,
.outer_loop_type = SPEED_LOOP,
.close_loop_type = SPEED_LOOP | CURRENT_LOOP,
.reverse_flag = MOTOR_DIRECTION_REVERSE,
},
.motor_type = M3508};
motor_lf = DJIMotorInit(&left_foward_config);
motor_rf = DJIMotorInit(&right_foward_config);
motor_lb = DJIMotorInit(&left_back_config);
motor_rb = DJIMotorInit(&right_back_config);
chassis_motor_config.can_init_config.tx_id=1;
chassis_motor_config.controller_setting_init_config.reverse_flag=MOTOR_DIRECTION_REVERSE;
motor_lf = DJIMotorInit(&chassis_motor_config);
chassis_motor_config.can_init_config.tx_id=2,
chassis_motor_config.controller_setting_init_config.reverse_flag=MOTOR_DIRECTION_REVERSE;
motor_rf = DJIMotorInit(&chassis_motor_config);
chassis_motor_config.can_init_config.tx_id=3,
chassis_motor_config.controller_setting_init_config.reverse_flag=MOTOR_DIRECTION_REVERSE;
motor_lb = DJIMotorInit(&chassis_motor_config);
chassis_motor_config.can_init_config.tx_id=4,
chassis_motor_config.controller_setting_init_config.reverse_flag=MOTOR_DIRECTION_REVERSE;
motor_rb = DJIMotorInit(&chassis_motor_config);
referee_data = RefereeInit(&huart6);

43
modules/daemon/daemon.c Normal file
View File

@ -0,0 +1,43 @@
#include "daemon.h"
#include "bsp_dwt.h" // 后续通过定时器来计时?
static DaemonInstance *daemon_instances[DAEMON_MX_CNT] = {NULL};
static uint8_t idx;
DaemonInstance *DaemonRegister(Daemon_Init_Config_s *config)
{
daemon_instances[idx] = (DaemonInstance *)malloc(sizeof(DaemonInstance));
daemon_instances[idx]->reload_count = config->reload_count;
daemon_instances[idx]->callback = config->callback;
daemon_instances[idx]->owner_id = config->id;
daemon_instances[idx]->temp_count = config->reload_count;
return daemon_instances[idx++];
}
void DaemonReload(DaemonInstance *instance)
{
instance->temp_count = instance->reload_count;
}
uint8_t DaemonIsOnline(DaemonInstance *instance)
{
return instance->temp_count>0;
}
void DaemonTask()
{
static DaemonInstance* pins; //提高可读性同时降低访存开销
for (size_t i = 0; i < idx; i++)
{
pins=daemon_instances[i];
if(pins->temp_count>0)
pins->temp_count--;
else if(pins->callback)
{ // 每个module根据自身的offline callback进行调用
pins->callback(pins->owner_id); // module将owner_id强制类型转换成自身类型
}
}
}

60
modules/daemon/daemon.h Normal file
View File

@ -0,0 +1,60 @@
#ifndef MONITOR_H
#define MONITOR_H
#include "stdint-gcc.h"
#define DAEMON_MX_CNT 64
/* 模块离线处理函数指针 */
typedef void (*offline_callback)(void *);
/* daemon结构体定义 */
typedef struct daemon_ins
{
uint16_t reload_count; // 重载值
offline_callback callback; // 异常处理函数,当模块发生异常时会被调用
uint16_t temp_count; //当前值,减为零说明模块离线或异常
void *owner_id; // daemon实例的地址,初始化的时候填入
} DaemonInstance;
/* daemon初始化配置 */
typedef struct
{
uint16_t reload_count; // 实际上这是app唯一需要设置的值?
offline_callback callback;
void *id; // id取拥有daemon的实例的地址,如DJIMotorInstance*,cast成void*类型
} Daemon_Init_Config_s;
/**
* @brief daemon实例
*
* @param config
* @return DaemonInstance*
*/
DaemonInstance *DaemonRegister(Daemon_Init_Config_s *config);
/**
* @brief ,temp_count,"喂狗"
*
* @param instance daemon实例指针
*/
void DaemonReload(DaemonInstance *instance);
/**
* @brief 线
*
* @param instance daemon实例指针
* @return uint8_t 线,1;. 线.
*/
uint8_t DaemonIsOnline(DaemonInstance *instance);
/**
* @brief rtos中,daemon实例的temp_count按频率进行递减操作.
* temp_count的值为reload_count.
*
*/
void DaemonTask();
#endif // !MONITOR_H

5
modules/daemon/daemon.md Normal file
View File

@ -0,0 +1,5 @@
daemon
<p align='right'>neozng1@hnu.edu.cn</p>
用于监测模块和应用运行情况的module(和官方代码中的deteck task作用相同)

View File

@ -1,3 +0,0 @@
#include "monitor.h"
#include "bsp_dwt.h"

View File

@ -1,6 +0,0 @@
#ifndef MONITOR_H
#define MONITOR_H
#endif // !MONITOR_H

View File

@ -10,8 +10,10 @@ static DJIMotorInstance *dji_motor_info[DJI_MOTOR_CNT] = {NULL};
* @brief DJI电机发送以四个一组的形式进行,,6(2can*3group)can_instance专门负责发送
* DJIMotorControl() 使, MotorSenderGrouping()
*
* C610(m2006)/C620(m3508):0x1ff,0x200; GM6020:0x1ff,0x2ff
* : GM6020: 0x204+id ; C610/C620: 0x200+id
* can1: [0]:0x1FF,[1]:0x200,[2]:0x2FF
* can2: [0]:0x1FF,[1]:0x200,[2]:0x2FF
* can2: [3]:0x1FF,[4]:0x200,[5]:0x2FF
*/
static CANInstance sender_assignment[6] =
{

View File

@ -18,12 +18,12 @@ static USARTInstance *rc_usart_instance;
static void sbus_to_rc(volatile const uint8_t *sbus_buf)
{
memcpy(&rc_ctrl[1], &rc_ctrl[TEMP], sizeof(RC_ctrl_t)); // 保存上一次的数据
// 摇杆
rc_ctrl[TEMP].rc.joystick[0] = (sbus_buf[0] | (sbus_buf[1] << 8)) & 0x07ff; //!< Channel 0
rc_ctrl[TEMP].rc.joystick[1] = ((sbus_buf[1] >> 3) | (sbus_buf[2] << 5)) & 0x07ff; //!< Channel 1
rc_ctrl[TEMP].rc.joystick[2] = ((sbus_buf[2] >> 6) | (sbus_buf[3] << 2) | (sbus_buf[4] << 10)) & 0x07ff; //!< Channel 2
rc_ctrl[TEMP].rc.joystick[3] = ((sbus_buf[4] >> 1) | (sbus_buf[5] << 7)) & 0x07ff; //!< Channel 3
rc_ctrl[TEMP].rc.joystick[4] = sbus_buf[16] | (sbus_buf[17] << 8); // 拨轮
// 摇杆,直接解算时减去偏置
rc_ctrl[TEMP].rc.joystick[0] = (sbus_buf[0] | (sbus_buf[1] << 8)) & 0x07ff - RC_CH_VALUE_OFFSET; //!< Channel 0
rc_ctrl[TEMP].rc.joystick[1] = ((sbus_buf[1] >> 3) | (sbus_buf[2] << 5)) & 0x07ff - RC_CH_VALUE_OFFSET; //!< Channel 1
rc_ctrl[TEMP].rc.joystick[2] = ((sbus_buf[2] >> 6) | (sbus_buf[3] << 2) | (sbus_buf[4] << 10)) & 0x07ff - RC_CH_VALUE_OFFSET; //!< Channel 2
rc_ctrl[TEMP].rc.joystick[3] = ((sbus_buf[4] >> 1) | (sbus_buf[5] << 7)) & 0x07ff - RC_CH_VALUE_OFFSET; //!< Channel 3
rc_ctrl[TEMP].rc.joystick[4] = sbus_buf[16] | (sbus_buf[17] << 8) - RC_CH_VALUE_OFFSET; // 左侧拨轮
// 开关,0左1右
rc_ctrl[TEMP].rc.s[0] = ((sbus_buf[5] >> 4) & 0x0003); //!< Switch left
rc_ctrl[TEMP].rc.s[1] = ((sbus_buf[5] >> 4) & 0x000C) >> 2; //!< Switch right
@ -61,13 +61,6 @@ static void sbus_to_rc(volatile const uint8_t *sbus_buf)
// rc_ctrl[TEMP].key_test[KEY_PRESS_WITH_CTRL] = rc_ctrl[TEMP].key_test[KEY_PRESS];
// if (rc_ctrl[TEMP].key_test[KEY_PRESS].shift)
// rc_ctrl[TEMP].key_test[Key_Shift] = rc_ctrl[TEMP].key_test[KEY_PRESS];
// 减去偏置值
rc_ctrl[TEMP].rc.joystick[0] -= RC_CH_VALUE_OFFSET;
rc_ctrl[TEMP].rc.joystick[1] -= RC_CH_VALUE_OFFSET;
rc_ctrl[TEMP].rc.joystick[2] -= RC_CH_VALUE_OFFSET;
rc_ctrl[TEMP].rc.joystick[3] -= RC_CH_VALUE_OFFSET;
rc_ctrl[TEMP].rc.joystick[4] -= RC_CH_VALUE_OFFSET;
}
/**