首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用moveit接口移动ur5机器人?

如何使用moveit接口移动ur5机器人?
EN

Stack Overflow用户
提问于 2022-09-02 12:50:35
回答 1查看 109关注 0票数 0

我目前正在研究ROS,我的问题是:用moveit接口移动ur5机器人?我编写了一个代码,用来让机器人执行一个简单的动作:在运行代码之前,我启动Gazebo和Rviz。

代码语言:javascript
复制
#!/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()

但是当我运行代码时,我会得到以下错误:

代码语言:javascript
复制
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'
EN

回答 1

Stack Overflow用户

发布于 2022-09-02 18:09:57

在您的__init__函数中,您将move_group分配给局部变量,而不是类属性;因此,当您试图获取函数之外的值时,它是不可用的。相反,您应该使用self分配它,如下所示:

代码语言:javascript
复制
self.move_group = moveit_commander.MoveGroupCommander(group_name)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73582855

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档