Skip to content

Commit

Permalink
Merge pull request #131 from ipa-nhg/Ros2LaunchGenerator
Browse files Browse the repository at this point in the history
Add first draft for the ROS2 launch files generator
  • Loading branch information
ipa-nhg authored Jun 10, 2021
2 parents e9f63bf + 36b7ffa commit 30cb113
Show file tree
Hide file tree
Showing 14 changed files with 732 additions and 402 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ RosSystem { Name 'test_system' RosComponents (
}
} , ComponentInterface { name test_node2 NameSpace test2
FromRosNode "test_pkg.test_node.test_node"
RosPublishers { RosPublisher "test2/scan" { ns test2 RefPublisher "test_pkg.test_node.test_node.scan" } }
RosSubscribers { RosSubscriber "test2/power_state" { ns test2 RefSubscriber "test_pkg.test_node.test_node.power_state" } }
RosSrvServers { RosServiceServer "test2/setBool" { ns test2 RefServer "test_pkg.test_node.test_node.setBool" } }
RosSrvClients { RosServiceClient "test2/init" { ns test2 RefClient "test_pkg.test_node.test_node.init" } }
RosParameters { RosParameter "test2/string_test" { ns test2 RefParameter "test_pkg.test_node.test_node.string_test" } ,
RosParameter "test2/bool_tets" { ns test2 RefParameter "test_pkg.test_node.test_node.bool_tets" } ,
RosParameter "test2/array_tets" { ns test2 RefParameter "test_pkg.test_node.test_node.array_tets" } ,
RosParameter "test2/base64_test" { ns test2 RefParameter "test_pkg.test_node.test_node.base64_test" } ,
RosParameter "test2/double_test" { ns test2 RefParameter "test_pkg.test_node.test_node.double_test" } ,
RosParameter "test2/int_test" { ns test2 RefParameter "test_pkg.test_node.test_node.int_test" } ,
RosParameter "test2/list_test" { ns test2 RefParameter "test_pkg.test_node.test_node.list_test" }
RosPublishers { RosPublisher "scan" { RefPublisher "test_pkg.test_node.test_node.scan" } }
RosSubscribers { RosSubscriber "power_state" { RefSubscriber "test_pkg.test_node.test_node.power_state" } }
RosSrvServers { RosServiceServer "setBool" { RefServer "test_pkg.test_node.test_node.setBool" } }
RosSrvClients { RosServiceClient "init" { RefClient "test_pkg.test_node.test_node.init" } }
RosParameters { RosParameter "string_test" { RefParameter "test_pkg.test_node.test_node.string_test" } ,
RosParameter "bool_tets" { RefParameter "test_pkg.test_node.test_node.bool_tets" } ,
RosParameter "array_tets" { RefParameter "test_pkg.test_node.test_node.array_tets" } ,
RosParameter "base64_test" { RefParameter "test_pkg.test_node.test_node.base64_test" } ,
RosParameter "double_test" { RefParameter "test_pkg.test_node.test_node.double_test" } ,
RosParameter "int_test" { RefParameter "test_pkg.test_node.test_node.int_test" } ,
RosParameter "list_test" { RefParameter "test_pkg.test_node.test_node.list_test" }
}
} , ComponentInterface { name test_nodea
RosPublishers { RosPublisher power_state { RefPublisher "test_pkg.test_node.test_node.power_state" } }
RosSubscribers { RosSubscriber scan { RefSubscriber "test_pkg.test_node.test_node.scan" } }
RosSrvServers { RosServiceServer init { RefServer "test_pkg.test_node.test_node.init" } }
RosSrvClients { RosServiceClient SetBool { RefClient "test_pkg.test_node.test_node.SetBool" } }
} ) TopicConnections {
TopicConnection scan { From ( "test_node.scan" ) To ( "test_nodea.scan" ) } ,
TopicConnection scan_rename { From ( "test_node.scan" ) To ( "test_nodea.scan" ) } ,
TopicConnection power_state { From ( "test_nodea.power_state" ) To ( "test_node.power_state" ) }
} ServiceConnections { ServiceConnection init { From ( "test_nodea.init" ) To "test_node.init" } }
Parameters {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
ComponentInterface { name test_system
RosPublishers{
RosPublisher "scan" { RefPublisher "test_pkg.test_node.test_node.scan"},
RosPublisher "test2/scan" { RefPublisher "test_pkg.test_node.test_node.scan"},
RosPublisher "power_state" { RefPublisher "test_pkg.test_node.test_node.power_state"}
}
RosSubscribers{
RosSubscriber "power_state" { RefSubscriber "test_pkg.test_node.test_node.power_state"},
RosSubscriber "test2/power_state" { RefSubscriber "test_pkg.test_node.test_node.power_state"},
RosSubscriber "scan" { RefSubscriber "test_pkg.test_node.test_node.scan"}
}
RosSrvServers{
RosServiceServer "setBool" { RefServer "test_pkg.test_node.test_node.setBool"},
RosServiceServer "test2/setBool" { RefServer "test_pkg.test_node.test_node.setBool"},
RosServiceServer "init" { RefServer "test_pkg.test_node.test_node.init"}
}
RosSrvClients{
RosServiceClient "init" { RefClient "test_pkg.test_node.test_node.init"},
RosServiceClient "test2/init" { RefClient "test_pkg.test_node.test_node.init"},
RosServiceClient "SetBool" { RefClient "test_pkg.test_node.test_node.SetBool"}
}
RosParameters{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
<rosparam param="list">[1,2,a]</rosparam>
<rosparam param="list">[1,3]</rosparam>
<rosparam>
first_element:8
third_element:dsd
first_element: 8
third_element: dsd
</rosparam>

<node pkg="test_pkg" type="test_node" name="test_node" cwd="node" respawn="false" output="screen">
<remap from='scan' to='scan_rename' />
</node>
<node pkg="test_pkg" type="test_node" name="test_node2" ns="test2" cwd="node" respawn="false" output="screen">
</node>
<node pkg="test_pkg" type="test_node" name="test_nodea" cwd="node" respawn="false" output="screen">
<remap from='scan' to='scan_rename' />
</node>

</launch>
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,15 @@ class RosSystemGeneratorTest {

// Test the generated launch file
Assert.assertEquals(new String(Files.readAllBytes(Paths.get(RESOURCES_BASE_DIR+'/test_system/launch/', 'test_system.launch'))).trim,
fsa.textFiles.get(CustomOutputProvider::DEFAULT_OUTPUT+'test_system/launch/test_system.launch').toString.trim)
fsa.textFiles.get(CustomOutputProvider::DEFAULT_OUTPUT+'test_system/launch/test_system.launch').toString.trim)

// Test the generated package.xml file
Assert.assertEquals(new String(Files.readAllBytes(Paths.get(RESOURCES_BASE_DIR+'/test_system/', 'package.xml'))).trim,
fsa.textFiles.get(CustomOutputProvider::DEFAULT_OUTPUT+'test_system/package.xml').toString.trim)

// Test the generated CMakeLists.txt file
Assert.assertEquals(new String(Files.readAllBytes(Paths.get(RESOURCES_BASE_DIR+'/test_system/', 'CMakeLists.txt'))).trim,
fsa.textFiles.get(CustomOutputProvider::DEFAULT_OUTPUT+'test_system/CMakeLists.txt').toString.trim)

// Test the generated component interface
Assert.assertEquals(new String(Files.readAllBytes(Paths.get(RESOURCES_BASE_DIR+'/test_system.componentinterface'))).trim,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class RosSystemParsingTest {
Assert.assertEquals("test_node", ComponentName)

val TopicConnectionName = model.topicConnections.get(0).topicName
Assert.assertEquals("scan", TopicConnectionName)
Assert.assertEquals("scan_rename", TopicConnectionName)

val FromTopic = model.topicConnections.get(0).from.get(0).name
val Publisher = model.rosComponent.get(0).rospublisher.get(0).name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class CMakeListsCompiler {
@Inject extension GeneratorHelpers


def compile_CMakeLists(RosSystem system) '''«init_pkg()»
def compile_CMakeLists_ROS1(RosSystem system) '''«init_pkg()»
cmake_minimum_required(VERSION 2.8.3)
projectsystem.name.toLowerCase»)

Expand All @@ -22,4 +22,28 @@ install(DIRECTORY launch
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)'''

def compile_CMakeLists_ROS2(RosSystem system) '''«init_pkg()»
cmake_minimum_required(VERSION 3.5)
projectsystem.name.toLowerCase»)

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

find_package(ament_cmake REQUIRED)

### INSTALL ###
install(DIRECTORY launch
DESTINATION share/${PROJECT_NAME}
)

ament_package()
'''


}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import rossystem.RosSystem
import ros.ParameterValue
import ros.impl.ParameterStructMemberImpl
import ros.Node
import ros.impl.ArtifactImpl
import org.eclipse.emf.ecore.EObject
import ros.impl.NodeImpl

class ComponentInterfaceCompiler {
@Inject extension GeneratorHelpers
Expand Down Expand Up @@ -51,10 +54,8 @@ class ComponentInterfaceCompiler {
boolean ArtifactSet
boolean PackageSet

String artifact_impl
Object artifact_name
String node_impl
String node_name
ArtifactImpl artifact_impl
NodeImpl node_impl

String param_value
String value_return
Expand Down Expand Up @@ -102,55 +103,55 @@ ComponentInterface { name «system.name»
RosPublishers{
«FOR pub:pubs»
«val count_pub=count_pub--»
RosPublisher "«pub.name»" { RefPublisher "«pub.publisher.package_pub».«pub.publisher.artifact_pub».«pub.publisher.node_pub».«pub.publisher.name»"}«IF count_pub > 1 »,«ENDIF»
RosPublisher "«pub.name»" { RefPublisher "«pub.publisher.package_pub».«pub.publisher.getArtifact».«pub.publisher.getNode».«pub.publisher.name»"}«IF count_pub > 1 »,«ENDIF»
«ENDFOR»
}
«ENDIF»
«IF !subs.empty»
RosSubscribers{
«FOR sub:subs»
«val count_sub=count_sub--»
RosSubscriber "«sub.name»" { RefSubscriber "«sub.subscriber.package_sub».«sub.subscriber.artifact_sub».«sub.subscriber.node_sub».«sub.subscriber.name»"}«IF count_sub > 1 »,«ENDIF»
RosSubscriber "«sub.name»" { RefSubscriber "«sub.subscriber.package_sub».«sub.subscriber.getArtifact».«sub.subscriber.getNode».«sub.subscriber.name»"}«IF count_sub > 1 »,«ENDIF»
«ENDFOR»
}
«ENDIF»
«IF !svrs.empty»
RosSrvServers{
«FOR svrs:svrs»
«val count_srvs=count_srvs--»
RosServiceServer "«svrs.name»" { RefServer "«svrs.srvserver.package_srvserv».«svrs.srvserver.artifact_srvserv».«svrs.srvserver.node_srvserv».«svrs.srvserver.name»"}«IF count_srvs > 1 »,«ENDIF»
RosServiceServer "«svrs.name»" { RefServer "«svrs.srvserver.package_srvserv».«svrs.srvserver.getArtifact».«svrs.srvserver.getNode».«svrs.srvserver.name»"}«IF count_srvs > 1 »,«ENDIF»
«ENDFOR»
}
«ENDIF»
«IF !svrc.empty»
RosSrvClients{
«FOR svrc:svrc»
«val count_srvc=count_srvc--»
RosServiceClient "«svrc.name»" { RefClient "«svrc.srvclient.package_srvcli».«svrc.srvclient.artifact_srvcli».«svrc.srvclient.node_srvcli».«svrc.srvclient.name»"}«IF count_srvc > 1 »,«ENDIF»
RosServiceClient "«svrc.name»" { RefClient "«svrc.srvclient.package_srvcli».«svrc.srvclient.getArtifact».«svrc.srvclient.getNode».«svrc.srvclient.name»"}«IF count_srvc > 1 »,«ENDIF»
«ENDFOR»
}
«ENDIF»
«IF !acts.empty»
RosActionServers{
«FOR acts:acts»
«val count_acts=count_acts--»
RosActionServer "«acts.name»" { RefServer "«acts.actserver.package_actserver».«acts.actserver.artifact_actserver».«acts.actserver.node_actserver».«acts.actserver.name»"}«IF count_acts > 1 »,«ENDIF»
RosActionServer "«acts.name»" { RefServer "«acts.actserver.package_actserver».«acts.actserver.getArtifact».«acts.actserver.getNode».«acts.actserver.name»"}«IF count_acts > 1 »,«ENDIF»
«ENDFOR»
}
«ENDIF»
«IF !actc.empty»
RosActionClients{
«FOR actc:actc»
«val count_actc=count_actc--»
RosActionClient "«actc.name»" { RefClient "«actc.actclient.package_actclient».«actc.actclient.artifact_actclient».«actc.actclient.node_actclient».«actc.actclient.name»"}«IF count_actc > 1 »,«ENDIF»
RosActionClient "«actc.name»" { RefClient "«actc.actclient.package_actclient».«actc.actclient.getArtifact».«actc.actclient.getNode».«actc.actclient.name»"}«IF count_actc > 1 »,«ENDIF»
«ENDFOR»
}
«ENDIF»
«IF count_param>0»
RosParameters{
«FOR param:rosparams»
«val count_param=count_param--»
RosParameter "«compile_param_name(param.parameter,"")»" { RefParameter "«param.parameter.package_rosparam».«param.parameter.artifact_rosparam».«param.parameter.node_rosparam».«param.parameter.name»"«IF param.value!==null » value «compile_rosparam_value(param.value)»«ENDIF» }«IF count_param > 1»,«ENDIF»
RosParameter "«compile_param_name(param.parameter,"")»" { RefParameter "«param.parameter.package_rosparam».«param.parameter.getArtifact».«param.parameter.getNode».«param.parameter.name»"«IF param.value!==null » value «compile_rosparam_value(param.value)»«ENDIF» }«IF count_param > 1»,«ENDIF»
«ENDFOR»«FOR param:system.parameter»
«val count_param=count_param--»
RosParameter "«param.name»" { RefParameter "«param.name»"«IF param.value!==null » value «compile_rosparam_value(param.value)»«ENDIF» }«IF count_param > 1»,«ENDIF»
Expand All @@ -167,77 +168,25 @@ RosParameters{
}

def compile_art(ComponentInterface component)
'''«IF ! (component.fromRosNode===null)»«component.fromRosNode.getArtifact_rosnode»«ELSEIF !ArtifactSet && !component.rospublisher.empty»«FOR Rospublisher:component.rospublisher»«IF !ArtifactSet»«Rospublisher.publisher.getArtifact_pub()»«ENDIF»«ENDFOR»«ELSEIF !ArtifactSet && !component.rossubscriber.empty»«FOR Rossubscriber:component.rossubscriber»«IF !ArtifactSet»«Rossubscriber.subscriber.getArtifact_sub()»«ENDIF»«ENDFOR»«ELSEIF !ArtifactSet && !component.rosserviceserver.empty»«FOR Rosserviceserver:component.rosserviceserver»«IF !ArtifactSet»«Rosserviceserver.srvserver.getArtifact_srvserv()»«ENDIF»«ENDFOR»«ELSEIF !ArtifactSet && !component.rosserviceclient.empty»«FOR Rosserviceclient:component.rosserviceclient»«IF !ArtifactSet»«Rosserviceclient.srvclient.getArtifact_srvcli()»«ENDIF»«ENDFOR»«ELSEIF !ArtifactSet && !component.rosparameter.empty»«FOR RosParameter:component.rosparameter»«IF !ArtifactSet»«RosParameter.parameter.getArtifact_rosparam()»«ENDIF»«ENDFOR»«ELSEIF !ArtifactSet && !component.rosactionserver.empty»«FOR Rosactionserver:component.rosactionserver»«IF !ArtifactSet»«Rosactionserver.actserver.getArtifact_actserver()»«ENDIF»«ENDFOR»«ELSEIF !ArtifactSet && !component.rosactionclient.empty»«FOR Rosactionclient:component.rosactionclient»«IF !ArtifactSet»«Rosactionclient.actclient.getArtifact_actclient()»«ENDIF»«ENDFOR»«ENDIF»'''
def getArtifact_pub(Publisher publisher){
artifact_impl = publisher.eContainer.eContainer.toString;
return artifact_impl.getArtifact;
}
def getArtifact_sub(Subscriber subscriber){
artifact_impl = subscriber.eContainer.eContainer.toString;
return artifact_impl.getArtifact;
}
def getArtifact_srvserv(ServiceServer serviceserver){
artifact_impl = serviceserver.eContainer.eContainer.toString;
return artifact_impl.getArtifact;
}
def getArtifact_srvcli(ServiceClient serviceclient){
artifact_impl = serviceclient.eContainer.eContainer.toString;
return artifact_impl.getArtifact;
}
def getArtifact_actserver(ActionServer actionserver){
artifact_impl = actionserver.eContainer.eContainer.toString;
return artifact_impl.getArtifact;
}
def getArtifact_actclient(ActionClient actionclient){
artifact_impl = actionclient.eContainer.eContainer.toString;
return artifact_impl.getArtifact;
}
def getArtifact_rosparam(Parameter param){
artifact_impl = param.eContainer.eContainer.toString;
return artifact_impl.getArtifact;
}
def getArtifact_rosnode(Node node){
artifact_impl = node.eContainer.toString;
return artifact_impl.getArtifact;
}
def getArtifact(String artifact_impl){
artifact_name = artifact_impl.substring(artifact_impl.indexOf("name")+6,artifact_impl.length-1)
'''«IF ! (component.fromRosNode===null)»«component.fromRosNode.getArtifactFromNode»«ELSEIF !ArtifactSet && !component.rospublisher.empty»«FOR Rospublisher:component.rospublisher»«IF !ArtifactSet»«Rospublisher.publisher.getArtifact()»«ENDIF»«ENDFOR»«ELSEIF !ArtifactSet && !component.rossubscriber.empty»«FOR Rossubscriber:component.rossubscriber»«IF !ArtifactSet»«Rossubscriber.subscriber.getArtifact()»«ENDIF»«ENDFOR»«ELSEIF !ArtifactSet && !component.rosserviceserver.empty»«FOR Rosserviceserver:component.rosserviceserver»«IF !ArtifactSet»«Rosserviceserver.srvserver.getArtifact()»«ENDIF»«ENDFOR»«ELSEIF !ArtifactSet && !component.rosserviceclient.empty»«FOR Rosserviceclient:component.rosserviceclient»«IF !ArtifactSet»«Rosserviceclient.srvclient.getArtifact()»«ENDIF»«ENDFOR»«ELSEIF !ArtifactSet && !component.rosparameter.empty»«FOR RosParameter:component.rosparameter»«IF !ArtifactSet»«RosParameter.parameter.getArtifact()»«ENDIF»«ENDFOR»«ELSEIF !ArtifactSet && !component.rosactionserver.empty»«FOR Rosactionserver:component.rosactionserver»«IF !ArtifactSet»«Rosactionserver.actserver.getArtifact()»«ENDIF»«ENDFOR»«ELSEIF !ArtifactSet && !component.rosactionclient.empty»«FOR Rosactionclient:component.rosactionclient»«IF !ArtifactSet»«Rosactionclient.actclient.getArtifact()»«ENDIF»«ENDFOR»«ENDIF»'''

def getArtifact(EObject interfaz){
artifact_impl = interfaz.eContainer.eContainer as ArtifactImpl;
ArtifactSet=true;
return artifact_name;
return artifact_impl.name
}

def getNode_pub(Publisher publisher){
node_impl = publisher.eContainer.toString;
return node_impl.getNode;
}
def getNode_sub(Subscriber subscriber){
node_impl = subscriber.eContainer.toString;
return node_impl.getNode;
}
def getNode_srvserv(ServiceServer serviceserver){
node_impl = serviceserver.eContainer.toString;
return node_impl.getNode;
}
def getNode_srvcli(ServiceClient serviceclient){
node_impl = serviceclient.eContainer.toString;
return node_impl.getNode;
}
def getNode_actserver(ActionServer actionserver){
node_impl = actionserver.eContainer.toString;
return node_impl.getNode;
}
def getNode_actclient(ActionClient actionclient){
node_impl = actionclient.eContainer.toString;
return node_impl.getNode;
}
def getNode_rosparam(Parameter param){
node_impl = param.eContainer.toString;
return node_impl.getNode;
def getArtifactFromNode(Node node){
artifact_impl = node.eContainer as ArtifactImpl;
ArtifactSet=true;
return artifact_impl.name
}
def getNode(String node_impl){
node_name = node_impl.substring(node_impl.indexOf("name")+6,node_impl.length-1)
return node_name;

def getNode(EObject interfaz){
node_impl = interfaz.eContainer as NodeImpl;
return node_impl.name;
}


def prefix(String NS){
if(NS===""){
Expand Down
Loading

0 comments on commit 30cb113

Please sign in to comment.