Skip to content
Snippets Groups Projects
Commit 43fb5092 authored by Florent Lamiraux's avatar Florent Lamiraux
Browse files

Add commands SetConstant and Set to GainAdaptive

    * include/sot-core/gain-adaptive.h,
    * src/task/gain-adaptive-command.h: new,
    * src/task/gain-adaptive.cpp.
parent 3fb2b37e
No related branches found
No related tags found
No related merge requests found
......@@ -106,6 +106,8 @@ class SOTGAINADAPTATIVE_EXPORT GainAdaptive
public: /* --- PARAMS --- */
virtual void commandLine( const std::string& cmdLine,std::istringstream& cmdArgs,
std::ostream& os );
private:
void addCommands();
};
} // namespace sot
......
/*
* Copyright 2010,
* Florent Lamiraux
*
* CNRS
*
* 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 GAIN_ADAPTIVE_COMMAND_H
#define GAIN_ADAPTIVE_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 {
namespace gainAdaptive {
using ::dynamicgraph::command::Command;
using ::dynamicgraph::command::Value;
// Command SetConstant
class SetConstant : public Command
{
public:
virtual ~SetConstant() {}
/// Create command and store it in Entity
/// \param entity instance of Entity owning this command
/// \param docstring documentation of the command
SetConstant(GainAdaptive& entity, const std::string& docstring) :
Command(entity, boost::assign::list_of(Value::DOUBLE), docstring)
{
}
virtual Value doExecute()
{
GainAdaptive& gainAdaptive = static_cast<GainAdaptive&>(owner());
std::vector<Value> values = getParameterValues();
double gain = values[0].value();
gainAdaptive.init(gain);
// return void
return Value();
}
}; // class SetConstant
// Command Set
class Set : public Command
{
public:
virtual ~Set() {}
/// Create command and store it in Entity
/// \param entity instance of Entity owning this command
/// \param docstring documentation of the command
Set(GainAdaptive& entity, const std::string& docstring) :
Command(entity, boost::assign::list_of(Value::DOUBLE)(Value::DOUBLE)
(Value::DOUBLE), docstring)
{
}
virtual Value doExecute()
{
GainAdaptive& gainAdaptive = static_cast<GainAdaptive&>(owner());
std::vector<Value> values = getParameterValues();
double c0 = values[0].value();
double cinf = values[1].value();
double p0 = values[2].value();
gainAdaptive.init(c0, cinf, p0);
// return void
return Value();
}
}; // class Set
} // namespace gainAdaptive
} // namespace command
} //namespace sot
#endif //GAIN_ADAPTIVE_COMMAND_H
......@@ -29,6 +29,8 @@
#include <sot-core/factory.h>
#include <sot-core/exception-signal.h>
#include "../src/task/gain-adaptive-command.h"
using namespace sot;
using namespace dynamicgraph;
......@@ -55,7 +57,31 @@ Entity(name) \
,gainSOUT( boost::bind(&GainAdaptive::computeGain,this,_1,_2), \
errorSIN,"sotGainAdaptive("+name+")::output(double)::gain" )
void GainAdaptive::addCommands()
{
std::string docstring;
// Command SetConstant
docstring = " \n"
" setConstant\n"
" Input:\n"
" floating point value: value at 0. Other values are set to"
"default.\n"
" \n";
addCommand("setConstant",
new command::gainAdaptive::SetConstant(*this, docstring));
// Command Set
docstring = " \n"
" set\n"
" Input:\n"
" floating point value: value at 0,\n"
" floating point value: value at infinity,\n"
" floating point value: value at slope,\n"
" \n";
addCommand("set",
new command::gainAdaptive::SetConstant(*this, docstring));
}
GainAdaptive::
GainAdaptive( const std::string & name )
......@@ -64,6 +90,7 @@ GainAdaptive( const std::string & name )
sotDEBUG(15) << "New gain <"<<name<<">"<<std::endl;
init();
Entity::signalRegistration( gainSOUT<<errorSIN );
addCommands();
}
......@@ -73,6 +100,7 @@ GainAdaptive( const std::string & name,const double& lambda )
{
init(lambda);
Entity::signalRegistration( gainSOUT );
addCommands();
}
GainAdaptive::
......@@ -84,6 +112,7 @@ GainAdaptive( const std::string & name,
{
init(valueAt0,valueAtInfty,tanAt0);
Entity::signalRegistration( gainSOUT );
addCommands();
}
......
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