iCub-main
Loading...
Searching...
No Matches
solver.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010 RobotCub Consortium, European Commission FP6 Project IST-004370
3 * Author: Ugo Pattacini, Alessandro Roncone
4 * email: ugo.pattacini@iit.it, alessandro.roncone@iit.it
5 * website: www.robotcub.org
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 __SOLVER_H__
20#define __SOLVER_H__
21
22#include <mutex>
23#include <string>
24
25#include <yarp/os/all.h>
26#include <yarp/sig/all.h>
27#include <yarp/dev/all.h>
28#include <yarp/math/Math.h>
29
30#include <iCub/ctrl/pids.h>
32#include <iCub/gazeNlp.h>
33#include <iCub/utils.h>
34#include <iCub/localizer.h>
35#include <iCub/controller.h>
36
37constexpr double EYEPINVREFGEN_GAIN = 12.5; // [-]
38constexpr double SACCADES_VEL = 1000.0; // [deg/s]
39constexpr double SACCADES_INHIBITION_PERIOD = 0.2; // [s]
40constexpr double SACCADES_ACTIVATION_ANGLE = 10.0; // [deg]
41constexpr double NECKSOLVER_ACTIVATIONDELAY = 0.25; // [s]
42constexpr double NECKSOLVER_ACTIVATIONANGLE_JOINTS = 0.5; // [deg/s]
43constexpr double NECKSOLVER_ACTIVATIONANGLE = 2.5; // [deg]
44constexpr double NECKSOLVER_RESTORINGANGLE = 5.0; // [deg]
45
46using namespace std;
47using namespace yarp::os;
48using namespace yarp::dev;
49using namespace yarp::sig;
50using namespace yarp::math;
51using namespace iCub::ctrl;
52using namespace iCub::iKin;
53
54
55// The thread launched by the application which computes
56// the eyes target position relying on the pseudoinverse
57// method.
58class EyePinvRefGen : public GazeComponent, public PeriodicThread
59{
60protected:
64 PolyDriver *drvTorso, *drvHead;
68 mutex mtx;
69
74
75 unsigned int period;
77 bool genOn;
83 double Ts;
84
85 Matrix orig_lim,lim;
86 Vector fbTorso;
87 Vector fbHead;
88 Vector qd,fp;
89 Matrix eyesJ;
91
92 Vector getEyesCounterVelocity(const Matrix &eyesJ, const Vector &fp);
93
94public:
95 EyePinvRefGen(PolyDriver *_drvTorso, PolyDriver *_drvHead, ExchangeData *_commData,
96 Controller *_ctrl, const Vector &_counterRotGain, const unsigned int _period);
97 virtual ~EyePinvRefGen();
98
99 void enable() { genOn=true; }
100 void disable() { genOn=false; }
101 Vector getCounterRotGain();
102 void setCounterRotGain(const Vector &gain);
103 void minAllowedVergenceChanged() override;
104 bool bindEyes(const double ver);
105 bool clearEyes();
106 void manageBindEyes(const double ver);
107 bool threadInit() override;
108 void threadRelease() override;
109 void afterStart(bool s) override;
110 void run() override;
111 void suspend();
112 void resume();
113};
114
115
116// The thread launched by the application which is
117// in charge of inverting the head kinematic relying
118// on IPOPT computation.
119class Solver : public GazeComponent, public PeriodicThread
120{
121protected:
126 PolyDriver *drvTorso, *drvHead;
131 mutex mtx;
132
133 unsigned int period;
137 double Ts;
138
139 Vector fbTorso;
140 Vector fbHead;
141 Vector neckPos;
142 Vector gazePos;
143
145
152
153 void updateAngles();
154 Vector computeTargetUserTolerance(const Vector &xd);
155
156public:
157 Solver(PolyDriver *_drvTorso, PolyDriver *_drvHead, ExchangeData *_commData,
158 EyePinvRefGen *_eyesRefGen, Localizer *_loc, Controller *_ctrl,
159 const unsigned int _period);
160 virtual ~Solver();
161
162 // Returns a measure of neck angle required to reach the target
163 double neckTargetRotAngle(const Vector &xd);
164 void bindNeckPitch(const double min_deg, const double max_deg);
165 void bindNeckRoll(const double min_deg, const double max_deg);
166 void bindNeckYaw(const double min_deg, const double max_deg);
167 void getCurNeckPitchRange(double &min_deg, double &max_deg);
168 void getCurNeckRollRange(double &min_deg, double &max_deg);
169 void getCurNeckYawRange(double &min_deg, double &max_deg);
170 void clearNeckPitch();
171 void clearNeckRoll();
172 void clearNeckYaw();
173 double getNeckAngleUserTolerance() const;
174 void setNeckAngleUserTolerance(const double angle);
175 bool threadInit() override;
176 void threadRelease() override;
177 void afterStart(bool s) override;
178 void run() override;
179 void suspend();
180 void resume();
181};
182
183
184#endif
185
186
iCubInertialSensor * imu
Definition solver.h:62
double eyesHalfBaseline
Definition solver.h:82
Vector counterRotGain
Definition solver.h:90
mutex mtx
Definition solver.h:68
double orig_eye_pan_max
Definition solver.h:73
Integrator * I
Definition solver.h:67
iKinChain * chainNeck
Definition solver.h:63
void run() override
Definition solver.cpp:301
void minAllowedVergenceChanged() override
Definition solver.cpp:136
bool saccadeUnderWayOld
Definition solver.h:76
bool clearEyes()
Definition solver.cpp:182
Vector getCounterRotGain()
Definition solver.cpp:218
void afterStart(bool s) override
Definition solver.cpp:291
PolyDriver * drvTorso
Definition solver.h:64
void manageBindEyes(const double ver)
Definition solver.cpp:210
void enable()
Definition solver.h:99
Matrix lim
Definition solver.h:85
bool bindEyes(const double ver)
Definition solver.cpp:146
ExchangeData * commData
Definition solver.h:65
int nJointsTorso
Definition solver.h:78
Vector fbTorso
Definition solver.h:86
void threadRelease() override
Definition solver.cpp:285
void suspend()
Definition solver.cpp:444
Vector fbHead
Definition solver.h:87
double orig_eye_tilt_max
Definition solver.h:71
Controller * ctrl
Definition solver.h:66
iKinChain * chainEyeR
Definition solver.h:63
bool threadInit() override
Definition solver.cpp:273
double orig_eye_tilt_min
Definition solver.h:70
void disable()
Definition solver.h:100
Vector fp
Definition solver.h:88
Vector getEyesCounterVelocity(const Matrix &eyesJ, const Vector &fp)
Definition solver.cpp:237
iKinChain * chainEyeL
Definition solver.h:63
iCubHeadCenter * neck
Definition solver.h:61
virtual ~EyePinvRefGen()
Definition solver.cpp:125
double saccadesClock
Definition solver.h:81
bool genOn
Definition solver.h:77
void setCounterRotGain(const Vector &gain)
Definition solver.cpp:226
PolyDriver * drvHead
Definition solver.h:64
Vector qd
Definition solver.h:88
void resume()
Definition solver.cpp:452
Matrix orig_lim
Definition solver.h:85
int nJointsHead
Definition solver.h:79
double orig_eye_pan_min
Definition solver.h:72
double Ts
Definition solver.h:83
unsigned int period
Definition solver.h:75
Matrix eyesJ
Definition solver.h:89
int saccadesRxTargets
Definition solver.h:80
unsigned int period
Definition solver.h:133
void threadRelease() override
Definition solver.cpp:757
void run() override
Definition solver.cpp:774
PolyDriver * drvHead
Definition solver.h:126
void bindNeckPitch(const double min_deg, const double max_deg)
Definition solver.cpp:569
void getCurNeckYawRange(double &min_deg, double &max_deg)
Definition solver.cpp:629
void clearNeckYaw()
Definition solver.cpp:660
double neckRollMin
Definition solver.h:148
Controller * ctrl
Definition solver.h:130
int nJointsHead
Definition solver.h:135
bool threadInit() override
Definition solver.cpp:731
iCubHeadCenter * neck
Definition solver.h:122
ExchangeData * commData
Definition solver.h:127
void getCurNeckPitchRange(double &min_deg, double &max_deg)
Definition solver.cpp:611
mutex mtx
Definition solver.h:131
double neckPitchMin
Definition solver.h:146
EyePinvRefGen * eyesRefGen
Definition solver.h:128
void suspend()
Definition solver.cpp:872
iKinChain * chainNeck
Definition solver.h:124
double neckYawMin
Definition solver.h:150
void clearNeckRoll()
Definition solver.cpp:649
Vector fbHead
Definition solver.h:140
Vector computeTargetUserTolerance(const Vector &xd)
Definition solver.cpp:708
Vector neckPos
Definition solver.h:141
iKinChain * chainEyeR
Definition solver.h:124
double getNeckAngleUserTolerance() const
Definition solver.cpp:671
void updateAngles()
Definition solver.cpp:685
double neckTargetRotAngle(const Vector &xd)
Definition solver.cpp:697
iKinChain * chainEyeL
Definition solver.h:124
void bindNeckYaw(const double min_deg, const double max_deg)
Definition solver.cpp:597
void clearNeckPitch()
Definition solver.cpp:638
double Ts
Definition solver.h:137
iCubInertialSensor * imu
Definition solver.h:123
double neckAngleUserTolerance
Definition solver.h:136
void setNeckAngleUserTolerance(const double angle)
Definition solver.cpp:678
int nJointsTorso
Definition solver.h:134
PolyDriver * drvTorso
Definition solver.h:126
virtual ~Solver()
Definition solver.cpp:557
void resume()
Definition solver.cpp:881
Localizer * loc
Definition solver.h:129
void getCurNeckRollRange(double &min_deg, double &max_deg)
Definition solver.cpp:620
GazeIpOptMin * invNeck
Definition solver.h:125
Vector fbTorso
Definition solver.h:139
double neckYawMax
Definition solver.h:151
void afterStart(bool s) override
Definition solver.cpp:764
double neckRollMax
Definition solver.h:149
double neckPitchMax
Definition solver.h:147
Vector gazePos
Definition solver.h:142
AWLinEstimator * torsoVel
Definition solver.h:144
void bindNeckRoll(const double min_deg, const double max_deg)
Definition solver.cpp:583
Adaptive window linear fitting to estimate the first derivative.
A class for defining a saturated integrator based on Tustin formula: .
Definition pids.h:48
A class for describing the kinematic of the straight line coming out from the point located between t...
Definition iKinFwd.h:1450
A class for defining the Inertia Sensor Kinematics of the iCub.
Definition iKinFwd.h:1476
A Base class for defining a Serial Link Chain.
Definition iKinFwd.h:354
constexpr double NECKSOLVER_ACTIVATIONANGLE_JOINTS
Definition solver.h:42
constexpr double SACCADES_VEL
Definition solver.h:38
constexpr double SACCADES_ACTIVATION_ANGLE
Definition solver.h:40
constexpr double NECKSOLVER_RESTORINGANGLE
Definition solver.h:44
constexpr double EYEPINVREFGEN_GAIN
Definition solver.h:37
constexpr double SACCADES_INHIBITION_PERIOD
Definition solver.h:39
constexpr double NECKSOLVER_ACTIVATIONANGLE
Definition solver.h:43
constexpr double NECKSOLVER_ACTIVATIONDELAY
Definition solver.h:41