|
|
@ -1,12 +1,14 @@ |
|
|
|
package com.iflytop.gd.hardware.drivers; |
|
|
|
|
|
|
|
import com.iflytop.gd.hardware.comm.can.A8kCanBusService; |
|
|
|
import com.iflytop.gd.hardware.constants.ActionOvertimeConstant; |
|
|
|
import com.iflytop.gd.hardware.exception.HardwareException; |
|
|
|
import com.iflytop.gd.hardware.type.A8kPacket; |
|
|
|
import com.iflytop.gd.hardware.type.CmdId; |
|
|
|
import com.iflytop.gd.hardware.type.Servo.LeisaiRegIndex; |
|
|
|
import com.iflytop.gd.hardware.type.Servo.LeisaiServoMId; |
|
|
|
import com.iflytop.gd.hardware.type.Servo.LeisaiServoSpeedLevel; |
|
|
|
import com.iflytop.gd.hardware.type.StepMotor.StepMotorMId; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
@ -16,6 +18,7 @@ import org.springframework.stereotype.Component; |
|
|
|
@RequiredArgsConstructor |
|
|
|
public class LeisaiServoDriver { |
|
|
|
final private A8kCanBusService canBus; |
|
|
|
private final ActionOvertimeConstant actionOvertimeConstant; |
|
|
|
static public final Integer actionOvertime = 10000; |
|
|
|
|
|
|
|
public void moduleStop(LeisaiServoMId id) throws HardwareException { |
|
|
@ -60,6 +63,29 @@ public class LeisaiServoDriver { |
|
|
|
canBus.callcmd(id.mid, CmdId.leisai_servo_move_to_zero); |
|
|
|
} |
|
|
|
|
|
|
|
// ====== ===== ====== ===== ====== ===== 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 void setReg(LeisaiServoMId id, LeisaiRegIndex regindex, int val) throws HardwareException { |
|
|
|
log.info("setReg called with id: {}, regindex: {}, val: {}", id, regindex, val); |
|
|
|
canBus.moduleSetReg(id.mid, regindex.regIndex, val); |
|
|
|