icub-basic-demos
robot_interfaces.cpp
1 /*
2  * Copyright (C) 2011 Department of Robotics Brain and Cognitive Sciences - Istituto Italiano di Tecnologia
3  * Author: Marco Randazzo
4  * email: marco.randazzo@iit.it
5  * Permission is granted to copy, distribute, and/or modify this program
6  * under the terms of the GNU General Public License, version 2 or any
7  * later version published by the Free Software Foundation.
8  *
9  * A copy of the license can be found at
10  * http://www.robotcub.org/icub/license/gpl.txt
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15  * Public License for more details
16 */
17 
18 #include "robot_interfaces.h"
19 #include <string>
20 
21 using namespace yarp::os;
22 using namespace yarp::dev;
23 using namespace iCub::skinDynLib;
24 
25 robot_interfaces::robot_interfaces()
26 {
27  bodyParts.resize(5);
28  bodyParts[0] = TORSO;
29  bodyParts[1] = LEFT_ARM;
30  bodyParts[2] = RIGHT_ARM;
31  bodyParts[3] = LEFT_LEG;
32  bodyParts[4] = RIGHT_LEG;
33 }
34 
35 robot_interfaces::robot_interfaces(iCub::skinDynLib::BodyPart bp1)
36 {
37  bodyParts.resize(1);
38  bodyParts[0] = bp1;
39 }
40 
41 robot_interfaces::robot_interfaces(iCub::skinDynLib::BodyPart bp1, iCub::skinDynLib::BodyPart bp2)
42 {
43  bodyParts.resize(2);
44  bodyParts[0] = bp1;
45  bodyParts[1] = bp2;
46 }
47 
48 robot_interfaces::robot_interfaces(iCub::skinDynLib::BodyPart bp1, iCub::skinDynLib::BodyPart bp2, iCub::skinDynLib::BodyPart bp3)
49 {
50  bodyParts.resize(3);
51  bodyParts[0] = bp1;
52  bodyParts[1] = bp2;
53  bodyParts[2] = bp3;
54 }
55 
56 robot_interfaces::robot_interfaces(iCub::skinDynLib::BodyPart bp1, iCub::skinDynLib::BodyPart bp2, iCub::skinDynLib::BodyPart bp3,
57  iCub::skinDynLib::BodyPart bp4)
58 {
59  bodyParts.resize(4);
60  bodyParts[0] = bp1;
61  bodyParts[1] = bp2;
62  bodyParts[2] = bp3;
63  bodyParts[3] = bp4;
64 }
65 
66 robot_interfaces::robot_interfaces(iCub::skinDynLib::BodyPart bp1, iCub::skinDynLib::BodyPart bp2, iCub::skinDynLib::BodyPart bp3,
67  iCub::skinDynLib::BodyPart bp4, iCub::skinDynLib::BodyPart bp5)
68 {
69  bodyParts.resize(5);
70  bodyParts[0] = bp1;
71  bodyParts[1] = bp2;
72  bodyParts[2] = bp3;
73  bodyParts[3] = bp4;
74  bodyParts[4] = bp5;
75 }
76 
77 robot_interfaces::robot_interfaces(iCub::skinDynLib::BodyPart *bps, int size)
78 {
79  bodyParts.resize(size);
80  for(int i=0; i<size; i++)
81  bodyParts[i] = bps[i];
82 }
83 
84 bool robot_interfaces::init()
85 {
86  std::string part;
87  std::string robot;
88  std::string localPort;
89  std::string remotePort;
90 
91  robot = "icub";
92  BodyPart i;
93  bool ok = true;
94  for (unsigned int iii=0; iii<bodyParts.size(); iii++)
95  {
96  i = bodyParts[iii];
97 
98  ipos[i]=0;
99  itrq[i]=0;
100  iimp[i]=0;
101  icmd[i]=0;
102  ienc[i]=0;
103  ipid[i]=0;
104  ivel[i]=0;
105  iamp[i]=0;
106  iint[i]=0;
107  idir[i]=0;
108  dd[i]=0;
109 
110  part = BodyPart_s[i];
111  localPort = "/demoForceControl/" + part;
112  remotePort = "/" + robot + "/" + part;
113  options[i].put("robot",robot);
114  options[i].put("part",part);
115  options[i].put("device","remote_controlboard");
116  options[i].put("local",localPort);
117  options[i].put("remote",remotePort);
118 
119  dd[i] = new PolyDriver(options[i]);
120  if(!dd[i] || !(dd[i]->isValid()))
121  {
122  yError("Problems instantiating the device driver %s\n", part.c_str());
123  }
124 
125  ok = ok & dd[i]->view(ipos[i]);
126  ok = ok & dd[i]->view(itrq[i]);
127  ok = ok & dd[i]->view(iimp[i]);
128  ok = ok & dd[i]->view(icmd[i]);
129  ok = ok & dd[i]->view(ivel[i]);
130  ok = ok & dd[i]->view(ienc[i]);
131  ok = ok & dd[i]->view(ipid[i]);
132  ok = ok & dd[i]->view(iamp[i]);
133  ok = ok & dd[i]->view(iint[i]);
134  ok = ok & dd[i]->view(idir[i]);
135  }
136  return ok;
137 }
138 
139