Aufgrund einer Wartung wird GitLab am 17.08. zwischen 8:30 und 9:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 17.08. between 8:30 and 9:00 am.

Commit 8e24f5f6 authored by Svetlana's avatar Svetlana

Using middleware for ROS cpp generation

parent d4cbd950
......@@ -12,9 +12,11 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: de.monticore.lang.monticar:embedded-montiarc-math-generator:0.0.6-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: de.monticore.lang.monticar:embedded-montiarc:0.0.11c-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: org.antlr:antlr4-runtime:4.7.1" level="project" />
<orderEntry type="library" name="Maven: de.monticore.lang:Tagging:0.0.1" level="project" />
<orderEntry type="library" name="Maven: de.monticore.lang.monticar:struct:0.0.10-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: de.monticore.lang.monticar:enum:0.0.10-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: de.se_rwth.commons:se-commons-logging:1.7.7" level="project" />
<orderEntry type="library" name="Maven: de.se_rwth.commons:se-commons-utilities:1.7.7" level="project" />
<orderEntry type="library" name="Maven: javax.inject:javax.inject:1" level="project" />
......@@ -25,7 +27,6 @@
<orderEntry type="library" name="Maven: org.javassist:javassist:3.18.2-GA" level="project" />
<orderEntry type="library" name="Maven: com.google.code.findbugs:annotations:2.0.1" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:2.4" level="project" />
<orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:3.0.0" level="project" />
<orderEntry type="library" name="Maven: org.antlr:antlr4:4.5.1" level="project" />
<orderEntry type="library" name="Maven: de.monticore:monticore-grammar:4.5.4-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: de.monticore:monticore-emf-runtime:4.5.4-SNAPSHOT" level="project" />
......@@ -43,14 +44,17 @@
<orderEntry type="library" name="Maven: org.mod4j.org.eclipse.equinox:app:1.2.0" level="project" />
<orderEntry type="library" name="Maven: org.mod4j.org.eclipse.emf.ecore:xmi:2.5.0" level="project" />
<orderEntry type="library" name="Maven: org.mod4j.org.eclipse.emf:common:2.5.0" level="project" />
<orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:3.0.0" level="project" />
<orderEntry type="library" name="Maven: de.se_rwth.commons:se-commons-groovy:1.7.7" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.groovy:groovy:2.3.7" level="project" />
<orderEntry type="library" name="Maven: jline:jline:2.12" level="project" />
<orderEntry type="library" name="Maven: de.monticore.lang:NumberUnit:0.0.10-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: de.monticore.lang.monticar:common-monticar:0.0.10-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: de.monticore.lang.monticar:embedded-montiarc:0.0.10-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: de.monticore.lang.monticar:struct:0.0.10-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: de.monticore.lang.monticar:enum:0.0.10-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.1.2" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.1.2" level="project" />
<orderEntry type="library" name="Maven: org.jscience:jscience:4.3.1" level="project" />
<orderEntry type="library" name="Maven: org.javolution:javolution:5.2.3" level="project" />
<orderEntry type="library" name="Maven: de.monticore.lang.monticar:embedded-montiarc-math-generator:0.0.6-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: de.monticore.lang.monticar:embedded-montiarc-behaviour:0.0.10-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: de.monticore.lang.monticar:embedded-montiarc-math:0.0.10-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: de.monticore.lang:math:0.0.10-SNAPSHOT" level="project" />
......@@ -72,15 +76,10 @@
<orderEntry type="library" name="Maven: de.monticore:monticore-grammar:grammars:4.5.2" level="project" />
<orderEntry type="library" name="Maven: org.freemarker:freemarker:2.3.23" level="project" />
<orderEntry type="library" name="Maven: commons-cli:commons-cli:1.4" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.1.2" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.1.2" level="project" />
<orderEntry type="library" name="Maven: org.jscience:jscience:4.3.1" level="project" />
<orderEntry type="library" name="Maven: org.javolution:javolution:5.2.3" level="project" />
<orderEntry type="library" name="Maven: de.moticore.lang.monticar:embedded-montiarc-math-roscpp-generator:0.0.1-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: de.monticore.lang.monticar:embedded-montiarc-math-roscpp-generator:0.0.1c-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: de.monticore.lang.monticar:embedded-montiarc-math-rosmsg-generator:0.0.1-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: com.esotericsoftware.yamlbeans:yamlbeans:1.12" level="project" />
<orderEntry type="library" name="Maven: de.moticore.lang.monticar:embedded-montiarc-math-middleware-generator:0.0.1-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: org.jgrapht:jgrapht-core:1.1.0" level="project" />
<orderEntry type="library" name="Maven: de.monticore.lang.monticar:embedded-montiarc-math-roscpp-generator:0.0.1c-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: de.monticore.lang.monticar:embedded-montiarc-math-rosmsg-generator:0.0.1-SNAPSHOT" level="project" />
</component>
</module>
\ No newline at end of file
......@@ -21,15 +21,20 @@
</build>
<dependencies>
<dependency>
<groupId>de.monticore.lang.monticar</groupId>
<artifactId>embedded-montiarc</artifactId>
<version>0.0.11c-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>de.monticore.lang.monticar</groupId>
<artifactId>embedded-montiarc-math-generator</artifactId>
<version>0.0.6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>de.moticore.lang.monticar</groupId>
<groupId>de.monticore.lang.monticar</groupId>
<artifactId>embedded-montiarc-math-roscpp-generator</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.1c-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>de.moticore.lang.monticar</groupId>
......
package dp;
component Imagepreprocessing {
ports
in Z(0:255)^{3, 224, 224} imageIn,
out Z(0:255)^{3, 224, 224} imageOut;
ports in Q^{3,224} in1,
in Z^{3,224} in2,
//in B^{3,224} in3,
out Q^{3,224} out1,
out Z^{3,224} out2;
//out B^{3,224} out3;
}
package dp;
conforms to de.monticore.lang.monticar.generator.roscpp.RosToEmamTagSchema;
tags Imagepreprocessing {
tag imagepreprocessing.in1 with RosConnection = {topic=(/topicName1,std_msgs/Float64MultiArray)};
tag imagepreprocessing.in2 with RosConnection = {topic=(/topicName2,std_msgs/Int32MultiArray)};
//tag imagepreprocessing.in3 with RosConnection = {topic=(/topicName3,std_msgs/ByteMultiArray)};
tag imagepreprocessing.out1 with RosConnection = {topic=(/topicName4,std_msgs/Float64MultiArray)};
tag imagepreprocessing.out2 with RosConnection = {topic=(/topicName5,std_msgs/Int32MultiArray)};
//tag imagepreprocessing.out3 with RosConnection = {topic=(/topicName6,std_msgs/ByteMultiArray)};
}
package de.monticore.lang.monticar.torcs_dl;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.PortSymbol;
import de.monticore.lang.embeddedmontiarc.tagging.RosToEmamTagSchema;
import de.monticore.lang.monticar.generator.middleware.MiddlewareGenerator;
import de.monticore.lang.monticar.generator.middleware.impls.CPPGenImpl;
import de.monticore.lang.monticar.generator.middleware.impls.RosCppGenImpl;
import de.monticore.lang.monticar.generator.order.nfp.TagBreakpointsTagSchema.TagBreakpointsTagSchema;
import de.monticore.lang.monticar.generator.order.nfp.TagDelayTagSchema.TagDelayTagSchema;
import de.monticore.lang.monticar.generator.order.nfp.TagExecutionOrderTagSchema.TagExecutionOrderTagSchema;
......@@ -9,18 +12,13 @@ import de.monticore.lang.monticar.generator.order.nfp.TagInitTagSchema.TagInitTa
import de.monticore.lang.monticar.generator.order.nfp.TagMinMaxTagSchema.TagMinMaxTagSchema;
import de.monticore.lang.monticar.generator.order.nfp.TagTableTagSchema.TagTableTagSchema;
import de.monticore.lang.monticar.generator.order.nfp.TagThresholdTagSchema.TagThresholdTagSchema;
import de.monticore.lang.monticar.generator.roscpp.GeneratorRosCpp;
import de.monticore.lang.monticar.generator.roscpp.helper.YamlHelper;
import de.monticore.lang.monticar.generator.roscpp.tagging.RosToEmamTagSchema;
import de.monticore.lang.monticar.generator.rosmsg.GeneratorRosMsg;
import de.monticore.lang.monticar.generator.roscpp.helper.TagHelper;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.monticore.symboltable.Scope;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import static de.monticore.lang.monticar.generator.order.simulator.AbstractSymtab.createSymTab;
......@@ -28,20 +26,34 @@ public class Experiments {
public static void main(String[] args) {
System.out.println("Experiments!");
//---
Scope scope = createSymTab("resources");
TaggingResolver symtab = new TaggingResolver(scope, Collections.singletonList("resources"));
TagMinMaxTagSchema.registerTagTypes(symtab);
TagTableTagSchema.registerTagTypes(symtab);
TagBreakpointsTagSchema.registerTagTypes(symtab);
TagExecutionOrderTagSchema.registerTagTypes(symtab);
TagInitTagSchema.registerTagTypes(symtab);
TagThresholdTagSchema.registerTagTypes(symtab);
TagDelayTagSchema.registerTagTypes(symtab);
TaggingResolver taggingResolver = new TaggingResolver(scope, Arrays.asList("resources"));
TagMinMaxTagSchema.registerTagTypes(taggingResolver);
TagTableTagSchema.registerTagTypes(taggingResolver);
TagBreakpointsTagSchema.registerTagTypes(taggingResolver);
TagExecutionOrderTagSchema.registerTagTypes(taggingResolver);
TagInitTagSchema.registerTagTypes(taggingResolver);
TagThresholdTagSchema.registerTagTypes(taggingResolver);
TagDelayTagSchema.registerTagTypes(taggingResolver);
RosToEmamTagSchema.registerTagTypes(taggingResolver);
MiddlewareGenerator middlewareGenerator = new MiddlewareGenerator();
middlewareGenerator.add(new CPPGenImpl(), "cpp");
middlewareGenerator.add(new RosCppGenImpl(), "roscpp");
RosToEmamTagSchema.registerTagTypes(symtab);
GeneratorRosCpp generatorRosCpp = new GeneratorRosCpp();
GeneratorRosMsg generatorRosMsg = new GeneratorRosMsg();
// DistributedTargetGenerator distributedTargetGenerator = new DistributedTargetGenerator();
//
// distributedTargetGenerator.add(new CPPGenImpl(), "cpp");
// distributedTargetGenerator.add(new RosCppGenImpl(), "roscpp");
// GeneratorRosCpp generatorRosCpp = new GeneratorRosCpp();
// GeneratorRosMsg generatorRosMsg = new GeneratorRosMsg();
LinkedList<String> inputs = new LinkedList<String>();
inputs.add("Imagepreprocessing");
......@@ -53,19 +65,29 @@ public class Experiments {
for (String inpu : inputs) {
System.out.println("Generating for " + inpu);
ExpandedComponentInstanceSymbol component = symtab.<ExpandedComponentInstanceSymbol>resolve("dp."+inpu.toLowerCase(), ExpandedComponentInstanceSymbol.KIND).orElse(null);
generatorRosMsg.setTarget("generated/", inpu);
ExpandedComponentInstanceSymbol componentInstanceSymbol = taggingResolver.<ExpandedComponentInstanceSymbol>resolve("dp."+inpu.toLowerCase(), ExpandedComponentInstanceSymbol.KIND).orElse(null);
TagHelper.resolveTags(taggingResolver, componentInstanceSymbol);
middlewareGenerator.setGenerationTargetPath("generated/"+inpu);
middlewareGenerator.generate(componentInstanceSymbol, taggingResolver);
for(PortSymbol port : component.getPorts()) {
List<File> msgFiles = generatorRosMsg.generate(port.getTypeReference());
System.out.println(" Msg files: " + msgFiles.toString());
}
// distributedTargetGenerator.setGenerationTargetPath("generated/"+inpu);
// distributedTargetGenerator.generate(componentInstanceSymbol, symtab);
generatorRosCpp.setGenerationTargetPath("generated/"+inpu);
List<File> files = YamlHelper.generateFromFile("resources/config/"+inpu+".yaml", symtab, generatorRosCpp);
for (File f : files) {
System.out.println(" " + f.toString());
}
// ExpandedComponentInstanceSymbol component = symtab.<ExpandedComponentInstanceSymbol>resolve("dp."+inpu.toLowerCase(), ExpandedComponentInstanceSymbol.KIND).orElse(null);
// generatorRosMsg.setTarget("generated/", inpu);
//
// for(PortSymbol port : component.getPorts()) {
// List<File> msgFiles = generatorRosMsg.generate(port.getTypeReference());
// System.out.println(" Msg files: " + msgFiles.toString());
// }
//
// generatorRosCpp.setGenerationTargetPath("generated/"+inpu);
// List<File> files = YamlHelper.generateFromFile("resources/config/"+inpu+".yaml", symtab, generatorRosCpp);
// for (File f : files) {
// System.out.println(" " + f.toString());
// }
}
} catch (IOException e) {
......
#pragma once
#include "${compName}.h"
class IAdapter_${compName}{
public:
virtual ~IAdapter_${compName}(){}
virtual void init(${compName}* comp) = 0;
virtual void tick() = 0;
};
cmake_minimum_required(VERSION 3.5)
project(${compName} LANGUAGES CXX)
add_library(${compName} ${compName}.h)
target_include_directories(${compName} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
set_target_properties(${compName} PROPERTIES LINKER_LANGUAGE CXX)
export(TARGETS ${compName} FILE ${compName}.cmake)
cmake_minimum_required(VERSION 3.5)
project (Coordinator_${compName} CXX)
set (CMAKE_CXX_STANDARD 11)
set (THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
add_executable(Coordinator_${compName} Coordinator_${compName}.cpp)
set_target_properties(Coordinator_${compName} PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(Coordinator_${compName} ${targets} Threads::Threads)
target_include_directories(Coordinator_${compName} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
export(TARGETS Coordinator_${compName} FILE Coordinator_${compName}.cmake)
\ No newline at end of file
#include <iostream>
#include <thread>
#include <chrono>
#include <atomic>
#include <list>
#include "IAdapter_${compName}.h"
${includes}
using namespace std;
using namespace chrono;
static int exeMs = 100;
bool parseCommandLineParameters(int argc, char* argv[]){
if(argc == 1){
return true;
}
if(argc == 3 && string(argv[1]) == "-t"){
try{
int tmp = stoi(argv[2]);
if(tmp >= 0){
exeMs = tmp;
return true;
}
}catch(...){
//Ignore
}
}
cout << "Usage: " << argv[0] << " [-h | -t sleepTimeMs]\n";
return false;
}
void startMiddleware(IAdapter_${compName}& adapter,${compName}& comp,atomic<bool>& done){
adapter.init(&comp);
done = true;
}
int main(int argc, char* argv[])
{
if(!parseCommandLineParameters(argc,argv)){
return 1;
}
atomic<bool> done(false);
${compName} comp;
comp.init();
list<IAdapter_${compName}*> adapters;
${addAdapters}
list<thread*> threads;
for(auto a : adapters){
threads.push_back(new thread(startMiddleware,ref(*a),ref(comp),ref(done)));
}
cout << "waiting for all middleware to start\n";
this_thread::sleep_for(seconds(3));
cout << "started! Executing every " << exeMs << "ms\n";
time_point<system_clock> start, end;
while(!done){
start = system_clock::now();
comp.execute();
for(auto a : adapters){
(*a).tick();
}
end = system_clock::now();
int elapsedMs = duration_cast<milliseconds>(end-start).count();
int newSleep = exeMs - elapsedMs;
if(newSleep <= 0){
cout << "Cant keep up! "<< (-newSleep) <<"ms late!\n";
}else{
this_thread::sleep_for(milliseconds(newSleep));
}
}
return 0;
}
\ No newline at end of file
#pragma once
#include "${compName}.h"
#include <thread>
#include <chrono>
#include "IAdapter_${compName}.h"
class DummyAdapter_${compName}: public IAdapter_${compName}{
${compName}* component;
public:
DummyAdapter_${compName}(){
}
void tick(){
cout << "Dummy publish data: component.out1 = "<< component->out1 << endl;
}
void init(${compName}* comp){
this->component = comp;
while(1){
std::this_thread::sleep_for(std::chrono::seconds(1));
component->in2 += 1000;
}
}
};
cmake_minimum_required(VERSION 3.5)
project (DummyAdapter_${compName})
add_library(DummyAdapter_${compName} DummyAdapter_${compName}.h)
set_target_properties(DummyAdapter_${compName} PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(DummyAdapter_${compName} ${compName})
target_include_directories(DummyAdapter_${compName} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
export(TARGETS DummyAdapter_${compName} FILE DummyAdapter_${compName}.cmake)
cmake_minimum_required(VERSION 3.5)
project (struct_msgs)
find_package(genmsg REQUIRED)
FILE(GLOB MSG_FILES_RAW RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ../*/roscpp/struct_msgs/*.msg)
#generate struct_msgs iff .msg files where found
if(MSG_FILES_RAW)
#filter: add each struct msg only once (distinct by filename without path)
foreach(CUR_MSG_FILE ${MSG_FILES_RAW})
get_filename_component(TMP_MSG_NAME ${CUR_MSG_FILE} NAME)
IF(NOT MSG_DEFINED_${TMP_MSG})
LIST(APPEND MSG_FILES ${CUR_MSG_FILE})
SET(MSG_DEFINED_${TMP_MSG} TRUE)
ENDIF()
endforeach(CUR_MSG_FILE)
#generate messages
add_message_files(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} FILES ${MSG_FILES})
generate_messages()
#export the include_dirs, so that other subprojects can use it
set(struct_msgs_INCLUDE_DIRS ${struct_msgs_INCLUDE_DIRS} PARENT_SCOPE)
endif()
Markdown is supported
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