After installation of Movelt, and tinker around in Rviz to move the robot, what’s essential is to learn to program in C++ to let robot move. It’s realized by MoveIt’s MoveItCpp API. steps to take
- add dependencies on the Movelt package to cmakelist.txt (find_package(moveit_msgs REQUIRED) find_package(moveit_ros_planning_interface REQUIRED) … ament_target_dependencies(myworkcell_node rclcpp moveit_msgs moveit_ros_planning_interface ) and to package.xml (<depend>moveit_msgs</depend> <depend>moveit_ros_planning_interface</depend>)
- open myworkcell_core/src/myworkcell_node.cpp add objects as new class members (moveit_cpp::MoveItCppPtr moveit_cpp_; moveit_cpp::PlanningComponentPtr planning_component_; moveit_cpp::PlanningComponent::PlanRequestParameters plan_parameters_;)
- add required includes (#include <moveit/moveit_cpp/moveit_cpp.h> #include <moveit/moveit_cpp/planning_component.h>)
- Create a new
setup()function insideScanNPlanafter the constructor and abovestart, to initialize the Movelt objects after the node started (// MoveIt setup void setup() { // Instantiate moveit_cpp moveit_cpp_ = std::make_shared<moveit_cpp::MoveItCpp>(this->shared_from_this()); // Planning component associated with a single motion group planning_component_ = std::make_shared<moveit_cpp::PlanningComponent>(“manipulator”, moveit_cpp_); // Parameters set on this node plan_parameters_.load(this->shared_from_this()); })


Then execution, launch and testing.