在Python代码中遇到类未定义的错误

我是编程新手,正在完成一门关于自动驾驶汽车的课程。这是我的作业代码(纵向车辆模型)。我已经在注释(#)中尝试解释了代码。我遇到了以下错误:

类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”。请尝试重命名它们。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注