第一次提交
This commit is contained in:
@@ -47,25 +47,36 @@ static void brakeOutput(void *signal_id)
|
||||
{
|
||||
case 1: // 电机前进状态
|
||||
un_h_bridge_output.bit_data.channel_01 = setBrakeOn();
|
||||
un_h_bridge_output.bit_data.channel_04 = setBrakeOn();
|
||||
un_h_bridge_output.bit_data.channel_02 = setBrakeOff();
|
||||
un_h_bridge_output1.bit_data.channel_01 = setBrakeOn();
|
||||
un_h_bridge_output1.bit_data.channel_02 = setBrakeOff();
|
||||
un_h_bridge_output.bit_data.channel_03 = setBrakeOff();
|
||||
un_h_bridge_output.bit_data.sleep_01 = setBrakeOn();
|
||||
un_h_bridge_output.bit_data.sleep_02 = setBrakeOn(); // 正转
|
||||
un_inf_can_kgf_output1.bit_data.KGF13 = setBrakeOff(); // 抱闸继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF14 = setBrakeOff(); // 抱闸继电器
|
||||
printf("Brake: Motor forward\n");
|
||||
break;
|
||||
|
||||
case 2: // 电机后退状态
|
||||
un_h_bridge_output.bit_data.channel_01 = setBrakeOff();
|
||||
un_h_bridge_output.bit_data.channel_02 = setBrakeOn();
|
||||
un_h_bridge_output1.bit_data.channel_01 = setBrakeOff();
|
||||
un_h_bridge_output1.bit_data.channel_02 = setBrakeOn();
|
||||
un_h_bridge_output.bit_data.channel_04 = setBrakeOff();
|
||||
un_h_bridge_output.bit_data.channel_02 = setBrakeOn();
|
||||
un_h_bridge_output.bit_data.channel_03 = setBrakeOn();
|
||||
un_h_bridge_output.bit_data.sleep_01 = setBrakeOn();
|
||||
un_h_bridge_output.bit_data.sleep_02 = setBrakeOn(); // 反转
|
||||
un_inf_can_kgf_output1.bit_data.KGF13 = setBrakeOn(); // 抱闸继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF14 = setBrakeOn(); // 抱闸继电器
|
||||
|
||||
printf("Brake: Motor reverse\n");
|
||||
break;
|
||||
|
||||
default:
|
||||
un_h_bridge_output.bit_data.channel_01 = setBrakeOff();
|
||||
un_h_bridge_output.bit_data.channel_04 = setBrakeOff();
|
||||
un_h_bridge_output.bit_data.channel_02 = setBrakeOff();
|
||||
un_h_bridge_output1.bit_data.channel_01 = setBrakeOff();
|
||||
un_h_bridge_output1.bit_data.channel_02 = setBrakeOff();
|
||||
un_h_bridge_output.bit_data.channel_03 = setBrakeOff();
|
||||
un_h_bridge_output.bit_data.sleep_01 = setBrakeOff();
|
||||
un_h_bridge_output.bit_data.sleep_02 = setBrakeOff(); // 关闭
|
||||
printf("Brake: Motor off\n");
|
||||
break;
|
||||
}
|
||||
@@ -88,16 +99,9 @@ static void brakeTimerProcess(void *signal_id)
|
||||
if (shouldApplyBrake())
|
||||
{
|
||||
brake_data.state = BRAKE_STATE_APPLYING_BRAKE;
|
||||
if( 0 == brake_data.brake_direction)
|
||||
{
|
||||
brake_data.brake_motor_state = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
brake_data.brake_motor_state = 2;
|
||||
}
|
||||
brake_data.brake_motor_state = 1;
|
||||
brakeOutput(NULL);
|
||||
timerStart(&brake_data.brake_apply_timer, (uint32_t)(getParam("brk_on")), 1);
|
||||
timerStart(&brake_data.brake_apply_timer, (uint32_t)(getParam("brk_on")), 0);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -105,17 +109,9 @@ static void brakeTimerProcess(void *signal_id)
|
||||
if (shouldReleaseBrake() && power_data.current_state == POWER_WORKING)
|
||||
{
|
||||
brake_data.state = BRAKE_STATE_RELEASING_BRAKE;
|
||||
|
||||
if( 0 == brake_data.brake_direction)
|
||||
{
|
||||
brake_data.brake_motor_state = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
brake_data.brake_motor_state = 1;
|
||||
}
|
||||
brake_data.brake_motor_state = 2;
|
||||
brakeOutput(NULL);
|
||||
timerStart(&brake_data.brake_release_timer, (uint32_t)(getParam("brk_off")), 1);
|
||||
timerStart(&brake_data.brake_release_timer, (uint32_t)(getParam("brk_off")), 0);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -144,15 +140,16 @@ static void brakeTimerProcess(void *signal_id)
|
||||
brake_data.state = BRAKE_STATE_IDLE;
|
||||
break;
|
||||
}
|
||||
// // 如果刹车位置有变化,存入EEPROM
|
||||
// if (brake_data.brake_position != brake_data.old_brake_position)
|
||||
// {
|
||||
// setParam("brk_pos", (float)brake_data.brake_position);
|
||||
// brake_data.old_brake_position = brake_data.brake_position;
|
||||
//
|
||||
// printf("writeE2 brake_position = %d\n",brake_data.brake_position);
|
||||
//
|
||||
// }
|
||||
// 如果刹车位置有变化,存入EEPROM
|
||||
if (brake_data.brake_position != brake_data.old_brake_position)
|
||||
{
|
||||
setParam("brk_pos", (float)brake_data.brake_position);
|
||||
brake_data.old_brake_position = brake_data.brake_position;
|
||||
|
||||
|
||||
printf("writeE2 brake_position = %d\n",brake_data.brake_position);
|
||||
|
||||
}
|
||||
timerStart(&brake_data.brake_timer, 100, 1); // 周期调用
|
||||
}
|
||||
|
||||
@@ -184,14 +181,6 @@ static void brakeInput(void *signal_id)
|
||||
|
||||
}
|
||||
|
||||
void paramUpdate(void *signal_id)
|
||||
{
|
||||
brake_data.brake_direction = (uint8_t)getParam("brk_rev");
|
||||
timerStart(&brake_data.brake_param_timer, 1000, 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 修改APP模块的初始化函数
|
||||
void brakeAppInit(void)
|
||||
{
|
||||
@@ -215,7 +204,6 @@ void brakeAppInit(void)
|
||||
timerInit(&brake_data.brake_timer);
|
||||
timerInit(&brake_data.brake_apply_timer);
|
||||
timerInit(&brake_data.brake_release_timer);
|
||||
timerInit(&brake_data.brake_param_timer);
|
||||
|
||||
// 订阅输入信号,处理刹车逻辑
|
||||
subscribe(&un_sw_sample, brakeInput);
|
||||
@@ -223,16 +211,13 @@ void brakeAppInit(void)
|
||||
subscribe(&can_fault_info, brakeInput);
|
||||
subscribe(ðernet_fault_Info, brakeInput);
|
||||
|
||||
|
||||
// 订阅定时器信号,用于状态机的定时处理
|
||||
subscribe(&brake_data.brake_timer, brakeTimerProcess);
|
||||
subscribe(&brake_data.brake_apply_timer, brakeTimerProcess);
|
||||
subscribe(&brake_data.brake_release_timer, brakeTimerProcess);
|
||||
subscribe(&brake_data.brake_param_timer, paramUpdate);
|
||||
|
||||
// 启动定时器,定期调用 brakeTimerProcess
|
||||
timerStart(&brake_data.brake_timer, 500, 1);
|
||||
timerStart(&brake_data.brake_param_timer, 1000, 1);
|
||||
|
||||
|
||||
printf("app_brake: initial OK \n");
|
||||
}
|
||||
|
||||
@@ -29,8 +29,7 @@ typedef struct BrakeSystem
|
||||
uint8_t brake_command; // 刹车命令变量:1表示刹车,2表示释放
|
||||
uint8_t brake_motor_state; // 刹车电机状态变量:0停止,1前进,2后退
|
||||
uint8_t brake_command_in_progress; // 刹车命令执行状态:0表示空闲,1表示正在执行
|
||||
uint8_t brake_direction;
|
||||
|
||||
|
||||
uint8_t emergency_stop_switch; // 急停开关
|
||||
uint8_t remote_emergency_stop; // 遥控器急停开关
|
||||
uint8_t remote_fault; // 遥控器故障
|
||||
@@ -42,7 +41,6 @@ typedef struct BrakeSystem
|
||||
uint8_t old_brake_position; // 旧的刹车位置
|
||||
Timer brake_apply_timer; // 刹车定时器
|
||||
Timer brake_release_timer; // 释放刹车定时器
|
||||
Timer brake_param_timer; //参数更新时间
|
||||
|
||||
} BrakeSystem;
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -13,52 +13,14 @@ extern "C"
|
||||
|
||||
#define SPEED_PID_MODE 0
|
||||
#define THROTTLE_PID_MODE 1
|
||||
|
||||
#define TURN_MIN_TOUQUE 1 //n*m
|
||||
|
||||
#define SPEED_MODE 0x01
|
||||
#define TORQUE_MODE 0x02
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#define ANGULAR_VELOCITY_TO_RPM 30.0 / PI
|
||||
|
||||
|
||||
#define TORQUE_HYSTERESIS_THRESHOLD 0.3f
|
||||
|
||||
#define MOTOR_MODE TORQUE_MODE
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//轮毂电机
|
||||
#define FRONT_LEFT_MOTOR_CANID 0x7F
|
||||
#define FRONT_RIGHT_MOTOR_CANID 0x7F
|
||||
#define REAR_LEFT_MOTOR_CANID 0x7F
|
||||
#define REAR_RIGHT_MOTOR_CANID 0x7F
|
||||
|
||||
|
||||
#define FRONT_LEFT_MOTOR_RxCANID (0x20000FD + (FRONT_LEFT_MOTOR_CANID << 8)) // 0x2007CFD
|
||||
#define FRONT_RIGHT_MOTOR_RxCANID (0x20000FD + (FRONT_RIGHT_MOTOR_CANID << 8)) // 0x2007DFD
|
||||
#define REAR_LEFT_MOTOR_RxCANID (0x20000FD + (REAR_LEFT_MOTOR_CANID << 8)) // 0x2007EFD
|
||||
#define REAR_RIGHT_MOTOR_RxCANID (0x20000FD + (REAR_RIGHT_MOTOR_CANID << 8)) // 0x2007FFD
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define ALPHA 0.1f // 滤波系数α∈[0.01,0.3],0.2对应截止频率约10Hz(假设采样周期10ms)
|
||||
#define LOWPASS_FILTER(speed, prev) (ALPHA * (speed) + (1 - ALPHA) * (prev))
|
||||
|
||||
// 状态机内部状态
|
||||
typedef enum
|
||||
{
|
||||
STATE_INIT, ///< 初始状态(转速为0且等待扭矩方向判定)
|
||||
STATE_FORWARD, ///< 前进
|
||||
STATE_BACKWARD, ///< 后退
|
||||
} MotorState;
|
||||
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
@@ -68,11 +30,8 @@ typedef enum
|
||||
|
||||
typedef struct DiffData
|
||||
{
|
||||
uint16_t diff_cnt;
|
||||
uint8_t motor_init_state; // 电机状态
|
||||
ControlMode mode ; // 控制模式
|
||||
MotorState motor_state[4]; //当前车辆状态
|
||||
float desired_speed; // 期望速度
|
||||
float desired_speed; // 期望速度
|
||||
float desired_curvature; // 期望曲率
|
||||
float left_motor_speed; // 当前左电机速度
|
||||
float right_motor_speed; // 当前右电机速度
|
||||
@@ -95,28 +54,16 @@ typedef struct DiffData
|
||||
float out_left_motor_speed; // 输出左电机速度
|
||||
float out_right_motor_speed; // 输出右电机速度
|
||||
float out_torq[4]; //4个电机扭矩
|
||||
float out_torq_last[4]; //4个电机扭矩
|
||||
|
||||
uint16_t feedPower; //馈电功率
|
||||
uint16_t dispPower; //放电功率
|
||||
|
||||
float max_Torq; // 最大扭矩限制
|
||||
float min_Torq; // 最小扭矩限制
|
||||
float min_Torq; // 最小扭矩限制
|
||||
|
||||
float left_speed_diff; // 左侧转速差
|
||||
float right_speed_diff; // 右侧转速差
|
||||
|
||||
float left_diff_touue; // 左侧扭矩差
|
||||
float right_diff_touue; // 右侧扭矩差
|
||||
float diff_dead_zone; // 差速速度死区
|
||||
|
||||
float vehicle_mass; // 车重
|
||||
float wheel_radius; // 轮胎直径
|
||||
float gear_ratio; // 减速比
|
||||
float wheel_base; // 轴距
|
||||
float max_motor_rpm; // 电机最大速度
|
||||
float diff_dead_zone; // 差速速度死区
|
||||
|
||||
|
||||
} DiffData;
|
||||
|
||||
|
||||
|
||||
@@ -110,22 +110,28 @@ static void lightOutput(void *signal_id)
|
||||
switch (i)
|
||||
{//正常所有灯光熄灭
|
||||
case LIGHT_HEAD://头灯,前面4个灯
|
||||
un_inf_can_kgf_output1.bit_data.KGF13 = state_value;
|
||||
un_inf_can_kgf_output2.bit_data.KGF07 = state_value;
|
||||
un_inf_can_kgf_output2.bit_data.KGF09 = state_value;
|
||||
break;
|
||||
case LIGHT_TAIL://尾灯,后面4个灯
|
||||
un_inf_can_kgf_output1.bit_data.KGF14 = state_value;
|
||||
un_inf_can_kgf_output2.bit_data.KGF11 = state_value;
|
||||
un_inf_can_kgf_output2.bit_data.KGF13 = state_value;
|
||||
break;
|
||||
case LIGHT_LEFT_TURN://左转向,左边4个灯
|
||||
un_inf_can_kgf_output1.bit_data.KGF13 = state_value;
|
||||
un_inf_can_kgf_output2.bit_data.KGF08 = state_value;
|
||||
un_inf_can_kgf_output2.bit_data.KGF12 = state_value;
|
||||
break;
|
||||
case LIGHT_RIGHT_TURN://右转向灯,右边4个灯
|
||||
un_inf_can_kgf_output1.bit_data.KGF14 = state_value;
|
||||
un_inf_can_kgf_output2.bit_data.KGF10 = state_value;
|
||||
un_inf_can_kgf_output2.bit_data.KGF14 = state_value;
|
||||
break;
|
||||
case LIGHT_BRAKE://刹车灯,四个黄灯
|
||||
un_inf_can_kgf_output1.bit_data.KGF13 = state_value;
|
||||
un_inf_can_kgf_output2.bit_data.KGF11 = state_value;
|
||||
un_inf_can_kgf_output2.bit_data.KGF13 = state_value;
|
||||
break;
|
||||
case LIGHT_ALARM://报警灯,四个红灯
|
||||
un_inf_can_kgf_output1.bit_data.KGF14 = state_value;
|
||||
un_inf_can_kgf_output2.bit_data.KGF11 = state_value;
|
||||
un_inf_can_kgf_output2.bit_data.KGF13 = state_value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,31 +278,21 @@ void processWriteRequestFrame(UnParamRequest *paramRequest, uint32_t sender_ip,
|
||||
|
||||
|
||||
void processReadRequestFrame(UnParamRequest *paramRequest, uint32_t sender_ip, uint16_t sender_port) {
|
||||
// 处理读请求的逻辑
|
||||
printf("Processing read request.\n");
|
||||
|
||||
// 先备份原始请求数据
|
||||
UnParamRequest originalRequest;
|
||||
memcpy(&originalRequest, paramRequest, sizeof(UnParamRequest));
|
||||
|
||||
// 清零响应数据
|
||||
// 清零 paramRequest
|
||||
memset(paramRequest, 0, sizeof(UnParamRequest));
|
||||
|
||||
// 处理客户端请求的参数
|
||||
// 先发送信号,然后从结构体读数
|
||||
for (int i = 0; i < 256; ++i) {
|
||||
if (strlen((char *)originalRequest.bit_data.param_name[i]) > 0) {
|
||||
// 复制参数名到响应
|
||||
strcpy((char *)paramRequest->bit_data.param_name[i],
|
||||
(char *)originalRequest.bit_data.param_name[i]);
|
||||
// 读取参数值
|
||||
float readData = readParameter(originalRequest.bit_data.param_name[i]);
|
||||
memcpy(paramRequest->bit_data.data[i], &readData, sizeof(float));
|
||||
|
||||
printf("Read parameter: %s = %f\n",
|
||||
originalRequest.bit_data.param_name[i], readData);
|
||||
if (strlen((char *)paramRequest->bit_data.param_name[i]) > 0) {
|
||||
float readData = readParameter(paramRequest->bit_data.param_name[i]);
|
||||
memcpy(paramRequest->bit_data.data[i], &readData, sizeof(paramRequest->bit_data.data[i]));
|
||||
}
|
||||
}
|
||||
|
||||
// 发送响应 - 直接传递 paramRequest
|
||||
// 发送响应
|
||||
sendParamRequestResponse(paramRequest, sender_ip, sender_port, 0);
|
||||
}
|
||||
|
||||
@@ -310,7 +300,6 @@ void processReadRequestFrame(UnParamRequest *paramRequest, uint32_t sender_ip, u
|
||||
|
||||
|
||||
|
||||
|
||||
void OnParamSignal(void *data)
|
||||
{
|
||||
RequestContext *signal = (RequestContext *)data;
|
||||
@@ -432,55 +421,37 @@ void paramAppInit(void)
|
||||
// 上电读取所有参数
|
||||
memset(param_manager.arr, 0, sizeof(param_manager.arr));
|
||||
accessEeprom(0, param_manager.arr, sizeof(param_manager.arr), READ_OPERATION);
|
||||
// whl_bas 轮胎直径<单位:m>
|
||||
// max_rpm 最大转速<单位:rpm/min>
|
||||
// whl_dia 轴距<单位:m>
|
||||
// max_acc 最大加速度
|
||||
// spd_kp 遥控速度P
|
||||
// spd_ki 遥控速度I
|
||||
// spd_kd 遥控速度D
|
||||
// spd_il 遥控速度积分限制
|
||||
// spd_ol 遥控速度PID输出限制
|
||||
// crv_kp 遥控转弯P
|
||||
// crv_ki 遥控转弯I
|
||||
// crv_kd 遥控转弯D
|
||||
// crv_il 遥控转弯积分限制
|
||||
// crv_ol 遥控转弯PID输出限制
|
||||
// brk_on 刹车刹紧时间 单位:ms
|
||||
// brk_off 刹车释放时间 单位:ms
|
||||
// maxTorq 最大扭矩 单位:n*m
|
||||
// feedPwr 最大馈电功率 单位:w
|
||||
// dispPwr 最大放电功率 单位:w
|
||||
// VehMass 车重 单位:kg
|
||||
// gRatio 减速比
|
||||
// prCTime 预充电时间 单位:s
|
||||
// brk_pos 刹车位置
|
||||
// pwr_sta 电源状态
|
||||
// high_sw 高压开关状态
|
||||
// stop_sw 急停开关状态
|
||||
// lightSt 灯光状态
|
||||
// pwr_btn 电源开关状态
|
||||
// sleepTm 休眠时间 单位:min
|
||||
// wakeTm 唤醒时间 单位:min
|
||||
// Ospd_kp 自主速度P
|
||||
// Ospd_ki 自主速度I
|
||||
// Ospd_kd 自主速度D
|
||||
// Ospd_il 自主速度积分限制
|
||||
// Ospd_ol 自主速度PID输出限制
|
||||
// Ocrv_kp 自主转弯P
|
||||
// Ocrv_ki 自主转弯I
|
||||
// Ocrv_kd 自主转弯D
|
||||
// Ocrv_il 自主转弯积分限制
|
||||
// Ocrv_ol 自主转弯PID输出限制
|
||||
// minTorq 输出扭矩死区 单位:n*m
|
||||
// brk_rev 刹车方向
|
||||
// mot_kp 同侧扭矩P参数
|
||||
// mot_ki 同侧扭矩I参数
|
||||
// mot_kd 同侧扭矩d参数
|
||||
// mot_il 同侧扭矩积分限制
|
||||
// mot_ol 同侧扭矩输出限制
|
||||
// diff_sp 同侧扭矩速度差阈值
|
||||
// test 初始化测试参数
|
||||
|
||||
// 初始化每个参数
|
||||
// param_manager.bit_data.whl_bas = 1.5f; // 初始化轮距
|
||||
// param_manager.bit_data.max_rpm = 5500.0f; // 初始化最大转速
|
||||
// param_manager.bit_data.whl_dia = 0.6f; // 初始化轮直径
|
||||
// param_manager.bit_data.max_acc = 1.0f; // 初始化最大加速度
|
||||
// param_manager.bit_data.spd_kp = 5.0f; // 初始化速度控制 KP
|
||||
// param_manager.bit_data.spd_ki = 1.0f; // 初始化速度控制 KI
|
||||
// param_manager.bit_data.spd_kd = 0.0f; // 初始化速度控制 KD
|
||||
// param_manager.bit_data.spd_il = 5.0f; // 初始化速度控制 IL
|
||||
// param_manager.bit_data.spd_ol = 5.0f; // 初始化速度控制 OL
|
||||
// param_manager.bit_data.crv_kp = 1.0f; // 初始化曲线控制 KP
|
||||
// param_manager.bit_data.crv_ki = 0.0f; // 初始化曲线控制 KI
|
||||
// param_manager.bit_data.crv_kd = 0.0f; // 初始化曲线控制 KD
|
||||
// param_manager.bit_data.crv_il = 2.0f; // 初始化曲线控制 IL
|
||||
// param_manager.bit_data.crv_ol = 2.0f; // 初始化曲线控制 OL
|
||||
// param_manager.bit_data.brk_on = 1500.0f; // 初始化制动开启参数
|
||||
// param_manager.bit_data.brk_off = 800.0f; // 初始化制动关闭参数
|
||||
// param_manager.bit_data.maxTorq = 60.0f; // 初始化最大扭矩
|
||||
// param_manager.bit_data.feedPwr = 10000.0f; // 初始化馈电功率
|
||||
// param_manager.bit_data.dispPwr = 10000.0f; // 初始化显示功率
|
||||
// param_manager.bit_data.VehMass = 700.0f; // 初始化车辆质量
|
||||
// param_manager.bit_data.gRatio = 28.0f; // 初始化减速比
|
||||
// param_manager.bit_data.prCTime = 5.0f; // 初始化预充时间
|
||||
// param_manager.bit_data.brk_pos = 0.0f; // 初始化刹车位置, 0表示未刹车
|
||||
// param_manager.bit_data.pwr_sta = 0.0f; // 初始化电源状态
|
||||
// param_manager.bit_data.lightSt = 0.0f; // 初始化灯光状态
|
||||
// param_manager.bit_data.pwr_btn = 0.0f; // 初始化电源按钮状态
|
||||
// param_manager.bit_data.test = 0.0f; // 初始化测试参数
|
||||
|
||||
|
||||
// 订阅信号
|
||||
subscribe(¶m_signal, handleParamOp);
|
||||
subscribe(&request_context, OnParamSignal);// 接收到上位机读写参数信号
|
||||
|
||||
@@ -41,8 +41,8 @@ extern "C"
|
||||
X(pwr_btn) \
|
||||
X(sleepTm) \
|
||||
X(wakeTm) \
|
||||
X(minYpos) \
|
||||
X(maxYpos) \
|
||||
X(Ospd_kp) \
|
||||
X(Ospd_ki) \
|
||||
X(Ospd_kd) \
|
||||
X(Ospd_il) \
|
||||
X(Ospd_ol) \
|
||||
@@ -52,7 +52,8 @@ extern "C"
|
||||
X(Ocrv_il) \
|
||||
X(Ocrv_ol) \
|
||||
X(minTorq) \
|
||||
X(brk_rev) \
|
||||
X(minYpos) \
|
||||
X(maxYpos) \
|
||||
X(mot_kp) \
|
||||
X(mot_ki) \
|
||||
X(mot_kd) \
|
||||
@@ -60,9 +61,6 @@ extern "C"
|
||||
X(mot_ol) \
|
||||
X(diff_sp) \
|
||||
X(turn_sp) \
|
||||
X(pit_sp) \
|
||||
X(xy_pos) \
|
||||
X(z_pos) \
|
||||
X(test)
|
||||
|
||||
// 定义一个包含所有参数名称的结构体
|
||||
|
||||
@@ -34,73 +34,73 @@ typedef struct {
|
||||
PowerSystem power_data;
|
||||
static PowerButton power_button = {BUTTON_STATE_INITIAL, 0, 0, 0, {0},0};
|
||||
|
||||
//// 电源按钮处理函数
|
||||
//static void handlePowerButton(void)
|
||||
//{
|
||||
// switch (power_button.state)
|
||||
// {
|
||||
// case BUTTON_STATE_INITIAL:
|
||||
// if (power_data.remote_power_switch == app_close())
|
||||
// {
|
||||
// power_button.state = BUTTON_STATE_SHORT_PRESS_DETECTED;
|
||||
// timerStart(&power_button.timer, 500, 0); // 启动短按定时器,500ms
|
||||
// }
|
||||
// break;
|
||||
//
|
||||
// case BUTTON_STATE_SHORT_PRESS_DETECTED:
|
||||
// if (power_data.remote_power_switch == app_open())
|
||||
// {
|
||||
// if (power_button.timer.active) // 定时器未到期,短按完成,启动等待长按定时器
|
||||
// {
|
||||
// power_button.state = BUTTON_STATE_WAIT_FOR_LONG_PRESS;
|
||||
// timerStart(&power_button.timer, 500, 0); // 启动等待长按定时器,500ms
|
||||
// }
|
||||
// }
|
||||
// else if (!power_button.timer.active)// 短按定时器到期,按键仍被按下,视为无效,重置为初始状态
|
||||
// {
|
||||
// power_button.state = BUTTON_STATE_INITIAL;
|
||||
// }
|
||||
// break;
|
||||
//
|
||||
// case BUTTON_STATE_WAIT_FOR_LONG_PRESS:
|
||||
// if (power_data.remote_power_switch == app_close())// 检测是否在等待时间内进行长按
|
||||
// {
|
||||
// power_button.state = BUTTON_STATE_LONG_PRESS;
|
||||
// timerStart(&power_button.timer, 1000, 0); // 启动长按定时器,1000ms
|
||||
// }
|
||||
// else if (!power_button.timer.active) // 等待长按超时,重置为初始状态
|
||||
// {
|
||||
// power_button.state = BUTTON_STATE_INITIAL;
|
||||
// }
|
||||
// break;
|
||||
//
|
||||
// case BUTTON_STATE_LONG_PRESS:
|
||||
//
|
||||
// if (!power_button.timer.active)// 长按完成,切换电源状态 20250423 修改不需要判断松开按键就打开控制器
|
||||
// {
|
||||
// power_button.is_power_on = !power_button.is_power_on;
|
||||
// printf("PowerButton: is_power_on = %d\n", power_button.is_power_on);
|
||||
// power_button.state = BUTTON_STATE_LONG_PRESS_WAIT;
|
||||
// }
|
||||
// else if(power_data.remote_power_switch == app_open())
|
||||
// {
|
||||
// power_button.state = BUTTON_STATE_INITIAL;
|
||||
// printf("Long press for short duration");
|
||||
// }
|
||||
// else
|
||||
// break;
|
||||
//
|
||||
// case BUTTON_STATE_LONG_PRESS_WAIT:
|
||||
// if (power_data.remote_power_switch == app_open())// 检测按键释放
|
||||
// {
|
||||
// power_button.state = BUTTON_STATE_INITIAL;
|
||||
// printf("Release the button");
|
||||
// }
|
||||
// default:
|
||||
// power_button.state = BUTTON_STATE_INITIAL;
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
// 电源按钮处理函数
|
||||
static void handlePowerButton(void)
|
||||
{
|
||||
switch (power_button.state)
|
||||
{
|
||||
case BUTTON_STATE_INITIAL:
|
||||
if (power_data.remote_power_switch == app_close())
|
||||
{
|
||||
power_button.state = BUTTON_STATE_SHORT_PRESS_DETECTED;
|
||||
timerStart(&power_button.timer, 500, 1); // 启动短按定时器,500ms
|
||||
}
|
||||
break;
|
||||
|
||||
case BUTTON_STATE_SHORT_PRESS_DETECTED:
|
||||
if (power_data.remote_power_switch == app_open())
|
||||
{
|
||||
if (power_button.timer.active) // 定时器未到期,短按完成,启动等待长按定时器
|
||||
{
|
||||
power_button.state = BUTTON_STATE_WAIT_FOR_LONG_PRESS;
|
||||
timerStart(&power_button.timer, 500, 1); // 启动等待长按定时器,500ms
|
||||
}
|
||||
}
|
||||
else if (!power_button.timer.active)// 短按定时器到期,按键仍被按下,视为无效,重置为初始状态
|
||||
{
|
||||
power_button.state = BUTTON_STATE_INITIAL;
|
||||
}
|
||||
break;
|
||||
|
||||
case BUTTON_STATE_WAIT_FOR_LONG_PRESS:
|
||||
if (power_data.remote_power_switch == app_close())// 检测是否在等待时间内进行长按
|
||||
{
|
||||
power_button.state = BUTTON_STATE_LONG_PRESS;
|
||||
timerStart(&power_button.timer, 1000, 1); // 启动长按定时器,1000ms
|
||||
}
|
||||
else if (!power_button.timer.active) // 等待长按超时,重置为初始状态
|
||||
{
|
||||
power_button.state = BUTTON_STATE_INITIAL;
|
||||
}
|
||||
break;
|
||||
|
||||
case BUTTON_STATE_LONG_PRESS:
|
||||
|
||||
if (!power_button.timer.active)// 长按完成,切换电源状态 20250423 修改不需要判断松开按键就打开控制器
|
||||
{
|
||||
power_button.is_power_on = !power_button.is_power_on;
|
||||
printf("PowerButton: is_power_on = %d\n", power_button.is_power_on);
|
||||
power_button.state = BUTTON_STATE_LONG_PRESS_WAIT;
|
||||
}
|
||||
else if(power_data.remote_power_switch == app_open())
|
||||
{
|
||||
power_button.state = BUTTON_STATE_INITIAL;
|
||||
printf("Long press for short duration");
|
||||
}
|
||||
else
|
||||
break;
|
||||
|
||||
case BUTTON_STATE_LONG_PRESS_WAIT:
|
||||
if (power_data.remote_power_switch == app_open())// 检测按键释放
|
||||
{
|
||||
power_button.state = BUTTON_STATE_INITIAL;
|
||||
printf("Release the button");
|
||||
}
|
||||
default:
|
||||
power_button.state = BUTTON_STATE_INITIAL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 输出处理函数
|
||||
@@ -113,111 +113,124 @@ static void powerOutput(void *signal_id)
|
||||
{
|
||||
case POWER_PRE_CHARGE:
|
||||
publishMessage(&power_data.pre_charge_finish, 1);//发布预充完成信号,100ms发送一次,直到预充完成
|
||||
un_inf_can_kgf_output1.bit_data.KGF01 = setPowerOn(); // E3
|
||||
un_inf_can_kgf_output1.bit_data.KGF02 = setPowerOn(); // 导航仪
|
||||
un_inf_can_kgf_output1.bit_data.KGF03 = setPowerOff(); // 导航仪
|
||||
un_inf_can_kgf_output1.bit_data.KGF05 = setPowerOn(); // 交换机、路由器
|
||||
un_inf_can_kgf_output1.bit_data.KGF06 = setPowerOn(); // 交换机、路由器
|
||||
un_inf_can_kgf_output1.bit_data.KGF07 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output1.bit_data.KGF08 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output1.bit_data.KGF09 = setPowerOn(); // 上装
|
||||
un_inf_can_kgf_output1.bit_data.KGF11 = setPowerOn(); // 上装
|
||||
un_inf_can_kgf_output1.bit_data.KGF12 = setPowerOn(); // 待定
|
||||
// un_inf_can_kgf_output1.bit_data.KGF13 = setPowerOn(); // 前左右红灯
|
||||
// un_inf_can_kgf_output1.bit_data.KGF14 = setPowerOn(); // 后左右红灯
|
||||
un_inf_can_kgf_output1.bit_data.KGF15 = setPowerOn(); // 网络摄像头
|
||||
un_inf_can_kgf_output1.bit_data.KGF16 = setPowerOn(); // 遥控器
|
||||
un_inf_can_kgf_output1.bit_data.KGF04 = setPowerOn(); // 预充继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF05 = setPowerOn(); // 上装转台继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF06 = setPowerOn(); // 上装转台继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF07 = setPowerOff(); // 高压继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF08 = setPowerOff(); // 高压继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF11 = setPowerOn(); // 低压继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF12 = setPowerOn(); // 低压继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF15 = setPowerOn(); // 导航计算机
|
||||
un_inf_can_kgf_output1.bit_data.KGF16 = setPowerOn(); // 导航计算机
|
||||
un_inf_can_kgf_output2.bit_data.KGF01 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output2.bit_data.KGF02 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output2.bit_data.KGF15 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output2.bit_data.KGF16 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output2.bit_data.KGF03 = setPowerOn(); // 遥控器
|
||||
un_inf_can_kgf_output2.bit_data.KGF05 = setPowerOn(); // 网络交换机
|
||||
un_inf_can_kgf_output2.bit_data.KGF06 = setPowerOn(); // 网络交换机
|
||||
|
||||
break;
|
||||
|
||||
case POWER_NEUTRAL:
|
||||
publishMessage(&power_data.pre_charge_finish, 1);//20250316增加,发送空挡信号,保证电机控制器高压上电后,发送空挡信号
|
||||
un_inf_can_kgf_output1.bit_data.KGF01 = setPowerOn(); // E3
|
||||
un_inf_can_kgf_output1.bit_data.KGF02 = setPowerOn(); // 导航仪
|
||||
un_inf_can_kgf_output1.bit_data.KGF03 = setPowerOff(); // 导航仪
|
||||
un_inf_can_kgf_output1.bit_data.KGF05 = setPowerOn(); // 交换机、路由器
|
||||
un_inf_can_kgf_output1.bit_data.KGF06 = setPowerOn(); // 交换机、路由器
|
||||
un_inf_can_kgf_output1.bit_data.KGF07 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output1.bit_data.KGF08 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output1.bit_data.KGF09 = setPowerOn(); // 上装
|
||||
un_inf_can_kgf_output1.bit_data.KGF11 = setPowerOn(); // 上装
|
||||
un_inf_can_kgf_output1.bit_data.KGF12 = setPowerOn(); // 待定
|
||||
// un_inf_can_kgf_output1.bit_data.KGF13 = setPowerOn(); // 前左右红灯
|
||||
// un_inf_can_kgf_output1.bit_data.KGF14 = setPowerOn(); // 后左右红灯
|
||||
un_inf_can_kgf_output1.bit_data.KGF15 = setPowerOn(); // 网络摄像头
|
||||
un_inf_can_kgf_output1.bit_data.KGF16 = setPowerOn(); // 遥控器
|
||||
un_inf_can_kgf_output1.bit_data.KGF04 = setPowerOff(); // 预充继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF05 = setPowerOn(); // 上装转台继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF06 = setPowerOn(); // 上装转台继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF07 = setPowerOn(); // 高压继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF08 = setPowerOn(); // 高压继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF11 = setPowerOn(); // 低压继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF12 = setPowerOn(); // 低压继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF15 = setPowerOn(); // 导航计算机
|
||||
un_inf_can_kgf_output1.bit_data.KGF16 = setPowerOn(); // 导航计算机
|
||||
un_inf_can_kgf_output2.bit_data.KGF01 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output2.bit_data.KGF02 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output2.bit_data.KGF15 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output2.bit_data.KGF16 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output2.bit_data.KGF03 = setPowerOn(); // 遥控器
|
||||
un_inf_can_kgf_output2.bit_data.KGF05 = setPowerOn(); // 网络交换机
|
||||
un_inf_can_kgf_output2.bit_data.KGF06 = setPowerOn(); // 网络交换机
|
||||
break;
|
||||
|
||||
|
||||
case POWER_STANDBY:
|
||||
// 初始状态,只开启基本设备
|
||||
un_inf_can_kgf_output1.bit_data.KGF01 = setPowerOn(); // E3
|
||||
un_inf_can_kgf_output1.bit_data.KGF02 = setPowerOn(); // 导航仪
|
||||
un_inf_can_kgf_output1.bit_data.KGF03 = setPowerOff(); // 导航仪
|
||||
un_inf_can_kgf_output1.bit_data.KGF05 = setPowerOn(); // 交换机、路由器
|
||||
un_inf_can_kgf_output1.bit_data.KGF06 = setPowerOn(); // 交换机、路由器
|
||||
un_inf_can_kgf_output1.bit_data.KGF07 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output1.bit_data.KGF08 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output1.bit_data.KGF09 = setPowerOn(); // 上装
|
||||
un_inf_can_kgf_output1.bit_data.KGF11 = setPowerOn(); // 上装
|
||||
un_inf_can_kgf_output1.bit_data.KGF12 = setPowerOn(); // 待定
|
||||
// un_inf_can_kgf_output1.bit_data.KGF13 = setPowerOn(); // 前左右红灯
|
||||
// un_inf_can_kgf_output1.bit_data.KGF14 = setPowerOn(); // 后左右红灯
|
||||
un_inf_can_kgf_output1.bit_data.KGF15 = setPowerOn(); // 网络摄像头
|
||||
un_inf_can_kgf_output1.bit_data.KGF16 = setPowerOn(); // 遥控器
|
||||
un_inf_can_kgf_output1.bit_data.KGF04 = setPowerOff(); // 预充继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF05 = setPowerOff(); // 上装转台继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF06 = setPowerOff(); // 上装转台继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF07 = setPowerOff(); // 高压继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF08 = setPowerOff(); // 高压继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF11 = setPowerOff(); // 低压继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF12 = setPowerOff(); // 低压继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF15 = setPowerOff(); // 导航计算机
|
||||
un_inf_can_kgf_output1.bit_data.KGF16 = setPowerOff(); // 导航计算机
|
||||
un_inf_can_kgf_output2.bit_data.KGF01 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output2.bit_data.KGF02 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output2.bit_data.KGF15 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output2.bit_data.KGF16 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output2.bit_data.KGF03 = setPowerOn(); // 遥控器
|
||||
un_inf_can_kgf_output2.bit_data.KGF05 = setPowerOn(); // 网络交换机
|
||||
un_inf_can_kgf_output2.bit_data.KGF06 = setPowerOn(); // 网络交换机
|
||||
break;
|
||||
|
||||
case POWER_WORKING:
|
||||
// 工作状态,除预充继电器外所有设备开启
|
||||
un_inf_can_kgf_output1.bit_data.KGF01 = setPowerOn(); // E3
|
||||
un_inf_can_kgf_output1.bit_data.KGF02 = setPowerOn(); // 导航仪
|
||||
un_inf_can_kgf_output1.bit_data.KGF03 = setPowerOff(); // 导航仪
|
||||
un_inf_can_kgf_output1.bit_data.KGF05 = setPowerOn(); // 交换机、路由器
|
||||
un_inf_can_kgf_output1.bit_data.KGF06 = setPowerOn(); // 交换机、路由器
|
||||
un_inf_can_kgf_output1.bit_data.KGF07 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output1.bit_data.KGF08 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output1.bit_data.KGF09 = setPowerOn(); // 上装
|
||||
un_inf_can_kgf_output1.bit_data.KGF11 = setPowerOn(); // 上装
|
||||
un_inf_can_kgf_output1.bit_data.KGF12 = setPowerOn(); // 待定
|
||||
// un_inf_can_kgf_output1.bit_data.KGF13 = setPowerOn(); // 前左右红灯
|
||||
// un_inf_can_kgf_output1.bit_data.KGF14 = setPowerOn(); // 后左右红灯
|
||||
un_inf_can_kgf_output1.bit_data.KGF15 = setPowerOn(); // 网络摄像头
|
||||
un_inf_can_kgf_output1.bit_data.KGF16 = setPowerOn(); // 遥控器
|
||||
un_inf_can_kgf_output1.bit_data.KGF04 = setPowerOff(); // 预充继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF05 = setPowerOn(); // 上装转台继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF06 = setPowerOn(); // 上装转台继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF07 = setPowerOn(); // 高压继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF08 = setPowerOn(); // 高压继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF11 = setPowerOn(); // 低压继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF12 = setPowerOn(); // 低压继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF15 = setPowerOn(); // 导航计算机
|
||||
un_inf_can_kgf_output1.bit_data.KGF16 = setPowerOn(); // 导航计算机
|
||||
un_inf_can_kgf_output2.bit_data.KGF01 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output2.bit_data.KGF02 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output2.bit_data.KGF15 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output2.bit_data.KGF16 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output2.bit_data.KGF03 = setPowerOn(); // 遥控器
|
||||
un_inf_can_kgf_output2.bit_data.KGF05 = setPowerOn(); // 网络交换机
|
||||
un_inf_can_kgf_output2.bit_data.KGF06 = setPowerOn(); // 网络交换机
|
||||
break;
|
||||
|
||||
case POWER_EMERGENCY:
|
||||
// 急停状态,断开高压
|
||||
un_inf_can_kgf_output1.bit_data.KGF01 = setPowerOn(); // E3
|
||||
un_inf_can_kgf_output1.bit_data.KGF02 = setPowerOn(); // 导航仪
|
||||
un_inf_can_kgf_output1.bit_data.KGF03 = setPowerOff(); // 导航仪
|
||||
un_inf_can_kgf_output1.bit_data.KGF05 = setPowerOn(); // 交换机、路由器
|
||||
un_inf_can_kgf_output1.bit_data.KGF06 = setPowerOn(); // 交换机、路由器
|
||||
un_inf_can_kgf_output1.bit_data.KGF07 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output1.bit_data.KGF08 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output1.bit_data.KGF09 = setPowerOn(); // 上装
|
||||
un_inf_can_kgf_output1.bit_data.KGF11 = setPowerOn(); // 上装
|
||||
un_inf_can_kgf_output1.bit_data.KGF12 = setPowerOn(); // 待定
|
||||
// un_inf_can_kgf_output1.bit_data.KGF13 = setPowerOn(); // 前左右红灯
|
||||
// un_inf_can_kgf_output1.bit_data.KGF14 = setPowerOn(); // 后左右红灯
|
||||
un_inf_can_kgf_output1.bit_data.KGF15 = setPowerOn(); // 网络摄像头
|
||||
un_inf_can_kgf_output1.bit_data.KGF16 = setPowerOn(); // 遥控器
|
||||
un_inf_can_kgf_output1.bit_data.KGF04 = setPowerOff(); // 预充继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF05 = setPowerOn(); // 上装转台继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF06 = setPowerOn(); // 上装转台继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF07 = setPowerOff(); // 高压继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF08 = setPowerOff(); // 高压继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF11 = setPowerOn(); // 低压继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF12 = setPowerOn(); // 低压继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF15 = setPowerOn(); // 导航计算机
|
||||
un_inf_can_kgf_output1.bit_data.KGF16 = setPowerOn(); // 导航计算机
|
||||
un_inf_can_kgf_output2.bit_data.KGF01 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output2.bit_data.KGF02 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output2.bit_data.KGF15 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output2.bit_data.KGF16 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output2.bit_data.KGF03 = setPowerOn(); // 遥控器
|
||||
un_inf_can_kgf_output2.bit_data.KGF05 = setPowerOn(); // 网络交换机
|
||||
un_inf_can_kgf_output2.bit_data.KGF06 = setPowerOn(); // 网络交换机
|
||||
break;
|
||||
|
||||
case POWER_SLEEP:
|
||||
// 休眠状态,关闭所有设备
|
||||
un_inf_can_kgf_output1.bit_data.KGF01 = setPowerOn(); // E3
|
||||
un_inf_can_kgf_output1.bit_data.KGF02 = setPowerOn(); // 导航仪
|
||||
un_inf_can_kgf_output1.bit_data.KGF03 = setPowerOff(); // 导航仪
|
||||
un_inf_can_kgf_output1.bit_data.KGF05 = setPowerOn(); // 交换机、路由器
|
||||
un_inf_can_kgf_output1.bit_data.KGF06 = setPowerOn(); // 交换机、路由器
|
||||
un_inf_can_kgf_output1.bit_data.KGF07 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output1.bit_data.KGF08 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output1.bit_data.KGF09 = setPowerOn(); // 上装
|
||||
un_inf_can_kgf_output1.bit_data.KGF11 = setPowerOn(); // 上装
|
||||
un_inf_can_kgf_output1.bit_data.KGF12 = setPowerOn(); // 待定
|
||||
// un_inf_can_kgf_output1.bit_data.KGF13 = setPowerOn(); // 前左右红灯
|
||||
// un_inf_can_kgf_output1.bit_data.KGF14 = setPowerOn(); // 后左右红灯
|
||||
un_inf_can_kgf_output1.bit_data.KGF15 = setPowerOn(); // 网络摄像头
|
||||
un_inf_can_kgf_output1.bit_data.KGF16 = setPowerOn(); // 遥控器
|
||||
un_inf_can_kgf_output1.bit_data.KGF04 = setPowerOff(); // 预充继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF05 = setPowerOff(); // 上装转台继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF06 = setPowerOff(); // 上装转台继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF07 = setPowerOff(); // 高压继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF08 = setPowerOff(); // 高压继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF11 = setPowerOff(); // 低压继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF12 = setPowerOff(); // 低压继电器
|
||||
un_inf_can_kgf_output1.bit_data.KGF15 = setPowerOff(); // 导航计算机
|
||||
un_inf_can_kgf_output1.bit_data.KGF16 = setPowerOff(); // 导航计算机
|
||||
un_inf_can_kgf_output2.bit_data.KGF01 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output2.bit_data.KGF02 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output2.bit_data.KGF15 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output2.bit_data.KGF16 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output2.bit_data.KGF03 = setPowerOn(); // 遥控器
|
||||
un_inf_can_kgf_output2.bit_data.KGF05 = setPowerOn(); // 网络交换机
|
||||
un_inf_can_kgf_output2.bit_data.KGF06 = setPowerOn(); // 网络交换机
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -225,7 +238,7 @@ static void powerOutput(void *signal_id)
|
||||
}
|
||||
publishMessage(&power_data, 1);
|
||||
publishMessage(&un_inf_can_kgf_output1, 1);
|
||||
// publishMessage(&un_inf_can_kgf_output2, 1);
|
||||
publishMessage(&un_inf_can_kgf_output2, 1);
|
||||
}
|
||||
|
||||
static void wakeupProcess(void *signal_id)
|
||||
@@ -235,14 +248,14 @@ static void wakeupProcess(void *signal_id)
|
||||
un_gather_output.bit_data.sleep_duration = (uint16_t)getParam("sleepTm");
|
||||
un_gather_output.bit_data.wakeup_interval = (uint16_t)getParam("wakeTm");
|
||||
|
||||
if(un_gather_output.bit_data.sleep_duration < 5)//最小值限定
|
||||
if(un_gather_output.bit_data.sleep_duration < 10)//最小值限定
|
||||
{
|
||||
un_gather_output.bit_data.sleep_duration = 5;
|
||||
un_gather_output.bit_data.sleep_duration = 10;
|
||||
}
|
||||
|
||||
if(un_gather_output.bit_data.wakeup_interval < 5)//最小值限定
|
||||
if(un_gather_output.bit_data.wakeup_interval < 10)//最小值限定
|
||||
{
|
||||
un_gather_output.bit_data.wakeup_interval = 5;
|
||||
un_gather_output.bit_data.wakeup_interval = 10;
|
||||
}
|
||||
|
||||
un_gather_output.bit_data.vehicle_mode = power_data.current_state;
|
||||
@@ -258,13 +271,13 @@ static void powerTimerProcess(void *signal_id)
|
||||
(void)signal_id;
|
||||
|
||||
// 调用电源按钮处理函数
|
||||
// handlePowerButton();
|
||||
handlePowerButton();
|
||||
// 电源按钮状态有变化,保存到参数
|
||||
// if (power_button.is_power_on != power_button.old_is_power_on)
|
||||
// {
|
||||
// setParam("pwr_btn", (float)power_button.is_power_on);
|
||||
// power_button.old_is_power_on = power_button.is_power_on;
|
||||
// }
|
||||
if (power_button.is_power_on != power_button.old_is_power_on)
|
||||
{
|
||||
setParam("pwr_btn", (float)power_button.is_power_on);
|
||||
power_button.old_is_power_on = power_button.is_power_on;
|
||||
}
|
||||
|
||||
// 状态转换逻辑
|
||||
switch (power_data.current_state)
|
||||
@@ -272,82 +285,45 @@ static void powerTimerProcess(void *signal_id)
|
||||
case POWER_PRE_CHARGE:
|
||||
if (!power_data.timer_pre_charge.active) // 预充时间到
|
||||
{
|
||||
power_data.current_state = POWER_NEUTRAL; // 工作
|
||||
power_data.pre_charge_finish = 1; // 预充完成
|
||||
printf("Power: Transitioning from PRE_CHARGE to POWER_NEUTRAL state\n");
|
||||
}
|
||||
break;
|
||||
case POWER_NEUTRAL://20250316增加,发送空挡信号
|
||||
if (power_data.neutral_cnt >= 5) // 运行5次
|
||||
{
|
||||
power_data.neutral_cnt = 0;
|
||||
power_data.current_state = POWER_WORKING; // 工作
|
||||
power_data.pre_charge_finish = 1; // 预充完成
|
||||
printf("Power: Transitioning from POWER_NEUTRAL to WORKING state\n");
|
||||
printf("Power: Transitioning from PRE_CHARGE to WORKING state\n");
|
||||
}
|
||||
break;
|
||||
case POWER_STANDBY:
|
||||
if (power_button.is_power_on == app_close() && power_data.emergency_stop == app_close()) // 遥控器电源开关闭合且急停开关闭合
|
||||
{
|
||||
power_data.current_state = POWER_EMERGENCY; // 急停
|
||||
printf("Power: Transitioning from STANDBY to EMERGENCY state\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
power_data.neutral_cnt ++;
|
||||
power_data.current_state = POWER_NEUTRAL; // 空挡
|
||||
power_data.pre_charge_finish = 1; // 预充完成
|
||||
}
|
||||
break;
|
||||
|
||||
case POWER_STANDBY:
|
||||
|
||||
power_data.current_state = POWER_WORKING; // 休眠 20251005 修改不需要休眠,直接上电
|
||||
// if (power_data.high_voltage_switch == app_open()) // 高压开关断开
|
||||
// {
|
||||
// power_data.current_state = POWER_SLEEP; // 休眠
|
||||
// printf("Power: Transitioning from STANDBY to SLEEP state\n");
|
||||
// }
|
||||
// else if (power_button.is_power_on == app_close() && power_data.emergency_stop == app_close()) // 遥控器电源开关闭合且急停开关闭合
|
||||
// {
|
||||
// power_data.current_state = POWER_EMERGENCY; // 急停
|
||||
// printf("Power: Transitioning from STANDBY to EMERGENCY state\n");
|
||||
// }
|
||||
break;
|
||||
|
||||
case POWER_WORKING:
|
||||
// if (power_data.high_voltage_switch == app_open()) // 高压开关断开
|
||||
// {
|
||||
// power_data.current_state = POWER_SLEEP; // 休眠
|
||||
// printf("Power: Transitioning from STANDBY to SLEEP state\n");
|
||||
//
|
||||
if (power_data.emergency_stop == app_close()) // 急停开关闭合
|
||||
{
|
||||
power_data.current_state = POWER_EMERGENCY; // 急停
|
||||
printf("Power: Transitioning from WORKING to EMERGENCY state\n");
|
||||
|
||||
printf("emergency_stop_switch: %d, remote_emergency_stop: %d\n", power_data.emergency_stop_switch, power_data.remote_emergency_stop); //打印状态
|
||||
printf("remote_stop: %d\n", un_remote_control_input.bit_data.switch_b);
|
||||
printf("Power: Transitioning from WORKING to EMERGENCY state\n");
|
||||
}
|
||||
break;
|
||||
case POWER_EMERGENCY:
|
||||
// if (power_data.high_voltage_switch == app_open()) // 高压开关断开
|
||||
// {
|
||||
// power_data.current_state = POWER_SLEEP; // 休眠
|
||||
// printf("Power: Transitioning from EMERGENCY to SLEEP state\n");
|
||||
// }
|
||||
// else if (power_button.is_power_on == app_open()) // 遥控器电源开关断开 //20251005 修改不需要电源开关
|
||||
// {
|
||||
// power_data.current_state = POWER_STANDBY; // 待机
|
||||
// printf("Power: Transitioning from EMERGENCY to STANDBY state\n");
|
||||
// }
|
||||
if (power_data.emergency_stop == app_open()) // 急停断开
|
||||
if (power_button.is_power_on == app_open()) // 遥控器电源开关断开
|
||||
{
|
||||
power_data.current_state = POWER_STANDBY; // 待机
|
||||
printf("Power: Transitioning from EMERGENCY to STANDBY state\n");
|
||||
}
|
||||
else if (power_data.emergency_stop == app_open()) // 急停断开
|
||||
{
|
||||
power_data.current_state = POWER_PRE_CHARGE; // 预充
|
||||
timerStart(&power_data.timer_pre_charge, (uint32_t)(getParam("prCTime") * 1000), 1); // 启动预充定时器
|
||||
printf("Power: Transitioning from EMERGENCY to PRE_CHARGE state\n");
|
||||
}
|
||||
break;
|
||||
case POWER_SLEEP:
|
||||
if (power_data.high_voltage_switch == app_close()) // 高压开关闭合
|
||||
{
|
||||
power_data.current_state = POWER_STANDBY; // 待机
|
||||
printf("Power: Transitioning from SLEEP to STANDBY state\n");
|
||||
}
|
||||
break;
|
||||
// case POWER_SLEEP:
|
||||
// if (power_data.high_voltage_switch == app_close()) // 高压开关闭合
|
||||
// {
|
||||
// power_data.current_state = POWER_STANDBY; // 待机
|
||||
// printf("Power: Transitioning from SLEEP to STANDBY state\n");
|
||||
// }
|
||||
// break;
|
||||
default:
|
||||
power_data.current_state = POWER_STANDBY; // 待机
|
||||
break;
|
||||
@@ -376,13 +352,10 @@ static void powerInput(void *signal_id)
|
||||
memcpy(&old_data, &power_data, sizeof(PowerSystem));
|
||||
|
||||
// 填充数据
|
||||
power_data.emergency_stop_switch = 0;//急停开关 20251005 修改四轮四转车无急停开关以及采集模块 高压
|
||||
power_data.high_voltage_switch = 1;//高压开关
|
||||
|
||||
if (signal_id == &un_sw_sample)
|
||||
{
|
||||
// power_data.emergency_stop_switch = (uint8_t)un_sw_sample.bit_data.emergency_stop_switch;//急停开关
|
||||
// power_data.high_voltage_switch = (uint8_t)un_sw_sample.bit_data.High_voltage_switch;//高压开关
|
||||
power_data.emergency_stop_switch = (uint8_t)un_sw_sample.bit_data.emergency_stop_switch;//急停开关
|
||||
power_data.high_voltage_switch = (uint8_t)un_sw_sample.bit_data.High_voltage_switch;//高压开关
|
||||
}
|
||||
else if ( (signal_id == &un_remote_control_input) && (1 == un_remote_control_input.bit_data.enable) )// 遥控器断线,不更新数据
|
||||
{
|
||||
@@ -425,22 +398,7 @@ void powerAppInit(void)
|
||||
power_data.old_high_voltage_switch = power_data.high_voltage_switch;
|
||||
//恢复急停开关状态
|
||||
power_data.emergency_stop = (uint8_t)getParam("stop_sw");
|
||||
power_data.old_emergency_stop = power_data.emergency_stop;
|
||||
|
||||
un_inf_can_kgf_output1.bit_data.KGF01 = setPowerOff(); // E3 初始化上电默认打开
|
||||
un_inf_can_kgf_output1.bit_data.KGF02 = setPowerOn(); // 导航仪
|
||||
un_inf_can_kgf_output1.bit_data.KGF03 = setPowerOff(); // 导航仪
|
||||
un_inf_can_kgf_output1.bit_data.KGF05 = setPowerOn(); // 交换机、路由器
|
||||
un_inf_can_kgf_output1.bit_data.KGF06 = setPowerOn(); // 交换机、路由器
|
||||
un_inf_can_kgf_output1.bit_data.KGF07 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output1.bit_data.KGF08 = setPowerOn(); // 计算机
|
||||
un_inf_can_kgf_output1.bit_data.KGF09 = setPowerOn(); // 上装
|
||||
un_inf_can_kgf_output1.bit_data.KGF11 = setPowerOn(); // 上装
|
||||
un_inf_can_kgf_output1.bit_data.KGF12 = setPowerOn(); // 待定
|
||||
un_inf_can_kgf_output1.bit_data.KGF13 = setPowerOn(); // 前左右红灯
|
||||
un_inf_can_kgf_output1.bit_data.KGF14 = setPowerOn(); // 后左右红灯
|
||||
un_inf_can_kgf_output1.bit_data.KGF15 = setPowerOn(); // 网络摄像头
|
||||
un_inf_can_kgf_output1.bit_data.KGF16 = setPowerOn(); // 遥控器
|
||||
power_data.old_emergency_stop = power_data.emergency_stop;
|
||||
|
||||
// 订阅输入信号
|
||||
subscribe(&un_sw_sample, powerInput); // 急停开关、高压开关
|
||||
|
||||
@@ -280,7 +280,7 @@ static void requestInput(void *signal_id)
|
||||
}
|
||||
else if(signal_id == &un_motor_input1)
|
||||
{
|
||||
// un_motor_status_output.bit_data.left_wheel_speed = SWAP_ENDIAN_16( (uint16_t)((int16_t)(un_motor_input1.bit_data.MotCon_1Signal4) + 30000) );
|
||||
un_motor_status_output.bit_data.left_wheel_speed = SWAP_ENDIAN_16( (uint16_t)((int16_t)(un_motor_input1.bit_data.MotCon_1Signal4) + 30000) );
|
||||
|
||||
// un_motor_status_output.bit_data.left_torque = ((un_motor_input1.bit_data.torque << 8) | (un_motor_input1.bit_data.torque >> 8));//左侧扭矩
|
||||
// un_motor_status_output.bit_data.left_voltage = ((un_motor_input1.bit_data.bus_voltage << 8) | (un_motor_input1.bit_data.bus_voltage >> 8));//左侧电压
|
||||
@@ -289,7 +289,7 @@ static void requestInput(void *signal_id)
|
||||
}
|
||||
else if(signal_id == &un_motor_input2)
|
||||
{
|
||||
// un_motor_status_output.bit_data.right_wheel_speed = SWAP_ENDIAN_16 ( (uint16_t)((int16_t)(un_motor_input1.bit_data.MotCon_1Signal3) + 30000) );//左侧轮速
|
||||
un_motor_status_output.bit_data.right_wheel_speed = SWAP_ENDIAN_16 ( (uint16_t)((int16_t)(un_motor_input1.bit_data.MotCon_1Signal3) + 30000) );//左侧轮速
|
||||
// un_motor_status_output.bit_data.right_torque = ((un_motor_input2.bit_data.torque << 8) | (un_motor_input2.bit_data.torque >> 8));//右侧扭矩
|
||||
// un_motor_status_output.bit_data.right_fault_code = un_motor_input2.bit_data.fault_code;//右侧故障码
|
||||
// un_motor_status_output.bit_data.right_voltage = ((un_motor_input2.bit_data.bus_voltage << 8) | (un_motor_input2.bit_data.bus_voltage >> 8));//右侧电压
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
// 声明 temp_data 变量
|
||||
TempSystem temp_data;
|
||||
|
||||
|
||||
static void handleTemperatureAlarm(int16_t current_temp, float alarm_temp,
|
||||
float critical_temp, float threshold_temp,
|
||||
TempState *state)
|
||||
@@ -86,25 +87,8 @@ static void tempOutput(void *signal_id)
|
||||
{
|
||||
(void)signal_id;
|
||||
|
||||
// 电机1风扇 左前
|
||||
// 电机1风扇
|
||||
switch (temp_data.state[0])
|
||||
{
|
||||
case TEMP_NORMAL:
|
||||
un_inf_can_kgf_output1.bit_data.KGF02 = setFanOff();//电机控制器风扇
|
||||
un_inf_can_kgf_output1.bit_data.pwm_02 = 0;
|
||||
break;
|
||||
case TEMP_WARNING:
|
||||
un_inf_can_kgf_output1.bit_data.KGF02 = setFanOn();//电机控制器风扇
|
||||
un_inf_can_kgf_output1.bit_data.pwm_02 = 5;
|
||||
break;
|
||||
case TEMP_CRITICAL:
|
||||
un_inf_can_kgf_output1.bit_data.KGF02 = setFanOn();//电机控制器风扇
|
||||
un_inf_can_kgf_output1.bit_data.pwm_02 = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
// 电机2风扇 右前
|
||||
switch (temp_data.state[1])
|
||||
{
|
||||
case TEMP_NORMAL:
|
||||
un_inf_can_kgf_output1.bit_data.KGF01 = setFanOff();//电机控制器风扇
|
||||
@@ -118,89 +102,39 @@ static void tempOutput(void *signal_id)
|
||||
un_inf_can_kgf_output1.bit_data.KGF01 = setFanOn();//电机控制器风扇
|
||||
un_inf_can_kgf_output1.bit_data.pwm_01 = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// 电机3风扇 左后
|
||||
switch (temp_data.state[2])
|
||||
}
|
||||
// 电机2风扇
|
||||
switch (temp_data.state[1])
|
||||
{
|
||||
case TEMP_NORMAL:
|
||||
un_inf_can_kgf_output2.bit_data.KGF08 = setFanOff();//电机控制器风扇
|
||||
un_inf_can_kgf_output2.bit_data.pwm_08 = 0;
|
||||
un_inf_can_kgf_output1.bit_data.KGF03 = setFanOff();//电机控制器风扇
|
||||
un_inf_can_kgf_output1.bit_data.pwm_03 = 0;
|
||||
break;
|
||||
case TEMP_WARNING:
|
||||
un_inf_can_kgf_output2.bit_data.KGF08 = setFanOn();//电机控制器风扇
|
||||
un_inf_can_kgf_output2.bit_data.pwm_08 = 5;
|
||||
un_inf_can_kgf_output1.bit_data.KGF03 = setFanOn();//电机控制器风扇
|
||||
un_inf_can_kgf_output1.bit_data.pwm_03 = 5;
|
||||
break;
|
||||
case TEMP_CRITICAL:
|
||||
un_inf_can_kgf_output2.bit_data.KGF08 = setFanOn();//电机控制器风扇
|
||||
un_inf_can_kgf_output2.bit_data.pwm_08 = 0;
|
||||
un_inf_can_kgf_output1.bit_data.KGF03 = setFanOn();//电机控制器风扇
|
||||
un_inf_can_kgf_output1.bit_data.pwm_03 = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
// 电机4风扇 右后
|
||||
switch (temp_data.state[3])
|
||||
{
|
||||
case TEMP_NORMAL:
|
||||
un_inf_can_kgf_output2.bit_data.KGF07 = setFanOff();//电机控制器风扇
|
||||
un_inf_can_kgf_output2.bit_data.pwm_07 = 0;
|
||||
break;
|
||||
case TEMP_WARNING:
|
||||
un_inf_can_kgf_output2.bit_data.KGF07 = setFanOn();//电机控制器风扇
|
||||
un_inf_can_kgf_output2.bit_data.pwm_07 = 5;
|
||||
break;
|
||||
case TEMP_CRITICAL:
|
||||
un_inf_can_kgf_output2.bit_data.KGF07 = setFanOn();//电机控制器风扇
|
||||
un_inf_can_kgf_output2.bit_data.pwm_07 = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
// // 电机3风扇
|
||||
// switch (temp_data.state[2])
|
||||
// {
|
||||
// case TEMP_NORMAL:
|
||||
// un_inf_can_kgf_output1.bit_data.KGF01 = setFanOff();//电机控制器风扇
|
||||
// un_inf_can_kgf_output1.bit_data.pwm_01 = 0;
|
||||
// break;
|
||||
// case TEMP_WARNING:
|
||||
// un_inf_can_kgf_output1.bit_data.KGF01 = setFanOn();//电机控制器风扇
|
||||
// un_inf_can_kgf_output1.bit_data.pwm_01 = 5;
|
||||
// break;
|
||||
// case TEMP_CRITICAL:
|
||||
// un_inf_can_kgf_output1.bit_data.KGF01 = setFanOn();//电机控制器风扇
|
||||
// un_inf_can_kgf_output1.bit_data.pwm_01 = 0;
|
||||
// break;
|
||||
// }
|
||||
|
||||
}
|
||||
publishMessage(&un_inf_can_kgf_output1, 1);
|
||||
publishMessage(&un_inf_can_kgf_output2, 1);
|
||||
}
|
||||
|
||||
// 温度状态处理函数
|
||||
static void tempProcess(void *signal_id)
|
||||
{
|
||||
(void)signal_id;
|
||||
int16_t max_temp[4] = {0,0,0,0};
|
||||
int16_t max_temp[2] = {0,0};
|
||||
|
||||
// 调用按钮处理函数
|
||||
max_temp[0] = temp_data.current_temp[0];
|
||||
max_temp[1] = temp_data.current_temp[1];
|
||||
max_temp[2] = temp_data.current_temp[2];
|
||||
max_temp[3] = temp_data.current_temp[3];
|
||||
|
||||
// printf("motor1 temp: %d, motor2 temp: %d\n", max_temp[0], max_temp[1]);
|
||||
handleTemperatureAlarm(max_temp[0], MOTOR_WARNING_TEMP, MOTOR_CRITICAL_TEMP, MOTOR_THRESHOLD_TEMP, &temp_data.state[0]);
|
||||
|
||||
handleTemperatureAlarm(max_temp[1], MOTOR_WARNING_TEMP, MOTOR_CRITICAL_TEMP, MOTOR_THRESHOLD_TEMP, &temp_data.state[1]);
|
||||
|
||||
handleTemperatureAlarm(max_temp[2], MOTOR_WARNING_TEMP, MOTOR_CRITICAL_TEMP, MOTOR_THRESHOLD_TEMP, &temp_data.state[2]);
|
||||
|
||||
handleTemperatureAlarm(max_temp[3], MOTOR_WARNING_TEMP, MOTOR_CRITICAL_TEMP, MOTOR_THRESHOLD_TEMP, &temp_data.state[3]);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// printf("motor1 temp: %d, motor2 temp: %d\n", max_temp[0], max_temp[1]);
|
||||
handleTemperatureAlarm(max_temp[0], MOTOR_WARNING_TEMP, MOTOR_CRITICAL_TEMP, MOTOR_THRESHOLD_TEMP, &temp_data.state[0]);
|
||||
|
||||
handleTemperatureAlarm(max_temp[1], MOTOR_WARNING_TEMP, MOTOR_CRITICAL_TEMP, MOTOR_THRESHOLD_TEMP, &temp_data.state[1]);
|
||||
|
||||
// if (max_temp[0] >= 60) // 假设60度为危险温度
|
||||
// {
|
||||
@@ -251,15 +185,8 @@ static void tempInput(void *signal_id)
|
||||
{
|
||||
temp_data.current_temp[1] = ( (int16_t)(un_motor_temp2.bit_data.controller_temp) - 40);
|
||||
}
|
||||
else if(signal_id == &un_motor_temp3)
|
||||
{
|
||||
temp_data.current_temp[2] = ( (int16_t)(un_motor_temp3.bit_data.controller_temp) - 40);
|
||||
}
|
||||
else if(signal_id == &un_motor_temp4)
|
||||
{
|
||||
temp_data.current_temp[3] = ( (int16_t)(un_motor_temp4.bit_data.controller_temp) - 40);
|
||||
}
|
||||
else{}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -278,8 +205,7 @@ void tempAppInit(void)
|
||||
// 订阅输入信号,处理温度逻辑
|
||||
subscribe(&un_motor_temp1, tempInput);
|
||||
subscribe(&un_motor_temp2, tempInput);
|
||||
subscribe(&un_motor_temp3, tempInput);
|
||||
subscribe(&un_motor_temp4, tempInput);
|
||||
|
||||
|
||||
// 启动定时器,每秒检查一次温度
|
||||
subscribe(&temp_data.timer, tempProcess);
|
||||
|
||||
@@ -9,9 +9,7 @@
|
||||
#include "app_frm_signal.h"
|
||||
#include "app_frm_timer.h"
|
||||
|
||||
#include "drive_rs04.h"
|
||||
#include "sdrv_vic.h"
|
||||
#include <math.h>
|
||||
|
||||
PID_t turnable_speed_pid;
|
||||
PID_t turnable_position_pid;
|
||||
@@ -19,106 +17,234 @@ PID_t turnable_position_pid;
|
||||
TurnableData turnable_data = {0};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief 将笛卡尔坐标 (x,y,z) 转换为球坐标 (r,θ,φ)
|
||||
*
|
||||
* @param x X轴坐标值(单位:米)
|
||||
* @param y Y轴坐标值(单位:米)
|
||||
* @param z Z轴坐标值(单位:米)
|
||||
* @param[out] out 输出球坐标结构体指针
|
||||
* @return bool 转换是否成功:
|
||||
* - true: 转换成功
|
||||
* - false: 输入无效(包含NaN/INF或out为NULL)
|
||||
*
|
||||
* @note 特殊输入处理:
|
||||
* 1. 如果输入包含 NaN 或无穷大,返回 false
|
||||
* 2. 当 r < 1e-10 时视为原点,设置 out=(0, 0, 0)
|
||||
* 3. 在Z轴附近 (|z/r| ≈ 1) 时自动截断到 [-1,1] 保证数值稳定性
|
||||
*
|
||||
* @warning 使用要求:
|
||||
* - 必须检查返回值,不能直接使用out内容
|
||||
* - out指针必须指向有效内存
|
||||
*
|
||||
* @example 正确用法:
|
||||
* SphericalCoordinate sph;
|
||||
* if (cartesianToSpherical(1.0f, 0.0f, 0.0f, &sph)) {
|
||||
* // 使用sph...
|
||||
* }
|
||||
* @brief 带死区的原始数据到物理量转换函数(简单版)
|
||||
* @param raw_value 原始16位无符号整数值 [0, 65535]
|
||||
* @param min 物理量最小值(如 -10.0)
|
||||
* @param max 物理量最大值(如 +10.0)
|
||||
* @param deadzone 死区范围(物理量单位,如 1.0 表示 ±1.0 内为死区)
|
||||
* @return 转换后的物理量值(若在死区内返回0,否则返回实际值)
|
||||
*/
|
||||
uint8_t cartesianToSpherical(float x, float y, float z, SphericalCoordinate* out)
|
||||
static float convertPhysical(uint16_t raw_value, float min, float max, float deadzone)
|
||||
{
|
||||
// 参数有效性检查(防御性编程)
|
||||
if (!out || !isfinite(x) || !isfinite(y) || !isfinite(z)) {
|
||||
return 0;
|
||||
}
|
||||
// 1. 计算实际物理量值
|
||||
float physical_value = min + ((float)raw_value / 65535.0f) * (max - min);
|
||||
|
||||
// 计算径向距离 r = √(x² + y² + z²)
|
||||
out->r = sqrtf(x * x + y * y + z * z);
|
||||
|
||||
// 原点判定(使用容差避免浮点误差)
|
||||
if (out->r < 1e-10f) {
|
||||
out->theta = 0.0f;
|
||||
out->phi = 0.0f;
|
||||
return 1;
|
||||
// 2. 判断是否在死区内(绝对值 ≤ deadzone)
|
||||
if (fabs(physical_value) <= deadzone)
|
||||
{
|
||||
return 0.0f; // 死区内返回0
|
||||
}
|
||||
else
|
||||
{
|
||||
return physical_value; // 死区外返回实际值
|
||||
}
|
||||
|
||||
// 极角 θ = acos(z/r) 的数值稳定性处理
|
||||
float z_over_r = z / out->r;
|
||||
if (z_over_r > 1.0f) z_over_r = 1.0f; // 处理上溢出
|
||||
if (z_over_r < -1.0f) z_over_r = -1.0f; // 处理下溢出
|
||||
out->theta = acosf(z_over_r);
|
||||
|
||||
// 方位角 φ = atan2(y, x)
|
||||
out->phi = atan2f(y, x);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// 计算CRC8校验(多项式 x^8 + 1,简单的累加和)
|
||||
uint8_t encoder_calculate_crc(const uint8_t* data, uint8_t length)
|
||||
/**
|
||||
* @brief 将浮点数转换为uint32_t(按小端序存储)
|
||||
* @param num 输入的浮点数
|
||||
* @return 转换后的uint32_t值(直接内存拷贝结果)
|
||||
* @note 此函数通过内存直接拷贝实现转换,不进行数值计算,结果受平台字节序影响
|
||||
*/
|
||||
uint32_t floatToUint32(float num)
|
||||
{
|
||||
uint8_t crc = 0x00;
|
||||
for (int i = 0; i < length; i++) {
|
||||
crc += data[i];
|
||||
}
|
||||
return crc;
|
||||
uint32_t result;
|
||||
// 将浮点数的内存数据直接拷贝到uint32_t变量
|
||||
memcpy(&result, &num, sizeof(num));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 电机失能函数(停止电机运行)
|
||||
* @param motor_id 目标电机ID (范围取决于系统设计,通常0-255)
|
||||
* @param master_id 主控制器ID (用于标识发送方)
|
||||
* @param unsdodata 指向UnSdoOutput联合体的指针,用于填充CAN报文数据
|
||||
* @return 0: 成功, -1: 参数无效
|
||||
* @note 此函数会修改unsdodata指向的结构体内容,调用后需及时发送CAN报文
|
||||
*/
|
||||
int8_t motorDisable(uint8_t master_id, uint8_t motor_id, StrTxCanFrame *unsdodata)
|
||||
{
|
||||
/* 参数有效性检查 */
|
||||
if (unsdodata == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* 设置CAN报文ID域 */
|
||||
unsdodata->tx_can_id.bits.mode = 3; /* 通信模式3:电机失能 */
|
||||
unsdodata->tx_can_id.bits.motor_id = motor_id; /* 目标电机ID */
|
||||
unsdodata->tx_can_id.bits.res = 0; /* 保留位清零 */
|
||||
unsdodata->tx_can_id.bits.data = master_id; /* 主控制器ID */
|
||||
|
||||
/* 清零数据域 */
|
||||
unsdodata->tx_can_data.bit_data.data = 0;
|
||||
unsdodata->tx_can_data.bit_data.index = 0;
|
||||
unsdodata->tx_can_data.bit_data.object_index = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 电机使能函数(启动电机运行)
|
||||
* @param motor_id 目标电机ID (范围取决于系统设计,通常0-255)
|
||||
* @param master_id 主控制器ID (用于标识发送方)
|
||||
* @param unsdodata 指向UnSdoOutput联合体的指针,用于填充CAN报文数据
|
||||
* @return 0: 成功, -1: 参数无效
|
||||
* @note 通信模式4:电机使能
|
||||
*/
|
||||
int8_t motorEnable(uint8_t master_id, uint8_t motor_id, StrTxCanFrame *unsdodata)
|
||||
{
|
||||
/* 参数有效性检查 */
|
||||
if (unsdodata == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* 设置CAN报文ID域 */
|
||||
unsdodata->tx_can_id.bits.mode = 3; /* 通信模式4:电机使能 */
|
||||
unsdodata->tx_can_id.bits.motor_id = motor_id; /* 目标电机ID */
|
||||
unsdodata->tx_can_id.bits.res = 0; /* 保留位清零 */
|
||||
unsdodata->tx_can_id.bits.data = master_id; /* 主控制器ID */
|
||||
|
||||
/* 清零数据域 */
|
||||
unsdodata->tx_can_data.bit_data.data = 0;
|
||||
unsdodata->tx_can_data.bit_data.index = 0;
|
||||
unsdodata->tx_can_data.bit_data.object_index = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置电机运行模式
|
||||
* @param motor_id 目标电机ID (范围取决于系统设计,通常0-255)
|
||||
* @param master_id 主控制器ID (用于标识发送方)
|
||||
* @param unsdodata 指向UnSdoOutput联合体的指针,用于填充CAN报文数据
|
||||
* @param mode 要设置的模式值 (具体含义需参考电机协议文档)
|
||||
* @return 0: 成功, -1: 参数无效
|
||||
* @note RUM_MODE应为预定义的宏,表示运行模式索引
|
||||
*/
|
||||
int8_t setMotorMode(uint8_t master_id, uint8_t motor_id, StrTxCanFrame *unsdodata, uint8_t mode)
|
||||
{
|
||||
/* 参数有效性检查 */
|
||||
if (unsdodata == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* 设置CAN报文ID域 */
|
||||
unsdodata->tx_can_id.bits.mode = 0x12; /* 通信模式0x12:参数写入 */
|
||||
unsdodata->tx_can_id.bits.motor_id = motor_id; /* 目标电机ID */
|
||||
unsdodata->tx_can_id.bits.res = 0; /* 保留位清零 */
|
||||
unsdodata->tx_can_id.bits.data = master_id; /* 主控制器ID */
|
||||
|
||||
/* 设置数据域 */
|
||||
unsdodata->tx_can_data.bit_data.index = RUM_MODE; /* 运行模式索引 */
|
||||
unsdodata->tx_can_data.bit_data.object_index = 0; /* 子索引通常为0 */
|
||||
unsdodata->tx_can_data.bit_data.data = mode; /* 模式值 */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 写入电机参数
|
||||
* @param motor_id 目标电机ID (范围取决于系统设计,通常0-255)
|
||||
* @param master_id 主控制器ID (用于标识发送方)
|
||||
* @param unsdodata 指向UnSdoOutput联合体的指针,用于填充CAN报文数据
|
||||
* @param index 要写入的参数索引 (具体含义需参考电机协议文档)
|
||||
* @param ref 要写入的参数值 (浮点数,会自动转换为uint32_t)
|
||||
* @return 0: 成功, -1: 参数无效
|
||||
* @note 使用floatToUint32函数转换浮点参数
|
||||
*/
|
||||
int8_t setMotorWrite(uint8_t master_id, uint8_t motor_id, StrTxCanFrame *unsdodata, uint16_t index, float ref)
|
||||
{
|
||||
/* 参数有效性检查 */
|
||||
if (unsdodata == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* 设置CAN报文ID域 */
|
||||
unsdodata->tx_can_id.bits.mode = 0x12; /* 通信模式0x12:参数写入 */
|
||||
unsdodata->tx_can_id.bits.motor_id = motor_id; /* 目标电机ID */
|
||||
unsdodata->tx_can_id.bits.res = 0; /* 保留位清零 */
|
||||
unsdodata->tx_can_id.bits.data = master_id; /* 主控制器ID */
|
||||
|
||||
/* 设置数据域 */
|
||||
unsdodata->tx_can_data.bit_data.index = index; /* 参数索引 */
|
||||
unsdodata->tx_can_data.bit_data.object_index = 0; /* 子索引通常为0 */
|
||||
unsdodata->tx_can_data.bit_data.data = floatToUint32(ref); /* 转换并写入参数值 */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 动态斜率限制(支持变时间间隔)
|
||||
* @param last_command 上一次的电流指令值
|
||||
* @param target_current 本次目标电流指令
|
||||
* @param delta_time 距离上一次调用的时间间隔 (s)
|
||||
* @return 限制后的安全电流指令
|
||||
*/
|
||||
float dynamic_current_limit(float *last_command, float target_current, float delta_time)
|
||||
{
|
||||
// 计算期望的变化量
|
||||
float desired_change = target_current - *last_command;
|
||||
|
||||
// 计算两种限制
|
||||
float step_limit = MAX_STEP;
|
||||
float time_limit = MAX_DI_DT * delta_time; // 动态计算时间限制
|
||||
|
||||
// 选择更严格的限制
|
||||
float max_allowed_change = (step_limit < time_limit) ? step_limit : time_limit;
|
||||
|
||||
// 应用限制并返回新指令
|
||||
float actual_change = constrain(desired_change, -max_allowed_change, max_allowed_change);
|
||||
*last_command = *last_command + actual_change;//更新过去值
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return *last_command + actual_change;
|
||||
}
|
||||
|
||||
static void setTurnableMotorOutput()
|
||||
{
|
||||
|
||||
turnable_data.out_pitch_motor_ampere = constrain(turnable_data.out_pitch_motor_ampere, -RS02_ANGULAR_VELOCITY_MAX, RS02_ANGULAR_VELOCITY_MAX);
|
||||
turnable_data.out_left_motor_ampere = constrain(turnable_data.out_left_motor_ampere, -RS02_ANGULAR_VELOCITY_MAX, RS02_ANGULAR_VELOCITY_MAX);
|
||||
|
||||
|
||||
static float previous_time2 = 0.0f;
|
||||
|
||||
float time1 = (float)getCurrentTime();
|
||||
float dt = (time1 - previous_time2) / PERIOD_TICK;
|
||||
previous_time2 = time1;
|
||||
|
||||
// turnable_data.out_pitch_motor_ampere_limit = dynamic_current_limit(&turnable_data.out_pitch_motor_ampere_last,turnable_data.out_pitch_motor_ampere,dt);
|
||||
turnable_data.out_right_motor_ampere_limit = dynamic_current_limit(&turnable_data.out_right_motor_ampere_last,turnable_data.out_right_motor_ampere,dt);
|
||||
turnable_data.out_left_motor_ampere_limit = dynamic_current_limit(&turnable_data.out_left_motor_ampere_last ,turnable_data.out_left_motor_ampere ,dt);
|
||||
|
||||
setMotorWrite(MASTER_CANID, PITCH_MOTOR_CANID, &un_sdo_output1, LIMIT_SPEED_INDEX,turnable_data.out_pitch_motor_ampere);
|
||||
setMotorWrite(MASTER_CANID, PITCH_MOTOR_CANID, &un_sdo_output4, LOC_REF_INDEX,turnable_data.desired_pitch_position);
|
||||
|
||||
setMotorWrite(MASTER_CANID, RIGHT_MOTOR_CANID, &un_sdo_output2, SPD_REF,turnable_data.out_left_motor_ampere);
|
||||
|
||||
|
||||
setMotorWrite(MASTER_CANID, RIGHT_MOTOR_CANID, &un_sdo_output2, IQ_REF_INDEX,turnable_data.out_right_motor_ampere_limit);
|
||||
setMotorWrite(MASTER_CANID, TURN_MOTOR_CANID, &un_sdo_output3, IQ_REF_INDEX,turnable_data.out_left_motor_ampere_limit);
|
||||
|
||||
|
||||
|
||||
|
||||
un_can_debug_output.bit_data.speed = (uint8_t)(int8_t)(turnable_data.speed*10);
|
||||
un_can_debug_output.bit_data.desired_speed = (uint8_t)(int8_t)(turnable_data.desired_speed*10);
|
||||
|
||||
// un_can_debug_output.bit_data.curvature = (uint8_t)(int8_t)(diff_data.yaw_rate*10);
|
||||
// un_can_debug_output.bit_data.desired_curvature = (uint8_t)(int8_t)(diff_data.desired_yaw_rate*10);
|
||||
|
||||
un_can_debug_output.bit_data.set_left_out = (uint16_t)(int16_t)(turnable_data.out_left_motor_ampere_limit * 100);
|
||||
un_can_debug_output.bit_data.set_right_out = (uint16_t)(int16_t)(turnable_data.out_right_motor_ampere_limit*100);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
publishMessage(&un_sdo_output1, 1);
|
||||
publishMessage(&un_sdo_output2, 1);
|
||||
publishMessage(&un_sdo_output4, 1);
|
||||
publishMessage(&un_sdo_output2, 1);
|
||||
publishMessage(&un_sdo_output3, 1);
|
||||
publishMessage(&un_sdo_output4, 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -128,79 +254,90 @@ static void setTurnableMotorOutput()
|
||||
// 转台
|
||||
static void turnableProcess(void *signal_id)
|
||||
{
|
||||
|
||||
// static float previous_time1 = 0.0f;
|
||||
|
||||
// float time1 = (float)getCurrentTime();
|
||||
// float dt = (time1 - previous_time1) / PERIOD_TICK;
|
||||
// previous_time1 = time1;
|
||||
// if((turnable_data.current_state == POWER_WORKING))//高压上电才运行
|
||||
// {
|
||||
switch(turnable_data.turnable_state)//先发送切换模式以及电机失能,后面直接使能 最后发送数据
|
||||
{
|
||||
case 0:
|
||||
timerStart(&turnable_data.turnable_timer, 1000, 1); // 启动定时器,1s
|
||||
turnable_data.turnable_state = 1;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
if (!turnable_data.turnable_timer.active)// 1s定时
|
||||
{
|
||||
turnable_data.turnable_state = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
turnable_data.turnable_state = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case 2://模式设置
|
||||
if(turnable_data.turnable_cnt >= 5)//发送5次
|
||||
{
|
||||
turnable_data.turnable_cnt = 0;
|
||||
turnable_data.turnable_state = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
turnable_data.turnable_cnt ++;
|
||||
turnable_data.turnable_state = 2;
|
||||
|
||||
setMotorMode(MASTER_CANID, PITCH_MOTOR_CANID, &un_sdo_output1, POSITION_MODE_CSP);
|
||||
setMotorMode(MASTER_CANID, RIGHT_MOTOR_CANID, &un_sdo_output2, VELOCITY_MODE);
|
||||
|
||||
setMotorWrite(MASTER_CANID, RIGHT_MOTOR_CANID, &un_sdo_output5, LIMIT_CUR,5); //设置最大电流为5A
|
||||
|
||||
publishMessage(&un_sdo_output1, 1);
|
||||
publishMessage(&un_sdo_output2, 1);
|
||||
publishMessage(&un_sdo_output5, 1);
|
||||
|
||||
}
|
||||
switch(turnable_data.turnable_state)//先发送切换模式以及电机失能,后面直接使能 最后发送数据
|
||||
{
|
||||
case 0:
|
||||
timerStart(&turnable_data.turnable_timer, 3000, 1); // 启动定时器,1s
|
||||
turnable_data.turnable_state = 1;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
if (!turnable_data.turnable_timer.active)// 1s定时
|
||||
{
|
||||
turnable_data.turnable_state = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
turnable_data.turnable_state = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
case 3:
|
||||
if(turnable_data.turnable_cnt >= 5)//发送5次
|
||||
{
|
||||
turnable_data.turnable_cnt = 0;
|
||||
turnable_data.turnable_state = 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
turnable_data.turnable_cnt ++;
|
||||
turnable_data.turnable_state = 3;
|
||||
|
||||
motorEnable(MASTER_CANID, PITCH_MOTOR_CANID, &un_sdo_output1);
|
||||
motorEnable(MASTER_CANID, RIGHT_MOTOR_CANID, &un_sdo_output2);
|
||||
|
||||
publishMessage(&un_sdo_output1, 1);
|
||||
publishMessage(&un_sdo_output2, 1);
|
||||
}
|
||||
break;
|
||||
|
||||
case 4:
|
||||
turnable_data.turnable_cnt = 0;
|
||||
turnable_data.turnable_state = 4;
|
||||
|
||||
setTurnableMotorOutput();//输出函数
|
||||
break;
|
||||
|
||||
default:break;
|
||||
}
|
||||
case 2://模式设置
|
||||
if(turnable_data.turnable_cnt >= 5)//发送5次
|
||||
{
|
||||
turnable_data.turnable_cnt = 0;
|
||||
turnable_data.turnable_state = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
turnable_data.turnable_cnt ++;
|
||||
turnable_data.turnable_state = 2;
|
||||
|
||||
setMotorMode(MASTER_CANID, PITCH_MOTOR_CANID, &un_sdo_output1, POSITION_MODE_CSP);
|
||||
setMotorMode(MASTER_CANID, RIGHT_MOTOR_CANID, &un_sdo_output2, CURRENT_MODE);
|
||||
setMotorMode(MASTER_CANID, TURN_MOTOR_CANID, &un_sdo_output3, CURRENT_MODE);
|
||||
|
||||
publishMessage(&un_sdo_output1, 1);
|
||||
publishMessage(&un_sdo_output2, 1);
|
||||
publishMessage(&un_sdo_output3, 1);
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
case 3:
|
||||
if(turnable_data.turnable_cnt >= 5)//发送5次
|
||||
{
|
||||
turnable_data.turnable_cnt = 0;
|
||||
turnable_data.turnable_state = 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
turnable_data.turnable_cnt ++;
|
||||
turnable_data.turnable_state = 3;
|
||||
|
||||
motorEnable(MASTER_CANID, PITCH_MOTOR_CANID, &un_sdo_output1);
|
||||
motorEnable(MASTER_CANID, RIGHT_MOTOR_CANID, &un_sdo_output2);
|
||||
motorEnable(MASTER_CANID, TURN_MOTOR_CANID, &un_sdo_output3);
|
||||
|
||||
publishMessage(&un_sdo_output1, 1);
|
||||
publishMessage(&un_sdo_output2, 1);
|
||||
publishMessage(&un_sdo_output3, 1);
|
||||
}
|
||||
break;
|
||||
|
||||
case 4:
|
||||
turnable_data.turnable_cnt = 0;
|
||||
turnable_data.turnable_state = 4;
|
||||
setTurnableMotorOutput();//输出函数
|
||||
break;
|
||||
|
||||
default:break;
|
||||
}
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// turnable_data.turnable_cnt ++;
|
||||
// turnable_data.turnable_state = 0;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@@ -210,45 +347,51 @@ void turnableParametersInit(void *signal_id)
|
||||
{
|
||||
(void)signal_id; // 标记变量为已使用,避免编译器警告
|
||||
|
||||
if(0 == un_right_intput.rx_can_id.bits.mode_state)//判断状态是否为复位,如果复位就重新使能
|
||||
{
|
||||
motorEnable(MASTER_CANID, RIGHT_MOTOR_CANID, &un_sdo_output3);
|
||||
publishMessage(&un_sdo_output3, 1);
|
||||
}
|
||||
setPidParameters(&turnable_speed_pid,
|
||||
getParam("spd_kp"),
|
||||
getParam("spd_ki"),
|
||||
getParam("spd_kd"),
|
||||
getParam("spd_il"),
|
||||
getParam("spd_ol")
|
||||
);
|
||||
|
||||
if(0 == un_pitch_intput.rx_can_id.bits.mode_state)//判断状态是否为复位,如果复位就重新使能
|
||||
{
|
||||
motorEnable(MASTER_CANID, PITCH_MOTOR_CANID, &un_sdo_output3);
|
||||
publishMessage(&un_sdo_output3, 1);
|
||||
}
|
||||
// if(0 == un_right_intput.rx_can_id.bits.mode_state)//判断状态是否为复位,如果复位就重新使能
|
||||
// {
|
||||
// motorEnable(MASTER_CANID, RIGHT_MOTOR_CANID, &un_sdo_output5);
|
||||
// publishMessage(&un_sdo_output5, 1);
|
||||
// }
|
||||
//
|
||||
// if(0 == un_turn_intput.rx_can_id.bits.mode_state)//判断状态是否为复位,如果复位就重新使能
|
||||
// {
|
||||
// motorEnable(MASTER_CANID, TURN_MOTOR_CANID, &un_sdo_output5);
|
||||
// publishMessage(&un_sdo_output5, 1);
|
||||
// }
|
||||
//
|
||||
// if(0 == un_pitch_intput.rx_can_id.bits.mode_state)//判断状态是否为复位,如果复位就重新使能
|
||||
// {
|
||||
// motorEnable(MASTER_CANID, PITCH_MOTOR_CANID, &un_sdo_output5);
|
||||
// publishMessage(&un_sdo_output5, 1);
|
||||
// }
|
||||
|
||||
|
||||
turnable_data.desired_horizontal_speed = getParam("turn_sp");
|
||||
turnable_data.desired_pitch_speed = getParam("pit_sp");
|
||||
|
||||
turnable_data.min_pitch_postion = getParam("minYpos"); //俯仰位置最小限制值
|
||||
turnable_data.max_pitch_postion = getParam("maxYpos"); //俯仰位置最大限制值
|
||||
|
||||
printf( "turnable left A %f\n",turnable_data.out_left_motor_ampere);
|
||||
printf( "turnable right A %f\n",turnable_data.out_right_motor_ampere);
|
||||
printf( "turnable pitch A %f\n",turnable_data.out_pitch_motor_ampere);
|
||||
// printf( "desired speed %f\n",turnable_data.desired_speed);
|
||||
printf( "speed %f\n",turnable_data.speed);
|
||||
printf( "turnable state %d\n",turnable_data.turnable_state);
|
||||
printf( "turnable left %f\n",turnable_data.out_left_motor_ampere);
|
||||
printf( "turnable right %f\n",turnable_data.out_right_motor_ampere);
|
||||
printf( "turnable pitch %f\n",turnable_data.out_pitch_motor_ampere);
|
||||
printf( "turnable x_axis %d\n",un_remote_control_input.bit_data.x_axis);
|
||||
// printf( "speed %f\n",turnable_data.speed);
|
||||
// printf( "turnable state %d\n",turnable_data.turnable_state);
|
||||
|
||||
timerStart(&turnable_data.turnable_timer1,1000,1);//100ms调用一次
|
||||
timerStart(&turnable_data.turnable_timer1,1000,1);//1s调用一次
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static void dataRequest(void *signal_id)
|
||||
{
|
||||
str_magnetic_encoder.magnetic_data = ENCODER_HEADER;
|
||||
|
||||
publishMessage(&str_magnetic_encoder, 1);
|
||||
timerStart(&turnable_data.turnable_timer3,100,1);//100ms调用一次
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -266,26 +409,14 @@ static void turnableInput(void *signal_id)
|
||||
}
|
||||
else if(signal_id == &un_computer_turnable_Input)
|
||||
{
|
||||
turnable_data.position_x = (float)( SWAP_ENDIAN_32(un_computer_turnable_Input.bit_data.position_x) );
|
||||
turnable_data.position_y = (float)( SWAP_ENDIAN_32(un_computer_turnable_Input.bit_data.position_y) );
|
||||
turnable_data.position_z = (float)( SWAP_ENDIAN_32(un_computer_turnable_Input.bit_data.position_z) );
|
||||
}
|
||||
else if(signal_id == &un_encoder_data_input)
|
||||
{
|
||||
if( un_encoder_data_input.arr[sizeof(un_encoder_data_input)-1] == encoder_calculate_crc(&un_encoder_data_input.arr[0], sizeof(un_encoder_data_input)-1) )//CRC校验
|
||||
{
|
||||
turnable_data.horizontal_position = (float)(un_encoder_data_input.bit_data.abs_value)*2.0f*PI/ENCODER_MAX_COUNTS;//将数据转换为实际角度
|
||||
}
|
||||
turnable_data.desired_speed = (float)( SWAP_ENDIAN_32(un_computer_turnable_Input.bit_data.position_x) );
|
||||
}
|
||||
else if ( (signal_id == &un_remote_control_input) && (1 == un_remote_control_input.bit_data.enable) )// 遥控器断线,不更新数据
|
||||
{
|
||||
// diff_data.remote_emergency_stop = !(uint8_t)un_remote_control_input.bit_data.switch_b;
|
||||
// diff_data.mode = un_remote_control_input.bit_data.switch_c =
|
||||
|
||||
float x_axis_temp = (float)(un_remote_control_input.bit_data.x_axis) - REMOTE_ZERO;
|
||||
if( ( x_axis_temp > 50 ) || ( x_axis_temp < -50 ) )
|
||||
{
|
||||
turnable_data.out_left_motor_ampere = 0.02*(x_axis_temp);//计算电流
|
||||
turnable_data.out_left_motor_ampere = 0.01*(x_axis_temp);//计算电流
|
||||
turnable_data.out_right_motor_ampere = turnable_data.out_left_motor_ampere;
|
||||
}
|
||||
else
|
||||
@@ -297,29 +428,26 @@ static void turnableInput(void *signal_id)
|
||||
x_axis_temp = (float)(un_remote_control_input.bit_data.y_axis) - REMOTE_ZERO;
|
||||
if(x_axis_temp > 50) //根据Y轴数据来定义
|
||||
{
|
||||
turnable_data.out_pitch_motor_ampere = 0.01*fabs(x_axis_temp);
|
||||
turnable_data.out_pitch_motor_ampere = 0.02*fabs(x_axis_temp);
|
||||
turnable_data.desired_pitch_position = turnable_data.max_pitch_postion;
|
||||
}
|
||||
else if(x_axis_temp < -50)
|
||||
{
|
||||
turnable_data.out_pitch_motor_ampere = 0.01*fabs(x_axis_temp);
|
||||
turnable_data.out_pitch_motor_ampere = 0.02*fabs(x_axis_temp);
|
||||
turnable_data.desired_pitch_position = turnable_data.min_pitch_postion;
|
||||
}
|
||||
else
|
||||
{
|
||||
turnable_data.out_pitch_motor_ampere = 0;
|
||||
}
|
||||
}
|
||||
else if(signal_id == &un_pitch_intput)
|
||||
{
|
||||
turnable_data.pitch_position = convertPhysical( SWAP_ENDIAN_16(un_right_intput.rx_can_data.bit_data.current_angle),-RS02_ANGULAR_VELOCITY_MAX,RS02_ANGULAR_VELOCITY_MAX,MOTOR_ANGLE_DEADZONE );
|
||||
}
|
||||
else{}
|
||||
}
|
||||
}
|
||||
else{}
|
||||
|
||||
turnable_data.right_motor_speed = convertPhysical( SWAP_ENDIAN_16(un_right_intput.rx_can_data.bit_data.current_velocity),-RS02_ANGULAR_VELOCITY_MAX,RS02_ANGULAR_VELOCITY_MAX,MOTOR_VELOCITY_DEADZONE );
|
||||
turnable_data.right_motor_speed = convertPhysical( SWAP_ENDIAN_16(un_right_intput.rx_can_data.bit_data.current_velocity),ANGULAR_VELOCITY_MIN,ANGULAR_VELOCITY_MAX,MOTOR_VELOCITY_DEADZONE );
|
||||
turnable_data.left_motor_speed = convertPhysical( SWAP_ENDIAN_16(un_turn_intput.rx_can_data.bit_data.current_velocity) ,ANGULAR_VELOCITY_MIN,ANGULAR_VELOCITY_MAX, MOTOR_VELOCITY_DEADZONE );
|
||||
turnable_data.speed = (turnable_data.right_motor_speed + turnable_data.left_motor_speed)/2.0f;
|
||||
|
||||
|
||||
// 发布左右电机期望转速,电源在工作状态才能发送
|
||||
if ( (power_data.current_state == POWER_STANDBY) || (power_data.current_state == POWER_SLEEP) )//这几种状态可以转转台
|
||||
{
|
||||
turnable_data.turnable_state = 0;//清空状态。保证每次上电都初始化
|
||||
@@ -327,9 +455,7 @@ static void turnableInput(void *signal_id)
|
||||
else
|
||||
{
|
||||
turnableProcess(signal_id);//处理映射
|
||||
}
|
||||
|
||||
// timerStart(&turnable_data.turnable_timer2,100,1);//100ms调用一次
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -338,49 +464,33 @@ void turnableInit()
|
||||
// 初始化速度 PID 控制器
|
||||
initializePid(&turnable_speed_pid, PID_MODE_DERIVATIVE_CALC, 0.0001f);
|
||||
|
||||
// // 设置速度 PID 控制器的参数
|
||||
// setPidParameters(&turnable_speed_pid,
|
||||
// getParam("spd_kp"),
|
||||
// getParam("spd_ki"),
|
||||
// getParam("spd_kd"),
|
||||
// getParam("spd_il"),
|
||||
// getParam("spd_ol")
|
||||
// );
|
||||
// 设置速度 PID 控制器的参数
|
||||
setPidParameters(&turnable_speed_pid,
|
||||
getParam("spd_kp"),
|
||||
getParam("spd_ki"),
|
||||
getParam("spd_kd"),
|
||||
getParam("spd_il"),
|
||||
getParam("spd_ol")
|
||||
);
|
||||
|
||||
//目标参数初始化
|
||||
str_magnetic_encoder.ip[0] = 192;
|
||||
str_magnetic_encoder.ip[1] = 168;
|
||||
str_magnetic_encoder.ip[2] = 17;
|
||||
str_magnetic_encoder.ip[3] = 33;
|
||||
str_magnetic_encoder.port = 2011;
|
||||
|
||||
subscribe(&un_remote_control_input, turnableInput);
|
||||
subscribe(&un_computer_turnable_Input, turnableInput);
|
||||
subscribe(&un_pitch_intput, turnableInput);
|
||||
subscribe(&un_remote_control_input, turnableInput);
|
||||
|
||||
timerInit(&turnable_data.turnable_timer);
|
||||
timerInit(&turnable_data.turnable_timer1);
|
||||
|
||||
// timerInit(&turnable_data.turnable_timer2);
|
||||
// subscribe(&turnable_data.turnable_timer2, turnableInput);
|
||||
//
|
||||
// timerStart(&turnable_data.turnable_timer2,100,1);//100ms调用一次
|
||||
|
||||
subscribe(&turnable_data.turnable_timer1, turnableParametersInit);
|
||||
timerStart(&turnable_data.turnable_timer1,1000,1);//100ms调用一次
|
||||
|
||||
timerInit(&turnable_data.turnable_timer3);
|
||||
subscribe(&turnable_data.turnable_timer3, dataRequest);
|
||||
timerStart(&turnable_data.turnable_timer3,100,1);//100ms调用一次
|
||||
|
||||
subscribe(&un_encoder_data_input, turnableInput);
|
||||
|
||||
|
||||
turnable_data.turnable_state = 0;
|
||||
un_right_intput.rx_can_data.bit_data.current_velocity = ZERO_VAULE;
|
||||
un_right_intput.rx_can_data.bit_data.current_angle = ZERO_VAULE;
|
||||
un_right_intput.rx_can_data.bit_data.current_torque = ZERO_VAULE;
|
||||
|
||||
|
||||
un_turn_intput.rx_can_data.bit_data.current_velocity = ZERO_VAULE;
|
||||
un_turn_intput.rx_can_data.bit_data.current_angle = ZERO_VAULE;
|
||||
un_turn_intput.rx_can_data.bit_data.current_torque = ZERO_VAULE;
|
||||
|
||||
un_pitch_intput.rx_can_data.bit_data.current_velocity = ZERO_VAULE;
|
||||
un_pitch_intput.rx_can_data.bit_data.current_angle = ZERO_VAULE;
|
||||
|
||||
@@ -8,88 +8,105 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//编码器协议头
|
||||
#define MASTER_CANID 0xFD
|
||||
|
||||
#define ENCODER_HEADER 0x1A
|
||||
#define ENCODER_MAX_COUNTS 0x1FFFFF// 最大位21位
|
||||
|
||||
#define ENCODER_PORT 2011
|
||||
|
||||
|
||||
//转台电机
|
||||
#define PITCH_MOTOR_CANID 0x7D
|
||||
#define RIGHT_MOTOR_CANID 0x7E
|
||||
#define TURN_MOTOR_CANID 0x7F
|
||||
|
||||
#define TURN_MOTOR_CANID 0x7F
|
||||
|
||||
#define PITCH_MOTOR_RxCANID (0x20000FD + (PITCH_MOTOR_CANID << 8)) // 0x2007DFD
|
||||
#define RIGHT_MOTOR_RxCANID (0x20000FD + (RIGHT_MOTOR_CANID << 8)) // 0x2007EFD
|
||||
#define TURN_MOTOR_RxCANID (0x20000FD + (TURN_MOTOR_CANID << 8)) // 0x2007FFD
|
||||
|
||||
#define MOTOR_RxCAN_Mask 0x1F00FFFF //<2F><><EFBFBD><EFBFBD>CAN<41><4E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD>λ
|
||||
|
||||
#define LIMIT_SPEED_INDEX 0x7017//CSP<53><50><EFBFBD>ٶ<EFBFBD>
|
||||
#define LOC_REF_INDEX 0x7016//CSP<53><50>λ<EFBFBD><CEBB>
|
||||
#define IQ_REF_INDEX 0x7006//<2F><><EFBFBD><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
// 力矩量程定义 (对应Byte4~5: 当前力矩)
|
||||
#define TORQUE_MIN -120.0f // 最小力矩: -120 Nm
|
||||
#define TORQUE_MAX 120.0f // 最大力矩: 120 Nm
|
||||
#define RUM_MODE 0x7005//modeģʽ
|
||||
|
||||
#define OPERATION_MODE 0 // <20>˿<EFBFBD>ģʽ
|
||||
#define POSITION_MODE_PP 1 // λ<><CEBB>ģʽ (PP - Profile Position)
|
||||
#define VELOCITY_MODE 2 // <20>ٶ<EFBFBD>ģʽ
|
||||
#define CURRENT_MODE 3 // <20><><EFBFBD><EFBFBD>ģʽ
|
||||
#define POSITION_MODE_CSP 5 // λ<><CEBB>ģʽ (CSP - Cyclic Synchronous Position)
|
||||
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD>仯<EFBFBD><E4BBAF> (A)
|
||||
#define MAX_STEP 1.0f // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>仯<EFBFBD><E4BBAF> (A)<29><><EFBFBD><EFBFBD>5A<35><41>ʼ
|
||||
#define MAX_DI_DT 1000.0f // <20><><EFBFBD><EFBFBD><EFBFBD>仯<EFBFBD><E4BBAF> (A/s)<29><><EFBFBD><EFBFBD>5000A/s<><73>ʼ
|
||||
|
||||
|
||||
// <20><>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define PI 3.14159f // <20>߾<EFBFBD><DFBE>Ȧ<EFBFBD>ֵ
|
||||
|
||||
// <20>Ƕ<EFBFBD><C7B6><EFBFBD><EFBFBD>̶<EFBFBD><CCB6><EFBFBD> (<28><>ӦByte0~1: <20><>ǰ<EFBFBD>Ƕ<EFBFBD>)
|
||||
#define ANGLE_RANGE_MIN (-4.0f * PI) // <20><>С<EFBFBD>Ƕ<EFBFBD>: -4<><34> <20><><EFBFBD><EFBFBD>
|
||||
#define ANGLE_RANGE_MAX (4.0f * PI) // <20><><EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD>: 4<><34> <20><><EFBFBD><EFBFBD>
|
||||
|
||||
// <20><><EFBFBD>ٶ<EFBFBD><D9B6><EFBFBD><EFBFBD>̶<EFBFBD><CCB6><EFBFBD> (<28><>ӦByte2~3: <20><>ǰ<EFBFBD><C7B0><EFBFBD>ٶ<EFBFBD>)
|
||||
#define ANGULAR_VELOCITY_MIN -15.0f // <20><>С<EFBFBD><D0A1><EFBFBD>ٶ<EFBFBD>: -15 rad/s
|
||||
#define ANGULAR_VELOCITY_MAX 15.0f // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>: 15 rad/s
|
||||
|
||||
|
||||
#define MOTOR_VELOCITY_DEADZONE 1.0f// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: 120 Nm
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̶<EFBFBD><CCB6><EFBFBD> (<28><>ӦByte4~5: <20><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>)
|
||||
#define TORQUE_MIN -120.0f // <20><>С<EFBFBD><D0A1><EFBFBD><EFBFBD>: -120 Nm
|
||||
#define TORQUE_MAX 120.0f // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: 120 Nm
|
||||
|
||||
#define ZERO_VAULE 0x0080 // 32768,需要高位在前
|
||||
#define ZERO_VAULE 0x0080 // 32768,<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD>ǰ
|
||||
|
||||
#define REMOTE_ZERO 1022
|
||||
#define REMOTE_ZERO 980
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
float r; // 径向距离
|
||||
float theta; // 极角(与Z轴的夹角,弧度制,范围[0, π])
|
||||
float phi; // 方位角(XY平面内与X轴的夹角,弧度制,范围[-π, π])
|
||||
} SphericalCoordinate;
|
||||
#define SWAP_ENDIAN_16(x) ((((x) & 0xFF) << 8) | (((x) >> 8) & 0xFF))
|
||||
#define SWAP_ENDIAN_32(x) (((x) << 24) | (((x) & 0xFF00) << 8) | (((x) >> 8) & 0xFF00) | ((x) >> 24))
|
||||
|
||||
|
||||
|
||||
typedef struct TurnableData
|
||||
{
|
||||
uint8_t turnable_state;
|
||||
PowerState current_state; // 当前电源状态
|
||||
PowerState current_state; // <EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD>Դ״̬
|
||||
|
||||
float position_x; //转台相对位置x
|
||||
float position_y; //转台相对位置y
|
||||
float position_z; //转台相对位置z
|
||||
float position_x; //ת̨<EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD>x
|
||||
float position_y; //ת̨<EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD>y
|
||||
float position_z; //ת̨<EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD>z
|
||||
|
||||
float desired_pitch_speed; // 期望俯仰位置
|
||||
float desired_horizontal_speed; // 期望水平位置
|
||||
float desired_pitch_position; // 期望俯仰位置
|
||||
float desired_horizontal_position; // 期望水平位置
|
||||
float desired_speed; // <20><><EFBFBD><EFBFBD>ת̨<D7AA>ٶ<EFBFBD>
|
||||
float desired_pitch_position; // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD>
|
||||
float desired_horizontal_position; // <20><><EFBFBD><EFBFBD>ˮƽλ<C6BD><CEBB>
|
||||
|
||||
float left_motor_speed; // 当前左电机速度
|
||||
float right_motor_speed; // 当前右电机速度
|
||||
float speed; // 当前转盘速度
|
||||
float pitch_position; // 当前俯仰位置
|
||||
float horizontal_position; // 当前水平位置
|
||||
float left_motor_speed; // <EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
||||
float right_motor_speed; // <EFBFBD><EFBFBD>ǰ<EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
||||
float speed; // <EFBFBD><EFBFBD>ǰת<EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
||||
float pitch_position; // <EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD>
|
||||
float horizontal_position; // <EFBFBD><EFBFBD>ǰˮƽλ<EFBFBD><EFBFBD>
|
||||
|
||||
float max_speed; // 最大速度
|
||||
float out_left_motor_ampere; // 输出左电机电流
|
||||
float out_right_motor_ampere; // 输出右电机电流
|
||||
float out_pitch_motor_ampere; // 输出右电机电流
|
||||
float max_speed; // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
||||
float out_left_motor_ampere; // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
float out_right_motor_ampere; // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
float out_pitch_motor_ampere; // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
float out_left_motor_ampere_last; // 输出左电机电流
|
||||
float out_right_motor_ampere_last; // 输出右电机电流
|
||||
float out_pitch_motor_ampere_last; // 输出右电机电流
|
||||
float out_left_motor_ampere_last; // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
float out_right_motor_ampere_last; // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
float out_pitch_motor_ampere_last; // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
float out_left_motor_ampere_limit; // 输出左电机电流限制值
|
||||
float out_right_motor_ampere_limit; // 输出右电机电流限制值
|
||||
float out_pitch_motor_ampere_limit; // 输出右电机电流限制值
|
||||
|
||||
Timer turnable_timer; // 定时器
|
||||
Timer turnable_timer1; // 定时器
|
||||
Timer turnable_timer2; // 定时器
|
||||
Timer turnable_timer3; // 定时器
|
||||
float out_left_motor_ampere_limit; // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||
float out_right_motor_ampere_limit; // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||
float out_pitch_motor_ampere_limit; // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||
|
||||
Timer turnable_timer; // <20><>ʱ<EFBFBD><CAB1>
|
||||
Timer turnable_timer1; // <20><>ʱ<EFBFBD><CAB1>
|
||||
Timer turnable_timer2; // <20><>ʱ<EFBFBD><CAB1>
|
||||
uint8_t turnable_cnt;
|
||||
|
||||
float max_ampere; // 最大电流限制
|
||||
|
||||
float min_pitch_postion; // 位置信息
|
||||
float max_pitch_postion; // 位置信息
|
||||
float min_pitch_postion; // λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
float max_pitch_postion; // λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
|
||||
float max_ampere; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
} TurnableData;
|
||||
|
||||
|
||||
|
||||
@@ -2,32 +2,22 @@
|
||||
|
||||
#include "interface_config.h"
|
||||
|
||||
StrRxCanFrame un_motor_input1 ;//电机控制器1 左前侧
|
||||
StrRxCanFrame un_motor_input2 ;//电机控制器2 右前侧
|
||||
StrRxCanFrame un_motor_input3 ;//电机控制器1 左后侧
|
||||
StrRxCanFrame un_motor_input4 ;//电机控制器2 右后侧
|
||||
|
||||
|
||||
UnMotorTempInput un_motor_temp1 ;//电机控制器1 左前侧
|
||||
UnMotorTempInput un_motor_temp2 ;//电机控制器2 右前侧
|
||||
UnMotorTempInput un_motor_temp3 ;//电机控制器3 左后侧
|
||||
UnMotorTempInput un_motor_temp4 ;//电机控制器4 右后侧
|
||||
UnMotorInput un_motor_input1 ;//电机控制器1 左前侧
|
||||
UnMotorInput un_motor_input2 ;//电机控制器2 右前侧
|
||||
UnMotorInput un_motor_input3 ;//电机控制器1 左后侧
|
||||
UnMotorInput un_motor_input4 ;//电机控制器2 右后侧
|
||||
|
||||
UnMotorTempInput un_motor_temp1 ;//电机控制器1 温度
|
||||
UnMotorTempInput un_motor_temp2 ;//电机控制器2 温度
|
||||
|
||||
|
||||
UnBmsInput un_bms_input ;//BMS接收数据
|
||||
UnTempModuleInput un_temp_module_input ;//温度采集模块
|
||||
|
||||
StrTxCanFrame un_motor_output1 ;//电机输出
|
||||
StrTxCanFrame un_motor_output2 ;//电机输出
|
||||
StrTxCanFrame un_motor_output3 ;//电机输出
|
||||
StrTxCanFrame un_motor_output4 ;//电机输出
|
||||
|
||||
StrTxCanFrame un_motor_output5 ;//电机输出
|
||||
StrTxCanFrame un_motor_output6 ;//电机输出
|
||||
StrTxCanFrame un_motor_output7 ;//电机输出
|
||||
StrTxCanFrame un_motor_output8 ;//电机输出
|
||||
|
||||
UnMotorOutput un_motor_output1 ;//电机输出
|
||||
UnMotorOutput un_motor_output2 ;//电机输出
|
||||
UnMotorOutput un_motor_output3 ;//电机输出
|
||||
UnMotorOutput un_motor_output4 ;//电机输出
|
||||
|
||||
UnInfCanKGFOutput un_inf_can_kgf_output1 ;//kgf输出
|
||||
UnInfCanKGFOutput un_inf_can_kgf_output2 ;
|
||||
@@ -37,8 +27,6 @@ UnWheelSpeedOutput un_wheel_wpeed_output ;//轮速输出
|
||||
UnRemoteControlInput un_remote_control_input ;//遥控器输入
|
||||
|
||||
UnHBridgeOutput un_h_bridge_output ;//H桥输出
|
||||
UnHBridgeOutput un_h_bridge_output1 ;//H桥输出
|
||||
|
||||
|
||||
UnGatherOutput un_gather_output ;//采集模块输出
|
||||
|
||||
@@ -46,20 +34,23 @@ UnUltrasonicInput un_ultrasonic_input1 ;//超声波传感
|
||||
|
||||
UnUltrasonicOutput un_ultrasonic_output1 ;//超声波传感器输出
|
||||
|
||||
//UnHBridgeOutput un_h_bridge_output1 ;//左太阳能板电机
|
||||
//UnHBridgeOutput un_h_bridge_output2 ;//右太阳能板电机
|
||||
//
|
||||
//UnLifterOutput un_lifter_output ;//基站升降杆输出
|
||||
|
||||
|
||||
|
||||
StrTxCanFrame un_sdo_output1 ;//电机1输出
|
||||
StrTxCanFrame un_sdo_output2 ;//电机2输出
|
||||
StrTxCanFrame un_sdo_output3 ;//电机3输出
|
||||
StrTxCanFrame un_sdo_output4 ;//电机4输出
|
||||
StrTxCanFrame un_sdo_output5 ;//电机5输出
|
||||
|
||||
|
||||
StrTxCanFrame un_sdo_output4 ;//电机3速度输出
|
||||
|
||||
StrTxCanFrame un_sdo_output5 ;//电机使能输出
|
||||
|
||||
StrRxCanFrame un_pitch_intput ;//电机输入
|
||||
StrRxCanFrame un_right_intput ;//电机输入
|
||||
|
||||
|
||||
StrRxCanFrame un_turn_intput ;//电机输入
|
||||
|
||||
|
||||
//IO口
|
||||
@@ -71,13 +62,13 @@ UnAutoComputerInput un_auto_computer_input ;//自主计算机
|
||||
UnManualComputerInput un_manual_computer_input ;//自主计算机手动数据
|
||||
UnRequestFrame un_request_frame ;//请求帧
|
||||
|
||||
UnComputerOutput un_computer_output ;//输出给自主计算机
|
||||
|
||||
UnComputerTurnableInput un_computer_turnable_Input ;//转台以太网输入
|
||||
|
||||
UnEncoderData un_encoder_data_input ;
|
||||
|
||||
StrMagneticEncoder str_magnetic_encoder ;//编码器请求
|
||||
UnComputerOutput un_computer_output ;//输出给自主计算机
|
||||
|
||||
|
||||
|
||||
|
||||
//输出给上位机
|
||||
UnVehicleInfoOutput un_vehicle_Info_output ;// 车辆信息,输出给上位机
|
||||
@@ -95,5 +86,20 @@ UnCanDebugOutput un_can_debug_output;//调试输出
|
||||
|
||||
|
||||
|
||||
|
||||
// 限制值在最小值和最大值之间
|
||||
float constrain(float value, float min_val, float max_val)
|
||||
{
|
||||
if (value < min_val)
|
||||
{
|
||||
return min_val;
|
||||
}
|
||||
else if (value > max_val)
|
||||
{
|
||||
return max_val;
|
||||
}
|
||||
else
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,14 +25,15 @@
|
||||
// 接收电机控制器输入
|
||||
typedef struct _StrMotorInput
|
||||
{
|
||||
//-----接收数据0x101或者0x201----------------------------------------------
|
||||
unsigned int speed : 16; // 转速 偏移量 -30000
|
||||
unsigned int bus_voltage : 16; // 母线电压 系数 0.1 偏移量 -3000
|
||||
unsigned int torque : 16; // 扭矩 系数 0.01 偏移量 -300 实际物理量=数据×系数+偏移量
|
||||
unsigned int fault_code : 8; // 故障码
|
||||
unsigned int heartbeat : 8; // 心跳
|
||||
//-----接收数据0x589或者0x189----------------------------------------------
|
||||
uint8_t MotCon_1Signal1 ;
|
||||
uint8_t MotCon_1Signal2 ;
|
||||
uint16_t MotCon_1Signal3 ;
|
||||
uint16_t MotCon_1Signal4 ;
|
||||
uint16_t MotCon_1Signal5 ;
|
||||
|
||||
} StrMotorInput;
|
||||
} StrMotorInput;
|
||||
|
||||
typedef union _UnMotorInput
|
||||
{
|
||||
StrMotorInput bit_data; // 使用定义的结构体变量名
|
||||
@@ -59,6 +60,14 @@ typedef union _UnCanDebugOutput
|
||||
} UnCanDebugOutput;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct _StrMotorTempInput
|
||||
{
|
||||
//-----接收数据0x103或者0x104----------------------------------------------
|
||||
@@ -78,15 +87,31 @@ typedef union _UnMotorTempInput
|
||||
uint8_t arr[sizeof(StrMotorInput)]; // 通过结构体类型确定大小
|
||||
} UnMotorTempInput;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 接收BMS输入
|
||||
typedef struct _StrBmsInput
|
||||
{
|
||||
//-----接收BMS数据----------------------------------------------
|
||||
uint16_t bus_voltage; // 总电压 系数 0.1V/bit
|
||||
uint16_t bus_current; // 电流 系数 0.1A/bit 偏移量 -30000
|
||||
uint16_t soc; // SOC 系数 0.1%/bit
|
||||
uint8_t Life; // 生命周期 范围 0~255
|
||||
uint8_t Reserve; // 保留位
|
||||
//----接收0x100----------------------------------
|
||||
// 多字节数据,高位在前,低位在后
|
||||
unsigned int bus_voltage : 16; // 母线电压 单位为10mV
|
||||
unsigned int bus_current : 16; // 母线电流 单位为10mA
|
||||
unsigned int remainder_capacity : 16; // 剩余容量 单位为10mAh 充电为正,放电为负
|
||||
unsigned int crc1 : 16; //crc
|
||||
//----接收0x101----------------------------------
|
||||
// 多字节数据,高位在前,低位在后
|
||||
unsigned int full_capacity : 16; // 充满容量 单位为10mAh
|
||||
unsigned int Discharge_times : 16; // 放电循环次数 单位为1次
|
||||
unsigned int soc : 16; // soc 1%
|
||||
unsigned int crc2 : 16; //crc
|
||||
} StrBmsInput;
|
||||
|
||||
typedef union _UnBmsInput
|
||||
@@ -145,6 +170,9 @@ typedef union _UnAutoComputerInput
|
||||
} UnAutoComputerInput;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 接收自主计算机手动输入
|
||||
|
||||
typedef struct _StrManualComputerInput
|
||||
@@ -163,9 +191,38 @@ typedef struct _StrManualComputerInput
|
||||
typedef union _UnManualComputerInput
|
||||
{
|
||||
StrManualComputerInput bit_data; // 使用定义的结构体变量名
|
||||
unsigned int arr[sizeof(StrManualComputerInput) / sizeof(unsigned int)]; // 通过结构体类型确定大小
|
||||
uint8_t arr[sizeof(StrManualComputerInput)]; // 通过结构体类型确定大小
|
||||
} UnManualComputerInput;
|
||||
|
||||
|
||||
// 接收转台指令输入
|
||||
typedef struct _StrComputerTurnableInput
|
||||
{
|
||||
// 多字节数据,高位在前,低位在后
|
||||
unsigned int frame_header : 16; // 帧头 固定值0xFFCC
|
||||
unsigned int frame_type : 16; // 帧类型 固定值0x0001
|
||||
unsigned int frame_length : 8; // 帧长 固定值0x19
|
||||
unsigned int heartbeat : 8; // 心跳 按帧累加
|
||||
|
||||
// --- 坐标数据部分 ---
|
||||
int32_t position_x; // X轴坐标
|
||||
int32_t position_y; // Y轴坐标
|
||||
int32_t position_z; // Z轴坐标
|
||||
|
||||
unsigned int crc : 8; // CRC 按字节累加之和,溢出取低8位
|
||||
} StrComputerTurnableInput;
|
||||
|
||||
typedef union _UnComputerTurnableInput
|
||||
{
|
||||
StrComputerTurnableInput bit_data; // 使用定义的结构体变量名
|
||||
uint8_t arr[sizeof(StrComputerTurnableInput)]; // 通过结构体类型确定大小
|
||||
} UnComputerTurnableInput;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 接收请求帧
|
||||
typedef struct _StrRequestFrame
|
||||
{
|
||||
@@ -214,14 +271,6 @@ typedef union _UnRemoteControlInput
|
||||
uint8_t arr[sizeof(StrRemoteControlInput)]; // 通过结构体类型确定大小
|
||||
} UnRemoteControlInput;
|
||||
|
||||
// 磁编
|
||||
typedef struct _StrMagneticEncoder
|
||||
{
|
||||
uint8_t ip[4]; // IPv4
|
||||
uint16_t port; // 端口
|
||||
uint8_t magnetic_data; // 协议类型(1A)
|
||||
} StrMagneticEncoder;
|
||||
|
||||
|
||||
//-----IO口---------------------------------------------------------------
|
||||
// 从IO口输入
|
||||
@@ -291,18 +340,19 @@ typedef union _UnSwSample
|
||||
// 输出到电机控制器
|
||||
typedef struct _StrMotorOutput
|
||||
{
|
||||
//-----发送数据0x201或者0x202----------------------------------------------
|
||||
unsigned int mode : 8; // 模式 0x1恒速模式,0x2恒扭模式,其他无效
|
||||
unsigned int gear : 8; // 档位 0x0空挡模式,0x1前进挡,0x2倒退档,其他无效
|
||||
unsigned int set_torque : 16; // 给定扭矩 系数 0.01 偏移量 -300 实际物理量=数据×系数+偏移量
|
||||
unsigned int set_rotation_speed : 16; // 给定转速 偏移量 -30000
|
||||
unsigned int fault_code : 8; // 故障码
|
||||
unsigned int heartbeat : 8; // 心跳
|
||||
//-----发送数据0x401或者0x402----------------------------------------------
|
||||
unsigned int feed_power : 16; // 馈电功率 单位为 W 最大为10KW
|
||||
unsigned int discharge_power : 16; // 放电功率 单位为 W 最大为15kW
|
||||
unsigned int reserve1 : 16; // 保留
|
||||
unsigned int reserve2 : 16; // 保留
|
||||
//-----发送数据0x609或者0x209----------------------------------------------
|
||||
uint8_t MotCon_1Signal1 ;
|
||||
uint8_t MotCon_1Signal2 ;
|
||||
uint16_t MotCon_1Signal3 ;
|
||||
uint16_t MotCon_1Signal4 ;
|
||||
uint16_t MotCon_1Signal5 ;
|
||||
//-----接收数据0x589或者0x189----------------------------------------------
|
||||
uint8_t MotCon_1Signal6 ;
|
||||
uint8_t MotCon_1Signal7 ;
|
||||
uint16_t MotCon_1Signal8 ;
|
||||
uint16_t MotCon_1Signal9 ;
|
||||
uint16_t MotCon_1Signal10 ;
|
||||
|
||||
} StrMotorOutput;
|
||||
|
||||
typedef union _UnMotorOutput
|
||||
@@ -335,26 +385,172 @@ typedef union _UnGatherOutput
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// canoe协议输出
|
||||
typedef struct _StrSdoOutput
|
||||
// CAN ID 解析(联合体形式,支持位域和32位直接访问)
|
||||
typedef union _UnCanIdInfo
|
||||
{
|
||||
//-----发送数据0x601----------------------------------------------
|
||||
unsigned int cmd : 8; // 命令
|
||||
unsigned int object_index : 16; // 索引
|
||||
unsigned int sub_index : 8; // 从索引
|
||||
unsigned int data : 32; // 数据
|
||||
} StrSdoOutput;
|
||||
uint32_t raw; // 32位整型,直接读写整个CAN ID
|
||||
struct
|
||||
{
|
||||
uint32_t motor_id : 8; // 0-7 bit (电机ID)
|
||||
uint32_t data : 16; // 8-23 bit (数据字段)
|
||||
uint32_t mode : 5; // 24-28 bit (模式)
|
||||
uint32_t res : 3; // 29-31 bit (保留位)
|
||||
} bits;
|
||||
|
||||
typedef union _UnSdoOutput
|
||||
} UnCanIdInfo;
|
||||
|
||||
|
||||
// 输出can数据
|
||||
typedef struct _StrTxCanOutput
|
||||
{
|
||||
StrSdoOutput bit_data; // 使用定义的结构体变量名
|
||||
uint8_t arr[sizeof(StrSdoOutput)]; // 通过结构体类型确定大小
|
||||
} UnSdoOutput;
|
||||
uint16_t index; // 索引(类似寄存器地址)
|
||||
uint16_t object_index; // 子索引(通常为0x0000)
|
||||
uint32_t data; // 数据字段
|
||||
} StrTxCanOutput;
|
||||
|
||||
|
||||
// CAN数据区联合体 (8字节,严格遵循图片协议,大端序数据)
|
||||
typedef union _UnTxCanData {
|
||||
StrTxCanOutput bit_data; // 结构化访问
|
||||
uint8_t arr[sizeof(StrTxCanOutput)]; // 字节数组形式(用于原始数据读写)
|
||||
} UnTxCanData;
|
||||
|
||||
|
||||
// 接收CAN帧结构体
|
||||
typedef struct _StrTxCanFrame
|
||||
{
|
||||
UnCanIdInfo tx_can_id; // 接收到的29位CAN ID
|
||||
UnTxCanData tx_can_data; // 接收到的8字节数据区
|
||||
} StrTxCanFrame;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//// CAN ID 解析(联合体形式,支持位域和32位直接访问)
|
||||
//typedef union _UnCanIdInfo
|
||||
//{
|
||||
// struct
|
||||
// {
|
||||
// uint32_t motor_id : 8; // 0-7 bit (电机ID)
|
||||
// uint32_t data : 16; // 8-23 bit (数据字段)
|
||||
// uint32_t mode : 5; // 24-28 bit (模式)
|
||||
// uint32_t res : 3; // 29-31 bit (保留位)
|
||||
// } bits;
|
||||
// uint32_t raw; // 32位整型,直接读写整个CAN ID
|
||||
//} UnCanIdInfo;
|
||||
//
|
||||
//// CANoe协议输出(主结构体)
|
||||
//typedef struct _StrSdoOutput
|
||||
//{
|
||||
// uint16_t index; // 索引(类似寄存器地址)
|
||||
// uint16_t object_index; // 子索引(通常为0x0000)
|
||||
// uint32_t data; // 数据字段
|
||||
// UnCanIdInfo rx_can_id; // CAN ID(联合体形式)
|
||||
//} StrSdoOutput;
|
||||
//
|
||||
//// 主联合体(支持结构体和字节数组访问)
|
||||
//typedef union _UnSdoOutput
|
||||
//{
|
||||
// StrSdoIntput bit_data; // 结构化访问
|
||||
// uint8_t arr[sizeof(StrSdoIntput)]; // 字节数组形式(用于原始数据读写)
|
||||
//} UnSdoIntput;
|
||||
|
||||
|
||||
|
||||
|
||||
// CAN ID 解析联合体 (29位扩展帧,严格遵循图片协议,小端序适配)
|
||||
typedef union _UnRxCanIdInfo {
|
||||
uint32_t raw; // 完整的32位值
|
||||
|
||||
struct {
|
||||
// 注意:小端序下,位域布局从低位到高位(Bit0到Bit31)
|
||||
// 编译器通常从低位开始分配位域
|
||||
|
||||
// 主机CAN_ID (Bit7~Bit0) - 8位 - 最低字节
|
||||
uint32_t host_id : 8; // Bit7~0: 主机CAN_ID
|
||||
|
||||
// 电机状态与故障信息域 (Bit23~Bit8) - 16位
|
||||
uint32_t motor_can_id : 8; // Bit15~8: 当前电机CAN ID
|
||||
uint32_t undervoltage : 1; // Bit16: 欠压故障 (0无1有)
|
||||
uint32_t overcurrent : 1; // Bit17: 过流 (0无1有)
|
||||
uint32_t overtemperature : 1; // Bit18: 过温 (0无1有)
|
||||
uint32_t mag_encoder_fault : 1; // Bit19: 磁编码故障 (0无1有)
|
||||
uint32_t hall_fault : 1; // Bit20: HALL编码故障 (0无1有)
|
||||
uint32_t uncalibrated : 1; // Bit21: 未标定 (0无1有)
|
||||
uint32_t mode_state : 2; // Bit23~22: 模式状态 (0:Reset,1:Cali,2:Motor)
|
||||
|
||||
// 协议标识 (Bit28~Bit24) - 5位
|
||||
uint32_t protocol_id : 5; // Bit28~24: 协议标识(图中为2)
|
||||
|
||||
// 保留位 (Bit31~29) - 3位(图片中未使用)
|
||||
uint32_t reserved : 3; // Bit31~29: 保留位,应设置为0
|
||||
} bits;
|
||||
} UnRxCanIdInfo;
|
||||
|
||||
// 输出can数据
|
||||
typedef struct _StrRxCanOutput
|
||||
{
|
||||
uint16_t current_angle; // Byte0~1: 当前角度 [0~65535]对应(-4π~4π)
|
||||
uint16_t current_velocity; // Byte2~3: 当前角速度 [0~65535]对应(-15rad/s~15rad/s)
|
||||
uint16_t current_torque; // Byte4~5: 当前力矩 [0~65535]对应(-120Nm~120Nm)
|
||||
uint16_t temperature; // Byte6~7: 当前温度: Temp(摄氏度)*10
|
||||
} StrRxCanOutput;
|
||||
|
||||
// CAN数据区联合体 (8字节,严格遵循图片协议,大端序数据)
|
||||
typedef union _UnRxCanData
|
||||
{
|
||||
StrRxCanOutput bit_data; // 结构化访问
|
||||
uint8_t arr[sizeof(StrRxCanOutput)]; // 字节数组形式(用于原始数据读写)
|
||||
} UnRxCanData;
|
||||
|
||||
// 接收CAN帧结构体
|
||||
typedef struct _StrRxCanFrame
|
||||
{
|
||||
UnRxCanIdInfo rx_can_id; // 接收到的29位CAN ID
|
||||
UnRxCanData rx_can_data; // 接收到的8字节数据区
|
||||
} StrRxCanFrame;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//// ID 解析输出
|
||||
//typedef struct _StrCanIdInfo
|
||||
//{
|
||||
////-----发送数据0x601----------------------------------------------
|
||||
// uint32_t motor_id:8;
|
||||
// uint32_t data:16;
|
||||
// uint32_t mode:5;
|
||||
// uint32_t res:3;
|
||||
//} StrCanIdInfo;
|
||||
//
|
||||
//
|
||||
//
|
||||
//// canoe协议输出
|
||||
//typedef struct _StrSdoOutput
|
||||
//{
|
||||
////-----发送数据0x601----------------------------------------------
|
||||
// uint16_t index; //索引,类似寄存器地址
|
||||
// uint16_t object_index; // 从索引 为0x0000
|
||||
// uint32_t data; // 数据
|
||||
// StrCanIdInfo rx_can_id;
|
||||
//} StrSdoOutput;
|
||||
//
|
||||
//typedef union _UnSdoOutput
|
||||
//{
|
||||
// StrSdoOutput bit_data; // 使用定义的结构体变量名
|
||||
// uint8_t arr[sizeof(StrSdoOutput)]; // 通过结构体类型确定大小
|
||||
//} UnSdoOutput;
|
||||
|
||||
|
||||
// 超声波数据发送
|
||||
typedef struct _StrUltrasonicOutput
|
||||
@@ -642,103 +838,6 @@ typedef union _UnrLifterOutput
|
||||
} UnLifterOutput;
|
||||
|
||||
|
||||
// CAN ID 解析(联合体形式,支持位域和32位直接访问)
|
||||
typedef union _UnCanIdInfo
|
||||
{
|
||||
uint32_t raw; // 32位整型,直接读写整个CAN ID
|
||||
struct
|
||||
{
|
||||
uint32_t motor_id : 8; // 0-7 bit (电机ID)
|
||||
uint32_t data : 16; // 8-23 bit (数据字段)
|
||||
uint32_t mode : 5; // 24-28 bit (模式)
|
||||
uint32_t res : 3; // 29-31 bit (保留位)
|
||||
} bits;
|
||||
|
||||
} UnCanIdInfo;
|
||||
|
||||
|
||||
// 输出can数据
|
||||
typedef struct _StrTxCanOutput
|
||||
{
|
||||
uint16_t index; // 索引(类似寄存器地址)
|
||||
uint16_t object_index; // 子索引(通常为0x0000)
|
||||
uint32_t data; // 数据字段
|
||||
} StrTxCanOutput;
|
||||
|
||||
|
||||
// CAN数据区联合体 (8字节,严格遵循图片协议,大端序数据)
|
||||
typedef union _UnTxCanData {
|
||||
StrTxCanOutput bit_data; // 结构化访问
|
||||
uint8_t arr[sizeof(StrTxCanOutput)]; // 字节数组形式(用于原始数据读写)
|
||||
} UnTxCanData;
|
||||
|
||||
|
||||
// 接收CAN帧结构体
|
||||
typedef struct _StrTxCanFrame
|
||||
{
|
||||
UnCanIdInfo tx_can_id; // 接收到的29位CAN ID
|
||||
UnTxCanData tx_can_data; // 接收到的8字节数据区
|
||||
} StrTxCanFrame;
|
||||
|
||||
|
||||
|
||||
// CAN ID 解析联合体 (29位扩展帧,严格遵循图片协议,小端序适配)
|
||||
typedef union _UnRxCanIdInfo {
|
||||
uint32_t raw; // 完整的32位值
|
||||
|
||||
struct {
|
||||
// 注意:小端序下,位域布局从低位到高位(Bit0到Bit31)
|
||||
// 编译器通常从低位开始分配位域
|
||||
|
||||
// 主机CAN_ID (Bit7~Bit0) - 8位 - 最低字节
|
||||
uint32_t host_id : 8; // Bit7~0: 主机CAN_ID
|
||||
|
||||
// 电机状态与故障信息域 (Bit23~Bit8) - 16位
|
||||
uint32_t motor_can_id : 8; // Bit15~8: 当前电机CAN ID
|
||||
uint32_t undervoltage : 1; // Bit16: 欠压故障 (0无1有)
|
||||
uint32_t overcurrent : 1; // Bit17: 过流 (0无1有)
|
||||
uint32_t overtemperature : 1; // Bit18: 过温 (0无1有)
|
||||
uint32_t mag_encoder_fault : 1; // Bit19: 磁编码故障 (0无1有)
|
||||
uint32_t hall_fault : 1; // Bit20: HALL编码故障 (0无1有)
|
||||
uint32_t uncalibrated : 1; // Bit21: 未标定 (0无1有)
|
||||
uint32_t mode_state : 2; // Bit23~22: 模式状态 (0:Reset,1:Cali,2:Motor)
|
||||
|
||||
// 协议标识 (Bit28~Bit24) - 5位
|
||||
uint32_t protocol_id : 5; // Bit28~24: 协议标识(图中为2)
|
||||
|
||||
// 保留位 (Bit31~29) - 3位(图片中未使用)
|
||||
uint32_t reserved : 3; // Bit31~29: 保留位,应设置为0
|
||||
} bits;
|
||||
} UnRxCanIdInfo;
|
||||
|
||||
// 输出can数据
|
||||
typedef struct _StrRxCanOutput
|
||||
{
|
||||
uint16_t current_angle; // Byte0~1: 当前角度 [0~65535]对应(-4π~4π)
|
||||
uint16_t current_velocity; // Byte2~3: 当前角速度 [0~65535]对应(-15rad/s~15rad/s)
|
||||
uint16_t current_torque; // Byte4~5: 当前力矩 [0~65535]对应(-120Nm~120Nm)
|
||||
uint16_t temperature; // Byte6~7: 当前温度: Temp(摄氏度)*10
|
||||
} StrRxCanOutput;
|
||||
|
||||
// CAN数据区联合体 (8字节,严格遵循图片协议,大端序数据)
|
||||
typedef union _UnRxCanData
|
||||
{
|
||||
StrRxCanOutput bit_data; // 结构化访问
|
||||
uint8_t arr[sizeof(StrRxCanOutput)]; // 字节数组形式(用于原始数据读写)
|
||||
} UnRxCanData;
|
||||
|
||||
// 接收CAN帧结构体
|
||||
typedef struct _StrRxCanFrame
|
||||
{
|
||||
UnRxCanIdInfo rx_can_id; // 接收到的29位CAN ID
|
||||
UnRxCanData rx_can_data; // 接收到的8字节数据区
|
||||
} StrRxCanFrame;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//-----以太网-------------------------------------------------------------
|
||||
// 输出给自主计算机
|
||||
typedef struct _StrComputerOutput
|
||||
@@ -970,57 +1069,6 @@ typedef union _UnAutoControlOutput
|
||||
} UnAutoControlOutput;
|
||||
|
||||
|
||||
// 接收转台指令输入
|
||||
typedef struct _StrComputerTurnableInput
|
||||
{
|
||||
// 多字节数据,高位在前,低位在后
|
||||
unsigned int frame_header : 16; // 帧头 固定值0xFFCC
|
||||
unsigned int frame_type : 16; // 帧类型 固定值0x0001
|
||||
unsigned int frame_length : 8; // 帧长 固定值0x19
|
||||
unsigned int heartbeat : 8; // 心跳 按帧累加
|
||||
|
||||
// --- 坐标数据部分 ---
|
||||
int32_t position_x; // X轴坐标
|
||||
int32_t position_y; // Y轴坐标
|
||||
int32_t position_z; // Z轴坐标
|
||||
|
||||
unsigned int crc : 8; // CRC 按字节累加之和,溢出取低8位
|
||||
} StrComputerTurnableInput;
|
||||
|
||||
typedef union _UnComputerTurnableInput
|
||||
{
|
||||
StrComputerTurnableInput bit_data; // 使用定义的结构体变量名
|
||||
uint8_t arr[sizeof(StrComputerTurnableInput)]; // 通过结构体类型确定大小
|
||||
} UnComputerTurnableInput;
|
||||
|
||||
|
||||
|
||||
// 编码器数据帧结构体(针对0x1A命令的响应)
|
||||
typedef struct _StrEncoderData {
|
||||
//--------------------------------------------------
|
||||
// 编码器数据帧 - 对应 0x1A 命令的响应格式(10字节)
|
||||
unsigned int cf : 8; // 命令识别符 固定值0x1A
|
||||
unsigned int sf : 8; // 编码器状态 1byte
|
||||
unsigned int abs_value : 24; // 角度数据 3byte LSB(重命名:abs_value)
|
||||
unsigned int enid : 8; // 编码器ID 1byte
|
||||
unsigned int abm : 24; // 圈数数据 3byte LSB
|
||||
unsigned int almc : 8; // 编码器故障 1byte
|
||||
unsigned int crc : 8; // CRC校验 多项式x^8+1
|
||||
} StrEncoderData;
|
||||
|
||||
// 联合体定义,便于字节数组访问
|
||||
typedef union _UnEncoderData {
|
||||
StrEncoderData bit_data; // 位域方式访问
|
||||
unsigned char arr[sizeof(StrEncoderData)]; // 字节数组方式访问
|
||||
} UnEncoderData;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1040,44 +1088,43 @@ typedef union _UnVoltageSignalOutput
|
||||
|
||||
|
||||
//外部数据结构声明
|
||||
extern StrRxCanFrame un_motor_input1 ;//电机控制器1 左侧
|
||||
extern StrRxCanFrame un_motor_input2 ;//电机控制器2 右侧
|
||||
extern StrRxCanFrame un_motor_input3 ;//电机控制器1 左后侧
|
||||
extern StrRxCanFrame un_motor_input4 ;//电机控制器2 右后侧
|
||||
|
||||
extern UnMotorInput un_motor_input1 ;//电机控制器1 左侧
|
||||
extern UnMotorInput un_motor_input2 ;//电机控制器2 右侧
|
||||
extern UnMotorInput un_motor_input3 ;//电机控制器1 左后侧
|
||||
extern UnMotorInput un_motor_input4 ;//电机控制器2 右后侧
|
||||
extern UnBmsInput un_bms_input ;//BMS接收数据
|
||||
extern UnTempModuleInput un_temp_module_input;//温度采集模块
|
||||
extern UnAutoComputerInput un_auto_computer_input;//自主计算机自动数据
|
||||
extern UnManualComputerInput un_manual_computer_input;//自主计算机手动数据
|
||||
|
||||
extern StrTxCanFrame un_sdo_output1 ;//电机1输出
|
||||
extern StrTxCanFrame un_sdo_output2 ;//电机2输出
|
||||
extern StrTxCanFrame un_sdo_output3 ;//电机3输出
|
||||
extern StrTxCanFrame un_sdo_output4 ;//电机3速度输出
|
||||
extern StrTxCanFrame un_sdo_output5 ;//电机使能输出
|
||||
|
||||
extern StrRxCanFrame un_pitch_intput ;//电机输入
|
||||
extern StrRxCanFrame un_right_intput ;//电机输入
|
||||
extern StrRxCanFrame un_turn_intput ;//电机输入
|
||||
|
||||
|
||||
extern UnUltrasonicInput un_ultrasonic_input1;//超声波传感器输入1
|
||||
|
||||
extern UnUltrasonicOutput un_ultrasonic_output1;//超声波传感器输出
|
||||
|
||||
|
||||
|
||||
extern StrTxCanFrame un_motor_output1; //电机输出
|
||||
extern StrTxCanFrame un_motor_output2; //电机输出
|
||||
extern StrTxCanFrame un_motor_output3; //电机输出
|
||||
extern StrTxCanFrame un_motor_output4; //电机输出
|
||||
|
||||
|
||||
extern StrTxCanFrame un_motor_output5 ;//电机输出
|
||||
extern StrTxCanFrame un_motor_output6 ;//电机输出
|
||||
extern StrTxCanFrame un_motor_output7 ;//电机输出
|
||||
extern StrTxCanFrame un_motor_output8 ;//电机输出
|
||||
|
||||
|
||||
extern UnMotorOutput un_motor_output1; //电机输出
|
||||
extern UnMotorOutput un_motor_output2; //电机输出
|
||||
extern UnMotorOutput un_motor_output3; //电机输出
|
||||
extern UnMotorOutput un_motor_output4; //电机输出
|
||||
extern UnMotorTempInput un_motor_temp1; //电机控制器1 温度
|
||||
extern UnMotorTempInput un_motor_temp2; //电机控制器2 温度
|
||||
extern UnMotorTempInput un_motor_temp3; //电机控制器3 左后侧
|
||||
extern UnMotorTempInput un_motor_temp4; //电机控制器4 右后侧
|
||||
|
||||
|
||||
extern UnInfCanKGFOutput un_inf_can_kgf_output1;
|
||||
extern UnInfCanKGFOutput un_inf_can_kgf_output2;
|
||||
extern UnHBridgeOutput un_h_bridge_output;
|
||||
extern UnHBridgeOutput un_h_bridge_output1;//H桥输出
|
||||
|
||||
extern UnWheelSpeedOutput un_wheel_wpeed_output;
|
||||
extern UnGatherOutput un_gather_output;//采集模块输出
|
||||
@@ -1093,12 +1140,9 @@ extern UnSwSample un_sw_sample;
|
||||
extern UnRequestFrame un_request_frame; //请求帧
|
||||
|
||||
extern UnComputerOutput un_computer_output; //输出给自主计算机
|
||||
|
||||
extern UnComputerTurnableInput un_computer_turnable_Input ;//转台以太网输入
|
||||
|
||||
extern UnEncoderData un_encoder_data_input ;
|
||||
|
||||
extern StrMagneticEncoder str_magnetic_encoder ;//编码器请求
|
||||
|
||||
//输出给上位机
|
||||
extern UnVehicleInfoOutput un_vehicle_Info_output; // 车辆信息,输出给上位机
|
||||
extern UnMotorStatusOutput un_motor_status_output; // 电机状态信息,输出给上位机
|
||||
@@ -1107,21 +1151,6 @@ extern UnAnalogSignalOutput un_analog_signal_output; // 模拟信号输
|
||||
extern UnRemoteControlOutput un_remote_control_output;// 遥控器数据输出,给上位机
|
||||
extern UnManualControlOutput un_manual_control_output;// 手动控制数据,返回给请求者
|
||||
extern UnAutoControlOutput un_auto_control_output; // 自动控制数据输出,返回给请求者
|
||||
extern UnSdoOutput un_sdo_output ;//转向电机输出
|
||||
|
||||
extern StrTxCanFrame un_sdo_output1 ;//电机1输出
|
||||
extern StrTxCanFrame un_sdo_output2 ;//电机2输出
|
||||
extern StrTxCanFrame un_sdo_output3 ;//电机3输出
|
||||
extern StrTxCanFrame un_sdo_output4 ;//电机4输出
|
||||
extern StrTxCanFrame un_sdo_output5 ;//电机5输出
|
||||
|
||||
extern StrTxCanFrame un_motor_output5 ;//电机1输出
|
||||
extern StrTxCanFrame un_motor_output6 ;//电机2输出
|
||||
extern StrTxCanFrame un_motor_output7 ;//电机3输出
|
||||
extern StrTxCanFrame un_motor_output8 ;//电机4输出
|
||||
|
||||
extern StrRxCanFrame un_pitch_intput ;//电机输入
|
||||
extern StrRxCanFrame un_right_intput ;//电机输入
|
||||
|
||||
|
||||
//变量
|
||||
@@ -1133,6 +1162,8 @@ extern UnCanDebugOutput un_can_debug_output;//调试输出
|
||||
//函数
|
||||
void canSendAll(void *signal_id);
|
||||
void ethernetSendAll(void *signal_id);
|
||||
float constrain(float value, float min_val, float max_val);
|
||||
|
||||
|
||||
#pragma pack()
|
||||
|
||||
|
||||
@@ -51,6 +51,10 @@ void bootmian(void *signal_id)
|
||||
ssdk_printf(SSDK_INFO, "go to boot!\r\n");
|
||||
wrbyte_24c02(Update_Flg_E2adr,CAN_BOOTLOADER_UPGRADE); //д<><D0B4>־<EFBFBD><D6BE><EFBFBD><EFBFBD>
|
||||
// udelay(3000);//<2F><>ʱ3ms
|
||||
wrbyte_24c02(BOOT_DES_IP, ethernet_parameter.download_ip[0]);
|
||||
wrbyte_24c02(BOOT_DES_IP+1, ethernet_parameter.download_ip[1]);
|
||||
wrbyte_24c02(BOOT_DES_IP+2, ethernet_parameter.download_ip[2]);
|
||||
wrbyte_24c02(BOOT_DES_IP+3, ethernet_parameter.download_ip[3]);
|
||||
|
||||
// sdrv_rstgen_global_reset(&rstctl_glb);
|
||||
for(;;)
|
||||
|
||||
@@ -3,17 +3,15 @@
|
||||
#include "debug.h"
|
||||
#include "interface_config.h"
|
||||
#include "app/app_config.h"
|
||||
#define TX_PADDING_VAL (0xA5)
|
||||
#include "sdrv_vic.h"
|
||||
#include "intrinsics.h"
|
||||
#include "app/app_differential_drive.h"
|
||||
#include "app/app_param_manage.h"
|
||||
#include "app/app_ultrasonic.h"
|
||||
#include "app/app_turntable.h"
|
||||
#include "drive_rs04.h"
|
||||
|
||||
|
||||
#define TX_PADDING_VAL (0xA5)
|
||||
|
||||
uint32_t OTA_CANTxID = 0x02;//Ĭ<>Ϸ<EFBFBD><CFB7><EFBFBD>IDΪ0x02
|
||||
uint32_t OTA_CANRxID = 0x01;//Ĭ<>Ͻ<EFBFBD><CFBD><EFBFBD>IDΪ0x01
|
||||
uint32_t WDT_CANRxID = 0x03;//Ĭ<>Ͻ<EFBFBD><CFBD><EFBFBD>IDΪ0x03
|
||||
@@ -43,15 +41,17 @@ UnCanFault can_fault_info = {
|
||||
|
||||
|
||||
|
||||
//
|
||||
//StrCanFifoQueue can0_Queue;//8֡can<61><6E><EFBFBD>棬<EFBFBD><E6A3AC><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD>
|
||||
//StrCanFifoQueue can1_Queue;
|
||||
//StrCanFifoQueue can2_Queue;
|
||||
//StrCanFifoQueue can3_Queue;
|
||||
//StrCanFifoQueue can4_Queue;
|
||||
//StrCanFifoQueue can5_Queue;
|
||||
//StrCanFifoQueue can6_Queue;
|
||||
//StrCanFifoQueue can7_Queue;
|
||||
|
||||
StrCanFifoQueue can0_Queue;//8֡can<61><6E><EFBFBD>棬<EFBFBD><E6A3AC><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD>
|
||||
StrCanFifoQueue can1_Queue;
|
||||
StrCanFifoQueue can2_Queue;
|
||||
StrCanFifoQueue can3_Queue;
|
||||
StrCanFifoQueue can4_Queue;
|
||||
StrCanFifoQueue can5_Queue;
|
||||
StrCanFifoQueue can6_Queue;
|
||||
StrCanFifoQueue can7_Queue;
|
||||
|
||||
|
||||
|
||||
|
||||
//bool busoff_occur_flag = false;//busoff<66><66>־
|
||||
@@ -237,7 +237,7 @@ void flexcan_Receive_callback_0(flexcan_handle_t *handle,
|
||||
|
||||
case FLEXCAN_RX_FIFO_IDLE:
|
||||
|
||||
if(TEMP_MODULE_INPUT_ID_1 == (buf->id))//<2F>¶<EFBFBD>
|
||||
if(TEMP_MODULE_INPUT_ID_1 == (buf->id))//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1
|
||||
{
|
||||
for(i = 0; i < (buf->length); i++)
|
||||
{
|
||||
@@ -282,15 +282,16 @@ void flexcan_Receive_callback_0(flexcan_handle_t *handle,
|
||||
* @return none
|
||||
*/
|
||||
|
||||
//uint32_t time_elapsed = 0;
|
||||
//uint32_t time_elapsed1 = 0;
|
||||
uint32_t time_elapsed = 0;
|
||||
uint32_t time_elapsed1 = 0;
|
||||
void flexcan_Receive_callback_1(flexcan_handle_t *handle,
|
||||
flexcan_status_e status, uint32_t result,
|
||||
void *userData)
|
||||
{
|
||||
flexcan_frame_t *buf = (flexcan_frame_t *)userData;
|
||||
|
||||
uint8_t i = 0;
|
||||
uint8_t i = 0;
|
||||
static uint32_t start_time = 0;
|
||||
//--------------------------------------------------------------
|
||||
switch (status)
|
||||
{
|
||||
@@ -298,15 +299,29 @@ void flexcan_Receive_callback_1(flexcan_handle_t *handle,
|
||||
break;
|
||||
|
||||
case FLEXCAN_RX_FIFO_IDLE:
|
||||
if( FRONT_LEFT_MOTOR_RxCANID == ( (buf->id) & MOTOR_RxCAN_Mask) )
|
||||
if(MOTOR_INPUT_ID_1 == (buf->id))//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1
|
||||
{
|
||||
un_motor_input1.rx_can_id.raw = (buf->id);
|
||||
time_elapsed = getCurrentTime() - start_time;
|
||||
start_time = getCurrentTime();
|
||||
|
||||
can_fault_info.bit_data.motor1_count ++;
|
||||
for(i = 0; i < (buf->length); i++)
|
||||
{
|
||||
un_motor_input1.rx_can_data.arr[i] = buf->dataBuffer[i];
|
||||
}
|
||||
|
||||
}
|
||||
un_motor_input1.arr[i] = buf->dataBuffer[i];
|
||||
}
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
|
||||
publishMessage(&un_motor_input1, 1);
|
||||
}
|
||||
// else if( MOTOR_INPUT_ID_3 == (buf->id) )
|
||||
// {
|
||||
// for(i = 0; i < (buf->length); i++)
|
||||
// {
|
||||
// un_motor_temp1.arr[i] = buf->dataBuffer[i];
|
||||
// }
|
||||
// //<2F><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
|
||||
// publishMessage(&un_motor_temp1, 1);//<2F><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
|
||||
// }
|
||||
else{}
|
||||
break;
|
||||
|
||||
case FLEXCAN_TX_IDLE:
|
||||
@@ -345,6 +360,7 @@ void flexcan_Receive_callback_2(flexcan_handle_t *handle,
|
||||
{
|
||||
flexcan_frame_t *buf = (flexcan_frame_t *)userData;
|
||||
uint8_t i = 0;
|
||||
static uint32_t start_time1 = 0;
|
||||
//--------------------------------------------------------------
|
||||
switch (status)
|
||||
{
|
||||
@@ -352,16 +368,29 @@ void flexcan_Receive_callback_2(flexcan_handle_t *handle,
|
||||
break;
|
||||
|
||||
case FLEXCAN_RX_FIFO_IDLE:
|
||||
if( FRONT_RIGHT_MOTOR_RxCANID == ( (buf->id) & MOTOR_RxCAN_Mask) )
|
||||
{
|
||||
un_motor_input2.rx_can_id.raw = (buf->id);
|
||||
if(MOTOR_INPUT_ID_2 == (buf->id))//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2
|
||||
{
|
||||
time_elapsed1 = getCurrentTime() - start_time1;
|
||||
start_time1 = getCurrentTime();
|
||||
|
||||
can_fault_info.bit_data.motor2_count ++;
|
||||
for(i = 0; i < (buf->length); i++)
|
||||
{
|
||||
un_motor_input2.rx_can_data.arr[i] = buf->dataBuffer[i];
|
||||
}
|
||||
|
||||
}
|
||||
else{}
|
||||
un_motor_input2.arr[i] = buf->dataBuffer[i];
|
||||
}
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
|
||||
publishMessage(&un_motor_input2, 1);
|
||||
}
|
||||
// else if( MOTOR_INPUT_ID_4 == (buf->id) )
|
||||
// {
|
||||
// for(i = 0; i < (buf->length); i++)
|
||||
// {
|
||||
// un_motor_temp2.arr[i] = buf->dataBuffer[i];
|
||||
// }
|
||||
// //<2F><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
|
||||
// publishMessage(&un_motor_temp2, 1);//<2F><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
|
||||
// }
|
||||
else{}
|
||||
break;
|
||||
|
||||
case FLEXCAN_TX_IDLE:
|
||||
@@ -407,17 +436,26 @@ void flexcan_Receive_callback_3(flexcan_handle_t *handle,
|
||||
break;
|
||||
|
||||
case FLEXCAN_RX_FIFO_IDLE:
|
||||
|
||||
if( REAR_LEFT_MOTOR_RxCANID == ( (buf->id) & MOTOR_RxCAN_Mask) )
|
||||
{
|
||||
un_motor_input3.rx_can_id.raw = (buf->id);
|
||||
|
||||
if(BMS_INPUT_ID1 == (buf->id))//BMS
|
||||
{
|
||||
can_fault_info.bit_data.bms_count ++;
|
||||
for(i = 0; i < (buf->length); i++)
|
||||
{
|
||||
un_motor_input3.rx_can_data.arr[i] = buf->dataBuffer[i];
|
||||
}
|
||||
|
||||
}
|
||||
else{}
|
||||
un_bms_input.arr[i] = buf->dataBuffer[i];
|
||||
}
|
||||
publishMessage(&un_bms_input, 1);
|
||||
}
|
||||
else if(BMS_INPUT_ID2 == (buf->id))//BMS
|
||||
{
|
||||
for(i = 0; i < (buf->length); i++)
|
||||
{
|
||||
un_bms_input.arr[i+8] = buf->dataBuffer[i];
|
||||
}
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
|
||||
publishMessage(&un_bms_input, 1);
|
||||
}
|
||||
else{}
|
||||
|
||||
break;
|
||||
|
||||
@@ -454,25 +492,13 @@ void flexcan_Receive_callback_4(flexcan_handle_t *handle,
|
||||
void *userData)
|
||||
{
|
||||
//--------------------------------------------------------------
|
||||
flexcan_frame_t *buf = (flexcan_frame_t *)userData;
|
||||
uint8_t i = 0;
|
||||
|
||||
switch (status)
|
||||
{
|
||||
case FLEXCAN_RX_IDLE:
|
||||
break;
|
||||
|
||||
case FLEXCAN_RX_FIFO_IDLE:
|
||||
if( REAR_RIGHT_MOTOR_RxCANID == ( (buf->id) & MOTOR_RxCAN_Mask) )
|
||||
{
|
||||
un_motor_input4.rx_can_id.raw = (buf->id);
|
||||
for(i = 0; i < (buf->length); i++)
|
||||
{
|
||||
un_motor_input4.rx_can_data.arr[i] = buf->dataBuffer[i];
|
||||
}
|
||||
}
|
||||
else{}
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case FLEXCAN_TX_IDLE:
|
||||
@@ -516,12 +542,33 @@ void flexcan_Receive_callback_5(flexcan_handle_t *handle,
|
||||
break;
|
||||
|
||||
case FLEXCAN_RX_FIFO_IDLE:
|
||||
for(i = 0; i < (buf->length); i++)
|
||||
{
|
||||
un_bms_input.arr[i] = buf->dataBuffer[i];
|
||||
}
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
|
||||
publishMessage(&un_bms_input, 1);
|
||||
if( PITCH_MOTOR_RxCANID == ( (buf->id) & MOTOR_RxCAN_Mask) )
|
||||
{
|
||||
un_pitch_intput.rx_can_id.raw = (buf->id);
|
||||
for(i = 0; i < (buf->length); i++)
|
||||
{
|
||||
un_pitch_intput.rx_can_data.arr[i] = buf->dataBuffer[i];
|
||||
}
|
||||
}
|
||||
else if( RIGHT_MOTOR_RxCANID == ( (buf->id) & MOTOR_RxCAN_Mask) )
|
||||
{
|
||||
un_right_intput.rx_can_id.raw = (buf->id);
|
||||
for(i = 0; i < (buf->length); i++)
|
||||
{
|
||||
un_right_intput.rx_can_data.arr[i] = buf->dataBuffer[i];
|
||||
}
|
||||
|
||||
}
|
||||
else if( TURN_MOTOR_RxCANID == ( (buf->id) & MOTOR_RxCAN_Mask) )
|
||||
{
|
||||
un_turn_intput.rx_can_id.raw = (buf->id);
|
||||
for(i = 0; i < (buf->length); i++)
|
||||
{
|
||||
un_turn_intput.rx_can_data.arr[i] = buf->dataBuffer[i];
|
||||
}
|
||||
|
||||
}
|
||||
else{}
|
||||
break;
|
||||
|
||||
case FLEXCAN_TX_IDLE:
|
||||
@@ -565,6 +612,7 @@ void flexcan_Receive_callback_6(flexcan_handle_t *handle,
|
||||
break;
|
||||
|
||||
case FLEXCAN_RX_FIFO_IDLE:
|
||||
|
||||
if(OTA_CANRxID == (buf->id))//IDΪ1<CEAA><31> boot<6F><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
boot_can_flag = true;
|
||||
@@ -586,25 +634,8 @@ void flexcan_Receive_callback_6(flexcan_handle_t *handle,
|
||||
}
|
||||
publishMessage(&un_ultrasonic_input1, 1);
|
||||
}
|
||||
else if( RIGHT_MOTOR_RxCANID == ( (buf->id) & MOTOR_RxCAN_Mask) )
|
||||
{
|
||||
un_right_intput.rx_can_id.raw = (buf->id);
|
||||
for(i = 0; i < (buf->length); i++)
|
||||
{
|
||||
un_right_intput.rx_can_data.arr[i] = buf->dataBuffer[i];
|
||||
}
|
||||
// publishMessage(&un_right_intput, 1);
|
||||
}
|
||||
else if( PITCH_MOTOR_RxCANID == ( (buf->id) & MOTOR_RxCAN_Mask) )
|
||||
{
|
||||
un_pitch_intput.rx_can_id.raw = (buf->id);
|
||||
for(i = 0; i < (buf->length); i++)
|
||||
{
|
||||
un_pitch_intput.rx_can_data.arr[i] = buf->dataBuffer[i];
|
||||
}
|
||||
// publishMessage(&un_pitch_intput, 1);
|
||||
}
|
||||
else{}
|
||||
|
||||
else{}
|
||||
break;
|
||||
|
||||
case FLEXCAN_TX_IDLE:
|
||||
@@ -660,6 +691,8 @@ void flexcan_Receive_callback_7(flexcan_handle_t *handle,
|
||||
}
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
|
||||
publishMessage(&un_remote_control_input, 1);
|
||||
|
||||
// printf("ori_remote_stop: %d\n", un_remote_control_input.bit_data.switch_b);
|
||||
}
|
||||
else if(REMOTE_ID_1 == (buf->id))
|
||||
{
|
||||
@@ -667,7 +700,7 @@ void flexcan_Receive_callback_7(flexcan_handle_t *handle,
|
||||
{
|
||||
un_remote_control_input.arr[i+8] = buf->dataBuffer[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
@@ -874,11 +907,11 @@ void initialization_All_Flexcan(void)
|
||||
{
|
||||
sdrv_gpio_set_pin_output_level(GPIO_H12, 0); //CANʹ<4E><CAB9>
|
||||
|
||||
initialization_Flexcan(CAN_INDEX_0, &can_0_config, &can_0_fifo_config, flexcan_Receive_callback_0);//1M
|
||||
initialization_Flexcan(CAN_INDEX_0, &can_0_config, &can_0_fifo_config, flexcan_Receive_callback_0);//250k
|
||||
|
||||
initialization_Flexcan(CAN_INDEX_1, &can_1_config, &can_1_fifo_config, flexcan_Receive_callback_1);//1M
|
||||
initialization_Flexcan(CAN_INDEX_1, &can_1_config, &can_1_fifo_config, flexcan_Receive_callback_1);//250k
|
||||
|
||||
initialization_Flexcan(CAN_INDEX_2, &can_2_config, &can_2_fifo_config, flexcan_Receive_callback_2);//1M
|
||||
initialization_Flexcan(CAN_INDEX_2, &can_2_config, &can_2_fifo_config, flexcan_Receive_callback_2);//250k
|
||||
|
||||
initialization_Flexcan(CAN_INDEX_3, &can_3_config, &can_3_fifo_config, flexcan_Receive_callback_3);//1M
|
||||
|
||||
@@ -1017,112 +1050,90 @@ void canTimerProcess(void *signal_id)
|
||||
}
|
||||
}
|
||||
|
||||
static void processMotorOutput1(void *signal_id)
|
||||
{
|
||||
(void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CAN_Send_Msg(&can_handle_1, un_motor_output1.tx_can_id.raw, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output1.tx_can_data.arr[0], 8, 15);//<2F><><EFBFBD><EFBFBD>1Ť<31>غ<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CAN_Send_Msg(&can_handle_3, un_motor_output3.tx_can_id.raw, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output3.tx_can_data.arr[0], 8, 16);//<2F><><EFBFBD><EFBFBD>1Ť<31>غ<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
static void processMotorOutput2(void *signal_id)
|
||||
{
|
||||
(void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CAN_Send_Msg(&can_handle_2, un_motor_output2.tx_can_id.raw, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output2.tx_can_data.arr[0], 8, 15);//<2F><><EFBFBD><EFBFBD>2Ť<32>غ<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CAN_Send_Msg(&can_handle_4, un_motor_output4.tx_can_id.raw, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output4.tx_can_data.arr[0], 8, 16);//<2F><><EFBFBD><EFBFBD>2Ť<32>غ<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
|
||||
static void processSdoOutput1(void *signal_id)
|
||||
{
|
||||
(void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CAN_Send_Msg(&can_handle_6, un_sdo_output1.tx_can_id.raw, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_sdo_output1.tx_can_data.arr[0], 8, 15);//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>1Ť<EFBFBD>غ<EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CAN_Send_Msg(&can_handle_6, un_sdo_output4.tx_can_id.raw, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_sdo_output4.tx_can_data.arr[0], 8, 16);//<2F><><EFBFBD><EFBFBD>1Ť<31>غ<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void processmotorOutput5(void *signal_id)
|
||||
{
|
||||
(void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CAN_Send_Msg(&can_handle_6, un_sdo_output5.tx_can_id.raw, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_sdo_output5.tx_can_data.arr[0], 8, 19);//<2F><><EFBFBD><EFBFBD>2Ť<32>غ<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
(void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CAN_Send_Msg(&can_handle_4, un_sdo_output1.tx_can_id.raw, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_sdo_output1.tx_can_data.arr[0], 8, 15);//
|
||||
}
|
||||
|
||||
static void processSdoOutput2(void *signal_id)
|
||||
{
|
||||
(void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CAN_Send_Msg(&can_handle_6, un_sdo_output2.tx_can_id.raw, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_sdo_output2.tx_can_data.arr[0], 8, 17);//<2F><><EFBFBD><EFBFBD>2Ť<32>غ<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
(void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CAN_Send_Msg(&can_handle_4, un_sdo_output2.tx_can_id.raw, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_sdo_output2.tx_can_data.arr[0], 8, 16);
|
||||
}
|
||||
|
||||
static void processSdoOutput3(void *signal_id)
|
||||
{
|
||||
(void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
(void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CAN_Send_Msg(&can_handle_4, un_sdo_output3.tx_can_id.raw, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_sdo_output3.tx_can_data.arr[0], 8, 17);
|
||||
}
|
||||
|
||||
switch(un_sdo_output3.tx_can_id.raw)
|
||||
{
|
||||
case RIGHT_MOTOR_CANID:
|
||||
CAN_Send_Msg(&can_handle_6, un_sdo_output3.tx_can_id.raw, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_sdo_output3.tx_can_data.arr[0], 8, 18);//<2F><><EFBFBD><EFBFBD>2Ť<32>غ<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
break;
|
||||
|
||||
case PITCH_MOTOR_CANID:
|
||||
CAN_Send_Msg(&can_handle_6, un_sdo_output3.tx_can_id.raw, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_sdo_output3.tx_can_data.arr[0], 8, 18);//<2F><><EFBFBD><EFBFBD>2Ť<32>غ<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
break;
|
||||
default:;
|
||||
}
|
||||
static void processSdoOutput4(void *signal_id)
|
||||
{
|
||||
(void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CAN_Send_Msg(&can_handle_4, un_sdo_output4.tx_can_id.raw, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_sdo_output4.tx_can_data.arr[0], 8, 18);
|
||||
}
|
||||
|
||||
static void processSdoOutput5(void *signal_id)
|
||||
{
|
||||
(void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CAN_Send_Msg(&can_handle_1, un_motor_output5.tx_can_id.raw, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output5.tx_can_data.arr[0], 8, 17);//<2F><><EFBFBD><EFBFBD>2Ť<32>غ<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
(void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CAN_Send_Msg(&can_handle_4, un_sdo_output5.tx_can_id.raw, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_sdo_output5.tx_can_data.arr[0], 8, 19);
|
||||
}
|
||||
|
||||
static void processSdoOutput6(void *signal_id)
|
||||
{
|
||||
(void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CAN_Send_Msg(&can_handle_2, un_motor_output6.tx_can_id.raw, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output6.tx_can_data.arr[0], 8, 17);//<2F><><EFBFBD><EFBFBD>2Ť<32>غ<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
|
||||
static void processSdoOutput7(void *signal_id)
|
||||
{
|
||||
(void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CAN_Send_Msg(&can_handle_3, un_motor_output7.tx_can_id.raw, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output7.tx_can_data.arr[0], 8, 17);//<2F><><EFBFBD><EFBFBD>2Ť<32>غ<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
static void processSdoOutput8(void *signal_id)
|
||||
{
|
||||
(void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CAN_Send_Msg(&can_handle_4, un_motor_output8.tx_can_id.raw, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output8.tx_can_data.arr[0], 8, 17);//<2F><><EFBFBD><EFBFBD>2Ť<32>غ<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//static void processMotorOutput3(void *signal_id)
|
||||
//{
|
||||
// (void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//
|
||||
//// CAN_Send_Msg(&can_handle_1, LEFT_FRONT_MOTOR_OUTPUT2, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output1.arr[8], 8, 17);//<2F><><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//// CAN_Send_Msg(&can_handle_1, LEFT_REAR_MOTOR_OUTPUT2, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output3.arr[8], 8, 18);//<2F><><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//
|
||||
//}
|
||||
//
|
||||
//static void processMotorOutput4(void *signal_id)
|
||||
//static void processSdoOutput4(void *signal_id)
|
||||
//{
|
||||
// (void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//// CAN_Send_Msg(&can_handle_2, RIGHT_FRONT_MOTOR_OUTPUT2, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output2.arr[8], 8, 17);//<2F><><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//// CAN_Send_Msg(&can_handle_2, RIGHT_REAR_MOTOR_OUTPUT2, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output4.arr[8], 8, 18);//<2F><><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// CAN_Send_Msg(&can_handle_3, 0x601, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_sdo_output4, 8, 18);
|
||||
//}
|
||||
//
|
||||
//static void processSdoOutput5(void *signal_id)
|
||||
//{
|
||||
// (void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// CAN_Send_Msg(&can_handle_3, 0x601, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_sdo_output5, 8, 19);
|
||||
//}
|
||||
//
|
||||
//
|
||||
//static void processSdoOutput7(void *signal_id)
|
||||
//{
|
||||
// (void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// CAN_Send_Msg(&can_handle_3, 0x601, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_sdo_output7, 8, 20);
|
||||
//}
|
||||
|
||||
|
||||
|
||||
static void processMotorOutput1(void *signal_id)
|
||||
{
|
||||
(void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
un_motor_output1.bit_data.MotCon_1Signal1 = 0x5A;
|
||||
un_motor_output1.bit_data.MotCon_1Signal2 = 0x02;
|
||||
CAN_Send_Msg(&can_handle_1, 0x609, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output1, 8, 15);//<2F><><EFBFBD><EFBFBD>1Ť<31>غ<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
static void processMotorOutput2(void *signal_id)
|
||||
{
|
||||
(void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
un_motor_output2.bit_data.MotCon_1Signal1 = 0x5A;
|
||||
un_motor_output2.bit_data.MotCon_1Signal2 = 0x02;
|
||||
CAN_Send_Msg(&can_handle_2, 0x60A, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output2, 8, 15);//<2F><><EFBFBD><EFBFBD>2Ť<32>غ<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
static void processMotorOutput3(void *signal_id)
|
||||
{
|
||||
(void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
CAN_Send_Msg(&can_handle_1, 0x209, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output1.arr[8], 8, 16);//<2F><><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
static void processMotorOutput4(void *signal_id)
|
||||
{
|
||||
(void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CAN_Send_Msg(&can_handle_2, 0x20A, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output2.arr[8], 8, 16);//<2F><><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
static void processKgfOutput1(void *signal_id)
|
||||
{
|
||||
(void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
// if(1 == ecu_online)//20250318 <20><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>߲<EFBFBD><DFB2>ܷ<EFBFBD><DCB7>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>E3ͬʱ<CDAC><CAB1><EFBFBD><EFBFBD>
|
||||
// {
|
||||
un_inf_can_kgf_output1.bit_data.can_rx5 = 0xE3;
|
||||
CAN_Send_Msg(&can_handle_0, 0x11000002, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_inf_can_kgf_output1, 8, 15);//KGF1
|
||||
// }
|
||||
CAN_Send_Msg(&can_handle_0, 0x11000002, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_inf_can_kgf_output1, 8, 15);//KGF1
|
||||
}
|
||||
|
||||
static void processKgfOutput2(void *signal_id)
|
||||
@@ -1136,6 +1147,16 @@ static void processKgfOutput2(void *signal_id)
|
||||
|
||||
}
|
||||
|
||||
//static void processKgfOutput2(void *signal_id)
|
||||
//{
|
||||
// (void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// if(1 == ecu_online)//20250318 <20><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>߲<EFBFBD><DFB2>ܷ<EFBFBD><DCB7>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>E3ͬʱ<CDAC><CAB1><EFBFBD><EFBFBD>
|
||||
// {
|
||||
// un_inf_can_kgf_output2.bit_data.can_rx5 = 0xE3;
|
||||
// CAN_Send_Msg(&can_handle_0, 0x14000002, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_inf_can_kgf_output2, 8, 16);//KGF2
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
|
||||
|
||||
@@ -1154,14 +1175,13 @@ static void processWheelSpeedOutput(void *signal_id)
|
||||
un_wheel_wpeed_output.bit_data.right_front = (uint16_t)((int16_t)(CANPressSpeedTemp));//ת<><D7AA>*1.8*60*100/1000/ ת/<2F><><EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EFBFBD>km/h һȦ1.8<EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>100<30><30><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5>Ϊ0.01<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD> 20240629 <20><><EFBFBD>ٱȲ<D9B1><C8B2><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD>
|
||||
un_wheel_wpeed_output.bit_data.right_rear = (uint16_t)((int16_t)(CANPressSpeedTemp));//<2F><>ת<EFBFBD><D7AA>Ϊint<6E><74><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD><EFBFBD><DEB7><EFBFBD>
|
||||
|
||||
CAN_Send_Msg(&can_handle_7, 0x98, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_wheel_wpeed_output, 8, 15);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CAN_Send_Msg(&can_handle_5, 0x98, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_wheel_wpeed_output, 8, 15);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
static void processHBridgeOutput(void *signal_id)
|
||||
{
|
||||
(void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CAN_Send_Msg(&can_handle_5, 0x7F2, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_h_bridge_output, 8, 17);//H<><48><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CAN_Send_Msg(&can_handle_5, 0x722, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_h_bridge_output1, 8, 19);//H<><48><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CAN_Send_Msg(&can_handle_0, 0x7F2, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_h_bridge_output, 8, 17);//H<><48><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
static void processUnGatherOutput(void *signal_id)
|
||||
@@ -1175,7 +1195,7 @@ static void processUnGatherOutput(void *signal_id)
|
||||
static void processUltrasonicOutput(void *signal_id)
|
||||
{
|
||||
(void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CAN_Send_Msg(&can_handle_6, ULTRASONIC_ID_1, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_ultrasonic_output1, 8, 15);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CAN_Send_Msg(&can_handle_6, ULTRASONIC_ID_1, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_ultrasonic_output1, 8, 18);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
//static void processHBridgeOutput2(void *signal_id)
|
||||
@@ -1198,11 +1218,11 @@ static void processUltrasonicOutput(void *signal_id)
|
||||
void canSendAll(void *signal_id)
|
||||
{
|
||||
static uint16_t wheel_speed_cnt = 0;
|
||||
static uint16_t kgf_cnt = 0;
|
||||
// static uint8_t kgf_cnt = 0;
|
||||
static uint16_t bms_cnt1 = 0;
|
||||
// static uint16_t bms_cnt2 = 0;
|
||||
// static uint16_t motor_speed_cnt = 0;
|
||||
// static uint16_t motor_power_cnt = 0;
|
||||
static uint16_t bms_cnt2 = 0;
|
||||
static uint16_t motor_speed_cnt = 0;
|
||||
static uint16_t motor_power_cnt = 0;
|
||||
// static uint8_t h_bridge_cnt = 0;
|
||||
uint8_t CanData[8] = {0,0,0,0,0,0,0,0};
|
||||
//-------------------------------------------------------------------------
|
||||
@@ -1215,41 +1235,58 @@ void canSendAll(void *signal_id)
|
||||
|
||||
CanData[0] = 0x5A;
|
||||
|
||||
CAN_Send_Msg(&can_handle_5, BMS_REQUEST_ID, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, CanData, 1, 15);//BMS<4D><53><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CAN_Send_Msg(&can_handle_3, 0x100, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, CanData, 1, 15);//BMS<4D><53><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
bms_cnt2 ++;
|
||||
if(bms_cnt2 >= 1100)//1s
|
||||
{
|
||||
bms_cnt2 = 0;
|
||||
|
||||
CanData[0] = 0x5A;
|
||||
|
||||
CAN_Send_Msg(&can_handle_3, 0x101, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, CanData, 1, 16);//BMS<4D><53><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
|
||||
// motor_power_cnt ++;
|
||||
// if(motor_power_cnt >= 1000)//1s<31><73><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
||||
// {
|
||||
// motor_power_cnt = 0;
|
||||
// processMotorOutput3(CanData);
|
||||
// processMotorOutput4(CanData);
|
||||
// }
|
||||
|
||||
// motor_power_cnt ++;
|
||||
// if(motor_power_cnt >= 10)//<2F><>ȡת<C8A1><D7AA> 20ms<6D><73><EFBFBD><EFBFBD>
|
||||
// {
|
||||
// motor_power_cnt = 0;
|
||||
//
|
||||
// un_motor_output1.bit_data.MotCon_1Signal6 = 0x84;
|
||||
// un_motor_output1.bit_data.MotCon_1Signal7 = 0x02;
|
||||
// un_motor_output2.bit_data.MotCon_1Signal6 = 0x84;
|
||||
// un_motor_output2.bit_data.MotCon_1Signal7 = 0x02;
|
||||
//
|
||||
// processMotorOutput3(CanData);
|
||||
// processMotorOutput4(CanData);
|
||||
// }
|
||||
|
||||
kgf_cnt ++;
|
||||
if(kgf_cnt >= 1000)//20210312 <20><><EFBFBD><EFBFBD>CANͨѶģ<D1B6><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 20210710<31><EFBFBD>Ϊ50ms<6D><73><EFBFBD><EFBFBD>
|
||||
motor_speed_cnt ++;
|
||||
if(motor_speed_cnt >= 1000)//1s<31><73><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
||||
{
|
||||
kgf_cnt = 0;
|
||||
motor_speed_cnt = 0;
|
||||
|
||||
processKgfOutput1(CanData);
|
||||
CanData[0] = 0xA4;
|
||||
CanData[1] = 0x02;
|
||||
CanData[2] = 0;
|
||||
CanData[3] = 0xFF;
|
||||
CanData[4] = 0;
|
||||
CanData[5] = 0xFF;
|
||||
|
||||
CAN_Send_Msg(&can_handle_1, 0x609, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData,CanData, 8, 17);//<2F><><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CAN_Send_Msg(&can_handle_2, 0x60A, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData,CanData, 8, 17);//<2F><><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
motor_power_cnt ++;
|
||||
if(motor_power_cnt >= 10)//<2F><>ȡת<C8A1><D7AA> 20ms<6D><73><EFBFBD><EFBFBD>
|
||||
{
|
||||
motor_power_cnt = 0;
|
||||
|
||||
un_motor_output1.bit_data.MotCon_1Signal6 = 0x84;
|
||||
un_motor_output1.bit_data.MotCon_1Signal7 = 0x02;
|
||||
un_motor_output2.bit_data.MotCon_1Signal6 = 0x84;
|
||||
un_motor_output2.bit_data.MotCon_1Signal7 = 0x02;
|
||||
|
||||
processMotorOutput3(CanData);
|
||||
processMotorOutput4(CanData);
|
||||
}
|
||||
|
||||
// kgf_cnt ++;
|
||||
// if(kgf_cnt >= 5)//20210312 <20><><EFBFBD><EFBFBD>CANͨѶģ<D1B6><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 20210710<31><EFBFBD>Ϊ50ms<6D><73><EFBFBD><EFBFBD>
|
||||
// {
|
||||
// kgf_cnt = 0;
|
||||
//
|
||||
// processKgfOutput1(CanData);
|
||||
// processKgfOutput2(CanData);
|
||||
}
|
||||
// }
|
||||
//
|
||||
//<2F><><EFBFBD>ٷ<EFBFBD><D9B7><EFBFBD>
|
||||
wheel_speed_cnt ++;
|
||||
@@ -1265,7 +1302,7 @@ void canSendAll(void *signal_id)
|
||||
// CAN_Send_Msg(&can_handle_3, 0x123, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, CanData, 8, 16);//BMS<4D><53><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// CAN_Send_Msg(&can_handle_4, 0x124, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, CanData, 8, 16);//BMS<4D><53><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// CAN_Send_Msg(&can_handle_5, 0x125, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, CanData, 8, 16);//BMS<4D><53><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// CAN_Send_Msg(&can_handle_6, 0x126, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, &un_can_debug_output.arr[0], 8, 16);//BMS<4D><53><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// CAN_Send_Msg(&can_handle_6, 0x126, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, &un_can_debug_output.arr[0], 8, 19);//BMS<4D><53><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// CAN_Send_Msg(&can_handle_7, 0x127, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, CanData, 8, 16);//BMS<4D><53><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
//
|
||||
@@ -1357,7 +1394,7 @@ void canInterfaceInit(void)
|
||||
// un_motor_output2.bit_data.set_torque = 30000;
|
||||
// un_motor_output2.bit_data.set_rotation_speed = 30000;
|
||||
// un_motor_output2.bit_data.mode = 0;
|
||||
// can_fault_info.bit_data.navigator_state = 1;
|
||||
can_fault_info.bit_data.navigator_state = 1;
|
||||
|
||||
memset(&un_inf_can_kgf_output1, 0, sizeof(UnInfCanKGFOutput));
|
||||
memset(&un_inf_can_kgf_output2, 0, sizeof(UnInfCanKGFOutput));
|
||||
@@ -1374,23 +1411,8 @@ void canInterfaceInit(void)
|
||||
|
||||
subscribe(&can_timer_interface1, canSendAll);
|
||||
subscribe(&can_timer_interface2, canInterfaceTimerProcess);
|
||||
|
||||
subscribe(&un_motor_output1, processMotorOutput1);
|
||||
subscribe(&un_motor_output2, processMotorOutput2);
|
||||
|
||||
subscribe(&un_sdo_output1, processSdoOutput1);
|
||||
subscribe(&un_sdo_output2, processSdoOutput2);
|
||||
subscribe(&un_sdo_output3, processSdoOutput3);
|
||||
subscribe(&un_sdo_output5, processmotorOutput5);
|
||||
|
||||
subscribe(&un_motor_output5, processSdoOutput5);
|
||||
subscribe(&un_motor_output6, processSdoOutput6);
|
||||
subscribe(&un_motor_output7, processSdoOutput7);
|
||||
subscribe(&un_motor_output8, processSdoOutput8);
|
||||
|
||||
|
||||
|
||||
|
||||
subscribe(&un_motor_output2, processMotorOutput2);
|
||||
subscribe(&un_inf_can_kgf_output1, processKgfOutput1);
|
||||
subscribe(&un_inf_can_kgf_output2, processKgfOutput2);
|
||||
subscribe(&un_wheel_wpeed_output, processWheelSpeedOutput);
|
||||
@@ -1399,20 +1421,17 @@ void canInterfaceInit(void)
|
||||
subscribe(&un_sw_sample, canInterfaceInput); // <20><>ͣ<EFBFBD><CDA3><EFBFBD>ء<EFBFBD><D8A1><EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ѱ<EFBFBD>־
|
||||
subscribe(&un_ultrasonic_output1, processUltrasonicOutput); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// subscribe(&un_h_bridge_output2, processHBridgeOutput2);
|
||||
// subscribe(&un_lifter_output, processLifterOutput);
|
||||
|
||||
// subscribe(&un_sdo_output1, processSdoOutput1);
|
||||
// subscribe(&un_sdo_output2, processSdoOutput2);
|
||||
// subscribe(&un_sdo_output3, processSdoOutput3);
|
||||
// subscribe(&un_sdo_output4, processSdoOutput4);
|
||||
subscribe(&un_sdo_output1, processSdoOutput1);
|
||||
subscribe(&un_sdo_output2, processSdoOutput2);
|
||||
subscribe(&un_sdo_output3, processSdoOutput3);
|
||||
subscribe(&un_sdo_output4, processSdoOutput4);
|
||||
subscribe(&un_sdo_output5, processSdoOutput5);
|
||||
|
||||
|
||||
// subscribe(&un_sdo_output5, processSdoOutput5);
|
||||
// subscribe(&un_sdo_output7, processSdoOutput7);
|
||||
|
||||
|
||||
@@ -21,34 +21,11 @@
|
||||
#define TX_MB_INDEX (USED_MB_FOR_FIFO)
|
||||
|
||||
|
||||
#define LEFT_FRONT_MOTOR_INPUT1 0x101
|
||||
#define LEFT_FRONT_MOTOR_INPUT2 0x103//<2F>¶<EFBFBD>
|
||||
|
||||
|
||||
#define LEFT_REAR_MOTOR2_INPUT1 0x102
|
||||
#define LEFT_REAR_MOTOR2_INPUT2 0x104//<2F>¶<EFBFBD>
|
||||
|
||||
|
||||
#define RIGHT_FRONT_MOTOR_INPUT1 0x101
|
||||
#define RIGHT_FRONT_MOTOR_INPUT2 0x103//<2F>¶<EFBFBD>
|
||||
|
||||
|
||||
#define RIGHT_REAR_MOTOR_INPUT1 0x102
|
||||
#define RIGHT_REAR_MOTOR_INPUT2 0x104//<2F>¶<EFBFBD>
|
||||
|
||||
|
||||
#define LEFT_FRONT_MOTOR_OUTPUT1 0x201
|
||||
#define LEFT_FRONT_MOTOR_OUTPUT2 0x401
|
||||
|
||||
#define LEFT_REAR_MOTOR_OUTPUT1 0x202
|
||||
#define LEFT_REAR_MOTOR_OUTPUT2 0x402
|
||||
|
||||
#define RIGHT_FRONT_MOTOR_OUTPUT1 0x201
|
||||
#define RIGHT_FRONT_MOTOR_OUTPUT2 0x401
|
||||
|
||||
#define RIGHT_REAR_MOTOR_OUTPUT1 0x202
|
||||
#define RIGHT_REAR_MOTOR_OUTPUT2 0x402
|
||||
#define MOTOR_INPUT_ID_1 0x189
|
||||
#define MOTOR_INPUT_ID_2 0x18A
|
||||
|
||||
#define MOTOR_INPUT_ID_3 0x103
|
||||
#define MOTOR_INPUT_ID_4 0x104
|
||||
|
||||
|
||||
|
||||
@@ -58,17 +35,16 @@
|
||||
//#define MOTOR_INPUT_ID_4 0x10F94708//<2F>Һ<EFBFBD>
|
||||
//
|
||||
//
|
||||
#define MOTOR_INPUT_ID_5 0x10F81708//<2F><>ǰ <20><>λ
|
||||
#define MOTOR_INPUT_ID_6 0x10F82708//<2F><>ǰ
|
||||
#define MOTOR_INPUT_ID_7 0x10F83708//<2F><><EFBFBD><EFBFBD>
|
||||
//#define MOTOR_INPUT_ID_1 0x10F81708//<2F><>ǰ <20><>λ
|
||||
//#define MOTOR_INPUT_ID_2 0x10F82708//<2F><>ǰ
|
||||
//#define MOTOR_INPUT_ID_3 0x10F83708//<2F><><EFBFBD><EFBFBD>
|
||||
#define MOTOR_INPUT_ID_8 0x10F84708//<2F>Һ<EFBFBD>
|
||||
|
||||
|
||||
|
||||
|
||||
#define BMS_INPUT_ID1 0x4028001
|
||||
#define BMS_REQUEST_ID 0x400FF80
|
||||
|
||||
#define BMS_INPUT_ID1 0x100
|
||||
#define BMS_INPUT_ID2 0x101
|
||||
#define REMOTE_ID 0x12000023
|
||||
#define REMOTE_ID_1 0x12000024
|
||||
#define TEMP_MODULE_INPUT_ID_1 0x15000003
|
||||
@@ -85,10 +61,7 @@ typedef struct _StrCanFault
|
||||
{
|
||||
uint8_t navigator_count; //<2F><><EFBFBD><EFBFBD><EFBFBD>Ǽ<EFBFBD><C7BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
uint8_t motor1_count; //<2F>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD>
|
||||
uint8_t motor2_count; //<2F>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD>
|
||||
uint8_t motor3_count; //<2F>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD>
|
||||
uint8_t motor4_count; //<2F>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
uint8_t motor2_count; //<2F>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD>
|
||||
uint8_t bms_count; //bms<6D><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
uint8_t temperature_count; //<2F>¶ȼ<C2B6><C8BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
uint8_t remote_count; //ң<>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
@@ -96,8 +69,6 @@ typedef struct _StrCanFault
|
||||
uint8_t navigator_state; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
||||
uint8_t motor1_state; //<2F><><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD>״̬
|
||||
uint8_t motor2_state; //<2F><><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD>״̬
|
||||
uint8_t motor3_state; //<2F><><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD>״̬
|
||||
uint8_t motor4_state; //<2F><><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD>״̬
|
||||
uint8_t bms_state; //bms״̬
|
||||
uint8_t temperature_state; //<2F>¶ȼ<C2B6><C8BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
uint8_t remote_state; //ң<><D2A3>״̬
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "sdrv_eth.h"
|
||||
#include "app/app_param_manage.h"
|
||||
#include "app/app_differential_drive.h"
|
||||
#include "app/app_turntable.h"
|
||||
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define MAX_BUFFER_SIZE (sizeof(((RequestContext *)0)->param_request->arr))
|
||||
@@ -207,7 +207,16 @@ void udp_Callback_1(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_ad
|
||||
uint16_t i = 0;
|
||||
uint16_t len = 0;
|
||||
uint16_t udp_temp = 0;
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
// uint8_t ip_addr[4] = {0,0,0,0};
|
||||
//
|
||||
// ip_addr[0] = addr->addr & 0xff; /* IADDR4 */
|
||||
// ip_addr[1] = (addr->addr >> 8) & 0xff; /* IADDR3 */
|
||||
// ip_addr[2] = (addr->addr >> 16) & 0xff; /* IADDR2 */
|
||||
// ip_addr[3] = (addr->addr >> 24) & 0xff; /* IADDR1 */
|
||||
|
||||
|
||||
|
||||
|
||||
if( (0xFF == buf[0] ) && ( 0xBB == buf[1] ) )//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>ң<EFBFBD><D2A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6>ң<EFBFBD><D2A3><EFBFBD><EFBFBD>
|
||||
{
|
||||
@@ -226,10 +235,18 @@ void udp_Callback_1(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_ad
|
||||
{
|
||||
un_manual_computer_input.arr[i] = buf[i];
|
||||
}
|
||||
|
||||
udp_temp = ((un_manual_computer_input.bit_data.set_speed << 8) | (un_manual_computer_input.bit_data.set_speed >> 8));//<2F>趨<EFBFBD>ٶ<EFBFBD> 20240928 <20>ĸߵ<C4B8>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>
|
||||
un_manual_computer_input.bit_data.set_speed = udp_temp;
|
||||
|
||||
udp_temp = ((un_manual_computer_input.bit_data.set_curvature << 8) | (un_manual_computer_input.bit_data.set_curvature >> 8));//<2F>趨<EFBFBD><E8B6A8><EFBFBD><EFBFBD>
|
||||
un_manual_computer_input.bit_data.set_curvature = udp_temp;
|
||||
|
||||
publishMessage(&un_manual_computer_input, 1);
|
||||
|
||||
// p->len = len;
|
||||
// printf("Manualrecive len:%d\n",len);
|
||||
// printf("Manualrecive len:%d, speed: %d , cur: %d\n",len,un_manual_computer_input.bit_data.set_speed,un_manual_computer_input.bit_data.set_curvature);
|
||||
|
||||
// udp_sendto(upcb, p, addr, port);
|
||||
}
|
||||
else if( (0xFF == buf[0] ) && (0xCC == buf[1] ) )//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>Զ<EFBFBD>
|
||||
@@ -273,27 +290,35 @@ void udp_Callback_1(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_ad
|
||||
// printf("Autorecive len:%d\n",len);
|
||||
// udp_sendto(upcb, p, addr, port);
|
||||
}
|
||||
else if(ENCODER_HEADER == buf[0])//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
else if( (0xFF == buf[0] ) && ( 0x12 == buf[1] ) )
|
||||
{
|
||||
if( (p->len) >= sizeof(un_encoder_data_input) )//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ȳ<EFBFBD><C8B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>С<EFBFBD><D0A1><EFBFBD><EFBFBD>
|
||||
|
||||
if( (p->len) >= sizeof(un_computer_turnable_Input) )//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ȳ<EFBFBD><C8B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>С<EFBFBD><D0A1><EFBFBD><EFBFBD>
|
||||
{
|
||||
len = sizeof(un_encoder_data_input);
|
||||
len = sizeof(un_computer_turnable_Input);
|
||||
}
|
||||
else
|
||||
{
|
||||
len = p->len;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
for(i = 0; i < len; i++)
|
||||
{
|
||||
un_encoder_data_input.arr[i] = buf[i];
|
||||
un_computer_turnable_Input.arr[i] = buf[i];
|
||||
// printf("%d", un_computer_turnable_Input.arr[i]); // <20><>16<31><36><EFBFBD>ƴ<EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD>ʺ϶<CABA><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>
|
||||
}
|
||||
publishMessage(&un_encoder_data_input, 1);
|
||||
publishMessage(&un_computer_turnable_Input, 1);
|
||||
|
||||
// // <20><>ӡPITCH<43><48><EFBFBD><EFBFBD>CAN<41><4E><EFBFBD><EFBFBD>
|
||||
// printf("un_computer_turnable_Input - ID: 0x%08X, Data: ", buf->id);
|
||||
// for(i = 0; i < 8; i++) {
|
||||
// printf("%02X ", buf->dataBuffer[i]);
|
||||
// }
|
||||
// printf("\n");
|
||||
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
}
|
||||
else{}
|
||||
|
||||
pbuf_free(p);
|
||||
}
|
||||
@@ -332,8 +357,21 @@ void udp_Callback_2(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_ad
|
||||
void udp_Callback_4(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
|
||||
{
|
||||
uint8_t *buf = (uint8_t *)(p->payload);
|
||||
uint8_t ip_addr[4] = {0,0,0,0};
|
||||
//------------------------------------------------------------------------------------------------
|
||||
|
||||
//20250822 <20><><EFBFBD>ӱ<EFBFBD><D3B1><EFBFBD>ˢд<CBA2><D0B4>λ<EFBFBD><CEBB>IP
|
||||
ip_addr[0] = addr->addr & 0xff; /* IADDR4 */
|
||||
ip_addr[1] = (addr->addr >> 8) & 0xff; /* IADDR3 */
|
||||
ip_addr[2] = (addr->addr >> 16) & 0xff; /* IADDR2 */
|
||||
ip_addr[3] = (addr->addr >> 24) & 0xff; /* IADDR1 */
|
||||
|
||||
ethernet_parameter.download_ip[0] = ip_addr[0];
|
||||
ethernet_parameter.download_ip[1] = ip_addr[1];
|
||||
ethernet_parameter.download_ip[2] = ip_addr[2];
|
||||
ethernet_parameter.download_ip[3] = ip_addr[3];
|
||||
|
||||
|
||||
boot_eth_flag = true;
|
||||
FrameHeader = ( (buf[0] << 8) | (buf[1]) );
|
||||
printf("FrameHeader %d\n",FrameHeader);
|
||||
@@ -453,12 +491,10 @@ static void autoControlOutput(void *signal_id)
|
||||
UdpSendToData(UDPCB_2,(uint8_t *)(&un_auto_control_output), sizeof(un_auto_control_output), (uint8_t *)ðernet_parameter.upper_ip[0], ethernet_parameter.target_upper_port);
|
||||
}
|
||||
|
||||
static void magneticEncoderOutput(void *signal_id)
|
||||
{
|
||||
(void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
UdpSendToData(UDPCB_2,(uint8_t *)(&str_magnetic_encoder), 1, (uint8_t *)&str_magnetic_encoder.ip[0], str_magnetic_encoder.port);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//<2F><>̫<EFBFBD><CCAB> <20><><EFBFBD><EFBFBD>
|
||||
void ethernetSendAll(void *signal_id)
|
||||
@@ -546,12 +582,26 @@ void udp_Callback_3(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_ad
|
||||
static unsigned int received_size = 0;
|
||||
uint8_t *buf = (uint8_t *)(p->payload);
|
||||
|
||||
uint8_t ip_addr[4] = {0,0,0,0};
|
||||
//------------------------------------------------------------------------------------------------
|
||||
|
||||
//20250822 <20><><EFBFBD>ӱ<EFBFBD><D3B1><EFBFBD>ˢд<CBA2><D0B4>λ<EFBFBD><CEBB>IP
|
||||
ip_addr[0] = addr->addr & 0xff; /* IADDR4 */
|
||||
ip_addr[1] = (addr->addr >> 8) & 0xff; /* IADDR3 */
|
||||
ip_addr[2] = (addr->addr >> 16) & 0xff; /* IADDR2 */
|
||||
ip_addr[3] = (addr->addr >> 24) & 0xff; /* IADDR1 */
|
||||
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>µ<EFBFBD>֡ͷ
|
||||
if ((0x80 == buf[1]) && (0xFF == buf[0]))
|
||||
{
|
||||
// <20><><EFBFBD>ý<EFBFBD><C3BD>չ<EFBFBD><D5B9><EFBFBD>
|
||||
received_size = 0;
|
||||
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>֡ͷ,<2C><><EFBFBD>ý<EFBFBD><C3BD>չ<EFBFBD><D5B9><EFBFBD>\n");
|
||||
|
||||
printf("IP<EFBFBD><EFBFBD>ַ: %d.%d.%d.%d\n", ip_addr[0], ip_addr[1], ip_addr[2], ip_addr[3]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>㹻<EFBFBD>Ŀռ<C4BF><D5BC><EFBFBD><EFBFBD>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@@ -665,10 +715,7 @@ void ethernetInterfaceInit(void)
|
||||
subscribe(&un_pid_output, pidOutput);
|
||||
subscribe(&un_remote_control_output, remoteControlOutput);
|
||||
subscribe(&un_manual_control_output, manualControlOutput);
|
||||
subscribe(&un_auto_control_output, autoControlOutput);
|
||||
|
||||
subscribe(&str_magnetic_encoder, magneticEncoderOutput);
|
||||
|
||||
subscribe(&un_auto_control_output, autoControlOutput);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>ʹ<EFBFBD>þ<EFBFBD>̬<EFBFBD><CCAC>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ص<EFBFBD>
|
||||
subscribe(&request_send, OnParamSend);
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
#include "app/app_ultrasonic.h"
|
||||
#include "app/app_turntable.h"
|
||||
|
||||
|
||||
void testAppInit(void);
|
||||
|
||||
#define IP_ADDR0 10
|
||||
@@ -114,24 +113,26 @@ int main(void)
|
||||
CAN_Send_Msg(&can_handle_6,OTA_CANTxID, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, BOOT_Arr,2, TX_MB_INDEX);//app 帧
|
||||
|
||||
printf("CAN_Send_Msg can_handle_6 OK %d\n",getCurrentTime());
|
||||
|
||||
|
||||
|
||||
//打印版本号
|
||||
printf("version: V1.75 \n");
|
||||
printf("version: V1.72 \n");
|
||||
// 初始化框架 放在最前面,解决电机can发送信号累积不处理的问题。
|
||||
|
||||
testAppInit();
|
||||
paramAppInit();
|
||||
diffAppInit();
|
||||
// brakeAppInit();
|
||||
brakeAppInit();
|
||||
powerAppInit(); //电源管理
|
||||
// tempAppInit(); //温度
|
||||
tempAppInit(); //温度
|
||||
lightAppInit(); //灯光
|
||||
ethernetInterfaceInit(); //以太网先初始化
|
||||
requestAppInit();
|
||||
canInterfaceInit();
|
||||
bootInterfaceInit();
|
||||
turnableInit();
|
||||
// ultrasonicAppInit();
|
||||
turnableInit();
|
||||
|
||||
printf("All init OK ------ %d\n",getCurrentTime());
|
||||
|
||||
for (;;)
|
||||
|
||||
Reference in New Issue
Block a user