iCub-main
Loading...
Searching...
No Matches
controller.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 __CONTROLLER_H__
20#define __CONTROLLER_H__
21
22#include <mutex>
23#include <condition_variable>
24#include <string>
25#include <vector>
26#include <set>
27
28#include <yarp/os/all.h>
29#include <yarp/sig/all.h>
30#include <yarp/dev/all.h>
31#include <yarp/math/Math.h>
32
34#include <iCub/ctrl/pids.h>
35#include <iCub/utils.h>
36
37constexpr int32_t GAZECTRL_SWOFFCOND_DISABLESLOT = 10; // [-]
38constexpr double GAZECTRL_MOTIONDONE_NECK_QTHRES = 0.500; // [deg]
39constexpr double GAZECTRL_MOTIONDONE_EYES_QTHRES = 0.100; // [deg]
40constexpr double GAZECTRL_CRITICVER_STABILIZATION = 4.0; // [deg]
41
42using namespace std;
43using namespace yarp::os;
44using namespace yarp::dev;
45using namespace yarp::sig;
46using namespace yarp::math;
47using namespace iCub::ctrl;
48using namespace iCub::iKin;
49
50
51// The thread launched by the application which is
52// in charge of computing the control commands.
53class Controller : public GazeComponent, public PeriodicThread
54{
55protected:
59 PolyDriver *drvTorso, *drvHead;
60 IControlMode *modHead;
61 IPositionControl *posHead;
62 IVelocityControl *velHead;
63 IPositionDirect *posNeck;
65
71
72 BufferedPort<Vector> port_x;
73 BufferedPort<Vector> port_q;
74 BufferedPort<Bottle> port_event;
75 BufferedPort<Bottle> port_debug;
76 Stamp txInfo_x;
77 Stamp txInfo_q;
81
82 mutex mutexRun;
84 mutex mutexCtrl;
85 mutex mutexData;
86 mutex mutexLook;
88 condition_variable cv_eventLook;
89 unsigned int period;
100 double neckTime;
101 double eyesTime;
102 double pathPerc;
105 double q_stamp;
106 double Ts;
107
108 Matrix lim;
110 Vector v,vNeck,vEyes;
114 vector<int> jointsToSet;
115
116 multiset<double> motionOngoingEvents;
118
119 Vector computedxFP(const Matrix &H, const Vector &v, const Vector &w, const Vector &x_FP);
120 Vector computeNeckVelFromdxFP(const Vector &fp, const Vector &dfp);
121 Vector computeEyesVelFromdxFP(const Vector &dfp);
123 void setJointsCtrlMode();
124 void stopLimb(const bool execStopPosition=true);
125 void notifyEvent(const string &event, const double checkPoint=-1.0);
128 void stopControlHelper();
129
130public:
131 Controller(PolyDriver *_drvTorso, PolyDriver *_drvHead, ExchangeData *_commData,
132 const double _neckTime, const double _eyesTime,
133 const double _min_abs_vel, const unsigned int _period);
134 virtual ~Controller();
135
137 void minAllowedVergenceChanged() override;
138 void resetCtrlEyes();
139 void doSaccade(const Vector &ang, const Vector &vel);
140 bool look(const Vector &x);
141 void stopControl();
142 void printIter(Vector &xd, Vector &fp, Vector &qd, Vector &q, Vector &v, double printTime);
143 bool threadInit() override;
144 void threadRelease() override;
145 void afterStart(bool s) override;
146 void run() override;
147 void suspend();
148 void resume();
149 double getTneck() const;
150 double getTeyes() const;
151 void setTneck(const double execTime);
152 void setTeyes(const double execTime);
153 bool isMotionDone();
154 void setTrackingMode(const bool f);
155 bool getTrackingMode() const;
156 bool setGazeStabilization(const bool f);
157 bool getGazeStabilization() const;
158 bool getDesired(Vector &des);
159 bool getVelocity(Vector &vel);
160 bool getPose(const string &poseSel, Vector &x, Stamp &stamp);
161 bool registerMotionOngoingEvent(const double checkPoint);
162 bool unregisterMotionOngoingEvent(const double checkPoint);
164};
165
166
167#endif
168
169
bool unregisterMotionOngoingEvent(const double checkPoint)
iCubInertialSensor * imu
Definition controller.h:57
mutex mtx_eventLook
Definition controller.h:87
void stopControlHelper()
iKinChain * chainNeck
Definition controller.h:58
virtual ~Controller()
void stopLimb(const bool execStopPosition=true)
double eyesTime
Definition controller.h:101
Vector vNeck
Definition controller.h:110
bool setGazeStabilization(const bool f)
void setJointsCtrlMode()
BufferedPort< Bottle > port_event
Definition controller.h:74
double saccadeStartTime
Definition controller.h:98
bool getPose(const string &poseSel, Vector &x, Stamp &stamp)
double getTeyes() const
mutex mutexRun
Definition controller.h:82
void afterStart(bool s) override
bool reliableGyro
Definition controller.h:93
iKinChain * chainEyeR
Definition controller.h:58
void threadRelease() override
Vector qdEyes
Definition controller.h:111
Vector computedxFP(const Matrix &H, const Vector &v, const Vector &w, const Vector &x_FP)
void printIter(Vector &xd, Vector &fp, Vector &qd, Vector &q, Vector &v, double printTime)
double printAccTime
Definition controller.h:99
PolyDriver * drvHead
Definition controller.h:59
vector< int > neckJoints
Definition controller.h:113
void stopControl()
int nJointsHead
Definition controller.h:96
mutex mutexChain
Definition controller.h:83
minJerkVelCtrl * mjCtrlNeck
Definition controller.h:66
unsigned int period
Definition controller.h:89
Matrix lim
Definition controller.h:108
double startupMinVer
Definition controller.h:104
iKinChain * chainEyeL
Definition controller.h:58
bool ctrlInhibited
Definition controller.h:91
PolyDriver * drvTorso
Definition controller.h:59
mutex mutexCtrl
Definition controller.h:84
Vector computeEyesVelFromdxFP(const Vector &dfp)
void setTeyes(const double execTime)
bool areJointsHealthyAndSet()
Vector fbHead
Definition controller.h:112
void motionOngoingEventsFlush()
vector< int > jointsToSet
Definition controller.h:114
multiset< double > motionOngoingEvents
Definition controller.h:116
bool look(const Vector &x)
Vector fbEyes
Definition controller.h:112
void notifyEvent(const string &event, const double checkPoint=-1.0)
minJerkVelCtrl * mjCtrlEyes
Definition controller.h:67
void minAllowedVergenceChanged() override
void setTneck(const double execTime)
bool getVelocity(Vector &vel)
int nJointsTorso
Definition controller.h:95
void doSaccade(const Vector &ang, const Vector &vel)
Stamp txInfo_event
Definition controller.h:79
bool threadInit() override
mutex mutexLook
Definition controller.h:86
Vector fbNeck
Definition controller.h:112
Vector qdNeck
Definition controller.h:111
bool isMotionDone()
ExchangeData * commData
Definition controller.h:64
Vector vEyes
Definition controller.h:110
Vector qddeg
Definition controller.h:109
Vector q0
Definition controller.h:111
bool getDesired(Vector &des)
void findMinimumAllowedVergence()
vector< int > eyesJoints
Definition controller.h:113
void resetCtrlEyes()
Vector qd
Definition controller.h:111
IPositionControl * posHead
Definition controller.h:61
Integrator * IntState
Definition controller.h:68
Stamp txInfo_pose
Definition controller.h:78
void setTrackingMode(const bool f)
bool getGazeStabilization() const
Stamp txInfo_debug
Definition controller.h:80
double ctrlActiveRisingEdgeTime
Definition controller.h:97
void motionOngoingEventsHandling()
Stamp txInfo_x
Definition controller.h:76
Vector qdeg
Definition controller.h:109
BufferedPort< Vector > port_q
Definition controller.h:73
Integrator * IntStabilizer
Definition controller.h:70
IPositionDirect * posNeck
Definition controller.h:63
Vector fbTorso
Definition controller.h:112
IVelocityControl * velHead
Definition controller.h:62
Vector vdeg
Definition controller.h:109
IControlMode * modHead
Definition controller.h:60
double q_stamp
Definition controller.h:105
BufferedPort< Bottle > port_debug
Definition controller.h:75
Stamp txInfo_q
Definition controller.h:77
bool stabilizeGaze
Definition controller.h:94
double min_abs_vel
Definition controller.h:103
BufferedPort< Vector > port_x
Definition controller.h:72
void run() override
double pathPerc
Definition controller.h:102
bool unplugCtrlEyes
Definition controller.h:90
mutex mutexData
Definition controller.h:85
double getTneck() const
double Ts
Definition controller.h:106
double neckTime
Definition controller.h:100
iCubHeadCenter * neck
Definition controller.h:56
Integrator * IntPlan
Definition controller.h:69
multiset< double > motionOngoingEventsCurrent
Definition controller.h:117
Vector computeNeckVelFromdxFP(const Vector &fp, const Vector &dfp)
bool getTrackingMode() const
bool motionDone
Definition controller.h:92
condition_variable cv_eventLook
Definition controller.h:88
Bottle listMotionOngoingEvents()
bool registerMotionOngoingEvent(const double checkPoint)
A class for defining a saturated integrator based on Tustin formula: .
Definition pids.h:48
Abstract class for minimum-jerk controllers with velocity commands.
Definition minJerkCtrl.h:47
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 GAZECTRL_MOTIONDONE_EYES_QTHRES
Definition controller.h:39
constexpr int32_t GAZECTRL_SWOFFCOND_DISABLESLOT
Definition controller.h:37
constexpr double GAZECTRL_CRITICVER_STABILIZATION
Definition controller.h:40
constexpr double GAZECTRL_MOTIONDONE_NECK_QTHRES
Definition controller.h:38
static struct bpf_program fp