Welcome to ROSMASTER X3 Plus repository
16.3 MoveIt moves randomly
3. Random movement
This lesson takes MoveIT simulation as an example. If you need to set up the real machine and simulation to be synchronized, please see the lesson [02, MoveIt Precautions and Controlling the Real Machine]. ! ! ! be safe! ! !
The effect demonstration is a virtual machine and other main control running conditions (related to the main control performance, depending on the actual situation).
3.1. Start
#Raspberry Pi 5 master needs to enter docker first, please perform this step#If running the script into docker fails, please refer to ROS/07, Docker tutorial~/run_docker.shStart MoveIT
xxxxxxxxxxroslaunch arm_moveit_demo x3plus_moveit_demo.launch sim:=true<PI5 needs to open another terminal to enter the same docker container

Start random motion node (choose one of two)
xxxxxxxxxxrosrun arm_moveit_demo 01_random_move.py # pythonrosrun arm_moveit_demo 01_random_move # C++The renderings are as follows

The source code implementation effect is the same as the MoveIT interface [MotionPlanning--->Planning--->Goal State (random)].
3.2, python source code
Import header file
xxxxxxxxxximport rospyfrom time import sleepfrom moveit_commander.move_group import MoveGroupCommanderInitialize nodes and create planning group instances
xxxxxxxxxx#Initialize node rospy.init_node("yahboomcar_random_move") # Initialize the robot arm planning group yahboomcar = MoveGroupCommander("arm_group")Set planning parameters
xxxxxxxxxx# When motion planning fails, re-planning is allowed yahboomcar.allow_replanning(True) # Set planning time yahboomcar.set_planning_time(5) # Number of attempts to plan yahboomcar.set_num_planning_attempts(10) #Set the allowed target position error yahboomcar.set_goal_position_tolerance(0.01) #Set the allowed target attitude error yahboomcar.set_goal_orientation_tolerance(0.01) # Set the allowable target error yahboomcar.set_goal_tolerance(0.01) # Set maximum speed yahboomcar.set_max_velocity_scaling_factor(1.0) # Set maximum acceleration yahboomcar.set_max_acceleration_scaling_factor(1.0)Set random target points in a loop
xxxxxxxxxxwhile not rospy.is_shutdown(): #Set random target point yahboomcar.set_random_target() # Start exercising yahboomcar.go() sleep(0.5)3.3, C++ source code
Import header file
xxxxxxxxxxCreate nodes and planning groups
xxxxxxxxxxros::init(argc, argv, "yahboomcar_random_move_cpp"); ros::NodeHandle n;ros::AsyncSpinner spinner(1);spinner.start(); moveit::planning_interface::MoveGroupInterface yahboomcar("arm_group");Set planning parameters and initial position
xxxxxxxxxx //Set the maximum speed yahboomcar.setMaxVelocityScalingFactor(1.0); //Set the maximum acceleration yahboomcar.setMaxAccelerationScalingFactor(1.0); //Set target point yahboomcar.setNamedTarget("down"); //Start moving yahboomcar.move(); sleep(0.1);Set random target points in a loop
xxxxxxxxxx while (!ros::isShuttingDown()){ //Set random target point yahboomcar.setRandomTarget(); yahboomcar.move(); sleep(0.5); }3.4, Node graph
Take C++ node as an example
