|
|
@ -2,6 +2,7 @@ package com.iflytop.gd.infrastructure.devices; |
|
|
|
|
|
|
|
import com.iflytop.gd.infrastructure.drivers.CmdId; |
|
|
|
import com.iflytop.gd.infrastructure.drivers.ModuleId; |
|
|
|
import com.iflytop.gd.infrastructure.drivers.RegIndex; |
|
|
|
import com.iflytop.gd.system.constants.DistanceUnit; |
|
|
|
import com.iflytop.gd.system.constants.RotationDirection; |
|
|
|
import com.iflytop.gd.system.devices.StepMotor; |
|
|
@ -13,6 +14,9 @@ import com.iflytop.gd.system.models.DataPacket; |
|
|
|
import java.io.IOException; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
/** |
|
|
|
* 标准电机实现 |
|
|
|
*/ |
|
|
|
public class StandardStepMotor implements StepMotor { |
|
|
|
protected final ModuleId moduleId; |
|
|
|
protected final CommandBus commandBus; |
|
|
@ -143,12 +147,15 @@ public class StandardStepMotor implements StepMotor { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void setReg() { |
|
|
|
|
|
|
|
public void setReg(RegIndex regIndex, Integer value) throws HardwareErrorException, CommandExecTimeoutException, IOException, InterruptedException { |
|
|
|
DataPacket dataPacket = DataPacket.createCommandDataPacket(moduleId.index, CmdId.module_set_reg.index, value); |
|
|
|
commandBus.waitForCommandExec(dataPacket, DEFAULT_COMMAND_EXEC_TIMEOUT_SECONDS, TimeUnit.SECONDS); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Integer readReg() { |
|
|
|
return 0; |
|
|
|
public Integer readReg(RegIndex regIndex) throws HardwareErrorException, CommandExecTimeoutException, IOException, InterruptedException { |
|
|
|
DataPacket commandDataPacket = DataPacket.createCommandDataPacket(moduleId.index, CmdId.module_get_reg.index); |
|
|
|
DataPacket ackDataPacket = commandBus.waitForCommandExec(commandDataPacket, DEFAULT_COMMAND_EXEC_TIMEOUT_SECONDS, TimeUnit.SECONDS); |
|
|
|
return ackDataPacket.getContentI32(0); |
|
|
|
} |
|
|
|
} |