I’m following the Python for Robotics course and I’m woorking on Unit 4 - Methods. But when I take a look at the
robot_control_class.py I see many time the argument
self appearing. I’m trying to understand this. I have read another topic here where I saw a small explanation but I’m not sure if I understand it correct so I try to get the confirmation in this topic.
A small snippet of the
robot_control_class.py is below.
def __init__(self, robot_name="turtlebot"): rospy.init_node('robot_control_node', anonymous=True) if robot_name == "summit": rospy.loginfo("Robot Summit...") cmd_vel_topic = "/summit_xl_control/cmd_vel" # We check that sensors are working self._check_summit_laser_ready() else: rospy.loginfo("Robot Turtlebot...") cmd_vel_topic='/cmd_vel' self._check_laser_ready() # We start the publisher self.vel_publisher = rospy.Publisher(cmd_vel_topic, Twist, queue_size=1) self.cmd = Twist() self.laser_subscriber = rospy.Subscriber( '/kobuki/laser/scan', LaserScan, self.laser_callback) self.summit_laser_subscriber = rospy.Subscriber( '/hokuyo_base/scan', LaserScan, self.summit_laser_callback) self.ctrl_c = False self.rate = rospy.Rate(1) rospy.on_shutdown(self.shutdownhook)
So now if I create a script and import the class and instantiate it as follows:
from robot_control_class import RobotControl rc = RobotControl() disValues = rc.get_laser_full() maximum = 0 for dis in disValues: if dis > maximum: maximum = dis print("Maximum distance is:", maximum) Does the argument `self` basically says that I refer to the variable `rc`?
Thanks in advance