Skip to content

Commit

Permalink
Allow to set waypoint in walkToRelativePose.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmurooka committed Nov 1, 2023
1 parent aa11647 commit 4ba9f7e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
5 changes: 4 additions & 1 deletion include/BaselineWalkingController/FootManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,12 @@ class FootManager
/** \brief Send footstep sequence to walk to the relative target pose.
\param targetTrans relative target pose of foot midpose (x [m], y [m], theta [rad])
\param lastFootstepNum number of last footstep
\param waypointTransList waypoint pose list of foot midpose relative to current pose (x [m], y [m], theta [rad])
\return whether footstep is successfully sent
*/
bool walkToRelativePose(const Eigen::Vector3d & targetTrans, int lastFootstepNum = 0);
bool walkToRelativePose(const Eigen::Vector3d & targetTrans,
int lastFootstepNum = 0,
const std::vector<Eigen::Vector3d> & waypointTransList = {});

/** \brief Start velocity mode.
\return whether it is successfully started
Expand Down
28 changes: 18 additions & 10 deletions src/FootManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,9 @@ Eigen::Vector3d FootManager::calcZmpWithOffset(const std::unordered_map<Foot, sv
}
}

bool FootManager::walkToRelativePose(const Eigen::Vector3d & targetTrans, int lastFootstepNum)
bool FootManager::walkToRelativePose(const Eigen::Vector3d & targetTrans,
int lastFootstepNum,
const std::vector<Eigen::Vector3d> & waypointTransList)
{
if(footstepQueue_.size() > 0)
{
Expand All @@ -608,22 +610,28 @@ bool FootManager::walkToRelativePose(const Eigen::Vector3d & targetTrans, int la
// transformation in the world frame.
const sva::PTransformd & initialFootMidpose =
projGround(sva::interpolate(targetFootPoses_.at(Foot::Left), targetFootPoses_.at(Foot::Right), 0.5));
const sva::PTransformd & goalFootMidpose = convertTo3d(targetTrans) * initialFootMidpose;

Foot foot = targetTrans.y() >= 0 ? Foot::Left : Foot::Right;
Foot foot = (waypointTransList.empty() ? targetTrans.y() : waypointTransList[0].y()) >= 0 ? Foot::Left : Foot::Right;
sva::PTransformd footMidpose = initialFootMidpose;
double startTime = ctl().t() + 1.0;

while(convertTo2d(goalFootMidpose * footMidpose.inv()).norm() > 1e-6)
for(size_t i = 0; i < waypointTransList.size() + 1; i++)
{
Eigen::Vector3d deltaTrans = convertTo2d(goalFootMidpose * footMidpose.inv());
footMidpose = convertTo3d(clampDeltaTrans(deltaTrans, foot)) * footMidpose;
const Eigen::Vector3d & goalTrans = (i == waypointTransList.size() ? targetTrans : waypointTransList[i]);
const sva::PTransformd & goalFootMidpose = convertTo3d(goalTrans) * initialFootMidpose;
double thre = (i == waypointTransList.size() ? 1e-6 : 1e-2);

const auto & footstep = makeFootstep(foot, footMidpose, startTime);
appendFootstep(footstep);
while(convertTo2d(goalFootMidpose * footMidpose.inv()).norm() > thre)
{
Eigen::Vector3d deltaTrans = convertTo2d(goalFootMidpose * footMidpose.inv());
footMidpose = convertTo3d(clampDeltaTrans(deltaTrans, foot)) * footMidpose;

foot = opposite(foot);
startTime = footstep.transitEndTime;
const auto & footstep = makeFootstep(foot, footMidpose, startTime);
appendFootstep(footstep);

foot = opposite(foot);
startTime = footstep.transitEndTime;
}
}

for(int i = 0; i < lastFootstepNum + 1; i++)
Expand Down
16 changes: 16 additions & 0 deletions src/states/ConfigWalkState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ void ConfigWalkState::start(mc_control::fsm::Controller & _ctl)
ctl().footManager_->setRelativeVel(config_("configs")("velocityMode")("velocity"));
velModeEndTime_ = ctl().t() + static_cast<double>(config_("configs")("velocityMode")("duration"));
}
else if(config_.has("configs") && config_("configs").has("footMidpose"))
{
auto convertDegToRad = [](const Eigen::Vector3d & trans) -> Eigen::Vector3d {
return Eigen::Vector3d(trans.x(), trans.y(), mc_rtc::constants::toRad(trans.z()));
};
Eigen::Vector3d targetTrans = convertDegToRad(config_("configs")("footMidpose")("target"));
std::vector<Eigen::Vector3d> waypointTransList = {};
if(config_("configs")("footMidpose").has("waypointList"))
{
for(const Eigen::Vector3d & waypointTrans : config_("configs")("footMidpose")("waypointList"))
{
waypointTransList.push_back(convertDegToRad(waypointTrans));
}
}
ctl().footManager_->walkToRelativePose(targetTrans, 0, waypointTransList);
}

// Set reference CoM Z position
if(config_.has("configs") && config_("configs").has("refComZList"))
Expand Down

0 comments on commit 4ba9f7e

Please sign in to comment.