iCub-main
utils.h
Go to the documentation of this file.
1 /*
2 * Copyright (C)2013 iCub Facility - Istituto Italiano di Tecnologia
3 * Author: Marco Randazzo
4 * email: marco.randazzo@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 #include <yarp/os/Network.h>
20 #include <yarp/os/Time.h>
21 #include <yarp/os/Log.h>
22 #include <yarp/os/LogStream.h>
23 #include <yarp/os/BufferedPort.h>
24 #include <yarp/sig/Vector.h>
25 #include <yarp/math/Math.h>
26 
27 #include <yarp/dev/ControlBoardInterfaces.h>
28 #include <yarp/dev/PolyDriver.h>
29 #include <yarp/os/PeriodicThread.h>
30 #include <yarp/os/Thread.h>
31 
32 #include <fstream>
33 #include <iostream>
34 #include <iomanip>
35 #include <string>
36 #include <vector>
37 #include <deque>
38 #include <map>
39 
40 using namespace std;
41 using namespace yarp::os;
42 using namespace yarp::sig;
43 using namespace yarp::dev;
44 using namespace yarp::math;
45 
46 #define VCTP_TIME yarp::os::createVocab('t','i','m','e')
47 #define VCTP_OFFSET yarp::os::createVocab('o','f','f')
48 #define VCTP_CMD_NOW yarp::os::createVocab('c','t','p','n')
49 #define VCTP_CMD_QUEUE yarp::os::createVocab('c','t','p','q')
50 #define VCTP_CMD_FILE yarp::os::createVocab('c','t','p','f')
51 #define VCTP_POSITION yarp::os::createVocab('p','o','s')
52 #define VCTP_WAIT yarp::os::createVocab('w','a','i','t')
53 
54 #define ACTION_IDLE 0
55 #define ACTION_START 1
56 #define ACTION_RUNNING 2
57 #define ACTION_STOP 3
58 #define ACTION_RESET 4
59 
60 // ******************** ACTION CLASS
62 {
63  int N_JOINTS;
64 public:
65  int counter;
66  double time;
67  double* q_joints;
68  string tag;
69 
70 public:
71  int get_n_joints();
72  action_struct(int n);
73  action_struct(const action_struct& as);
74  action_struct & operator=(const action_struct & as);
75  ~action_struct();
76 };
77 
79 {
80 public:
83  bool forever;
84  std::deque<action_struct> action_vector;
85  std::deque<action_struct>::iterator action_it;
86 
87  void clear();
88  action_class();
89  void print();
90  bool openFile(string filename, int n_joints);
91  bool parseCommandLineFixTime(const char* command_line, int line, double fixTime, int n_joints);
92  bool parseCommandLine(const char* command_line, int line, int n_joints);
93 };
94 
95 // ******************** ROBOT DRIVER CLASS
97 {
98  friend class BroadcastingThread;
99 private:
100  bool verbose;
101  bool drv_connected;
102  Property drvOptions_ll;
103  PolyDriver *drv_ll;
104  IPositionControl *ipos_ll;
105  IPositionDirect *iposdir_ll;
106  IPidControl *ipid_ll;
107  IControlMode *icmd_ll;
108  IEncoders *ienc_ll;
109  IMotorEncoders *imotenc_ll;
110 
111 public:
112  int n_joints;
113  std::map<int, int> joints_map;
114 
115 public:
116  robotDriver();
117  bool configure(const Property &copt);
118  bool init();
119  ~robotDriver();
120  bool setControlMode(const int j, const int mode);
121  bool setPosition(int j, double ref);
122  bool getEncoder(int j, double *v);
123  bool positionMove(int j, double ref);
124 };
size_t current_action
Definition: utils.h:81
STL namespace.
string tag
Definition: utils.h:68
std::map< int, int > joints_map
Definition: utils.h:113
std::deque< action_struct >::iterator action_it
Definition: utils.h:85
int n
std::deque< action_struct > action_vector
Definition: utils.h:84
static int v
Definition: iCub_Sim.cpp:42
int n_joints
Definition: utils.h:112
bool print(const pc104Data &pc104data)
Definition: ethParser.cpp:57
double time
Definition: utils.h:66
bool forever
Definition: utils.h:83
double * q_joints
Definition: utils.h:67
int counter
Definition: utils.h:65
int current_status
Definition: utils.h:82
GLenum mode
Definition: rendering.cpp:48