funny-things
All Modules
iCubBreatherThread.h
1/*
2 * Copyright (C) 2010 RobotCub Consortium, European Commission FP6 Project IST-004370
3 * Author: Alessandro Roncone
4 * email: 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 * This thread detects a touched taxel on the skin (through readings from the
18 * skinContactList port), and it moves the "controlateral" limb toward
19 * the affected taxel.
20*/
21
22#include <yarp/os/all.h>
23
24#include <yarp/sig/Vector.h>
25
26#include <yarp/dev/PolyDriver.h>
27#include <yarp/dev/Drivers.h>
28#include <yarp/dev/all.h>
29
30#include <yarp/math/RandnScalar.h>
31
32#include <mutex>
33#include <iostream>
34#include <string>
35#include <cstdarg>
36#include <vector>
37
38using namespace yarp::os;
39using namespace yarp::sig;
40using namespace yarp::dev;
41
42using namespace std;
43
44class iCubBreatherThread: public PeriodicThread
45{
46protected:
47 /***************************************************************************/
48 // EXTERNAL VARIABLES: change them from command line or through .ini file
49 int verbosity; // Flag that manages verbosity
50 string name; // Name of the module (to change port names accordingly)
51 string robot; // Name of the robot (to address both icub and icubSim)
52 string part; // Arm to control (either "right_arm" or "left_arm")
53 double noiseStd;
54 double refSpeed;
55 double rate;
56
57 // Classical interfaces
58 PolyDriver dd; // head device driver
59 IPositionControl *ipos;
60 IEncoders *iencs;
61 IControlMode *imod;
62 Vector *encs;
63 Vector encs_0;
64 int jnts;
65
66 bool isRunning;
67 bool onStart;
68
69 yarp::os::Bottle groupPartBottle;
70 std::vector <double> noiseStDvtns;
71 std::vector <double> refSpeeds;
72
73 mutex mtx;
74 yarp::math::RandnScalar randngen;
75
81 bool setCtrlModes(const string &_s);
82
89 bool areJointsHealthyAndSet(vector<int> &jointsToSet,const string &_s);
90
95 bool goHome();
96
97 bool goToTarget(const Vector &nT);
98
99 Vector computeNewTarget();
100
106 int printMessage(const int l, const char *f, ...) const;
107
108public:
109 // CONSTRUCTOR
110 iCubBreatherThread(int _rate, string _name, string _robot,
111 string _part, bool _autoStart, double _noiseStd,
112 double _refSpeed, int _v, const ResourceFinder &_rf);
113 // INIT
114 virtual bool threadInit();
115 // RUN
116 virtual void run();
117 // RELEASE
118 virtual void threadRelease();
119 // RESTART THE CYCLE
120 bool startBreathing();
121 bool stopBreathing();
122};