8 changed files with 266 additions and 41 deletions
-
65src/main/java/com/iflytop/gd/infrastructure/devices/StandardServoMotor.java
-
75src/main/java/com/iflytop/gd/infrastructure/devices/VirtualServoMotor.java
-
50src/main/java/com/iflytop/gd/infrastructure/devices/VirtualStepMotor.java
-
11src/main/java/com/iflytop/gd/system/devices/Door.java
-
62src/main/java/com/iflytop/gd/system/devices/ServoMotor.java
-
12src/main/java/com/iflytop/gd/system/models/ServoMotorStatus.java
-
2src/main/java/com/iflytop/gd/system/models/StepMotorStatus.java
@ -0,0 +1,65 @@ |
|||
package com.iflytop.gd.infrastructure.devices; |
|||
|
|||
import com.iflytop.gd.infrastructure.drivers.RegIndex; |
|||
import com.iflytop.gd.system.devices.ServoMotor; |
|||
|
|||
|
|||
/** |
|||
* 标准物理伺服电机 |
|||
*/ |
|||
public class StandardServoMotor implements ServoMotor { |
|||
@Override |
|||
public void enable() { |
|||
|
|||
} |
|||
|
|||
@Override |
|||
public void disable() { |
|||
|
|||
} |
|||
|
|||
@Override |
|||
public void stop() { |
|||
|
|||
} |
|||
|
|||
@Override |
|||
public Integer getCurrentPosition() { |
|||
return 0; |
|||
} |
|||
|
|||
@Override |
|||
public void moveToZero() { |
|||
|
|||
} |
|||
|
|||
@Override |
|||
public void moveTo(Integer position) { |
|||
|
|||
} |
|||
|
|||
@Override |
|||
public void setMaxVelocity(Integer maxVelocity) { |
|||
|
|||
} |
|||
|
|||
@Override |
|||
public void setMaxTorque(Integer maxTorque) { |
|||
|
|||
} |
|||
|
|||
@Override |
|||
public void setProtectiveTorque(Integer protectiveTorque) { |
|||
|
|||
} |
|||
|
|||
@Override |
|||
public Integer readReg(RegIndex regIndex) { |
|||
return 0; |
|||
} |
|||
|
|||
@Override |
|||
public void writeReg(RegIndex regIndex, Integer value) { |
|||
|
|||
} |
|||
} |
@ -0,0 +1,75 @@ |
|||
package com.iflytop.gd.infrastructure.devices; |
|||
|
|||
import com.iflytop.gd.infrastructure.drivers.RegIndex; |
|||
import com.iflytop.gd.system.devices.ServoMotor; |
|||
import com.iflytop.gd.system.models.ServoMotorStatus; |
|||
import org.springframework.context.annotation.Profile; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
|
|||
/** |
|||
* 虚拟伺服电机 |
|||
*/ |
|||
@Component |
|||
@Profile("dev") |
|||
public class VirtualServoMotor implements ServoMotor { |
|||
private final ServoMotorStatus servoMotorStatus = new ServoMotorStatus(); |
|||
private final Map<RegIndex, Integer> registers = new HashMap<RegIndex, Integer>(); |
|||
@Override |
|||
public void enable() { |
|||
this.servoMotorStatus.setEnabled(true); |
|||
} |
|||
|
|||
@Override |
|||
public void disable() { |
|||
this.servoMotorStatus.setEnabled(false); |
|||
} |
|||
|
|||
@Override |
|||
public void stop() { |
|||
this.servoMotorStatus.setStopped(true); |
|||
} |
|||
|
|||
@Override |
|||
public Integer getCurrentPosition() { |
|||
return this.servoMotorStatus.getCurrentPosition(); |
|||
} |
|||
|
|||
@Override |
|||
public void moveToZero() { |
|||
this.servoMotorStatus.setCurrentPosition(0); |
|||
} |
|||
|
|||
@Override |
|||
public void moveTo(Integer position) { |
|||
this.servoMotorStatus.setCurrentPosition(position); |
|||
} |
|||
|
|||
@Override |
|||
public void setMaxVelocity(Integer maxVelocity) { |
|||
//TODO 等待硬件给出寄存器索引 |
|||
} |
|||
|
|||
@Override |
|||
public void setMaxTorque(Integer maxTorque) { |
|||
//TODO 等待硬件给出寄存器索引 |
|||
} |
|||
|
|||
@Override |
|||
public void setProtectiveTorque(Integer protectiveTorque) { |
|||
//TODO 等待硬件给出寄存器索引 |
|||
} |
|||
|
|||
@Override |
|||
public Integer readReg(RegIndex regIndex) { |
|||
return this.registers.get(regIndex); |
|||
} |
|||
|
|||
@Override |
|||
public void writeReg(RegIndex regIndex, Integer value) { |
|||
this.registers.put(regIndex, value); |
|||
} |
|||
} |
@ -1,7 +1,18 @@ |
|||
package com.iflytop.gd.system.devices; |
|||
|
|||
public interface Door { |
|||
/** |
|||
* 开门 |
|||
*/ |
|||
void open(); |
|||
|
|||
/** |
|||
* 关门 |
|||
*/ |
|||
void close(); |
|||
|
|||
/** |
|||
* 停止 |
|||
*/ |
|||
void stop(); |
|||
} |
@ -1,20 +1,82 @@ |
|||
package com.iflytop.gd.system.devices; |
|||
|
|||
|
|||
import com.iflytop.gd.infrastructure.drivers.RegIndex; |
|||
|
|||
/** |
|||
* 伺服电机 |
|||
*/ |
|||
public interface ServoMotor { |
|||
|
|||
/** |
|||
* 使能 |
|||
*/ |
|||
void enable(); |
|||
|
|||
/** |
|||
* 失能 |
|||
*/ |
|||
void disable(); |
|||
|
|||
/** |
|||
* 停止 |
|||
*/ |
|||
void stop(); |
|||
|
|||
|
|||
/** |
|||
* 获取当前位置 |
|||
* @return |
|||
*/ |
|||
Integer getCurrentPosition(); |
|||
|
|||
|
|||
/** |
|||
* 移动到零点 |
|||
*/ |
|||
void moveToZero(); |
|||
|
|||
|
|||
/** |
|||
* 移动到指定位置 |
|||
* @param position |
|||
*/ |
|||
void moveTo(Integer position); |
|||
|
|||
/****************寄存器配置开始*****************/ |
|||
|
|||
/** |
|||
* 设置最大速度 |
|||
* @param maxVelocity |
|||
*/ |
|||
void setMaxVelocity(Integer maxVelocity); |
|||
|
|||
/** |
|||
* 设置最大力矩 |
|||
* @param maxTorque |
|||
*/ |
|||
void setMaxTorque(Integer maxTorque); |
|||
|
|||
/** |
|||
* 设置保护力矩 |
|||
* @param protectiveTorque |
|||
*/ |
|||
void setProtectiveTorque(Integer protectiveTorque); |
|||
|
|||
|
|||
/** |
|||
* 读取寄存器值 |
|||
* @param regIndex |
|||
* @return |
|||
*/ |
|||
Integer readReg(RegIndex regIndex); |
|||
|
|||
|
|||
/** |
|||
* 设置寄存器 |
|||
* @param regIndex |
|||
* @param value |
|||
*/ |
|||
void writeReg(RegIndex regIndex, Integer value); |
|||
/****************寄存器配置结束*****************/ |
|||
} |
@ -0,0 +1,12 @@ |
|||
package com.iflytop.gd.system.models; |
|||
|
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
@Getter |
|||
@Setter |
|||
public class ServoMotorStatus { |
|||
private boolean stopped = false; |
|||
private boolean isEnabled = false; |
|||
private Integer currentPosition; |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue