無人車系統(六):軌跡跟蹤Stanley方法

前面介紹的Pure Pursuit方法利用無人車的橫向跟蹤誤差來設計控制器。在無人車軌跡跟蹤任務中,除了橫向跟蹤誤差外,是否還有其他信息有助於提高控制器的穩定性與有效性。本篇介紹的Stanely方法就結合橫向跟蹤誤差eye_y與航向角偏差eθe_{\theta}來設計控制器。值得注意的是,Stanley計算橫向跟蹤誤差與pure pursuit方法是有區別的,Pure pursuit是以後軸中心爲基準點計算幾何學公式,而Stanley是基於前軸中心爲基準點計算幾何學公式的。

Stanley 方法分析與控制器設計

參照無人駕駛算法——使用Stanley method實現無人車軌跡追蹤

在這裏插入圖片描述

Stanley 控制器設計如下:

δ(k)=θe(k)+arctanλe(k)v(k) \delta(k)=\theta_{e}(k)+\arctan \frac{\lambda e(k)}{v(k)}

其中,θe(k)\theta_e(k)kk時刻的航向角偏差,e(k)e(k)爲根據上圖幾何學計算的橫向跟蹤誤差,λ\lambda爲需要調節的參數,vv爲無人車當前速度。

2. python示例

參數λ=2.0\lambda=2.0,速度爲常值v=2.0v=2.0

"""
Stanley method
"""

import numpy as np
import math
import copy
import matplotlib
import matplotlib.pyplot as plt
%matplotlib inline

# set up matplotlib
is_ipython = 'inline' in matplotlib.get_backend()
if is_ipython:
    from IPython import display

plt.ion()
plt.figure(figsize=(18, 3))

class UGV_model:
    def __init__(self, x0, y0, theta0, L, v0, T): # L:wheel base
        self.x = x0 # X
        self.y = y0 # Y
        self.theta = theta0 # headding
        self.l = L  # wheel base
        self.v = v0  # speed
        self.dt = T  # decision time periodic
    def update(self, vt, deltat):  # update ugv's state
        dx = self.v*np.cos(self.theta)
        dy = self.v*np.sin(self.theta)
        dtheta = self.v*np.tan(deltat)/self.l
        self.x += dx*self.dt
        self.y += dy*self.dt
        self.theta += dtheta*self.dt
        
    def plot_duration(self):
        plt.scatter(self.x, self.y, color='r')   
        plt.axis([self.x-9, self.x+9, -3, 3])
#         plt.axis([self.x-9, self.x+9, -10, 10])
        if is_ipython:
            display.clear_output(wait=True)
            display.display(plt.gcf())  
            
            
            
from scipy.spatial import KDTree



# set reference trajectory
refer_path = np.zeros((1000, 2))
refer_path[:,0] = np.linspace(0, 1000, 1000)
refer_head = np.zeros(1000)
# refer_path[:,1] = 5*np.sin(refer_path[:,0]/5.0)

refer_tree = KDTree(refer_path)

plt.plot(refer_path[:,0], refer_path[:,1], '-.b', linewidth=5.0)
ugv = UGV_model(0, 1.0, 0, 2.0, 2.0, 0.1)
k = 2.0
pind = 0
ind = 0 
for i in range(1000):
    robot_state = np.zeros(2)
    robot_state[0] = ugv.x
    robot_state[1] = ugv.y
    _, ind = refer_tree.query(robot_state)
    if ind < pind:
        ind = pind
    else:
        pind = ind
        
    dist = np.linalg.norm(robot_state-refer_path[ind])
    dx, dy = refer_path[ind] - robot_state
    alpha = math.atan2(dy, dx)
    e = np.sign(np.sin(alpha-ugv.theta))*dist
    dtheta = refer_head[ind]-ugv.theta
    delta = dtheta+math.atan2(k*e/ugv.v, 1.0)
    ugv.update(2.0, delta)
    ugv.plot_duration()

在這裏插入圖片描述


以上

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章