12 #include <hrpModel/ModelLoaderUtil.h> 14 #include "hrpsys/util/VectorConvert.h" 17 #include "../ImpedanceController/JointPathEx.h" 25 "implementation_id",
"SequencePlayer",
26 "type_name",
"SequencePlayer",
27 "description",
"sequence player component",
28 "version", HRPSYS_PACKAGE_VERSION,
30 "category",
"example",
31 "activity_type",
"DataFlowComponent",
34 "lang_type",
"compile",
36 "conf.default.debugLevel",
"0",
37 "conf.default.fixedLink",
"",
46 m_qInitIn(
"qInit", m_qInit),
47 m_basePosInitIn(
"basePosInit", m_basePosInit),
48 m_baseRpyInitIn(
"baseRpyInit", m_baseRpyInit),
49 m_zmpRefInitIn(
"zmpRefInit", m_zmpRefInit),
50 m_qRefOut(
"qRef", m_qRef),
51 m_tqRefOut(
"tqRef", m_tqRef),
52 m_zmpRefOut(
"zmpRef", m_zmpRef),
53 m_accRefOut(
"accRef", m_accRef),
54 m_basePosOut(
"basePos", m_basePos),
55 m_baseRpyOut(
"baseRpy", m_baseRpy),
56 m_optionalDataOut(
"optionalData", m_optionalData),
57 m_SequencePlayerServicePort(
"SequencePlayerService"),
79 std::cout <<
"SequencePlayer::onInitialize()" << std::endl;
119 std::string nameServer = rtcManager.
getConfig()[
"corba.nameservers"];
120 int comPos = nameServer.find(
",");
122 comPos = nameServer.length();
124 nameServer = nameServer.substr(0, comPos);
127 CosNaming::NamingContext::_duplicate(
naming.getRootContext())
129 std::cerr <<
"failed to load model[" << prop[
"model"] <<
"]" 133 unsigned int dof =
m_robot->numJoints();
137 std::vector<std::string> fsensor_names;
140 for (
unsigned int i=0;
i<npforce;
i++){
145 unsigned int nvforce = virtual_force_sensor.size()/10;
146 for (
unsigned int i=0;
i<nvforce;
i++){
147 fsensor_names.push_back(virtual_force_sensor[
i*10+0]);
150 unsigned int nforce = npforce + nvforce;
153 for (
unsigned int i=0;
i<nforce;
i++){
159 if (prop.
hasKey(
"seq_optional_data_dim")) {
168 for (
unsigned int i=0;
i<dof;
i++)
m_qInit.data[
i] = 0.0;
209 std::cout <<
"SequencePlayer::onActivated(" << ec_id <<
")" << std::endl;
249 double zmp[3], acc[3],
pos[3], rpy[3], wrenches[6*
m_wrenches.size()];
262 for (
int i=0;
i<3;
i++){
266 m_robot->calcForwardKinematics();
397 for (
unsigned int i=0;
i<
m_robot->numJoints();
i++){
401 m_robot->calcForwardKinematics();
418 for (
unsigned int i=0;
i<
m_robot->numJoints();
i++){
420 if (j) j->
q = angles[
i];
422 m_robot->calcForwardKinematics();
427 std::vector<const double*> v_poss;
428 std::vector<double> v_tms;
429 v_poss.push_back(angles);
446 double pose[
m_robot->numJoints()];
447 for (
unsigned int i=0;
i<
m_robot->numJoints();
i++){
463 bool tmp_mask[
robot()->numJoints()];
464 if (mask.length() !=
robot()->numJoints()) {
465 for (
unsigned int i=0;
i <
robot()->numJoints();
i++) tmp_mask[
i] =
true;
467 for (
unsigned int i=0;
i <
robot()->numJoints();
i++) tmp_mask[
i] = mask.get_buffer()[
i];
469 int len = angless.length();
470 std::vector<const double*> v_poss;
471 std::vector<double> v_tms;
472 for (
unsigned int i = 0;
i < angless.length();
i++ ) v_poss.push_back(angless[
i].get_buffer());
473 for (
unsigned int i = 0;
i < times.length();
i++ ) v_tms.push_back(times[
i]);
499 std::vector<const double*> v_poss;
500 std::vector<double> v_tms;
501 for (
unsigned int i = 0;
i < angless.length();
i++ ) v_poss.push_back(angless[
i].get_buffer());
502 for (
unsigned int i = 0;
i < times.length();
i++ ) v_tms.push_back(times[
i]);
519 bool SequencePlayer::setJointAnglesSequenceFull(
const OpenHRP::dSequenceSequence i_jvss,
const OpenHRP::dSequenceSequence i_vels,
const OpenHRP::dSequenceSequence i_torques,
const OpenHRP::dSequenceSequence i_poss,
const OpenHRP::dSequenceSequence i_rpys,
const OpenHRP::dSequenceSequence i_accs,
const OpenHRP::dSequenceSequence i_zmps,
const OpenHRP::dSequenceSequence i_wrenches,
const OpenHRP::dSequenceSequence i_optionals,
const dSequence i_tms)
528 int len = i_jvss.length();
529 std::vector<const double*> v_jvss, v_vels, v_torques, v_poss, v_rpys, v_accs, v_zmps, v_wrenches, v_optionals;
530 std::vector<double> v_tms;
531 for (
unsigned int i = 0;
i < i_jvss.length();
i++ ) v_jvss.push_back(i_jvss[
i].get_buffer());
532 for (
unsigned int i = 0;
i < i_vels.length();
i++ ) v_vels.push_back(i_vels[
i].get_buffer());
533 for (
unsigned int i = 0;
i < i_torques.length();
i++ ) v_torques.push_back(i_torques[
i].get_buffer());
534 for (
unsigned int i = 0;
i < i_poss.length();
i++ ) v_poss.push_back(i_poss[
i].get_buffer());
535 for (
unsigned int i = 0;
i < i_rpys.length();
i++ ) v_rpys.push_back(i_rpys[
i].get_buffer());
536 for (
unsigned int i = 0;
i < i_accs.length();
i++ ) v_accs.push_back(i_accs[
i].get_buffer());
537 for (
unsigned int i = 0;
i < i_zmps.length();
i++ ) v_zmps.push_back(i_zmps[
i].get_buffer());
538 for (
unsigned int i = 0;
i < i_wrenches.length();
i++ ) v_wrenches.push_back(i_wrenches[
i].get_buffer());
539 for (
unsigned int i = 0;
i < i_optionals.length();
i++ ) v_optionals.push_back(i_optionals[
i].get_buffer());
540 for (
unsigned int i = 0;
i < i_tms.length();
i++ ) v_tms.push_back(i_tms[
i]);
589 std::vector<int> indices;
591 std::vector<hrp::dvector> avs;
593 std::cerr <<
"[setTargetPose] Could not find joint group " << gname << std::endl;
596 start_av.resize(indices.size());
597 end_av.resize(indices.size());
600 if ( !
m_robot->joint(indices[0])->parent ) {
601 std::cerr <<
"[setTargetPose] " <<
m_robot->joint(indices[0])->name <<
" does not have parent" << std::endl;
604 string base_parent_name =
m_robot->joint(indices[0])->parent->name;
605 string target_name =
m_robot->joint(indices[indices.size()-1])->
name;
610 for (
unsigned int i=0;
i<
m_robot->numJoints();
i++){
612 if (j) j->
q =
m_qRef.data.get_buffer()[
i];
614 m_robot->calcForwardKinematics();
615 for (
unsigned int i = 0;
i < manip->numJoints();
i++ ){
616 start_av[
i] = manip->joint(
i)->q;
628 if ( (frame_name != NULL) && (!
m_robot->link(frame_name) ) ) {
629 std::cerr <<
"[setTargetPose] Could not find frame_name " << frame_name << std::endl;
631 }
else if ( frame_name != NULL ) {
635 end_p = frame_R * end_p + frame_p;
636 end_R = frame_R * end_R;
640 std::cerr <<
"[setTargetPose] Solveing IK with frame " << (frame_name? frame_name:
"world_frame") <<
", Error " <<
m_error_pos <<
m_error_rot <<
", Iteration " <<
m_iteration << std::endl;
641 std::cerr <<
" Start\n" << start_p <<
"\n" << start_R<< std::endl;
642 std::cerr <<
" End\n" << end_p <<
"\n" << end_R<< std::endl;
645 int len =
max(((start_p - end_p).
norm() / 0.02 ),
649 std::vector<const double *> v_pos;
650 std::vector<double> v_tm;
655 for (
int i = 0;
i < len;
i++ ) {
656 double a = (1+
i)/(
double)len;
660 bool ret = manip->calcInverseKinematics2(p, R);
664 std::cerr <<
"target pos/rot : " <<
i <<
"/" << a <<
" : " 665 << p[0] <<
" " << p[1] <<
" " << p[2] <<
"," 666 << omega[0] <<
" " << omega[1] <<
" " << omega[2] << std::endl;
669 std::cerr <<
"[setTargetPose] IK failed" << std::endl;
672 v_pos[
i] = (
const double *)
malloc(
sizeof(
double)*manip->numJoints());
673 for (
unsigned int j = 0;
j < manip->numJoints();
j++ ){
674 ((
double *)v_pos[
i])[
j] = manip->joint(
j)->q;
681 for(
int i = 0;
i < len;
i++ ) {
682 std::cerr << v_tm[
i] <<
":";
683 for(
int j = 0;
j < start_av.size();
j++ ) {
684 std::cerr << v_pos[
i][
j] <<
" ";
686 std::cerr << std::endl;
694 for (
int i = 0;
i < len;
i++ ) {
695 free((
double *)v_pos[
i]);
716 m_robot->calcForwardKinematics();
720 std::string
pos = std::string(basename)+
".pos";
721 std::string wst = std::string(basename)+
".waist";
722 std::ifstream ifspos(pos.c_str());
723 std::ifstream ifswst(wst.c_str());
724 if (!ifspos.is_open() || !ifswst.is_open()){
726 << wst <<
")" << std::endl;
736 for (
int i=0; i<3; i++) ifswst >>
m_robot->rootLink()->p[
i];
738 for (
int i=0; i<3; i++) ifswst >> rpy[
i];
740 m_robot->calcForwardKinematics();
757 if (
m_qInit.data.length() == 0){
758 std::cerr <<
"can't determine initial posture" << std::endl;
762 for (
unsigned int i=0;
i<
m_robot->numJoints();
i++){
783 double zero[] = {0,0,0};
797 std::vector<const double *> v_pos, v_rpy, v_zmp;
798 std::vector<double> v_tm;
799 for (
unsigned int i = 0;
i < pos.length();
i++ ) v_pos.push_back(pos[
i].get_buffer());
800 for (
unsigned int i = 0;
i < rpy.length();
i++ ) v_rpy.push_back(rpy[
i].get_buffer());
801 for (
unsigned int i = 0;
i < zmp.length();
i++ ) v_zmp.push_back(zmp[
i].get_buffer());
802 for (
unsigned int i = 0;
i < tm.length() ;
i++ ) v_tm.push_back(tm[
i]);
803 return m_seq->
playPattern(v_pos, v_rpy, v_zmp, v_tm,
m_qInit.data.get_buffer(), pos.length()>0?pos[0].length():0);
813 if (i_mode_ == OpenHRP::SequencePlayerService::LINEAR){
815 }
else if (i_mode_ == OpenHRP::SequencePlayerService::HOFFARBIB){
825 std::cerr <<
"[addJointGroup] group name = " << gname << std::endl;
832 std::vector<int> indices;
833 for (
size_t i=0;
i<jnames.length();
i++){
838 std::cerr <<
"[addJointGroup] link name " << jnames[i] <<
"is not found" << std::endl;
847 std::cerr <<
"[removeJointGroup] group name = " << gname << std::endl;
878 std::vector<const double *> v_pos;
879 std::vector<double> v_tm;
880 for (
unsigned int i = 0;
i < pos.length();
i++ ) v_pos.push_back(pos[
i].get_buffer());
881 for (
unsigned int i = 0;
i < tm.length() ;
i++ ) v_tm.push_back(tm[
i]);
902 RTC::Create<SequencePlayer>,
903 RTC::Delete<SequencePlayer>);
ComponentProfile m_profile
png_infop png_charpp int png_charpp profile
static const char * sequenceplayer_spec[]
bool setTargetPose(const char *gname, const double *xyz, const double *rpy, double tm, const char *frame_name)
unsigned int m_debugLevel
bool setJointAnglesSequence(std::vector< const double * > pos, std::vector< double > tm)
virtual RTC::ReturnCode_t onFinalize()
bool setJointAnglesSequenceFull(const OpenHRP::dSequenceSequence i_jvss, const OpenHRP::dSequenceSequence i_vels, const OpenHRP::dSequenceSequence i_torques, const OpenHRP::dSequenceSequence i_poss, const OpenHRP::dSequenceSequence i_rpys, const OpenHRP::dSequenceSequence i_accs, const OpenHRP::dSequenceSequence i_zmps, const OpenHRP::dSequenceSequence i_wrenches, const OpenHRP::dSequenceSequence i_optionals, const dSequence i_tms)
void SequencePlayerInit(RTC::Manager *manager)
bool stringTo(To &val, const char *str)
void getJointAngles(double *i_qRef)
bool setWrenches(const double *wrenches, double tm)
void setZmp(const double *i_zmp, double i_tm=0.0)
void setBaseAcc(const double *i_acc, double i_tm=0.0)
bool setJointAnglesOfGroup(const char *gname, const double *i_qRef, const size_t i_qsize, double i_tm=0.0)
bool setZmp(const double *zmp, double tm)
sequence player component
png_infop png_charpp name
virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id)
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
std::vector< TimedDoubleSeq > m_wrenches
coil::Guard< coil::Mutex > Guard
bool setJointAngles(const double *angles, double tm)
vstring split(const std::string &input, const std::string &delimiter, bool ignore_empty)
OutPort< TimedOrientation3D > m_baseRpyOut
HRP_UTIL_EXPORT void calcRotFromRpy(Matrix33 &out_R, double r, double p, double y)
void player(SequencePlayer *i_player)
bool getJointGroup(const char *gname, std::vector< int > &indices)
void setBaseRpy(const double *i_rpy, double i_tm=0.0)
boost::shared_ptr< JointPathEx > JointPathExPtr
std::string basename(const std::string name)
Properties * hasKey(const char *key) const
coil::Properties & getProperties()
bool setJointAnglesSequence(const OpenHRP::dSequenceSequence angless, const OpenHRP::bSequence &mask, const OpenHRP::dSequence ×)
static Manager & instance()
InPort< TimedPoint3D > m_basePosInitIn
InPort< TimedDoubleSeq > m_qInitIn
bool addOutPort(const char *name, OutPortBase &outport)
bool removeJointGroup(const char *gname)
boost::shared_ptr< Body > BodyPtr
void loadPattern(const char *basename, double time)
SequencePlayerService_impl m_service0
bool addJointGroup(const char *gname, const OpenHRP::SequencePlayerService::StrSequence &jnames)
bool removeJointGroup(const char *gname, double time=2.5)
bool setJointAnglesSequenceOfGroup(const char *gname, std::vector< const double * > pos, std::vector< double > tm, const size_t pos_size)
Matrix33 rotFromRpy(const Vector3 &rpy)
bool setJointAnglesSequenceOfGroup(const char *gname, const OpenHRP::dSequenceSequence angless, const OpenHRP::dSequence ×)
bool addJointGroup(const char *gname, const std::vector< int > &indices)
bool setBaseRpy(const double *rpy, double tm)
bool resetJointGroup(const char *gname, const double *full)
std::vector< std::string > vstring
void setBasePos(const double *i_pos, double i_tm=0.0)
bool setBasePos(const double *pos, double tm)
coil::Properties & getConfig()
bool waitInterpolationOfGroup(const char *gname)
bool clearJointAnglesOfGroup(const char *gname)
OutPort< TimedPoint3D > m_zmpRefOut
ExecutionContextHandle_t UniqueId
bool bindParameter(const char *param_name, VarType &var, const char *def_val, bool(*trans)(VarType &, const char *)=coil::stringTo)
OutPort< TimedDoubleSeq > m_tqRefOut
def j(str, encoding="cp932")
void playPattern(const OpenHRP::dSequenceSequence &pos, const OpenHRP::dSequenceSequence &rpy, const OpenHRP::dSequenceSequence &zmp, const OpenHRP::dSequence &tm)
Matrix33 rodrigues(const Vector3 &axis, double q)
TimedPoint3D m_zmpRefInit
bool playPatternOfGroup(const char *gname, std::vector< const double * > pos, std::vector< double > tm, const double *qInit, unsigned int len)
int loadBodyFromModelLoader(::World *world, const char *name, const char *url, CosNaming::NamingContext_var cxt)
void setMaxIKIteration(short iter)
bool setInterpolationMode(interpolator::interpolation_mode i_mode_)
void get(double *o_q, double *o_zmp, double *o_accel, double *o_basePos, double *o_baseRpy, double *o_tq, double *o_wrenches, double *o_optional_data)
TimedAcceleration3D m_accRef
OutPort< TimedAcceleration3D > m_accRefOut
virtual ~SequencePlayer()
void clear(double i_timeLimit=0)
#define __PRETTY_FUNCTION__
void setMaxIKError(double pos, double rot)
bool setJointAngle(short id, double angle, double tm)
TimedDoubleSeq m_optionalData
bool setJointAnglesOfGroup(const char *gname, const OpenHRP::dSequence &jvs, double tm)
HRP_UTIL_EXPORT Vector3 rpyFromRot(const Matrix33 &m)
TimedOrientation3D m_baseRpy
bool setInitialState(double tm=0.0)
InPort< TimedPoint3D > m_zmpRefInitIn
OutPort< TimedDoubleSeq > m_qRefOut
void loadPattern(const char *i_basename, double i_tm)
bool setInterpolationMode(OpenHRP::SequencePlayerService::interpolationMode i_mode_)
bool addPort(PortBase &port)
OutPort< TimedDoubleSeq > m_optionalDataOut
virtual bool write(DataType &value)
HRP_UTIL_EXPORT Vector3 omegaFromRot(const Matrix33 &r)
virtual RTC::ReturnCode_t onInitialize()
RTC::CorbaPort m_SequencePlayerServicePort
bool setJointAnglesSequenceFull(std::vector< const double * > pos, std::vector< const double * > vel, std::vector< const double * > torques, std::vector< const double * > bpos, std::vector< const double * > brpy, std::vector< const double * > bacc, std::vector< const double * > zmps, std::vector< const double * > wrenches, std::vector< const double * > optionals, std::vector< double > tm)
bool clearJointAnglesOfGroup(const char *gname)
OutPort< TimedPoint3D > m_basePosOut
SequencePlayer(RTC::Manager *manager)
bool playPatternOfGroup(const char *gname, const OpenHRP::dSequenceSequence &pos, const OpenHRP::dSequence &tm)
bool addInPort(const char *name, InPortBase &inport)
void registerOutPort(const char *name, OutPortBase &outport)
InPort< TimedOrientation3D > m_baseRpyInitIn
TimedPoint3D m_basePosInit
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
double m_timeToStartPlaying
void setJointAngles(const double *i_qRef, double i_tm=0.0)
void playPattern(std::vector< const double * > pos, std::vector< const double * > zmp, std::vector< const double * > rpy, std::vector< double > tm, const double *qInit, unsigned int len)
void setWrenches(const double *i_wrenches, double i_tm=0.0)
bool registerProvider(const char *instance_name, const char *type_name, PortableServer::RefCountServantBase &provider)
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
std::vector< OutPort< TimedDoubleSeq > * > m_wrenchesOut
TimedOrientation3D m_baseRpyInit