2

enter image description hereI am using ROS and python to write a robot program. This program can run normally on ROS melodic, but it will raise AttributeError: module 'moveit_commander' has no attribute 'MoveGroupCommander' on noetic, may I ask this is ros Is there a reason for the version? Is there a way to end it?enter image description here

this is my code

def pick1(self, forward, side, object, euler, nanko):
        target_x = forward+0.07
        target_y = side
        if object == 1:
            object_placeX = 0.55
            object_placeY = 0.2
        elif object == 2:
            object_placeX = 0.4
            object_placeY = 0.25
        elif object == 3:
            object_placeX = 0.3
            object_placeY = 0.3
        else:
            sys.exit()

        if nanko > 0:
            object_placeX -= 0.05

        # 左手
        left_arm = moveit_commander.MoveGroupCommander("l_arm_waist_group")
        left_arm.set_max_velocity_scaling_factor(0.2)
        left_gripper = actionlib.SimpleActionClient("/sciurus17/controller2/left_hand_controller/gripper_cmd", GripperCommandAction)
        left_gripper.wait_for_server()

        gripper_goal = GripperCommandGoal()
        gripper_goal.command.max_effort = 2.0

        rospy.sleep(0.3)

        gripper_goal.command.position = -0.9
        left_gripper.send_goal(gripper_goal)
        left_gripper.wait_for_result(rospy.Duration(1.0))

        # SRDFに定義されている"home"の姿勢にする
        left_arm.set_named_target("l_arm_waist_init_pose")
        left_arm.go()
        gripper_goal.command.position = 0.0
        left_gripper.send_goal(gripper_goal)
        left_gripper.wait_for_result(rospy.Duration(1.0))

        # 掴む準備をする
        target_pose = geometry_msgs.msg.Pose()
        target_pose.position.x = target_x
        target_pose.position.y = target_y
        target_pose.position.z = 0.3
        q = quaternion_from_euler(-3.14 / 2.0, 0.0, euler)  # 上方から掴みに行く場合
        target_pose.orientation.x = q[0]
        target_pose.orientation.y = q[1]
        target_pose.orientation.z = q[2]
        target_pose.orientation.w = q[3]
        left_arm.set_pose_target(target_pose)  # 目標ポーズ設定
        left_arm.go()  # 実行

        # ハンドを開く
        gripper_goal.command.position = -0.7
        left_gripper.send_goal(gripper_goal)
        left_gripper.wait_for_result(rospy.Duration(1.0))

        # 掴みに行く
        target_pose = geometry_msgs.msg.Pose()
        target_pose.position.x = target_x
        target_pose.position.y = target_y
        target_pose.position.z = 0.11
        q = quaternion_from_euler(-3.14 / 2.0, 0.0, euler)  # 上方から掴みに行く場合
        target_pose.orientation.x = q[0]
        target_pose.orientation.y = q[1]
        target_pose.orientation.z = q[2]
        target_pose.orientation.w = q[3]
        left_arm.set_pose_target(target_pose)  # 目標ポーズ設定
        left_arm.go()  # 実行

        # ハンドを閉じる
        gripper_goal.command.position = -0.3
        left_gripper.send_goal(gripper_goal)
        left_gripper.wait_for_result(rospy.Duration(1.0))

        # 持ち上げる
        target_pose = geometry_msgs.msg.Pose()
        target_pose.position.x = target_x
        target_pose.position.y = target_y
        target_pose.position.z = 0.3
        q = quaternion_from_euler(-3.14 / 2.0, 0.0, euler)  # 上方から掴みに行く場合
        target_pose.orientation.x = q[0]
        target_pose.orientation.y = q[1]
        target_pose.orientation.z = q[2]
        target_pose.orientation.w = q[3]
        left_arm.set_pose_target(target_pose)  # 目標ポーズ設定
        left_arm.go()  # 実行

        # 移動する
        target_pose = geometry_msgs.msg.Pose()
        target_pose.position.x = object_placeX
        target_pose.position.y = object_placeY
        target_pose.position.z = 0.3
        q = quaternion_from_euler(-3.14 / 2.0, 0.0, 0.0)  # 上方から掴みに行く場合
        target_pose.orientation.x = q[0]
        target_pose.orientation.y = q[1]
        target_pose.orientation.z = q[2]
        target_pose.orientation.w = q[3]
        left_arm.set_pose_target(target_pose)  # 目標ポーズ設定
        left_arm.go()  # 実行

        # 下ろす
        target_pose = geometry_msgs.msg.Pose()
        target_pose.position.x = object_placeX
        target_pose.position.y = object_placeY
        target_pose.position.z = 0.14
        q = quaternion_from_euler(-3.14 / 2.0, 0.0, 0.0)  # 上方から掴みに行く場合
        target_pose.orientation.x = q[0]
        target_pose.orientation.y = q[1]
        target_pose.orientation.z = q[2]
        target_pose.orientation.w = q[3]
        left_arm.set_pose_target(target_pose)  # 目標ポーズ設定
        left_arm.go()  # 実行

        # ハンドを開く
        gripper_goal.command.position = -0.7
        left_gripper.send_goal(gripper_goal)
        left_gripper.wait_for_result(rospy.Duration(1.0))

        # 少しだけハンドを持ち上げる
        target_pose = geometry_msgs.msg.Pose()
        target_pose.position.x = object_placeX
        target_pose.position.y = object_placeY
        target_pose.position.z = 0.2
        q = quaternion_from_euler(-3.14 / 2.0, 0.0, 0.0)  # 上方から掴みに行く場合
        target_pose.orientation.x = q[0]
        target_pose.orientation.y = q[1]
        target_pose.orientation.z = q[2]
        target_pose.orientation.w = q[3]
        left_arm.set_pose_target(target_pose)  # 目標ポーズ設定
        left_arm.go()  # 実行

        # SRDFに定義されている"home"の姿勢にする
        left_arm.set_named_target("l_arm_waist_init_pose")
        left_arm.go()

        print("done")
Wuxx959
  • 21
  • 2

1 Answers1

0

The reason it works different between versions is because Noetic uses Python3 and Melodic uses Python2.7. A key difference here is how they handle imports, and thus why you're having a problem. Make sure at the top of your script you have:

import moveit_commander

If that doesn't work it means you need to install the Noetic version of moveit via: sudo apt install ros-noetic-moveit

BTables
  • 4,413
  • 2
  • 11
  • 30
  • Thank you for your reply, I have tried to rebuild moveit from source code on two computers, but now I encounter an error from mu5dm, indicating that the versions are out of sync, what is the reason?I have uploaded the picture of the error in the question – Wuxx959 Sep 15 '22 at 01:08
  • @Wuxx959 that’s a separate issue. Usually that one would be caused by using the wrong distro message. If you built from source it’s most likely that you’re building for the wrong ROS distro. – BTables Sep 15 '22 at 15:07