Skip to content
Snippets Groups Projects
Commit 30773aee authored by René Schöne's avatar René Schöne
Browse files

again new try for position calculation

- still not perfect (oszillation possible)
- add a few more locations in configs
parent b6880ac9
Branches
No related tags found
No related merge requests found
Pipeline #13658 passed
{ {
"regions": [ "regions": [
{ "name": "G", "positions": ["target_Blue"] }, { "name": "G", "positions": ["target_Blue"] },
{ "name": "I", "positions": ["target_Green"] } { "name": "G", "positions": ["target_Green"] }
] ]
} }
...@@ -100,11 +100,22 @@ CommandCheckForOccupiedCollaborationZone maps byte[] bytes to String {: ...@@ -100,11 +100,22 @@ CommandCheckForOccupiedCollaborationZone maps byte[] bytes to String {:
reject(); reject();
} }
// if target is collaboration zone
ObjectOfInterest obj = scene.resolveObjectOfInterest(pp.getIdPlace()); ObjectOfInterest obj = scene.resolveObjectOfInterest(pp.getIdPlace());
DropOffLocation loc = obj.asDropOffLocation(); DropOffLocation loc = obj.asDropOffLocation();
if (loc.isCollaborationZone()) { if (loc.isCollaborationZone()) {
CollaborationZone cz = loc.asCollaborationZone(); String specialIncomingName = "(>)" + loc.getName();
String specialIncomingName = "(>)" + cz.getName(); if (!occupiedZoneNames.contains(specialIncomingName)) {
occupiedZoneNames.add(specialIncomingName);
updated = true;
}
}
// if object is located at collaboration zone
LogicalObjectOfInterest logicalObj = scene.getLogicalScene().resolveLogicalObjectOfInterest(pp.getIdPick());
LogicalMovableObject toBePicked = logicalObj.asLogicalMovableObject();
DropOffLocation sourceLocation = toBePicked.myLocation();
if (sourceLocation != null && sourceLocation.isCollaborationZone()) {
String specialIncomingName = "(^)" + sourceLocation.getName();
if (!occupiedZoneNames.contains(specialIncomingName)) { if (!occupiedZoneNames.contains(specialIncomingName)) {
occupiedZoneNames.add(specialIncomingName); occupiedZoneNames.add(specialIncomingName);
updated = true; updated = true;
......
...@@ -314,29 +314,43 @@ aspect Computation { ...@@ -314,29 +314,43 @@ aspect Computation {
for (String zoneName : arrayAsList(getOccupiedCollaborationZoneNames())) { for (String zoneName : arrayAsList(getOccupiedCollaborationZoneNames())) {
if (zoneName.startsWith("(>)")) { if (zoneName.startsWith("(>)")) {
String targetZone = zoneName.substring(3); String targetZone = zoneName.substring(3);
if (getCurrentPosition().equals(zoneName) && myState == de.tudresden.inf.st.ceti.Object.State.STATE_IDLE) { // (1)
System.out.println(pre + targetZone); String currentTarget = getCurrentPosition().startsWith("(") ? getCurrentPosition().substring(3) : getCurrentPosition();
return targetZone; // robot was moving and has now reached its target if (!targetZone.equals(currentTarget) && myState == de.tudresden.inf.st.ceti.Object.State.STATE_IDLE) {
return logAndReturn(pre, "(+)" + targetZone);
} }
if (isStateMoving(myState) || "unknown".equals(getCurrentPosition())) {
System.out.println(pre + zoneName);
return zoneName; // actually return (>) + targetZone
} }
// (2) // getCurrentPosition().startsWith("(+)") &&
if (isStateMoving(myState)) {
return logAndReturn(pre, zoneName);
}
// (3)
if (getCurrentPosition().startsWith("(>)") && myState == de.tudresden.inf.st.ceti.Object.State.STATE_IDLE) {
return logAndReturn(pre, getCurrentPosition().substring(3));
} }
if (zoneName.startsWith("(^)")) { if (zoneName.startsWith("(^)")) {
String targetZone = zoneName.substring(3); String sourceZone = zoneName.substring(3);
if (getCurrentPosition().equals(zoneName) && myState == de.tudresden.inf.st.ceti.Object.State.STATE_IDLE) { // (4)
System.out.println(pre + "(empty)"); if (!getCurrentPosition().startsWith("(^)") && !getCurrentPosition().equals("safe") && myState == de.tudresden.inf.st.ceti.Object.State.STATE_IDLE) {
return ""; // robot was moving and has now reached its target return logAndReturn(pre, "(-)" + sourceZone);
}
// (6)
if (getCurrentPosition().startsWith("(^)") && myState == de.tudresden.inf.st.ceti.Object.State.STATE_IDLE) {
return logAndReturn(pre, "safe");
} }
if (isStateMoving(myState) || "unknown".equals(getCurrentPosition())) {
System.out.println(pre + zoneName);
return zoneName; // actually return (^) + targetZone
} }
// (5)
if (getCurrentPosition().startsWith("(-)") && isStateMoving(myState)) {
return logAndReturn(pre, "(^)" + getCurrentPosition().substring(3));
} }
} }
System.out.println(pre + getCurrentPosition()); // no-op
return getCurrentPosition(); return logAndReturn(pre, getCurrentPosition());
}
private String Robot.logAndReturn(String pre, String returnValue) {
System.out.println(pre + returnValue);
return returnValue;
} }
private boolean Robot.isStateMoving(de.tudresden.inf.st.ceti.Object.State state) { private boolean Robot.isStateMoving(de.tudresden.inf.st.ceti.Object.State state) {
...@@ -404,16 +418,9 @@ aspect Navigation { ...@@ -404,16 +418,9 @@ aspect Navigation {
syn Robot CollaborationZone.occupient() { syn Robot CollaborationZone.occupient() {
// (>) == moving in, (^) == evacuate/moving out // (>) == moving in, (^) == evacuate/moving out
for (Robot robot : worldModelB().getRobotList()) { for (Robot robot : worldModelB().getRobotList()) {
String zoneName = robot.getCurrentPosition(); String zoneName = robot.getCurrentPosition().startsWith("(") ? robot.getCurrentPosition().substring(3) : robot.getCurrentPosition();
if (zoneName.startsWith("(>)") && zoneName.substring(3).equals(getName())) {
// robot is currently moving into this zone. always regard it as occupied by it
return robot;
}
if (zoneName.startsWith("(^)") && zoneName.substring(3).equals(getName())) {
// robot is moving out of this zone. also regard it as occupied
return robot;
}
if (zoneName.equals(getName())) { if (zoneName.equals(getName())) {
// robot is currently in this zone, or moving into or out of this zone. always regard it as occupied by it
return robot; return robot;
} }
} }
......
...@@ -45,6 +45,7 @@ public class MainB extends SharedMainParts<MqttHandler, WorldModelB> { ...@@ -45,6 +45,7 @@ public class MainB extends SharedMainParts<MqttHandler, WorldModelB> {
protected void createSpecificMainHandlerConnections() { protected void createSpecificMainHandlerConnections() {
mainHandler.newConnection("place-b/demo", bytes -> { mainHandler.newConnection("place-b/demo", bytes -> {
String topic = new String(bytes); String topic = new String(bytes);
int slashIndex;
switch (topic) { switch (topic) {
case "objectRed1/red": case "objectRed1/red":
UtilB.updatePositionOfObjectToLocation(model.getMyScene(), "objectRed1", "binRed"); UtilB.updatePositionOfObjectToLocation(model.getMyScene(), "objectRed1", "binRed");
...@@ -65,29 +66,32 @@ public class MainB extends SharedMainParts<MqttHandler, WorldModelB> { ...@@ -65,29 +66,32 @@ public class MainB extends SharedMainParts<MqttHandler, WorldModelB> {
case "arm2/picking": case "arm2/picking":
case "arm2/placing": case "arm2/placing":
case "arm2/moving": case "arm2/moving":
int slashIndex = topic.indexOf("/"); slashIndex = topic.indexOf("/");
String robot = topic.substring(0, slashIndex); String robot = topic.substring(0, slashIndex);
String stateString = "STATE_" + topic.substring(slashIndex + 1).toUpperCase(); String stateString = "STATE_" + topic.substring(slashIndex + 1).toUpperCase();
Object.State state = Object.State.valueOf(stateString); Object.State state = Object.State.valueOf(stateString);
updateAndPublishScene(robot, r -> r.toBuilder().setState(state).build()); updateAndPublishScene(robot, r -> r.toBuilder().setState(state).build());
break; break;
case "big-blue/cz": case "bigBlue/cz1":
updateAndPublishScene("bigBlue", bigBlue -> { case "bigBlue/G1":
Object.Builder builder = bigBlue.toBuilder(); case "bigBlue/G2":
case "bigBlue/I1":
case "bigBlue/I2":
case "bigGreen/cz1":
case "bigGreen/G1":
case "bigGreen/G2":
case "bigGreen/I1":
case "bigGreen/I2":
slashIndex = topic.indexOf("/");
String obj = topic.substring(0, slashIndex);
String location = topic.substring(slashIndex + 1);
Position pos = model.getMyScene().resolveObjectOfInterest(location).asDropOffLocation().getPosition();
updateAndPublishScene(obj, o -> {
Object.Builder builder = o.toBuilder();
builder.getPosBuilder() builder.getPosBuilder()
.setX(0.0012) .setX(pos.getX())
.setY(0.65) .setY(pos.getY())
.setZ(0.94); .setZ(pos.getZ());
return builder.build();
});
break;
case "big-blue/g1":
updateAndPublishScene("bigBlue", bigBlue -> {
Object.Builder builder = bigBlue.toBuilder();
builder.getPosBuilder()
.setX(0.1)
.setY(1.0)
.setZ(0.93);
return builder.build(); return builder.build();
}); });
break; break;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
"name": "arm2", "name": "arm2",
"reachableLocations": [ "reachableLocations": [
"cz1", "cz1",
"G1", "G1", "G2", "G3", "G4",
"I1", "I2", "I3" ,"I4" "I1", "I2", "I3" ,"I4"
] ]
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
{ "name": "D", "positions": ["D1"] }, { "name": "D", "positions": ["D1"] },
{ "name": "E", "positions": ["E1"] }, { "name": "E", "positions": ["E1"] },
{ "name": "F", "positions": ["F1"] }, { "name": "F", "positions": ["F1"] },
{ "name": "G", "positions": ["G1"] }, { "name": "G", "positions": ["G1", "G2", "G3", "G4"] },
{ "name": "H", "positions": ["H1"] }, { "name": "H", "positions": ["H1"] },
{ "name": "I", "positions": ["I1", "I2", "I3", "I4"] }, { "name": "I", "positions": ["I1", "I2", "I3", "I4"] },
{ "name": "CZ", "positions": ["cz1"] } { "name": "CZ", "positions": ["cz1"] }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment