

タイトルの通り、最近、ros melodic から noetic
にロボットでバージョンアップしたところ、サンプルコードすら実行できず、エラーが報告される理由がわかりませんが、このロボットはすでに noetic
バージョンをサポートしています。

[![ターミナルの表示](https://i.stack.imgur.com/HM7Qi.png)](https://i.stack.imgur.com/HM7Qi.png)

[code]

    limlab@limlab:~$ rosrun sciurus17_examples pick_and_place_right_arm_demo.py
    Traceback (most recent call last):
      File "/home/limlab/catkin_ws/devel/lib/sciurus17_examples/pick_and_place_right_arm_demo.py", line 15, in <module>
        exec(compile(fh.read(), python_script, 'exec'), context)
      File "/home/limlab/catkin_ws/src/sciurus17_ros/sciurus17_examples/scripts/pick_and_place_right_arm_demo.py", line 152, in <module>
        main()
      File "/home/limlab/catkin_ws/src/sciurus17_ros/sciurus17_examples/scripts/pick_and_place_right_arm_demo.py", line 15, in main
        robot = mmoveit_commander.RobotCommander()
    AttributeError: module 'moveit_cammander' has no attribute 'RobotCommander'
    limlab@limlab:~$
    
[/code]

コードは以下の通りです。

[code]

    import rospy
    import moveit_commander
    import geometry_msgs.msg
    import rosnode
    import actionlib
    from tf.transformations import quaternion_from_euler
    from control_msgs.msg import (GripperCommandAction, GripperCommandGoal)
    
    
    def main():
        rospy.init_node("sciurus17_pick_and_place_controller")
        robot = moveit_commander.RobotCommander()
        arm = moveit_commander.MoveGroupCommander("r_arm_waist_group")
        arm.set_max_velocity_scaling_factor(0.1)
        gripper = actionlib.SimpleActionClient("/sciurus17/controller1/right_hand_controller/gripper_cmd", GripperCommandAction)
        gripper.wait_for_server()
        gripper_goal = GripperCommandGoal()
        gripper_goal.command.max_effort = 2.0
    
        rospy.sleep(1.0)
    
        print("Group names:")
        print(robot.get_group_names())
    
        print("Current state:")
        print(robot.get_current_state())
    
        # アーム初期ポーズを表示
        arm_initial_pose = arm.get_current_pose().pose
        print("Arm initial pose:")
        print(arm_initial_pose)
    
        # 何かを掴んでいた時のためにハンドを開く
        gripper_goal.command.position = 0.9
        gripper.send_goal(gripper_goal)
        gripper.wait_for_result(rospy.Duration(1.0))
    
        # SRDFに定義されている"home"の姿勢にする
        arm.set_named_target("r_arm_waist_init_pose")
        arm.go()
        gripper_goal.command.position = 0.0
        gripper.send_goal(gripper_goal)
        gripper.wait_for_result(rospy.Duration(1.0))
    
        # 掴む準備をする
        target_pose = geometry_msgs.msg.Pose()
        target_pose.position.x = 0.25
        target_pose.position.y = 0.0
        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]
        arm.set_pose_target(target_pose)  # 目標ポーズ設定
        arm.go()  # 実行
    
        # ハンドを開く
        gripper_goal.command.position = 0.7
        gripper.send_goal(gripper_goal)
        gripper.wait_for_result(rospy.Duration(1.0))
    
        # 掴みに行く
        target_pose = geometry_msgs.msg.Pose()
        target_pose.position.x = 0.25
        target_pose.position.y = 0.0
        target_pose.position.z = 0.13
        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]
        arm.set_pose_target(target_pose)  # 目標ポーズ設定
        arm.go()  # 実行
    
        # ハンドを閉じる
        gripper_goal.command.position = 0.4
        gripper.send_goal(gripper_goal)
        gripper.wait_for_result(rospy.Duration(1.0))
    
        # 持ち上げる
        target_pose = geometry_msgs.msg.Pose()
        target_pose.position.x = 0.25
        target_pose.position.y = 0.0
        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]
        arm.set_pose_target(target_pose)  # 目標ポーズ設定
        arm.go()                            # 実行
    
        # 移動する
        target_pose = geometry_msgs.msg.Pose()
        target_pose.position.x = 0.4
        target_pose.position.y = 0.0
        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]
        arm.set_pose_target(target_pose)  # 目標ポーズ設定
        arm.go()  # 実行
    
        # 下ろす
        target_pose = geometry_msgs.msg.Pose()
        target_pose.position.x = 0.4
        target_pose.position.y = 0.0
        target_pose.position.z = 0.13
        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]
        arm.set_pose_target(target_pose)  # 目標ポーズ設定
        arm.go()  # 実行
    
        # ハンドを開く
        gripper_goal.command.position = 0.7
        gripper.send_goal(gripper_goal)
        gripper.wait_for_result(rospy.Duration(1.0))
    
        # 少しだけハンドを持ち上げる
        target_pose = geometry_msgs.msg.Pose()
        target_pose.position.x = 0.4
        target_pose.position.y = 0.0
        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]
        arm.set_pose_target(target_pose)  # 目標ポーズ設定
        arm.go()  # 実行
    
        # SRDFに定義されている"home"の姿勢にする
        arm.set_named_target("r_arm_waist_init_pose")
        arm.go()
    
        print("done")
    
    
    if __name__ == '__main__':
    
        try:
            if not rospy.is_shutdown():
                main()
        except rospy.ROSInterruptException:
            pass
    
[/code]


CC BY-SA 4.0
2022-09-14T08:09:30.373
91103
2022-09-15T09:58:08.530
2022-09-15T09:58:08.530
26370
54384
question
python python3 linux ubuntu
ROSのエラー： AttributeError: module 'moveit_commander' has no attribute 'MoveGroupCommander'