Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put PRs for multi-contact locomotion together for easy merge #16

Merged
merged 45 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
6a47f24
[WIP] add PostureManager, which update reference posture in PostureTa…
orikuma Sep 19, 2023
1a7eb93
[WIP] use PostureManager in MultiContactController
orikuma Sep 19, 2023
f503af7
Configuration in PostureManager is not mandatory
orikuma Sep 19, 2023
362a85d
Preserve map from joint names to joint angles instead of vector of po…
orikuma Sep 19, 2023
e8d322c
Register logger for PostureManager
orikuma Sep 19, 2023
e19c408
Load nominal posture trajectory from configurations
orikuma Sep 19, 2023
63493b2
Reset PostureManager in InitialState
orikuma Sep 19, 2023
c3a7817
Clear nominalPostureList_ in PostureManager::reset
orikuma Sep 20, 2023
ca55e66
Show joint name for nominalPosture in mc_rtc log
orikuma Sep 20, 2023
0283198
Apply .clang-format-fix.sh
orikuma Sep 25, 2023
b0d093c
Overwrite nominalCentraoidalPose in InitialState if it is specified i…
orikuma Oct 18, 2023
0ffb5bd
Set collision pairs from collisionConfigList in InitState
orikuma Oct 19, 2023
a734c7b
Check limb swing motion has been finished at the end of ConfigMotion …
orikuma Oct 19, 2023
89782e6
Set initial posture by nominalPosture in MCC::Initial
orikuma Oct 19, 2023
d9de077
Do not reset shared_ptrs to prevent SEGV when changing controllers
orikuma Oct 19, 2023
4746378
Do not reset shared_ptr for PostureManger to prevent SEGV when changi…
orikuma Oct 19, 2023
20c4029
Refactor the check for finishing limb motion
orikuma Oct 23, 2023
fb7c8ef
Fix clang-format
orikuma Oct 27, 2023
c258747
Initialize base pose by basePose config in MCC::Initial
orikuma Oct 24, 2023
99f1e9e
Preserve last base pose in datastore as MCC::LastBasePose to use it a…
orikuma Oct 24, 2023
8a74a58
Remove MCC::LastBasePose to avoid unexpected reuse
orikuma Oct 24, 2023
489fc75
Initialize base pose in the reset function
gergondet Oct 25, 2023
404a5a3
Remove posW initialization in InitialState::run
orikuma Oct 25, 2023
60f7bcb
Manage saveLastBasePose in MultiContactController, not in MCC::Config…
orikuma Oct 25, 2023
b4fd077
Put basePose from yaml config in datastore to use it only once
orikuma Oct 26, 2023
12d625d
Reset the robot posture task on reset
gergondet Oct 31, 2023
099cfec
Update vertices of contact updated by touchdown
orikuma Nov 2, 2023
a088c2f
Update global vertices just after touchDown is detected when enableWr…
orikuma Nov 5, 2023
8da894d
Global vertices can updated when touchDown is detected regardless of …
orikuma Nov 5, 2023
44f461e
Apply clang-format-fix
orikuma Nov 5, 2023
8cf2f1a
Apply clang-format-fix
orikuma Nov 5, 2023
4dd48d9
Add option to wait for finishing nominal centroidal trajectory to exi…
orikuma Mar 27, 2024
6cb9713
Add option to wait for finishing nominal postures to exit ConfigMotio…
orikuma Mar 27, 2024
779eec7
Add InterruptState to stop multi-contact motion until an user allows …
orikuma Apr 3, 2024
490a938
Do not disable enableManagerUpdate_ to keep CoM feedback control whil…
orikuma Apr 3, 2024
3e96498
Fix PR comment in https://github.com/isri-aist/MultiContactController…
orikuma Apr 11, 2024
21e4efa
Add GUI entry to show number of joints managed by PostureManager
orikuma Apr 11, 2024
62bcaba
Fix PR comment in https://github.com/isri-aist/MultiContactController…
orikuma Apr 12, 2024
97b00df
Fix PR comment in https://github.com/isri-aist/MultiContactController…
orikuma Apr 12, 2024
da202a4
Fix PR comment in https://github.com/isri-aist/MultiContactController…
orikuma Apr 12, 2024
283a134
Update comment to excluding Empty command for updateGlobalVertices
orikuma Apr 12, 2024
f401697
Fix PR comment in https://github.com/isri-aist/MultiContactController…
orikuma Apr 12, 2024
06f4dbb
apply clang-format-fix
orikuma Apr 12, 2024
4a89827
Merge branch 'master' into demo
orikuma Apr 12, 2024
36a13da
Update comments.
mmurooka Apr 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions include/MultiContactController/CentroidalManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,20 @@ class CentroidalManager
*/
CentroidalManager(MultiContactController * ctlPtr, const mc_rtc::Configuration & mcRtcConfig = {});

