From 2c83a66633f94b8adaca2389ba44722edf3c010e Mon Sep 17 00:00:00 2001 From: murmur Date: Wed, 11 Dec 2024 23:32:34 +0800 Subject: [PATCH] add valve functions --- protocol.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ protocol.h | 27 +++++++++++++++------- 2 files changed, 85 insertions(+), 8 deletions(-) diff --git a/protocol.c b/protocol.c index a31e7b2..d6ffa6b 100644 --- a/protocol.c +++ b/protocol.c @@ -398,8 +398,74 @@ void DecodePumpStatusMsg(uint16_t reg4002) { return 0; } +// valve +/* +# 轮廓位置模式,配置流程 +1.配置模式: +00B1h=0、运行模式 03C2h=0x01,使设备工作在轮廓位置模式; +1.1(设置为 CIA402 模式) +1.2(设置为轮廓位置模式) +2.参数配置: +2.1写目标位置 (03E7h)(用户单位); +2.2写当前段位移指令匀速运行速度 (03F8h) (用户单位/s); +2.3设置位移的加速度 (03FCh)(用户单位/s2) +2.4设置位移的减速度 (03FEh)(用户单位/s2); +3.写控制字使电机使能 +(0380h)= 0x06→0x07→ 0x0F,电机使能: +4.使电机运行 +(0380h)= 0x2F→0x3F,电机运行 +5.监控参数: +实际位置反馈:(03C8h) (用户单位) +# 堵转找寻原点方式,配置流程 +1.设置原点回归方式 +(0416h)=37;17=负限位,18=正限位 +2.设置堵转检测力矩和堵转检测时间 +(0170h)=300,(0172h)=50 +3.设置模式 +写 (00B1h)=0、运行模式 (03C2h)=0x06,使其工作在原点回归模式; +4.写寻找限位开关速度和寻找原点信号速度 +(0417h)= 10000 (0419h)=1000; +5.设置回零加速度 +(041Bh)=200000; +6.写控制字 + (0380h)= 0x06→0x07→0x0F→0x1F,电机运行 +*/ +static uint8_t SetValveMode(uint8_t index, uint16_t mode) { + WritePump1Reg(index, RTU_VALVE_CMD_CTL_MODE, mode); +} +static uint8_t SetValveRunMode(uint8_t index, uint16_t mode) { + WritePump1Reg(index, RTU_VALVE_CMD_RUN_MODE, mode); +} + +// PP=轮廓位置模式 +static uint8_t SetValvePPPos(uint8_t index, uint16_t pos) { + WritePump1Reg(index, RTU_VALVE_CMD_PP_POS, pos); +} +static uint8_t SetValvePPSpeed(uint8_t index, uint16_t speed) { + WritePump1Reg(index, RTU_VALVE_CMD_PP_SPEED, speed); +} +static uint8_t SetValvePPAcc(uint8_t index, uint16_t acc) { + WritePump1Reg(index, RTU_VALVE_CMD_PP_ACCEL, acc); +} +static uint8_t SetValvePPDec(uint8_t index, uint16_t dec) { + WritePump1Reg(index, RTU_VALVE_CMD_PP_DECEL, dec); +} + +// HM=原点回归模式 +static uint8_t SetValveHomeMode(uint8_t index, uint16_t mode) { + WritePump1Reg(index, RTU_VALVE_CMD_HOME_MODE, mode); +} +static uint8_t SetValveHomeSpeed(uint8_t index, uint16_t speed) { + WritePump1Reg(index, RTU_VALVE_CMD_HOME_SPEED, speed); +} +static uint8_t SetValveHomeAcc(uint8_t index, uint16_t acc) { + WritePump1Reg(index, RTU_VALVE_CMD_HOME_ACCEL, acc); +} +static uint8_t SetValveFunc(uint8_t index, uint16_t func) { + WritePump1Reg(index, RTU_VALVE_CMD_FUNC, func); +} // 定时1s更新设备状态 // 活度计通过网口获取 diff --git a/protocol.h b/protocol.h index 2ae21fc..d1c0a59 100644 --- a/protocol.h +++ b/protocol.h @@ -269,15 +269,26 @@ const uint8_t statusInfo[16][32]={ | 使电机运行原点回归 | 0380h | +------------------------------------+------------+ */ -#define RTU_VALVE_CMD_CTL_MODE 0x00B1 // 阀门控制模式 -#define RTU_VALVE_CMD_RUN_MODE 0x03C2 // 阀门运行模式 -#define RTU_VALVE_CMD_ORIGIN_MODE 0x0416 // 阀门原点回归模式 -#define RTU_VALVE_CMD_ORIGIN_SPEED 0x0417 // 阀门原点回归速度 -#define RTU_VALVE_CMD_ORIGIN_ACCEL 0x041B // 阀门原点回归加速度 -#define RTU_VALVE_CMD_ENABLE 0x0380 // 阀门使能 -#define RTU_VALVE_CMD_DISABLE 0x0380 // 阀门失能 -#define RTU_VALVE_CMD_RUN_ORIGIN 0x0380 // 阀门运行原点回归 +#define RTU_VALVE_CMD_CTL_MODE 0x00B1 // 阀门控制模式 +#define RTU_VALVE_CMD_RUN_MODE 0x03C2 // 阀门运行模式 +#define RTU_VALVE_CMD_PP_POS 0x03E7 // 阀门轮廓位置 +#define RTU_VALVE_CMD_PP_SPEED 0x03F8 // 阀门轮廓速度 +#define RTU_VALVE_CMD_PP_ACCEL 0x03FC // 阀门轮廓加速度 +#define RTU_VALVE_CMD_PP_DECEL 0x03FE // 阀门轮廓减速度 + +#define RTU_VALVE_CMD_HOME_MODE 0x0416 // 阀门原点回归方式 +#define RTU_VALVE_CMD_HOME_SPEED 0x0417 // 阀门原点回归速度 +#define RTU_VALVE_CMD_HOME_ACCEL 0x041B // 阀门原点回归加速度 +#define RTU_VALVE_CMD_FUNC 0x0380 // 阀门控制 + +#define RTU_VALVE_CFG_CTL_CIA402 0x0000 // 为CIA402模式 +#define RTU_VALVE_CFG_MODE_HM 0x0001 // 原点回归模式(HM) +#define RTU_VALVE_CFG_MODE_PP 0x0006 // 轮廓位置模式(PP) +#define RTU_VALVE_CFG_ENABLE 0x0006 // 准备 +#define RTU_VALVE_CFG_DISABLE 0x0007 // 失能 +#define RTU_VALVE_CFG_RUN 0x000F // 运行 +#define RTU_VALVE_CFG_RUN_ORIGIN 0x001F // 运行原点回归 // 错误码定义 typedef enum {