from robot_control_class import RobotControl
import time
current_time = time.time()
# Create an instance of the RobotControl class
robotcontrol = RobotControl()
# initially get a laser scan
a = robotcontrol.get_laser(360)
# use a conditional while loop
while (a >= 1.0):
# move robot
robotcontrol.move_straight()
print("Current distance to wall: %f" % a)
# wait delay for 0.5 seconds to move straight
time.sleep(0.5)
# update laser scan reading for while loop
a = robotcontrol.get_laser(360)
# once while loop exits, stop the robot
robotcontrol.stop_robot()
# now turn the robot 90 degs
# stop the robot again
# finish up
# Turn the robot 90 degrees to the right
robotcontrol.turn(90, -1, 1.8)
# Concatenate a string and an integer
clockwise = "clockwise"
t = 5
print("Turned robot {} for {} seconds".format(clockwise, t))
From watching your video, I was able to get a few insights.
Your robot is not exactly stopping “just less than 1m” in front of the wall, but it is stopping way too close to the wall during the “move straight towards wall” stage. So you might want to move slowly until the robot is “just less than 1m” in front of the wall and not “right in front of the wall”.
You have turned 90 degrees correctly, but since you are way too close to wall when you turned 90 degrees, the front laser that should actually report a value of “infinity” is probably reporting a measurable finite value.
Your fix:
move robot slowly
stop just less than 1m in front of the wall
turn 90 degs and measure front laser if it reports infinity
I open the robot_control_class.py file where the RobotControl class is defined.
Find the move_straight function definition inside the RobotControl class. It should look like this:
def move_straight(self):
# code to move the robot straight
Modify the function definition to accept a speed parameter, like this:
def move_straight(self, speed=1):
# code to move the robot straight
I back to my code I add the parameter in this line :
Here my Full Code After Edit
from robot_control_class import RobotControl
import time
current_time = time.time()
# Create an instance of the RobotControl class
robotcontrol = RobotControl()
# initially get a laser scan
a = robotcontrol.get_laser(360)
# use a conditional while loop
while (a >= 1.0):
# move robot slowly
robotcontrol.move_straight(speed=0.1)
print("Current distance to wall: %f" % a)
# wait delay for 0.5 seconds to move straight
time.sleep(0.2)
# update laser scan reading for while loop
a = robotcontrol.get_laser(360)
# once while loop exits, stop the robot
robotcontrol.stop_robot()
# Turn the robot 90 degrees to the right
robotcontrol.turn(90, -1, 1.8)
time.sleep(5)
print("measurement after turn 90: %f" % a)
# Concatenate a string and an integer
clockwise = "clockwise"
t = 5
print("Turned robot {} for {} seconds".format(clockwise, t))
Yes, it will be the same, because you have not updated the a variable after the while loop finished.
Update a again after doing the 90 degree turn to measure frontal range of the robot! The variable is not going to update itself, unless you update it!
from robot_control_class import RobotControl
import time
current_time = time.time()
# Create an instance of the RobotControl class
robotcontrol = RobotControl()
# initially get a laser scan
a = robotcontrol.get_laser(360)
# use a conditional while loop
while (a >= 1.1): # change here: stop just less than 1m in front of the wall
# move robot
robotcontrol.move_straight()
print("Current distance to wall: %f" % a)
# wait delay for 1.0 seconds to move straight
time.sleep(0.1)
# update laser scan reading for while loop
a = robotcontrol.get_laser(360)
# once while loop exits, stop the robot
robotcontrol.stop_robot()
# Update measurement after the robot stops
a = robotcontrol.get_laser(360)
print("Current distance after Stop: %f" % a)
# Turn the robot 90 degrees to the right
robotcontrol.turn(90, -1, 1.8)
time.sleep(5)
print("measurement after turn 90 should be inf ..")
print("testing .....")
# Update measurement after the robot turns
a = robotcontrol.get_laser(360)
print("measurement after turn 90: %f" % a)
# Concatenate a string and an integer
clockwise = "clockwise"
t = 5
print("Turned robot {} for {} seconds".format(clockwise, t))
Sample:
facing an issue : I must now get inf reading but now giving me 5.1 m
I did what exactly you said Please See the Terminal in The Video
My Output
Current distance to wall: 3.417782
Current distance to wall: 2.875315
Current distance to wall: 2.339479
Current distance to wall: 1.789348
Current distance to wall: 1.269653
Current distance after Stop: 0.674259
measurement after turn 90 should be inf ..
testing .....
front laser value after turn 90: inf
Left Laser Value after turn 90: 0.654951
Turned robot clockwise for 5 seconds
I just saw your video, the robot actually takes around 2 seconds to turn 90 degrees, not 5 seconds.
Anyways, that is not a problem now. It has turned 90 degrees and measures “inf”.
Left laser scan value also seems fine to me.
I am not sure how to help you with this. Maybe someone from TheConstruct team can help you!
It looks fine to me. I finished this course over 3 months back - not too long, fairly recent - but I do remember doing the same thing and I got everything right.
I guess at this point, only TheConstruct team can help you out with this.
This task is a very simple task and if anything is wrong then there might be an issue with the Autograder (I believe so, I am not sure!).
Regards,
Girish
PS: Please don’t bold your sentences! Also avoid salutations like “dear”. You can just tag my name.
@nass2usa has already pointed out this error to me. It seems that the issue is coming from the provided robot_control_class.py which the student is supposed to just copy and paste.
I had already instructed him to fix it and I also think that he did. But the autograder seems to be failing.
I also vaguely remember that robotcontrol.turn() function did not take all the three arguments as a number. It was more like robotcontrol.turn(string, float, float) where the string was direction “clockwise” or “counterclockwise” and other two numbers were angular speed and degrees to rotate.
And how did you solve that issue? I’m asking because the error comes from a system file. In any case, I’ve already fixed that file in our system so now it works correctly. Also, I’ve updated the notebook to remove the Python class from there, since it’s not required to copy it.