The goal of the assignment is to extract features (line segments) from laser scans.
Note – the algorithms of feature extraction will be used in the next
assignment on feature based localization.
Note: To simplify the task, you can limit the range of scanned data from the scanner by narrowing the observed angle and limiting the maximum distance.
array {
object {
array { float(3) } pose # [x,y,theta in degrees]
float time
array { float(512)} scan # distances in meters in [-pi/2,pi/2]
} # a single measurement
}
import json
##reading data from the file
json_data = open('line_detection_1.json')
data = json.load(json_data)
### plot in polar system
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(0,512)
theta = (np.pi/512 )*(x-256) # angle in radians
# Reading first dataset (index 0)
scan_data=data[0]["scan"]
fig1 = plt.figure()
ax1 = fig1.add_axes([0.1,0.1,0.8,0.8],polar=True) # TODO: modify the code to use Cartesian coordinates
line, = ax1.plot(theta,scan_data,lw=2.5)
ax1.set_ylim(0,2) # plot range
plt.show()
import numpy as np
import pylab as pl
from matplotlib import collections as mc
lines = [[(0, 1), (1, 1)], [(2, 3), (3, 3)], [(1, 2), (1, 3)]]
c = np.array([(1, 0, 0, 1), (0, 1, 0, 1), (0, 0, 1, 1)])
lc = mc.LineCollection(lines, colors=c, linewidths=2)
lines2 = [[(0.1, 1.1), (1.1, 1.1)], [(2.1, 3.1), (3.1, 3.1)], [(1.1, 2.1), (1.1, 3.1)]]
lc2 = mc.LineCollection(lines2, colors=[0,0,0],linewidths=1)
fig, ax = pl.subplots()
ax.add_collection(lc)
ax.add_collection(lc2)
ax.autoscale()
ax.margins(0.1)
pl.show()