/** \brief Reset.
\param constraintSetConfig mc_rtc configuration that has nominalCentroidalPose

This method should be called once when controller is reset.
The validity of nominalCentroidalPoseConfig should be checked before calling this function.

An example of \p nominalCentroidalPoseConfig is as follows.
@code
nominalCentroidalPose:
translation: [0.0, 0.0, 0.966]
@endcode
*/
virtual void reset(const mc_rtc::Configuration & nominalCentroidalPoseConfig);

/** \brief Reset.

This method should be called once when controller is reset.
Expand Down Expand Up @@ -229,6 +243,11 @@ class CentroidalManager
/** \brief Set anchor frame. */
void setAnchorFrame();

/** \brief Check whether reference CoM trajectory is completed at given time
\param t time
*/
bool isFinished(const double t) const;

protected:
/** \brief Const accessor to the controller. */
inline const MultiContactController & ctl() const
Expand Down
3 changes: 3 additions & 0 deletions include/MultiContactController/LimbManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,5 +258,8 @@ class LimbManager

//! Whether to require updating impedance gains for limb tasks
bool requireImpGainUpdate_ = true;

//! Whether to require updating target pose for contact constraint
bool requireTouchDownPoseUpdate_ = false;
};
} // namespace MCC
3 changes: 3 additions & 0 deletions include/MultiContactController/LimbManagerSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ class LimbManagerSet : public std::unordered_map<Limb, std::shared_ptr<LimbManag
/** \brief Get whether future contact command is stacked. */
bool contactCommandStacked() const;

/** \brief Get whether any limbs are executing swing motion. */
bool isExecutingLimbSwing() const;

