我是编程新手,正在完成一门关于自动驾驶汽车的课程。这是我的作业代码(纵向车辆模型)。我已经在注释(#)中尝试解释了代码。我遇到了以下错误:
类Bicycle未定义。
代码如下:
from notebook_grader import BicycleSolution, grade_bicycleimport numpy as npimport matplotlib.pyplot as pltimport matplotlib.image as mpimgclass Bicycle(): def __init__(self): self.xc = 0 self.yc = 0 self.theta = 0 self.delta = 0 self.beta = 0 self.L = 2 self.lr = 1.2 self.w_max = 1.22 self.sample_time = 0.01def reset(self): self.xc = 0 self.yc = 0 self.theta = 0 self.delta = 0 self.beta = 0class Bicycle(Bicycle): def step(self, v, w): # ================================== # Implement kinematic model here # ================================== #so that max rate is not exceeded if w > 0: w = min(w, self.w_max) else: w = max(w, -self.w_max) #sampling time t_sample = 10e-3 #implementing the differential equations xc_dot = v * np.cos(self.theta + self.beta) yc_dot = v * np.sin(self.theta + self.beta) theta_dot = (v / self.L) * (np.cos(self.beta) * np.tan(self.delta)) delta_dot = w self.beta = np.arctan(self.lr * np.tan(self.delta) / self.L) #update equations using the sampling time self.xc += xc_dot * t_sample self.yc += yc_dot * t_sample self.theta += theta_dot * t_sample self.delta += delta_dot * t_sample
回答:
您定义了两个冲突的类:父类和子类都是”Bicycle”。请尝试重命名它们。