Welcome to Transbot SE repository
3.MoveIt moves randomly
3. MoveIt moves randomly
This lesson takes the MoveIT simulation as an example. If you need to set the synchronization between the real machine and the simulation, please refer to the lesson [02, MoveIt Precautions and Controlling the Real Machine]. ! ! ! be careful! ! !
The effect demonstration is a virtual machine, and other masters are running (related to the performance of the master, depending on the actual situation).
3.1. Start
Start the MoveIT
roslaunch transbot_se_moveit_config demo.launch Start random motion node (choose one of two)
xxxxxxxxxxrosrun transbot_se_moveit_config 01_random_move.py # pythonrosrun transbot_se_moveit_config 01_random_move # C++The effect diagram is as follows

The effect of the source code is the same as that of 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("transbot_set_move") # 初始化机械臂 Initialize the robotic arm transbot = MoveGroupCommander("arm_group")Set planning parameters
xxxxxxxxxx # 当运动规划失败后,允许重新规划 When motion planning fails, re-planning is allowed transbot.allow_replanning(True) transbot.set_planning_time(5) # 尝试规划的次数 Number of planning attempts transbot.set_num_planning_attempts(10) # 设置允许目标位置误差 Set the allowable target position error transbot.set_goal_position_tolerance(0.01) # 设置允许目标姿态误差 Set the allowable target attitude error transbot.set_goal_orientation_tolerance(0.01) # 设置允许目标误差 Set the allowable target error transbot.set_goal_tolerance(0.01) # 设置最大速度 Set maximum speed transbot.set_max_velocity_scaling_factor(1.0) # 设置最大加速度 Set maximum acceleration transbot.set_max_acceleration_scaling_factor(1.0)Loop to set random target points
xxxxxxxxxxwhile not rospy.is_shutdown(): # 设置随机目标点 Set random target points transbot.set_random_target() # 开始运动 Start transbot.go() sleep(0.5)3.3. C++ source code
Import header file
xxxxxxxxxxCreate nodes and planning groups
xxxxxxxxxx rros::init(argc, argv, "transbot_random_move_cpp"); ros::NodeHandle n; ros::AsyncSpinner spinner(1); spinner.start(); moveit::planning_interface::MoveGroupInterface transbot("arm_group");Set planning parameters and initial position
xxxxxxxxxx // 设置最大速度 Set maximum speed transbot.setMaxVelocityScalingFactor(1.0); // 设置最大加速度 Set maximum acceleration transbot.setMaxAccelerationScalingFactor(1.0); //设置目标点 Set target point transbot.setNamedTarget("down"); //开始移动 Start moving transbot.move(); sleep(0.1);Loop to set random target points
xxxxxxxxxx while (!ros::isShuttingDown()){ //设置随机目标点 Set random target points transbot.setRandomTarget(); transbot.move(); sleep(0.5); }3.4. Node diagram
Take C++ node as an example
