update functions
This commit is contained in:
parent
90d7bed5b4
commit
dee9ff6204
85
protocol.c
85
protocol.c
@ -11,12 +11,16 @@ DeviceStatus deviceStatus = {
|
||||
.initStatus = 1
|
||||
};
|
||||
|
||||
DeviceParam dp = {{
|
||||
{"pump1", 4, 60, 100, 100},
|
||||
{"pump2", 3, 10, 100, 100},
|
||||
{"valve1", 3, 10, 100, 100},
|
||||
{"valve2", 4, 10, 100, 100}
|
||||
}};
|
||||
DeviceParam dp = {
|
||||
.pump = {
|
||||
{"pump1", 4, 60, 100, 100},
|
||||
{"pump2", 3, 10, 100, 100}
|
||||
},
|
||||
.valve = {
|
||||
{"valve1", 1, 10, 100, 100},
|
||||
{"valve2", 2, 10, 100, 100}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -206,7 +210,7 @@ void writeCMD(uint8_t *txBuf, uint16_t txLen) {
|
||||
void sendMsgToHost(uint8_t *txBuf, uint16_t txLen) {
|
||||
// 发送数据
|
||||
// HAL_UART_Transmit_DMA(&huart1, txBuf, txLen);
|
||||
transDataToHost(txBuf, txLen);
|
||||
// transDataToHost(txBuf, txLen);
|
||||
}
|
||||
|
||||
|
||||
@ -688,7 +692,7 @@ void (*readValve2Reg)(uint8_t index, uint16_t reg) = ReadPump2Reg;
|
||||
* @return 0:成功 其他:失败
|
||||
*/
|
||||
static uint8_t SetValveCOMMMode(uint8_t index, uint16_t mode) {
|
||||
WritePump1Reg(index, RTU_VALVE_CMD_CTL_MODE, mode);
|
||||
WritePump1Reg(dp.valve[index].id, RTU_VALVE_CMD_CTL_MODE, mode);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -699,7 +703,7 @@ static uint8_t SetValveCOMMMode(uint8_t index, uint16_t mode) {
|
||||
* @return 0:成功 其他:失败
|
||||
*/
|
||||
static uint8_t SetValveRunMode(uint8_t index, uint16_t mode) {
|
||||
WritePump1Reg(index, RTU_VALVE_CMD_RUN_MODE, mode);
|
||||
WritePump1Reg(dp.valve[index].id, RTU_VALVE_CMD_RUN_MODE, mode);
|
||||
}
|
||||
|
||||
// PP=轮廓位置模式
|
||||
@ -711,7 +715,7 @@ static uint8_t SetValveRunMode(uint8_t index, uint16_t mode) {
|
||||
* @return 0:成功 其他:失败
|
||||
*/
|
||||
static uint8_t SetValvePPPos(uint8_t index, uint32_t pos) {
|
||||
writeValve2Reg(index, RTU_VALVE_CMD_PP_POS, pos);
|
||||
writeValve2Reg(dp.valve[index].id, RTU_VALVE_CMD_PP_POS, pos);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -722,7 +726,7 @@ static uint8_t SetValvePPPos(uint8_t index, uint32_t pos) {
|
||||
* @return 0:成功 其他:失败
|
||||
*/
|
||||
static uint8_t SetValvePPSpeed(uint8_t index, uint32_t speed) {
|
||||
writeValve2Reg(index, RTU_VALVE_CMD_PP_SPEED, speed);
|
||||
writeValve2Reg(dp.valve[index].id, RTU_VALVE_CMD_PP_SPEED, speed);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -733,7 +737,7 @@ static uint8_t SetValvePPSpeed(uint8_t index, uint32_t speed) {
|
||||
* @return 0:成功 其他:失败
|
||||
*/
|
||||
static uint8_t SetValvePPAcc(uint8_t index, uint32_t acc) {
|
||||
writeValve2Reg(index, RTU_VALVE_CMD_PP_ACCEL, acc);
|
||||
writeValve2Reg(dp.valve[index].id, RTU_VALVE_CMD_PP_ACCEL, acc);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -744,7 +748,7 @@ static uint8_t SetValvePPAcc(uint8_t index, uint32_t acc) {
|
||||
* @return 0:成功 其他:失败
|
||||
*/
|
||||
static uint8_t SetValvePPDec(uint8_t index, uint32_t dec) {
|
||||
writeValve2Reg(index, RTU_VALVE_CMD_PP_DECEL, dec);
|
||||
writeValve2Reg(dp.valve[index].id, RTU_VALVE_CMD_PP_DECEL, dec);
|
||||
}
|
||||
|
||||
// HM=原点回归模式
|
||||
@ -756,7 +760,7 @@ static uint8_t SetValvePPDec(uint8_t index, uint32_t dec) {
|
||||
* @return 0:成功 其他:失败
|
||||
*/
|
||||
static uint8_t SetValveHomeDetectMode(uint8_t index, uint16_t mode) {
|
||||
writeValve1Reg(index, RTU_VALVE_CMD_HOME_MODE, mode);
|
||||
writeValve1Reg(dp.valve[index].id, RTU_VALVE_CMD_HOME_MODE, mode);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -767,7 +771,7 @@ static uint8_t SetValveHomeDetectMode(uint8_t index, uint16_t mode) {
|
||||
* @return 0:成功 其他:失败
|
||||
*/
|
||||
static uint8_t SetValveHomeSwtSpeed(uint8_t index, uint32_t speed) {
|
||||
writeValve2Reg(index, RTU_VALVE_CMD_HOME_SWT_SPEED, speed);
|
||||
writeValve2Reg(dp.valve[index].id, RTU_VALVE_CMD_HOME_SWT_SPEED, speed);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -778,7 +782,7 @@ static uint8_t SetValveHomeSwtSpeed(uint8_t index, uint32_t speed) {
|
||||
* @return 0:成功 其他:失败
|
||||
*/
|
||||
static uint8_t SetValveHomeOriSpeed(uint8_t index, uint32_t speed) {
|
||||
writeValve2Reg(index, RTU_VALVE_CMD_HOME_ORI_SPEED, speed);
|
||||
writeValve2Reg(dp.valve[index].id, RTU_VALVE_CMD_HOME_ORI_SPEED, speed);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -789,7 +793,7 @@ static uint8_t SetValveHomeOriSpeed(uint8_t index, uint32_t speed) {
|
||||
* @return 0:成功 其他:失败
|
||||
*/
|
||||
static uint8_t SetValveHomeAcc(uint8_t index, uint32_t acc) {
|
||||
writeValve2Reg(index, RTU_VALVE_CMD_HOME_ACCEL, acc);
|
||||
writeValve2Reg(dp.valve[index].id, RTU_VALVE_CMD_HOME_ACCEL, acc);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -800,7 +804,7 @@ static uint8_t SetValveHomeAcc(uint8_t index, uint32_t acc) {
|
||||
* @return 0:成功 其他:失败
|
||||
*/
|
||||
static uint8_t SetValveFunc(uint8_t index, uint16_t func) {
|
||||
writeValve1Reg(index, RTU_VALVE_CMD_FUNC, func);
|
||||
writeValve1Reg(dp.valve[index].id, RTU_VALVE_CMD_FUNC, func);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -811,7 +815,7 @@ static uint8_t SetValveFunc(uint8_t index, uint16_t func) {
|
||||
* @return 0:成功 其他:失败
|
||||
*/
|
||||
static uint8_t SetValveHomeTorque(uint8_t index, uint16_t torque) {
|
||||
writeValve1Reg(index, RTU_VALVE_CMD_HOME_TORQUE, torque*10);
|
||||
writeValve1Reg(dp.valve[index].id, RTU_VALVE_CMD_HOME_TORQUE, torque*10);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -822,7 +826,7 @@ static uint8_t SetValveHomeTorque(uint8_t index, uint16_t torque) {
|
||||
* @return 0:成功 其他:失败
|
||||
*/
|
||||
static uint8_t SetValveHomeTime(uint8_t index, uint16_t time) {
|
||||
writeValve1Reg(index, RTU_VALVE_CMD_HOME_TIME, time*10);
|
||||
writeValve1Reg(dp.valve[index].id, RTU_VALVE_CMD_HOME_TIME, time*10);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -836,9 +840,11 @@ uint8_t ValveBackToOrigin(uint8_t index,uint8_t direction) {
|
||||
// 1.设置原点回归方式
|
||||
// (0416h)=37;17=负限位,18=正限位
|
||||
if(direction) {
|
||||
printf("back to Origin, +\r\n");
|
||||
SetValveHomeDetectMode(index, 37);//正方向堵转
|
||||
}
|
||||
else {
|
||||
printf("back to Origin, -\r\n");
|
||||
SetValveHomeDetectMode(index, 38);//反方向堵转
|
||||
}
|
||||
// 2.设置堵转检测力矩和堵转检测时间
|
||||
@ -846,8 +852,8 @@ uint8_t ValveBackToOrigin(uint8_t index,uint8_t direction) {
|
||||
SetValveHomeTorque(index, 600);//60%
|
||||
SetValveHomeTime(index, 10000);//1000ms
|
||||
// 3.写 (00B1h)=0、运行模式 (03C2h)=0x06,使其工作在原点回归模式;
|
||||
// SetValveCOMMMode(index, RTU_VALVE_CFG_COMM_CIA402);
|
||||
// SetValveRunMode(index, RTU_VALVE_CFG_MODE_HM);
|
||||
SetValveCOMMMode(index, RTU_VALVE_CFG_COMM_CIA402);
|
||||
SetValveRunMode(index, RTU_VALVE_CFG_MODE_HM);
|
||||
// 4.写寻找限位开关速度和寻找原点信号速度(0417h)= 10000 (0419h)=1000;
|
||||
// SetValveHomeSwtSpeed(index, 20000);
|
||||
SetValveHomeOriSpeed(index, 20000);
|
||||
@ -855,9 +861,9 @@ uint8_t ValveBackToOrigin(uint8_t index,uint8_t direction) {
|
||||
SetValveHomeAcc(index, 200000);
|
||||
// 6.写控制字
|
||||
// (0380h)= 0x06→0x07→0x0F→0x1F,电机运行
|
||||
// SetValveFunc(index, RTU_VALVE_CFG_PREPARE);
|
||||
// SetValveFunc(index, RTU_VALVE_CFG_DISABLE);
|
||||
// SetValveFunc(index, RTU_VALVE_CFG_ENABLE);
|
||||
SetValveFunc(index, RTU_VALVE_CFG_PREPARE);
|
||||
SetValveFunc(index, RTU_VALVE_CFG_DISABLE);
|
||||
SetValveFunc(index, RTU_VALVE_CFG_ENABLE);
|
||||
SetValveFunc(index, RTU_VALVE_CFG_RUN_ORIGIN);
|
||||
}
|
||||
|
||||
@ -869,6 +875,7 @@ uint8_t ValveBackToOrigin(uint8_t index,uint8_t direction) {
|
||||
* @return 0:成功 其他:失败
|
||||
*/
|
||||
uint8_t ValveRunInit(uint8_t index) {
|
||||
printf("set mode to PP\r\n");
|
||||
// 1.配置模式:
|
||||
// 00B1h=0、运行模式 03C2h=0x01,使设备工作在轮廓位置模式;
|
||||
SetValveCOMMMode(index, RTU_VALVE_CFG_COMM_CIA402);
|
||||
@ -894,6 +901,7 @@ uint8_t ValveRunInit(uint8_t index) {
|
||||
* @return 0:成功 其他:失败
|
||||
*/
|
||||
uint8_t ValveRunToAngle(uint8_t index, uint32_t angle) {
|
||||
printf("set angel to %d\r\n",angle);
|
||||
// 限制角度的逻辑不在这里,此处只执行控制逻辑
|
||||
if(angle > 360) {
|
||||
log_e("阀门角度设置错误");
|
||||
@ -916,13 +924,14 @@ uint8_t ValveRunToAngle(uint8_t index, uint32_t angle) {
|
||||
* @return 0:成功 其他:失败
|
||||
*/
|
||||
uint8_t InitValve(void) {
|
||||
SetValvePPSpeed(dp.valve[0].id, dp.valve[0].maxSpeed);
|
||||
SetValvePPAcc(dp.valve[0].id, dp.valve[0].maxAccel);
|
||||
SetValvePPDec(dp.valve[0].id, dp.valve[0].maxDecel);
|
||||
printf("InitValve\n");
|
||||
SetValvePPSpeed(0, dp.valve[0].maxSpeed);
|
||||
SetValvePPAcc(0, dp.valve[0].maxAccel);
|
||||
SetValvePPDec(0, dp.valve[0].maxDecel);
|
||||
|
||||
SetValvePPSpeed(dp.valve[1].id, dp.valve[1].maxSpeed);
|
||||
SetValvePPAcc(dp.valve[1].id, dp.valve[1].maxAccel);
|
||||
SetValvePPDec(dp.valve[1].id, dp.valve[1].maxDecel);
|
||||
SetValvePPSpeed(1, dp.valve[1].maxSpeed);
|
||||
SetValvePPAcc(1, dp.valve[1].maxAccel);
|
||||
SetValvePPDec(1, dp.valve[1].maxDecel);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1253,29 +1262,31 @@ CmdFrameError_t ProcessHostCommand(uint8_t *rxBuf, uint8_t rxLen) {
|
||||
void runPumpDemo(void) {
|
||||
printf("runPumpDemo\r\n");
|
||||
// printf("InitPump\n");
|
||||
InitPump();
|
||||
// InitPump();
|
||||
// 泵1正转100步
|
||||
printf("SetPumpStepTarget(0, 100)\n");
|
||||
SetPumpStepTarget(0, 200000);
|
||||
printf("StartPumpRelativeMove(0)\n");
|
||||
StartPumpRelativeMove(0);
|
||||
HAL_Delay(1000);
|
||||
// HAL_Delay(1000);
|
||||
// 泵1反转100步
|
||||
printf("SetPumpStepTarget(0, -100)\n");
|
||||
SetPumpStepTarget(1, -300000);
|
||||
printf("StartPumpRelativeMove(0)\n");
|
||||
StartPumpRelativeMove(1);
|
||||
HAL_Delay(1000);
|
||||
// HAL_Delay(1000);
|
||||
printf("StopPump(0)\n");
|
||||
StopPump(0);
|
||||
HAL_Delay(1000);
|
||||
// HAL_Delay(1000);
|
||||
}
|
||||
|
||||
void runValveDemo(void) {
|
||||
InitValve();
|
||||
ValveBackToOrigin(0);
|
||||
printf("runValveDemo\r\n");
|
||||
InitValve();
|
||||
ValveBackToOrigin(0,1);
|
||||
|
||||
// 阀门1正转120度
|
||||
printf("ValveRunToAngle(0, 120)\n");
|
||||
ValveRunInit(0);
|
||||
ValveRunToAngle(0, 120);
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ typedef union {
|
||||
}AlarmCode_t;
|
||||
|
||||
// 用于输出具体的告警信息字符串
|
||||
static const uint8_t alarmInfo[16][32]={
|
||||
static const uint8_t alarmInfo[16][50]={
|
||||
"位置误差超限",
|
||||
"CCW方向禁止限位",
|
||||
"CW方向禁止限位",
|
||||
@ -166,7 +166,7 @@ typedef union {
|
||||
} bits;
|
||||
uint16_t all;
|
||||
} StatusCode_t;
|
||||
static const uint8_t statusInfo[16][32]={
|
||||
static const uint8_t statusInfo[16][60]={
|
||||
"使能",
|
||||
"采样中(软件示波器功能开启)",
|
||||
"驱动器报故障",
|
||||
@ -423,4 +423,5 @@ void DecodePumpStatusMsg(uint16_t reg4002);
|
||||
void UpdatePumpStatus();
|
||||
void ProcessMotorMsg(uint8_t *rxBuf, uint16_t rxLen);
|
||||
void runPumpDemo(void);
|
||||
void runVavleDemo(void);
|
||||
#endif // PROTOCOL_H
|
Loading…
Reference in New Issue
Block a user