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

Overload task constructors to hide targets and poses in GUI #457

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 11 additions & 2 deletions include/mc_tasks/AdmittanceTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ struct MC_TASKS_DLLAPI AdmittanceTask : TransformTask
* \throws If the frame does not have a force sensor attached
*
*/
AdmittanceTask(const mc_rbdyn::RobotFrame & frame, double stiffness = 5.0, double weight = 1000.0);
AdmittanceTask(const mc_rbdyn::RobotFrame & frame,
double stiffness = 5.0,
double weight = 1000.0,
bool showTarget = true,
bool showPose = true);

/*! \brief Initialize a new admittance task.
*
Expand All @@ -74,7 +78,9 @@ struct MC_TASKS_DLLAPI AdmittanceTask : TransformTask
const mc_rbdyn::Robots & robots,
unsigned robotIndex,
double stiffness = 5.0,
double weight = 1000.0);
double weight = 1000.0,
bool showTarget = true,
bool showPose = true);

/*! \brief Reset the task
*
Expand Down Expand Up @@ -205,6 +211,9 @@ struct MC_TASKS_DLLAPI AdmittanceTask : TransformTask
void addToGUI(mc_rtc::gui::StateBuilder & gui) override;
void addToLogger(mc_rtc::Logger & logger) override;

bool showTarget_ = true;
bool showPose_ = true;

/** Transform's refVelB() becomes internal to the task. */
using TransformTask::refVelB;

Expand Down
16 changes: 14 additions & 2 deletions include/mc_tasks/ImpedanceTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ struct MC_TASKS_DLLAPI ImpedanceTask : TransformTask
const mc_rbdyn::Robots & robots,
unsigned robotIndex,
double stiffness = 5.0,
double weight = 1000.0);
double weight = 1000.0,
bool showTarget = true,
bool showPose = true,
bool showCompliance = true);

/** \brief Constructor
*
Expand All @@ -85,7 +88,12 @@ struct MC_TASKS_DLLAPI ImpedanceTask : TransformTask
*
* \throws If the frame does not have a force sensor attached to it
*/
ImpedanceTask(const mc_rbdyn::RobotFrame & frame, double stiffness = 5.0, double weight = 1000.0);
ImpedanceTask(const mc_rbdyn::RobotFrame & frame,
double stiffness = 5.0,
double weight = 1000.0,
bool showTarget = true,
bool showPose = true,
bool showCompliance = true);

/*! \brief Reset the task
*
Expand Down Expand Up @@ -183,6 +191,10 @@ struct MC_TASKS_DLLAPI ImpedanceTask : TransformTask
protected:
ImpedanceGains gains_ = ImpedanceGains::Default();

bool showTarget_ = true;
bool showPose_ = true;
bool showCompliance_ = true;

/** Relative pose, velocity, and acceleration from target frame to compliance frame represented in the world frame.
* To store these values across control cycles, represent them in a constant world frame instead of the time-varying
* surface frame.
Expand Down
13 changes: 11 additions & 2 deletions include/mc_tasks/TransformTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ struct MC_TASKS_DLLAPI TransformTask : public TrajectoryTaskGeneric
*
* \param weight Task weight
*/
TransformTask(const mc_rbdyn::RobotFrame & frame, double stiffness = 2.0, double weight = 500.0);
TransformTask(const mc_rbdyn::RobotFrame & frame,
double stiffness = 2.0,
double weight = 500.0,
bool showTarget = true,
bool showPose = true);

/*! \brief Constructor
*
Expand All @@ -44,7 +48,9 @@ struct MC_TASKS_DLLAPI TransformTask : public TrajectoryTaskGeneric
const mc_rbdyn::Robots & robots,
unsigned int robotIndex,
double stiffness = 2.0,
double weight = 500);
double weight = 500,
bool showTarget = true,
bool showPose = true);

/*! \brief Reset the task
*
Expand Down Expand Up @@ -209,6 +215,9 @@ struct MC_TASKS_DLLAPI TransformTask : public TrajectoryTaskGeneric
/* Don't use parent's refVel() as the velocity frame (spatial or body) is
* ambiguous. */
using TrajectoryTaskGeneric::refVel;

bool showTarget_ = true;
bool showPose_ = true;
};

} // namespace mc_tasks
57 changes: 50 additions & 7 deletions src/mc_tasks/AdmittanceTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <mc_rtc/gui/ArrayInput.h>
#include <mc_rtc/gui/ArrayLabel.h>
#include <mc_rtc/gui/Checkbox.h>
#include <mc_rtc/gui/NumberInput.h>
#include <mc_rtc/gui/Transform.h>

Expand All @@ -28,12 +29,18 @@ AdmittanceTask::AdmittanceTask(const std::string & surfaceName,
const mc_rbdyn::Robots & robots,
unsigned int robotIndex,
double stiffness,
double weight)
: AdmittanceTask(robots.robot(robotIndex).frame(surfaceName), stiffness, weight)
double weight,
bool showTarget,
bool showPose)
: AdmittanceTask(robots.robot(robotIndex).frame(surfaceName), stiffness, weight, showTarget, showPose)
{
}