/** \brief Get limbs of the specified group.
\param group limb group
*/
Expand Down
21 changes: 20 additions & 1 deletion include/MultiContactController/MultiContactController.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,26 @@ namespace MCC
{
class LimbManagerSet;
class CentroidalManager;
class PostureManager;

/** \brief Humanoid multi-contact motion controller. */
struct MultiContactController : public mc_control::fsm::Controller
{
public:
/** \brief Constructor. */
/** \brief Constructor.

If the pose is stored in the "basePose" key of the controller configuration, the pose will be registered in the
"MCC::ResetBasePose" key of the datastore and applied to the baselink poses of the control and real robots in the
reset function.
*/
MultiContactController(mc_rbdyn::RobotModulePtr rm, double dt, const mc_rtc::Configuration & _config);

/** \brief Reset a controller.

This method is called when starting the controller.

If the pose is registered in the "MCC::ResetBasePose" key of the datastore, the pose will be applied to the
baselink poses of the control and real robots in the reset function.
*/
void reset(const mc_control::ControllerResetData & resetData) override;

Expand All @@ -43,6 +52,10 @@ struct MultiContactController : public mc_control::fsm::Controller
/** \brief Stop a controller.

This method is called when stopping the controller.

If the "saveLastBasePose" key in the controller configuration is true, the baselink pose of the current control
robot is registered in the "MCC::ResetBasePose" key of the datastore. This is intended to be used in subsequent
controller initializations.
*/
void stop() override;

Expand Down Expand Up @@ -86,9 +99,15 @@ struct MultiContactController : public mc_control::fsm::Controller
//! Centroidal manager
std::shared_ptr<CentroidalManager> centroidalManager_;

//! Posture manager
std::shared_ptr<PostureManager> postureManager_;

//! Whether to enable manager update
bool enableManagerUpdate_ = false;

//! Whether to save last base pose when stopping this controller.
bool saveLastBasePose_ = false;

protected:
//! Controller name
std::string name_ = "MCC";
Expand Down
122 changes: 122 additions & 0 deletions include/MultiContactController/PostureManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#pragma once

#include <mc_rtc/gui/StateBuilder.h>
#include <mc_rtc/log/Logger.h>
#include <mc_tasks/PostureTask.h>

namespace mc_rbdyn
{
class Robot;
}

namespace MCC
{
class MultiContactController;

/** \brief Posture manager.

Posture manager calculates the target of robot posture.
*/
class PostureManager
{
public:
typedef std::map<std::string, std::vector<double>> PostureMap;

/** \brief Configuration. */
struct Configuration
{
//! Name
std::string name = "PostureManager";

/** \brief Load mc_rtc configuration. */
virtual void load(const mc_rtc::Configuration & mcRtcConfig);
};

public:
/** \brief Constructor.
\param ctlPtr pointer to controller
\param mcRtcConfig mc_rtc configuration
*/
PostureManager(MultiContactController * ctlPtr, const mc_rtc::Configuration & mcRtcConfig = {});

/** \brief Reset.
\param initialPosture map of joint names and angles for the initial posture

This method should be called once when controller is reset.
*/
virtual void reset(const PostureManager::PostureMap & initialPosture = {});

/** \brief Update.

This method should be called once every control cycle.
*/
virtual void update();

/** \brief Stop.

This method should be called once when stopping the controller.
*/
virtual void stop();

/** \brief Add entries to the GUI. */
virtual void addToGUI(mc_rtc::gui::StateBuilder & gui);

/** \brief Remove entries from the GUI. */
virtual void removeFromGUI(mc_rtc::gui::StateBuilder & gui);

/** \brief Add entries to the logger. */
virtual void addToLogger(mc_rtc::Logger & logger);

/** \brief Remove entries from the logger. */
virtual void removeFromLogger(mc_rtc::Logger & logger);

/** \brief Append a nominal postures of the robot
\param t time
\param PostureMap map from joint names to joint angle [rad]
\return whether nominalCentroidalPose is appended
*/
virtual bool appendNominalPosture(double t, const PostureMap & nominalPosture);

/** \brief Get nominal posture.
\param t time
*/
virtual PostureMap getNominalPosture(double t) const;

/** \brief Check whether reference postures are completed at given time
\param t time
*/
virtual bool isFinished(double t) const;

protected:
/** \brief Const accessor to the controller. */
inline const MultiContactController & ctl() const
{
return *ctlPtr_;
}

/** \brief Accessor to the controller. */
inline MultiContactController & ctl()
{
return *ctlPtr_;
}

/** \brief Const accessor to the configuration. */
inline virtual const Configuration & config() const
{
return config_;
}

protected:
//! Configuration
Configuration config_;

//! Pointer to controller
MultiContactController * ctlPtr_ = nullptr;

//! Pointer to posture task in controller
std::shared_ptr<mc_tasks::PostureTask> postureTask_;

//! Nominal posture list
std::map<double, PostureMap> nominalPostureList_;
};
} // namespace MCC
9 changes: 9 additions & 0 deletions include/MultiContactController/states/ConfigMotionState.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,14 @@ struct ConfigMotionState : State

//! Task configuration list
std::multimap<double, mc_rtc::Configuration> taskConfigList_;

//! Option to select whether this state should wait for finishing swing motion or not
bool exitWhenLimbSwingFinished_ = false;

//! Option to select whether this state should wait for finishing reference CoM trajectory or not
bool exitWhenCentroidalManagerFinished_ = false;

//! Option to select whether this state should wait for finishing reference postures or not
bool exitWhenPostureManagerFinished_ = false;
};
} // namespace MCC
31 changes: 31 additions & 0 deletions include/MultiContactController/states/InterruptState.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include <MultiContactController/State.h>

