-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathROS cheatsheet.txt
325 lines (307 loc) · 11.9 KB
/
ROS cheatsheet.txt
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
ROS cheatsheet
* CONDA
- rqt will not work in conda environment
- conda deactivate # conda activate (to undo)
* File nav
rospack find [package_name] # get path to ros package
roscd <package or stack> # get to ros package
roscd log # get log
rosls package # list ros packages
* catkin workspace
catkin_make
- Example struct:
workspace_folder/ -- WORKSPACE
src/ -- SOURCE SPACE
CMakeLists.txt -- 'Toplevel' CMake file, provided by catkin
package_1/
CMakeLists.txt -- CMakeLists.txt file for package_1
package.xml -- Package manifest for package_1
...
package_n/
CMakeLists.txt -- CMakeLists.txt file for package_n
package.xml -- Package manifest for package_n
* Create package
- Create package when in catkin_ws/src
catkin_create_pkg <package_name> [depend1] [depend2] [depend3] # create package, list dependencies (eg. catkin_create_pkg beginner_tutorials std_msgs rospy roscpp)
catkin_make # build packages in workspace
catkin_make --source my_src # build packages at specified location
. ~/catkin_ws/devel/setup.bash # add workspace to ROS environment
* Graph overview
- Nodes: A node is an executable that uses ROS to communicate with other nodes.
- Messages: ROS data type used when subscribing or publishing to a topic.
- Topics: Nodes can publish messages to a topic as well as subscribe to a topic to receive messages.
- Master: Name service for ROS (i.e. helps nodes find each other)
- rosout: ROS equivalent of stdout/stderr
- roscore: Master + rosout + parameter server (parameter server will be introduced later)
* Nodes
- Executable that is connected to ROS network
roscore # create master
rosnode list # list nodes
rosnode info /rosout # get info on node rosout
rosrun [package_name] [node_name] # run node inside package
rosrun turtlesim turtlesim_node __name:=my_turtle # run node inside package & rename
rosnode cleanup # remove unused nodes
rosnode ping my_turtle # ping node
* Topics
- Topic is a channel for outputting and receiving info
- Publisher outputs info onto topic, subscribers listen to topic
rosrun rqt_graph rqt_graph # display graph of system
rostopic echo [topic] # show data published on topic
rostopic list -v # list topics (verbose)
rostopic type [topic] # get type of data for topic
rostopic type [topic] | rosmsg show # get type of data for topic, more info
rostopic pub -1 [topic] [msg_type] [args] # publish message to topic once
rostopic pub -r 1 [topic] [msg_type] [args] # publish message to topic every 1 second
rostopic hz [topic] # get data publish freq for topic
* Service
- Service is a channel for making requests, and sending responses
rosservice list # print information about active services
rosservice call [service] [args] # call the service with the provided args
rosservice type [service] # print service type
rosservice type [service] | rossrv show # print service type, more info
rosservice find # find services by service type
rosservice uri # print service ROSRPC uri
* Parameter server
- Way to store and manipulate data
rosparam set # set parameter
rosparam get # get parameter
rosparam get / # get all parameters
rosparam load [file_name] [namespace] # load parameters from file
rosparam dump [file_name] [namespace] # dump parameters to file
rosparam delete # delete parameter
rosparam list # list parameter names
* Debug
rosrun rqt_console rqt_console # open rqt console
rosrun rqt_logger_level rqt_logger_level # adjust verbosity of nodes
* Launch
roslaunch [package] [filename.launch] # launch node as specified by file
* Edit
rosed [package_name] [filename] # edit file in package
* srv and msg files
- msg files are simple text files that describe the fields of a ROS message
Header header
string child_frame_id
geometry_msgs/PoseWithCovariance pose
geometry_msgs/TwistWithCovariance twist
- srv file describes a service: a request and a response
int64 A
int64 B
---
int64 Sum
rosmsg show [message type] # show message format
rossrv show <service type> # show service format
roscp [package_name] [file_to_copy_path] [copy_path] # copy file in package
* Help
- Using rosmsg as an example:
rosmsg -h # # list subcomands for rosmsg
rosmsg show -h # get info for subcommand
* Python
rospy.loginfo(str) - print str to console, node's log, and rosout
- constructor args are in the same order as in the .msg file
- Make sure you have sourced your workspace's setup.sh file after calling catkin_make: source ./devel/setup.bash
* C++
- If you have subscription in an application, and don't have ros::spinOnce(), your callbacks would never get called
- ros::spin() enters a loop, calling message callbacks as fast as possible; low CPU usage if nothing to do
* Workflow
- Install ROS (http://wiki.ros.org/ROS/Installation)
- Create workspace
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/
catkin_make
- Create package in workspace/src
cd catkin_ws/src
catkin_create_pkg <package_name> [depend1] [depend2] [depend3]
cd ~/catkin_ws
catkin_make
. ~/catkin_ws/devel/setup.bash
- Customize package
- package.xml: modify description tag, maintainer tags, license tags, dependencies tags
- <description>: Update description to be helpful
- <maintainer email="[email protected]">user</maintainer>: Use your preferred email
- <license>: pick license (eg. BSD)
- <build_depend>, <buildtool_depend>, <exec_depend>, <test_depend>: may need to be added
- Build package
source /opt/ros/noetic/setup.bash # already in ~/.bashrc
cd catkin_ws
catkin_make # catkin_make [make_targets] [-DCMAKE_VARIABLES=...]
- Create custom messages
cd catkin_ws/src/<package>
- Create and customize message:
mkdir msg
echo "int64 num" > msg/Num.msg
- Update package.xml
- Uncomment the following:
<build_depend>message_generation</build_depend>
<exec_depend>message_runtime</exec_depend>
- Update CMakeList.txt
- Add message_generation to find_package
find_package(catkin REQUIRED COMPONENTS
<dependencies>
message_generation
)
- Add .msg to add_message_files
add_message_files(
FILES
Num.msg
)
- Uncomment generate_messages
generate_messages(
DEPENDENCIES
std_msgs
)
- Update CATKIN_DEPENDS in catkin_package
catkin_package(
CATKIN_DEPENDS message_runtime
)
- Check ROS can see your message
rosmsg show <package>/Num
- Make package
cd catkin_ws
catkin_make
cd -
- Create custom service
cd catkin_ws/src/<package>
- Copy existing service:
mkdir srv
roscp rospy_tutorials AddTwoInts.srv srv/AddTwoInts.srv
- Update package.xml
- Uncomment the following:
<build_depend>message_generation</build_depend>
<exec_depend>message_runtime</exec_depend>
- Update CMakeList.txt
- Add message_generation to find_package
find_package(catkin REQUIRED COMPONENTS
<dependencies>
message_generation
)
- Add .srv to add_service_files
add_service_files(
FILES
AddTwoInts.srv
)
- Uncomment generate_messages
generate_messages(
DEPENDENCIES
std_msgs
)
- Check ROS can see your service
rossrv show <package>/AddTwoInts
- Make package
cd catkin_ws
catkin_make
cd -
- Python
- Python goes in scripts:
roscd <package>
mkdir scripts
cd scripts
- Example code
- Publisher
- Get code
wget https://raw.github.com/ros/ros_tutorials/kinetic-devel/rospy_tutorials/001_talker_listener/talker.py
chmod +x talker.py
- Update CMakeList.txt
catkin_install_python(PROGRAMS
scripts/talker.py
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
- Build code
cd ~/catkin_ws
catkin_make
- Subscriber
- Get code
wget https://raw.github.com/ros/ros_tutorials/kinetic-devel/rospy_tutorials/001_talker_listener/listener.py
chmod +x listener.py
- Update CMakeList.txt
catkin_install_python(PROGRAMS
scripts/listener.py
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
- Build code
cd ~/catkin_ws
catkin_make
- Server
- Get code
- http://wiki.ros.org/ROS/Tutorials/WritingServiceClient%28python%29
- Create add_two_ints_server.py
chmod +x add_two_ints_server.py
- Update CMakeList.txt
catkin_install_python(PROGRAMS
scripts/add_two_ints_server.py
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
- Build code
cd ~/catkin_ws
catkin_make
- Client
- Get code
- http://wiki.ros.org/ROS/Tutorials/WritingServiceClient%28python%29
- Create add_two_ints_client.py
chmod +x add_two_ints_client.py
- Update CMakeList.txt
catkin_install_python(PROGRAMS
scripts/add_two_ints_client.py
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
- Build code
cd ~/catkin_ws
catkin_make
- Execute Python nodes
roscore
cd ~/catkin_ws
source ./devel/setup.bash
rosrun <package> XXXX.py
- CPP
- CPP goes in src:
roscd <package>
mkdir -p src
cd src
- Example code
- Publisher
- Get code
wget https://raw.github.com/ros/ros_tutorials/noetic-devel/roscpp_tutorials/talker/talker.cpp
- Add to CMakeList.txt
add_executable(talker src/talker.cpp)
target_link_libraries(talker ${catkin_LIBRARIES})
add_dependencies(talker <package>_generate_messages_cpp)
- Build code
cd ~/catkin_ws
catkin_make
- Subscriber
- Get code
wget https://raw.github.com/ros/ros_tutorials/noetic-devel/roscpp_tutorials/listener/listener.cpp
- Add to CMakeList.txt
add_executable(listener src/listener.cpp)
target_link_libraries(listener ${catkin_LIBRARIES})
add_dependencies(listener <package>_generate_messages_cpp)
- Build code
cd ~/catkin_ws
catkin_make
- Server
- Get code
- http://wiki.ros.org/ROS/Tutorials/WritingServiceClient%28c%2B%2B%29
- Create add_two_ints_server.cpp
- Add to CMakeList.txt
add_executable(add_two_ints_server src/add_two_ints_server.cpp)
target_link_libraries(add_two_ints_server ${catkin_LIBRARIES})
add_dependencies(add_two_ints_server beginner_tutorials_gencpp)
- Build code
cd ~/catkin_ws
catkin_make
- Client
- Get code
- http://wiki.ros.org/ROS/Tutorials/WritingServiceClient%28c%2B%2B%29
- Create add_two_ints_client.cpp
- Add to CMakeList.txt
add_executable(add_two_ints_client src/add_two_ints_client.cpp)
target_link_libraries(add_two_ints_client ${catkin_LIBRARIES})
add_dependencies(add_two_ints_client beginner_tutorials_gencpp)
- Build code
cd ~/catkin_ws
catkin_make
- Executables located here at ~/catkin_ws/devel/lib/<package>
- Execute CPP nodes
roscore
cd ~/catkin_ws
source ./devel/setup.bash
rosrun <package> XXXX