PyBody.cpp
Go to the documentation of this file.
1 #include <boost/python.hpp>
2 #include <boost/foreach.hpp>
3 #include <boost/range/value_type.hpp>
4 #include <hrpModel/Link.h>
5 #include "PySimulator.h"
6 #include "PyLink.h"
7 #include "PyBody.h"
8 
9 const char* PyBody::pybody_spec[] =
10 {
11  "implementation_id", "PyBody",
12  "type_name", "PyBody",
13  "description", "PyBody component",
14  "version", "0.1",
15  "vendor", "AIST",
16  "category", "Generic",
17  "activity_type", "DataFlowComponent",
18  "max_instance", "10",
19  "language", "C++",
20  "lang_type", "compile",
21  // Configuration variables
22 
23  ""
24 };
25 
26 PyBody::PyBody(RTC::Manager* manager) : BodyRTC(manager), simulator(NULL)
27 {
28 }
29 
31 {
32  //std::cout << "~PyBody()" << std::endl;
33 }
34 
35 void PyBody::setPosition(PyObject *v)
36 {
37  rootLink()->setPosition(v);
38 }
39 
40 void PyBody::setRotation(PyObject *v)
41 {
42  rootLink()->setRotation(v);
43 }
44 
45 void PyBody::setPosture(PyObject *v)
46 {
47  if (PySequence_Size(v) != numJoints()) return;
48  for (unsigned int i=0; i<numJoints(); i++) {
49  hrp::Link *j = joint(i);
50  if (j) j->q = boost::python::extract<double>(PySequence_GetItem(v, i));
51  }
53 }
54 
56 {
57  return rootLink()->getPosition();
58 }
59 
61 {
62  return rootLink()->getRotation();
63 }
64 
65 PyObject *PyBody::getPosture()
66 {
67  boost::python::list retval;
68  for (unsigned int i=0; i<numJoints(); i++){
69  hrp::Link *j = joint(i);
70  double q = j ? j->q : 0;
71  retval.append(boost::python::object(q));
72  }
73  return boost::python::incref(retval.ptr());
74 }
75 
77 {
78  Body::calcForwardKinematics();
79 }
80 
82 {
83  return (PyLink *)Body::rootLink();
84 }
85 
86 PyLink *PyBody::link(std::string name)
87 {
88  return (PyLink *)Body::link(name);
89 }
90 
91 PyObject *PyBody::links()
92 {
93  boost::python::list retval;
94  for (unsigned int i=0; i<numLinks(); i++){
95  PyLink *l = (PyLink *)Body::link(i);
96  retval.append(boost::python::ptr(l));
97  }
98  return boost::python::incref(retval.ptr());
99 }
100 
102 {
103  return (PyLink *)Body::joint(i);
104 }
105 PyObject *PyBody::joints()
106 {
107  boost::python::list retval;
108  for (unsigned int i=0; i<numJoints(); i++){
109  PyLink *l = (PyLink *)Body::joint(i);
110  retval.append(boost::python::ptr(l));
111  }
112  return boost::python::incref(retval.ptr());
113 }
114 
115 std::string PyBody::getName()
116 {
117  return Body::name();
118 }
119 
120 PyObject *PyBody::calcCM()
121 {
122  hrp::Vector3 cm = Body::calcCM();
123  boost::python::list retval;
124  for (int i=0; i<3; i++){
125  retval.append(boost::python::object(cm[i]));
126  }
127  return boost::python::incref(retval.ptr());
128 }
129 
130 void PyBody::notifyChanged(int change)
131 {
132  switch(change){
133  case STRUCTURE:
134  updateLinkTree();
135  break;
136  case KINEMATICS:
139  break;
140  }
141 }
142 
144 {
145  simulator = i_sim;
146 }
147 
148 template <class _Delete>
150 {
151 }
152 
154 {
156  manager->registerFactory(profile,
157  RTC::Create<PyBody>,
158  DummyDelete<PyBody>
159  //RTC::Delete<PyBody>
160  );
161 }
png_infop png_charpp int png_charpp profile
PyBody(RTC::Manager *manager=&RTC::Manager::instance())
Definition: PyBody.cpp:26
PySimulator * simulator
Definition: PyBody.h:35
static const char * pybody_spec[]
Definition: PyBody.h:34
void setListener(PySimulator *i_sim)
Definition: PyBody.cpp:143
PyLink * rootLink()
Definition: PyBody.cpp:81
void DummyDelete(RTC::RTObject_impl *rtc)
Definition: PyBody.cpp:149
PyObject * joints()
Definition: PyBody.cpp:105
PyLink * joint(int i)
Definition: PyBody.cpp:101
png_uint_32 i
void notifyChanged()
std::string getName()
Definition: PyBody.cpp:115
Eigen::Vector3d Vector3
void updateLinkTree()
PyObject * getPosition()
Definition: PyBody.cpp:55
PyObject * calcCM()
Definition: PyBody.cpp:120
PyObject * links()
Definition: PyBody.cpp:91
def j(str, encoding="cp932")
const std::string & name()
virtual ~PyBody()
Definition: PyBody.cpp:30
void setPosture(PyObject *v)
Definition: PyBody.cpp:45
void setRotation(PyObject *v)
Definition: PyBody.cpp:40
unsigned int numJoints() const
PyLink * link(std::string name)
Definition: PyBody.cpp:86
void setPosition(PyObject *v)
Definition: PyBody.cpp:35
void calcForwardKinematics()
Definition: PyBody.cpp:76
unsigned int numLinks() const
void notifyChanged(int change)
Definition: PyBody.cpp:130
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
static void moduleInit(RTC::Manager *)
Definition: PyBody.cpp:153
PyObject * getRotation()
Definition: PyBody.cpp:60
PyObject * getPosture()
Definition: PyBody.cpp:65


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Thu May 6 2021 02:41:50