33 #include "../util/eigen_matnd.h" 35 #include <Rcs_macros.h> 45 :
ActionModel(wrapped->getGraph()), wrapped(wrapped), dynamicalSystems(std::move(ds)), taskCombinationMethod(tcm)
67 for (
unsigned int i = 0; i <
getDim(); i++) {
75 std::vector<std::string> names;
76 for (
unsigned int i = 0; i <
getDim(); ++i) {
77 names.push_back(
"a_" + std::to_string(i));
83 MatNd* q_des, MatNd* q_dot_des, MatNd* T_des,
const MatNd* action,
double dt)
85 RCHECK(action->n == 1);
88 Eigen::VectorXd x_dot_old =
x_dot;
92 for (
unsigned int i = 0; i <
getDim(); ++i) {
94 Eigen::VectorXd x_dot_ds = x_dot_old;
105 x_dot += action->ele[i]*x_dot_ds;
112 MatNd_create2(a, action->m, action->n);
113 MatNd_softMax(a, action, action->m);
114 x_dot += MatNd_get(a, i, 0)*x_dot_ds;
116 MatNd_set(
activation, i, 0, MatNd_get(a, i, 0));
123 MatNd* otherActions = NULL;
124 MatNd_clone2(otherActions, action);
125 MatNd_deleteRow(otherActions, i);
129 for (
unsigned int idx = 0; idx < otherActions->m; idx++) {
131 std::cout <<
"factor " << (1 - otherActions->ele[idx]) << std::endl;
134 prod *= (1 - otherActions->ele[idx]);
137 std::cout <<
"prod " << prod << std::endl;
140 x_dot += action->ele[i]*prod*x_dot_ds;
141 MatNd_set(
activation, i, 0, action->ele[i]*prod);
143 MatNd_destroy(otherActions);
150 std::cout <<
"action DS " << i <<
" = " << action->ele[i] << std::endl;
151 std::cout <<
"x_dot DS " << i <<
" =" << std::endl << x_dot_ds << std::endl;
157 double normalizer = MatNd_getNormL1(action) + 1e-8;
159 MatNd_constMulSelf(
activation, 1./normalizer);
173 std::cout <<
"x_dot (combined MP) =\n" <<
x_dot << std::endl;
174 std::cout <<
"x (combined MP) =\n" <<
x << std::endl;
177 MatNd_printComment(
"q_des", q_des);
178 MatNd_printComment(
"q_dot_des", q_dot_des);
180 MatNd_printComment(
"T_des", T_des);
200 MatNd_setZero(action);
225 std::vector<DynamicalSystem*> dsvc;
227 dsvc.push_back(ds->clone());
236 if (tcmName ==
"sum") {
239 else if (tcmName ==
"mean") {
242 else if (tcmName ==
"softmax") {
245 else if (tcmName ==
"product") {
249 std::ostringstream os;
250 os <<
"Unsupported task combination method: " << tcmName <<
"! Supported methods: sum, mean, softmax, product.";
251 throw std::invalid_argument(os.str());
virtual std::vector< std::string > getNames() const
Eigen::VectorXd getXdot() const
virtual void getStableAction(MatNd *action) const
Eigen::VectorXd x
Current state in task space.
const char * getTaskCombinationMethodName() const
virtual unsigned int getDim() const
Get the number of DS, i.e. entries in the dynamicalSystems vector, owned by the action model...
virtual void computeCommand(MatNd *q_des, MatNd *q_dot_des, MatNd *T_des, const MatNd *action, double dt)=0
static TaskCombinationMethod checkTaskCombinationMethod(std::string tcmName)
TaskCombinationMethod taskCombinationMethod
Way to combine the tasks' contribution.
std::vector< DynamicalSystem * > dynamicalSystems
List of dynamical systems.
Eigen::VectorXd getX() const
ActionModel * wrapped
Wrapped action model.
MatNd * getActivation() const
virtual ActionModel * getWrappedActionModel() const
MatNd * activation
The activation resulting from the action and the task combination method (used for logging) ...
virtual void computeCommand(MatNd *q_des, MatNd *q_dot_des, MatNd *T_des, const MatNd *action, double dt)
AMDynamicalSystemActivation(ActionModel *wrapped, std::vector< DynamicalSystem *> ds, TaskCombinationMethod tcm)
virtual void getMinMax(double *min, double *max) const
ActionModel * clone() const
Eigen::VectorXd x_dot
Current velocity in task space.
virtual ~AMDynamicalSystemActivation()
virtual unsigned int getDim() const =0
virtual void getStableAction(MatNd *action) const =0
const std::vector< DynamicalSystem * > & getDynamicalSystems() const
Get a vector of the owned dynamical systems.
MatNd viewEigen2MatNd(M &src)