@@ -89,19 +89,25 @@ extern "C"
89
89
static PyObject *IK (PyObject *self, PyObject *args)
90
90
{
91
91
ETS *ets;
92
- npy_float64 *np_Tep, *np_ret;
93
- PyObject *py_q, *py_Tep ;
94
- PyArrayObject *py_np_q , *py_np_Tep ;
95
- PyObject *py_ets ;
96
- int n ;
97
- PyObject *py_ret ;
98
- npy_intp dim[ 1 ] = { 7 } ;
92
+ npy_float64 *np_Tep, *np_ret, *np_q0 ;
93
+ PyArrayObject *py_np_Tep ;
94
+ PyObject *py_ets , *py_ret, *py_Tep, *py_q0, *py_np_q0 ;
95
+ PyObject *py_tup, *py_it, *py_search, *py_solution, *py_E ;
96
+ npy_intp dim[ 1 ] = { 1 } ;
97
+ int ilimit, slimit, q0_used = 0 , reject_jl ;
98
+ double tol, E ;
99
99
100
+ int it = 0 , search = 0 , solution = 0 ;
100
101
101
102
if (!PyArg_ParseTuple (
102
- args, " OO " ,
103
+ args, " OOOiidi " ,
103
104
&py_ets,
104
- &py_Tep))
105
+ &py_Tep,
106
+ &py_q0,
107
+ &ilimit,
108
+ &slimit,
109
+ &tol,
110
+ &reject_jl))
105
111
return NULL ;
106
112
107
113
if (!_check_array_type (py_Tep))
@@ -111,26 +117,67 @@ extern "C"
111
117
if (!(ets = (ETS *)PyCapsule_GetPointer (py_ets, " ETS" )))
112
118
return NULL ;
113
119
120
+ // Assign empty q0
121
+ MapVectorX q0 (NULL , 0 );
122
+
123
+ // Check if q0 is None
124
+ if (py_q0 != Py_None)
125
+ {
126
+ // Make sure q is number array
127
+ // Cast to numpy array
128
+ // Get data out
129
+ if (!_check_array_type (py_q0))
130
+ return NULL ;
131
+ q0_used = 1 ;
132
+ py_np_q0 = (PyObject *)PyArray_FROMANY (py_q0, NPY_DOUBLE, 1 , 2 , NPY_ARRAY_F_CONTIGUOUS);
133
+ np_q0 = (npy_float64 *)PyArray_DATA ((PyArrayObject *)py_np_q0);
134
+ // MapVectorX q0(np_q0, ets->n);
135
+ new (&q0) MapVectorX (np_q0, ets->n );
136
+ }
137
+
138
+ // std::cout << q0.size() << '\n';
139
+
140
+ // Set the dimension of the returned array to match the number of joints
141
+ dim[0 ] = ets->n ;
142
+
114
143
py_np_Tep = (PyArrayObject *)PyArray_FROMANY (py_Tep, NPY_DOUBLE, 1 , 2 , NPY_ARRAY_DEFAULT);
115
144
np_Tep = (npy_float64 *)PyArray_DATA (py_np_Tep);
116
- MapMatrix4dc Tep (np_Tep);
117
145
118
- py_ret = PyArray_EMPTY (1 , dim, NPY_DOUBLE, 0 );
119
- np_ret = (npy_float64 *)PyArray_DATA ((PyArrayObject *)py_ret);
120
- // MapMatrix4dc Tep(np_Tep);
146
+ // Tep in row major from Python
147
+ MapMatrix4dr row_Tep (np_Tep);
121
148
122
- std::cout << Tep << std::endl;
149
+ // Convert to col major here
150
+ Matrix4dc Tep = row_Tep;
123
151
152
+ py_ret = PyArray_EMPTY (1 , dim, NPY_DOUBLE, 0 );
153
+ np_ret = (npy_float64 *)PyArray_DATA ((PyArrayObject *)py_ret);
154
+ MapVectorX ret (np_ret, ets->n );
124
155
156
+ // std::cout << Tep << std::endl;
157
+ // std::cout << ret << std::endl;
125
158
126
- // _ETS_IK (ets, n, q, Tep, ret);
159
+ _IK_LM_Chan (ets, Tep, q0, ilimit, slimit, tol, reject_jl, ret, &it, &search, &solution, &E );
127
160
128
161
// _angle_axis(Te, Tep, ret);
129
162
130
163
// Free the memory
131
164
Py_DECREF (py_np_Tep);
132
165
133
- return py_ret;
166
+ if (q0_used)
167
+ {
168
+ Py_DECREF (py_np_q0);
169
+ }
170
+
171
+ // Build the return tuple
172
+
173
+ py_it = Py_BuildValue (" i" , it);
174
+ py_search = Py_BuildValue (" i" , search);
175
+ py_solution = Py_BuildValue (" i" , solution);
176
+ py_E = Py_BuildValue (" d" , E);
177
+
178
+ py_tup = PyTuple_Pack (5 , py_ret, py_solution, py_it, py_search, py_E);
179
+
180
+ return py_tup;
134
181
}
135
182
136
183
static PyObject *Robot_link_T (PyObject *self, PyObject *args)
@@ -658,8 +705,10 @@ extern "C"
658
705
659
706
static PyObject *ETS_init (PyObject *self, PyObject *args)
660
707
{
708
+ ET *et;
661
709
ETS *ets;
662
710
PyObject *etsl, *ret;
711
+ int j = 0 ;
663
712
664
713
ets = (ETS *)PyMem_RawMalloc (sizeof (ETS));
665
714
@@ -679,6 +728,25 @@ extern "C"
679
728
return NULL ;
680
729
}
681
730
731
+ ets->qlim_l = (double *)PyMem_RawMalloc (ets->n * sizeof (double ));
732
+ ets->qlim_h = (double *)PyMem_RawMalloc (ets->n * sizeof (double ));
733
+ ets->q_range2 = (double *)PyMem_RawMalloc (ets->n * sizeof (double ));
734
+
735
+ // Cache joint limits
736
+ for (int i = 0 ; i < ets->m ; i++)
737
+ {
738
+ et = ets->ets [i];
739
+
740
+ if (et->isjoint )
741
+ {
742
+ ets->qlim_l [j] = et->qlim [0 ];
743
+ ets->qlim_h [j] = et->qlim [1 ];
744
+ ets->q_range2 [j] = (et->qlim [1 ] - et->qlim [0 ]) / 2.0 ;
745
+
746
+ j += 1 ;
747
+ }
748
+ }
749
+
682
750
Py_DECREF (iter_et);
683
751
684
752
ret = PyCapsule_New (ets, " ETS" , NULL );
@@ -691,6 +759,7 @@ extern "C"
691
759
int jointtype;
692
760
PyObject *ret, *py_et;
693
761
PyArrayObject *py_T, *py_qlim;
762
+ npy_float64 *np_qlim;
694
763
int isjoint, isflip, jindex;
695
764
696
765
et = (ET *)PyMem_RawMalloc (sizeof (ET));
@@ -708,9 +777,12 @@ extern "C"
708
777
if (!(et = (ET *)PyCapsule_GetPointer (py_et, " ET" )))
709
778
return NULL ;
710
779
780
+ np_qlim = (npy_float64 *)PyArray_DATA (py_qlim);
781
+ et->qlim [0 ] = np_qlim[0 ];
782
+ et->qlim [1 ] = np_qlim[1 ];
783
+
711
784
et->T = (npy_float64 *)PyArray_DATA (py_T);
712
785
new (&et->Tm ) MapMatrix4dc (et->T );
713
- et->qlim = (npy_float64 *)PyArray_DATA (py_qlim);
714
786
et->axis = jointtype;
715
787
716
788
et->isjoint = isjoint;
@@ -752,6 +824,7 @@ extern "C"
752
824
int jointtype;
753
825
PyObject *ret;
754
826
PyArrayObject *py_T, *py_qlim;
827
+ npy_float64 *np_qlim;
755
828
756
829
et = (ET *)PyMem_RawMalloc (sizeof (ET));
757
830
@@ -764,9 +837,13 @@ extern "C"
764
837
&PyArray_Type, &py_qlim))
765
838
return NULL ;
766
839
840
+ np_qlim = (npy_float64 *)PyArray_DATA (py_qlim);
841
+ et->qlim = (double *)PyMem_RawMalloc (2 * sizeof (double ));
842
+ et->qlim [0 ] = np_qlim[0 ];
843
+ et->qlim [1 ] = np_qlim[1 ];
844
+
767
845
et->T = (npy_float64 *)PyArray_DATA (py_T);
768
846
new (&et->Tm ) MapMatrix4dc (et->T );
769
- et->qlim = (npy_float64 *)PyArray_DATA (py_qlim);
770
847
771
848
et->axis = jointtype;
772
849
0 commit comments