generic_gripper.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015-2019 CNRS-UM LIRMM, CNRS-AIST JRL
3  */
4 
5 #pragma once
6 
7 #include <mc_control/api.h>
8 #include <mc_rbdyn/RobotModule.h>
9 
10 #include <map>
11 #include <string>
12 #include <vector>
13 
14 namespace mc_rbdyn
15 {
16 struct Robot;
17 } // namespace mc_rbdyn
18 
19 namespace mc_control
20 {
21 
35 {
36 
45  Gripper(const mc_rbdyn::Robot & robot,
46  const std::vector<std::string> & jointNames,
47  const std::string & robot_urdf,
48  bool reverseLimits,
50 
61  Gripper(const mc_rbdyn::Robot & robot,
62  const std::vector<std::string> & jointNames,
63  const std::vector<mc_rbdyn::Mimic> & mimics,
64  bool reverseLimits,
66 
68  void resetDefaults();
69 
72  void saveConfig();
73 
79  void restoreConfig();
80 
82  void configure(const mc_rtc::Configuration & config);
83 
88  void reset(const std::vector<double> & currentQ);
89 
94  void reset(const Gripper & gripper);
95 
104  void run(double timeStep, mc_rbdyn::Robot & robot, mc_rbdyn::Robot & real);
105 
110  void setTargetQ(const std::vector<double> & targetQ);
111 
118  void setTargetQ(const std::string & jointName, double targetQ);
119 
125  double getTargetQ(const std::string & jointName) const;
126 
130  std::vector<double> getTargetQ() const;
131 
140  void setTargetOpening(double targetOpening);
141 
148  void setTargetOpening(const std::string & jointName, double targetOpening);
149 
156  double getTargetOpening(const std::string & jointName) const;
157 
161  std::vector<double> curPosition() const;
162 
166  std::vector<double> curOpening() const;
167 
174  double curOpening(const std::string & jointName) const;
175 
177  inline const std::vector<std::string> & joints() const { return names; }
178 
180  inline const std::vector<std::string> & activeJoints() const { return active_joints; }
181 
182  /* \brief Checks whether a joint is an active gripper joint */
183  inline bool hasActiveJoint(const std::string & jointName) const
184  {
185  return std::find(active_joints.begin(), active_joints.end(), jointName) != active_joints.end();
186  }
187 
191  inline const std::vector<double> & q() const { return _q; }
192 
199  double opening() const;
200 
202  void percentVMAX(double percent);
204  double percentVMAX() const;
205 
213  void actualCommandDiffTrigger(double d) { config_.actualCommandDiffTrigger = d; }
215  double actualCommandDiffTrigger() const { return config_.actualCommandDiffTrigger; }
216 
219  void overCommandLimitIterN(unsigned int N) { config_.overCommandLimitIterN = std::max(N, 1u); }
222  unsigned int overCommandLimitIterN() const { return config_.overCommandLimitIterN; }
223 
229  void releaseSafetyOffset(double offset) { config_.releaseSafetyOffset = offset; }
232  double releaseSafetyOffset() const { return config_.releaseSafetyOffset; }
233 
244  bool complete() const;
245 
250  inline bool is_metric() const noexcept { return is_metric_; }
251 
253  inline bool reversed() const noexcept { return reversed_; }
254 
255 protected:
260  void setTargetOpening(size_t activeJointId, double targetOpening);
261 
267  void setTargetQ(size_t activeJointId, double targetQ);
268 
270  void setTargetQ_(size_t activeJoints, double targetQ);
272  void setTargetQ_(const std::vector<double> & targetQ);
273 
275  double curPosition(size_t jointId) const;
276 
278  double curOpening(size_t jointId) const;
279 
281  double targetOpening(size_t jointId) const;
282 
284  double getTargetQ(size_t jointId) const;
285 
287  double clampQ(size_t activeJoint, double q);
288 
289 protected:
291  std::vector<std::string> names;
293  std::vector<std::string> active_joints;
295  std::vector<size_t> active_joints_idx;
297  std::vector<int> joints_mbc_idx;
298 
301 
303  std::vector<double> closeP;
305  std::vector<double> openP;
307  std::vector<double> vmax;
308 
310  std::vector<std::pair<size_t, double>> mult;
312  std::vector<double> offset;
314  std::vector<double> _q;
315 
317  std::vector<double> targetQIn;
319  std::vector<double> * targetQ;
320 
322  std::vector<double> reached_threshold_;
323 
325  std::vector<double> actualQ;
326 
327 protected:
335 
337  std::vector<double> percentOpen;
339  std::vector<bool> overCommandLimit;
341  std::vector<unsigned int> overCommandLimitIter;
343  bool reversed_ = false;
344 };
345 
346 using GripperPtr = std::unique_ptr<Gripper>;
347 using GripperRef = std::reference_wrapper<Gripper>;
348 
349 } // namespace mc_control
mc_rtc::Configuration
Simplify access to values hold within a JSON file.
Definition: Configuration.h:165
mc_control::GripperPtr
std::unique_ptr< Gripper > GripperPtr
Definition: generic_gripper.h:346
mc_control::Gripper::offset
std::vector< double > offset
Definition: generic_gripper.h:312
mc_control::Gripper::active_joints_idx
std::vector< size_t > active_joints_idx
Definition: generic_gripper.h:295
mc_control::Gripper::actualCommandDiffTrigger
void actualCommandDiffTrigger(double d)
Definition: generic_gripper.h:213
mc_control::Gripper::is_metric_
bool is_metric_
Definition: generic_gripper.h:300
mc_control::Gripper::overCommandLimitIterN
void overCommandLimitIterN(unsigned int N)
Definition: generic_gripper.h:219
mc_control::Gripper::joints
const std::vector< std::string > & joints() const
Returns all joints involved in the gripper.
Definition: generic_gripper.h:177
mc_control::Gripper::active_joints
std::vector< std::string > active_joints
Definition: generic_gripper.h:293
mc_rbdyn::Robot
Definition: Robot.h:62
mc_control::Gripper::overCommandLimitIter
std::vector< unsigned int > overCommandLimitIter
Definition: generic_gripper.h:341
mc_control::Gripper::percentOpen
std::vector< double > percentOpen
Definition: generic_gripper.h:337
mc_control::GripperRef
std::reference_wrapper< Gripper > GripperRef
Definition: generic_gripper.h:347
mc_control::Gripper::joints_mbc_idx
std::vector< int > joints_mbc_idx
Definition: generic_gripper.h:297
mc_control::Gripper::releaseSafetyOffset
void releaseSafetyOffset(double offset)
Definition: generic_gripper.h:229
RobotModule.h
mc_control::Gripper::reversed
bool reversed() const noexcept
When true the gripper is considered "open" when the joints' values are minimal.
Definition: generic_gripper.h:253
mc_control::Gripper::targetQIn
std::vector< double > targetQIn
Definition: generic_gripper.h:317
mc_control::Gripper::activeJoints
const std::vector< std::string > & activeJoints() const
Returns all active joints involved in the gripper.
Definition: generic_gripper.h:180
api.h
mc_control::Gripper::hasActiveJoint
bool hasActiveJoint(const std::string &jointName) const
Definition: generic_gripper.h:183
mc_control::Gripper::q
const std::vector< double > & q() const
Return all gripper joints configuration.
Definition: generic_gripper.h:191
mc_control::Gripper::_q
std::vector< double > _q
Definition: generic_gripper.h:314
mc_control::Gripper::actualCommandDiffTrigger
double actualCommandDiffTrigger() const
Definition: generic_gripper.h:215
mc_control::Gripper::names
std::vector< std::string > names
Definition: generic_gripper.h:291
mc_control::Gripper::is_metric
bool is_metric() const noexcept
Returns true if a gripper is metric, i.e. all active joints are prismatic rather than revolute.
Definition: generic_gripper.h:250
MC_RBDYN_DLLAPI
#define MC_RBDYN_DLLAPI
Definition: api.h:50
mc_control::Gripper::savedConfig_
Config savedConfig_
Definition: generic_gripper.h:332
mc_rbdyn::RobotModule::Gripper::Safety
Definition: RobotModule.h:115
mc_control::Gripper::closeP
std::vector< double > closeP
Definition: generic_gripper.h:303
mc_control::Gripper::overCommandLimitIterN
unsigned int overCommandLimitIterN() const
Definition: generic_gripper.h:222
mc_control::Gripper::openP
std::vector< double > openP
Definition: generic_gripper.h:305
mc_control::Gripper::targetQ
std::vector< double > * targetQ
Definition: generic_gripper.h:319
mc_control
Definition: CompletionCriteria.h:10
mc_control::Gripper::releaseSafetyOffset
double releaseSafetyOffset() const
Definition: generic_gripper.h:232
mc_control::Gripper
A robot's gripper reprensentation.
Definition: generic_gripper.h:34
mc_rbdyn
Definition: generic_gripper.h:14
mc_control::Gripper::config_
Config config_
Definition: generic_gripper.h:330
mc_control::Gripper::defaultConfig_
Config defaultConfig_
Definition: generic_gripper.h:334
mc_control::Gripper::vmax
std::vector< double > vmax
Definition: generic_gripper.h:307
mc_control::Gripper::reached_threshold_
std::vector< double > reached_threshold_
Definition: generic_gripper.h:322
mc_control::Gripper::overCommandLimit
std::vector< bool > overCommandLimit
Definition: generic_gripper.h:339
mc_control::Gripper::mult
std::vector< std::pair< size_t, double > > mult
Definition: generic_gripper.h:310
mc_control::Gripper::actualQ
std::vector< double > actualQ
Definition: generic_gripper.h:325