iCub-main
Loading...
Searching...
No Matches
embObjMotionControlDefaults.h
Go to the documentation of this file.
1// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2
3/* Copyright (C) 2012 iCub Facility, Istituto Italiano di Tecnologia
4 * Author: auto-generated
5 * email: robotology-superbuild
6 * Permission is granted to copy, distribute, and/or modify this program
7 * under the terms of the GNU General Public License, version 2 or any
8 * later version published by the Free Software Foundation.
9 *
10 * A copy of the license can be found at
11 * http://www.robotcub.org/icub/license/gpl.txt
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16 * Public License for more details
17 */
18
19#ifndef __embObjMotionControlDefaultsh__
20#define __embObjMotionControlDefaultsh__
21
22#include <string>
23#include <string_view>
25
26namespace yarp::dev::eomc {
27
36namespace ParamValues {
37
38static constexpr std::string_view NONE_STR = "NONE";
39
40namespace controlLaw {
41static constexpr std::string_view current = "low_lev_current";
42static constexpr std::string_view direct = "direct";
43static constexpr std::string_view trajectory = "minjerk";
44static constexpr std::string_view torque = "torque";
45} // namespace controlLaw
46
47namespace fbkUnits {
48static constexpr std::string_view metric = "metric_units";
49static constexpr std::string_view machine = "machine_units";
50} // namespace fbkUnits
51
52// Only scale matters; the physical quantity is already encoded in outputType.
53namespace outUnits {
54static constexpr std::string_view metric = "metric_units";
55static constexpr std::string_view machine = "machine_units";
56} // namespace outUnits
57
59static constexpr std::string_view NONE = NONE_STR;
60static constexpr std::string_view PT100 = "PT100";
61static constexpr std::string_view PT1000 = "PT1000";
62} // namespace temperatureSensor
63
64namespace axisType {
65static constexpr std::string_view prismatic = "prismatic";
66static constexpr std::string_view revolute = "revolute";
67} // namespace axisType
68
69// Keys used in the CONTROLS config group to select a PID group per control mode.
70namespace controlMode {
71static constexpr std::string_view position = "positionControl";
72static constexpr std::string_view velocity = "velocityControl";
73static constexpr std::string_view mixed = "mixedControl";
74static constexpr std::string_view torque = "torqueControl";
75static constexpr std::string_view current = "currentControl";
76static constexpr std::string_view positionDirect = "positionDirect";
77static constexpr std::string_view velocityDirect = "velocityDirect";
78} // namespace controlMode
79
80// Strings used in config "outputType" field to select the physical output quantity.
81namespace outputType {
82static constexpr std::string_view n_a = "n_a";
83static constexpr std::string_view pwm = "pwm";
84static constexpr std::string_view velocity = "velocity";
85static constexpr std::string_view current = "current";
86static constexpr std::string_view vel_cur = "vel_cur"; //velocity with inner current loop
87} // namespace outputType
88
89} // namespace ParamValues
90
98namespace defaults {
99
100
105typedef struct
106{
107
108
109 // FOC (Field Oriented Control) default values
110 struct
111 {
112 bool verbose; // verbose output - default: false (0)
113 bool autoCalibration; // auto calibration - default: false (0)
114 float kbemf_foc; // back-emf compensation for FOC - default: 0.0f
115 std::string temperatureSensorType; // temperature sensor type - default: "NONE"
116 } focDefaults;
117
118 // Timeouts defaults
120
121 // AMC FOC timeouts default values
122 /**********************************************
123 * Important note on AMC FOC timeouts defaults:
124 * These defaults are used when the parser detects that the configuration file is for an AMC board
125 * and the TIMEOUTS group is missing or incomplete. The default values are set to 300 ms to account for the additional latency typically observed in AMC boards compared to other types of boards (EMS).
126 * now the timeout are mandatory, but this values are used to check if the user provided timeout are correct or not, in case of wrong value the default one will be used and a warning will be printed
127 */
129
130 // Temperature limits default values
132
133 // Control parameters default values
134 struct
135 {
136 double deadZone; // dead zone value - default: not specified
137 double pidScale; // PID scale - default: 0.0
138 double pidOffset; // PID offset - default: 0.0
139 // Deadzone parameters for different encoder types
140 struct
141 {
142 double jointWithAEA; // AEA encoder deadzone - default: 0.0494
143 double jointWithAEA3; // AEA3 encoder deadzone - default: 0.0 (TODO: fix if needed)
144 double jointWithAMO; // AMO encoder deadzone - default: 0.0055 (360 / 2^16)
145 double jointWithAKSIM2; // AKSIM2 encoder deadzone - default: 0.00068 (360 / 2^19)
146 double otherEncoder; // AKSIM2 encoder deadzone - default: 0.00068 (360 / 2^19)
147 } deadzone;
148
150
151 // Lugre friction model default values
152 struct
153 {
154 double Km; // Km parameter - default: -1.0
155 } lugre;
156 } controlParametersDefaults;
157
158 configType::TrqPidInfo torquePidDefaults; // Torque PID default values
159
160 double jointPosLimitsDelta; // default: 2.0. the positionLimits are reduced by this value when returned in the function "GetPositionLimits".
161
162 // Minimum time interval (in seconds) between consecutive positionMove commands.
163 // If commands arrive faster than this threshold, a performance warning is issued
164 // to alert the user that a different control mode may be more appropriate.
165 double maxPositionMoveInterval; // default = 0.080 seconds;
166
168
174class DefaultsFactory
175{
176private:
178
183 DefaultsFactory()
184 {
186 }
187
188 // Delete copy constructor and assignment operator to prevent copies
189 DefaultsFactory(const DefaultsFactory&) = delete;
190 DefaultsFactory& operator=(const DefaultsFactory&) = delete;
191
192public:
198 static DefaultsFactory& getInstance()
199 {
200 static DefaultsFactory instance; // Created only once, destroyed at program exit
201 return instance;
202 }
203
208 {
209 // Torque PID defaults
210 defaults.torquePidDefaults.viscousPos = 0.0;
211 defaults.torquePidDefaults.viscousNeg = 0.0;
212 defaults.torquePidDefaults.coulombPos = 0.0;
213 defaults.torquePidDefaults.coulombNeg = 0.0;
214 defaults.torquePidDefaults.velocityThres = 0.0;
215
216 // FOC defaults
217 defaults.focDefaults.verbose = false;
218 defaults.focDefaults.autoCalibration = false;
219 defaults.focDefaults.kbemf_foc = 0.0f;
220
221 // Timeouts defaults
222 defaults.timeoutsDefaults.velocity_ref = 100;
223 defaults.timeoutsDefaults.current_ref = 100;
224 defaults.timeoutsDefaults.pwm_ref = 100;
225 defaults.timeoutsDefaults.torque_ref = 100;
226 defaults.timeoutsDefaults.torque_fbk = 100;
227
228 // AMC FOC timeouts defaults
229 defaults.timeoutsDefaults_amcFoc.velocity_ref = 300;
230 defaults.timeoutsDefaults_amcFoc.current_ref = 300;
231 defaults.timeoutsDefaults_amcFoc.pwm_ref = 300;
232 defaults.timeoutsDefaults_amcFoc.torque_ref = 300;
233 defaults.timeoutsDefaults_amcFoc.torque_fbk = 300;
234
235 // Temperature limits defaults
236 defaults.temperatureLimitsDefaults.hardware = 0.0;
237 defaults.temperatureLimitsDefaults.warning = 0.0;
238
239 // Control parameters defaults
240 defaults.controlParametersDefaults.deadZone = 0.0;
241 defaults.controlParametersDefaults.pidScale = 0.0;
242 defaults.controlParametersDefaults.pidOffset = 0.0;
243 defaults.controlParametersDefaults.deadzone.jointWithAEA = 0.0494;
244 defaults.controlParametersDefaults.deadzone.jointWithAEA3 = 0.0;
245 defaults.controlParametersDefaults.deadzone.jointWithAMO = 0.0055;
246 defaults.controlParametersDefaults.deadzone.jointWithAKSIM2 = 0.00068;
247
248 // Kalman Filter defaults
249 defaults.controlParametersDefaults.kalmanFilterParams.enabled = false;
250 defaults.controlParametersDefaults.kalmanFilterParams.x0.fill(0.0);
251 defaults.controlParametersDefaults.kalmanFilterParams.Q.fill(0.0);
252 defaults.controlParametersDefaults.kalmanFilterParams.R = 0.0;
253 defaults.controlParametersDefaults.kalmanFilterParams.P0 = 0.0;
254
255 // Lugre friction model defaults
256 defaults.controlParametersDefaults.lugre.Km = -1.0;
257
258 // Joint position limits delta default value
259 defaults.jointPosLimitsDelta = 2.0;
260
261 // Max position move interval default value
262 defaults.maxPositionMoveInterval = 0.080;
263 }
264
269 void setDefaultTimeouts(int defaultTimeout)
270 {
271 defaults.timeoutsDefaults.velocity_ref = defaultTimeout;
272 defaults.timeoutsDefaults.current_ref = defaultTimeout;
273 defaults.timeoutsDefaults.pwm_ref = defaultTimeout;
274 defaults.timeoutsDefaults.torque_ref = defaultTimeout;
275 defaults.timeoutsDefaults.torque_fbk = defaultTimeout;
276 }
277
284 bool setTimeoutValue(const std::string& timeoutType, int value)
285 {
286 if (timeoutType == "velocity_ref")
287 defaults.timeoutsDefaults.velocity_ref = value;
288 else if (timeoutType == "current_ref")
289 defaults.timeoutsDefaults.current_ref = value;
290 else if (timeoutType == "pwm_ref")
291 defaults.timeoutsDefaults.pwm_ref = value;
292 else if (timeoutType == "torque_ref")
293 defaults.timeoutsDefaults.torque_ref = value;
294 else if (timeoutType == "torque_fbk")
295 defaults.timeoutsDefaults.torque_fbk = value;
296 else
297 return false;
298 return true;
299 }
300
306 {
307 return defaults;
308 }
309
316 {
317 return defaults;
318 }
319
325 {
327 }
328};
329
330} // namespace defaults
331} // namespace yarp::dev::eomc
332
333#endif // __embObjMotionControlDefaultsh__
const embObjMotionControlDefaults_t & getDefaults() const
Get the current defaults structure.
void setDefaultTimeouts(int defaultTimeout)
Set all timeout values to the same value at runtime.
embObjMotionControlDefaults_t & getDefaultsMutable()
Get mutable reference to defaults (advanced usage) Allows direct modification of nested fields.
void initializeDefaults()
Initialize all default values.
static DefaultsFactory & getInstance()
Get the singleton instance (thread-safe in C++11+) Uses Meyer's singleton pattern for automatic threa...
bool setTimeoutValue(const std::string &timeoutType, int value)
Set individual timeout values at runtime.
void resetDefaults()
Reset all defaults to initial values Useful if you need to restore defaults after modifications.
static constexpr std::string_view prismatic
Allowed parameter values (tokens) used for configuration file validation.
static constexpr std::string_view NONE_STR
Default (fallback) values for embObjMotionControl configuration parameters.
Structure containing all default values used in embObjMotionControl and eomcParser classes.