在代码中,有一个类具有名为“goal_callback”的函数。在函数中,使用.init前缀定义变量,其他变量通常不使用前缀定义。 我知道,自我。前缀用于使变量成为“类变量”,以便类中的每个函数都可以访问它。所以在代码中,我只有一个函数,如果我们用self定义变量,会有什么不同吗。前缀与否。 “起飞”变量和“起飞”或“着陆”变量之间的差异到底是什么
#! /usr/bin/env python
class CustomActionMsgClass(object):
def __init__(self):
self._as = actionlib.SimpleActionServer("action_custom_msg_as", CustomActionMsgAction,
self.goal_callback, False)
def goal_callback(self, goal):
success = True
r = rospy.Rate(1)
self._pub_takeoff = rospy.Publisher('/drone/takeoff', Empty, queue_size=1)
self._takeoff_msg = Empty()
self._land_msg = Empty()
# Get the goal word: UP or DOWN
takeoff_or_land = goal.goal #goal has attribute named 'goal'.
if __name__ == '__main__':
rospy.init_node('action_custom_msg')
CustomActionMsgClass()
rospy.spin()
下面是对象级和类级变量的示例
在代码中
_pub_takeoff
是对象的变量takeoff_or_land
是局部变量相关问题 更多 >
编程相关推荐