iCub-main
Loading...
Searching...
No Matches
embObjMotionControlConfigTypes.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 __embObjMotionControlConfigTypesh__
20#define __embObjMotionControlConfigTypesh__
21
22#include <array>
23#include <memory>
24#include <string>
25#include <vector>
26#include <yarp/dev/PidEnums.h>
27#include <yarp/os/LogStream.h>
28#include <yarp/dev/ControlBoardPid.h>
29#include <yarp/dev/ControlBoardHelper.h>
30#include <yarp/dev/ControlBoardInterfacesImpl.h>
31
32#include "EoMotionControl.h"
33#include "serviceParser.h"
34
35namespace yarp {
36 namespace dev {
37 namespace eomc {
38 namespace configType {
39
40typedef struct
41{
48
49
51{
52public:
53
54 yarp::dev::Pid pid;
55 yarp::dev::PidFeedbackUnitsEnum fbk_PidUnits;
56 yarp::dev::PidOutputUnitsEnum out_PidUnits;
57 eOmc_ctrl_out_type_t out_type;
58 std::string controlLaw;
60 bool enabled;
61
63 {
64 enabled = false;
65 out_type = eomc_ctrl_out_type_n_a;
66 fbk_PidUnits = yarp::dev::PidFeedbackUnitsEnum::RAW_MACHINE_UNITS;
67 out_PidUnits = yarp::dev::PidOutputUnitsEnum::RAW_MACHINE_UNITS;
68 }
69 virtual ~PidInfo() = default; //this make the class polymorphic and allows dynamic_cast, which is used in the parser to check if the pid is a TrqPidInfo or a simple PidInfo
70
71 void print() const
72 {
73 yInfo("PidInfo:");
74 yInfo(" pid: [kp=%f, ki=%f, kd=%f, max_int=%f, max_output=%f, scale=%f, offset=%f, kff=%f]",
75 pid.kp, pid.ki, pid.kd, pid.max_int, pid.max_output, pid.scale, pid.offset, pid.kff);
76
77 // Convert enums to string
78 auto fbkUnitsToString = [](yarp::dev::PidFeedbackUnitsEnum e) -> std::string {
79 switch(e) {
80 case yarp::dev::PidFeedbackUnitsEnum::RAW_MACHINE_UNITS : return "RAW_MACHINE_UNITS";
81 case yarp::dev::PidFeedbackUnitsEnum::METRIC : return "METRIC";
82
83 default: return "UNKNOWN";
84 }
85 };
86 auto outUnitsToString = [](yarp::dev::PidOutputUnitsEnum e) -> std::string {
87 switch(e) {
88 case yarp::dev::PidOutputUnitsEnum::RAW_MACHINE_UNITS: return "RAW_MACHINE_UNITS";
89 case yarp::dev::PidOutputUnitsEnum::POSITION_METRIC : return "POSITION_METRIC";
90 case yarp::dev::PidOutputUnitsEnum::VELOCITY_METRIC : return "VELOCITY_METRIC";
91 case yarp::dev::PidOutputUnitsEnum::DUTYCYCLE_PWM_PERCENT : return "DUTYCYCLE_PWM_PERCENT";
92 case yarp::dev::PidOutputUnitsEnum::TORQUE_METRIC : return "TORQUE_METRIC";
93 case yarp::dev::PidOutputUnitsEnum::CURRENT_METRIC : return "CURRENT_METRIC";
94 default: return "UNKNOWN";
95 }
96 };
97 auto outTypeToString = [](eOmc_ctrl_out_type_t e) -> std::string {
98 switch(e) {
99 case eomc_ctrl_out_type_n_a: return "n/a";
100 case eomc_ctrl_out_type_pwm: return "pwm";
101 case eomc_ctrl_out_type_cur: return "cur";
102 case eomc_ctrl_out_type_vel_pwm: return "vel_pwm";
103 case eomc_ctrl_out_type_vel_cur: return "vel_cur";
104 default: return "UNKNOWN";
105 }
106 };
107
108 yInfo(" fbk_PidUnits: %s", fbkUnitsToString(fbk_PidUnits).c_str());
109 yInfo(" out_PidUnits: %s", outUnitsToString(out_PidUnits).c_str());
110 yInfo(" out_type: %s", outTypeToString(out_type).c_str());
111 yInfo(" usernamePidSelected: %s", usernamePidSelected.c_str());
112 yInfo(" enabled: %s", enabled ? "true" : "false");
113 }
114
115};
116
117class TrqPidInfo : public PidInfo
118{
119public:
120 double ktau;
127};
128
129// Kalman Filter default values
130typedef struct
131{
133 std::array<float32_t, 3> x0;
134 std::array<float32_t, 3> Q;
135 float32_t R;
136 float32_t P0;
138
139typedef struct
140{
141 double hardware;
142 double warning;
143} temperatureLimits_t; // limits expressed as raw values after conversion is applied
144
145} // namespace yarp::dev::eomc::configType
146
152
153typedef struct
154{
155 eOmc_encoder_t type;
156 double tolerance;
158} encoder_t;
159
166
167typedef struct
168{
171
172typedef struct
173{
174 std::vector<PidInfo> trj;
175 std::vector<PidInfo> mix;
176 std::vector<PidInfo> dir_pos;
177 std::vector<PidInfo> dir_vel;
178 std::vector<TrqPidInfo> trq;
179 std::vector<PidInfo> cur;
180 std::vector<PidInfo> vel;
182
189
191{
192public:
193 virtual ~ITemperatureSensor() = default;
194 virtual double convertTempCelsiusToRaw(const double temperature) = 0;
195 virtual double convertRawToTempCelsius(const double temperature) = 0;
197};
198
200{
201private:
202 int _r_1;
203 int _r_2;
204 int _r_3;
205 double _ptc_offset;
206 double _ptc_gradient;
207 double _pga_gain;
208 int _vcc;
209 double _resolution_pga;
210 double _resolution_tdb;
211 double _half_bridge_resistor_coeff;
212 double _first_res_coeff;
213 double _second_res_coeff;
214
215public:
217 {
218 _r_1 = 4700;
219 _r_2 = 4700;
220 _r_3 = 100;
221
222 _ptc_offset = 100.0;
223 _ptc_gradient = 0.3851;
224 _pga_gain = 2;
225 _vcc = 5;
226 _resolution_pga = 2.048;
227 _resolution_tdb = 32767;
228
229 _half_bridge_resistor_coeff = (double)_r_3 / (double)(_r_2 + _r_3);
230 _first_res_coeff = _r_1*_r_2 + _r_1*_r_3 + _ptc_offset*_r_2 + _ptc_offset*_r_3;
231 _second_res_coeff = _r_3*_r_1 - _r_2*_ptc_offset;
232 }
233
239
240 virtual double convertTempCelsiusToRaw(const double temperature) override
241 {
242 double res = 0;
243 double tmp = (((_ptc_offset + _ptc_gradient * temperature) / ((double)_r_1 + (_ptc_offset + _ptc_gradient * temperature))) - _half_bridge_resistor_coeff) * (double)_vcc;
244 res = (_resolution_tdb + 1) * ((_pga_gain * tmp) / _resolution_pga);
245 return res;
246 }
247
248 virtual double convertRawToTempCelsius(const double temperature) override
249 {
250 double res = 0;
251 double tmp = temperature * ((_resolution_pga) / (_pga_gain * _vcc * (_resolution_tdb + 1)));
252 double den = _ptc_gradient * (_r_2 - _r_2*tmp - _r_3*tmp);
253 res = (tmp * (_first_res_coeff) / den) + ((_second_res_coeff) / den);
254 return res;
255 }
256
261};
262
264{
265private:
266 int _r_1;
267 int _r_2;
268 int _r_3;
269 double _ptc_offset;
270 double _ptc_gradient;
271 double _pga_gain;
272 int _vcc;
273 double _resolution_pga;
274 double _resolution_tdb;
275 double _half_bridge_resistor_coeff;
276 double _first_res_coeff;
277 double _second_res_coeff;
278
279public:
281 {
282 _r_1 = 4700;
283 _r_2 = 4700;
284 _r_3 = 1000;
285
286 _ptc_offset = 1000;
287 _ptc_gradient = 3.851;
288 _pga_gain = 2;
289 _vcc = 5;
290 _resolution_pga = 2.048;
291 _resolution_tdb = 32767;
292
293 _half_bridge_resistor_coeff = (double)_r_3 / (double)(_r_2 + _r_3);
294 _first_res_coeff = _r_1*_r_2 + _r_1*_r_3 + _ptc_offset*_r_2 + _ptc_offset*_r_3;
295 _second_res_coeff = _r_3*_r_1 - _r_2*_ptc_offset;
296 }
297
303
304 virtual double convertTempCelsiusToRaw(const double temperature) override
305 {
306 double res = 0;
307 double tmp = (((_ptc_offset + _ptc_gradient * temperature) / ((double)_r_1 + (_ptc_offset + _ptc_gradient * temperature))) - _half_bridge_resistor_coeff) * (double)_vcc;
308 res = (_resolution_tdb + 1) * ((_pga_gain * tmp) / _resolution_pga);
309 return res;
310 }
311
312 virtual double convertRawToTempCelsius(const double temperature) override
313 {
314 double res = 0;
315 double tmp = temperature * ((_resolution_pga) / (_pga_gain * _vcc * (_resolution_tdb + 1)));
316 double den = _ptc_gradient * (_r_2 - _r_2*tmp - _r_3*tmp);
317 res = (tmp * (_first_res_coeff) / den) + ((_second_res_coeff) / den);
318 return res;
319 }
320
325};
326
328{
329public:
332
333 virtual double convertTempCelsiusToRaw(const double temperature) override
334 {
335 (void)temperature;
336 return 0;
337 }
338
339 virtual double convertRawToTempCelsius(const double temperature) override
340 {
341 (void)temperature;
342 return 0;
343 }
344
349};
350
363
365{
366public:
367 int id;
368 std::vector<int> joints;
369 eOmc_jointset_configuration_t cfg;
370
371 JointsSet(int num=0)
372 {
373 id = num;
374 joints.resize(0);
375 cfg.candotorquecontrol = 0;
376 cfg.usespeedfeedbackfrommotors = 0;
377 cfg.dummy = 0;
378 cfg.constraints.type = eomc_jsetconstraint_unknown;
379 cfg.constraints.param1 = 0;
380 cfg.constraints.param2 = 0;
381 }
382
383 int getNumberofJoints(void) { return joints.size(); }
384 eOmc_jointset_configuration_t* getConfiguration(void) { return &cfg; }
385 void setUseSpeedFeedbackFromMotors(bool flag) { cfg.usespeedfeedbackfrommotors = flag; }
386 void setCanDoTorqueControl(bool flag) { cfg.candotorquecontrol = flag; }
387 void dumpdata();
388};
389
390typedef struct
391{
396
397typedef struct
398{
399 double posMin;
400 double posMax;
401 double posHwMax;
402 double posHwMin;
403 double velMax;
405
406typedef struct
407{
408 double posMin;
409 double posMax;
410 double pwmMax;
412
413typedef struct
414{
415 std::vector<double> matrixJ2M;
416 std::vector<double> matrixM2J;
417 std::vector<double> matrixE2J;
419
420typedef struct
421{
423 std::string name;
424 JointTypeEnum type;
425} axisInfo_t;
426
427typedef struct
428{
429 double min_stiff;
430 double max_stiff;
431 double min_damp;
432 double max_damp;
433 double param_a;
434 double param_b;
435 double param_c;
437
444
445typedef struct
446{
447 double Km;
448 double Kw;
449 double S0;
450 double S1;
451 double Vth;
452 double Fc_pos;
453 double Fc_neg;
454 double Fs_pos;
455 double Fs_neg;
457
459{
463
464 std::vector<double> gearbox_M2J;
465 std::vector<double> gearbox_E2J;
466 std::vector<double> deadzone;
467
468 std::vector<kalmanFilterParams_t> kalman_params;
469 std::vector<std::unique_ptr<ITemperatureSensor>> temperatureSensorsVector;
470 std::vector<focBasedSpecificInfo_t> foc_based_info;
471
472 std::vector<encoder_t> jointEncs;
473 std::vector<encoder_t> motorEncs;
474
475 std::vector<rotorLimits_t> rotorsLimits;
476 std::vector<jointLimits_t> jointsLimits;
477 std::vector<motorCurrentLimits_t> currentLimits;
478 std::vector<temperatureLimits_t> temperatureLimits;
479
481 std::vector<JointsSet> jsets;
482 std::vector<int> joint2set;
483 std::vector<timeouts_t> timeouts;
484
485 std::vector<impedanceParameters_t> impedance_params;
486 std::vector<lugreParameters_t> lugre_params;
487 std::vector<impedanceLimits_t> impedance_limits;
488
490
491 std::vector<int> axisMap;
492 std::vector<axisInfo_t> axesInfo;
493
494 void resize(const int njoints)
495 {
496 gearbox_M2J.resize(njoints);
497 gearbox_E2J.resize(njoints);
498 deadzone.resize(njoints);
499
500 kalman_params.resize(njoints);
501 temperatureSensorsVector.resize(njoints);
502 foc_based_info.resize(njoints);
503
504 jointEncs.resize(njoints);
505 motorEncs.resize(njoints);
506
507 rotorsLimits.resize(njoints);
508 jointsLimits.resize(njoints);
509 currentLimits.resize(njoints);
510 temperatureLimits.resize(njoints);
511
512 jsets.resize(njoints);
513 joint2set.resize(njoints);
514 timeouts.resize(njoints);
515
516 impedance_params.resize(njoints);
517 lugre_params.resize(njoints);
518 impedance_limits.resize(njoints);
519
520 axisMap.resize(njoints);
521 axesInfo.resize(njoints);
522
523 pidControllers.trj.resize(njoints);
524 pidControllers.dir_pos.resize(njoints);
525 pidControllers.dir_vel.resize(njoints);
526 pidControllers.trq.resize(njoints);
527 pidControllers.cur.resize(njoints);
528 pidControllers.vel.resize(njoints);
529 pidControllers.mix.resize(njoints);
530 }
531
533 {
534 pidControllers.trj.clear();
535 pidControllers.dir_pos.clear();
536 pidControllers.dir_vel.clear();
537 pidControllers.trq.clear();
538 pidControllers.cur.clear();
539 pidControllers.vel.clear();
540 pidControllers.mix.clear();
541 }
542};
543
544
545 } // namespace eomc
546 } // namespace dev
547} // namespace yarp
548
549
550#endif
virtual double convertRawToTempCelsius(const double temperature)=0
virtual double convertTempCelsiusToRaw(const double temperature)=0
virtual motor_temperatureSensorTypeEnum_t getType()=0
eOmc_jointset_configuration_t * getConfiguration(void)
virtual double convertRawToTempCelsius(const double temperature) override
virtual double convertTempCelsiusToRaw(const double temperature) override
virtual motor_temperatureSensorTypeEnum_t getType() override
virtual double convertTempCelsiusToRaw(const double temperature) override
virtual motor_temperatureSensorTypeEnum_t getType() override
TemperatureSensorPT1000 & operator=(const TemperatureSensorPT1000 &other)=default
TemperatureSensorPT1000 & operator=(TemperatureSensorPT1000 &&other)=default
virtual double convertRawToTempCelsius(const double temperature) override
TemperatureSensorPT1000(const TemperatureSensorPT1000 &other)=default
TemperatureSensorPT1000(TemperatureSensorPT1000 &&other)=default
virtual double convertRawToTempCelsius(const double temperature) override
TemperatureSensorPT100(TemperatureSensorPT100 &&other)=default
TemperatureSensorPT100 & operator=(const TemperatureSensorPT100 &other)=default
TemperatureSensorPT100 & operator=(TemperatureSensorPT100 &&other)=default
virtual double convertTempCelsiusToRaw(const double temperature) override
TemperatureSensorPT100(const TemperatureSensorPT100 &other)=default
virtual motor_temperatureSensorTypeEnum_t getType() override
Copyright (C) 2008 RobotCub Consortium.
std::vector< focBasedSpecificInfo_t > foc_based_info
std::vector< lugreParameters_t > lugre_params
std::vector< temperatureLimits_t > temperatureLimits
std::vector< impedanceLimits_t > impedance_limits
std::vector< motorCurrentLimits_t > currentLimits
std::vector< std::unique_ptr< ITemperatureSensor > > temperatureSensorsVector
std::vector< kalmanFilterParams_t > kalman_params
std::vector< impedanceParameters_t > impedance_params
bool useRawEncoderData
its value depends on environment variable "ETH_VERBOSEWHENOK"
bool pwmIsLimited
if true than do not use calibration data
int resolution
Num of error bits passable for joint encoder.