-
Notifications
You must be signed in to change notification settings - Fork 9
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
Add interrupt state #14
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#pragma once | ||
|
||
#include <TrajColl/CubicInterpolator.h> | ||
|
||
#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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include <mc_rtc/gui/Button.h> | ||
#include <MultiContactController/MultiContactController.h> | ||
#include <MultiContactController/states/InterruptState.h> | ||
|
||
using namespace MCC; | ||
|
||
void InterruptState::start(mc_control::fsm::Controller & _ctl) | ||
{ | ||
State::start(_ctl); | ||
|
||
phase_ = 0; | ||
|
||
baseTime_ = 0.0; | ||
if(config_.has("configs") && config_("configs").has("baseTime")) | ||
{ | ||
if(config_("configs")("baseTime") == "Relative") | ||
{ | ||
baseTime_ = ctl().t(); | ||
} | ||
else | ||
{ | ||
baseTime_ = static_cast<double>(config_("configs")("baseTime")); | ||
} | ||
} | ||
|
||
// Setup GUI | ||
ctl().gui()->addElement({ctl().name()}, mc_rtc::gui::Button("Start", [this]() { phase_ = 1; })); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think "Resume" is a good name for the button in the Interrupt state. (and we can distinguishes the buttons between Initial state and Interrupt state) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in f401697 |
||
|
||
output("OK"); | ||
} | ||
|
||
bool InterruptState::run(mc_control::fsm::Controller &) | ||
{ | ||
if(phase_ == 0) | ||
{ | ||
// Auto start | ||
if(config_.has("configs") && config_("configs").has("autoStartTime") | ||
&& ctl().t() - baseTime_ > static_cast<double>(config_("configs")("autoStartTime"))) | ||
{ | ||
phase_ = 1; | ||
} | ||
} | ||
if(phase_ == 1) | ||
{ | ||
phase_ = 2; | ||
|
||
// Clean up GUI | ||
ctl().gui()->removeElement({ctl().name()}, "Start"); | ||
|
||
// Start updating references | ||
// NOTE: enableManagerUpdate_ is not explicitly disabled by InterruptState | ||
// for feedback control to maintain balance while stopping in CentroidalManager | ||
ctl().enableManagerUpdate_ = true; | ||
} | ||
|
||
return complete(); | ||
} | ||
|
||
void InterruptState::teardown(mc_control::fsm::Controller &) {} | ||
|
||
bool InterruptState::complete() const | ||
{ | ||
return phase_ == 2; | ||
} | ||
|
||
EXPORT_SINGLE_STATE("MCC::Interrupt", InterruptState) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in f401697