-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathREADMECompiler.xtend
More file actions
149 lines (118 loc) · 5.69 KB
/
READMECompiler.xtend
File metadata and controls
149 lines (118 loc) · 5.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package de.fraunhofer.ipa.rossystem.generator
import system.RosInterface
import system.RosNode
import system.System
import system.impl.RosActionClientReferenceImpl
import system.impl.RosActionServerReferenceImpl
import system.impl.RosPublisherReferenceImpl
import system.impl.RosServiceClientReferenceImpl
import system.impl.RosServiceServerReferenceImpl
import system.impl.RosSubscriberReferenceImpl
import com.google.inject.Inject
import ros.Parameter
class READMECompiler {
@Inject extension GeneratorHelpers
def compile_toREADME(System system) '''
# «system.name»
This package has be created automatically using the [RosTooling](https://github.com/ipa320/RosTooling).
It holds the launch file to run the following nodes:
«FOR node:getRos2Nodes(system)»
«IF !node.namespace.nullOrEmpty»- «GeneratorHelpers.removeLeadingSlash(node.namespace)»_«(node as RosNode).name»«ELSE»
- «(node as RosNode).name»«ENDIF»
«ENDFOR»
«FOR subsystem:system.subsystems»
«FOR node:getRos2Nodes(subsystem)»
«IF !node.namespace.nullOrEmpty»- «GeneratorHelpers.removeLeadingSlash(node.namespace)»_«(node as RosNode).name»«ELSE»
- «(node as RosNode).name»«ENDIF»
«ENDFOR»
«ENDFOR»
«IF(!IsInterfacesEmpty(system))»The listed nodes offer the following connections:
«FOR node:getRos2Nodes(system)»«FOR port:(node as RosNode).rosinterfaces»
«getPortInfo(port)»
«ENDFOR»«ENDFOR»«FOR subsystem:system.subsystems»«FOR node:getRos2Nodes(subsystem)»«FOR port:(node as RosNode).rosinterfaces»
«getPortInfo(port)»
«ENDFOR»«ENDFOR»«ENDFOR»«ENDIF»
## Installation
### Using release
«IF system.fromFile.nullOrEmpty»
This package can be copied to a valid ROS 2 workspace. To be sure that all the related dependencies are installed and the command **rosdep install** can be used.
Then the workspace must be compiled using the common ROS 2 build command:
```
mkdir -p ros2_ws/src
cd ros2_ws/
cp -r PATHtoTHISPackage/«system.name» src/.
rosdep install --from-path src/ -i -y
colcon build
source install/setup.bash
```
«ELSE»
To launch this system there is already an existing package that contains the launch file.
The package can be easily installed with the following command:
```
sudo apt install ros-ROSDISTRO-«system.fromFile.split("/",2).get(0).replace("_","-")»
```
«ENDIF»
«IF !getAllRepos(system).empty»
### From source code
```
mkdir -p ros2_ws/src
cd ros2_ws/
«FOR repo:getAllRepos(system)»git clone «repo»«ENDFOR»
rosdep install --from-path src/ -i -y
colcon build
source install/setup.bash
```
«ENDIF»
## Usage
«IF system.fromFile.nullOrEmpty»
To execute the launch file, the following command can be called:
```
ros2 launch «system.name» «system.name».launch.py «FOR param:system.parameter»«(param as ros.Parameter).name»:=«get_param_value((param as ros.Parameter).value,(param as ros.Parameter).name)» «ENDFOR»
```
The generated launch files requires the xterm package, it can be installed by:
```
sudo apt install xterm
```
«ELSE»
To launch this system there is already an existing package that contains the launch file. It can be started by:
```
ros2 launch «system.fromFile.split("/",2).get(0)» «system.fromFile.substring(system.fromFile.lastIndexOf('/') + 1)» «FOR param:system.parameter»«(param as ros.Parameter).name»:=«get_param_value((param as ros.Parameter).value,(param as ros.Parameter).name)» «ENDFOR»
```
«ENDIF»
'''
def IsInterfacesEmpty(System system){
for(node: getRos2Nodes(system)){
if (!(node as RosNode).rosinterfaces.empty){
return false
}
}
for (subsystem: system.subsystems){
for(node: getRos2Nodes(subsystem)){
if (!(node as RosNode).rosinterfaces.empty){
return false
}
}
}
return true
}
def getPortInfo(RosInterface port ){
if(port.reference.eClass.toString.contains("RosPublisherReference") && (port.reference as RosPublisherReferenceImpl).basicGetFrom.message !== null){
return "- Publisher: "+ port.name+" ["+(port.reference as RosPublisherReferenceImpl).basicGetFrom.message.fullname+"]"
}
if(port.reference.eClass.toString.contains("RosSubscriberReference") && (port.reference as RosSubscriberReferenceImpl).basicGetFrom.message !== null){
return "- Subscriber: "+ port.name+" ["+(port.reference as RosSubscriberReferenceImpl).basicGetFrom.message.fullname+"]"
}
if(port.reference.eClass.toString.contains("RosServiceServerReference") && (port.reference as RosServiceServerReferenceImpl).basicGetFrom.service !== null){
return "- ServiceServer: "+ port.name+" ["+(port.reference as RosServiceServerReferenceImpl).basicGetFrom.service.fullname+"]"
}
if(port.reference.eClass.toString.contains("RosServiceClientReference") && (port.reference as RosServiceClientReferenceImpl).basicGetFrom.service !== null){
return "- ServiceClient: "+ port.name+" ["+(port.reference as RosServiceClientReferenceImpl).basicGetFrom.service.fullname+"]"
}
if(port.reference.eClass.toString.contains("RosActionServerReference") && (port.reference as RosActionServerReferenceImpl).basicGetFrom.action !== null){
return "- ActionServer: "+ port.name+" ["+(port.reference as RosActionServerReferenceImpl).basicGetFrom.action.fullname+"]"
}
if(port.reference.eClass.toString.contains("RosActionClientReference") && (port.reference as RosActionClientReferenceImpl).basicGetFrom.action !== null){
return "- ActionClient: "+ port.name+" ["+(port.reference as RosActionClientReferenceImpl).basicGetFrom.action.fullname+"]"
}
}
}