namespace MCC
{
/** \brief FSM state to initialize. */
struct InterruptState : State
{
public:
/** \brief Start. */
void start(mc_control::fsm::Controller & ctl) override;

/** \brief Run. */
bool run(mc_control::fsm::Controller & ctl) override;

/** \brief Teardown. */
void teardown(mc_control::fsm::Controller & ctl) override;

protected:
/** \brief Check whether state is completed. */
bool complete() const;

protected:
//! Phase
int phase_ = 0;

//! BaseTime for automatic start
double baseTime_ = 0.0;
};
} // namespace MCC
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ add_library(${CONTROLLER_NAME} SHARED
LimbManager.cpp
LimbManagerSet.cpp
CentroidalManager.cpp
PostureManager.cpp
swing/SwingTrajCubicSplineSimple.cpp
centroidal/CentroidalManagerDDP.cpp
centroidal/CentroidalManagerPC.cpp
Expand Down
15 changes: 15 additions & 0 deletions src/CentroidalManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ CentroidalManager::CentroidalManager(MultiContactController * ctlPtr, const mc_r
{
}

void CentroidalManager::reset(const mc_rtc::Configuration & nominalCentroidalPoseConfig)
{
config().nominalCentroidalPose = static_cast<sva::PTransformd>(nominalCentroidalPoseConfig);
reset();
}

void CentroidalManager::reset()
{
refData_.reset();
Expand Down Expand Up @@ -426,6 +432,15 @@ void CentroidalManager::setAnchorFrame()
ctl().datastore().make_call(anchorName, [this](const mc_rbdyn::Robot & robot) { return calcAnchorFrame(robot); });
}

bool CentroidalManager::isFinished(const double t) const
{
if(nominalCentroidalPoseList_.empty())
{
return true;
}
return t > nominalCentroidalPoseList_.rbegin()->first;
}

CentroidalManager::RefData CentroidalManager::calcRefData(double t) const
{
RefData refData;
Expand Down
18 changes: 18 additions & 0 deletions src/LimbManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ void LimbManager::reset(const mc_rtc::Configuration & _constraintConfig)
impGainType_ = "Uninitialized";

requireImpGainUpdate_ = false;

requireTouchDownPoseUpdate_ = false;
}

contactCommandList_.clear();
Expand Down Expand Up @@ -144,6 +146,7 @@ void LimbManager::update()
{
targetPose_ = swingTraj_->endPose_;
}

targetVel_ = sva::MotionVecd::Zero();
targetAccel_ = sva::MotionVecd::Zero();

Expand Down Expand Up @@ -244,6 +247,11 @@ void LimbManager::update()
{
touchDown_ = true;

if(config_.keepPoseForTouchDownLimb)
{
requireTouchDownPoseUpdate_ = true;
}

if(config_.stopSwingTrajForTouchDownLimb)
{
swingTraj_->touchDown(ctl().t());
Expand Down Expand Up @@ -274,6 +282,16 @@ void LimbManager::update()

// Update currentContactCommand_ (this should be after setting swingTraj_)
currentContactCommand_ = getContactCommand(ctl().t());
if(currentContactCommand_ && currentContactCommand_->constraint->type() != "Empty" && requireTouchDownPoseUpdate_)
{
// \todo In order to correctly update global vertices when transitioning from an EmptyContact with no vertices for
// wrench distribution to, for example, a GraspContact with vertices for wrench distribution, the condition here is
// skipped for EmptyContact and requireTouchDownPoseUpdate_ is retained. The current implementation works well for
// contact transitions where the hand grasps the environment (i.e., EmptyContact -> GraspContact), but it does not
// work well to perform other contact transitions in the future (e.g., SurfaceContact -> GraspContact).
currentContactCommand_->constraint->updateGlobalVertices(targetPose_);
requireTouchDownPoseUpdate_ = false;
}

// Update phase_
if(currentSwingCommand_)
Expand Down
12 changes: 12 additions & 0 deletions src/LimbManagerSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@ bool LimbManagerSet::contactCommandStacked() const
return false;
}

bool LimbManagerSet::isExecutingLimbSwing() const
{
for(const auto & limbManagerKV : *this)
{
if(limbManagerKV.second->currentSwingCommand_ != nullptr)
{
return true;
}
}
return false;
}

void LimbManagerSet::addToGUI(mc_rtc::gui::StateBuilder & gui)
{
for(const auto & limbManagerKV : *this)
Expand Down
Loading
Loading