iCub-main
Loading...
Searching...
No Matches
eomcParser.h
Go to the documentation of this file.
1// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2
3
4/* Copyright (C) 2012 iCub Facility, Istituto Italiano di Tecnologia
5 * Author: Valentina Gaggero
6 * email: valentina.gaggero@iit.it
7 * Permission is granted to copy, distribute, and/or modify this program
8 * under the terms of the GNU General Public License, version 2 or any
9 * later version published by the Free Software Foundation.
10 *
11 * A copy of the license can be found at
12 * http://www.robotcub.org/icub/license/gpl.txt
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
17 * Public License for more details
18 */
19
20#ifndef __mcParserh__
21#define __mcParserh__
22
23#include <string>
24#include <string_view>
25#include <vector>
26#include <memory>
27
28#include <yarp/os/Bottle.h>
29#include <yarp/dev/ControlBoardInterfacesImpl.h>
30
33
34// - public #define --------------------------------------------------------------------------------------------------
35
36namespace yarp {
37 namespace dev {
38 namespace eomc {
39
40// Structure to track optional parameters and their defaults
41typedef struct
42{
43 std::string parameterName;
44 std::string defaultValue;
45 bool wasUsed;
47
48
65class Parser
66{
67
68private:
69 int _njoints;
70 std::string _boardname;
71
72 //these are the user selected control modes for each control type (one name per joint)
73 std::vector<std::string> _userNameControlPosition;
74 std::vector<std::string> _userNameControlVelocity;
75 std::vector<std::string> _userNameControlMixed;
76 std::vector<std::string> _userNameControlTorque;
77 std::vector<std::string> _userNameControlCurrent;
78 std::vector<std::string> _userNameControlPositionDirect;
79 std::vector<std::string> _userNameControlVelocityDirect;
80
81
82 // Track optional parameters and their defaults
83 std::vector<OptionalParameterInfo_t> _optionalParametersUsed;
84
85 const defaults::embObjMotionControlDefaults_t& _defaultSettings;
86
87
88 //general utils functions
89 bool extractGroup(yarp::os::Bottle &input, yarp::os::Bottle &out, const std::string &key1, const std::string &txt, int size, bool mandatory=true);
90 bool GetGroupBottle(yarp::os::Searchable &config, const std::string &groupName, yarp::os::Bottle &outBottle, bool mandatory=true);
91 inline bool isEquals(std::string_view s1, std::string_view s2)
92 {
93 if (s1.size() != s2.size())
94 {
95 return false;
96 }
97 return std::equal(s1.begin(), s1.end(),
98 s2.begin(), s2.end(),
99 [](unsigned char a, unsigned char b) {
100 return std::tolower(a) == std::tolower(b);
101 });
102 }
103
104 //PID parsing auxiliary functions
105
106 //auxiliary functions for parse the CONTROLS group in xml *_mc.xml
107 bool readUserNameControlsGroup(yarp::os::Searchable &config);
108 //from the pid group in xml file extracts the control law type
109 bool getOutputType(yarp::os::Bottle& pidsGroup, eOmc_ctrl_out_type_t &out_type);
110 //get from config file the values of the pids
111 bool readControlLaw(yarp::os::Bottle& pidsGroup, std::string &controlLaw_str);
112 //from the pid group in xml file extracts the pid units type (feedback and output)
113 bool parsePidUnitsType(yarp::os::Bottle& pidsGroup, eOmc_ctrl_out_type_t outType, yarp::dev::PidFeedbackUnitsEnum &fbk_pidunits, yarp::dev::PidOutputUnitsEnum& out_pidunits);
114
115 bool parseSelectedPositionControl(yarp::os::Searchable &config, std::vector<eomc::PidInfo> &pos_pids);
116 bool parseSelectedVelocityControl(yarp::os::Searchable &config, std::vector<eomc::PidInfo> &vel_pids);
117 bool parseSelectedMixedControl(yarp::os::Searchable &config, std::vector<eomc::PidInfo> &mix_pids);
118 bool parseSelectedTorqueControl(yarp::os::Searchable &config, std::vector<eomc::TrqPidInfo> &trq_pids);
119 bool parseSelectedPositionDirectControl(yarp::os::Searchable &config, std::vector<eomc::PidInfo> &posDir_pids);
120 bool parseSelectedVelocityDirectControl(yarp::os::Searchable &config, std::vector<eomc::PidInfo> &velDir_pids);
121 bool parseSelectedCurrentPid(yarp::os::Searchable &config, bool pidisMandatory, std::vector<eomc::PidInfo> &curr_pids);
122
123 bool areControlPidGroupEqualInJointSet(const std::vector<std::string> &controlGroup, const std::vector<int> &joint2set, const std::string &controlName);
124
125 bool parsePidsGroup2FOC(yarp::os::Bottle& pidsGroup, std::vector<eomc::PidInfo> &curr_pids);
139 bool parsePidsGroupMinimalParams(yarp::os::Bottle& pidsGroup, std::vector<eomc::PidInfo> &pids);
140
154 bool parsePidsGroupRegulationParams(yarp::os::Bottle& pidsGroup, std::vector<eomc::PidInfo> &pids);
155 bool parsePidsGroupRegulationParams(yarp::os::Bottle& pidsGroup, std::vector<eomc::TrqPidInfo> &pids);
156
173 bool parsePidsGroupTorqueCompensationParams(yarp::os::Bottle& pidsGroup, std::vector<eomc::TrqPidInfo> &pids);
174
175 //bool checkJointTypes(PidInfo *pids, const std::string &pid_type);
176 //bool checkSinglePid(PidInfo &firstPid, PidInfo &currentPid, const int &firstjoint, const int &currentjoint, const std::string &pid_type);
177
178 //jointset parsing auxiliary functions
179 bool convert(std::string const &fromstring, eOmc_jsetconstraint_t &jsetconstraint, bool& formaterror);
180 bool convert(yarp::os::Bottle &bottle, std::vector<double> &matrix, bool &formaterror, int targetsize);
181
182
183
184
185 template <class T>
186 bool checkAndSetVectorSize(std::vector<T> &vec, int size, const std::string &funcName)
187 {
188 if(size > (int)vec.capacity())
189 {
190 yError() << "embObjMC BOARD " << _boardname << " in " << funcName.c_str() << ": try to insert " << size << "element in vector with " << vec.capacity() << " elements";
191 return false;
192 }
193
194 vec.resize(size);
195 return true;
196 }
197
198 // ///////// DEBUG FUNCTIONS
199 // void debugUtil_printControlLaws(void);
200
201
202public:
203 Parser(int numofjoints, std::string boardname);
204 ~Parser();
205
206 bool parsePids(yarp::os::Searchable &config, PidControllers_t &pids, bool lowLevPidisMandatory);
207 bool parseFocGroup(yarp::os::Searchable &config, std::vector<focBasedSpecificInfo_t>& foc_based_info, std::string groupName, std::vector<std::unique_ptr<eomc::ITemperatureSensor>>& temperatureSensorsVector);
208 bool parseJointsetCfgGroup(yarp::os::Searchable &config, std::vector<JointsSet> &jsets, std::vector<int> &jointtoset);
209 bool parseTimeoutsGroup(yarp::os::Searchable &config, std::vector<timeouts_t> &timeouts);
210 bool parseCurrentLimits(yarp::os::Searchable &config, std::vector<motorCurrentLimits_t> &currLimits);
211
212 // temperatureLimits array has to be initialized correctly before calling this function
213 bool parseTemperatureLimits(yarp::os::Searchable &config, std::vector<temperatureLimits_t> &temperatureLimits);
214
215 // temperatureLimits array has to be initialized correctly before calling this function
216 bool parseJointsLimits(yarp::os::Searchable &config, std::vector<jointLimits_t> &jointsLimits);
217
218 bool parseRotorsLimits(yarp::os::Searchable &config, std::vector<rotorLimits_t> &rotorsLimits);
219 bool parseCouplingInfo(yarp::os::Searchable &config, couplingInfo_t &couplingInfo);
220 bool parseMotioncontrolVersion(yarp::os::Searchable &config, int &version);
221 bool parseBehaviourFalgs(yarp::os::Searchable &config, bool &useRawEncoderData, bool &pwmIsLimited);
222 bool isVerboseEnabled(yarp::os::Searchable &config);
223 bool parseAxisInfo(yarp::os::Searchable &config, int axisMap[], std::vector<axisInfo_t> &axisInfo);
224 bool parseEncoderFactor(yarp::os::Searchable &config, double encoderFactor[]);
225 bool parsefullscalePWM(yarp::os::Searchable &config, double dutycycleToPWM[]);
226 bool parseAmpsToSensor(yarp::os::Searchable &config, double ampsToSensor[]);
227 bool parseGearboxValues(yarp::os::Searchable &config, double gearbox_M2J[], double gearbox_E2J[]);
228 bool parseUseMotorSpeedFbkFlags(yarp::os::Searchable &config, int useMotorSpeedFbk[]);
229 bool parseImpedanceGroup(yarp::os::Searchable &config,std::vector<impedanceParameters_t> &impedance);
230 bool parseLugreGroup(yarp::os::Searchable &config,std::vector<lugreParameters_t> &lugre);
231 bool parseDeadzoneValue(yarp::os::Searchable &config, double deadzone[], bool *found);
232 bool parseKalmanFilterParams(yarp::os::Searchable &config, std::vector<kalmanFilterParams_t> &kalmanFilterParams);
233 bool parseMaintenanceModeGroup(yarp::os::Searchable &config, bool &skipRecalibrationEnabled);
234
235 // Methods for tracking optional parameters
236 void registerOptionalParameter(std::string_view paramName, std::string_view defaultValue, bool wasUsed);
239
240};
241
242}}}; //close namespaces
243
244#endif // include guard
bool parseJointsetCfgGroup(yarp::os::Searchable &config, std::vector< JointsSet > &jsets, std::vector< int > &jointtoset)
bool parseJointsLimits(yarp::os::Searchable &config, std::vector< jointLimits_t > &jointsLimits)
bool parseUseMotorSpeedFbkFlags(yarp::os::Searchable &config, int useMotorSpeedFbk[])
bool parseMaintenanceModeGroup(yarp::os::Searchable &config, bool &skipRecalibrationEnabled)
bool parseAmpsToSensor(yarp::os::Searchable &config, double ampsToSensor[])
bool parseFocGroup(yarp::os::Searchable &config, std::vector< focBasedSpecificInfo_t > &foc_based_info, std::string groupName, std::vector< std::unique_ptr< eomc::ITemperatureSensor > > &temperatureSensorsVector)
Parser(int numofjoints, std::string boardname)
bool parseMotioncontrolVersion(yarp::os::Searchable &config, int &version)
bool parseLugreGroup(yarp::os::Searchable &config, std::vector< lugreParameters_t > &lugre)
bool parseAxisInfo(yarp::os::Searchable &config, int axisMap[], std::vector< axisInfo_t > &axisInfo)
void registerOptionalParameter(std::string_view paramName, std::string_view defaultValue, bool wasUsed)
bool parseTimeoutsGroup(yarp::os::Searchable &config, std::vector< timeouts_t > &timeouts)
bool parseCouplingInfo(yarp::os::Searchable &config, couplingInfo_t &couplingInfo)
bool parseTemperatureLimits(yarp::os::Searchable &config, std::vector< temperatureLimits_t > &temperatureLimits)
bool parsePids(yarp::os::Searchable &config, PidControllers_t &pids, bool lowLevPidisMandatory)
bool parseDeadzoneValue(yarp::os::Searchable &config, double deadzone[], bool *found)
bool isVerboseEnabled(yarp::os::Searchable &config)
bool parseCurrentLimits(yarp::os::Searchable &config, std::vector< motorCurrentLimits_t > &currLimits)
bool parseEncoderFactor(yarp::os::Searchable &config, double encoderFactor[])
bool parsefullscalePWM(yarp::os::Searchable &config, double dutycycleToPWM[])
bool parseRotorsLimits(yarp::os::Searchable &config, std::vector< rotorLimits_t > &rotorsLimits)
bool parseImpedanceGroup(yarp::os::Searchable &config, std::vector< impedanceParameters_t > &impedance)
bool parseKalmanFilterParams(yarp::os::Searchable &config, std::vector< kalmanFilterParams_t > &kalmanFilterParams)
bool parseGearboxValues(yarp::os::Searchable &config, double gearbox_M2J[], double gearbox_E2J[])
bool parseBehaviourFalgs(yarp::os::Searchable &config, bool &useRawEncoderData, bool &pwmIsLimited)
Copyright (C) 2008 RobotCub Consortium.
out
Definition sine.m:8
Structure containing all default values used in embObjMotionControl and eomcParser classes.