AdmittanceTask::AdmittanceTask(const mc_rbdyn::RobotFrame & frame, double stiffness, double weight)
AdmittanceTask::AdmittanceTask(const mc_rbdyn::RobotFrame & frame,
double stiffness,
double weight,
bool showTarget,
bool showPose)
: TransformTask(frame, stiffness, weight)
{
if(!frame.hasForceSensor())
Expand All @@ -43,6 +50,8 @@ AdmittanceTask::AdmittanceTask(const mc_rbdyn::RobotFrame & frame, double stiffn
}
name_ = "admittance_" + frame.robot().name() + "_" + frame.name();
reset();
showTarget_ = showTarget;
showPose_ = showPose;
}

void AdmittanceTask::update(mc_solver::QPSolver &)
Expand Down Expand Up @@ -115,12 +124,46 @@ void AdmittanceTask::addToLogger(mc_rtc::Logger & logger)

void AdmittanceTask::addToGUI(mc_rtc::gui::StateBuilder & gui)
{
auto showTarget = [this, &gui]()
{
if(showTarget_)
{
gui.addElement({"Tasks", name_}, mc_rtc::gui::Transform(
"targetPose", [this]() { return this->targetPose(); },
[this](const sva::PTransformd & pos) { this->targetPose(pos); }));
}
else { gui.removeElement({"Tasks", name_}, "targetPose"); }
};

auto showPose = [this, &gui]()
{
if(showPose_)
{
gui.addElement({"Tasks", name_}, mc_rtc::gui::Transform("pose", [this]() { return this->surfacePose(); }));
}
else { gui.removeElement({"Tasks", name_}, "pose"); }
};

gui.addElement({"Tasks", name_},
mc_rtc::gui::Checkbox(
"Show target frame", [this]() { return showTarget_; },
[this, showTarget]()
{
showTarget_ = !showTarget_;
showTarget();
}),
mc_rtc::gui::Checkbox(
"Show pose frame", [this]() { return showPose_; },
[this, showPose]()
{
showPose_ = !showPose_;
showPose();
}));

showPose();
showTarget();
gui.addElement(
{"Tasks", name_},
mc_rtc::gui::Transform(
"pos_target", [this]() { return this->targetPose(); },
[this](const sva::PTransformd & pos) { this->targetPose(pos); }),
mc_rtc::gui::Transform("pos", [this]() { return frame_->position(); }),
mc_rtc::gui::ArrayInput(
"admittance", {"cx", "cy", "cz", "fx", "fy", "fz"}, [this]() { return this->admittance().vector(); },
[this](const Eigen::Vector6d & a) { this->admittance(a); }),
Expand Down
80 changes: 71 additions & 9 deletions src/mc_tasks/ImpedanceTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,20 @@ ImpedanceTask::ImpedanceTask(const std::string & surfaceName,
const mc_rbdyn::Robots & robots,
unsigned int robotIndex,
double stiffness,
double weight)
: ImpedanceTask(robots.robot(robotIndex).frame(surfaceName), stiffness, weight)
double weight,
bool showTarget,
bool showPose,
bool showCompliance)
: ImpedanceTask(robots.robot(robotIndex).frame(surfaceName), stiffness, weight, showTarget, showPose, showCompliance)
{
}

ImpedanceTask::ImpedanceTask(const mc_rbdyn::RobotFrame & frame, double stiffness, double weight)
ImpedanceTask::ImpedanceTask(const mc_rbdyn::RobotFrame & frame,
double stiffness,
double weight,
bool showTarget,
bool showPose,
bool showCompliance)
: TransformTask(frame, stiffness, weight), lowPass_(0.005, cutoffPeriod_)
{
const auto & robot = frame.robot();
Expand All @@ -40,6 +48,9 @@ ImpedanceTask::ImpedanceTask(const mc_rbdyn::RobotFrame & frame, double stiffnes
{
mc_rtc::log::error_and_throw("[{}] Frame {} does not have a force sensor attached", name_, frame.name());
}
showTarget_ = showTarget;
showPose_ = showPose;
showCompliance_ = showCompliance;
}

void ImpedanceTask::update(mc_solver::QPSolver & solver)
Expand Down Expand Up @@ -227,13 +238,64 @@ void ImpedanceTask::addToGUI(mc_rtc::gui::StateBuilder & gui)
// Don't add TransformTask because the target of TransformTask should not be set by user
TrajectoryTaskGeneric::addToGUI(gui);

auto showTarget = [this, &gui]()
{
if(showTarget_)
{
gui.addElement({"Tasks", name_},
mc_rtc::gui::Transform(
"targetPose", [this]() -> const sva::PTransformd & { return this->targetPose(); },
[this](const sva::PTransformd & pos) { this->targetPose(pos); }));
}
else { gui.removeElement({"Tasks", name_}, "targetPose"); }
};

auto showCompliance = [this, &gui]()
{
if(showCompliance_)
{
gui.addElement({"Tasks", name_},
mc_rtc::gui::Transform("compliancePose", [this]() { return this->compliancePose(); }));
}
else { gui.removeElement({"Tasks", name_}, "compliancePose"); }
};

auto showPose = [this, &gui]()
{
if(showPose_)
{
gui.addElement({"Tasks", name_}, mc_rtc::gui::Transform("pose", [this]() { return this->surfacePose(); }));
}
else { gui.removeElement({"Tasks", name_}, "pose"); }
};

gui.addElement({"Tasks", name_},
mc_rtc::gui::Checkbox(
"Show target frame", [this]() { return showTarget_; },
[this, showTarget]()
{
showTarget_ = !showTarget_;
showTarget();
}),
mc_rtc::gui::Checkbox(
"Show pose frame", [this]() { return showPose_; },
[this, showPose]()
{
showPose_ = !showPose_;
showPose();
}),
mc_rtc::gui::Checkbox(
"Show compliance frame", [this]() { return showCompliance_; },
[this, showCompliance]()
{
showCompliance_ = !showCompliance_;
showCompliance();
}));

showPose();
showTarget();
showCompliance();
gui.addElement({"Tasks", name_},
// pose
mc_rtc::gui::Transform(
"targetPose", [this]() -> const sva::PTransformd & { return this->targetPose(); },
[this](const sva::PTransformd & pos) { this->targetPose(pos); }),
mc_rtc::gui::Transform("compliancePose", [this]() { return this->compliancePose(); }),
mc_rtc::gui::Transform("pose", [this]() { return this->surfacePose(); }),
// wrench
mc_rtc::gui::ArrayInput(
"targetWrench", {"cx", "cy", "cz", "fx", "fy", "fz"},
Expand Down
55 changes: 48 additions & 7 deletions src/mc_tasks/TransformTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <mc_rbdyn/hat.h>
#include <mc_rtc/ConfigurationHelpers.h>
#include <mc_rtc/deprecated.h>
#include <mc_rtc/gui/Checkbox.h>
#include <mc_rtc/gui/Transform.h>

namespace mc_tasks
Expand All @@ -23,7 +24,11 @@ namespace mc_tasks
static inline mc_rtc::void_ptr_caster<tasks::qp::SurfaceTransformTask> tasks_error{};
static inline mc_rtc::void_ptr_caster<mc_tvm::TransformFunction> tvm_error{};

TransformTask::TransformTask(const mc_rbdyn::RobotFrame & frame, double stiffness, double weight)
TransformTask::TransformTask(const mc_rbdyn::RobotFrame & frame,
double stiffness,
double weight,
bool showTarget,
bool showPose)
: TrajectoryTaskGeneric(frame.robot().robots(), frame.robot().robotIndex(), stiffness, weight), frame_(frame)
{
switch(backend_)
Expand All @@ -41,14 +46,18 @@ TransformTask::TransformTask(const mc_rbdyn::RobotFrame & frame, double stiffnes

type_ = "transform";
name_ = "transform_" + frame.robot().name() + "_" + frame.name();
showTarget_ = showTarget;
showPose_ = showPose;
}

TransformTask::TransformTask(const std::string & surfaceName,
const mc_rbdyn::Robots & robots,
unsigned int robotIndex,
double stiffness,
double weight)
: TransformTask(robots.robot(robotIndex).frame(surfaceName), stiffness, weight)
double weight,
bool showTarget,
bool showPose)
: TransformTask(robots.robot(robotIndex).frame(surfaceName), stiffness, weight, showTarget, showPose)
{
}

Expand Down Expand Up @@ -242,11 +251,43 @@ std::function<bool(const mc_tasks::MetaTask &, std::string &)> TransformTask::bu
void TransformTask::addToGUI(mc_rtc::gui::StateBuilder & gui)
{
TrajectoryTaskGeneric::addToGUI(gui);
auto showTarget = [this, &gui]()
{
if(showTarget_)
{
gui.addElement({"Tasks", name_}, mc_rtc::gui::Transform(
"targetPose", [this]() { return this->target(); },
[this](const sva::PTransformd & pos) { this->target(pos); }));
}
else { gui.removeElement({"Tasks", name_}, "targetPose"); }
};

auto showPose = [this, &gui]()
{
if(showPose_)
{
gui.addElement({"Tasks", name_}, mc_rtc::gui::Transform("pose", [this]() { return frame_->position(); }));
}
else { gui.removeElement({"Tasks", name_}, "pose"); }
};

gui.addElement({"Tasks", name_},
mc_rtc::gui::Transform(
"pos_target", [this]() { return this->target(); },
[this](const sva::PTransformd & pos) { this->target(pos); }),
mc_rtc::gui::Transform("pos", [this]() { return frame_->position(); }));
mc_rtc::gui::Checkbox(
"Show target", [this]() { return showTarget_; },
[this, showTarget]()
{
showTarget_ = !showTarget_;
showTarget();
}),
mc_rtc::gui::Checkbox(
"Show pose", [this]() { return showPose_; },
[this, showPose]()
{
showPose_ = !showPose_;
showPose();
}));
showTarget();
showPose();
}

} // namespace mc_tasks
Expand Down
Loading