更新测试函数,修正默认参数

This commit is contained in:
murmur 2024-12-24 23:12:00 +08:00
parent c7be59a71d
commit 92485d58a9
2 changed files with 22 additions and 18 deletions

View File

@ -19,12 +19,12 @@ uint8_t isValveMovingBackToOrigin[2] = {0,0};
DeviceParam_t dp = { DeviceParam_t dp = {
.pump = { .pump = {
{"pump1", 4, 60, 100, 100}, {"pump1", 4, 60, 100, 100,40000},
{"pump2", 3, 10, 100, 100} {"pump2", 3, 10, 100, 100,40000}
}, },
.valve = { .valve = {
{"valve1", 1, 10, 100, 100}, {"valve1", 1, 10, 100, 100,47620},
{"valve2", 2, 10, 100, 100} {"valve2", 2, 10, 100, 100,47620}
} }
}; };
@ -198,7 +198,7 @@ static uint8_t writeCMD(uint8_t *txBuf, uint16_t txLen) {
uint16_t rxLen = txLen; uint16_t rxLen = txLen;
uint8_t rst = HAL_UART_Receive(&huart2, rxBuf, rxLen, READ_ACK_TIMEOUT); uint8_t rst = HAL_UART_Receive(&huart2, rxBuf, rxLen, READ_ACK_TIMEOUT);
if(memcmp(rxBuf, txBuf, 2) != 0) { if(memcmp(rxBuf, txBuf, 2) != 0) {
log_e("writeCMD error"); log_e("writeCMD error!");
printf("%d readCMD: ", rst); printf("%d readCMD: ", rst);
for(uint16_t i = 0; i < rxLen; i++) { for(uint16_t i = 0; i < rxLen; i++) {
printf("%02X ", rxBuf[i]); printf("%02X ", rxBuf[i]);
@ -206,6 +206,9 @@ static uint8_t writeCMD(uint8_t *txBuf, uint16_t txLen) {
printf("\r\n"); printf("\r\n");
return 1; return 1;
} }
else {
log_d("writeCMD success!");
}
return 0; return 0;
} }
@ -316,7 +319,7 @@ uint32_t ReadPump2Reg(uint8_t id, uint16_t reg) {
/* /*
+----------+--------+------------+----------+------------+ +----------+--------+------------+----------+------------+
| | | | <EFBFBD><EFBFBD><EFBFBD> | CRC校验值 | | | | | | CRC校验值 |
+----------+--------+------------+----------+------------+ +----------+--------+------------+----------+------------+
| 1 | 1 | 2 | 2 | 2 | | 1 | 1 | 2 | 2 | 2 |
+----------+--------+------------+----------+------------+ +----------+--------+------------+----------+------------+
@ -901,7 +904,7 @@ static uint8_t SetValveFunc(uint8_t index, uint16_t func) {
* *
* *
* @param index * @param index
* @param torque 6060% * @param torque 3030%
* @return 0: : * @return 0: :
*/ */
static uint8_t SetValveHomeTorque(uint8_t index, uint16_t torque) { static uint8_t SetValveHomeTorque(uint8_t index, uint16_t torque) {
@ -912,7 +915,7 @@ static uint8_t SetValveHomeTorque(uint8_t index, uint16_t torque) {
* *
* *
* @param index * @param index
* @param time (ms)1000ms * @param time (ms)55ms
* @return 0: : * @return 0: :
*/ */
static uint8_t SetValveHomeTime(uint8_t index, uint16_t time) { static uint8_t SetValveHomeTime(uint8_t index, uint16_t time) {
@ -968,12 +971,13 @@ static uint8_t valveCheckBTOResult(uint8_t index, uint32_t startTime)
* *
* *
* @param index * @param index
* @param direction
* @return 0: : * @return 0: :
*/ */
uint8_t ValveBackToOrigin(uint8_t index,uint8_t direction) { uint8_t ValveBackToOrigin(uint8_t index,int8_t direction) {
// 1.设置原点回归方式 // 1.设置原点回归方式
// (0416h)=37;17=负限位18=正限位 // (0416h)=37;17=负限位18=正限位
if(direction) { if(direction > 0) {
printf("back to Origin, +\r\n"); printf("back to Origin, +\r\n");
SetValveHomeDetectMode(index, 37);//正方向堵转 SetValveHomeDetectMode(index, 37);//正方向堵转
} }
@ -983,8 +987,8 @@ uint8_t ValveBackToOrigin(uint8_t index,uint8_t direction) {
} }
// 2.设置堵转检测力矩和堵转检测时间 // 2.设置堵转检测力矩和堵转检测时间
// (0170h)=300(0172h)=50 // (0170h)=300(0172h)=50
SetValveHomeTorque(index, 600);//60% SetValveHomeTorque(index, 30);//30%
SetValveHomeTime(index, 10000);//1000ms SetValveHomeTime(index, 5);//50ms
// 3.写 (00B1h)=0、运行模式 (03C2h)=0x06使其工作在原点回归模式 // 3.写 (00B1h)=0、运行模式 (03C2h)=0x06使其工作在原点回归模式
SetValveCOMMMode(index, RTU_VALVE_CFG_COMM_CIA402); SetValveCOMMMode(index, RTU_VALVE_CFG_COMM_CIA402);
SetValveRunMode(index, RTU_VALVE_CFG_MODE_HM); SetValveRunMode(index, RTU_VALVE_CFG_MODE_HM);
@ -1048,7 +1052,7 @@ uint8_t ValveRunToAngle(uint8_t index, uint32_t angle) {
} }
// 其它配置不变的情况下只需要写3个控制字 // 其它配置不变的情况下只需要写3个控制字
SetValvePPPos(index, (uint32_t)(angle*VALVE_PULSE_PER_ROUND/360)); SetValvePPPos(index, (uint32_t)(angle*dp.valve[index].fullCount/360));
// 电机以绝对位置,立即更新的方式运行 // 电机以绝对位置,立即更新的方式运行
// (电机是以控制字 6040h(0380h)的 bit4 的上升沿接收新的位置命令, // (电机是以控制字 6040h(0380h)的 bit4 的上升沿接收新的位置命令,
// 所以每次执行完一次运行后需 要把此位清零。) // 所以每次执行完一次运行后需 要把此位清零。)
@ -1066,7 +1070,7 @@ uint8_t InitValve(void) {
printf("InitValve\n"); printf("InitValve\n");
ValvePPInit(0); ValvePPInit(0);
ValvePPInit(1); // ValvePPInit(1);
} }
/** /**
@ -1476,9 +1480,8 @@ void runPumpDemo(void) {
void runValveDemo(void) { void runValveDemo(void) {
printf("runValveDemo\r\n"); printf("runValveDemo\r\n");
InitValve(); ValveBackToOrigin(0,-1);
ValveBackToOrigin(0,1); HAL_Delay(5000);
// 阀门1正转120度 // 阀门1正转120度
printf("ValveRunToAngle(0, 120)\n"); printf("ValveRunToAngle(0, 120)\n");
ValvePPInit(0); ValvePPInit(0);

View File

@ -302,7 +302,7 @@ static const uint8_t statusInfo[16][60]={
#define RTU_VALVE_CMD_SC 0x0381 // 阀门运行状态 #define RTU_VALVE_CMD_SC 0x0381 // 阀门运行状态
#define RTU_VALVE_CMD_AL 0x037F // 阀门运行告警 #define RTU_VALVE_CMD_AL 0x037F // 阀门运行告警
#define RTU_VALVE_CMD_POS 0x03C8 // 阀门运行位置,用户单位 #define RTU_VALVE_CMD_POS 0x03C8 // 阀门运行位置,用户单位
#define RTU_VALVE_CMD_SPEED 0x03D5 // 阀门当前速度,用户单位/s #define RTU_VALVE_CMD_SPEED 0x03D5 // 阀门当前速度,用户单位/srpm
#define RTU_VALVE_CMD_HOME_MODE 0x0416 // 阀门原点回归方式 #define RTU_VALVE_CMD_HOME_MODE 0x0416 // 阀门原点回归方式
#define RTU_VALVE_CMD_HOME_SWT_SPEED 0x0417 // 阀门回归寻找开关的速度 #define RTU_VALVE_CMD_HOME_SWT_SPEED 0x0417 // 阀门回归寻找开关的速度
@ -413,6 +413,7 @@ typedef struct {
uint32_t maxSpeed; uint32_t maxSpeed;
uint32_t maxAccel; uint32_t maxAccel;
uint32_t maxDecel; uint32_t maxDecel;
uint16_t fullCount;//电机总步数,用于根据角度估算需要移动的步数
} MotorDefaultParam_t; } MotorDefaultParam_t;