iCub-main
Loading...
Searching...
No Matches
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
40using namespace std;
41using namespace yarp::os;
42using namespace yarp::sig;
43using namespace yarp::dev;
44using namespace yarp::math;
45
46#define VCTP_TIME yarp::os::createVocab32('t','i','m','e')
47#define VCTP_OFFSET yarp::os::createVocab32('o','f','f')
48#define VCTP_CMD_NOW yarp::os::createVocab32('c','t','p','n')
49#define VCTP_CMD_QUEUE yarp::os::createVocab32('c','t','p','q')
50#define VCTP_CMD_FILE yarp::os::createVocab32('c','t','p','f')
51#define VCTP_POSITION yarp::os::createVocab32('p','o','s')
52#define VCTP_WAIT yarp::os::createVocab32('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;
64public:
66 double time;
67 double* q_joints;
68 string tag;
69
70public:
71 int get_n_joints();
72 action_struct(int n);
76};
77
79{
80public:
83 bool forever;
84 std::deque<action_struct> action_vector;
85 std::deque<action_struct>::iterator action_it;
86
87 void clear();
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;
99private:
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
111public:
113 std::map<int, int> joints_map;
114
115public:
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};
std::deque< action_struct >::iterator action_it
Definition utils.h:85
bool parseCommandLineFixTime(const char *command_line, int line, double fixTime, int n_joints)
Definition utils.cpp:159
void clear()
Definition utils.cpp:100
bool parseCommandLine(const char *command_line, int line, int n_joints)
Definition utils.cpp:203
void print()
Definition utils.cpp:113
std::deque< action_struct > action_vector
Definition utils.h:84
bool forever
Definition utils.h:83
size_t current_action
Definition utils.h:81
int current_status
Definition utils.h:82
bool openFile(string filename, int n_joints)
Definition utils.cpp:124
int get_n_joints()
Definition utils.cpp:49
action_struct & operator=(const action_struct &as)
Definition utils.cpp:75
double * q_joints
Definition utils.h:67
int counter
Definition utils.h:65
double time
Definition utils.h:66
string tag
Definition utils.h:68
std::map< int, int > joints_map
Definition utils.h:113
bool setPosition(int j, double ref)
Definition utils.cpp:327
int n_joints
Definition utils.h:112
bool setControlMode(const int j, const int mode)
Definition utils.cpp:321
bool getEncoder(int j, double *v)
Definition utils.cpp:333
bool configure(const Property &copt)
Definition utils.cpp:256
bool init()
Definition utils.cpp:281
bool positionMove(int j, double ref)
Definition utils.cpp:339
int n