-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello.cpp
57 lines (46 loc) · 1.12 KB
/
hello.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <python2.7/Python.h>
#include "IKSolver.h"
#ifdef __CPLUSPLUS
extern "C" {
#endif
static PyObject *
call_motors(PyObject *self, PyObject *args)
{
long leg;
float sx;
float sy;
float sz;
float tx;
float ty;
float tz;
float theta1;
float theta2;
float theta3;
float theta4;
int status = PyArg_ParseTuple(
args, "lffffff", &leg, &sx, &sy, &sz, &tx, &ty, &tz);
if (!status)
return NULL;
IK_getServoValues(
leg, sx, sy, sz, tx, ty, tz, &theta1, &theta2, &theta3, &theta4
);
PyObject *ret = PyTuple_New(4);
PyTuple_SET_ITEM(ret, 0, PyFloat_FromDouble(theta1));
PyTuple_SET_ITEM(ret, 1, PyFloat_FromDouble(theta2));
PyTuple_SET_ITEM(ret, 2, PyFloat_FromDouble(theta3));
PyTuple_SET_ITEM(ret, 3, PyFloat_FromDouble(theta4));
return ret;
}
static PyMethodDef HelloMethods[] = {
{"call_motors", call_motors, METH_VARARGS,
"Run the motors."},
{NULL, NULL, 0, NULL} /* Sentinel */
};
PyMODINIT_FUNC
inithello(void)
{
(void) Py_InitModule("hello", HelloMethods);
}
#ifdef __CPLUSPLUS
} // extern "C"
#endif