我有以下Python类,即使我在引起错误的行之前使用它,也坚持未定义 self 。
错误:
File "/home/sisko/moveit_ws/src/ur5bot_moveit_config/nodes/test.py", line 35, in Test
end_effector_link = self.arm.get_end_effector_link()
NameError: name 'self' is not defined
代码:
#!/usr/bin/env python
import moveit_commander
import rospy
from copy import deepcopy
class Test():
"""docstring for Test"""
def __init__(self):
rospy.init_node('move_group_python_interface_tutorial', anonymous=False)
# declarations
self.robot = moveit_commander.RobotCommander()
self.arm = moveit_commander.MoveGroupCommander('manipulator')
joint_positions = [0.2 ,-0.5, 1.57, -1.0, -0.4, 0.5]
self.arm.set_joint_value_target(joint_positions)
self.arm.go()
rospy.sleep(5)
self.arm.set_named_target('up')
self.arm.go()
rospy.sleep(5)
self.arm.set_named_target('home')
self.arm.go()
# Get the name of the end-effector link
end_effector_link = self.arm.get_end_effector_link()
if __name__ == '__main__':
t = Test()