My task 1 and 3 code below. That’s wrong? May You help my.
TASK 1
#!/usr/bin/env python
from cmath import inf
from robot_control_class import RobotControl
robotcntl = RobotControl()
l = robotcntl.get_laser_full()
def get_highest_lowest(list_check):
max = 0
i = 0
for value1 in l:
if value1 > max and value1 != inf:
max = value1
max_pos = i + 1
i+=1
min = max
i = 0
for value2 in l:
if value2 < min:
min = value2
min_pos = i + 1
i+=1
return [max_pos, min_pos] #pos_list = get_highest_lowest(l) #print (l) #print ("The position of higher value in the list is: ", pos_list[1]) #print ("The position of lowest value in the list is: ", pos_list[0])
TASK 3
#!/usr/bin/env python3
from robot_control_class import RobotControl
from cmath import inf
class ExamControl:
def init(self,motion,speed):
self.rc = RobotControl(robot_name=“turtlebot”)
self.motion = motion
self.speed = speed
Hi @rimmhomeem, could you please briefly summarize what tasks 1 and 3 are? What exactly is the description to pass the exam? Maybe you are missing an instruction.
As for the code you shared, it is really hard to read unformatted. To do so, please wrap your code in three ` symbols:
this is an example
It seems like you did so in the task 3 code for some of it. It’s really hard to help you with only the code pasted, we need more context.
I’ve made some changes in my code Task 2 - and pass Task 3 and Exam with scope 8.5!
Why Task 2?
In my view - the bot checks final position - so only made a little change in final angle position (Task 2) and got a green mark in Task3 scope.
Only one question left - what is wrong in code Task 1? I’ve checked it many times - maybe laser distance can be different while the bot checks the task?
TASK 1
#!/usr/bin/env python
from cmath import inf
from robot_control_class import RobotControl
robotcntl = RobotControl()
l = robotcntl.get_laser_full()
def get_highest_lowest(list_for_check):
max = 0
i = 0
pos = [0, 0]
for value1 in l:
if (value1 > max) and (value1 != inf):
max = value1
pos[0] = i + 1
i+=1
min = max
i = 0
for value2 in l:
if value2 < min:
min = value2
pos[1] = i + 1
i+=1
return pos
Task 1, summarized, is asking you to find the highest and lowest value of a list of laser readings, and return its position.
In your code, once you find max, you assign that value as min and start looping through the list to check for a smaller value. So the logic makes sense.
I’d say the fluctuation is due to the noise of the laser readings, because the min seems to stay in the same region.
One thing you can do is check the length of the list, move the robot, and see if the results make sense. Usually, the robot laser starts at the back and goes around counter-clockwise, so you can figure out if the results you are seeing make sense.