gripper-control.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2010,
3  * François Bleibel,
4  * Olivier Stasse,
5  *
6  * CNRS/AIST
7  *
8  */
9 
10 #define ENABLE_RT_LOG
11 
14 
15 #include <sot/core/debug.hh>
16 #include <sot/core/factory.hh>
19 
20 using namespace dynamicgraph::sot;
21 using namespace dynamicgraph;
22 
24 
25 /* --- PLUGIN --------------------------------------------------------------- */
26 /* --- PLUGIN --------------------------------------------------------------- */
27 /* --- PLUGIN --------------------------------------------------------------- */
28 
29 #define SOT_FULL_TO_REDUCED(sotName) \
30  sotName##FullSizeSIN(NULL, "GripperControl(" + name + \
31  ")::input(vector)::" + #sotName + "FullIN"), \
32  sotName##ReduceSOUT( \
33  SOT_INIT_SIGNAL_2(GripperControlPlugin::selector, \
34  sotName##FullSizeSIN, dynamicgraph::Vector, \
35  selectionSIN, Flags), \
36  "GripperControl(" + name + ")::input(vector)::" + #sotName + \
37  "ReducedOUT")
38 
39 const double GripperControl::OFFSET_DEFAULT = 0.9;
40 
41 // TODO: hard coded
42 const double DT = 0.005;
43 
45  : offset(GripperControl::OFFSET_DEFAULT), factor() {}
46 
48  : Entity(name),
49  calibrationStarted(false),
50  positionSIN(NULL,
51  "GripperControl(" + name + ")::input(vector)::position"),
52  positionDesSIN(
53  NULL, "GripperControl(" + name + ")::input(vector)::positionDes"),
54  torqueSIN(NULL, "GripperControl(" + name + ")::input(vector)::torque"),
55  torqueLimitSIN(
56  NULL, "GripperControl(" + name + ")::input(vector)::torqueLimit"),
57  selectionSIN(NULL, "GripperControl(" + name + ")::input(vector)::selec")
58 
59  ,
60  SOT_FULL_TO_REDUCED(position),
61  SOT_FULL_TO_REDUCED(torque),
62  SOT_FULL_TO_REDUCED(torqueLimit),
63  desiredPositionSOUT(
64  SOT_MEMBER_SIGNAL_4(GripperControl::computeDesiredPosition,
65  positionSIN, dynamicgraph::Vector, positionDesSIN,
66  dynamicgraph::Vector, torqueSIN,
67  dynamicgraph::Vector, torqueLimitSIN,
69  "GripperControl(" + name + ")::output(vector)::reference") {
70  sotDEBUGIN(5);
71 
75 
80  sotDEBUGOUT(5);
81 
82  initCommands();
83 }
84 
86 
88  std::string docstring = "Control of gripper.";
89  return docstring;
90 }
91 
92 /* --- SIGNALS -------------------------------------------------------------- */
93 /* --- SIGNALS -------------------------------------------------------------- */
94 /* --- SIGNALS -------------------------------------------------------------- */
95 
97  const dynamicgraph::Vector &torques,
98  const dynamicgraph::Vector &torqueLimits,
99  const dynamicgraph::Vector &currentNormVel) {
100  const dynamicgraph::Vector::Index SIZE = currentNormVel.size();
101 
102  // initialize factor, if needed.
103  if (factor.size() != SIZE) {
104  factor.resize(SIZE);
105  factor.fill(1.);
106  }
107 
108  // Torque not provided?
109  if (torques.size() == 0) {
110  dgRTLOG() << "torque is not provided " << std::endl;
111  return;
112  }
113 
114  for (size_type i = 0; i < SIZE; ++i) {
115  // apply a reduction factor if the torque limits are exceeded
116  // and the velocity goes in the same way
117  if ((torques(i) > torqueLimits(i)) && (currentNormVel(i) > 0)) {
118  factor(i) *= offset;
119  } else if ((torques(i) < -torqueLimits(i)) && (currentNormVel(i) < 0)) {
120  factor(i) *= offset;
121  }
122  // otherwise, release smoothly the reduction if possible/needed
123  else {
124  factor(i) /= offset;
125  }
126 
127  // ensure factor is in )0,1(
128  factor(i) = std::min(1., std::max(factor(i), 0.));
129  }
130 }
131 
133  const dynamicgraph::Vector &currentPos,
134  const dynamicgraph::Vector &desiredPos, const dynamicgraph::Vector &torques,
135  const dynamicgraph::Vector &torqueLimits,
136  dynamicgraph::Vector &referencePos) {
137  const dynamicgraph::Vector::Index SIZE = currentPos.size();
138  // if( (SIZE==torques.size()) )
139  // { /* ERROR ... */ }
140 
141  // compute the desired velocity
142  dynamicgraph::Vector velocity = (desiredPos - currentPos) * (1. / DT);
143 
144  computeIncrement(torques, torqueLimits, velocity);
145 
146  sotDEBUG(25) << " velocity " << velocity << std::endl;
147  sotDEBUG(25) << " factor " << factor << std::endl;
148 
149  // multiply the velocity elmt per elmt
150  dynamicgraph::Vector weightedVel(SIZE);
151  weightedVel = velocity * factor;
152  sotDEBUG(25) << " weightedVel " << weightedVel << std::endl;
153 
154  // integrate the desired velocity
155  referencePos.resize(SIZE);
156  referencePos = currentPos + weightedVel * DT;
157  return referencePos;
158 }
159 
161  const dynamicgraph::Vector &fullsize, const Flags &selec,
162  dynamicgraph::Vector &desPos) {
163  size_type size = 0;
164  for (size_type i = 0; i < fullsize.size(); ++i) {
165  if (selec(i)) size++;
166  }
167 
168  size_type curs = 0;
169  desPos.resize(size);
170  for (size_type i = 0; i < fullsize.size(); ++i) {
171  if (selec(i)) desPos(curs++) = fullsize(i);
172  }
173 
174  return desPos;
175 }
176 
177 /* --- COMMANDLINE ---------------------------------------------------------- */
178 /* --- COMMANDLINE ---------------------------------------------------------- */
179 /* --- COMMANDLINE ---------------------------------------------------------- */
181  namespace dc = ::dynamicgraph::command;
182  addCommand("offset",
183  dc::makeCommandVoid1(*this, &GripperControlPlugin::setOffset,
184  "set the offset (should be in )0, 1( )."));
185 }
186 
187 void GripperControlPlugin::setOffset(const double &value) {
188  if ((value > 0) && (value < 1))
189  offset = value;
190  else
191  throw std::invalid_argument("The offset should be in )0, 1(.");
192 }
gripper-control.hh
dynamicgraph::sot::GripperControlPlugin::torqueSIN
dynamicgraph::SignalPtr< dynamicgraph::Vector, sigtime_t > torqueSIN
Definition: gripper-control.hh:113
factory.hh
dynamicgraph
factor
dynamicgraph::sot::GripperControlPlugin::desiredPositionSOUT
dynamicgraph::SignalTimeDependent< dynamicgraph::Vector, sigtime_t > desiredPositionSOUT
Definition: gripper-control.hh:131
i
int i
dynamicgraph::SignalPtr::plug
virtual void plug(SignalBase< Time > *ref)
dynamicgraph::Entity
dynamicgraph::sot::GripperControl::computeDesiredPosition
dynamicgraph::Vector & computeDesiredPosition(const dynamicgraph::Vector &currentPos, const dynamicgraph::Vector &desiredPos, const dynamicgraph::Vector &torques, const dynamicgraph::Vector &torqueLimits, dynamicgraph::Vector &referencePos)
Definition: gripper-control.cpp:132
dynamicgraph::sot::GripperControlPlugin::torqueLimitReduceSOUT
dynamicgraph::SignalTimeDependent< dynamicgraph::Vector, sigtime_t > torqueLimitReduceSOUT
Definition: gripper-control.hh:127
dynamicgraph::sot::GripperControlPlugin::torqueReduceSOUT
dynamicgraph::SignalTimeDependent< dynamicgraph::Vector, sigtime_t > torqueReduceSOUT
Definition: gripper-control.hh:123
SOT_FULL_TO_REDUCED
#define SOT_FULL_TO_REDUCED(sotName)
Definition: gripper-control.cpp:29
dynamicgraph::sot::GripperControlPlugin::~GripperControlPlugin
virtual ~GripperControlPlugin(void)
Definition: gripper-control.cpp:85
dynamicgraph::sot::GripperControlPlugin::positionDesSIN
dynamicgraph::SignalPtr< dynamicgraph::Vector, sigtime_t > positionDesSIN
Definition: gripper-control.hh:112
dynamicgraph::sot::GripperControlPlugin::selectionSIN
dynamicgraph::SignalPtr< Flags, sigtime_t > selectionSIN
Definition: gripper-control.hh:115
value
value
dynamicgraph::sot::GripperControlPlugin::positionReduceSOUT
dynamicgraph::SignalTimeDependent< dynamicgraph::Vector, sigtime_t > positionReduceSOUT
Definition: gripper-control.hh:120
dynamicgraph::sot::DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(FeaturePosture, "FeaturePosture")
dynamicgraph::sot::GripperControlPlugin::initCommands
void initCommands()
Definition: gripper-control.cpp:180
debug.hh
dynamicgraph::sot::GripperControl::GripperControl
GripperControl(void)
Definition: gripper-control.cpp:44
sotDEBUGOUT
#define sotDEBUGOUT(level)
Definition: debug.hh:215
dynamicgraph::sot::GripperControlPlugin::torqueLimitSIN
dynamicgraph::SignalPtr< dynamicgraph::Vector, sigtime_t > torqueLimitSIN
Definition: gripper-control.hh:114
DT
const double DT
Definition: gripper-control.cpp:42
sotDEBUGIN
#define sotDEBUGIN(level)
Definition: debug.hh:214
size
FCL_REAL size() const
Index
std::size_t Index
dgRTLOG
#define dgRTLOG()
macros-signal.hh
dynamicgraph::sot::GripperControlPlugin::torqueFullSizeSIN
dynamicgraph::SignalPtr< dynamicgraph::Vector, sigtime_t > torqueFullSizeSIN
Definition: gripper-control.hh:121
dynamicgraph::sot::GripperControl::selector
static dynamicgraph::Vector & selector(const dynamicgraph::Vector &fullsize, const Flags &selec, dynamicgraph::Vector &desPos)
select only some of the values of the vector fullsize, based on the Flags vector.
Definition: gripper-control.cpp:160
dynamicgraph::sot::GripperControl
The goal of this entity is to ensure that the maximal torque will not be exceeded during a grasping t...
Definition: gripper-control.hh:56
dynamicgraph::size_type
Matrix::Index size_type
dynamicgraph::sot::GripperControlPlugin::positionFullSizeSIN
dynamicgraph::SignalPtr< dynamicgraph::Vector, sigtime_t > positionFullSizeSIN
Definition: gripper-control.hh:118
SOT_MEMBER_SIGNAL_4
#define SOT_MEMBER_SIGNAL_4(sotFunction, sotArg1, sotArg1Type, sotArg2, sotArg2Type, sotArg3, sotArg3Type, sotArg4, sotArg4Type)
Definition: macros-signal.hh:93
dynamicgraph::Vector
Eigen::VectorXd Vector
dynamicgraph::sot::GripperControlPlugin::torqueLimitFullSizeSIN
dynamicgraph::SignalPtr< dynamicgraph::Vector, sigtime_t > torqueLimitFullSizeSIN
Definition: gripper-control.hh:125
real-time-logger.h
dynamicgraph::sot::GripperControlPlugin::GripperControlPlugin
GripperControlPlugin(const std::string &name)
Definition: gripper-control.cpp:47
dynamicgraph::sot::GripperControlPlugin
Definition: gripper-control.hh:94
dynamicgraph::sot::GripperControlPlugin::getDocString
virtual std::string getDocString() const
Definition: gripper-control.cpp:87
dynamicgraph::sot::GripperControl::computeIncrement
void computeIncrement(const dynamicgraph::Vector &torques, const dynamicgraph::Vector &torqueLimits, const dynamicgraph::Vector &currentNormVel)
Computes the.
Definition: gripper-control.cpp:96
dynamicgraph::sot
dynamicgraph::sot::GripperControl::OFFSET_DEFAULT
static const double OFFSET_DEFAULT
Definition: gripper-control.hh:59
dynamicgraph::Entity::addCommand
void addCommand(const std::string &name, command::Command *command)
all-commands.h
dynamicgraph::sot::Flags
Definition: flags.hh:33
dynamicgraph::sot::GripperControl::offset
double offset
Definition: gripper-control.hh:58
dynamicgraph::sot::GripperControlPlugin::positionSIN
dynamicgraph::SignalPtr< dynamicgraph::Vector, sigtime_t > positionSIN
Definition: gripper-control.hh:111
dynamicgraph::Entity::signalRegistration
void signalRegistration(const SignalArray< sigtime_t > &signals)
dynamicgraph::sot::GripperControlPlugin::setOffset
void setOffset(const double &value)
Definition: gripper-control.cpp:187
compile.name
name
Definition: compile.py:23
dynamicgraph::sot::GripperControl::factor
dynamicgraph::Vector factor
The multiplication.
Definition: gripper-control.hh:61
sotDEBUG
#define sotDEBUG(level)
Definition: debug.hh:168


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Tue Oct 24 2023 02:26:31