第一次提交
This commit is contained in:
159
app/app_base.c
Normal file
159
app/app_base.c
Normal file
@@ -0,0 +1,159 @@
|
||||
#include "app_config.h"
|
||||
#include "app_dependence.h"
|
||||
#include "interface.h"
|
||||
|
||||
#include "app_base.h"
|
||||
|
||||
|
||||
// 使用内联函数
|
||||
static inline uint8_t setBaseOn(void) { return 1; }
|
||||
static inline uint8_t setBaseOff(void) { return 0; }
|
||||
|
||||
BaseSystem base_data;
|
||||
|
||||
// 输出处理函数
|
||||
static void baseOutput(void *signal_id)
|
||||
{
|
||||
(void)signal_id;
|
||||
// 根据电机状态,填充发送数据结构,发送信号
|
||||
switch (base_data.base_command)
|
||||
{
|
||||
case 1: // 上升状态
|
||||
un_lifter_output.bit_data.cmd = BASE_UP;
|
||||
un_h_bridge_output1.bit_data.channel_01 = setBaseOn();
|
||||
un_h_bridge_output1.bit_data.channel_02 = setBaseOff();
|
||||
un_h_bridge_output2.bit_data.channel_01 = setBaseOn();
|
||||
un_h_bridge_output2.bit_data.channel_02 = setBaseOff();
|
||||
// printf("base: up\n");
|
||||
break;
|
||||
|
||||
case 2: // 下降状态
|
||||
un_lifter_output.bit_data.cmd = BASE_DOWN;
|
||||
un_h_bridge_output1.bit_data.channel_01 = setBaseOff();
|
||||
un_h_bridge_output1.bit_data.channel_02 = setBaseOn();
|
||||
un_h_bridge_output2.bit_data.channel_01 = setBaseOff();
|
||||
un_h_bridge_output2.bit_data.channel_02 = setBaseOn();
|
||||
// printf("base: down\n");
|
||||
break;
|
||||
|
||||
default://停止
|
||||
un_lifter_output.bit_data.cmd = BASE_STOP;
|
||||
un_h_bridge_output1.bit_data.channel_01 = setBaseOff();
|
||||
un_h_bridge_output1.bit_data.channel_02 = setBaseOff();
|
||||
un_h_bridge_output2.bit_data.channel_01 = setBaseOff();
|
||||
un_h_bridge_output2.bit_data.channel_02 = setBaseOff();
|
||||
// printf("base: stop\n");
|
||||
break;
|
||||
}
|
||||
publishMessage(&un_h_bridge_output1, 1);
|
||||
publishMessage(&un_h_bridge_output2, 1);
|
||||
publishMessage(&un_lifter_output, 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//处理开关以及模式状态。还需要保存状态防止重启的问题。
|
||||
static void baseTimerProcess(void *signal_id)
|
||||
{
|
||||
(void)signal_id;
|
||||
|
||||
if( (base_data.emergency_stop_switch) || (base_data.remote_emergency_stop) )//急停只要有一个有效就停止
|
||||
{
|
||||
base_data.base_command = BASE_STOP;
|
||||
}
|
||||
else if(base_data.mode)//自动模式 一直上升就自动
|
||||
{
|
||||
if(base_data.input_data > REMOTE_DEADBAND)//上升
|
||||
{
|
||||
base_data.base_command = BASE_UP;
|
||||
}
|
||||
else if(base_data.input_data < -REMOTE_DEADBAND)//下降
|
||||
{
|
||||
base_data.base_command = BASE_DOWN;
|
||||
}
|
||||
else//不停止
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
else//手动模式-
|
||||
{
|
||||
if(base_data.input_data > REMOTE_DEADBAND)//上升
|
||||
{
|
||||
base_data.base_command = BASE_UP;
|
||||
}
|
||||
else if(base_data.input_data < -REMOTE_DEADBAND)//下降
|
||||
{
|
||||
base_data.base_command = BASE_DOWN;
|
||||
}
|
||||
else
|
||||
{
|
||||
base_data.base_command = BASE_STOP;
|
||||
}
|
||||
}
|
||||
baseOutput(signal_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 处理所有输入信号的函数
|
||||
static void baseInput(void *signal_id)
|
||||
{
|
||||
// BaseSystem old_data = base_data; // 定义并初始化old_data
|
||||
// 填充数据
|
||||
if (signal_id == &un_sw_sample)
|
||||
{
|
||||
base_data.emergency_stop_switch = (uint8_t)un_sw_sample.bit_data.emergency_stop_switch;
|
||||
base_data.Left_switch = (uint8_t)un_sw_sample.bit_data.Left_switch;
|
||||
base_data.right_switch = (uint8_t)un_sw_sample.bit_data.right_switch;
|
||||
}
|
||||
else if ( (signal_id == &un_remote_control_input) && (1 == un_remote_control_input.bit_data.enable) )// 遥控器断线,不更新数据
|
||||
{
|
||||
base_data.remote_emergency_stop = ((uint8_t)un_remote_control_input.bit_data.switch_b == 1) ? 0 : 1;
|
||||
base_data.mode = ((uint8_t)un_remote_control_input.bit_data.switch_c == 1) ? 1 : 0;//
|
||||
|
||||
}
|
||||
else if( (signal_id == &un_remote_control_input1) && (1 == un_remote_control_input.bit_data.enable) )
|
||||
{
|
||||
base_data.input_data = (int16_t)(un_remote_control_input1.bit_data.speed) - REMOTE_ZERO;
|
||||
// printf("un_remote_control_input1: %d\n", base_data.input_data);
|
||||
}
|
||||
else if (signal_id == &can_fault_info)
|
||||
{
|
||||
// base_data.remote_fault = !can_fault_info.bit_data.remote_state;
|
||||
// base_data.can_bus_fault = !can_fault_info.bit_data.motor1_state || !can_fault_info.bit_data.motor2_state || !can_fault_info.bit_data.navigator_state;
|
||||
}
|
||||
else if (signal_id == ðernet_fault_Info)
|
||||
{
|
||||
// base_data.ethernet_fault = !ethernet_fault_Info.bit_data.auto_state && !ethernet_fault_Info.bit_data.manual_state;
|
||||
}
|
||||
baseTimerProcess(signal_id);
|
||||
}
|
||||
|
||||
// 修改APP模块的初始化函数
|
||||
void baseAppInit(void)
|
||||
{
|
||||
// 初始化
|
||||
memset(&base_data, 0, sizeof(BaseSystem));
|
||||
|
||||
// 初始化定时器
|
||||
timerInit(&base_data.base_timer);
|
||||
|
||||
// 订阅输入信号,处理刹车逻辑
|
||||
subscribe(&un_sw_sample, baseInput);
|
||||
subscribe(&un_remote_control_input, baseInput);
|
||||
subscribe(&un_remote_control_input1, baseInput);
|
||||
|
||||
printf("app_base: initial OK \n");
|
||||
}
|
||||
Reference in New Issue
Block a user