New construction

Create a Catkin project environment, skip if you already have one
# mkdir -p catkin_ws/src

cd src
catkin_create_pkg showpath roscpp sensor_msgs std_msgs nav_msgs tf
cd. catkin_makeCopy the code

【catkin_make: No module named ‘catkin_pkg’】

ImportError: “from catkin_pkg.topological_order import topological_order” failed: No module named 'catkin_pkg'
Make sure that you have installed “catkin_pkg”, it is up to date and on the PYTHONPATH.
Copy the code

Solution:

  1. Open the catkin_make file
sudo gedit /opt/ros/kinetic/bin/catkin_make
Copy the code

Because catkin_make is a system file readonly, it cannot be edited via vim

2. Change the Python script interpreter to#! /usr/bin/python2Can be

Compile and run

  1. Write the main function: inshowpath/src/Created in theshowpath.cpp
  2. The editorCMakeLists.txtIn:showpath/CMakeLists.txtAdd two lines at the end
add_executable(showpath src/showpath.cpp)
target_link_libraries(showpath ${catkin_LIBRARIES})
Copy the code
  1. compile
Go back to the catkin_ws directory
# cd ~/catkin_ws

rm -rf build
catkin_make -j2
Copy the code
  1. run
source ./devel/setup.bash

Open a terminal to run
roscore

Open another terminal to run
rosrun showpath showpath

Open the third terminal test
rostopic echo /trajector
Copy the code

ROS master cannot connect to ROS master Unable to contact ROS master at [http://192.168.0.20:11311]] question reason: no running roscore solution: in the new terminal operation roscore other solution: export path

$ export ROS_HOSTNAME=localhost
$ export ROS_MASTER_URI=http://localhost:11311
Copy the code

Libroscpp. so: cannot open shared object file: No such file or directory

[rosout-1] restarting process
/opt/ros/melodic/lib/rosout/rosout: error while loading shared libraries: libroscpp.so: cannot open shared object file: No such file or directory
process[rosout-1]: started with pid [14028]
[rosout-1] process has died [pid 14028, exit code 127, cmd /opt/ros/melodic/lib/rosout/rosout __name:=rosout __log:=/home/nano/.ros/log/9bbbb974-69d3-11eb-a0bf-48b02d2de5df/rosout-1.log].
log file: /home/nano/.ros/log/9bbbb974-69d3-11eb-a0bf-48b02d2de5df/rosout-1*.log
Copy the code

Solution: Type the command directly on the command line to specify the path

LD_LIBRARY_PATH=/opt/ros/melodic/lib
Copy the code

Rviz experimental effect

rosrun rviz rviz
Copy the code
  1. inGlobal OptionsTake the first termFixed FrameInstead ofworld
  2. Click in the lower left corner of the sidebarAdd, add aPath
  3. inPathThe middle and lower,Topic, the choice of/trajectory

Resources

ROS displays tracks in real time in RVIz (use of nav_MSgs /Path messages) _qq_43176116 blog -CSDN blog