Module 3 if statement

This code is given in the module 3.4:

if self.laser_forward > 5:
self.cmd.linear.x = 0.5
self.cmd.angular.z = 0.5
elif self.laser_forward < 5 and self.laser_forward >= 0.5:
self.cmd.linear.x = 0.2
self.cmd.angular.z = 0.0
else:
self.cmd.linear.x = 0.0
self.cmd.angular.z = 0.0

I am trying to understand what is the point of this conditional:
elif self.laser_forward < 5 and self.laser_forward >= 0.5:

Doesn’t the statement if self.laser_forward > 5: imply that the result for the next statement will be less or equal to 5?

Should the robot just stop at 5m? I think it is not part of the assignment.

I am trying to understand this code, but it does not make any sense to me. Can you explain what this code is doing?

Hi @Ipogorelov ,

Welcome to this Community!

Yes, you are correct in the assumption that the next statement of self.laser_forward > 5 would be self.laser_forward <= 5, but technically, laser scanners have a “deadzone” in the minimal distances.
Therefore you have three conditions:

  1. If self.laser_forward > 5 : move forward and turn with higher speed.
  2. If (self.laser_forward < 5) and (self.laser_forward >= 0.5) : move forward slowly but don’t turn
  3. If self.laser_forward <= 0.5 (the else condition) : stop the robot.
    The laser probably has a dead zone under 0.5 m, so any distance under 0.5 m might be undetected. So, to avoid unwanted collision, the robot is stopped when laser detection is under deadzone range.

Hope this makes sense.

Regards,
Girish

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.