任务2
在 python_exam 文件夹中,创建一个名为 task2.py 的新 Python 脚本,该脚本执行以下操作: 以下:
a) 首先,它开始向前移动机器人,同时捕获激光读数 机器人前面。
b) 当激光读数检测到存在小于 1 的障碍物(墙壁)时 在机器人前方一米处,机器人将停止运动。
c) 停止后,机器人会向右转向 90 度,面向开口 房间的一角
这是我的代码:
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.7)
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))
我的输出结果是:
Current distance to wall: 5.515752
Current distance to wall: 5.039326
Current distance to wall: 4.567775
Current distance to wall: 4.036658
Current distance to wall: 3.503789
Current distance to wall: 2.954841
Current distance to wall: 2.495076
Current distance to wall: 1.974109
Current distance to wall: 1.437561
Current distance after Stop: 0.841572
measurement after turn 90 should be inf ..
testing .....
measurement after turn 90: inf
Turned robot clockwise for 5 seconds
问题是:
前方激光值不正确
左侧激光值不正确
这是测试视频,显示一切正常,除了在对任务进行评分时,使用 Gradebot 显示上述错误: https://www.youtube.com/watch?v=g-Ks_93oHDg&ab_channel=NasserCzar
您似乎正在调用此方法:
def turn(self, clockwise, speed, time):
但是你的电话是:
robotcontrol.turn(90, -1, 1.7)
而不是表示度数,
90
似乎起到了作用
更多的是评论。
被调用的方法期望它
可能有一个方向值,如 "clockwise"
。
值得
print()
诊断
从 .turn()
返回的结果。
另外,当您调试车削时,
查询当前的情况会很有用
指南针方向并报告。