ROS
ROS or Robot Operating System is a midlewear
run a roscore :
roscore
make a workspace :
mkdir -p \~/catkin_ws/src
cd \~/catkin_ws/src
catkin_init_workspace
build a workspace :
cd \~/catkin_ws/
catkin_make or catkin build
to build one specific pkg :
catkin_make --only-pkg-with-deps
or
catkin build
source a wrokspace :
source devel/setup.bash
creat a package :
cd \~/catkin_ws/src
catkin_create_pkg
ex :
catkin\_create\_pkg beginner\_tutorials std\_msgs rospy for python nodes
catkin\_create\_pkg beginner\_tutorials std\_msgs roscpp for cpp nodeadd a node to a package :
cd \~/catkin_ws/src/
touch
sudo nano ../CmakeList.txt
add at the end those lines :
catkin_install_python(PROGRAMS src/
DESTINATION \${CATKIN_PACKAGE_BIN_DESTINATION}
)
run a node :
rosrun [package_name] [node_name]
find a package :
rospack find name_of_the_package
go to a package folder :
roscd name_of_the_package
creat selfmade msg :
http://wiki.ros.org/ROS/Tutorials/CreatingMsgAndSrv
Network
export ROS\_HOSTNAME=localhost\
export ROS\_MASTER\_URI=[http://localhost:11311](http://localhost:11311/)
export ROS\_IP=192.168.x.xSERVICE
[]{#anchor}[]{#anchor-1}[]{#anchor-2}rospy.wait_for_service('
http://wiki.ros.org/action/show/rosmsg?action=show&redirect=rossrv
ACTION
http://wiki.ros.org/actionlib_tutorials/Tutorials
https://www.theconstructsim.com/ros-5-mins-034-ros-action/
TOPIC
listing of all the topic :
rostopic list
listen a topic :
rostopic echo
publish in a topic via a terminal :
rostopic pub
ex :
rostopic pub /turtle1/cmd\_vel geometry\_msgs/Twist \"linear:
x: 0.0
y: 0.0
z: 0.0
angular:
x: 0.0
y: 0.0
z: 0.0\"tips : use double tab to fill up the message
soft to show topic's data :
rqt_plot
rosrun plotjuggler plotjuggler
SUBSCRIBER
self.sub
parameters :
* name : // name of the topic
* data_class : // class of the data
* callback : // function call when new message arrive
* callback_args : // args send to the callback
* queue_size : // number max of message that can be receive at the same time
* buff_size : // buffer size (number of message save)
function :
self.sub
PUBLISHER
self.pub
parameters :
* name : // name of the topic
* data_class : // class of the data
* subscriber_listener : // listener for subscription event
* latch : // if TRUE send the last message to a new listener
* queue_size : // number of message save for asynchronouslypublishing messages
function :
self.pub
self.pub
self.pub
ROSBAG
rosbag record
-a // all
--duration=30 // duration limit
-b 1024 // size max in MB
-l 1000 // number max of message save
rosbag play
-q //without output in the shell
--clock // publish the clock time
--hz=200 // publish with this frequency
-s 5 // start x second after the begining
-l // loop
to sync the timestamp of your syst with .bag file's timestamp run this command :
rosparam set use_sim_time true
rosbag filter
to modify rosbag with an ihm use this tools : <https://github.com/facontidavide/rosbag_editor>
**
Blank node Python exemple :
**
-------------------------------------------
#!/usr/bin/python
#Maxime Duquesne 28/09/2022 \@CRSITAL
import rospy
import std_msgs.msg
""" here import another lib or msg """
class <node_name>():
""" here creat and fill global class varibles """
def __init__(self):
""" here load ros parameters """
if rospy.has_param('<parameter_name>'):
self.<varible_name> = rospy.get_param('<parameter_name>')
else :
print("no parameter topic <parameter_name> , default : <default_value>)
rospy.init_node('<node_name>')
""" here creat your subscriber and publisher """
self.sub<sub_name> = rospy.Subscriber('<topic_name>',<msg_type>, <callback_name>)
self.pub<pub_name> = rospy.Publisher('<topic_name>',<msg_type>, queue_size=<lenght>)
self.main_loop()
def __del__(self):
\\\ here clear your variable \\\
self.sub<sub_name>.unregister()
self.pub<pub_name>.unregister()
print("shutdown")
def main_loop(self):
rate = rospy.Rate(<frequency>)
while not rospy.is_shutdown(): \# until the node isn't kill or the roscore is shutdown
""" here do your stuff """
rate.sleep() # sleep for the duration of the rate
def ros_main():
<node_variable_name> = <node_name>()
rospy.spin() \# stuck here until the prg is not kill or the roscore is shutdown
if __name__ == '__main__':
ros\_main()-------------------------------------------
links :
http://wiki.ros.org/fr/ROS/Tutorials
http://wiki.ros.org/turtlesim/Tutorials
http://wiki.ros.org/rosbag/Code%20API
http://wiki.ros.org/rosbag/Commandline
http://docs.ros.org/en/jade/api/rospy/html/rospy-module.html