|
| 1 | +package de.fraunhofer.ipa.rossystem.generator |
| 2 | + |
| 3 | +import system.RosNode |
| 4 | +import ros.RosPackage |
| 5 | +import ros.Artifact |
| 6 | +import system.System |
| 7 | +import ros.AmentPackage |
| 8 | +import ros.impl.AmentPackageImpl |
| 9 | + |
| 10 | +class LaunchFileCompiler_ROS2 { |
| 11 | + |
| 12 | + |
| 13 | + def compile_toROS2launch(System system) ''' |
| 14 | +from launch import LaunchDescription |
| 15 | +from launch_ros.actions import Node |
| 16 | + |
| 17 | +def generate_launch_description(): |
| 18 | + ld = LaunchDescription() |
| 19 | + |
| 20 | + «FOR component:system.components» |
| 21 | + «(component as RosNode).name» = Node( |
| 22 | + package="«((component as RosNode).from.eContainer.eContainer as AmentPackageImpl).name»", |
| 23 | + executable="«((component as RosNode).from.eContainer as Artifact).name»", |
| 24 | + name="«(component as RosNode).name»" |
| 25 | + ) |
| 26 | + |
| 27 | + «ENDFOR» |
| 28 | + |
| 29 | + «FOR component:system.components» |
| 30 | + ld.add_action(«(component as RosNode).name») |
| 31 | + «ENDFOR» |
| 32 | + |
| 33 | + return ld |
| 34 | + ''' |
| 35 | + |
| 36 | +// def void compile_list_of_ROS2components(RosSystem system, ComponentStack stack) { |
| 37 | +// components_tmp_.clear; |
| 38 | +// Ros2components.clear; |
| 39 | +// if (stack === null){ |
| 40 | +// components_tmp_ = system.rosComponent; |
| 41 | +// } else { |
| 42 | +// components_tmp_ = stack.rosComponent; |
| 43 | +// } |
| 44 | +// for(ComponentInterface component:components_tmp_){ |
| 45 | +// if (component.compile_pkg_type.toString.contains("AmentPackage")){ |
| 46 | +// Ros2components.add(component); |
| 47 | +// } |
| 48 | +// } |
| 49 | +// } |
| 50 | +// |
| 51 | +// def check_ns(ComponentInterface component){ |
| 52 | +// if (component.hasNS){ |
| 53 | +// return component.get_ns(); |
| 54 | +// }else { |
| 55 | +// return ""; |
| 56 | +// } |
| 57 | +// } |
| 58 | +// |
| 59 | +// def List<String> InterfaceDef(String name, String type){ |
| 60 | +// ListInterfaceDef = new ArrayList() |
| 61 | +// ListInterfaceDef.add(name.replace("/","_")) |
| 62 | +// ListInterfaceDef.add(name) |
| 63 | +// ListInterfaceDef.add(type) |
| 64 | +// return ListInterfaceDef |
| 65 | +// } |
| 66 | +// |
| 67 | +// def boolean hasNS(ComponentInterface component){ |
| 68 | +// if(!component.nameSpace.nullOrEmpty){ |
| 69 | +// return true; |
| 70 | +// }else{ |
| 71 | +// return false |
| 72 | +// } |
| 73 | +// } |
| 74 | +// def String get_ns(ComponentInterface component){ |
| 75 | +// return component.nameSpace.replaceFirst("/",""); |
| 76 | +// } |
| 77 | +// |
| 78 | +// def String compile_remappings_str(ComponentInterface component) { |
| 79 | +// var remap_str = ""; |
| 80 | +// val NS = component.check_ns(); |
| 81 | +// for (rosPublisher : component.rospublisher) { |
| 82 | +// if (!((prefix(NS)+rosPublisher.name).equals(compile_topic_name(rosPublisher.publisher, NS)))) { |
| 83 | +// remap_str += "\t(\"" + rosPublisher.publisher.name + "\", \"" + rosPublisher.name + "\"),\n"; |
| 84 | +// } |
| 85 | +// } |
| 86 | +// for (rosSubscriber : component.rossubscriber) { |
| 87 | +// if (!((prefix(NS)+rosSubscriber.name).equals(compile_topic_name(rosSubscriber.subscriber, NS)))) { |
| 88 | +// remap_str += "\t(\"" + rosSubscriber.subscriber.name + "\", \"" + rosSubscriber.name + "\"),\n"; |
| 89 | +// } |
| 90 | +// } |
| 91 | +// for (rosServiceServer : component.rosserviceserver) { |
| 92 | +// if (!((prefix(NS)+rosServiceServer.name).equals(compile_service_name(rosServiceServer.srvserver, NS)))) { |
| 93 | +// remap_str += "\t(\"" + rosServiceServer.srvserver.name + "\", \"" + rosServiceServer.name + "\"),\n"; |
| 94 | +// } |
| 95 | +// } |
| 96 | +// for (rosServiceClient : component.rosserviceclient) { |
| 97 | +// if (!((prefix(NS)+rosServiceClient.name).equals(compile_service_name(rosServiceClient.srvclient, NS)))) { |
| 98 | +// remap_str += "\t(\"" + rosServiceClient.srvclient.name + "\", \"" + rosServiceClient.name + "\"),\n"; |
| 99 | +// } |
| 100 | +// } |
| 101 | +// for (rosActionServer : component.rosactionserver) { |
| 102 | +// if (!((prefix(NS)+rosActionServer.name).equals(compile_action_name(rosActionServer.actserver, NS)))) { |
| 103 | +// remap_str += "\t(\"" + rosActionServer.actserver.name + "\", \"" + rosActionServer.name + "\"),\n"; |
| 104 | +// } |
| 105 | +// } |
| 106 | +// for (rosActionClient : component.rosactionclient) { |
| 107 | +// if (!((prefix(NS)+rosActionClient.name).equals(compile_action_name(rosActionClient.actclient, NS)))) { |
| 108 | +// remap_str += "\t(\"" + rosActionClient.actclient.name + "\", \"" + rosActionClient.name + "\"),\n"; |
| 109 | +// } |
| 110 | +// } |
| 111 | +// if (!remap_str.empty) { |
| 112 | +// remap_str = ",\nremappings=[\n" + remap_str.substring(0,remap_str.length-2) + "]\n"; |
| 113 | +// } |
| 114 | +// return remap_str; |
| 115 | +// } |
| 116 | +// |
| 117 | +// def String compile_parameters_str(EList<RosParameter> rosParameters) { |
| 118 | +// param_count = rosParameters.length; |
| 119 | +// var param_str = ""; |
| 120 | +// for (rosParameter : rosParameters) { |
| 121 | +// val param_count=param_count--; |
| 122 | +// if (rosParameter.parameter.type instanceof ParameterStructTypeImpl) { |
| 123 | +// param_str += compile_struct_str(rosParameter.value, rosParameter.parameter.name); |
| 124 | +// } else { |
| 125 | +// param_str += "{ \"" + rosParameter.parameter.name + "\" : " + get_param_value(rosParameter.value, rosParameter.parameter.name); |
| 126 | +// } |
| 127 | +// if (param_count > 1){ |
| 128 | +// param_str +=" },\n" |
| 129 | +// } else { |
| 130 | +// param_str +=" }\n"; |
| 131 | +// } |
| 132 | +// } |
| 133 | +// return param_str; |
| 134 | +// } |
| 135 | +// |
| 136 | +// def String compile_struct_str(ParameterValue value, String name) { |
| 137 | +// var param_str = ""; |
| 138 | +// var elem_count = (value as ParameterSequenceImpl).eContents.length; |
| 139 | +// |
| 140 | +// for (elem : ((value as ParameterSequenceImpl).eContents)) { |
| 141 | +// var member = ((elem as ParameterStructImpl).eContents.get(0) as ParameterStructMemberImpl); |
| 142 | +// val param_val = get_param_value(member.getValue(), name + "/" + member.getName()); |
| 143 | +// if (param_val.startsWith("{")) { |
| 144 | +// param_str += param_val; |
| 145 | +// } else { |
| 146 | +// param_str += "{ \"" + name + "/" + member.getName() + "\" : " + param_val; |
| 147 | +// } |
| 148 | +// elem_count--; |
| 149 | +// if (elem_count > 0){ |
| 150 | +// param_str +=" },\n" |
| 151 | +// } |
| 152 | +// } |
| 153 | +// return param_str; |
| 154 | +// } |
| 155 | +// |
| 156 | +// def String get_param_value(ParameterValue value, String name) { |
| 157 | +// var param_val = ""; |
| 158 | +// if (value instanceof ParameterStringImpl) { |
| 159 | +// param_val = "\"" + (value as ParameterStringImpl).getValue() + "\""; |
| 160 | +// } else if (value instanceof ParameterIntegerImpl) { |
| 161 | +// param_val = (value as ParameterIntegerImpl).getValue().toString; |
| 162 | +// } else if (value instanceof ParameterDoubleImpl) { |
| 163 | +// param_val = (value as ParameterDoubleImpl).getValue().toString; |
| 164 | +// } else if (value instanceof ParameterBooleanImpl) { |
| 165 | +// param_val = (value as ParameterBooleanImpl).isValue().toString; |
| 166 | +// } else if (value instanceof ParameterSequenceImpl) { |
| 167 | +// var elem_count = (value as ParameterSequenceImpl).eContents.length; |
| 168 | +// if ((value as ParameterSequenceImpl).eContents.get(0) instanceof ParameterStructImpl) { |
| 169 | +// param_val = compile_struct_str(value, name); |
| 170 | +// } else { |
| 171 | +// param_val += "["; |
| 172 | +// for (elem : (value as ParameterSequenceImpl).eContents) { |
| 173 | +// param_val += get_param_value(elem as ParameterValue, name); |
| 174 | +// elem_count--; |
| 175 | +// if (elem_count > 0){ |
| 176 | +// param_val +=", " |
| 177 | +// } |
| 178 | +// } |
| 179 | +// param_val += "]"; |
| 180 | +// } |
| 181 | +// } |
| 182 | +// return param_val; |
| 183 | +// } |
| 184 | +} |
0 commit comments