7 #define deg2rad(x) ((x)*M_PI/180) 9 seqplay::seqplay(
unsigned int i_dof,
double i_dt,
unsigned int i_fnum,
unsigned int optional_data_dim) : m_dof(i_dof)
31 double initial_zmp[3] = {0,0,-WAIST_HEIGHT};
32 double initial_waist[3] = {0,0,WAIST_HEIGHT};
34 #elif defined(INITIAL_ZMP_REF_X) 35 double initial_zmp[3] = {INITIAL_ZMP_REF_X, 0, INITIAL_ZMP_REF_Z};
37 double initial_zmp[] = {0,0,0};
40 double initial_wrenches[6 * i_fnum];
41 for (
size_t i = 0;
i < 6 * i_fnum;
i++) initial_wrenches[
i] = 0;
43 double initial_optional_data[optional_data_dim];
44 for (
size_t i = 0;
i < optional_data_dim;
i++) initial_optional_data[
i] = 0;
56 void seqplay::goHalfSitting(
double tm)
61 angle_interpolator->setGoal(get_half_sitting_posture(), tm);
62 #ifdef INITIAL_ZMP_REF_X 63 double zmp[]={INITIAL_ZMP_REF_X, 0, INITIAL_ZMP_REF_Z};
65 double zmp[] = {0,0,0};
67 zmp_interpolator->setGoal(zmp, tm);
68 #ifdef INITIAL_ZMP_REF_Z 69 double waist_pos[]={ref_state.basePosAtt.px,
70 ref_state.basePosAtt.py,
73 double waist_pos[] = {0,0,0};
75 waist_pos_interpolator->setGoal(waist_pos, tm);
77 OpenHRP::convTransformToPosRpy(ref_state.basePosAtt, p, rpy);
78 double initial_rpy[3]={0,0,rpy[2]};
79 waist_rpy_interpolator->setGoal(initial_rpy, tm);
85 tm = (double)angle_interpolator->calc_interpolation_time(get_initial_posture());
87 angle_interpolator->setGoal(get_initial_posture(), tm);
89 double zmp[] = {0,0,-WAIST_HEIGHT};
90 double pos[] = {ref_state.basePosAtt.px,
91 ref_state.basePosAtt.py,
93 waist_pos_interpolator->setGoal(pos, tm);
94 #elif defined(INITIAL_ZMP_REF_Z) 95 double zmp[] = {0,0, INITIAL_ZMP_REF_Z};
97 double zmp[] = {0,0,0};
99 zmp_interpolator->setGoal(zmp, tm);
108 std::map<std::string, groupInterpolator *>::const_iterator it;
111 if (gi && !gi->
isEmpty())
return false;
119 char *s = (
char *)gname;
while(*s) {*s=toupper(*s);s++;}
126 void seqplay::setReferenceState(const ::CharacterState& ref,
double tm)
129 tm = (double)angle_interpolator->calc_interpolation_time(ref.angle);
131 if (ref.angle.length()>0) angle_interpolator->setGoal(ref.angle, tm,
false);
132 if (ref.velocity.length()>0)
133 velocity_interpolator->setGoal(ref.velocity, tm,
false);
134 if (ref.zmp.length()>0) zmp_interpolator->setGoal(ref.zmp, tm,
false);
135 if (ref.accel.length()>0 && ref.accel[0].length() == 3)
136 acc_interpolator->setGoal(ref.accel[0], tm,
false);
138 OpenHRP::convTransformToPosRpy(ref.basePosAtt, p, rpy);
139 waist_pos_interpolator->setGoal(p, tm,
false);
140 waist_rpy_interpolator->setGoal(rpy, tm,
false);
145 void seqplay::getReferenceState(::CharacterState_out ref)
147 ref =
new CharacterState;
221 void seqplay::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)
223 const double *q=NULL, *
z=NULL, *
a=NULL, *p=NULL, *e=NULL, *tq=NULL, *wr=NULL, *od=NULL;
double t=0;
224 double *v =
new double[len];
225 for (
unsigned int i=0;
i<pos.size();
i++){
227 if (
i < pos.size() - 1 ) {
229 if (tm.size() == pos.size()) {
230 t0 = tm[
i]; t1 = tm[
i+1];
234 const double *q_next = pos[
i+1];
236 =
i==0 ? qInit : pos[
i-1];
237 for (
unsigned int j = 0;
j < len;
j++) {
238 double d0, d1, v0, v1;
239 d0 = (q[
j] - q_prev[
j]);
240 d1 = (q_next[
j] - q[
j]);
243 if ( v0 * v1 >= 0 ) {
244 v[
j] = 0.5 * (v0 + v1);
250 for (
unsigned int j = 0;
j < len;
j++) { v[
j] = 0.0; }
252 if (
i < zmp.size()) z = zmp[
i];
253 if (
i < rpy.size()) e = rpy[
i];
254 if (
i < tm.size()) t = tm[
i];
255 go(q, z, a, p, e, tq, wr, od,
256 v, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
279 if (access(pos.c_str(),0)==0){
285 string zmp =
basename; zmp.append(
".zmp");
286 if (access(zmp.c_str(),0)==0){
292 string acc =
basename; acc.append(
".gsens");
293 if (access(acc.c_str(),0)==0){
299 string hip =
basename; hip.append(
".hip");
300 if (access(hip.c_str(),0)==0){
305 hip =
basename; hip.append(
".waist");
306 if (access(hip.c_str(),0)==0){
314 string torque =
basename; torque.append(
".torque");
315 if (access(torque.c_str(),0)==0){
320 if (
debug_level > 0) cout << endl <<
"wrenches = ";
321 string wrenches =
basename; wrenches.append(
".wrenches");
322 if (access(wrenches.c_str(),0)==0){
327 if (
debug_level > 0) cout << endl <<
"optional_data = ";
328 string optional_data =
basename; optional_data.append(
".optionaldata");
329 if (access(optional_data.c_str(),0)==0){
335 if (!found) cerr <<
"pattern not found(" << basename <<
")" << endl;
355 double *o_basePos,
double *o_baseRpy,
double *o_tq,
double *o_wrenches,
double *o_optional_data)
359 std::map<std::string, groupInterpolator *>::iterator it;
381 void seqplay::go(
const double *i_q,
const double *i_zmp,
const double *i_acc,
382 const double *i_p,
const double *i_rpy,
const double *i_tq,
const double *i_wrenches,
const double *i_optional_data,
double i_time,
385 go(i_q, i_zmp, i_acc, i_p, i_rpy, i_tq, i_wrenches, i_optional_data,
386 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
390 void seqplay::go(
const double *i_q,
const double *i_zmp,
const double *i_acc,
391 const double *i_p,
const double *i_rpy,
const double *i_tq,
const double *i_wrenches,
const double *i_optional_data,
392 const double *ii_q,
const double *ii_zmp,
const double *ii_acc,
393 const double *ii_p,
const double *ii_rpy,
const double *ii_tq,
const double *ii_wrenches,
const double *ii_optional_data,
394 double i_time,
bool immediate)
404 if (immediate)
sync();
416 std::map<std::string, groupInterpolator *>::const_iterator it;
426 char *s = (
char *)gname;
while(*s) {*s=toupper(*s);s++;}
429 std::cerr <<
"[addJointGroup] group name " << gname <<
" is already installed" << std::endl;
439 char *s = (
char *)gname;
while(*s) {*s=toupper(*s);s++;}
442 for(
unsigned j = 0;
j < i->
indices.size();
j++) {
447 std::cerr <<
"[getJointGroup] group name " << gname <<
" is not installed" << std::endl;
454 char *s = (
char *)gname;
while(*s) {*s=toupper(*s);s++;}
460 std::cerr <<
"[removeJointGroup] group name " << gname <<
" is not installed" << std::endl;
467 char *s = (
char *)gname;
while(*s) {*s=toupper(*s);s++;}
471 std::map<std::string, groupInterpolator *>::iterator it;
473 if ( it->first != std::string(gname) ) {
484 std::cerr <<
"[resetJointGroup] group name " << gname <<
" is not installed" << std::endl;
491 char *s = (
char *)gname;
while(*s) {*s=toupper(*s);s++;}
494 if (i_qsize != i->
indices.size() ) {
495 std::cerr <<
"[setJointAnglesOfGroup] group name " << gname <<
" : size of manipulater is not equal to input. " << i_qsize <<
" /= " << i->
indices.size() << std::endl;
501 std::map<std::string, groupInterpolator *>::iterator it;
504 if (gi) gi->
get(q, dq,
false);
516 std::cerr <<
"[setJointAnglesOfGroup] group name " << gname <<
" is not installed" << std::endl;
523 char *s = (
char *)gname;
while(*s) {*s=toupper(*s);s++;}
526 i->
clear(i_timeLimit);
532 char *s = (
char *)gname;
while(*s) {*s=toupper(*s);s++;}
535 if (len != i->
indices.size() ) {
536 std::cerr <<
"[playPatternOfGroup] group name " << gname <<
" : size of manipulater is not equal to input. " << len <<
" /= " << i->
indices.size() << std::endl;
542 std::map<std::string, groupInterpolator *>::iterator it;
545 if (gi) gi->
get(q, dq,
false);
552 const double *q=NULL;
double t=0;
553 double *v =
new double[len];
554 double *qi =
new double[len];
555 for (
unsigned int j=0;
j<len;
j++){
558 for (
unsigned int l=0;
l<pos.size();
l++){
560 if (
l < pos.size() - 1 ) {
562 if (tm.size() == pos.size()) {
563 t0 = tm[
l]; t1 = tm[
l+1];
567 const double *q_next = pos[
l+1];
568 const double *q_prev =
l==0 ? qi : pos[
l-1];
569 for (
unsigned int j = 0;
j < len;
j++) {
570 double d0, d1, v0, v1;
571 d0 = (q[
j] - q_prev[
j]);
572 d1 = (q_next[
j] - q[
j]);
575 if ( v0 * v1 >= 0 ) {
576 v[
j] = 0.5 * (v0 + v1);
582 for (
unsigned int j = 0;
j < len;
j++) { v[
j] = 0.0; }
584 if (
l < tm.size()) t = tm[
l];
593 std::cerr <<
"[playPatternOfGroup] group name " << gname <<
" is not installed" << std::endl;
607 const double *q=NULL;
608 for (
unsigned int i=0;
i<pos.size();
i++){
610 if (
i < pos.size() - 1 ) {
612 if (tm.size() == pos.size()) {
613 t0 = tm[
i]; t1 = tm[
i+1];
617 const double *q_next = pos[
i+1];
618 const double *q_prev =
i==0?x:pos[
i-1];
620 double d0, d1, v0, v1;
621 d0 = (q[
j] - q_prev[
j]);
622 d1 = (q_next[
j] - q[
j]);
625 if ( v0 * v1 >= 0 ) {
626 v[
j] = 0.5 * (v0 + v1);
632 for (
int j = 0;
j <
m_dof;
j++) { v[
j] = 0.0; }
660 bool seqplay::setJointAnglesSequenceFull(std::vector<const double*> i_pos, std::vector<const double*> i_vel, std::vector<const double*> i_torques, std::vector<const double*> i_bpos, std::vector<const double*> i_brpy, std::vector<const double*> i_bacc, std::vector<const double*> i_zmps, std::vector<const double*> i_wrenches, std::vector<const double*> i_optionals, std::vector<double> i_tm)
669 for (
int j = 0;
j <
m_dof;
j++) { dummy_dof[
j] = 0.0; }
674 double bpos[3], brpy[3], bacc[3], dummy_3[3]={0,0,0};
688 double zmp[3], wrench[6*fnum], dummy_fnum[6*fnum], optional[optional_data_dim], dummy_optional[optional_data_dim];
689 for (
int j = 0;
j < 6*fnum;
j++) { dummy_dof[
j] = 0.0; }
690 for (
int j = 0;
j < optional_data_dim;
j++) { dummy_optional[
j] = 0.0; }
704 const double *q=NULL;
705 for (
unsigned int i=0;
i<i_pos.size();
i++){
706 if (i_vel.size() > 0 ) {
712 if (
i < i_pos.size() - 1 ) {
714 if (i_tm.size() == i_pos.size()) {
715 t0 = i_tm[
i]; t1 = i_tm[
i+1];
719 const double *q_next = i_pos[
i+1];
720 const double *q_prev =
i==0?x:i_pos[
i-1];
722 double d0, d1, v0, v1;
723 d0 = (q[
j] - q_prev[
j]);
724 d1 = (q_next[
j] - q[
j]);
727 if ( v0 * v1 >= 0 ) {
728 v[
j] = 0.5 * (v0 + v1);
734 for (
int j = 0;
j <
m_dof;
j++) { v[
j] = 0.0; }
747 double tm = i_tm[i], tm_tmp;
764 char *s = (
char *)gname;
while(*s) {*s=toupper(*s);s++;}
768 std::cerr <<
"[setJointAnglesSequenceOfGroup] group name " << gname <<
" is not installed" << std::endl;
771 if (pos_size != i->
indices.size() ) {
772 std::cerr <<
"[setJointAnglesSequenceOfGroup] group name " << gname <<
" : size of manipulater is not equal to input. " << pos_size <<
" /= " << i->
indices.size() << std::endl;
779 std::map<std::string, groupInterpolator *>::iterator it;
782 if (gi) gi->
get(q, dq,
false);
785 double x[len], v[len];
791 const double *q_curr=NULL;
792 for (
unsigned int j=0;
j<pos.size();
j++){
794 if (
j < pos.size() - 1 ) {
796 if (tm.size() == pos.size()) {
797 t0 = tm[
j]; t1 = tm[
j+1];
801 const double *q_next = pos[
j+1];
802 const double *q_prev =
j==0?x:pos[
j-1];
803 for (
int k = 0; k < len; k++) {
804 double d0, d1, v0, v1;
805 d0 = (q_curr[k] - q_prev[k]);
806 d1 = (q_next[k] - q_curr[k]);
809 if ( v0 * v1 >= 0 ) {
810 v[k] = 0.5 * (v0 + v1);
816 for (
int k = 0; k < len; k++) { v[k] = 0.0; }
821 std::map<std::string, groupInterpolator *>::iterator it;
824 if (gi) gi->
get(q, dq,
false);
843 char *s = (
char *)gname;
while(*s) {*s=toupper(*s);s++;}
847 std::cerr <<
"[clearJointAnglesOfGroup] group name " << gname <<
" is not installed" << std::endl;
852 std::cerr <<
"[clearJointAnglesOfGroup] group name " << gname <<
" is not created" << std::endl;
857 std::cerr <<
"[clearJointAnglesOfGroup] group name " << gname <<
" is removing" << std::endl;
862 double x[len], v[len],
a[len];
std::map< std::string, groupInterpolator * > groupInterpolators
void set(const double *full, const double *dfull=NULL)
unsigned long long tick_t
void push(const double *x_, const double *v_, const double *a_, bool immediate=true)
bool setInterpolationMode(interpolation_mode i_mode_)
void interpolate(double &remain_t_)
bool setJointAnglesSequence(std::vector< const double * > pos, std::vector< double > tm)
void load(string fname, double time_to_start=1.0, double scale=1.0, bool immediate=true, size_t offset1=0, size_t offset2=0)
void setJointAngle(unsigned int i_rank, double jv, double tm)
void getJointAngles(double *i_qRef)
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)
void setGoal(const double *g, double tm)
void go(const double *i_q, const double *i_zmp, const double *i_acc, const double *i_p, const double *i_rpy, const double *i_tq, const double *i_wrenches, const double *i_optional_data, double i_time, bool immediate=true)
void setName(const std::string &_name)
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
bool getJointGroup(const char *gname, std::vector< int > &indices)
void setBaseRpy(const double *i_rpy, double i_tm=0.0)
std::string basename(const std::string name)
void get(double *full, double *dfull=NULL, bool popp=true)
seqplay(unsigned int i_dof, double i_dt, unsigned int i_fnum=0, unsigned int optional_data_dim=1)
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)
bool addJointGroup(const char *gname, const std::vector< int > &indices)
bool resetJointGroup(const char *gname, const double *full)
void clearOfGroup(const char *gname, double i_timeLimit)
void setBasePos(const double *i_pos, double i_tm=0.0)
def j(str, encoding="cp932")
void extract(double *dst, const double *src)
void go(const double *gx, const double *gv, double time, bool immediate=true)
bool playPatternOfGroup(const char *gname, std::vector< const double * > pos, std::vector< double > tm, const double *qInit, unsigned int len)
void clear(double i_timeLimit=0)
double calc_interpolation_time(const double *g)
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)
void clear(double i_timeLimit=0)
#define tick2sec(t)
convert time stamp counter into sec
void loadPattern(const char *i_basename, double i_tm)
void get(double *x_, bool popp=true)
std::vector< int > indices
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)
void go(const double *g, double tm)
void setGoal(const double *gx, const double *gv, double time, bool online=true)
interpolator * interpolators[NINTERPOLATOR]
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)
void set(const double *x, const double *v=NULL)
tick_t get_tick()
get time stamp counter