diff --git a/idl/SequencePlayerService.idl b/idl/SequencePlayerService.idl index 4cb3fd63d68..92540f34912 100644 --- a/idl/SequencePlayerService.idl +++ b/idl/SequencePlayerService.idl @@ -55,6 +55,38 @@ module OpenHRP */ boolean setJointAngle(in string jname, in double jv, in double tm); + /** + * @brief Interpolate all joint velocities on robot using duration specified by \em tm. Returns without waiting for whole sequence to be sent to robot. + * @param jvs sequence of joint velocitys + * @param tm duration [s] + * @return true joint velocitys are set successfully, false otherwise + */ + boolean setJointVelocities(in dSequence jvs, in double tm); + + /** + * @brief Interpolate all joint velocitys on robot using duration specified by \em tm. Returns without waiting for whole sequence to be sent to robot. If this function called during the robot moves, it overwrite current goal. [>= 315.5.0] + * @param jvs sequence of sequence of joint velocitys [rad] + * @param tm sequence of duration [s] + * @return true joint velocitys are set successfully, false otherwise + */ + boolean setJointVelocitiesSequence(in dSequenceSequence jvss, in dSequence tms); + + /** + * @brief Interpolate all joint torques on robot using duration specified by \em tm. Returns without waiting for whole sequence to be sent to robot. + * @param jvs sequence of joint torques + * @param tm duration [s] + * @return true joint torques are set successfully, false otherwise + */ + boolean setJointTorques(in dSequence jvs, in double tm); + + /** + * @brief Interpolate all joint torques on robot using duration specified by \em tm. Returns without waiting for whole sequence to be sent to robot. If this function called during the robot moves, it overwrite current goal. [>= 315.5.0] + * @param jvs sequence of sequence of joint torques [rad] + * @param tm sequence of duration [s] + * @return true joint torques are set successfully, false otherwise + */ + boolean setJointTorquesSequence(in dSequenceSequence jvss, in dSequence tms); + /** * @brief Interpolate position of the base link. Function returns without waiting for interpolation to finish * @param pos position of the base link [m] @@ -161,6 +193,24 @@ module OpenHRP */ boolean setJointAnglesOfGroup(in string gname, in dSequence jvs, in double tm); + /** + * @brief Interpolate joint velocities in a group using duration specified by \em tm. Returns without waiting for whole sequence to be sent to robot. + * @param gname name of the joint group + * @param jvs sequence of joint velocities + * @param tm duration [s] + * @return true joint velocities are set successfully, false otherwise + */ + boolean setJointVelocitiesOfGroup(in string gname, in dSequence jvs, in double tm); + + /** + * @brief Interpolate joint torques in a group using duration specified by \em tm. Returns without waiting for whole sequence to be sent to robot. + * @param gname name of the joint group + * @param jvs sequence of joint torques + * @param tm duration [s] + * @return true joint torques are set successfully, false otherwise + */ + boolean setJointTorquesOfGroup(in string gname, in dSequence jvs, in double tm); + /** * @brief clear pattern data with joint group * @param gname name of the joint group @@ -225,6 +275,24 @@ module OpenHRP */ boolean setJointAnglesSequenceOfGroup(in string gname, in dSequenceSequence jvss, in dSequence tms); + /** + * @brief Interpolate all joint velocities in groups, using duration specified by \em tm. Returns without waiting for whole sequence to be sent to robot. If this function called during the robot moves, it overwrite current goal. [>= 315.5.0] + * @param gname name of the joint group + * @param jvs sequence of sequence of joint velocities [rad] + * @param tm sequence of duration [s] + * @return true joint velocities are set successfully, false otherwise + */ + boolean setJointVelocitiesSequenceOfGroup(in string gname, in dSequenceSequence jvss, in dSequence tms); + + /** + * @brief Interpolate all joint torques in groups, using duration specified by \em tm. Returns without waiting for whole sequence to be sent to robot. If this function called during the robot moves, it overwrite current goal. [>= 315.5.0] + * @param gname name of the joint group + * @param jvs sequence of sequence of joint torques [rad] + * @param tm sequence of duration [s] + * @return true joint torques are set successfully, false otherwise + */ + boolean setJointTorquesSequenceOfGroup(in string gname, in dSequenceSequence jvss, in dSequence tms); + /** * @brief Interpolate all joint angles, using duration specified by \em tm. Returns without waiting for whole sequence to be sent to robot. If this function called during the robot moves, it overwrite current goal. [>= 315.5.0] * @param jvss sequence of sequence of joint angles [rad] diff --git a/rtc/SequencePlayer/SequencePlayer.cpp b/rtc/SequencePlayer/SequencePlayer.cpp index c8a685ad982..2d9e3bca267 100644 --- a/rtc/SequencePlayer/SequencePlayer.cpp +++ b/rtc/SequencePlayer/SequencePlayer.cpp @@ -49,6 +49,7 @@ SequencePlayer::SequencePlayer(RTC::Manager* manager) m_zmpRefInitIn("zmpRefInit", m_zmpRefInit), m_qRefOut("qRef", m_qRef), m_tqRefOut("tqRef", m_tqRef), + m_dqRefOut("dqRef", m_dqRef), m_zmpRefOut("zmpRef", m_zmpRef), m_accRefOut("accRef", m_accRef), m_basePosOut("basePos", m_basePos), @@ -88,6 +89,7 @@ RTC::ReturnCode_t SequencePlayer::onInitialize() // Set OutPort buffer addOutPort("qRef", m_qRefOut); addOutPort("tqRef", m_tqRefOut); + addOutPort("dqRef", m_dqRefOut); addOutPort("zmpRef", m_zmpRefOut); addOutPort("accRef", m_accRefOut); addOutPort("basePos", m_basePosOut); @@ -175,6 +177,7 @@ RTC::ReturnCode_t SequencePlayer::onInitialize() // allocate memory for outPorts m_qRef.data.length(dof); m_tqRef.data.length(dof); + m_dqRef.data.length(dof); m_optionalData.data.length(optional_data_dim); return RTC::RTC_OK; @@ -247,7 +250,7 @@ RTC::ReturnCode_t SequencePlayer::onExecute(RTC::UniqueId ec_id) Guard guard(m_mutex); double zmp[3], acc[3], pos[3], rpy[3], wrenches[6*m_wrenches.size()]; - m_seq->get(m_qRef.data.get_buffer(), zmp, acc, pos, rpy, m_tqRef.data.get_buffer(), wrenches, m_optionalData.data.get_buffer()); + m_seq->get(m_qRef.data.get_buffer(), zmp, acc, pos, rpy, m_tqRef.data.get_buffer(), wrenches, m_optionalData.data.get_buffer(), m_dqRef.data.get_buffer()); m_zmpRef.data.x = zmp[0]; m_zmpRef.data.y = zmp[1]; m_zmpRef.data.z = zmp[2]; @@ -304,6 +307,7 @@ RTC::ReturnCode_t SequencePlayer::onExecute(RTC::UniqueId ec_id) m_qRef.tm = m_qInit.tm; m_qRefOut.write(); m_tqRefOut.write(); + m_dqRefOut.write(); m_zmpRefOut.write(); m_accRefOut.write(); m_basePosOut.write(); @@ -507,6 +511,40 @@ bool SequencePlayer::setJointAnglesSequenceOfGroup(const char *gname, const Open return m_seq->setJointAnglesSequenceOfGroup(gname, v_poss, v_tms, angless.length()>0?angless[0].length():0); } +bool SequencePlayer::setJointVelocitiesSequenceOfGroup(const char *gname, const OpenHRP::dSequenceSequence velocitiess, const OpenHRP::dSequence& times) +{ + if ( m_debugLevel > 0 ) { + std::cerr << __PRETTY_FUNCTION__ << std::endl; + } + Guard guard(m_mutex); + if (!setInitialState()) return false; + + if (!m_seq->resetJointGroup(gname, m_qInit.data.get_buffer())) return false; + + std::vector v_vels; + std::vector v_tms; + for ( unsigned int i = 0; i < velocitiess.length(); i++ ) v_vels.push_back(velocitiess[i].get_buffer()); + for ( unsigned int i = 0; i < times.length(); i++ ) v_tms.push_back(times[i]); + return m_seq->setJointVelocitiesSequenceOfGroup(gname, v_vels, v_tms, velocitiess.length()>0?velocitiess[0].length():0); +} + +bool SequencePlayer::setJointTorquesSequenceOfGroup(const char *gname, const OpenHRP::dSequenceSequence torquess, const OpenHRP::dSequence& times) +{ + if ( m_debugLevel > 0 ) { + std::cerr << __PRETTY_FUNCTION__ << std::endl; + } + Guard guard(m_mutex); + if (!setInitialState()) return false; + + if (!m_seq->resetJointGroup(gname, m_qInit.data.get_buffer())) return false; + + std::vector v_torques; + std::vector v_tms; + for ( unsigned int i = 0; i < torquess.length(); i++ ) v_torques.push_back(torquess[i].get_buffer()); + for ( unsigned int i = 0; i < times.length(); i++ ) v_tms.push_back(times[i]); + return m_seq->setJointTorquesSequenceOfGroup(gname, v_torques, v_tms, torquess.length()>0?torquess[0].length():0); +} + bool SequencePlayer::clearJointAnglesOfGroup(const char *gname) { if ( m_debugLevel > 0 ) { @@ -545,6 +583,68 @@ bool SequencePlayer::setJointAnglesSequenceFull(const OpenHRP::dSequenceSequence return m_seq->setJointAnglesSequenceFull(v_jvss, v_vels, v_torques, v_poss, v_rpys, v_accs, v_zmps, v_wrenches, v_optionals, v_tms); } +bool SequencePlayer::setJointVelocities(const double *velocitys, double tm) +{ + if ( m_debugLevel > 0 ) { + std::cerr << __PRETTY_FUNCTION__ << std::endl; + } + Guard guard(m_mutex); + if (!setInitialState()) return false; + std::vector v_vels; + std::vector v_tms; + v_vels.push_back(velocitys); + v_tms.push_back(tm); + m_seq->setJointVelocitiesSequence(v_vels, v_tms); + return true; +} + +bool SequencePlayer::setJointVelocitiesSequence(const OpenHRP::dSequenceSequence velocityss, const OpenHRP::dSequence& times) +{ + if ( m_debugLevel > 0 ) { + std::cerr << __PRETTY_FUNCTION__ << std::endl; + } + Guard guard(m_mutex); + + if (!setInitialState()) return false; + + std::vector v_vels; + std::vector v_tms; + for ( unsigned int i = 0; i < velocityss.length(); i++ ) v_vels.push_back(velocityss[i].get_buffer()); + for ( unsigned int i = 0; i < times.length(); i++ ) v_tms.push_back(times[i]); + return m_seq->setJointVelocitiesSequence(v_vels, v_tms); +} + +bool SequencePlayer::setJointTorques(const double *torques, double tm) +{ + if ( m_debugLevel > 0 ) { + std::cerr << __PRETTY_FUNCTION__ << std::endl; + } + Guard guard(m_mutex); + if (!setInitialState()) return false; + std::vector v_torques; + std::vector v_tms; + v_torques.push_back(torques); + v_tms.push_back(tm); + m_seq->setJointTorquesSequence(v_torques, v_tms); + return true; +} + +bool SequencePlayer::setJointTorquesSequence(const OpenHRP::dSequenceSequence torquess, const OpenHRP::dSequence& times) +{ + if ( m_debugLevel > 0 ) { + std::cerr << __PRETTY_FUNCTION__ << std::endl; + } + Guard guard(m_mutex); + + if (!setInitialState()) return false; + + std::vector v_torques; + std::vector v_tms; + for ( unsigned int i = 0; i < torquess.length(); i++ ) v_torques.push_back(torquess[i].get_buffer()); + for ( unsigned int i = 0; i < times.length(); i++ ) v_tms.push_back(times[i]); + return m_seq->setJointTorquesSequence(v_torques, v_tms); +} + bool SequencePlayer::setBasePos(const double *pos, double tm) { if ( m_debugLevel > 0 ) { @@ -875,6 +975,30 @@ bool SequencePlayer::setJointAnglesOfGroup(const char *gname, const dSequence& j return m_seq->setJointAnglesOfGroup(gname, jvs.get_buffer(), jvs.length(), tm); } +bool SequencePlayer::setJointVelocitiesOfGroup(const char *gname, const dSequence& jvs, double tm) +{ + if ( m_debugLevel > 0 ) { + std::cerr << __PRETTY_FUNCTION__ << std::endl; + } + Guard guard(m_mutex); + if (!setInitialState()) return false; + + if (!m_seq->resetJointGroup(gname, m_qInit.data.get_buffer())) return false; + return m_seq->setJointVelocitiesOfGroup(gname, jvs.get_buffer(), jvs.length(), tm); +} + +bool SequencePlayer::setJointTorquesOfGroup(const char *gname, const dSequence& jvs, double tm) +{ + if ( m_debugLevel > 0 ) { + std::cerr << __PRETTY_FUNCTION__ << std::endl; + } + Guard guard(m_mutex); + if (!setInitialState()) return false; + + if (!m_seq->resetJointGroup(gname, m_qInit.data.get_buffer())) return false; + return m_seq->setJointTorquesOfGroup(gname, jvs.get_buffer(), jvs.length(), tm); +} + bool SequencePlayer::playPatternOfGroup(const char *gname, const dSequenceSequence& pos, const dSequence& tm) { if ( m_debugLevel > 0 ) { diff --git a/rtc/SequencePlayer/SequencePlayer.h b/rtc/SequencePlayer/SequencePlayer.h index 370c9ee2df9..b58327e70f6 100644 --- a/rtc/SequencePlayer/SequencePlayer.h +++ b/rtc/SequencePlayer/SequencePlayer.h @@ -104,6 +104,10 @@ class SequencePlayer bool setJointAnglesSequence(const OpenHRP::dSequenceSequence angless, const OpenHRP::bSequence& mask, const OpenHRP::dSequence& times); 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); bool clearJointAngles(); + bool setJointVelocities(const double *velocitys, double tm); + bool setJointVelocitiesSequence(const OpenHRP::dSequenceSequence velocityss, const OpenHRP::dSequence& times); + bool setJointTorques(const double *torques, double tm); + bool setJointTorquesSequence(const OpenHRP::dSequenceSequence torquess, const OpenHRP::dSequence& times); bool setBasePos(const double *pos, double tm); bool setBaseRpy(const double *rpy, double tm); bool setZmp(const double *zmp, double tm); @@ -117,6 +121,10 @@ class SequencePlayer bool removeJointGroup(const char *gname); bool setJointAnglesOfGroup(const char *gname, const OpenHRP::dSequence& jvs, double tm); bool setJointAnglesSequenceOfGroup(const char *gname, const OpenHRP::dSequenceSequence angless, const OpenHRP::dSequence& times); + bool setJointVelocitiesOfGroup(const char *gname, const OpenHRP::dSequence& jvs, double tm); + bool setJointVelocitiesSequenceOfGroup(const char *gname, const OpenHRP::dSequenceSequence velocitiess, const OpenHRP::dSequence& times); + bool setJointTorquesOfGroup(const char *gname, const OpenHRP::dSequence& jvs, double tm); + bool setJointTorquesSequenceOfGroup(const char *gname, const OpenHRP::dSequenceSequence torquess, const OpenHRP::dSequence& times); bool clearJointAnglesOfGroup(const char *gname); bool playPatternOfGroup(const char *gname, const OpenHRP::dSequenceSequence& pos, const OpenHRP::dSequence& tm); @@ -147,6 +155,8 @@ class SequencePlayer OutPort m_qRefOut; TimedDoubleSeq m_tqRef; OutPort m_tqRefOut; + TimedDoubleSeq m_dqRef; + OutPort m_dqRefOut; TimedPoint3D m_zmpRef; OutPort m_zmpRefOut; TimedAcceleration3D m_accRef; diff --git a/rtc/SequencePlayer/SequencePlayerService_impl.cpp b/rtc/SequencePlayer/SequencePlayerService_impl.cpp index 0ddf366ad93..ed4697b2ef6 100644 --- a/rtc/SequencePlayer/SequencePlayerService_impl.cpp +++ b/rtc/SequencePlayer/SequencePlayerService_impl.cpp @@ -194,6 +194,60 @@ CORBA::Boolean SequencePlayerService_impl::setJointAngle(const char *jname, CORB return m_player->setJointAngle(id, jv, tm); } +CORBA::Boolean SequencePlayerService_impl::setJointVelocities(const dSequence& jvs, CORBA::Double tm) +{ + if (jvs.length() != (unsigned int)(m_player->robot()->numJoints())) { + std::cerr << __PRETTY_FUNCTION__ << " num of joint is differ, input:" << jvs.length() << ", robot:" << (unsigned int)(m_player->robot()->numJoints()) << std::endl; + return false; + } + return m_player->setJointVelocities(jvs.get_buffer(), tm); +} + +CORBA::Boolean SequencePlayerService_impl::setJointVelocitiesSequence(const dSequenceSequence& jvss, const dSequence& tms) +{ + if (jvss.length() <= 0) { + std::cerr << __PRETTY_FUNCTION__ << " num of joint velocitys sequence is invalid:" << jvss.length() << " > 0" << std::endl; + return false; + } + if (jvss.length() != tms.length()) { + std::cerr << __PRETTY_FUNCTION__ << " length of joint velocitys sequence and time sequence differ, joint velocity:" << jvss.length() << ", time:" << tms.length() << std::endl; + return false; + } + const dSequence& jvs = jvss[0]; + if (jvs.length() != (unsigned int)(m_player->robot()->numJoints())) { + std::cerr << __PRETTY_FUNCTION__ << " num of joint is differ, input:" << jvs.length() << ", robot:" << (unsigned int)(m_player->robot()->numJoints()) << std::endl; + return false; + } + return m_player->setJointVelocitiesSequence(jvss, tms); +} + +CORBA::Boolean SequencePlayerService_impl::setJointTorques(const dSequence& jvs, CORBA::Double tm) +{ + if (jvs.length() != (unsigned int)(m_player->robot()->numJoints())) { + std::cerr << __PRETTY_FUNCTION__ << " num of joint is differ, input:" << jvs.length() << ", robot:" << (unsigned int)(m_player->robot()->numJoints()) << std::endl; + return false; + } + return m_player->setJointTorques(jvs.get_buffer(), tm); +} + +CORBA::Boolean SequencePlayerService_impl::setJointTorquesSequence(const dSequenceSequence& jvss, const dSequence& tms) +{ + if (jvss.length() <= 0) { + std::cerr << __PRETTY_FUNCTION__ << " num of joint torques sequence is invalid:" << jvss.length() << " > 0" << std::endl; + return false; + } + if (jvss.length() != tms.length()) { + std::cerr << __PRETTY_FUNCTION__ << " length of joint torques sequence and time sequence differ, joint torque:" << jvss.length() << ", time:" << tms.length() << std::endl; + return false; + } + const dSequence& jvs = jvss[0]; + if (jvs.length() != (unsigned int)(m_player->robot()->numJoints())) { + std::cerr << __PRETTY_FUNCTION__ << " num of joint is differ, input:" << jvs.length() << ", robot:" << (unsigned int)(m_player->robot()->numJoints()) << std::endl; + return false; + } + return m_player->setJointTorquesSequence(jvss, tms); +} + CORBA::Boolean SequencePlayerService_impl::setBasePos(const dSequence& pos, CORBA::Double tm) { if (pos.length() != 3) return false; @@ -306,6 +360,34 @@ CORBA::Boolean SequencePlayerService_impl::setJointAnglesSequenceOfGroup(const c return m_player->setJointAnglesSequenceOfGroup(gname, jvss, tms); } +CORBA::Boolean SequencePlayerService_impl::setJointVelocitiesOfGroup(const char *gname, const dSequence& jvs, CORBA::Double tm) +{ + return m_player->setJointVelocitiesOfGroup(gname, jvs, tm); +} + +CORBA::Boolean SequencePlayerService_impl::setJointVelocitiesSequenceOfGroup(const char *gname, const dSequenceSequence& jvss, const dSequence& tms) +{ + if (jvss.length() != tms.length()) { + std::cerr << __PRETTY_FUNCTION__ << " length of joint velocities sequence and time sequence differ, joint angle:" << jvss.length() << ", time:" << tms.length() << std::endl; + return false; + } + return m_player->setJointVelocitiesSequenceOfGroup(gname, jvss, tms); +} + +CORBA::Boolean SequencePlayerService_impl::setJointTorquesOfGroup(const char *gname, const dSequence& jvs, CORBA::Double tm) +{ + return m_player->setJointTorquesOfGroup(gname, jvs, tm); +} + +CORBA::Boolean SequencePlayerService_impl::setJointTorquesSequenceOfGroup(const char *gname, const dSequenceSequence& jvss, const dSequence& tms) +{ + if (jvss.length() != tms.length()) { + std::cerr << __PRETTY_FUNCTION__ << " length of joint torques sequence and time sequence differ, joint angle:" << jvss.length() << ", time:" << tms.length() << std::endl; + return false; + } + return m_player->setJointTorquesSequenceOfGroup(gname, jvss, tms); +} + CORBA::Boolean SequencePlayerService_impl::clearJointAnglesOfGroup(const char *gname) { return m_player->clearJointAnglesOfGroup(gname); diff --git a/rtc/SequencePlayer/SequencePlayerService_impl.h b/rtc/SequencePlayer/SequencePlayerService_impl.h index 03345e4345f..6476aca8b1f 100644 --- a/rtc/SequencePlayer/SequencePlayerService_impl.h +++ b/rtc/SequencePlayer/SequencePlayerService_impl.h @@ -25,6 +25,10 @@ class SequencePlayerService_impl CORBA::Boolean setJointAngles(const dSequence& jvs, CORBA::Double tm); CORBA::Boolean setJointAnglesWithMask(const dSequence& jvs, const bSequence& mask, CORBA::Double tm); CORBA::Boolean setJointAngle(const char *jname, CORBA::Double jv, CORBA::Double tm); + CORBA::Boolean setJointVelocities(const dSequence& jvs, CORBA::Double tm); + CORBA::Boolean setJointVelocitiesSequence(const dSequenceSequence& jvs, const dSequence &tms); + CORBA::Boolean setJointTorques(const dSequence& jvs, CORBA::Double tm); + CORBA::Boolean setJointTorquesSequence(const dSequenceSequence& jvs, const dSequence &tms); CORBA::Boolean setBasePos(const dSequence& pos, CORBA::Double tm); CORBA::Boolean setBaseRpy(const dSequence& rpy, CORBA::Double tm); CORBA::Boolean setZmp(const dSequence& zmp, CORBA::Double tm); @@ -41,6 +45,10 @@ class SequencePlayerService_impl CORBA::Boolean removeJointGroup(const char* gname); CORBA::Boolean setJointAnglesOfGroup(const char *gname, const dSequence& jvs, CORBA::Double tm); CORBA::Boolean setJointAnglesSequenceOfGroup(const char *gname, const dSequenceSequence& jvs, const dSequence &tms); + CORBA::Boolean setJointVelocitiesOfGroup(const char *gname, const dSequence& jvs, CORBA::Double tm); + CORBA::Boolean setJointVelocitiesSequenceOfGroup(const char *gname, const dSequenceSequence& jvs, const dSequence &tms); + CORBA::Boolean setJointTorquesOfGroup(const char *gname, const dSequence& jvs, CORBA::Double tm); + CORBA::Boolean setJointTorquesSequenceOfGroup(const char *gname, const dSequenceSequence& jvs, const dSequence &tms); CORBA::Boolean clearJointAnglesOfGroup(const char *gname); CORBA::Boolean clearOfGroup(const char *gname, CORBA::Double i_timelimit); CORBA::Boolean playPatternOfGroup(const char *gname, const dSequenceSequence& pos, const dSequence& tm); diff --git a/rtc/SequencePlayer/seqplay.cpp b/rtc/SequencePlayer/seqplay.cpp index 2ef8e7706ab..ab0c9d98ed0 100644 --- a/rtc/SequencePlayer/seqplay.cpp +++ b/rtc/SequencePlayer/seqplay.cpp @@ -16,6 +16,7 @@ seqplay::seqplay(unsigned int i_dof, double i_dt, unsigned int i_fnum, unsigned interpolators[TQ] = new interpolator(i_dof, i_dt); interpolators[WRENCHES] = new interpolator(6 * i_fnum, i_dt, interpolator::HOFFARBIB, 100); // wrenches = 6 * [number of force sensors] interpolators[OPTIONAL_DATA] = new interpolator(optional_data_dim, i_dt); + interpolators[DQ] = new interpolator(i_dof, i_dt); // Set interpolator name interpolators[Q]->setName("Q"); interpolators[ZMP]->setName("ZMP"); @@ -25,6 +26,7 @@ seqplay::seqplay(unsigned int i_dof, double i_dt, unsigned int i_fnum, unsigned interpolators[TQ]->setName("TQ"); interpolators[WRENCHES]->setName("WRENCHES"); interpolators[OPTIONAL_DATA]->setName("OPTIONAL_DATA"); + interpolators[DQ]->setName("DQ"); // #ifdef WAIST_HEIGHT @@ -220,7 +222,7 @@ void seqplay::setJointAngle(unsigned int i_rank, double jv, double tm) void seqplay::playPattern(std::vector pos, std::vector zmp, std::vector rpy, std::vector tm, const double *qInit, unsigned int len) { - const double *q=NULL, *z=NULL, *a=NULL, *p=NULL, *e=NULL, *tq=NULL, *wr=NULL, *od=NULL; double t=0; + const double *q=NULL, *z=NULL, *a=NULL, *p=NULL, *e=NULL, *tq=NULL, *wr=NULL, *od=NULL, *dq=NULL; double t=0; double *v = new double[len]; for (unsigned int i=0; i pos, std::vectorload(optional_data, tm, scale, false); if (debug_level > 0) cout << optional_data; } + if (debug_level > 0) cout << endl << "vel = "; + string vel = basename; torque.append(".vel"); + if (access(vel.c_str(),0)==0){ + found = true; + interpolators[DQ]->load(vel, tm, scale, false); + if (debug_level > 0) cout << vel; + } if (debug_level > 0) cout << endl; if (!found) cerr << "pattern not found(" << basename << ")" << endl; // @@ -352,45 +361,50 @@ void seqplay::pop_back() } void seqplay::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) + double *o_basePos, double *o_baseRpy, double *o_tq, double *o_wrenches, double *o_optional_data, double *o_dq) { double v[m_dof]; interpolators[Q]->get(o_q, v); + interpolators[ZMP]->get(o_zmp); + interpolators[ACC]->get(o_accel); + interpolators[P]->get(o_basePos); + interpolators[RPY]->get(o_baseRpy); + interpolators[TQ]->get(o_tq); + interpolators[WRENCHES]->get(o_wrenches); + interpolators[OPTIONAL_DATA]->get(o_optional_data); + interpolators[DQ]->get(o_dq); + std::map::iterator it; for (it=groupInterpolators.begin(); it!=groupInterpolators.end();){ groupInterpolator *gi = it->second; if (gi){ - gi->get(o_q, v); + gi->interpolate(o_q, v, o_dq, nullptr, o_tq, nullptr); + gi->get(groupInterpolator::G_Q, o_q); + gi->get(groupInterpolator::G_DQ, o_dq); + gi->get(groupInterpolator::G_TQ, o_tq); if (gi->state == groupInterpolator::removed){ - groupInterpolators.erase(it++); + it = groupInterpolators.erase(it); delete gi; continue; } } ++it; } - interpolators[ZMP]->get(o_zmp); - interpolators[ACC]->get(o_accel); - interpolators[P]->get(o_basePos); - interpolators[RPY]->get(o_baseRpy); - interpolators[TQ]->get(o_tq); - interpolators[WRENCHES]->get(o_wrenches); - interpolators[OPTIONAL_DATA]->get(o_optional_data); } void seqplay::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, + const double *i_p, const double *i_rpy, const double *i_tq, const double *i_wrenches, const double *i_optional_data, const double *i_dq, double i_time, bool immediate) { - go(i_q, i_zmp, i_acc, i_p, i_rpy, i_tq, i_wrenches, i_optional_data, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + go(i_q, i_zmp, i_acc, i_p, i_rpy, i_tq, i_wrenches, i_optional_data, i_dq, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, i_time, immediate); } void seqplay::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, + const double *i_p, const double *i_rpy, const double *i_tq, const double *i_wrenches, const double *i_optional_data, const double *i_dq, const double *ii_q, const double *ii_zmp, const double *ii_acc, - const double *ii_p, const double *ii_rpy, const double *ii_tq, const double *ii_wrenches, const double *ii_optional_data, + const double *ii_p, const double *ii_rpy, const double *ii_tq, const double *ii_wrenches, const double *ii_optional_data, const double *ii_dq, double i_time, bool immediate) { if (i_q) interpolators[Q]->go(i_q, ii_q, i_time, false); @@ -401,6 +415,7 @@ void seqplay::go(const double *i_q, const double *i_zmp, const double *i_acc, if (i_tq) interpolators[TQ]->go(i_tq, ii_tq, i_time, false); if (i_wrenches) interpolators[WRENCHES]->go(i_wrenches, ii_wrenches, i_time, false); if (i_optional_data) interpolators[OPTIONAL_DATA]->go(i_optional_data, ii_optional_data, i_time, false); + if (i_dq) interpolators[DQ]->go(i_dq, ii_dq, i_time, false); if (immediate) sync(); } @@ -416,7 +431,7 @@ bool seqplay::setInterpolationMode (interpolator::interpolation_mode i_mode_) std::map::const_iterator it; for (it=groupInterpolators.begin(); it!=groupInterpolators.end(); it++){ groupInterpolator *gi = it->second; - ret &= gi->inter->setInterpolationMode(i_mode_); + ret &= gi->setInterpolationMode(i_mode_); } return ret; } @@ -467,13 +482,15 @@ bool seqplay::resetJointGroup(const char *gname, const double *full) char *s = (char *)gname; while(*s) {*s=toupper(*s);s++;} groupInterpolator *i = groupInterpolators[gname]; if (i){ - i->set(full); + if(!i->isEmpty()) return true; + + i->set(groupInterpolator::G_Q, full); std::map::iterator it; for (it=groupInterpolators.begin(); it!=groupInterpolators.end(); it++){ if ( it->first != std::string(gname) ) { // other groupInterpolator *gi = it->second; - if (gi && (gi->state == groupInterpolator::created || gi->state == groupInterpolator::working) && gi->inter->isEmpty()) { - gi->set(full); + if (gi && (gi->state == groupInterpolator::created || gi->state == groupInterpolator::working) && gi->isEmpty()) { + gi->set(groupInterpolator::G_Q, full); } } } @@ -487,33 +504,42 @@ bool seqplay::resetJointGroup(const char *gname, const double *full) } bool seqplay::setJointAnglesOfGroup(const char *gname, const double* i_qRef, const size_t i_qsize, double i_tm) +{ + return setJointCommonOfGroup(Q, groupInterpolator::G_Q, gname, i_qRef, i_qsize, i_tm);} + +bool seqplay::setJointVelocitiesOfGroup(const char *gname, const double* i_dqRef, const size_t i_dqsize, double i_tm) +{ + return setJointCommonOfGroup(DQ, groupInterpolator::G_DQ, gname, i_dqRef, i_dqsize, i_tm); +} + +bool seqplay::setJointTorquesOfGroup(const char *gname, const double* i_tqRef, const size_t i_tqsize, double i_tm) +{ + return setJointCommonOfGroup(TQ, groupInterpolator::G_TQ, gname, i_tqRef, i_tqsize, i_tm); +} + +bool seqplay::setJointCommonOfGroup(unsigned int type, unsigned int g_type, const char *gname, const double* i_qRef, const size_t i_qsize, double i_tm) { char *s = (char *)gname; while(*s) {*s=toupper(*s);s++;} groupInterpolator *i = groupInterpolators[gname]; if (i){ if (i_qsize != i->indices.size() ) { - std::cerr << "[setJointAnglesOfGroup] group name " << gname << " : size of manipulater is not equal to input. " << i_qsize << " /= " << i->indices.size() << std::endl; + std::cerr << "[setJointCommonOfGroup] group name " << gname << " : size of manipulater is not equal to input. " << i_qsize << " /= " << i->indices.size() << std::endl; return false; } if (i->state == groupInterpolator::created){ double q[m_dof], dq[m_dof]; - interpolators[Q]->get(q, dq, false); + interpolators[type]->get(q, dq, false); std::map::iterator it; for (it=groupInterpolators.begin(); it!=groupInterpolators.end(); it++){ groupInterpolator *gi = it->second; - if (gi) gi->get(q, dq, false); + if (gi) gi->get(g_type, q, dq); } - double x[i->indices.size()], v[i->indices.size()]; - i->extract(x, q); - i->extract(v, dq); - i->inter->go(x,v,interpolators[Q]->deltaT()); + i->set(g_type,q,dq); } - double x[i->indices.size()], v[i->indices.size()]; - i->inter->get(x, v, false); - i->setGoal(i_qRef, i_tm); + i->setGoal(g_type, i_qRef, i_tm); return true; }else{ - std::cerr << "[setJointAnglesOfGroup] group name " << gname << " is not installed" << std::endl; + std::cerr << "[setJointCommonOfGroup] group name " << gname << " is not installed" << std::endl; return false; } } @@ -523,7 +549,7 @@ void seqplay::clearOfGroup(const char *gname, double i_timeLimit) char *s = (char *)gname; while(*s) {*s=toupper(*s);s++;} groupInterpolator *i = groupInterpolators[gname]; if (i){ - i->clear(i_timeLimit); + i->clear(); } } @@ -542,12 +568,9 @@ bool seqplay::playPatternOfGroup(const char *gname, std::vector std::map::iterator it; for (it=groupInterpolators.begin(); it!=groupInterpolators.end(); it++){ groupInterpolator *gi = it->second; - if (gi) gi->get(q, dq, false); + if (gi) gi->get(groupInterpolator::G_Q, q, dq); } - double x[i->indices.size()], v[i->indices.size()]; - i->extract(x, q); - i->extract(v, dq); - i->inter->go(x,v,interpolators[Q]->deltaT()); + i->set(groupInterpolator::G_Q, q, dq); } const double *q=NULL; double t=0; double *v = new double[len]; @@ -582,7 +605,7 @@ bool seqplay::playPatternOfGroup(const char *gname, std::vector for (unsigned int j = 0; j < len; j++) { v[j] = 0.0; } } if (l < tm.size()) t = tm[l]; - i->go(q, v, t); + i->go(groupInterpolator::G_Q, q, v, t); } sync(); delete [] v; @@ -700,6 +723,11 @@ bool seqplay::setJointAnglesSequenceFull(std::vector i_pos, std:: interpolators[OPTIONAL_DATA]->set(optional); interpolators[OPTIONAL_DATA]->clear(); interpolators[OPTIONAL_DATA]->push(optional, dummy_optional, dummy_optional, true); + double vel[m_dof]; + interpolators[DQ]->get(vel, false); + interpolators[DQ]->set(vel); + interpolators[DQ]->clear(); + interpolators[DQ]->push(vel, dummy_dof, dummy_dof, true); const double *q=NULL; for (unsigned int i=0; i i_pos, std:: interpolators[ZMP]->setGoal(i_zmps[i], i_tm[i], false); interpolators[WRENCHES]->setGoal(i_wrenches[i], i_tm[i], false); interpolators[OPTIONAL_DATA]->setGoal(i_optionals[i], i_tm[i], false); + interpolators[DQ]->setGoal(v, i_tm[i], false); do{ double tm = i_tm[i], tm_tmp; interpolators[Q]->interpolate(i_tm[i]); @@ -753,6 +782,7 @@ bool seqplay::setJointAnglesSequenceFull(std::vector i_pos, std:: tm_tmp = tm; interpolators[ZMP]->interpolate(tm_tmp); tm_tmp = tm; interpolators[WRENCHES]->interpolate(tm_tmp); tm_tmp = tm; interpolators[OPTIONAL_DATA]->interpolate(tm_tmp); + tm_tmp = tm; interpolators[DQ]->interpolate(tm_tmp); }while(i_tm[i]>0); sync(); } @@ -760,34 +790,47 @@ bool seqplay::setJointAnglesSequenceFull(std::vector i_pos, std:: } bool seqplay::setJointAnglesSequenceOfGroup(const char *gname, std::vector pos, std::vector tm, const size_t pos_size) +{ + return setJointCommonSequenceOfGroup(Q, groupInterpolator::G_Q, gname, pos, tm, pos_size); +} + +bool seqplay::setJointVelocitiesSequenceOfGroup(const char *gname, std::vector vel, std::vector tm, const size_t vel_size) +{ + return setJointCommonSequenceOfGroup(DQ, groupInterpolator::G_DQ, gname, vel, tm, vel_size); +} + +bool seqplay::setJointTorquesSequenceOfGroup(const char *gname, std::vector torque, std::vector tm, const size_t torque_size) +{ + return setJointCommonSequenceOfGroup(TQ, groupInterpolator::G_TQ, gname, torque, tm, torque_size); +} + +bool seqplay::setJointCommonSequenceOfGroup(unsigned int type, unsigned int g_type, const char *gname, std::vector pos, std::vector tm, const size_t pos_size) { char *s = (char *)gname; while(*s) {*s=toupper(*s);s++;} groupInterpolator *i = groupInterpolators[gname]; if (! i){ - std::cerr << "[setJointAnglesSequenceOfGroup] group name " << gname << " is not installed" << std::endl; + std::cerr << "[setJointCommonSequenceOfGroup] group name " << gname << " is not installed" << std::endl; return false; } if (pos_size != i->indices.size() ) { - std::cerr << "[setJointAnglesSequenceOfGroup] group name " << gname << " : size of manipulater is not equal to input. " << pos_size << " /= " << i->indices.size() << std::endl; + std::cerr << "[setJointCommonSequenceOfGroup] group name " << gname << " : size of manipulater is not equal to input. " << pos_size << " /= " << i->indices.size() << std::endl; return false; } int len = i->indices.size(); // playPatternOfGroup double q[m_dof], dq[m_dof]; - interpolators[Q]->get(q, dq, false); // fill all q,dq data + interpolators[type]->get(q, dq, false); // fill all q,dq data std::map::iterator it; for (it=groupInterpolators.begin(); it!=groupInterpolators.end(); it++){ groupInterpolator *gi = it->second; - if (gi) gi->get(q, dq, false); + if (gi) gi->get(g_type, q, dq); } - // extract currnet limb data double x[len], v[len]; + i->set(g_type, q, dq); + i->clear(g_type); i->extract(x, q); i->extract(v, dq); - // override currnet goal - i->inter->clear(); - i->inter->go(x,v,interpolators[Q]->deltaT()); const double *q_curr=NULL; for (unsigned int j=0; jstate == groupInterpolator::created){ double q[m_dof], dq[m_dof]; - interpolators[Q]->get(q, dq, false); + interpolators[type]->get(q, dq, false); std::map::iterator it; for (it=groupInterpolators.begin(); it!=groupInterpolators.end(); it++){ groupInterpolator *gi = it->second; - if (gi) gi->get(q, dq, false); + if (gi) gi->get(g_type, q, dq); } - double x[i->indices.size()], v[i->indices.size()]; - i->extract(x, q); - i->extract(v, dq); - i->inter->go(x,v,interpolators[Q]->deltaT()); + i->set(g_type, q, dq); } - i->inter->setGoal(pos[j], v, tm[j], false); - do{ - i->inter->interpolate(tm[j]); - }while(tm[j]>0); - i->inter->sync(); - i->state = groupInterpolator::working; + i->go(g_type, pos[j], v, tm[j]); } return true; } @@ -858,19 +893,102 @@ bool seqplay::clearJointAnglesOfGroup(const char *gname) return false; } - int len = i->indices.size(); - double x[len], v[len], a[len]; - i->inter->get(x, v, a, false); - i->inter->set(x, v); - while(i->inter->remain_time() > 0){ - i->inter->pop(); + double x[m_dof], v[m_dof]; + i->get(groupInterpolator::G_Q, x, v); + i->set(groupInterpolator::G_Q, x, v); + i->clear(groupInterpolator::G_Q); + + return true; +} + +bool seqplay::setJointVelocitiesSequence(std::vector vel, std::vector tm) +{ + // setJointVelocitys to override curren tgoal + double x[m_dof], v[m_dof], a[m_dof]; + interpolators[DQ]->get(x, v, a, false); + interpolators[DQ]->set(x, v); + interpolators[DQ]->clear(); + interpolators[DQ]->push(x, v, a, true); + + const double *q=NULL; + for (unsigned int i=0; i= 0 ) { + v[j] = 0.5 * (v0 + v1); + } else { + v[j] = 0; + } + } + } else { + for (int j = 0; j < m_dof; j++) { v[j] = 0.0; } + } + + interpolators[DQ]->setGoal(vel[i], v, tm[i], false); + do{ + interpolators[DQ]->interpolate(tm[i]); + }while(tm[i]>0); + sync(); } - double tm = interpolators[Q]->deltaT(); - i->inter->setGoal(x, v, tm, true);// true: update remian_t - do{ - i->inter->interpolate(tm); - }while(tm>0); - i->inter->sync(); + return true; +} + +bool seqplay::setJointTorquesSequence(std::vector torque, std::vector tm) +{ + // setJointTorques to override curren tgoal + double x[m_dof], v[m_dof], a[m_dof]; + interpolators[TQ]->get(x, v, a, false); + interpolators[TQ]->set(x, v); + interpolators[TQ]->clear(); + interpolators[TQ]->push(x, v, a, true); + const double *q=NULL; + for (unsigned int i=0; i= 0 ) { + v[j] = 0.5 * (v0 + v1); + } else { + v[j] = 0; + } + } + } else { + for (int j = 0; j < m_dof; j++) { v[j] = 0.0; } + } + + interpolators[TQ]->setGoal(torque[i], v, tm[i], false); + do{ + interpolators[TQ]->interpolate(tm[i]); + }while(tm[i]>0); + sync(); + } return true; } diff --git a/rtc/SequencePlayer/seqplay.h b/rtc/SequencePlayer/seqplay.h index cb1f1b0ddf8..31df23c18f6 100644 --- a/rtc/SequencePlayer/seqplay.h +++ b/rtc/SequencePlayer/seqplay.h @@ -32,6 +32,9 @@ class seqplay bool getJointGroup(const char *gname, std::vector& indices); bool removeJointGroup(const char *gname, double time=2.5); bool setJointAnglesOfGroup(const char *gname, const double* i_qRef, const size_t i_qsize, double i_tm=0.0); + bool setJointVelocitiesOfGroup(const char *gname, const double* i_dqRef, const size_t i_dqsize, double i_tm=0.0); + bool setJointTorquesOfGroup(const char *gname, const double* i_tqRef, const size_t i_tqsize, double i_tm=0.0); + bool setJointCommonOfGroup(unsigned int type, unsigned int g_type, const char *gname, const double* i_qRef, const size_t i_qsize, double i_tm=0.0); void clearOfGroup(const char *gname, double i_timeLimit); bool playPatternOfGroup(const char *gname, std::vector pos, std::vector tm, const double *qInit, unsigned int len); @@ -39,22 +42,27 @@ class seqplay // bool setJointAnglesSequence(std::vector pos, std::vector tm); bool setJointAnglesSequenceOfGroup(const char *gname, std::vector pos, std::vector tm, const size_t pos_size); + bool setJointVelocitiesSequenceOfGroup(const char *gname, std::vector vel, std::vector tm, const size_t vel_size); + bool setJointTorquesSequenceOfGroup(const char *gname, std::vector torque, std::vector tm, const size_t torque_size); + bool setJointCommonSequenceOfGroup(unsigned int type, unsigned int g_type, const char *gname, std::vector pos, std::vector tm, const size_t pos_size); bool setJointAnglesSequenceFull(std::vector pos, std::vector vel, std::vector torques, std::vector bpos, std::vector brpy, std::vector bacc, std::vector zmps, std::vector wrenches, std::vector optionals, std::vector tm); bool clearJointAngles(); bool clearJointAnglesOfGroup(const char *gname); // void setJointAngle(unsigned int i_rank, double jv, double tm); void loadPattern(const char *i_basename, double i_tm); + bool setJointVelocitiesSequence(std::vector vel, std::vector tm); + bool setJointTorquesSequence(std::vector torque, std::vector tm); void clear(double i_timeLimit=0); 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); + double *o_basePos, double *o_baseRpy, double *o_tq, double *o_wrenches, double *o_optional_data, double *o_dq); 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, + const double *i_p, const double *i_rpy, const double *i_tq, const double *i_wrenches, const double *i_optional_data, const double *i_dq, double i_time, bool immediate=true); 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, + const double *i_p, const double *i_rpy, const double *i_tq, const double *i_wrenches, const double *i_optional_data, const double *i_dq, const double *ii_q, const double *ii_zmp, const double *ii_acc, - const double *ii_p, const double *ii_rpy, const double *ii_tq, const double *ii_wrenches, const double *ii_optional_data, + const double *ii_p, const double *ii_rpy, const double *ii_tq, const double *ii_wrenches, const double *ii_optional_data, const double *ii_dq, double i_time, bool immediate=true); void sync(); bool setInterpolationMode(interpolator::interpolation_mode i_mode_); @@ -63,86 +71,145 @@ class seqplay public: groupInterpolator(const std::vector& i_indices, double i_dt) : indices(i_indices), state(created){ - inter = new interpolator(i_indices.size(), i_dt); + inters[G_Q] = new interpolator(i_indices.size(), i_dt); + inters[G_TQ] = new interpolator(i_indices.size(), i_dt); + inters[G_DQ] = new interpolator(i_indices.size(), i_dt); + xs.resize(G_NINTERPOLATOR, std::vector(i_indices.size(),0)); + vs.resize(G_NINTERPOLATOR, std::vector(i_indices.size(),0)); } ~groupInterpolator(){ - delete inter; + delete inters[G_Q]; + delete inters[G_TQ]; + delete inters[G_DQ]; } - void get(double *full, double *dfull = NULL, bool popp=true){ - if (state == created) return; + void interpolate(const double* full_q, const double* full_vq, + const double* full_dq, const double* full_vdq, + const double* full_tq, const double* full_vtq){ + if (state == created || state == removed) { + set(G_Q, full_q, full_vq); + set(G_DQ, full_dq, full_vdq); + set(G_TQ, full_tq, full_vtq); + return; + } + double x[indices.size()]; + double v[indices.size()]; if (state == removing){ - double x[indices.size()]; - double v[indices.size()]; for (size_t i=0; isetGoal(x, v, time2remove); - time2remove -= inter->deltaT(); + inters[G_Q]->setGoal(x, v, time2remove); + + for (size_t i=0; isetGoal(x, v, time2remove); + + for (size_t i=0; isetGoal(x, v, time2remove); + + time2remove -= inters[G_Q]->deltaT(); if (time2remove <= 0) state = removed; } - double x[indices.size()], v[indices.size()]; - inter->get(x, v, popp); + inters[G_Q]->get(xs[G_Q].data(), vs[G_Q].data(), true); + inters[G_DQ]->get(xs[G_DQ].data(), vs[G_DQ].data(), true); + inters[G_TQ]->get(xs[G_TQ].data(), vs[G_TQ].data(), true); + } + void get(unsigned int type, double *full, double *dfull = NULL){ + if (state == created || state == removed) return; for (size_t i=0; iset(x,v); + inters[type]->set(x,v); + inters[type]->clear(); } void extract(double *dst, const double *src){ for (size_t i=0; iisEmpty() && state != removing; } - void go(const double *g, double tm){ - inter->go(g, tm); + bool isEmpty() { + if(state == created) return true; + if(state == removing || state == removed) return false; + for(unsigned int i=0; iisEmpty()) return false; + } + return true; + } + void go(unsigned int type, const double *g, double tm){ + if(state == removing || state == removed) return; + inters[type]->go(g, tm); state = working; } - void go(const double *g, const double *v, double tm){ - inter->go(g, v, tm); + void go(unsigned int type, const double *g, const double *v, double tm){ + if(state == removing || state == removed) return; + inters[type]->go(g, v, tm); state = working; } - void setGoal(const double *g, double tm){ - inter->setGoal(g, tm); - inter->sync(); + void setGoal(unsigned int type, const double *g, double tm){ + if(state == removing || state == removed) return; + inters[type]->setGoal(g, tm); + inters[type]->sync(); state = working; } - void setGoal(const double *g, const double *v, double tm){ - inter->setGoal(g, v, tm); - inter->sync(); + void setGoal(unsigned int type, const double *g, const double *v, double tm){ + if(state == removing || state == removed) return; + inters[type]->setGoal(g, v, tm); + inters[type]->sync(); state = working; } void remove(double time){ - state = removing; - time2remove = time; + if(state == created) { + state = removed; + return; + } + if(state == working) { + state = removing; + time2remove = time; + return; + } } - void clear(double i_timeLimit=0) { - tick_t t1 = get_tick(); - while (!isEmpty()){ - if (i_timeLimit > 0 - && tick2sec(get_tick()-t1)>=i_timeLimit) break; - inter->pop_back(); + void clear() { + if(state == removing) return; + for(int i=0; iclear(); + } + } + void clear(unsigned int type) { + if(state == removing) return; + inters[type]->clear(); + } + + bool setInterpolationMode (interpolator::interpolation_mode i_mode_) { + bool ret = true; + for(int i=0; isetInterpolationMode(i_mode_); } + return ret; } - interpolator *inter; + enum {G_Q, G_TQ, G_DQ, G_NINTERPOLATOR}; + interpolator *inters[G_NINTERPOLATOR]; std::vector indices; + std::vector > xs, vs; typedef enum { created, working, removing, removed } gi_state; gi_state state; double time2remove; }; void pop_back(); - enum {Q, ZMP, ACC, P, RPY, TQ, WRENCHES, OPTIONAL_DATA, NINTERPOLATOR}; + enum {Q, ZMP, ACC, P, RPY, TQ, WRENCHES, OPTIONAL_DATA, DQ, NINTERPOLATOR}; interpolator *interpolators[NINTERPOLATOR]; std::map groupInterpolators; int debug_level, m_dof; diff --git a/rtc/StateHolder/StateHolder.cpp b/rtc/StateHolder/StateHolder.cpp index 8af4c5b4302..3c963cf89cf 100644 --- a/rtc/StateHolder/StateHolder.cpp +++ b/rtc/StateHolder/StateHolder.cpp @@ -37,12 +37,14 @@ StateHolder::StateHolder(RTC::Manager* manager) // m_currentQIn("currentQIn", m_currentQ), m_qIn("qIn", m_q), + m_dqIn("dqIn", m_dq), m_tqIn("tqIn", m_tq), m_basePosIn("basePosIn", m_basePos), m_baseRpyIn("baseRpyIn", m_baseRpy), m_zmpIn("zmpIn", m_zmp), m_optionalDataIn("optionalDataIn", m_optionalData), m_qOut("qOut", m_q), + m_dqOut("dqOut", m_dq), m_tqOut("tqOut", m_tq), m_basePosOut("basePosOut", m_basePos), m_baseRpyOut("baseRpyOut", m_baseRpy), @@ -84,6 +86,7 @@ RTC::ReturnCode_t StateHolder::onInitialize() // Set InPort buffers addInPort("currentQIn", m_currentQIn); addInPort("qIn", m_qIn); + addInPort("dqIn", m_dqIn); addInPort("tqIn", m_tqIn); addInPort("basePosIn", m_basePosIn); addInPort("baseRpyIn", m_baseRpyIn); @@ -92,6 +95,7 @@ RTC::ReturnCode_t StateHolder::onInitialize() // Set OutPort buffer addOutPort("qOut", m_qOut); + addOutPort("dqOut", m_dqOut); addOutPort("tqOut", m_tqOut); addOutPort("basePosOut", m_basePosOut); addOutPort("baseRpyOut", m_baseRpyOut); @@ -112,7 +116,7 @@ RTC::ReturnCode_t StateHolder::onInitialize() // - RTC::Properties& prop = getProperties(); + RTC::Properties prop = getProperties(); coil::stringTo(m_dt, prop["dt"].c_str()); std::cout << "StateHolder: dt = " << m_dt << std::endl; RTC::Manager& rtcManager = RTC::Manager::instance(); @@ -238,16 +242,23 @@ RTC::ReturnCode_t StateHolder::onExecute(RTC::UniqueId ec_id) if (m_qIn.isNew()){ m_qIn.read(); } + if (m_dqIn.isNew()){ + m_dqIn.read(); + } if (m_tqIn.isNew()){ m_tqIn.read(); } if (m_requestGoActual || (m_q.data.length() == 0 && m_currentQ.data.length() > 0)){ m_q = m_currentQ; - if (m_q.data.length() != m_tq.data.length()) { - m_tq.data.length(m_q.data.length()); - for(size_t i=0;i 0){ m_qOut.write(); } + if (m_dq.data.length() > 0){ + m_dqOut.write(); + } if (m_tq.data.length() > 0){ m_tqOut.write(); } diff --git a/rtc/StateHolder/StateHolder.h b/rtc/StateHolder/StateHolder.h index d0b4ccca5b8..81c0e105b6b 100644 --- a/rtc/StateHolder/StateHolder.h +++ b/rtc/StateHolder/StateHolder.h @@ -111,6 +111,7 @@ class StateHolder TimedDoubleSeq m_currentQ; InPort m_currentQIn; InPort m_qIn; + InPort m_dqIn; InPort m_tqIn; InPort m_basePosIn; InPort m_baseRpyIn; @@ -127,6 +128,7 @@ class StateHolder // DataOutPort declaration // TimedDoubleSeq m_q; + TimedDoubleSeq m_dq; TimedDoubleSeq m_tq; TimedPoint3D m_basePos; TimedOrientation3D m_baseRpy; @@ -135,6 +137,7 @@ class StateHolder TimedPoint3D m_zmp; std::vector m_wrenches; OutPort m_qOut; + OutPort m_dqOut; OutPort m_tqOut; OutPort m_basePosOut; OutPort m_baseRpyOut;