Last active
March 5, 2021 11:27
-
-
Save rfzeg/473c6efc4c3a2c89a8975cd6b8293a70 to your computer and use it in GitHub Desktop.
ROS publisher from launch file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ROS Marker publisher: | |
Step 1: Transform Yaml file into Python dict notation. | |
Alternative 1, online tool: | |
A useful tool which will shows the result in Python notation of any YAML input is: | |
https://yaml-online-parser.appspot.com/ | |
Make sure to remove excess single quotes (') and new lines. | |
Alternative 2, use a python : | |
# if needed install pyyaml | |
import yaml | |
with open('filename.yaml') as f: | |
loadad_yaml = yaml.safe_load(f) | |
Then loadad_yaml returns a python dictionary. | |
Step 2, add publisher to launch file: | |
<!-- publish a marker with rostopic (CUBE, type:1; SPHERE, type:2; CYLINDER, type:3) --> | |
<node name="pub1" pkg="rostopic" type="rostopic" args="pub /shape visualization_msgs/Marker '{header: {frame_id: 'map', seq: 0, stamp: {nsecs: 0, secs: 0}}, ns: 'MarkerWithShape', id: 0, type: 1, action: 0, pose: {orientation: {w: 1.0, x: 0.0, y: 0.0, z: 0.0}, position: {x: 0.0, y: 0.0, z: 0.0}},scale: {x: 2.0, y: 2.0, z: 2.0}, color: {a: 1.0, b: 0.0, g: 0.0, r: 1.0}, lifetime: {nsecs: 0, secs: 0},frame_locked: False, points: [{x: 0.0, y: 0.0, z: 0.0}], colors: [{a: 1.0, b: 0.0, g: 0.0, r: 1.0}], text: '',mesh_resource: '', mesh_use_embedded_materials: False}'"/> | |
or | |
<!-- publish a marker with rostopic (CUBE, type:1; SPHERE, type:2; CYLINDER, type:3) --> | |
<arg name="start" value="'{header: {frame_id: 'map', seq: 0, stamp: {nsecs: 0, secs: 0}}, ns: 'MarkerWithShape', id: 0, type: 1, action: 0, pose: {orientation: {w: 1.0, x: 0.0, y: 0.0, z: 0.0}, position: {x: -1.9, y: 5.1, z: 0.0}},scale: {x: 0.2, y: 0.2, z: 0.1}, color: {a: 1.0, b: 0.0, g: 0.0, r: 1.0}, lifetime: {nsecs: 0, secs: 0},frame_locked: False, points: [{x: 0.0, y: 0.0, z: 0.0}], colors: [{a: 1.0, b: 0.0, g: 0.0, r: 1.0}], text: '',mesh_resource: '', mesh_use_embedded_materials: False}'" /> | |
<node name="pub1" pkg="rostopic" type="rostopic" args="pub /shape visualization_msgs/Marker $(arg start)"/> | |
Multiple marker publishers using nested substitution args: <arg> $(arg) | |
<arg name="header" value="header: {frame_id: 'map', seq: 0, stamp: {nsecs: 0, secs: 0}}" /> | |
<arg name="start_conc" value="'{$(arg header), ns: 'MarkerWithShape', id: 0, type: 1, action: 0, pose: {orientation: {w: 1.0, x: 0.0, y: 0.0, z: 0.0}, position: {x: -1.9, y: 5.1, z: 0.1}},scale: {x: 0.2, y: 0.2, z: 0.2}, color: {a: 1.0, b: 1.0, g: 0.0, r: 0.0}, lifetime: {nsecs: 0, secs: 0},frame_locked: False, points: [{x: 0.0, y: 0.0, z: 0.0}], colors: [{a: 1.0, b: 0.0, g: 0.0, r: 1.0}], text: '',mesh_resource: '', mesh_use_embedded_materials: False}'" /> | |
<arg name="end_conc" value="'{$(arg header), ns: 'MarkerWithShape', id: 1, type: 1, action: 0, pose: {orientation: {w: 1.0, x: 0.0, y: 0.0, z: 0.0}, position: {x: 3.7, y: 0.3, z: 0.1}},scale: {x: 0.2, y: 0.2, z: 0.2}, color: {a: 1.0, b: 0.0, g: 0.0, r: 1.0}, lifetime: {nsecs: 0, secs: 0},frame_locked: False, points: [{x: 0.0, y: 0.0, z: 0.0}], colors: [{a: 1.0, b: 0.0, g: 0.0, r: 1.0}], text: '',mesh_resource: '', mesh_use_embedded_materials: False}'" /> | |
<node name="pub1" pkg="rostopic" type="rostopic" args="pub /shape visualization_msgs/Marker $(arg start_conc)"/> | |
<node name="pub2" pkg="rostopic" type="rostopic" args="pub /shape visualization_msgs/Marker $(arg end_conc)"/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment