Browse Source

add: 增加 Block 函数

master
HSZ_HeSongZhen 3 months ago
parent
commit
532d479f1d
  1. 7
      src/main/java/iflytop/app/config/ActionOvertimeConstant.java
  2. 26
      src/main/java/iflytop/app/hardware/driver/LeisaiServoDriver.java
  3. 13
      src/main/java/iflytop/app/hardware/driver/LiquidDistributionArmDriver.java
  4. 6
      src/main/java/iflytop/app/page/LeisaiServoPage.java
  5. 2
      src/main/java/iflytop/app/page/LiquidArmPage.java

7
src/main/java/iflytop/app/config/ActionOvertimeConstant.java

@ -1,6 +1,7 @@
package iflytop.app.config;
import iflytop.app.hardware.type.CmdId;
import iflytop.app.hardware.type.LeisaiServoMId;
import iflytop.app.hardware.type.MId;
import iflytop.app.hardware.type.StepMotorMId;
import jakarta.annotation.PostConstruct;
@ -27,6 +28,8 @@ public class ActionOvertimeConstant {
// 设置电机默认超时时间
//
pushNewConfig(StepMotorMId.DoorM, CmdId.step_motor_easy_move_to_zero, 10 * 1000);
pushNewConfig(LeisaiServoMId.MainXSV, CmdId.leisai_servo_move_to, 20 * 1000);
pushNewConfig(LeisaiServoMId.MainYSV, CmdId.leisai_servo_move_to, 20 * 1000);
}
public Integer get(MId mid, CmdId cmdId) {
@ -42,6 +45,10 @@ public class ActionOvertimeConstant {
pushNewConfig(mid.mid, cmdId, overtime);
}
private void pushNewConfig(LeisaiServoMId mid, CmdId cmdId, Integer overtime) {
pushNewConfig(mid.mid, cmdId, overtime);
}
private void pushNewConfig(MId mid, CmdId cmdId, Integer overtime) {
OvertimeConfigItem item = new OvertimeConfigItem();
item.mid = mid;

26
src/main/java/iflytop/app/hardware/driver/LeisaiServoDriver.java

@ -1,6 +1,7 @@
package iflytop.app.hardware.driver;
import com.fasterxml.jackson.databind.node.ObjectNode;
import iflytop.app.config.ActionOvertimeConstant;
import iflytop.app.hardware.channel.A8kCanBusConnection;
import iflytop.app.hardware.channel.A8kCanBusService;
import iflytop.app.hardware.type.*;
@ -15,7 +16,7 @@ import org.springframework.stereotype.Component;
@RequiredArgsConstructor
public class LeisaiServoDriver {
final private A8kCanBusService canBus;
static public final Integer actionOvertime = 10000;
private final ActionOvertimeConstant actionOvertimeConstant;
public void moduleStop(LeisaiServoMId id) throws HardwareException {
log.info("moduleStop called with id: {}", id);
@ -64,6 +65,29 @@ public class LeisaiServoDriver {
canBus.moduleSetReg(id.mid, regindex.regIndex, val);
}
// ====== ===== ====== ===== ====== ===== Block ====== ===== ====== ===== ====== =====
public void moveToBlock(LeisaiServoMId id, LeisaiServoSpeedLevel speedLevel, Integer pos) throws HardwareException {
log.info("moveToBlock called with id: {}, speedLevel: {}, pos: {}", id, speedLevel, pos);
canBus.callcmd(id.mid, CmdId.leisai_servo_move_to, speedLevel.ordinal(), pos);
waitForMod(id, actionOvertimeConstant.get(id.mid, CmdId.leisai_servo_move_to));
}
public void moveByBlock(LeisaiServoMId id, LeisaiServoSpeedLevel speedLevel, Integer dpos) throws HardwareException {
log.info("moveByBlock called with id: {}, speedLevel: {}, dpos: {}", id, speedLevel, dpos);
canBus.callcmd(id.mid, CmdId.leisai_servo_move_by, speedLevel.ordinal(), dpos);
waitForMod(id, actionOvertimeConstant.get(id.mid, CmdId.leisai_servo_move_by));
}
public void moveToZeroBlock(LeisaiServoMId id) throws HardwareException {
log.info("moveToZeroBlock called with id: {}", id);
canBus.callcmd(id.mid, CmdId.leisai_servo_move_to_zero);
waitForMod(id, actionOvertimeConstant.get(id.mid, CmdId.leisai_servo_move_to_zero));
}
public void waitForMod(LeisaiServoMId id, Integer overtime) throws HardwareException {
canBus.waitForMod(id.mid, overtime);
}
public Integer getReg(LeisaiServoMId id, LeisaiRegIndex regindex) throws HardwareException {
log.info("getReg called with id: {}, regindex: {}", id, regindex);

13
src/main/java/iflytop/app/hardware/driver/LiquidDistributionArmDriver.java

@ -1,6 +1,7 @@
package iflytop.app.hardware.driver;
import com.fasterxml.jackson.databind.node.ObjectNode;
import iflytop.app.config.ActionOvertimeConstant;
import iflytop.app.hardware.channel.A8kCanBusService;
import iflytop.app.hardware.type.*;
import iflytop.app.type.exception.HardwareException;
@ -14,6 +15,7 @@ import org.springframework.stereotype.Component;
@RequiredArgsConstructor
public class LiquidDistributionArmDriver {
final private A8kCanBusService canBus;
private final ActionOvertimeConstant actionOvertimeConstant;
public void liquidDistributionArmEnable(LiquidArmMId id, int enable) throws HardwareException {
log.info("liquidDistributionArmEnable called with id: {}, enable: {}", id, enable);
@ -46,6 +48,17 @@ public class LiquidDistributionArmDriver {
canBus.moduleStop(id.mid);
}
// ====== ===== ====== ===== ====== ===== Block ====== ===== ====== ===== ====== =====
public void liquidDistributionArmMoveToBlock(LiquidArmMId id, int index) throws HardwareException {
liquidDistributionArmMoveTo(id, index);
waitForMod(id, actionOvertimeConstant.get(id.mid, CmdId.liquid_distribution_arm_move_to));
}
public void waitForMod(LiquidArmMId id, Integer overtime) throws HardwareException {
canBus.waitForMod(id.mid, overtime);
}
public void setReg(LiquidArmMId id, LiquidArmRegIndex regindex, int val) throws HardwareException {
log.info("setReg called with id: {}, regindex: {}, val: {}", id, regindex, val);
canBus.moduleSetReg(id.mid, regindex.regIndex, val);

6
src/main/java/iflytop/app/page/LeisaiServoPage.java

@ -64,17 +64,17 @@ public class LeisaiServoPage {
public void moveTo(Integer pos) throws Exception {
log.info("moveTo called with pos: {}", pos);
driver.moveTo(id, speedLevel, pos);
driver.moveToBlock(id, speedLevel, pos);
}
public void moveByForward() throws Exception {
log.info("moveByForward called with dpos: {}", dpos);
driver.moveBy(id, speedLevel, dpos);
driver.moveByBlock(id, speedLevel, dpos);
}
public void moveByBackward() throws Exception {
log.info("moveByBackward called with dpos: {}", dpos);
driver.moveBy(id, speedLevel, -dpos);
driver.moveByBlock(id, speedLevel, -dpos);
}
public void rotateForward() throws Exception {

2
src/main/java/iflytop/app/page/LiquidArmPage.java

@ -38,7 +38,7 @@ public class LiquidArmPage {
public void moveTo(Integer index) throws HardwareException {
log.info("moveTo called with index: {}", index);
liquidDistributionArmCtrlDriver.liquidDistributionArmMoveTo(id, index);
liquidDistributionArmCtrlDriver.liquidDistributionArmMoveToBlock(id, index);
}
public void setCurPosAsPresetPos(Integer index) throws HardwareException {

Loading…
Cancel
Save