improve rrt car code

This commit is contained in:
Atsushi Sakai
2018-01-11 12:49:09 -08:00
parent 8d720a1b05
commit 54659b809d
5 changed files with 7 additions and 82 deletions

View File

@@ -1,12 +1,8 @@
#! /usr/bin/python
# -*- coding: utf-8 -*-
"""
Dubins path planner sample code
author Atsushi Sakai(@Atsushi_twi)
License MIT
author Atsushi Sakai (@Atsushi_twi)
"""
import math

Binary file not shown.

Before

Width:  |  Height:  |  Size: 245 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 389 KiB

View File

@@ -1,59 +0,0 @@
"""
A simple Python module for recording matplotlib animation
This tool use convert command of ImageMagick
author: Atsushi Sakai
"""
import matplotlib.pyplot as plt
import subprocess
iframe = 0
donothing = False
def save_frame():
"""
Save a frame for movie
"""
if not donothing:
global iframe
plt.savefig("recoder" + '{0:04d}'.format(iframe) + '.png')
iframe += 1
def save_movie(fname, d_pause):
"""
Save movie as gif
"""
if not donothing:
cmd = "convert -delay " + str(int(d_pause * 100)) + \
" recoder*.png " + fname
subprocess.call(cmd, shell=True)
cmd = "rm recoder*.png"
subprocess.call(cmd, shell=True)
if __name__ == '__main__':
print("A sample recording start")
import math
time = range(50)
x1 = [math.cos(t / 10.0) for t in time]
y1 = [math.sin(t / 10.0) for t in time]
x2 = [math.cos(t / 10.0) + 2 for t in time]
y2 = [math.sin(t / 10.0) + 2 for t in time]
for ix1, iy1, ix2, iy2 in zip(x1, y1, x2, y2):
plt.plot(ix1, iy1, "xr")
plt.plot(ix2, iy2, "xb")
plt.axis("equal")
plt.pause(0.1)
save_frame() # save each frame
save_movie("animation.gif", 0.1)
# save_movie("animation.mp4", 0.1)

View File

@@ -1,11 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
@brief: Path Planning Sample Code with RRT for car like robot.
Path Planning Sample Code with RRT and Dubins path
@author: AtsushiSakai(@Atsushi_twi)
@license: MIT
author: AtsushiSakai(@Atsushi_twi)
"""
@@ -17,13 +13,13 @@ import dubins_path_planning
class RRT():
u"""
"""
Class for RRT Planning
"""
def __init__(self, start, goal, obstacleList, randArea,
goalSampleRate=10, maxIter=1000):
u"""
"""
Setting Parameter
start:Start Position [x,y]
@@ -40,7 +36,7 @@ class RRT():
self.maxIter = maxIter
def Planning(self, animation=True):
u"""
"""
Pathplanning
animation: flag for animation on or off
@@ -62,7 +58,6 @@ class RRT():
if animation and i % 5 == 0:
self.DrawGraph(rnd=rnd)
matplotrecorder.save_frame() # save each frame
# generate coruse
lastIndex = self.get_best_last_index()
@@ -253,7 +248,7 @@ class RRT():
class Node():
u"""
"""
RRT Node
"""
@@ -271,8 +266,6 @@ class Node():
if __name__ == '__main__':
print("Start rrt start planning")
import matplotlib.pyplot as plt
import matplotrecorder
matplotrecorder.donothing = True
# ====Search Path with RRT====
obstacleList = [
@@ -297,9 +290,4 @@ if __name__ == '__main__':
plt.grid(True)
plt.pause(0.001)
for i in range(10):
matplotrecorder.save_frame() # save each frame
plt.show()
matplotrecorder.save_movie("animation.gif", 0.1)