MoveItCpp is a new high level interface, a unified C++ API that does not require the use of ROS Actions, Services, and Messages to access the core MoveIt functionality, and an alternative (not a full replacement) for the existing :doc:`MoveGroup API </doc/examples/move_group_interface/move_group_interface_tutorial>`, we recommend this interface for advanced users needing more realtime control or for industry applications. This interface has been developed at PickNik Robotics by necessity for our many commercial applications.
If you haven't already done so, make sure you've completed the steps in :doc:`Getting Started </doc/tutorials/getting_started/getting_started>`.
Open a shell, run the launch file:
ros2 launch moveit2_tutorials moveit_cpp_tutorial.launch.py
After a short moment, the RViz window should appear and look similar to the one at the top of this page. To progress through each demo step either press the Next button in the RvizVisualToolsGui panel at the bottom of the screen or select Key Tool in the Tools panel at the top of the screen and then press 0 on your keyboard while RViz is focused.
The entire code can be seen :codedir:`here in the MoveIt GitHub project<examples/moveit_cpp/src/moveit_cpp_tutorial.cpp >`. Next we step through the code piece by piece to explain its functionality.
.. tutorial-formatter:: ./src/moveit_cpp_tutorial.cpp
The entire launch file is :codedir:`here<examples/moveit_cpp/launch/moveit_cpp_tutorial.launch.py>` on GitHub. Notably, the launch file contains the following node
# MoveItCpp demo executable
moveit_cpp_node = Node(
name="moveit_cpp_tutorial",
package="moveit2_tutorials",
executable="moveit_cpp_tutorial",
output="screen",
parameters=[moveit_config.to_dict()],
)This node contains parameters which are passed to the executable associated with moveit_cpp_tutorial.
During the build process, the CMakeLists.txt file assigns where the launcher will look for the executable. Below is the CMakeLists.txt file for this tutorial:
add_executable(moveit_cpp_tutorial src/moveit_cpp_tutorial.cpp)
target_include_directories(moveit_cpp_tutorial PUBLIC include)
ament_target_dependencies(moveit_cpp_tutorial ${THIS_PACKAGE_INCLUDE_DEPENDS} Boost)
install(TARGETS moveit_cpp_tutorial
DESTINATION lib/${PROJECT_NAME}
)
install(DIRECTORY launch
DESTINATION share/${PROJECT_NAME}
)
install(DIRECTORY config
DESTINATION share/${PROJECT_NAME}
)add_executable builds the executable named moveit_cpp_tutorial from the source file src/moveit_cpp_tutorial.cpp.
target_include_directories specifies the directories to search for header files during compilation.
PUBLIC makes the include directory available to targets that depend on moveit_cpp_tutorial.
ament_target_dependencies specifies dependencies for the moveit_cpp_tutorial executable.
${THIS_PACKAGE_INCLUDE_DEPENDS} is a variable defined in the moveit2_tutorials root directory's CMakeLists.txt file, which list common dependencies used in moveit2_tutorials.
install(TARGET ...) and install(DIRECTORY ...) specify where to put the built executable and directories needed to run your program.
For more details about custom executables, please browse the other examples on this site as well as the ROS documentation.
