iCub-main
genericControlBoardDumper.cpp
Go to the documentation of this file.
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 /*
4  * Copyright (C) 2010 RobotCub Consortium, European Commission FP6 Project IST-004370
5  * Author: Francesco Nori
6  * email: francesco.nori@iit.it
7  * website: www.robotcub.org
8  * Permission is granted to copy, distribute, and/or modify this program
9  * under the terms of the GNU General Public License, version 2 or any
10  * later version published by the Free Software Foundation.
11  *
12  * A copy of the license can be found at
13  * http://www.robotcub.org/icub/license/gpl.txt
14  *
15  * This program is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
18  * Public License for more details
19 */
20 
22 
24 {
25  myIstmp=NULL;
26 }
27 
28 bool GetData::getStamp(Stamp &stmp)
29 {
30  if (myIstmp != NULL)
31  {
32  stmp = myIstmp->getLastInputStamp();
33  return true;
34  }
35  else
36  {
37  return false;
38  }
39 }
40 
41 void GetData::setStamp(IPreciselyTimed *iStmp)
42 {
43  myIstmp=iStmp;
44 }
45 
46 void GetEncs::setInterface(IEncoders *i)
47 {
48  iencs = i;
49 }
50 
51 bool GetEncs::getData(double *e)
52 {
53  //fprintf(stderr, "Entering getEncs\n");
54  if (iencs)
55  {
56  while(!iencs->getEncoders(e))
57  fprintf(stderr, "Getting bad encoders! \n");
58  return 1;
59  }
60  else
61  {
62  fprintf(stderr, "Interface is not ready! \n");
63  return 0;
64  }
65 }
66 
67 void GetPidRefs::setInterface(IPidControl *i)
68 {
69  ipid = i;
70 }
71 
72 bool GetPidRefs::getData(double *e)
73 {
74  //fprintf(stderr, "Entering getPosErrs\n");
75  if (ipid)
76  {
77  ipid->getPidReferences(VOCAB_PIDTYPE_POSITION, e);
78  return 1;
79  }
80  else
81  return 0;
82 }
83 
84 void GetSpeeds::setInterface(IEncoders *i)
85 {
86  iencs = i;
87 }
88 
89 bool GetSpeeds::getData(double *e)
90 {
91  //fprintf(stderr, "Entering getSpeeds\n");
92  if (iencs)
93  {
94  iencs->getEncoderSpeeds(e);
95  return 1;
96  }
97  else
98  return 0;
99 }
100 
101 void GetAccs::setInterface(IEncoders *i)
102 {
103  iencs = i;
104 }
105 
106 bool GetAccs::getData(double *e)
107 {
108  //fprintf(stderr, "Entering getAccs\n");
109  if (iencs)
110  {
111  iencs->getEncoderAccelerations(e);
112  return 1;
113  }
114  else
115  return 0;
116 }
117 
118 void GetPosErrs::setInterface(IPidControl *i)
119 {
120  ipid = i;
121 }
122 
123 bool GetPosErrs::getData(double *e)
124 {
125  //fprintf(stderr, "Entering getPosErrs\n");
126  if (ipid)
127  {
128  ipid->getPidErrors(VOCAB_PIDTYPE_POSITION,e);
129  return 1;
130  }
131  else
132  return 0;
133 }
134 
135 void GetOuts::setInterface(IPidControl *i)
136 {
137  ipid = i;
138 }
139 
140 bool GetOuts::getData(double *e)
141 {
142  //fprintf(stderr, "Entering getOuts\n");
143  if (ipid)
144  {
145  ipid->getPidOutputs(VOCAB_PIDTYPE_POSITION,e);
146  return 1;
147  }
148  else
149  return 0;
150 }
151 
152 void GetCurrs::setInterface(IAmplifierControl *i)
153 {
154  iamp = i;
155 }
156 
157 bool GetCurrs::getData(double *e)
158 {
159  //fprintf(stderr, "Entering getOuts\n");
160  if (iamp)
161  {
162  iamp->getCurrents(e);
163  return 1;
164  }
165  else
166  return 0;
167 }
168 
169 void GetTrqs::setInterface(ITorqueControl *i)
170 {
171  itrq = i;
172 }
173 
174 bool GetTrqs::getData(double *e)
175 {
176  //fprintf(stderr, "Entering getTrqs\n");
177  if (itrq)
178  {
179  itrq->getTorques(e);
180  return 1;
181  }
182  else
183  return 0;
184 }
185 
186 void GetControlModes::setInterface(IControlMode *i, int n_joints)
187 {
188  icmd = i;
189  nj=n_joints;
190 }
191 
193 {
194  //fprintf(stderr, "Entering getTrqs\n");
195  int tmp [50];
196  if (icmd)
197  {
198  icmd->getControlModes(tmp);
199  for (int i=0; i<nj; i++)
200  {
201  if (tmp[i] == VOCAB_CM_POSITION) e[i] = 0;
202  else if (tmp[i] == VOCAB_CM_POSITION_DIRECT) e[i] = 1;
203  else if (tmp[i] == VOCAB_CM_VELOCITY) e[i] = 2;
204  else if (tmp[i] == VOCAB_CM_MIXED) e[i] = 3;
205  else if (tmp[i] == VOCAB_CM_TORQUE) e[i] = 4;
206  else if (tmp[i] == VOCAB_CM_PWM) e[i] = 5;
207  else if (tmp[i] == VOCAB_CM_IDLE) e[i] = 6;
208  else e[i] =-1;
209  }
210  return 1;
211  }
212  else
213  return 0;
214 }
215 
216 void GetInteractionModes::setInterface(IInteractionMode *i, int n_joints)
217 {
218  iint = i;
219  nj=n_joints;
220 }
221 
223 {
224  //fprintf(stderr, "Entering getTrqs\n");
225  yarp::dev::InteractionModeEnum tmp[50];
226  if (iint)
227  {
228  iint->getInteractionModes(tmp);
229  for (int i=0; i<nj; i++)
230  {
231  if (tmp[i] == VOCAB_IM_STIFF) e[i] = 0;
232  else if (tmp[i] == VOCAB_IM_COMPLIANT) e[i] = 1;
233  else e[i] =-1;
234  }
235  return 1;
236  }
237  else
238  return 0;
239 }
240 
241 void GetTrqErrs::setInterface(IPidControl *i)
242 {
243  ipid = i;
244 }
245 
246 bool GetTrqErrs::getData(double *e)
247 {
248  //fprintf(stderr, "Entering getTrqErrs\n");
249  if (ipid)
250  {
251  ipid->getPidErrors(VOCAB_PIDTYPE_TORQUE,e);
252  return 1;
253  }
254  else
255  return 0;
256 }
257 
258 void GetTrqRefs::setInterface(ITorqueControl *i)
259 {
260  itrq = i;
261 }
262 
263 bool GetTrqRefs::getData(double *e)
264 {
265  //fprintf(stderr, "Entering getTrqRefs\n");
266  if (itrq)
267  {
268  itrq->getRefTorques(e);
269  return 1;
270  }
271  else
272  return 0;
273 }
274 
275 void GetMotEncs::setInterface(IMotorEncoders *i)
276 {
277  imotencs = i;
278 }
279 
280 bool GetMotEncs::getData(double *e)
281 {
282  if (imotencs)
283  {
284  while(!imotencs->getMotorEncoders(e))
285  fprintf(stderr, "Getting bad motor encoders! \n");
286  return 1;
287  }
288  else
289  {
290  fprintf(stderr, "Interface is not ready! \n");
291  return 0;
292  }
293 }
294 
295 
296 void GetTemps::setInterface(IMotor *i)
297 {
298  imot = i;
299 }
300 
301 bool GetTemps::getData(double *temp)
302 {
303  if (imot)
304  {
305  while(!imot->getTemperatures(temp))
306  fprintf(stderr, "Getting bad motortemperatures! \n");
307  return 1;
308  }
309  else
310  {
311  fprintf(stderr, "Interface is not ready! \n");
312  return 0;
313  }
314 }
315 
316 void GetMotSpeeds::setInterface(IMotorEncoders *i)
317 {
318  imotencs = i;
319 }
320 
322 {
323  if (imotencs)
324  {
325  while(!imotencs->getMotorEncoderSpeeds(e))
326  fprintf(stderr, "Getting bad motor encoders! \n");
327  return 1;
328  }
329  else
330  {
331  fprintf(stderr, "Interface is not ready! \n");
332  return 0;
333  }
334 }
335 
336 void GetMotAccs::setInterface(IMotorEncoders *i)
337 {
338  imotencs = i;
339 }
340 
341 bool GetMotAccs::getData(double *e)
342 {
343  if (imotencs)
344  {
345  while(!imotencs->getMotorEncoderAccelerations(e))
346  fprintf(stderr, "Getting bad motor encoders! \n");
347  return 1;
348  }
349  else
350  {
351  fprintf(stderr, "Interface is not ready! \n");
352  return 0;
353  }
354 }
355 
356 
357 void GetMotPwm::setInterface(IAmplifierControl* i)
358 {
359  iamp = i;
360 }
361 
362 bool GetMotPwm::getData(double *e)
363 {
364  if (!iamp)
365  {
366  return 0;
367  }
368 
369  bool ret = true;
370  for(int j=0; j<n_joint_part; j++)
371  {
372  ret &=iamp->getPWM(j, &e[j]);
373  }
374  return ret;
375 }
void setInterface(IEncoders *)
virtual bool getData(double *)
virtual bool getData(double *)
void setInterface(IControlMode *, int joints)
IAmplifierControl * iamp
virtual bool getData(double *)
void setInterface(IAmplifierControl *)
bool getStamp(Stamp &)
void setStamp(IPreciselyTimed *)
virtual bool getData(double *)
void setInterface(IEncoders *)
void setInterface(IInteractionMode *, int joints)
virtual bool getData(double *)
void setInterface(IMotorEncoders *)
IMotorEncoders * imotencs
virtual bool getData(double *)
IMotorEncoders * imotencs
void setInterface(IMotorEncoders *)
virtual bool getData(double *)
virtual bool getData(double *)
void setInterface(IAmplifierControl *)
IAmplifierControl * iamp
virtual bool getData(double *)
void setInterface(IMotorEncoders *)
IMotorEncoders * imotencs
void setInterface(IPidControl *)
IPidControl * ipid
virtual bool getData(double *)
void setInterface(IPidControl *)
virtual bool getData(double *)
void setInterface(IPidControl *)
virtual bool getData(double *)
void setInterface(IEncoders *)
virtual bool getData(double *)
void setInterface(IMotor *)
virtual bool getData(double *)
void setInterface(IPidControl *)
virtual bool getData(double *)
ITorqueControl * itrq
void setInterface(ITorqueControl *)
virtual bool getData(double *)
virtual bool getData(double *)
void setInterface(ITorqueControl *)
ITorqueControl * itrq
fprintf(fid,'\n')