# The desired speed can be computed from the circumference of the circle: # # \begin{align*} # v &= \frac{d}{t}\\ # &= \frac{2 \pi 10}{20}\\ # &= \pi # \end{align*} # # We can now implement this in a loop to step through the model equations. We will also run our bicycle model solution along with your model to show you the expected trajectory. This will help you verify the correctness of your model. # In[46]: sample_time = 0.01 time_end = 20 model = Bicycle() solution_model = BicycleSolution() # set delta directly model.delta = np.arctan(2 / 10) solution_model.delta = np.arctan(2 / 10) t_data = np.arange(0, time_end, sample_time) x_data = np.zeros_like(t_data) y_data = np.zeros_like(t_data) x_solution = np.zeros_like(t_data) y_solution = np.zeros_like(t_data) for i in range(t_data.shape[0]): x_data[i] = model.xc y_data[i] = model.yc model.step(np.pi, 0)
# ================================== # Implement kinematic model here # ================================== self.xc += v * np.cos(self.theta + self.beta) * self.sample_time self.yc += v * np.sin(self.theta + self.beta) * self.sample_time self.theta += v * np.cos(self.beta) * np.tan(self.delta) / self.L * self.sample_time self.delta += w * self.sample_time self.beta = np.arctan2(self.lr * np.tan(self.delta), self.L) pass sample_time = 0.01 time_end = 20 model = Bicycle() solution_model = BicycleSolution() # set delta directly model.delta = np.arctan(2/10) solution_model.delta = np.arctan(2/10) t_data = np.arange(0,time_end,sample_time) x_data = np.zeros_like(t_data) y_data = np.zeros_like(t_data) x_solution = np.zeros_like(t_data) y_solution = np.zeros_like(t_data) for i in range(t_data.shape[0]): x_data[i] = model.xc y_data[i] = model.yc model.step(np.pi, 0)