第三課:多峰润绵,連續(xù),粒子濾波

三種濾波的比較

粒子濾波的關(guān)鍵函數(shù)

這部分主要敘述士嚎,如何初始化粒子群悔叽,然后對粒子群做measurement爵嗅,并與權(quán)重對應(yīng),最后通過巧妙設(shè)計睹晒,實現(xiàn)按照權(quán)重占比,實現(xiàn)重組(重新生成)粒子群

def get_position(p):
    x = 0.0
    y = 0.0
    orientation = 0.0
    for i in range(len(p)):
        x += p[i].x
        y += p[i].y
        # orientation is tricky because it is cyclic. By normalizing
        # around the first particle we are somewhat more robust to
        # the 0=2pi problem [-pi,pi]
        orientation += (((p[i].orientation - p[0].orientation + pi) % (2.0 * pi))
                        + p[0].orientation - pi)
    return [x / len(p), y / len(p), orientation / len(p)]


def particle_filter(motions, measurements, N=500):  # I know it's tempting, but don't change N!
    # --------
    #
    # Make particles
    #

    p = []
    for i in range(N):
        r = robot()
        r.set_noise(bearing_noise, steering_noise, distance_noise)
        p.append(r)

    # --------
    #
    # Update particles
    #

    for t in range(len(motions)):

        # motion update (prediction)
        p2 = []
        for i in range(N):
            p2.append(p[i].move(motions[t]))
        p = p2

        # measurement update
        w = []
        for i in range(N):
            w.append(p[i].measurement_prob(measurements[t]))

        # resampling
        p3 = []
        index = int(random.random() * N)
        beta = 0.0
        mw = max(w)
        for i in range(N):
            beta += random.random() * 2.0 * mw
            while beta > w[index]:
                beta -= w[index]
                index = (index + 1) % N
            p3.append(p[index])
        p = p3

    return get_position(p)

自行車模型

在這講中,引入自行車模型的概念锉试,這篇博客講的很細(xì)致
https://blog.csdn.net/adamshan/article/details/78696874

自行車模型:一圖勝千言

課件中的表示方法與上圖一致呆盖,其對應(yīng)公式如下如所示:
運動學(xué)模型對應(yīng)公式

注意:上圖中描述的公式,其中綠色部分的beta应又,我認(rèn)為是tan(beta),不過tan在該范圍內(nèi)是單調(diào)遞增的尤筐,所以關(guān)系不大洞就,不是很影響。
而且在最后藍(lán)色的x`的推導(dǎo)部分旬蟋,分別對兩種情況做了描述:

  1. 當(dāng)|beta| < 0.001時, 認(rèn)為tanx = sinx = x, 是近似相同,在物理上認(rèn)為沒有小車基本沒有偏轉(zhuǎn)
  2. 當(dāng)|beta| >= 0.001時稠腊, 用上面的那一排公式求取鸣哀,用到了cx和cy

基于自行車模型的粒子濾波

這部分主要兩塊:

  1. 面向自行車模型的move函數(shù)
    def move(self, motion):  # Do not change the name of this function
        alfa = motion[0]
        d = motion[1]
        if alfa > max_steering_angle:
            raise ValueError('the steer angle is too much')
        if d < 0:
            raise ValueError('the distance is less than zero')

        result = robot()
        result.distance_noise = self.distance_noise
        result.steering_noise = self.steering_noise
        result.bearing_noise = self.bearing_noise
        result.length = self.length

        steer = random.gauss(alfa, steering_noise)
        distance = random.gauss(d, distance_noise)

        beta = d / self.length * tan(steer)
        R = distance / beta
        result.orientation = (self.orientation + beta) % (2 * pi)

        if abs(beta) < 0.001:
            result.x = self.x + distance * cos(self.orientation)
            result.y = self.y + distance * sin(self.orientation)
        else:
            cx = result.x - sin(self.orientation) * R
            cy = result.y + cos(self.orientation) * R
            result.x = cx + sin(beta+self.orientation) * R
            result.y = cy - cos(beta+self.orientation) * R

        return result
  1. 新的感知sense函數(shù)
    與四個landmark求對應(yīng)的方向夾角bearings
    def sense(self,flag):  # do not change the name of this function
        Z = []
        # ENTER CODE HERE
        # HINT: You will probably need to use the function atan2()
        for i in range(len(landmarks)):
            if flag:
                Z.append(((atan2((landmarks[i][0] - self.y), (landmarks[i][1] - self.x)) - self.orientation) % (2 * pi)) + random.gauss(0,self.bearing_noise))
            else:
                Z.append(((atan2((landmarks[i][0] - self.y), (landmarks[i][1] - self.x)) - self.orientation) % (2 * pi)))
        return Z  # Leave this line here. Return vector Z of 4 bearings.
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末我衬,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子井仰,更是在濱河造成了極大的恐慌破加,老刑警劉巖,帶你破解...
    沈念sama閱讀 219,427評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件范舀,死亡現(xiàn)場離奇詭異,居然都是意外死亡聪全,警方通過查閱死者的電腦和手機(jī)辅辩,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,551評論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來玫锋,“玉大人,你說我怎么就攤上這事臀稚∪担” “怎么了?”我有些...
    開封第一講書人閱讀 165,747評論 0 356
  • 文/不壞的土叔 我叫張陵散劫,是天一觀的道長。 經(jīng)常有香客問我赖条,道長,這世上最難降的妖魔是什么纬乍? 我笑而不...
    開封第一講書人閱讀 58,939評論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮纽竣,結(jié)果婚禮上茧泪,老公的妹妹穿的比我還像新娘。我一直安慰自己队伟,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,955評論 6 392
  • 文/花漫 我一把揭開白布港令。 她就那樣靜靜地躺著棘钞,像睡著了一般。 火紅的嫁衣襯著肌膚如雪宜猜。 梳的紋絲不亂的頭發(fā)上硝逢,一...
    開封第一講書人閱讀 51,737評論 1 305
  • 那天,我揣著相機(jī)與錄音叫乌,去河邊找鬼。 笑死憨奸,一個胖子當(dāng)著我的面吹牛凿试,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播那婉,決...
    沈念sama閱讀 40,448評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼盐类!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起在跳,我...
    開封第一講書人閱讀 39,352評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎呻引,沒想到半個月后吐咳,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,834評論 1 317
  • 正文 獨居荒郊野嶺守林人離奇死亡韭脊,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,992評論 3 338
  • 正文 我和宋清朗相戀三年沪羔,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片蔫饰。...
    茶點故事閱讀 40,133評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖茫因,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情冻押,我是刑警寧澤盛嘿,帶...
    沈念sama閱讀 35,815評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站次兆,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏狈邑。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,477評論 3 331
  • 文/蒙蒙 一米苹、第九天 我趴在偏房一處隱蔽的房頂上張望砰琢。 院中可真熱鬧良瞧,春花似錦训唱、人聲如沸褥蚯。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,022評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽歧强。三九已至为肮,卻和暖如春摊册,著一層夾襖步出監(jiān)牢的瞬間颊艳,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,147評論 1 272
  • 我被黑心中介騙來泰國打工白修, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留重斑,地道東北人兵睛。 一個月前我還...
    沈念sama閱讀 48,398評論 3 373
  • 正文 我出身青樓卤恳,卻偏偏與公主長得像累盗,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子符相,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,077評論 2 355

推薦閱讀更多精彩內(nèi)容