Skip to content

Commit 832d35a

Browse files
committed
Merge branch 'future' of https://github.com/petercorke/robotics-toolbox-python into future
2 parents 65aeda1 + 189186c commit 832d35a

File tree

3 files changed

+50
-18
lines changed

3 files changed

+50
-18
lines changed

roboticstoolbox/core/fknm.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1114,8 +1114,10 @@ int _inv(npy_float64 *m, npy_float64 *invOut)
11141114

11151115
det = m[0] * inv[0] + m[1] * inv[4] + m[2] * inv[8] + m[3] * inv[12];
11161116

1117-
if (det == 0)
1117+
if (det == 0) {
1118+
free(inv);
11181119
return 0;
1120+
}
11191121

11201122
det = 1.0 / det;
11211123

roboticstoolbox/core/frne.c

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ static PyObject *delete(PyObject *self, PyObject *args) {
106106
static PyObject *frne(PyObject *self, PyObject *args) {
107107

108108
Robot *robot;
109-
PyObject *rO, *qO, *qdO, *qddO, *gravO, *fextO;
109+
PyObject *rO, *qO, *qdO, *qddO, *gravO, *fextO, *temp;
110+
// PyObject *python_float;
110111
double *q, *qd, *qdd, *fext;
111112
// Vect *grav;
112113
int nq = 1; //, nqd = njoints, nqdd = njoints;
@@ -127,7 +128,6 @@ static PyObject *frne(PyObject *self, PyObject *args) {
127128
qd = (double *)PyMem_RawCalloc(njoints, sizeof(double));
128129
qdd = (double *)PyMem_RawCalloc(njoints, sizeof(double));
129130
fext = (double *)PyMem_RawCalloc(6, sizeof(double));
130-
// grav = (Vect *)PyMem_RawMalloc(sizeof(Vect));
131131

132132
// Create iterators for arrays
133133
PyObject *iq = PyObject_GetIter(qO);
@@ -137,27 +137,45 @@ static PyObject *frne(PyObject *self, PyObject *args) {
137137
PyObject *ifext = PyObject_GetIter(fextO);
138138

139139
// Create the gravity vector
140-
robot->gravity->x = PyFloat_AsDouble(PyIter_Next(igrav));
141-
robot->gravity->y = PyFloat_AsDouble(PyIter_Next(igrav));
142-
robot->gravity->z = PyFloat_AsDouble(PyIter_Next(igrav));
140+
temp = PyIter_Next(igrav);
141+
robot->gravity->x = PyFloat_AsDouble(temp);
142+
Py_DECREF(temp);
143+
144+
temp = PyIter_Next(igrav);
145+
robot->gravity->y = PyFloat_AsDouble(temp);
146+
Py_DECREF(temp);
147+
148+
temp = PyIter_Next(igrav);
149+
robot->gravity->z = PyFloat_AsDouble(temp);
150+
Py_DECREF(temp);
151+
143152

144153
// Create the joint arrays
145154
for (int i = 0; i < njoints; i++) {
146-
q[i] = PyFloat_AsDouble(PyIter_Next(iq));
147-
qd[i] = PyFloat_AsDouble(PyIter_Next(iqd));
148-
qdd[i] = PyFloat_AsDouble(PyIter_Next(iqdd));
155+
temp = PyIter_Next(iq);
156+
q[i] = PyFloat_AsDouble(temp);
157+
Py_DECREF(temp);
158+
159+
temp = PyIter_Next(iqd);
160+
qd[i] = PyFloat_AsDouble(temp);
161+
Py_DECREF(temp);
162+
163+
temp = PyIter_Next(iqdd);
164+
qdd[i] = PyFloat_AsDouble(temp);
165+
Py_DECREF(temp);
149166
}
150167

151168
// Create the fext array
152169
for (int i = 0; i < 6; i++) {
153-
fext[i] = PyFloat_AsDouble(PyIter_Next(ifext));
170+
temp = PyIter_Next(ifext);
171+
fext[i] = PyFloat_AsDouble(temp);
172+
Py_DECREF(temp);
154173
}
155174

156175
// Create a matrix for the return argument */
157176
double *tau;
158177
tau = (double *)PyMem_RawCalloc(njoints, sizeof(double));
159178

160-
161179
#define MEL(x,R,C) (x[(R)+(C)*nq])
162180

163181
// // For each point in the input trajectory
@@ -185,14 +203,19 @@ static PyObject *frne(PyObject *self, PyObject *args) {
185203
PyMem_RawFree(q);
186204
PyMem_RawFree(qd);
187205
PyMem_RawFree(qdd);
188-
// PyMem_RawFree(grav);
189206
PyMem_RawFree(fext);
190207

208+
Py_DECREF(iq);
209+
Py_DECREF(iqd);
210+
Py_DECREF(iqdd);
211+
Py_DECREF(igrav);
212+
Py_DECREF(ifext);
213+
191214
PyObject* ret = PyList_New(njoints);
192215
for (int i = 0; i < njoints; ++i) {
193-
PyObject* python_float = Py_BuildValue("d", tau[i]);
194-
PyList_SetItem(ret, i, python_float);
216+
PyList_SetItem(ret, i, Py_BuildValue("d", tau[i]));
195217
}
218+
196219
PyMem_RawFree(tau);
197220

198221
return ret;

roboticstoolbox/robot/ERobot.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,9 @@ def fkine(
12751275
Sequence, J. Haviland and P. Corke
12761276
"""
12771277

1278+
if start is not None:
1279+
include_base = False
1280+
12781281
# Use c extension to calculate fkine
12791282
if fast:
12801283
path, _, etool = self.get_path(end, start, _fknm=True)
@@ -1286,10 +1289,10 @@ def fkine(
12861289
T = np.empty((4, 4))
12871290
fknm.fkine(m, path, q, etool, tool, T)
12881291

1289-
if not include_base:
1290-
return T
1291-
else:
1292+
if self._base is not None and start is None and include_base == True:
12921293
return self.base.A @ T
1294+
else:
1295+
return T
12931296

12941297
# Otherwise use Python method
12951298
# we work with NumPy arrays not SE2/3 classes for speed
@@ -1340,7 +1343,11 @@ def fkine(
13401343
break
13411344

13421345
# add base transform if it is set
1343-
if self._base is not None and start == self.base_link:
1346+
if (
1347+
self._base is not None
1348+
and start == self.base_link
1349+
and include_base == True
1350+
):
13441351
Tk = self.base.A @ Tk
13451352

13461353
# cast to pose class and append

0 commit comments

Comments
 (0)