JointPathExC.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
10 #include <rtm/Manager.h>
11 #include <rtm/CorbaNaming.h>
12 #include <hrpModel/Body.h>
13 #include <hrpModel/Link.h>
14 #include <hrpModel/Sensor.h>
15 #include <hrpModel/ModelLoaderUtil.h>
16 #include "JointPathEx.h"
17 
18 
19 extern "C" {
22  static std::string print_prefix("[jpe]");
23 
24  int initializeOpenHRPModel (char* _filename)
25  {
26  int rtmargc=0;
27  char** argv=NULL;
28  //std::vector<char *> rtmargv;
29  //rtmargv.push_back(argv[0]);
30  rtmargc++;
31 
33  //manager = RTC::Manager::init(rtmargc, rtmargv.data());
34  manager = RTC::Manager::init(rtmargc, argv);
35 
36  std::string nameServer = manager->getConfig()["corba.nameservers"];
37  int comPos = nameServer.find(",");
38  if (comPos < 0){
39  comPos = nameServer.length();
40  }
41  nameServer = nameServer.substr(0, comPos);
42  RTC::CorbaNaming naming(manager->getORB(), nameServer.c_str());
43  std::string filename(_filename);
44  if (!loadBodyFromModelLoader(m_robot, filename.c_str(),
45  CosNaming::NamingContext::_duplicate(naming.getRootContext()),
46  true)){
47  std::cerr << print_prefix << " Failed to load model[" << filename << "]" << std::endl;
48  return 1;
49  } else {
50  std::cerr << print_prefix << " Success to load model[" << filename << "]" << std::endl;
51  }
52  return 0;
53  };
54 
55  int initializeJointPathExInstance (char* root_link_name, char* target_link_name)
56  {
57  jpe = hrp::JointPathExPtr(new hrp::JointPathEx(m_robot, m_robot->link(root_link_name), m_robot->link(target_link_name), 0.002, false, std::string("test")));
58  if ( !jpe ) {
59  std::cerr << print_prefix << " Fail to joint path from " << root_link_name << " to " << target_link_name << std::endl;
60  } else {
61  std::cerr << print_prefix << " Success to joint path from " << root_link_name << " to " << target_link_name << " (dof = " << jpe->numJoints() << std::endl;
62  }
63  return 0;
64  }
65 
66  int _setJointAngles (double* ja)
67  {
68  for ( unsigned int i = 0; i < m_robot->numJoints(); i++ ) {
69  m_robot->joint(i)->q = ja[i];
70  }
71  m_robot->calcForwardKinematics();
72  return 0;
73  }
74 
75  int _getJointAngles (double* ja)
76  {
77  for ( unsigned int i = 0; i < m_robot->numJoints(); i++ ) {
78  ja[i] = m_robot->joint(i)->q;
79  }
80 
81  return 0;
82  }
83 
84  int _calcInverseKinematics2Loop (double* _vel_p, double* _vel_r)
85  {
86  hrp::dvector qrefv = hrp::dvector::Zero(jpe->numJoints());
87  hrp::Vector3 vel_p, vel_r;
88  for (size_t i = 0; i < 3; i++) {
89  vel_p[i] = _vel_p[i];
90  vel_r[i] = _vel_r[i];
91  }
92  jpe->calcInverseKinematics2Loop(vel_p, vel_r, 1.0, 0.002, 0.0, &qrefv);
93  return 0;
94  }
95 };
int _getJointAngles(double *ja)
static std::string print_prefix("[jpe]")
char * filename
int initializeOpenHRPModel(char *_filename)
hrp::JointPathExPtr jpe
manager
int initializeJointPathExInstance(char *root_link_name, char *target_link_name)
CORBA::ORB_ptr getORB()
boost::shared_ptr< JointPathEx > JointPathExPtr
Definition: JointPathEx.h:67
png_uint_32 i
Eigen::VectorXd dvector
Eigen::Vector3d Vector3
coil::Properties & getConfig()
static Manager * init(int argc, char **argv)
int loadBodyFromModelLoader(::World *world, const char *name, const char *url, CosNaming::NamingContext_var cxt)
hrp::BodyPtr m_robot(new hrp::Body())
naming
int _calcInverseKinematics2Loop(double *_vel_p, double *_vel_r)
int _setJointAngles(double *ja)


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