Skip to content
Snippets Groups Projects
Commit 85a8d1fd authored by Nicolas Mansard's avatar Nicolas Mansard
Browse files

Modify the writting of new-style commands.

parent ae3db436
No related branches found
No related tags found
No related merge requests found
......@@ -83,7 +83,7 @@ class SOTROBOTSIMU_EXPORT RobotSimu
void setStateSize( const unsigned int& size );
void setState( const ml::Vector& st );
void increment( const double dt = 5e-2 );
void increment( const double & dt = 5e-2 );
......
/*
* Copyright 2010,
* Florent Lamiraux
*
* CNRS/AIST
*
* This file is part of sot-core.
* sot-core is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* sot-core is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. You should
* have received a copy of the GNU Lesser General Public License along
* with sot-core. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ROBOT_SIMU_COMMAND_H
#define ROBOT_SIMU_COMMAND_H
#include <boost/assign/list_of.hpp>
#include <dynamic-graph/command.h>
#include <dynamic-graph/command-setter.h>
#include <dynamic-graph/command-getter.h>
namespace sot {
namespace command {
using ::dynamicgraph::command::Command;
using ::dynamicgraph::command::Value;
// Command Increment
class Increment : public Command
{
public:
virtual ~Increment() {}
/// Create command and store it in Entity
/// \param entity instance of Entity owning this command
/// \param docstring documentation of the command
Increment(RobotSimu& entity, const std::string& docstring) :
Command(entity, boost::assign::list_of(Value::DOUBLE), docstring)
{
}
virtual Value doExecute()
{
RobotSimu& rs = static_cast<RobotSimu&>(owner());
std::vector<Value> values = getParameterValues();
double timeStep = values[0].value();
rs.increment(timeStep);
// return void
return Value();
}
}; // class Increment
} // namespace command
} //namespace sot
#endif //ROBOT_SIMU_COMMAND_H
......@@ -31,6 +31,7 @@
using namespace std;
#include <dynamic-graph/factory.h>
#include <dynamic-graph/command-bind.h>
using namespace sot;
using namespace dynamicgraph;
......@@ -121,7 +122,7 @@ RobotSimu( const std::string& n )
,motorcontrolSOUT( "RobotSimu("+n+")::output(vector)::motorcontrol" )
,ZMPPreviousControllerSOUT( "RobotSimu("+n+")::output(vector)::zmppreviouscontroller" )
{
/* --- FORCES --- */
/* --- SIGNALS --- */
for( int i=0;i<4;++i ){ withForceSignals[i] = false; }
forcesSOUT[0] =
new Signal<ml::Vector, int>("OpenHRP::output(vector6)::forceRLEG");
......@@ -137,11 +138,10 @@ RobotSimu( const std::string& n )
<<previousControlSOUT <<pseudoTorqueSOUT
<< motorcontrolSOUT << ZMPPreviousControllerSOUT );
state.fill(.0); stateSOUT.setConstant( state );
//
// Commands
//
/* --- Commands --- */
std::string docstring;
// Increment
/* Command increment. */
docstring =
"\n"
" Integrate dynamics for time step provided as input\n"
......@@ -149,16 +149,16 @@ RobotSimu( const std::string& n )
" take one floating point number as input\n"
"\n";
addCommand("increment",
new command::Increment(*this, docstring));
// setStateSize
::dynamicgraph::command::makeCommandVoid1( *this,&RobotSimu::increment,docstring));
/* Command setStateSize. */
docstring =
"\n"
" Set size of state vector\n"
"\n";
addCommand("resize",
new ::dynamicgraph::command::Setter<RobotSimu, unsigned>
new ::dynamicgraph::command::Setter<RobotSimu, unsigned int>
(*this, &RobotSimu::setStateSize, docstring));
// set
/* Command set. */
docstring =
"\n"
" Set state vector value\n"
......@@ -190,7 +190,7 @@ setState( const ml::Vector& st )
}
void RobotSimu::
increment( const double dt )
increment( const double & dt )
{
sotDEBUG(25) << "Time : " << controlSIN.getTime()+1 << std::endl;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment