From abb0733d8d5cbb6b49e39ec7e7f35ad3ec875b4c Mon Sep 17 00:00:00 2001 From: simondlevy Date: Thu, 26 Jul 2018 02:07:43 -0400 Subject: [PATCH] Fixed slam.setmap() --- python/breezyslam/algorithms.py | 2 +- python/pybreezyslam.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/python/breezyslam/algorithms.py b/python/breezyslam/algorithms.py index bb77f22..f48288d 100644 --- a/python/breezyslam/algorithms.py +++ b/python/breezyslam/algorithms.py @@ -122,7 +122,7 @@ class CoreSLAM(object): Sets current map pixels to values in bytearray, where bytearray length is square of map size passed to CoreSLAM.__init__(). ''' - self.map.__init__(mapbytes) + self.map.set(mapbytes) def __str__(self): diff --git a/python/pybreezyslam.c b/python/pybreezyslam.c index ca66f9f..680c14a 100644 --- a/python/pybreezyslam.c +++ b/python/pybreezyslam.c @@ -537,6 +537,26 @@ Map_get(Map * self, PyObject * args, PyObject * kwds) Py_RETURN_NONE; } +static PyObject * +Map_set(Map * self, PyObject * args, PyObject * kwds) +{ + PyObject * py_mapbytes = NULL; + + if (!PyArg_ParseTuple(args, "O", &py_mapbytes)) + { + return null_on_raise_argument_exception("Map", "get"); + } + + if (bad_mapbytes(py_mapbytes, self->map.size_pixels, "get")) + { + Py_RETURN_NONE; + } + + map_set(&self->map, PyByteArray_AsString(py_mapbytes)); + + Py_RETURN_NONE; +} + static PyObject * Map_update(Map *self, PyObject *args, PyObject *kwds) { @@ -584,6 +604,9 @@ static PyMethodDef Map_methods[] = {"get", (PyCFunction)Map_get, METH_VARARGS, "Map.get(bytearray) fills byte array with map pixels, where bytearray length is square of size of map." }, + {"set", (PyCFunction)Map_set, METH_VARARGS, + "Map.set(bytearray) fills current map with pixels in bytearray, where bytearray length is square of size of map." + }, {NULL} // Sentinel };