sot-doc  1.1.0
Documentation entry point for the Stack-Of-Tasks
doc/Tutorial_Ros_Bridge.md
1 # ROS Bridge with SoT {#tutorial_ros_bridge}
2 
3 The core of the stack of tasks mechanism is independent from ROS: an execution is hence realized in a closed environment
4 (the entities are only defined in the python environment and are only accessible via python commands).
5 However, some bridges with ROS exist: for the display, but also to send and receive some pieces of data.
6 
7 
8 \section tutorial_ros_bridge_sig_to_topic Signal to ROS topic
9 
10 Two entities allow you to exchange data from the ROS environment to the stack of tasks one,
11 and convert ros topics in sot signals, namely `rosPublish` and `rosSubscribe`.
12 
13 Here is a example of publication of matrix homogeneous from the sot environment to the ROS environment:
14 
15 
16  ros.rosPublish.add('matrixHomoStamped', robot.frames['rightGripper'].name +'_position', 'right_gripper')
17  ros.rosPublish.displaySignals()
18  --- <rosPublish> signal list:
19  |-- <Sig:N12dynamicgraph10RosPublishE(rosPublish)::input(MatrixHomo)::romeo_rightHand_position (Type Cst) AUTOPLUGGED
20  `-- <Sig:N12dynamicgraph10RosPublishE(rosPublish)::input(int)::trigger (Type Fun)
21 
22 The robot right hand position is publised in a ROS topic:
23 
24  rostopic list
25  /right_gripper
26 
27 
28 This creates an input signal for the ros.rosPublish entity (`romeo_rightHand_position`), as well as the rostopic
29 element `/right_gripper`.
30 
31 Please note that this alone does **NOT** publish anything. In order to publish something, it is hence necessary to plug a signal to the one created in rosPublish.
32 
33 
34  plug(robot.frames['rightGripper'].position, ros.rosPublish.signal(robot.frames['rightGripper'].name +'_position'))
35 
36 
37 Now you are publishing:
38 
39  rostopic echo -n 1 /right_gripper
40  header:
41  seq: 24577
42  stamp:
43  secs: 1408440100
44  nsecs: 786866991
45  frame_id: /dynamic_graph/world
46  child_frame_id: ''
47  transform:
48  translation:
49  x: 0.12276189235
50  y: -0.242369571396
51  z: 0.659561031231
52  rotation:
53  x: -0.0883991792798
54  y: 0.534618973732
55  z: -0.0459091290832
56  w: 0.839202284813
57 
58 
59 \section tutorial_ros_bridge_topic_to_sig ROS tf to signal
60 
61 Importing a tf requires to convert first the tf into a matrix homogeneous in order to import it in the stack of tasks.
62 The child_frame HAS TO be the odom frame, which is the base for the SoT environment.
63 Hence, in order to use the position of an object in the stack of tasks, you can add
64 this to the launch file:
65 
66  <node name="object" pkg="dynamic_graph_bridge" type="tf_publisher">
67  <param name="frame" type="string" value="object" />
68  <param name="child_frame" type="string" value="odom" />
69  <param name="topic" type="string" value="object" />
70  </node>