XBotInterface  2.4.1
XBotInterface provides a generic API to model and control a robot.
SyncFlags.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 IIT-ADVR
3  * Author: Arturo Laurenzi, Luca Muratore
4  * email: arturo.laurenzi@iit.it, luca.muratore@iit.it
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>
18 */
19 
20 #ifndef __XBOT_SYNCFLAGS__
21 #define __XBOT_SYNCFLAGS__
22 
24 
25 namespace XBot {
26 
27  inline void parseFlags(bool& pos,
28  bool& vel,
29  bool& acc,
30  bool& eff,
31  bool& k,
32  bool& d,
33  bool& ft,
34  bool& imu,
35  bool& motor_side,
36  Sync s = Sync::All){
37 
38  pos = (s == Sync::Position) || (s == Sync::All);
39  vel = (s == Sync::Velocity) || (s == Sync::All);
40  acc = (s == Sync::Acceleration) || (s == Sync::All);
41  eff = (s == Sync::Effort) || (s == Sync::All);
42  k = (s == Sync::Stiffness) || (s == Sync::Impedance) || (s == Sync::All);
43  d = (s == Sync::Damping) || (s == Sync::Impedance) || (s == Sync::All);
44  ft = (s == Sync::ForceTorque) || (s == Sync::Sensors) || (s == Sync::All);
45  imu = (s == Sync::Imu) || (s == Sync::Sensors) || (s == Sync::All);
46  motor_side = (s == Sync::MotorSide);
47 
48 
49 
50 
51  }
52 
53  template <typename... Flags>
54  inline void parseFlags(bool& pos,
55  bool& vel,
56  bool& acc,
57  bool& eff,
58  bool& k,
59  bool& d,
60  bool& ft,
61  bool& imu,
62  bool& motor_side,
63  Sync s, Flags... rest){
64 
65 
66  parseFlags(pos, vel, acc, eff, k, d, ft, imu, motor_side, rest...);
67 
68  pos = pos || (s == Sync::Position) || (s == Sync::All);
69  vel = vel || (s == Sync::Velocity) || (s == Sync::All);
70  acc = acc || (s == Sync::Acceleration) || (s == Sync::All);
71  eff = eff || (s == Sync::Effort) || (s == Sync::All);
72  k = k || (s == Sync::Stiffness) || (s == Sync::Impedance) || (s == Sync::All);
73  d = d || (s == Sync::Damping) || (s == Sync::Impedance) || (s == Sync::All);
74  ft = ft || (s == Sync::ForceTorque) || (s == Sync::Sensors) || (s == Sync::All);
75  imu = imu || (s == Sync::Imu) || (s == Sync::Sensors) || (s == Sync::All);
76  motor_side = motor_side || (s == Sync::MotorSide);
77 
78 
79  }
80 
81 
82 
83  class FlagsParser {
84 
85  public:
86 
87 
89  load_flags();
90  }
91 
92  template <typename... Flags>
93  void load_flags(Flags... flags)
94  {
95  pos = false;
96  vel = false;
97  acc = false;
98  eff = false;
99  k = false;
100  d = false;
101  ft = false;
102  imu = false;
103  mot = false;
104 
105  parseFlags(pos,
106  vel,
107  acc,
108  eff,
109  k,
110  d,
111  ft,
112  imu,
113  mot,
114  flags...
115  );
116 
117  if(mot && !pos && !vel)
118  {
119  throw std::runtime_error("Sync::MotorSide must be used together with Position OR Velocity!");
120  }
121 
122  }
123 
124  bool position_flag() const { return pos; }
125  bool velocity_flag() const { return vel; }
126  bool acceleration_flag() const { return acc; }
127  bool effort_flag() const { return eff; }
128  bool stiffness_flag() const { return k; }
129  bool damping_flag() const { return d; }
130  bool ft_flag() const { return ft; }
131  bool imu_flag() const { return imu; }
132  bool motor_side_flag() const { return mot; }
133 
134  private:
135 
136  bool pos, vel, acc, eff, k, d, ft, imu, mot;
137 
138  };
139 
140 }
141 #endif
XBot::Sync::Effort
@ Effort
XBot::FlagsParser::motor_side_flag
bool motor_side_flag() const
Definition: SyncFlags.h:132
XBot::Sync::ForceTorque
@ ForceTorque
XBot::Sync::MotorSide
@ MotorSide
XBot::FlagsParser
Definition: SyncFlags.h:83
XBot::FlagsParser::damping_flag
bool damping_flag() const
Definition: SyncFlags.h:129
XBot::Sync::Imu
@ Imu
XBot::FlagsParser::acceleration_flag
bool acceleration_flag() const
Definition: SyncFlags.h:126
XBot::FlagsParser::stiffness_flag
bool stiffness_flag() const
Definition: SyncFlags.h:128
TypedefAndEnums.h
XBot::FlagsParser::effort_flag
bool effort_flag() const
Definition: SyncFlags.h:127
XBot::Sync::Damping
@ Damping
XBot::FlagsParser::ft_flag
bool ft_flag() const
Definition: SyncFlags.h:130
XBot::Sync::Stiffness
@ Stiffness
XBot::Sync
Sync
enum class that represents a set of flags to specify what part of the robot/model state needs to be s...
Definition: TypedefAndEnums.h:107
XBot::Sync::Acceleration
@ Acceleration
XBot::FlagsParser::load_flags
void load_flags(Flags... flags)
Definition: SyncFlags.h:93
XBot::Sync::Sensors
@ Sensors
XBot::parseFlags
void parseFlags(bool &pos, bool &vel, bool &acc, bool &eff, bool &k, bool &d, bool &ft, bool &imu, bool &motor_side, Sync s=Sync::All)
Definition: SyncFlags.h:27
XBot::FlagsParser::velocity_flag
bool velocity_flag() const
Definition: SyncFlags.h:125
XBot::FlagsParser::imu_flag
bool imu_flag() const
Definition: SyncFlags.h:131
XBot::FlagsParser::position_flag
bool position_flag() const
Definition: SyncFlags.h:124
XBot::Sync::Velocity
@ Velocity
XBot::Sync::All
@ All
XBot::Sync::Position
@ Position
XBot
Definition: IXBotModel.h:20
XBot::Sync::Impedance
@ Impedance
XBot::FlagsParser::FlagsParser
FlagsParser()
Definition: SyncFlags.h:88