Command (dynamicgraph::command::Command) are objects that encapsulate an action to be performed on an entity.
In this page, we define a new command that will call method InvertedPendulum::incr. The source code is in src/command-increment.hh
.
We first define the new class by deriving dynamicgraph::command::Command:
The constructor takes
double
. Note the use of boost::assign::list_of
to build a vector in one command line:We then define the action of the command in virtual method doExecute
. We need to get a reference to the object on which the command will act. Note that we can straightfowardly statically cast in InvertedPendulum
the Entity object returned by method owner
:
We then get the parameters as a vector of dynamicgraph::command::Value objects and cast them into the appropriate types specified at construction:
Finally, we execute the action and return a value of the appropriate type, here the command return no value: