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

update grammars

- remove robot in placeA
- connect indexed list for other logical scenes in placeB (new ragconnect feature)
parent deb29eb9
No related branches found
No related tags found
No related merge requests found
Showing
with 42 additions and 92 deletions
aspect Resolving {
//--- resolveObjectOfInterest ---
inh ObjectOfInterest Robot.resolveObjectOfInterest(String name);
eq WorldModelA.getRobot().resolveObjectOfInterest(String name) {
return getScene().resolveObjectOfInterest(name);
}
}
aspect Glue {
class WorldModelA implements de.tudresden.inf.st.ros3rag.common.SharedMainParts.WorldModelWrapper {}
......
WorldModelA ::= Robot [Scene] /LogicalScene/ ;
Robot ::= <Name:String> ;
WorldModelA ::= [Scene] /LogicalScene/ ;
package de.tudresden.inf.st.placeA;
import de.tudresden.inf.st.placeA.ast.MqttHandler;
import de.tudresden.inf.st.placeA.ast.Robot;
import de.tudresden.inf.st.placeA.ast.Scene;
import de.tudresden.inf.st.placeA.ast.WorldModelA;
import de.tudresden.inf.st.ros3rag.common.SharedMainParts;
import de.tudresden.inf.st.ros3rag.common.Util;
import java.io.IOException;
......@@ -58,20 +56,14 @@ public class MainA extends SharedMainParts<MqttHandler, WorldModelA> {
@Override
protected de.tudresden.inf.st.ceti.Scene readSceneAndRobots() throws Exception {
/// Reading scene and robot
/// Reading scene
de.tudresden.inf.st.ceti.Scene scene = readScene(
UtilA.pathToDirectoryOfPlaceA().resolve(config.filenameInitialScene)
);
Scene myScene = UtilA.convert(scene);
model.setScene(myScene);
// if multiple robots are specified, then error message will be displayed
Util.extractRobotNames(scene).forEach(name -> {
if (model.getRobot() != null) {
logger.error("Robot already set. Overriding with newly found name.");
}
model.setRobot(new Robot().setName(name));
});
// no robots to be set
return scene;
}
......
package de.tudresden.inf.st.placeA;
import de.tudresden.inf.st.ceti.Object;
import de.tudresden.inf.st.placeA.ast.*;
import org.apache.commons.math3.geometry.euclidean.threed.Rotation;
import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.nio.file.Paths;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;
......@@ -37,19 +35,6 @@ public class SimpleMainA {
var model = new WorldModelA();
model.setScene(myScene);
// find robot (should be only one)
for (var obj : scene.getObjectsList()) {
if (obj.getType().equals(Object.Type.ARM)) {
if (model.getRobot() != null) {
logger.error("Found multiple robots in scene for place A!");
}
model.setRobot(new Robot().setName(obj.getId()));
}
}
if (model.getRobot() == null) {
logger.error("Found no robots in scene for place A!");
}
// send initial scene once
// MqttHandler publisher = new MqttHandler().dontSendWelcomeMessage().setHost("localhost");
// publisher.publish("scene/init", scene.toByteArray());
......@@ -66,11 +51,6 @@ public class SimpleMainA {
private static void testBuildModelA() {
WorldModelA model = new WorldModelA();
// robot
Robot robot = new Robot();
robot.setName("panda1");
model.setRobot(robot);
// scene
var scene = new Scene();
model.setScene(scene);
......
......@@ -44,9 +44,6 @@ public class UtilA {
public static String getModelInfos(WorldModelA model, boolean detailed) {
StringBuilder sb = new StringBuilder();
sb.append("myRobot: ")
.append(model.getRobot().getName())
.append("\n");
if (detailed) {
// also include "normal" scene
sb.append("myScene:");
......
// --- receiving ---
receive WorldModelB.MyScene using ParseScene, ConvertScene ;
receive WorldModelB.OtherScene1 ;
receive WorldModelB.OtherScene2 ;
receive indexed WorldModelB.OtherScene ;
receive WorldModelB.TestingOtherScene ;
receive Robot.CanReachObjectOfInterestWrapper using ParseReachability, ConvertReachability ;
......
......@@ -2,18 +2,6 @@ aspect Computation {
//--- unspecifiedLocation ---
syn nta LogicalDropOffLocation WorldModelB.unspecifiedLocation() = new LogicalDropOffLocation().setName("<unspecified>");
//--- getOtherSceneList ---
syn JastAddList<LogicalScene> WorldModelB.getOtherSceneList() {
JastAddList<LogicalScene> result = new JastAddList<>();
if (hasOtherScene1()) {
result.add(getOtherScene1());
}
if (hasOtherScene2()) {
result.add(getOtherScene2());
}
return result;
}
//--- mergedOtherScene ---
syn nta LogicalScene WorldModelB.mergedOtherScene() {
// return empty scene, if there are no other scenes (yet)
......
WorldModelB ::= Robot* [MyScene:Scene] [OtherScene1:LogicalScene] [OtherScene2:LogicalScene] /OtherScene:LogicalScene*/ /NextOperation:Operation/ TestingOtherScene:LogicalScene* ;
// workaround with NTA OtherSceneList as receiving lists is not possible yet
WorldModelB ::= Robot* [MyScene:Scene] OtherScene:LogicalScene* /NextOperation:Operation/ TestingOtherScene:LogicalScene* ;
Robot ::= <Name:String> CanReachObjectOfInterestWrapper ;
......
......@@ -82,7 +82,7 @@ public class MainB extends SharedMainParts<MqttHandler, WorldModelB> {
@Override
protected void connectEndpoints() throws IOException {
model.connectMyScene(mqttUri(TOPIC_MY_SCENE_UPDATE_FROM_ROS, config));
model.connectOtherScene1(mqttUri(TOPIC_OTHER_SCENE_UPDATE_FROM_PLACE_A, config));
model.connectOtherScene(mqttUri(TOPIC_OTHER_SCENE_UPDATE_FROM_PLACE_A, config));
model.connectNextOperation(mqttUri(TOPIC_COMMAND, config), false);
}
......
......@@ -188,7 +188,7 @@ public class SimpleMainB {
/// Connect endpoints
model.connectMyScene(mqttUri("TOPIC_MY_SCENE_UPDATE_FROM_ROS", config));
model.connectOtherScene1(mqttUri("TOPIC_OTHER_SCENE_UPDATE_FROM_PLACE_A", config));
model.connectOtherScene(mqttUri("TOPIC_OTHER_SCENE_UPDATE_FROM_PLACE_A", config));
model.connectNextOperation(mqttUri("TOPIC_COMMANDS", config), false);
System.out.println("before");
......@@ -264,7 +264,7 @@ public class SimpleMainB {
LogicalDropOffLocation otherGamma = new LogicalDropOffLocation().setName("placeGamma");
otherGamma.addContainedObject(otherObj1);
otherScene.addLogicalDropOffLocation(otherGamma);
model.setOtherScene1(otherScene);
model.addOtherScene(otherScene);
// printing and testing
printModelInfos(model);
......
......@@ -60,9 +60,11 @@ public class TestComputeOperations {
LogicalDropOffLocation red = logicalScene.resolveLogicalObjectOfInterest("red").asLogicalDropOffLocation();
LogicalDropOffLocation blue = logicalScene.resolveLogicalObjectOfInterest("blue").asLogicalDropOffLocation();
Robot arm1 = model.findRobot("arm1").orElseThrow();
DifferenceObjectAtWrongPlace diff = createDifferenceObjectAtWrongPlace(x, emptyPreviousLocation ? null : red, blue);
// object "x" shall be place at red or blue
DifferenceObjectAtWrongPlace diff = createDifferenceObjectAtWrongPlace(x, emptyPreviousLocation ? null : red, blue);
List<Operation> operations = diff.computeOperations();
assertThat(operations).isNotEmpty();
assertThat(operations).hasSize(1);
Operation op = operations.get(0);
......@@ -90,9 +92,11 @@ public class TestComputeOperations {
LogicalDropOffLocation green = logicalScene.resolveLogicalObjectOfInterest("green").asLogicalDropOffLocation();
Robot arm1 = model.findRobot("arm1").orElseThrow();
Robot arm2 = model.findRobot("arm2").orElseThrow();
DifferenceObjectAtWrongPlace diff = createDifferenceObjectAtWrongPlace(x, emptyPreviousLocation ? null : red, green);
// object "x" shall be place at red or green
DifferenceObjectAtWrongPlace diff = createDifferenceObjectAtWrongPlace(x, emptyPreviousLocation ? null : red, green);
List<Operation> operations = diff.computeOperations();
assertThat(operations).isNotEmpty();
assertThat(operations).hasSize(2);
Operation op1 = operations.get(0);
......@@ -137,9 +141,11 @@ public class TestComputeOperations {
Robot arm2 = model.findRobot("arm2").orElseThrow();
Robot arm4 = model.findRobot("arm4").orElseThrow();
Robot arm5 = model.findRobot("arm5").orElseThrow();
DifferenceObjectAtWrongPlace diff = createDifferenceObjectAtWrongPlace(x, emptyPreviousLocation ? null : red, purple);
// object "x" shall be place at red or purple
DifferenceObjectAtWrongPlace diff = createDifferenceObjectAtWrongPlace(x, emptyPreviousLocation ? null : red, purple);
List<Operation> operations = diff.computeOperations();
assertThat(operations).isNotEmpty();
assertThat(operations).hasSize(3);
......
......@@ -181,7 +181,6 @@ public class TestDifference {
assertNotNull(diffs);
assertEquals(2, diffs.getNumChild());
assertThat(diffs).allMatch(d -> d instanceof DifferenceObjectAtWrongPlace);
//noinspection unchecked
assertThat(diffs).map(diff -> (DifferenceObjectAtWrongPlace) diff)
.extracting(d -> d.getObject().getName(), d -> d.getPreviousLocation().getName(), d -> d.getNewLocation().getName())
.containsOnly(tuple("x", "blue", "red"),
......
......@@ -34,8 +34,8 @@ public class TestMultiScenes {
@ValueSource(booleans = {true, false})
public void oneSceneNoContains(boolean scene1) {
WorldModelB model = newModel();
TestUtils.addOtherLocations(scene1 ? model.getOtherScene1() : model.getOtherScene2(), "red");
TestUtils.addOtherObjects(scene1 ? model.getOtherScene1() : model.getOtherScene2(), "a");
TestUtils.addOtherLocations(model.getOtherScene(scene1 ? 0 : 1), "red");
TestUtils.addOtherObjects(model.getOtherScene(scene1 ? 0 : 1), "a");
LogicalScene actual = model.mergedOtherScene();
......@@ -50,16 +50,16 @@ public class TestMultiScenes {
WorldModelB model = newModel();
TestUtils.addOtherLocations(model, "red");
TestUtils.addOtherObjects(model, "a");
TestUtils.addOtherLocations(model.getOtherScene2(), "blue");
TestUtils.addOtherObjects(model.getOtherScene2(), "b");
TestUtils.addOtherLocations(model.getOtherScene(1), "blue");
TestUtils.addOtherObjects(model.getOtherScene(1), "b");
LogicalScene actual = model.mergedOtherScene();
assertThat(actual.getLogicalDropOffLocationList())
.size().isEqualTo(2);
assertThat(actual.getLogicalDropOffLocationList())
.doesNotContainAnyElementsOf(model.getOtherScene1().getLogicalDropOffLocationList())
.doesNotContainAnyElementsOf(model.getOtherScene2().getLogicalDropOffLocationList())
.doesNotContainAnyElementsOf(model.getOtherScene(0).getLogicalDropOffLocationList())
.doesNotContainAnyElementsOf(model.getOtherScene(1).getLogicalDropOffLocationList())
.extracting("Name").containsOnly("red", "blue");
assertThat(actual.getLogicalDropOffLocationList())
.extracting("ContainedObjects").containsOnly(Collections.emptyList());
......@@ -67,8 +67,8 @@ public class TestMultiScenes {
assertThat(actual.getLogicalMovableObjectList())
.size().isEqualTo(2);
assertThat(actual.getLogicalMovableObjectList())
.doesNotContainAnyElementsOf(model.getOtherScene1().getLogicalMovableObjectList())
.doesNotContainAnyElementsOf(model.getOtherScene2().getLogicalMovableObjectList())
.doesNotContainAnyElementsOf(model.getOtherScene(0).getLogicalMovableObjectList())
.doesNotContainAnyElementsOf(model.getOtherScene(1).getLogicalMovableObjectList())
.extracting("Name").containsOnly("a", "b");
assertThat(actual.getLogicalMovableObjectList())
.extracting("LocatedAt").containsOnly((LogicalDropOffLocation) null);
......@@ -80,9 +80,9 @@ public class TestMultiScenes {
WorldModelB model = newModel();
TestUtils.addOtherLocations(model, "red", "blue");
TestUtils.addOtherObjects(model, "a", "b");
model.getOtherScene2().addLogicalDropOffLocation(new LogicalDropOffLocation().setName("red"));
model.getOtherScene2().addLogicalMovableObject(new LogicalMovableObject().setName("a"));
TestUtils.addContainedObjects(scene1 ? model.getOtherScene1() : model.getOtherScene2(),
model.getOtherScene(1).addLogicalDropOffLocation(new LogicalDropOffLocation().setName("red"));
model.getOtherScene(1).addLogicalMovableObject(new LogicalMovableObject().setName("a"));
TestUtils.addContainedObjects(model.getOtherScene(scene1 ? 0 : 1),
"red", "a");
LogicalScene actual = model.mergedOtherScene();
......@@ -90,8 +90,8 @@ public class TestMultiScenes {
assertThat(actual.getLogicalDropOffLocationList())
.size().isEqualTo(2);
assertThat(actual.getLogicalDropOffLocationList())
.doesNotContainAnyElementsOf(model.getOtherScene1().getLogicalDropOffLocationList())
.doesNotContainAnyElementsOf(model.getOtherScene2().getLogicalDropOffLocationList())
.doesNotContainAnyElementsOf(model.getOtherScene(0).getLogicalDropOffLocationList())
.doesNotContainAnyElementsOf(model.getOtherScene(1).getLogicalDropOffLocationList())
.extracting("Name").containsExactly("red", "blue");
LogicalDropOffLocation red = actual.resolveLogicalObjectOfInterest("red").asLogicalDropOffLocation();
assertThat(red.getContainedObjectList())
......@@ -100,7 +100,7 @@ public class TestMultiScenes {
assertThat(actual.getLogicalMovableObjectList())
.size().isEqualTo(2);
assertThat(actual.getLogicalMovableObjectList())
.doesNotContainAnyElementsOf(model.getOtherScene1().getLogicalMovableObjectList())
.doesNotContainAnyElementsOf(model.getOtherScene(0).getLogicalMovableObjectList())
.extracting("Name").containsOnly("a", "b");
LogicalMovableObject a = actual.resolveLogicalObjectOfInterest("a").asLogicalMovableObject();
assertThat(a.getLocatedAt())
......@@ -114,17 +114,17 @@ public class TestMultiScenes {
TestUtils.addOtherObjects(model, "a", "b");
TestUtils.addContainedObjects(model, "red", "a");
TestUtils.addOtherLocations(model.getOtherScene2(), "red");
TestUtils.addOtherObjects(model.getOtherScene2(), "a", "b");
TestUtils.addContainedObjects(model.getOtherScene2(), "red", "a");
TestUtils.addOtherLocations(model.getOtherScene(1), "red");
TestUtils.addOtherObjects(model.getOtherScene(1), "a", "b");
TestUtils.addContainedObjects(model.getOtherScene(1), "red", "a");
LogicalScene actual = model.mergedOtherScene();
assertThat(actual.getLogicalDropOffLocationList())
.size().isEqualTo(2);
assertThat(actual.getLogicalDropOffLocationList())
.doesNotContainAnyElementsOf(model.getOtherScene1().getLogicalDropOffLocationList())
.doesNotContainAnyElementsOf(model.getOtherScene2().getLogicalDropOffLocationList())
.doesNotContainAnyElementsOf(model.getOtherScene(0).getLogicalDropOffLocationList())
.doesNotContainAnyElementsOf(model.getOtherScene(1).getLogicalDropOffLocationList())
.extracting("Name").containsExactly("red", "blue");
LogicalDropOffLocation red = actual.resolveLogicalObjectOfInterest("red").asLogicalDropOffLocation();
assertThat(red.getContainedObjectList())
......@@ -133,7 +133,7 @@ public class TestMultiScenes {
assertThat(actual.getLogicalMovableObjectList())
.size().isEqualTo(2);
assertThat(actual.getLogicalMovableObjectList())
.doesNotContainAnyElementsOf(model.getOtherScene1().getLogicalMovableObjectList())
.doesNotContainAnyElementsOf(model.getOtherScene(0).getLogicalMovableObjectList())
.extracting("Name").containsOnly("a", "b");
LogicalMovableObject a = actual.resolveLogicalObjectOfInterest("a").asLogicalMovableObject();
assertThat(a.getLocatedAt())
......
......@@ -12,8 +12,8 @@ public class TestUtils {
WorldModelB model = new WorldModelB();
Scene scene = new Scene();
model.setMyScene(scene);
model.setOtherScene1(new LogicalScene());
model.setOtherScene2(new LogicalScene());
model.addOtherScene(new LogicalScene());
model.addOtherScene(new LogicalScene());
return model;
}
......@@ -70,7 +70,7 @@ public class TestUtils {
}
public static void addOtherObjects(WorldModelB model, String... names) {
addOtherObjects(model.getOtherScene1(), names);
addOtherObjects(model.getOtherScene(0), names);
}
public static void addOtherObjects(LogicalScene scene, String... names) {
......@@ -80,7 +80,7 @@ public class TestUtils {
}
public static void addOtherLocations(WorldModelB model, String... names) {
addOtherLocations(model.getOtherScene1(), names);
addOtherLocations(model.getOtherScene(0), names);
}
public static void addOtherLocations(LogicalScene scene, String... names) {
......@@ -90,7 +90,7 @@ public class TestUtils {
}
public static void addContainedObjects(WorldModelB model, String locationName, String... objectNames) {
addContainedObjects(model.getOtherScene1(), locationName, objectNames);
addContainedObjects(model.getOtherScene(0), locationName, objectNames);
}
public static void addContainedObjects(LogicalScene scene, String locationName, String... objectNames) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment