Welcome to DOFBOT-JetsonNANO repository
4. MoveIt Random Movement
MoveIt Random Movement
MoveIt Random Movement1. Usage Environment2. Driving the Real Machine3. Launch MoveIt23.1 Random MovementStartup Command3.2 Source Code Analysis
1. Usage Environment
ROS2: Humble
Enter the commands in the tutorial into the accompanying virtual machine to run the function.
2. Driving the Real Machine
Driving the real machine is achieved by subscribing to the Moveit2 /joint_states topic, converting the joint state information of the robotic arm into control data for the actual robotic arm.
Note: Since the real robotic arm does not have obstacle avoidance capabilities, some poses may encounter obstacles; therefore, the planned robotic arm movements should be as reasonable as possible and avoid locations with obstacles.
(It is recommended to use preset poses for demonstrating the driving of the real machine.)
The Jetson-Nano motherboard requires multi-machine communication configuration. The robotic arm and the virtual machine need to be on the same network, and the virtual machine's ros_domain_id must be consistent with the ros_domain_id in the Docker container. (Both are pre-configured with the same ros_domain_id at the factory; simply ensure the virtual machine and the robotic arm are on the same network.)
3. Launch MoveIt2
xxxxxxxxxx# Launch this command in the virtual machine,ros2 launch dofbot_moveit demo.launch.py
3.1 Random Movement
This random movement demo is not recommended for use on a real machine, as some poses may encounter obstacles or hit the motherboard! **
Startup Command
The robotic arm needs to be successfully loaded in MoveIt and display You can start planning now!. Run the following command: The robotic arm will automatically plan a random action.
xxxxxxxxxx#Start this command in the virtual machine,ros2 run dofbot_moveit random_move
3.2 Source Code Analysis
Source code path:
xxxxxxxxxx#Path in the Virtual Machine~/dofbot_ws/src/dofbot_moveit/src/random_move.cppxxxxxxxxxxclass RandomMove : public rclcpp::Node{public: RandomMove() : Node("random_target_move") { // Initialize other content RCLCPP_INFO(this->get_logger(), "Initializing RandomMoveIt2Control."); } void initialize() { // Initialize move_group_interface_ and planning_scene_interface_ in this function. move_group_interface_ = std::make_shared<moveit::planning_interface::MoveGroupInterface>(shared_from_this(), "arm_group"); planning_scene_interface_ = std::make_shared<moveit::planning_interface::PlanningSceneInterface>(); move_group_interface_->setNumPlanningAttempts(10); // Set the maximum number of planning attempts to 10 move_group_interface_->setPlanningTime(5.0); // Set the maximum planning time per attempt to 5 seconds. // Plan Path moveit::planning_interface::MoveGroupInterface::Plan my_plan; // Move the robotic arm to the preset UP pose. move_group_interface_->setNamedTarget("up"); bool success = (move_group_interface_->plan(my_plan) == moveit::core::MoveItErrorCode::SUCCESS); if (success) { RCLCPP_INFO(this->get_logger(), "Init arm successed."); move_group_interface_->execute(my_plan); } else { RCLCPP_ERROR(this->get_logger(), "Init arm failed!"); } // Set random target position move_group_interface_->setRandomTarget(); bool success_random = (move_group_interface_->plan(my_plan) == moveit::core::MoveItErrorCode::SUCCESS); if (success_random) { RCLCPP_INFO(this->get_logger(), "Planning succeeded, moving the arm."); move_group_interface_->execute(my_plan); } else { RCLCPP_ERROR(this->get_logger(), "Planning failed!"); } }private: std::shared_ptr<moveit::planning_interface::MoveGroupInterface> move_group_interface_; std::shared_ptr<moveit::planning_interface::PlanningSceneInterface> planning_scene_interface_;};int main(int argc, char **argv){ rclcpp::init(argc, argv); auto node = std::make_shared<RandomMove>(); // Lazy Initialization node->initialize(); rclcpp::spin(node); rclcpp::shutdown(); return 0;}