20 changed files with 414 additions and 38 deletions
-
1src/main/java/com/dreamworks/boditech/controller/DeviceController.java
-
7src/main/java/com/dreamworks/boditech/controller/TestController.java
-
3src/main/java/com/dreamworks/boditech/driver/Command.java
-
15src/main/java/com/dreamworks/boditech/driver/ConsumableBufferTube.java
-
9src/main/java/com/dreamworks/boditech/driver/ConsumablePipetteTip.java
-
116src/main/java/com/dreamworks/boditech/driver/Device.java
-
29src/main/java/com/dreamworks/boditech/driver/actuator/ActArmXY.java
-
13src/main/java/com/dreamworks/boditech/driver/actuator/ActMotor.java
-
7src/main/java/com/dreamworks/boditech/driver/actuator/ActuatorModule.java
-
17src/main/java/com/dreamworks/boditech/driver/consumable/CsmBufferTubeA.java
-
17src/main/java/com/dreamworks/boditech/driver/consumable/CsmBufferTubeB.java
-
22src/main/java/com/dreamworks/boditech/driver/consumable/CsmLargeBufferTube.java
-
15src/main/java/com/dreamworks/boditech/driver/consumable/CsmPipetteTip.java
-
9src/main/java/com/dreamworks/boditech/driver/task/TaskTest.java
-
7src/main/java/com/dreamworks/boditech/driver/task/step/Step.java
-
4src/main/java/com/dreamworks/boditech/driver/task/step/StepBase.java
-
46src/main/java/com/dreamworks/boditech/driver/task/step/StepManager.java
-
54src/main/java/com/dreamworks/boditech/driver/task/step/StepPuncture.java
-
50src/main/java/com/dreamworks/boditech/driver/task/step/StepShake.java
-
11src/main/java/com/dreamworks/boditech/service/DeviceService.java
@ -1,15 +0,0 @@ |
|||
package com.dreamworks.boditech.driver; |
|||
public class ConsumableBufferTube { |
|||
// project id |
|||
public Integer projectId; |
|||
// project name |
|||
public Integer projectName; |
|||
// batch number |
|||
public Integer type; |
|||
// location x |
|||
public Integer locationX; |
|||
// location y |
|||
public Integer locationY; |
|||
// location z |
|||
public Integer LocationZ; |
|||
} |
@ -1,9 +0,0 @@ |
|||
package com.dreamworks.boditech.driver; |
|||
public class ConsumablePipetteTip { |
|||
// location x |
|||
public Integer locationX; |
|||
// location y |
|||
public Integer locationY; |
|||
// location z |
|||
public Integer LocationZ; |
|||
} |
@ -0,0 +1,29 @@ |
|||
package com.dreamworks.boditech.driver.actuator; |
|||
import com.dreamworks.boditech.driver.Command; |
|||
import com.dreamworks.boditech.driver.Device; |
|||
public class ActArmXY extends ActuatorBase { |
|||
// constructor |
|||
public ActArmXY(Integer mid, Device device) { |
|||
super(mid, device); |
|||
} |
|||
|
|||
/** |
|||
* move to given position |
|||
* @param x x position |
|||
* @param y y position |
|||
*/ |
|||
public void moveTo(int x, int y) { |
|||
this.moveTo(x, y, 0); |
|||
} |
|||
|
|||
/** |
|||
* move to given position |
|||
* @param x x position |
|||
* @param y y position |
|||
* @param velocity 0: default velocity, otherwise: rpm per minute for motor |
|||
*/ |
|||
public void moveTo(int x, int y, int velocity) { |
|||
this.call(Command.CMD_XYMOTOR_MOVE_TO, x, y, velocity); |
|||
this.waitForFinish(); |
|||
} |
|||
} |
@ -0,0 +1,17 @@ |
|||
package com.dreamworks.boditech.driver.consumable; |
|||
public class CsmBufferTubeA { |
|||
// area index |
|||
public Integer areaIndex; |
|||
// position |
|||
public Integer position; |
|||
// project name |
|||
public String projectName = "demo"; |
|||
|
|||
public Integer getLocationX() { |
|||
return 1000; |
|||
} |
|||
|
|||
public Integer getLocationY() { |
|||
return 1000; |
|||
} |
|||
} |
@ -0,0 +1,17 @@ |
|||
package com.dreamworks.boditech.driver.consumable; |
|||
public class CsmBufferTubeB { |
|||
// area index |
|||
public Integer areaIndex; |
|||
// position |
|||
public Integer position; |
|||
// project name |
|||
public String projectName; |
|||
|
|||
public Integer getLocationX() { |
|||
return 0; |
|||
} |
|||
|
|||
public Integer getLocationY() { |
|||
return 0; |
|||
} |
|||
} |
@ -0,0 +1,22 @@ |
|||
package com.dreamworks.boditech.driver.consumable; |
|||
public class CsmLargeBufferTube { |
|||
// position |
|||
public Integer position; |
|||
// project name |
|||
public String projectName; |
|||
|
|||
// get location x |
|||
public Integer getLocationX() { |
|||
return 0; |
|||
} |
|||
|
|||
// get location y |
|||
public Integer getLocationY() { |
|||
return 0; |
|||
} |
|||
|
|||
// get if the tube is empty |
|||
public boolean isEmpty() { |
|||
return false; |
|||
} |
|||
} |
@ -0,0 +1,15 @@ |
|||
package com.dreamworks.boditech.driver.consumable; |
|||
public class CsmPipetteTip { |
|||
// area index |
|||
public Integer areaIndex; |
|||
// position |
|||
public Integer position; |
|||
|
|||
public Integer getLocationX() { |
|||
return 500; |
|||
} |
|||
|
|||
public Integer getLocationY() { |
|||
return 500; |
|||
} |
|||
} |
@ -0,0 +1,7 @@ |
|||
package com.dreamworks.boditech.driver.task.step; |
|||
import com.dreamworks.boditech.driver.Task; |
|||
import com.dreamworks.boditech.driver.TaskExecutor; |
|||
public interface Step { |
|||
// execute step |
|||
public void execute(TaskExecutor executor, Task task ); |
|||
} |
@ -0,0 +1,4 @@ |
|||
package com.dreamworks.boditech.driver.task.step; |
|||
abstract public class StepBase implements Step { |
|||
|
|||
} |
@ -0,0 +1,46 @@ |
|||
package com.dreamworks.boditech.driver.task.step; |
|||
import com.fasterxml.jackson.core.JsonProcessingException; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import com.fasterxml.jackson.databind.ObjectMapper; |
|||
import java.util.ArrayList; |
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
public class StepManager { |
|||
// step name to step class |
|||
private static final Map<String,Class<? extends Step>> stepMap = new HashMap<>(); |
|||
|
|||
// load step map |
|||
private static void loadStepMap() { |
|||
if ( !StepManager.stepMap.isEmpty() ) { |
|||
return ; |
|||
} |
|||
StepManager.stepMap.put("shake", StepShake.class); |
|||
StepManager.stepMap.put("puncture", StepPuncture.class); |
|||
} |
|||
|
|||
// build step by given name |
|||
public static List<Step> buildSteps(String json) { |
|||
StepManager.loadStepMap(); |
|||
|
|||
ObjectMapper jsonMapper = new ObjectMapper(); |
|||
JsonNode stepJsonTree = null; |
|||
try { |
|||
stepJsonTree = jsonMapper.readTree(json); |
|||
} catch (JsonProcessingException e) { |
|||
throw new RuntimeException(e); |
|||
} |
|||
|
|||
List<Step> steps = new ArrayList<>(); |
|||
for ( JsonNode stepNode : stepJsonTree ) { |
|||
String name = stepNode.get("action").asText(); |
|||
Class<? extends Step> stepClass = StepManager.stepMap.get(name); |
|||
if ( stepClass == null ) { |
|||
throw new RuntimeException("step class not found: " + name); |
|||
} |
|||
Step step = jsonMapper.convertValue(stepNode, stepClass); |
|||
steps.add(step); |
|||
} |
|||
return steps; |
|||
} |
|||
} |
@ -0,0 +1,54 @@ |
|||
package com.dreamworks.boditech.driver.task.step; |
|||
import com.dreamworks.boditech.driver.Device; |
|||
import com.dreamworks.boditech.driver.Task; |
|||
import com.dreamworks.boditech.driver.TaskExecutor; |
|||
import com.dreamworks.boditech.driver.actuator.ActArmXY; |
|||
import com.dreamworks.boditech.driver.actuator.ActMotor; |
|||
import com.dreamworks.boditech.driver.actuator.ActuatorModule; |
|||
import com.dreamworks.boditech.driver.consumable.CsmBufferTubeA; |
|||
import com.dreamworks.boditech.driver.consumable.CsmBufferTubeB; |
|||
import com.dreamworks.boditech.driver.consumable.CsmPipetteTip; |
|||
import com.dreamworks.boditech.driver.task.TaskTest; |
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
public class StepPuncture extends StepBase { |
|||
@JsonProperty("action") |
|||
public String action; |
|||
|
|||
@JsonProperty("tubeType") |
|||
public String tubeType; |
|||
|
|||
@Override |
|||
public void execute(TaskExecutor executor, Task task) { |
|||
Device device = executor.getDevice(); |
|||
ActArmXY armXY = (ActArmXY)device.getActuator(ActuatorModule.ARM_XY); |
|||
ActMotor armZMotor = (ActMotor)device.getActuator(ActuatorModule.ARM_Z_MOTOR); |
|||
TaskTest taskTest = (TaskTest)task; |
|||
|
|||
// 01. 移动到TIP区域 |
|||
CsmPipetteTip tip = device.getPipeTip(); |
|||
armXY.moveTo(tip.getLocationX(), tip.getLocationY()); |
|||
|
|||
// 02. 下降到TIP区域 |
|||
armZMotor.moveTo(1000); |
|||
|
|||
// 03. 上升到准备区域 |
|||
armZMotor.moveTo(0); |
|||
|
|||
// 04. 移动到穿刺区域 |
|||
if ( "A".equals(this.tubeType) ) { |
|||
CsmBufferTubeA tube = device.getBufferTubeA(taskTest.projectName); |
|||
armXY.moveTo(tube.getLocationX(), tube.getLocationY()); |
|||
} else if ( "B".equals(this.tubeType) ) { |
|||
CsmBufferTubeB tube = device.getBufferTubeB(taskTest.projectName); |
|||
armXY.moveTo(tube.getLocationX(), tube.getLocationY()); |
|||
} else { |
|||
throw new RuntimeException("unknown tube type " + this.tubeType); |
|||
} |
|||
|
|||
// 05. 下降到穿刺区域 |
|||
armZMotor.moveTo(1000); |
|||
|
|||
// 06. 上升到准备区域 |
|||
armZMotor.moveTo(0); |
|||
} |
|||
} |
@ -0,0 +1,50 @@ |
|||
package com.dreamworks.boditech.driver.task.step; |
|||
import com.dreamworks.boditech.driver.Device; |
|||
import com.dreamworks.boditech.driver.Task; |
|||
import com.dreamworks.boditech.driver.TaskExecutor; |
|||
import com.dreamworks.boditech.driver.actuator.ActMotor; |
|||
import com.dreamworks.boditech.driver.actuator.ActuatorModule; |
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
public class StepShake extends StepBase { |
|||
@JsonProperty("action") |
|||
public String action; |
|||
|
|||
@Override |
|||
public void execute(TaskExecutor executor, Task task) { |
|||
Device device = executor.getDevice(); |
|||
ActMotor testTubeCapClipMotor = (ActMotor)device.getActuator(ActuatorModule.TEST_TUBE_SHAKING_CAP_CLIP_MOTOR); |
|||
ActMotor testTubeShakeMotor = (ActMotor)device.getActuator(ActuatorModule.TEST_TUBE_SHAKING_SHAKE_MOTOR); |
|||
ActMotor testTubeMoveMotor = (ActMotor)device.getActuator(ActuatorModule.TEST_TUBE_SHAKING_MOVE_MOTOR); |
|||
ActMotor testTubeClipMotor = (ActMotor)device.getActuator(ActuatorModule.TEST_TUBE_SHAKING_CLIP_MOTOR); |
|||
|
|||
// 01. 试管帽夹打开 |
|||
testTubeCapClipMotor.moveTo(500); |
|||
|
|||
// 02. 下降到试管位置 |
|||
testTubeMoveMotor.moveTo(150); |
|||
|
|||
// 03. 试管帽夹关闭 |
|||
testTubeCapClipMotor.moveTo(900); |
|||
|
|||
// 04. 上升到摇晃位置 |
|||
testTubeMoveMotor.moveTo(1300); |
|||
|
|||
// 05. 摇晃 |
|||
testTubeShakeMotor.rotate(ActMotor.ROTATE_DIRECTION_CLOCKWISE); |
|||
try { |
|||
Thread.sleep(3000); |
|||
} catch (InterruptedException e) { |
|||
throw new RuntimeException(e); |
|||
} |
|||
testTubeShakeMotor.stop(); |
|||
|
|||
// 06. 下降到试管位置 |
|||
testTubeMoveMotor.moveTo(150); |
|||
|
|||
// 07. 试管夹夹紧 |
|||
testTubeClipMotor.rotate(ActMotor.ROTATE_DIRECTION_CLOCKWISE); |
|||
|
|||
// 08. 上升到原始位置 |
|||
testTubeMoveMotor.moveTo(1300); |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue