Path: blob/master/experiments/bicycle.py
1700 views
# -*- coding: utf-8 -*-1"""2Created on Tue Apr 28 08:19:21 201534@author: Roger5"""678from math import *9import numpy as np10import matplotlib.pyplot as plt11from matplotlib.patches import Polygon1213wheelbase = 100 #inches1415vel = 20 *12 # fps to inches per sec16steering_angle = radians(1)17t = 1 # second18orientation = 0. # radians1920pos = np.array([0., 0.]2122for i in range(100):23#if abs(steering_angle) > 1.e-8:24turn_radius = tan(steering_angle)25radius = wheelbase / tan(steering_angle)2627dist = vel*t28arc_len = dist / (2*pi*radius)2930turn_angle = 2*pi * arc_len313233cx = pos[0] - radius * sin(orientation)34cy = pos[1] + radius * cos(orientation)3536orientation = (orientation + turn_angle) % (2.0 * pi)37pos[0] = cx + (sin(orientation) * radius)38pos[1] = cy - (cos(orientation) * radius)3940plt.scatter(pos[0], pos[1])4142plt.axis('equal')43444546474849