@@ -85,9 +85,10 @@ PyMODINIT_FUNC PyInit_fknm(void)
85
85
static PyObject * fkine_all (PyObject * self , PyObject * args )
86
86
{
87
87
Link * link ;
88
- npy_float64 * q , * base , * fk , * pfk ;
88
+ npy_float64 * q , * base , * fk , * pfk , * ret ;
89
+ npy_float64 * s_base ;
89
90
PyArrayObject * py_q , * py_base ;
90
- PyObject * links ;
91
+ PyObject * links , * iter_links ;
91
92
int m ;
92
93
93
94
if (!PyArg_ParseTuple (
@@ -100,28 +101,43 @@ static PyObject *fkine_all(PyObject *self, PyObject *args)
100
101
101
102
q = (npy_float64 * )PyArray_DATA (py_q );
102
103
base = (npy_float64 * )PyArray_DATA (py_base );
103
- PyObject * iter_links = PyObject_GetIter (links );
104
- npy_float64 * ret = (npy_float64 * )PyMem_RawCalloc (16 , sizeof (npy_float64 ));
104
+ iter_links = PyObject_GetIter (links );
105
+ ret = (npy_float64 * )PyMem_RawCalloc (16 , sizeof (npy_float64 ));
105
106
107
+ // Loop through each link in links which is m long
106
108
for (int i = 0 ; i < m ; i ++ )
107
109
{
108
110
if (!(link = (Link * )PyCapsule_GetPointer (PyIter_Next (iter_links ), "Link" )))
109
111
{
110
112
return NULL ;
111
113
}
112
114
115
+ // Calculate the current link transform
113
116
A (link , ret , q [link -> jindex ]);
117
+
118
+ // Get pointer to link._fk array
114
119
fk = (npy_float64 * )PyArray_DATA (link -> fk );
115
120
116
121
if (link -> parent )
117
122
{
123
+ // Get pointer to link.parent._fk array
118
124
pfk = (npy_float64 * )PyArray_DATA (link -> parent -> fk );
125
+
126
+ // Multiply parent._fk by link.A and store in link._fk
119
127
mult (pfk , ret , fk );
120
128
}
121
129
else
122
130
{
131
+ // Multiply base by link.A and store in link._fk
123
132
mult (base , ret , fk );
124
133
}
134
+
135
+ // Set dependant shapes
136
+ for (int i = 0 ; i < link -> n_shapes ; i ++ )
137
+ {
138
+ copy (fk , link -> shape_wT [i ]);
139
+ mult (fk , link -> shape_base [i ], link -> shape_sT [i ]);
140
+ }
125
141
}
126
142
127
143
Py_RETURN_NONE ;
@@ -188,15 +204,24 @@ static PyObject *link_init(PyObject *self, PyObject *args)
188
204
int jointtype ;
189
205
PyObject * ret , * py_parent ;
190
206
207
+ PyObject * py_shape_base , * py_shape_wT , * py_shape_sT ;
208
+ PyObject * iter_base , * iter_wT , * iter_sT ;
209
+ PyArrayObject * pys_base , * pys_wT , * pys_sT ;
210
+ npy_float64 * s_base , * s_wT , * s_sT ;
211
+
191
212
link = (Link * )PyMem_RawMalloc (sizeof (Link ));
192
213
193
- if (!PyArg_ParseTuple (args , "iiiiO !O!O " ,
214
+ if (!PyArg_ParseTuple (args , "iiiiiO !O!OOOO " ,
194
215
& link -> isjoint ,
195
216
& link -> isflip ,
196
217
& jointtype ,
197
218
& link -> jindex ,
219
+ & link -> n_shapes ,
198
220
& PyArray_Type , & link -> A ,
199
221
& PyArray_Type , & link -> fk ,
222
+ & py_shape_base ,
223
+ & py_shape_wT ,
224
+ & py_shape_sT ,
200
225
& py_parent ))
201
226
return NULL ;
202
227
@@ -209,6 +234,28 @@ static PyObject *link_init(PyObject *self, PyObject *args)
209
234
return NULL ;
210
235
}
211
236
237
+ // Set shape pointers
238
+ iter_base = PyObject_GetIter (py_shape_base );
239
+ iter_wT = PyObject_GetIter (py_shape_wT );
240
+ iter_sT = PyObject_GetIter (py_shape_sT );
241
+
242
+ link -> shape_base = (npy_float64 * )PyMem_RawCalloc (link -> n_shapes , sizeof (npy_float64 ));
243
+ link -> shape_wT = (npy_float64 * )PyMem_RawCalloc (link -> n_shapes , sizeof (npy_float64 ));
244
+ link -> shape_sT = (npy_float64 * )PyMem_RawCalloc (link -> n_shapes , sizeof (npy_float64 ));
245
+
246
+ for (int i = 0 ; i < link -> n_shapes ; i ++ )
247
+ {
248
+ if (
249
+ !(pys_base = (PyArrayObject * )PyIter_Next (iter_base )) ||
250
+ !(pys_wT = (PyArrayObject * )PyIter_Next (iter_wT )) ||
251
+ !(pys_sT = (PyArrayObject * )PyIter_Next (iter_sT )))
252
+ return NULL ;
253
+
254
+ link -> shape_base [i ] = (npy_float64 * )PyArray_DATA (pys_base );
255
+ link -> shape_wT [i ] = (npy_float64 * )PyArray_DATA (pys_wT );
256
+ link -> shape_sT [i ] = (npy_float64 * )PyArray_DATA (pys_sT );
257
+ }
258
+
212
259
link -> axis = jointtype ;
213
260
link -> parent = parent ;
214
261
@@ -245,19 +292,27 @@ static PyObject *link_update(PyObject *self, PyObject *args)
245
292
{
246
293
Link * link , * parent ;
247
294
int isjoint , isflip ;
248
- int jointtype ;
249
- int jindex ;
295
+ int jointtype , jindex , n_shapes ;
250
296
PyObject * lo , * py_parent ;
251
297
PyArrayObject * A , * fk ;
252
298
253
- if (!PyArg_ParseTuple (args , "OiiiiO!O!O" ,
299
+ PyObject * py_shape_base , * py_shape_wT , * py_shape_sT ;
300
+ PyObject * iter_base , * iter_wT , * iter_sT ;
301
+ PyArrayObject * pys_base , * pys_wT , * pys_sT ;
302
+ npy_float64 * s_base , * s_wT , * s_sT ;
303
+
304
+ if (!PyArg_ParseTuple (args , "OiiiiiO!O!OOOO" ,
254
305
& lo ,
255
306
& isjoint ,
256
307
& isflip ,
257
308
& jointtype ,
258
309
& jindex ,
310
+ & n_shapes ,
259
311
& PyArray_Type , & A ,
260
312
& PyArray_Type , & fk ,
313
+ & py_shape_base ,
314
+ & py_shape_wT ,
315
+ & py_shape_sT ,
261
316
& py_parent ))
262
317
return NULL ;
263
318
@@ -275,6 +330,33 @@ static PyObject *link_update(PyObject *self, PyObject *args)
275
330
return NULL ;
276
331
}
277
332
333
+ // Set shape pointers
334
+ iter_base = PyObject_GetIter (py_shape_base );
335
+ iter_wT = PyObject_GetIter (py_shape_wT );
336
+ iter_sT = PyObject_GetIter (py_shape_sT );
337
+
338
+ link -> shape_base = (npy_float64 * )PyMem_RawCalloc (n_shapes , sizeof (npy_float64 ));
339
+ link -> shape_wT = (npy_float64 * )PyMem_RawCalloc (n_shapes , sizeof (npy_float64 ));
340
+ link -> shape_sT = (npy_float64 * )PyMem_RawCalloc (n_shapes , sizeof (npy_float64 ));
341
+
342
+ for (int i = 0 ; i < n_shapes ; i ++ )
343
+ {
344
+ if (
345
+ !(pys_base = (PyArrayObject * )PyIter_Next (iter_base )) ||
346
+ !(pys_wT = (PyArrayObject * )PyIter_Next (iter_wT )) ||
347
+ !(pys_sT = (PyArrayObject * )PyIter_Next (iter_sT )))
348
+ return NULL ;
349
+
350
+ link -> shape_base [i ] = (npy_float64 * )PyArray_DATA (pys_base );
351
+ link -> shape_wT [i ] = (npy_float64 * )PyArray_DATA (pys_wT );
352
+ link -> shape_sT [i ] = (npy_float64 * )PyArray_DATA (pys_sT );
353
+ }
354
+
355
+ // if (n_shapes > 2)
356
+ // {
357
+ // copy(link->shape_base[0], link->shape_base[1]);
358
+ // }
359
+
278
360
if (jointtype == 0 )
279
361
{
280
362
link -> op = rx ;
@@ -307,6 +389,7 @@ static PyObject *link_update(PyObject *self, PyObject *args)
307
389
link -> jindex = jindex ;
308
390
link -> axis = jointtype ;
309
391
link -> parent = parent ;
392
+ link -> n_shapes = n_shapes ;
310
393
311
394
Py_RETURN_NONE ;
312
395
}
0 commit comments