4 changed files with 411 additions and 55 deletions
-
70src/main/java/com/iflytop/gd/infrastructure/devices/StandardStepMotor.java
-
170src/main/java/com/iflytop/gd/infrastructure/devices/VirtualStepMotor.java
-
213src/main/java/com/iflytop/gd/system/devices/StepMotor.java
-
13src/main/java/com/iflytop/gd/system/models/MotorStatus.java
@ -0,0 +1,170 @@ |
|||||
|
package com.iflytop.gd.infrastructure.devices; |
||||
|
|
||||
|
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; |
||||
|
import com.iflytop.gd.system.exceptions.CommandExecTimeoutException; |
||||
|
import com.iflytop.gd.system.exceptions.HardwareErrorException; |
||||
|
import com.iflytop.gd.system.models.MotorStatus; |
||||
|
|
||||
|
import java.io.IOException; |
||||
|
import java.util.HashMap; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
public class VirtualStepMotor implements StepMotor { |
||||
|
private MotorStatus motorStatus; |
||||
|
private Map<RegIndex, Integer> registers = new HashMap<RegIndex, Integer>(); |
||||
|
|
||||
|
@Override |
||||
|
public void easyMoveBy(Integer value, DistanceUnit unit) throws HardwareErrorException, CommandExecTimeoutException, IOException, InterruptedException { |
||||
|
int position = this.motorStatus.getCurrentPosition() + unit.toMM(value); |
||||
|
this.motorStatus.setCurrentPosition(position); |
||||
|
this.motorStatus.setStopped(true); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void easyMoveTo(Integer value, DistanceUnit unit) throws HardwareErrorException, CommandExecTimeoutException, IOException, InterruptedException { |
||||
|
this.motorStatus.setCurrentPosition(unit.toMM(value)); |
||||
|
this.motorStatus.setZeroPosition(this.motorStatus.getCurrentPosition() == 0); |
||||
|
this.motorStatus.setStopped(true); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void easyMoveToZero() throws HardwareErrorException, CommandExecTimeoutException, IOException, InterruptedException { |
||||
|
this.motorStatus.setCurrentPosition(0); |
||||
|
this.motorStatus.setZeroPosition(this.motorStatus.getCurrentPosition() == 0); |
||||
|
this.motorStatus.setStopped(true); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void easyMoveToZeroPointQuick() { |
||||
|
this.motorStatus.setCurrentPosition(0); |
||||
|
this.motorStatus.setZeroPosition(this.motorStatus.getCurrentPosition() == 0); |
||||
|
this.motorStatus.setStopped(true); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void enable() { |
||||
|
this.motorStatus.setEnabled(true); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void disable() { |
||||
|
this.motorStatus.setEnabled(false); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void moveForward(RotationDirection direction, Integer distance, DistanceUnit unit) throws HardwareErrorException, CommandExecTimeoutException, IOException, InterruptedException { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void moveBackward(RotationDirection direction, Integer distance, DistanceUnit unit) throws HardwareErrorException, CommandExecTimeoutException, IOException, InterruptedException { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void stop() { |
||||
|
this.motorStatus.setStopped(true); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void rotateForward() { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void rotateBackward() { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Map<String, Boolean> readIOState() { |
||||
|
Map<String, Boolean> ioState = new HashMap<>(); |
||||
|
ioState.put("IO1", true); |
||||
|
ioState.put("IO2", false); |
||||
|
return ioState; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Integer readPosition() { |
||||
|
return this.motorStatus.getCurrentPosition(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Integer readEncoderPosition() { |
||||
|
return this.motorStatus.getEncoderPosition(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void setReg(RegIndex regIndex, Integer value) throws HardwareErrorException, CommandExecTimeoutException, IOException, InterruptedException { |
||||
|
this.registers.put(regIndex, value); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Integer readReg(RegIndex regIndex) throws HardwareErrorException, CommandExecTimeoutException, IOException, InterruptedException { |
||||
|
return this.registers.get(regIndex); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void setMRes(Integer value) throws HardwareErrorException, CommandExecTimeoutException, IOException, InterruptedException { |
||||
|
setReg(RegIndex.kreg_step_motor_mres, value); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void setIRun(Integer value) throws HardwareErrorException, CommandExecTimeoutException, IOException, InterruptedException { |
||||
|
setReg(RegIndex.kreg_step_motor_irun, value); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void setIHold(Integer value) throws HardwareErrorException, CommandExecTimeoutException, IOException, InterruptedException { |
||||
|
setReg(RegIndex.kreg_step_motor_ihold, value); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void setStartAndStopVelocity(Integer value) throws HardwareErrorException, CommandExecTimeoutException, IOException, InterruptedException { |
||||
|
setReg(RegIndex.kreg_step_motor_vstart, value); |
||||
|
setReg(RegIndex.kreg_step_motor_vstop, value); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void setV1(Integer value) throws HardwareErrorException, CommandExecTimeoutException, IOException, InterruptedException { |
||||
|
setReg(RegIndex.kreg_step_motor_v1, value); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void setA1AndD1(Integer value) throws HardwareErrorException, CommandExecTimeoutException, IOException, InterruptedException { |
||||
|
setReg(RegIndex.kreg_step_motor_a1, value); |
||||
|
setReg(RegIndex.kreg_step_motor_d1, value); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void setAmaxAndDmax(Integer value) throws HardwareErrorException, CommandExecTimeoutException, IOException, InterruptedException { |
||||
|
setReg(RegIndex.kreg_step_motor_amax, value); |
||||
|
setReg(RegIndex.kreg_step_motor_dmax, value); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void setDefaultVelocity(Integer value) throws HardwareErrorException, CommandExecTimeoutException, IOException, InterruptedException { |
||||
|
setReg(RegIndex.kreg_step_motor_default_velocity, value); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void setVelocity(Integer low, Integer mid, Integer high) throws HardwareErrorException, CommandExecTimeoutException, IOException, InterruptedException { |
||||
|
setReg(RegIndex.kreg_step_motor_low_velocity, low); |
||||
|
setReg(RegIndex.kreg_step_motor_mid_velocity, mid); |
||||
|
setReg(RegIndex.kreg_step_motor_high_velocity, high); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void setOneCyclePulse(Integer pause, Integer denominator) throws HardwareErrorException, CommandExecTimeoutException, IOException, InterruptedException { |
||||
|
setReg(RegIndex.kreg_step_motor_one_circle_pulse, pause); |
||||
|
setReg(RegIndex.kreg_step_motor_one_circle_pulse_denominator, denominator); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void setDZero(Integer value) throws HardwareErrorException, CommandExecTimeoutException, IOException, InterruptedException { |
||||
|
setReg(RegIndex.kreg_step_motor_dzero_pos, value); |
||||
|
} |
||||
|
} |
@ -1,5 +1,16 @@ |
|||||
package com.iflytop.gd.system.models; |
package com.iflytop.gd.system.models; |
||||
|
|
||||
|
import lombok.Getter; |
||||
|
import lombok.Setter; |
||||
|
|
||||
|
@Getter |
||||
|
@Setter |
||||
public class MotorStatus { |
public class MotorStatus { |
||||
private Integer speed; |
|
||||
|
private boolean stopped = false; |
||||
|
private boolean isEnabled = false; |
||||
|
private Integer currentSpeed; |
||||
|
private Integer currentPosition; |
||||
|
private Integer encoderPosition; |
||||
|
private boolean isZeroPosition = true; |
||||
|
private boolean isLimitPosition = false; |
||||
} |
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue