39 #include <boost/numpy.hpp> 40 #include <boost/scoped_array.hpp> 44 namespace p = boost::python;
45 namespace np = boost::numpy;
48 if(q_arr.get_dtype() != np::dtype::get_builtin<double>()) {
49 PyErr_SetString(PyExc_TypeError,
"Incorrect array data type");
50 p::throw_error_already_set();
52 if(q_arr.get_nd() != 1) {
53 PyErr_SetString(PyExc_TypeError,
"Incorrect number of dimensions");
54 p::throw_error_already_set();
56 if(q_arr.shape(0) != 6) {
57 PyErr_SetString(PyExc_TypeError,
"Incorrect shape (should be 6)");
58 p::throw_error_already_set();
60 Py_intptr_t shape[2] = { 4, 4 };
61 np::ndarray result = np::zeros(2,shape,np::dtype::get_builtin<double>());
63 reinterpret_cast<double*>(result.get_data()));
68 if(array.get_dtype() != np::dtype::get_builtin<double>()) {
69 PyErr_SetString(PyExc_TypeError,
"Incorrect array data type");
70 p::throw_error_already_set();
72 if(array.get_nd() != 2) {
73 PyErr_SetString(PyExc_TypeError,
"Incorrect number of dimensions");
74 p::throw_error_already_set();
76 if(array.shape(0) != 4 || array.shape(1) != 4) {
77 PyErr_SetString(PyExc_TypeError,
"Incorrect shape (should be 4x4)");
78 p::throw_error_already_set();
80 double* T =
reinterpret_cast<double*
>(array.get_data());
81 double* q_sols = (
double*) malloc(8*6*
sizeof(
double));
82 double q6_des = PyFloat_AsDouble(q6_des_py);
84 q_sols = (
double*) realloc(q_sols, num_sols*6*
sizeof(
double));
85 return np::from_data(q_sols, np::dtype::get_builtin<double>() , p::make_tuple(num_sols, 6), p::make_tuple(6*
sizeof(
double),
sizeof(
double)), p::object());
np::ndarray forward_wrapper(np::ndarray const &q_arr)
np::ndarray inverse_wrapper(np::ndarray const &array, PyObject *q6_des_py)
int inverse(const double *T, double *q_sols, double q6_des=0.0)
BOOST_PYTHON_MODULE(ur_kin_py)
void forward(const double *q, double *T)