Begin C interpolation code for distances,angles

This commit is contained in:
simondlevy
2018-07-04 14:50:51 -04:00
parent 5c3b00ec9c
commit b64defee23
2 changed files with 34 additions and 27 deletions

View File

@@ -30,9 +30,6 @@ from rplidar import RPLidar as Lidar
from pltslamshow import SlamShow from pltslamshow import SlamShow
from scipy.interpolate import interp1d
import numpy as np
if __name__ == '__main__': if __name__ == '__main__':
# Connect to Lidar unit # Connect to Lidar unit
@@ -55,34 +52,41 @@ if __name__ == '__main__':
while True: while True:
# Extrat (quality, angle, distance) triples from current scan try:
items = [item for item in next(iterator)]
# Extract distances and angles from triples # Extract (quality, angle, distance) triples from current scan
distances = [item[2] for item in items] items = [item for item in next(iterator)]
angles = [item[1] for item in items]
# Interpolate to get 360 angles from 0 through 359, and corresponding distances # Extract distances and angles from triples
f = interp1d(angles, distances, fill_value='extrapolate') distances = [item[2] for item in items]
distances = list(f(np.arange(360))) # slam.update wants a list angles = [item[1] for item in items]
# Update SLAM with current Lidar scan, using third element of (quality, angle, distance) triples print(len(distances), len(angles))
slam.update(distances)
# Get current robot position # Update SLAM with current Lidar scan and scan angles
x, y, theta = slam.getpos() slam.update(distances, scan_angles_degrees=angles)
# Get current map bytes as grayscale except KeyboardInterrupt:
slam.getmap(mapbytes)
display.displayMap(mapbytes)
display.setPose(x, y, theta)
# Break on window close
if not display.refresh():
break break
# Get current robot position
#x, y, theta = slam.getpos()
# Get current map bytes as grayscale
#slam.getmap(mapbytes)
# Display the map
#display.displayMap(mapbytes)
# Display the robot's pose in the map
#display.setPose(x, y, theta)
# Break on window close
#if not display.refresh():
# break
# Shut down the lidar connection # Shut down the lidar connection
from time import sleep
lidar.stop() lidar.stop()
lidar.disconnect() lidar.disconnect()

View File

@@ -288,21 +288,25 @@ Scan_update(Scan *self, PyObject *args, PyObject *kwds)
"lidar must be a list"); "lidar must be a list");
} }
// Scan angles provided; run bozo-filter to match against lidar-list size // Scan angles provided
if (py_scan_angles_degrees != Py_None) if (py_scan_angles_degrees != Py_None)
{ {
// Bozo filter on SCAN_ANGLES_DEGREES argument // Bozo filter #1: SCAN_ANGLES_DEGREES must be a list
if (!PyList_Check(py_scan_angles_degrees)) if (!PyList_Check(py_scan_angles_degrees))
{ {
return null_on_raise_argument_exception_with_details("Scan", "update", return null_on_raise_argument_exception_with_details("Scan", "update",
"scan angles must be a list"); "scan angles must be a list");
} }
// Bozo filter #2: must have same number of scan angles as scan distances
if (PyList_Size(py_lidar) != PyList_Size(py_scan_angles_degrees)) if (PyList_Size(py_lidar) != PyList_Size(py_scan_angles_degrees))
{ {
return null_on_raise_argument_exception_with_details("Scan", "update", return null_on_raise_argument_exception_with_details("Scan", "update",
"number of scan angles must equal number of scan distances"); "number of scan angles must equal number of scan distances");
} }
printf("Interpolate!\n");
Py_RETURN_NONE;
} }
// No scan angles provided; lidar-list size must match scan size // No scan angles provided; lidar-list size must match scan size
@@ -312,13 +316,12 @@ Scan_update(Scan *self, PyObject *args, PyObject *kwds)
"lidar size mismatch"); "lidar size mismatch");
} }
// Default to no velocities // Default to no velocities
double dxy_mm = 0; double dxy_mm = 0;
double dtheta_degrees = 0; double dtheta_degrees = 0;
// Bozo filter on velocities tuple // Bozo filter on velocities tuple
if (py_velocities) if (py_velocities != Py_None)
{ {
if (!PyTuple_Check(py_velocities)) if (!PyTuple_Check(py_velocities))
{ {