MicroProject - how to pass a variable to get_laser(360)

I am stucked in the start of the MicroProject.

I want to make the robot move until one distance before the wall, and then make it turn.
I don´t have clear how to pass a variable in the function get_laser(360).
Would this approach be correct? or should I try another?

from robot_control_class import RobotControl

class MoveRobot:

    def __init__(self, motion, speed, time, get_laser):

        self.robotcontrol = RobotControl()

        self.motion = motion

        self.speed = speed

        self.time = time

        self.get_laser() = get_laser()

    def move_to_wall(self):

        a = self.robotcontrol.get_laser(360)

        if a <= 2:

            self.stop_robot()

        else:

            self.move_straight()

    def get_laser(self):

        self.robotcontrol.get_laser(360)

    def move_straight(self):

        self.robotcontrol.move_straight()

    

    def move_straight_time(self):

        self.robotcontrol.move_straight_time(self.motion, self.speed, self.time)

    def stop_robot(self):

        self.stop_robot()

mr1 = MoveRobot('forward', 0.3, 2, get_laser(360))

mr1.move_to_wall()

Many thanks,

Hello @cesarlopezleyton,

Yes, in order to evaluate a specific value from the laser, you would do it like this: get_laser(360). In this case, the value 360 corresponds to the front readings of the robot, as explained at the beginning of Unit 2 (you can have a look if you want to refresh it).

Now, in order to evaluate the value obtained from the laser, I would suggest you use a loop rather than a simple if/else statement. You can better understand why in Exercises 3.1 and 3.2 from Unit 3.

Best,

Many thanks for the quick answer. Now I am a little bit stucked. I am trying to make the robot turn to the direction where the distance is longer and then move straight on. But I don´t know how to implement it. I can get the longer distance from the laser beam, as well as the laser direction. I don´t how to continue. Perhaps I am doing it too complicated. Just trying to implement a loop. But we should try to implement when the turn should be clockwise or counterclockwise. And towards what laser beam direction.

from robot_control_class import RobotControl

class MoveRobot:

    def __init__(self, motion, speed, time):

        self.robotcontrol = RobotControl()

        self.motion = motion

        self.speed = speed

        self.time = time

        self.get_laser_full = get_laser_full()

        self.get_laser = get_laser(360)

    def move_to_wall(self):

        a = self.robotcontrol.get_laser_full()

        

        maxim_distance = 0

        counter = 0

        maxim_direction = 0

        for value in a:

            if value > maxim_distance:

                maxim_distance = value

                maxim_direction = counter

            counter = counter + 1

        print ("The higher distance is: ", maxim_distance)

        print ("The beam direction is: ", maxim_direction)

        self.get_laser_direction(maxim_direction)

        i = 0

        while (i<3):

            self.turn()

            self.move_straight()

            i+=1

    def move_straight(self):

        self.robotcontrol.move_straight()

    

    def move_straight_time(self):

        self.robotcontrol.move_straight_time(self.motion, self.speed, self.time)

    def stop_robot(self):

        self.stop_robot()

mr1 = MoveRobot('forward', 0.3, 2)

mr1.move_to_wall()

Thanks again,