Control UR5 robot by setting joint value in Final Project

Hi

I followed the instruction to run the python script to move the UR5 arm. But I met a problem that I can 100% follow the given example with group.go in the simulator. While if I comment that, the trajectory is not complete in the Rviz environment. Below is my code

#! /usr/bin/env python

import sys
import copy
import rospy
import moveit_commander
import moveit_msgs.msg
import geometry_msgs.msg

moveit_commander.roscpp_initialize(sys.argv)
rospy.init_node('move_group_python_interface_tutorial', anonymous=True)

robot = moveit_commander.RobotCommander()
scene = moveit_commander.PlanningSceneInterface()
group = moveit_commander.MoveGroupCommander("manipulator")
display_trajectory_publisher = rospy.Publisher('/move_group/display_planned_path', moveit_msgs.msg.DisplayTrajectory)

group_variable_values = group.get_current_joint_values()

group_variable_values[1] = 0
group_variable_values[2] = 0
group.set_joint_value_target(group_variable_values)
plan1 = group.plan()
group.go(wait=True)

group_variable_values[1] = -1.5
group_variable_values[2] = 1.5
group.set_joint_value_target(group_variable_values)
plan1 = group.plan()
group.go(wait=True)

group_variable_values[2] = 0
group.set_joint_value_target(group_variable_values)
plan1 = group.plan()
group.go(wait=True)

group_variable_values[1] = -1.5
group_variable_values[2] = 1.5
group.set_joint_value_target(group_variable_values)
plan1 = group.plan()
group.go(wait=True)

group_variable_values[1] = 0
group_variable_values[2] = 0
group.set_joint_value_target(group_variable_values)
plan1 = group.plan()
group.go(wait=True)

rospy.sleep(5)

moveit_commander.roscpp_shutdown()

Hello @youngyangcs,

I’m not sure that I understand your problem. The group.plan() function is used in order to calculate the plan of the trajectory and show it in RViz, thus it will be shown in RViz but not executed in the simulation. On the other hand, the group.go() function is used to calculate and execute the plan in the simulation, this it will be executed in the simulation but not shown in RViz. It will only be shown and executed in RViz and in the simulation if you leave those 2 lines. Does this make sense for you?

Best,

The problem I met is I couldn’t get a complete trajectory when using the group.plan