本文主要部分全部来源于ROS官网的Tutorials.
roscore # making sure that we have roscore running
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key # Now you can use the arrow keys of the keyboard to drive the turtle around.
sudo apt-get install ros-kinetic-rqt
sudo apt-get install ros-kinetic-rqt-common-plugins
rosrun rqt_graph rqt_graph
rostopic -h
rostopic echo /turtle1/cmd_vel # you will now see topic datas when you press the arrow key in turtle_teleop_key terminal
rostopic list -h # figure out what argument the list sub-command needs
rostopic list -v # displays a verbose list of topics to publish to and subscribe to and their type
rostopic type /turtle1/cmd_vel # You should get the message type of the topic: geometry_msgs/Twist
rosmsg show geometry_msgs/Twist # look at the details of the message using rosmsg
# publishes data on to a topic, rostopic pub [topic] [msg_type] [args]
rostopic pub -1 /turtle1/cmd_vel geometry_msgs/Twist -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, 1.8]'
rostopic pub /turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, -1.8]'
rostopic echo /turtle1/pose
# see how fast the turtlesim_node is publishing /turtle1/pose, $ rostopic hz [topic]
rostopic hz /turtle1/pose
# get in depth information about a topic
rostopic type /turtle1/cmd_vel | rosmsg show
rosrun rqt_plot rqt_plot
rosservice list # shows us that the turtlesim node provides nine services
rosservice type /clear # find out what type the clear service is
rosservice call /clear # clears the background of the turtlesim_node
rosservice type /spawn | rossrv show
rosservice call /spawn 2 2 0.2 "" # spawn a new turtle at a given location and orientation
rosparam list # look at what parameters are currently on the param server
rosparam set /background_r 150 # change the red channel of the background color
rosservice call /clear # call the clear service for the parameter change to take effect
rosparam get /background_g # get the value of the green background channel
rosparam get / # show us the contents of the entire Parameter Serve
rosparam dump params.yaml # write all the parameters to the file ./params.yaml (current directory)
rosparam load params.yaml copy # load these yaml files into new namespaces
rosparam get /copy/background_b
This tutorial introduces ROS using rqt_console and rqt_logger_level for debugging and roslaunch for starting many nodes at once.
sudo apt-get install ros-kinetic-rqt ros-kinetic-rqt-common-plugins ros-kinetic-turtlesim
rosrun rqt_console rqt_console
rosrun rqt_logger_level rqt_logger_level
rosrun turtlesim turtlesim_node # Since the default logger level is INFO you will see any info that the turtlesim publishes when it starts up
roscd beginner_tutorials
mkdir launch
cd launch
gedit turtlemimic.launch
roslaunch beginner_tutorials turtlemimic.launch
rostopic pub /turtlesim1/turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, -1.8]' # the two turtlesims start moving even though the publish command is only being sent to turtlesim1
rosed roscpp Logger.msg # demonstrates how you would edit the Logger.msg file within the roscpp package
rosed roscpp
echo "export EDITOR='gedit -w'" >> ~/.bashrc
source ~/.bashrc
echo $EDITOR
rosed roscpp Logger.msg # This time file will be open by The more beginner-friendly editor
$ roscd beginner_tutorials
$ mkdir msg
$ echo "int64 num" > msg/Num.msg
rosed beginner_tutorials package.xml
Open package.xml, and make sure these two lines are in it.
rosed beginner_tutorials CMakeLists.txt
Modify it like this:
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
message_generation
)
…
catkin_package(
…
CATKIN_DEPENDS message_runtime …
…)
…
add_message_files(
FILES
Num.msg
)
…
generate_messages(
DEPENDENCIES
std_msgs
)
…
Make sure ROS can see it.
rosmsg show beginner_tutorials/Num # You will see: int64 num
rosmsg show Num # You will see: [beginner_tutorials/Num]: int64 num
$ roscd beginner_tutorials
$ mkdir srv
$ roscp rospy_tutorials AddTwoInts.srv srv/AddTwoInts.srv
$ rosed beginner_tutorials CMakeLists.txt
Modify it like this:
…
add_service_files(
FILES
AddTwoInts.srv
)
…
make sure that ROS can see it using the rossrv show command
rossrv show beginner_tutorials/AddTwoInts
rossrv show AddTwoInts
Now that we have made some new messages we need to make our package again:
$ roscd beginner_tutorials
$ cd ../..
$ catkin_make install
$ cd -
Any .msg file in the msg directory will generate code for use in all supported languages. The C++ message header file will be generated in ~/catkin_ws/devel/include/beginner_tutorials/.
rosmsg -h
Let's just list some of the commands we've used so far:
rospack = ros+pack(age) : provides information related to ROS packages
roscd = ros+cd : changes directory to a ROS package or stack
rosls = ros+ls : lists files in a ROS package
roscp = ros+cp : copies files from/to a ROS package
rosmsg = ros+msg : provides information related to ROS message definitions
rossrv = ros+srv : provides information related to ROS service definitions
catkin_make : makes (compiles) a ROS package
手机扫一扫
移动阅读更方便
你可能感兴趣的文章