pythonrosroboticsmoveit

how to move ur5 robot using the moveit interface?


I am currently working on ROS and my question is: hoe to move ur5 robot using the moveit interface? I have written a code that is supposed to make the robot perform a simple movement: Before running the code, I start Gazebo and Rviz.

#!/usr/bin/env python3

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


class MoveRobotNode():
    """MoveRobotNode"""

    def __init__(self):
        moveit_commander.roscpp_initialize(sys.argv)
        rospy.init_node("move_robot_node", anonymous=True)

        robot = moveit_commander.RobotCommander()

        scene = moveit_commander.PlanningSceneInterface()

        group_name = "manipulator"
        move_group = moveit_commander.MoveGroupCommander(group_name)

    def go_to_joint_state(self):

        move_group = self.move_group

        joint_goal = move_group.get_current_joint_values()
        joint_goal[0] = 0
        joint_goal[1] = -tau / 8
        joint_goal[2] = 0
        joint_goal[3] = -tau / 4
        joint_goal[4] = 0
        joint_goal[5] = tau / 6  # 1/6 of a turn
        joint_goal[6] = 0

        move_group.go(joint_goal, wait=True)

        move_group.stop()

if __name__ == "__main__":
    robot_control = MoveRobotNode()
    robot_control.go_to_joint_state()


but when I run the code, I get this error:

maha@ms21:~/catkin_ws/src/move_robot_pkg$ python3 move_robot_node.py
[ INFO] [1662122291.175640005, 1575.932000000]: Loading robot model 'ur5'...
[ WARN] [1662122291.229793210, 1575.986000000]: Kinematics solver doesn't support #attempts anymore, but only a timeout.
Please remove the parameter '/robot_description_kinematics/manipulator/kinematics_solver_attempts' from your configuration.
[ INFO] [1662122292.257776819, 1577.012000000]: Ready to take commands for planning group manipulator.
Traceback (most recent call last):
 File "move_robot_node.py", line 47, in <module>
   robot_control.go_to_joint_state()
 File "move_robot_node.py", line 30, in go_to_joint_state
   move_group = self.move_group
AttributeError: 'MoveRobotNode' object has no attribute 'move_group'



Solution

  • In your __init__ function you're assigning move_group to a local variable and not a class attribute; so when you try to get the value outside of the function it isn't available. Instead you should assign it with self like so:

    self.move_group = moveit_commander.MoveGroupCommander(group_name)