ROS implementation code and compiled code running steps

1. Implement a code step

1. C++ code implementation steps

Steps to create a function package in catkin_ws/src/
In fact, you can create a workspace arbitrarily. For example, create a new space named catkin_ws_new,
then compile and place code in this workspace.

  1. catkin_ws/src/Open terminal under

  2. Terminal input

catkin_create_pkg [XXX] roscpp rospy std_msgs...

[XXX]Define the function package name for yourself, so that you can enter the function package name later and execute the compiled function package.

  1. After creating the function package, enter the src of the function package and copy the code into it (note the suffix)

  2. Go back catkin_ws/src/[XXX]/(that is, return to the CMakeLists.txt of the newly created function package) CMakeLists.txtand configure the compilation rules of the copied code.
    For example:
    add_executable(velocity_publisher src/velocity_publisher.cpp) target_link_libraries(velocity_publisher ${catkin_LIBRARIES})
    Note here: if the placed code is such as velocity_publisher.cpp, then the two lines of compilation rules corresponding to the above need to correspond one to one. , otherwise a compilation error occurs.

Added to the end of "Build" and before "Install"

There are two main points in configuring code compilation rules:
setting the code to be compiled and the generated executable file;
and setting the link library.

  1. Compile and run the code.
    Go back catkin_ws/to the terminal and enter
catkin_make

(6. Set environment variables source devel/setup.bash)
(7. roscore)

2. python code implementation steps

  1. When catkin_ws/src/creating a function package (that is, opening the terminal catkin_ws/src/under )
    terminal input
catkin_create_pkg [XXX] roscpp rospy std_msgs...

[XXX]Define the function package name for yourself, so that you can enter the function package name later and execute the compiled function package.

  1. After creating the function package, catkin_ws/src/[XXX]/create a new folder named scripts, this folder is dedicated to python code files
  2. Open the terminal under the path catkin_ws/src/[XXX]/scripts/and enter
python [XXXXXXX].py

[XXXXXX].py is the python code file to be executed

Question: [pkg name] [py file]
rosrun demo_py hello.py

2. Steps to run compiled code

  1. Under terminalcd ~/catkin_ws

  2. Then enter

rosrun [XXXXXXX]  [XXXXXXX]

第一个[XXXXXXX]: The input is catkin_ws/src/the name of the function package created inside, such as " learning_test"
第一个[XXXXXXX]: The input is catkin_ws/src/the 第一个[XXXXXX]/src/name of the compiled CPP code inside. If " offb_node.cpp" code file, then 第二个[XXXXXX]it is " offb_node"

Supongo que te gusta

Origin blog.csdn.net/m0_64730542/article/details/124551676
Recomendado
Clasificación