Commit 5129f322 authored by René Schöne's avatar René Schöne
Browse files

First, very rough ideas and some code snippets.

parent 6e0686df
Pipeline #6205 failed with stage
in 38 seconds
Ros2Rag ::= MappingDefinition* SyncDefinition* Program; //MqttRoot ;
abstract SyncDefinition ::= <AlwaysApply:Boolean> ;
abstract TokenWritingSyncDefinition : SyncDefinition ::= TargetType:SimpleTypeUse <TargetChild> ;
UpdateDefinition : TokenWritingSyncDefinition ::= <SourceAttribute> [MappingDefinitionUse] ;
ReadFromMqttDefinition : TokenWritingSyncDefinition ::= [MappingDefinitionUse] ;
WriteToMqttDefinition : SyncDefinition ::= SourceType:SimpleTypeUse <SourceChild> [MappingDefinitionUse] ;
MappingDefinition ::= <ID> From:SimpleTypeUse To:SimpleTypeUse <Content> ;
MappingDefinitionUse ::= <ID> ;
......@@ -8,6 +8,7 @@ aspect Aspect {
return sb.toString();
}
@Deprecated
public void Program.generateAspect(StringBuilder sb) {
sb.append("aspect ROS2RAG {\n");
......@@ -16,4 +17,58 @@ aspect Aspect {
sb.append("}\n");
}
public String Ros2Rag.generateAspect() {
StringBuilder sb = new StringBuilder();
generateAspect(sb);
return sb.toString();
}
// from "[always] read Joint.CurrentPosition using PoseToPosition;" generate method connectTo
// Joint j;
// j.getCurrentPosition().connectTo("/robot/joint2/pos");
public void Ros2Rag.generateAspect(StringBuilder sb) {
sb.append("aspect ROS2RAG {\n");
for (SyncDefinition def : getSyncDefinitionList()) {
def.generateAspect(sb);
}
sb.append("}\n");
}
abstract void SyncDefinition.generateAspect(StringBuilder sb);
@Override
void UpdateDefinition.generateAspect(StringBuilder sb) {
// TODO
}
// will be "addConnectionJoint_CurrentPosition" in example
/* // see discussion in codimd (InstanceLocation), why this won't work here
Position.connectTo(String topic) {
mqttUpdater().addConnectionJoint_CurrentPosition(this, topic);
}
MqttUpdater.addConnectionJoint_CurrentPosition(Position target, String topic) {
// either
topicActionMap.put(topic, new Action(JOINT_CURRENTPOSITION, target));
// or
topicForJoint_CurrentPosition.put(topic, target);
}
*/
*/
@Override
void ReadFromMqttDefinition.generateAspect(StringBuilder sb) {
sb.append("public void ").append(type).append(".connectTo(String topic) {\n")
.append(aspectIndent).append("mqttUpdater().addConnection")
.append(getTargetType().getID()).append("_")
.append(getTargetChild())
.append("(this, topic);\n")
.append("}\n");
}
@Override
void WriteToMqttDefinition.generateAspect(StringBuilder sb) {
// TODO
}
}
package org.jastadd.ros2rag.compiler;
import beaver.Parser;
import org.jastadd.ros2rag.ast.*;
import org.jastadd.ros2rag.parser.RelAstParser;
import org.jastadd.ros2rag.scanner.RelAstScanner;
import java.io.BufferedReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
/**
* Testing Ros2Rag without parser.
*
* @author rschoene - Initial contribution
*/
public class SimpleMain {
public static void main(String[] args) {
/*
// as soon as the cache of isInSafetyZone is invalidated, update the value of Robot.ShouldUseLowSpeed with its value
[always] update Robot.ShouldUseLowSpeed with isInSafetyZone() using transformation();
// when a (new?) value for ShouldUseLowSpeed is set, send it over via mqtt
[always] write Robot.ShouldUseLowSpeed;
// when an update of pose is read via mqtt, then update current position
[always] read Joint.CurrentPosition using PoseToPosition;
// PBPose is a datatype defined in protobuf
PoseToPosition: map PBPose to Position using
pose.position.x += sqrt(.5 * size.x)
MAP round(2)
x = x / 100
IGNORE_IF_SAME
;
--- using generated methods ---
Joint j;
j.getCurrentPosition().connectTo("/robot/joint2/pos");
RobotArm r;
// this should not be required
r.getShouldUseLowSpeed().addObserver(j.getCurrentPosition());
r.getShouldUseLowSpeed().connectTo("/robot/config/speed");
*/
Ros2Rag model = new Ros2Rag();
Program program = parseProgram(Paths.get("src", "test", "resources", "MinimalExample.relast"));
model.setProgram(program);
MappingDefinition mappingDefinition = new MappingDefinition();
mappingDefinition.setID("PoseToPosition");
mappingDefinition.setFrom(new SimpleTypeUse("PBPose"));
mappingDefinition.setTo(new SimpleTypeUse("Position"));
mappingDefinition.setContent(" pose.position.x += sqrt(.5 * size.x)\n" +
" MAP round(2)\n" +
" x = x / 100\n" +
" IGNORE_IF_SAME\n" +
" ;");
model.addMappingDefinition(mappingDefinition);
ReadFromMqttDefinition readFromMqttDefinition = new ReadFromMqttDefinition();
readFromMqttDefinition.setAlwaysApply(false);
readFromMqttDefinition.setTargetType(new SimpleTypeUse("Joint"));
readFromMqttDefinition.setTargetChild("CurrentPosition");
readFromMqttDefinition.setMappingDefinitionUse(new MappingDefinitionUse("PoseToPosition"));
model.addSyncDefinition(readFromMqttDefinition);
System.out.println(model.generateAspect());
}
private static Program parseProgram(Path path) {
try (BufferedReader reader = Files.newBufferedReader(path)) {
RelAstScanner scanner = new RelAstScanner(reader);
RelAstParser parser = new RelAstParser();
return (Program) parser.parse(scanner);
} catch (IOException | Parser.Exception e) {
e.printStackTrace();
}
return null;
}
}
Model ::= RobotArm ZoneModel ;
ZoneModel ::= <Size:Position> SafetyZone:Zone*;
ZoneModel ::= Size:Position SafetyZone:Zone*;
Zone ::= Position*;
RobotArm ::= Joint* EndEffector /<ShouldUseLowSpeed:Boolean>/ ;
Joint ::= <Name> <CurrentPosition:Position>;
Joint ::= <Name> ;
rel Join.CurrentPosition -> Position ;
EndEffector : Joint;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment