iCub-main
Loading...
Searching...
No Matches
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#include <vector>
23
25{
26 myIstmp=NULL;
27}
28
29bool GetData::getStamp(Stamp &stmp)
30{
31 if (myIstmp != NULL)
32 {
33 stmp = myIstmp->getLastInputStamp();
34 return true;
35 }
36 else
37 {
38 return false;
39 }
40}
41
42void GetData::setStamp(IPreciselyTimed *iStmp)
43{
44 myIstmp=iStmp;
45}
46
47void GetEncs::setInterface(IEncoders *i)
48{
49 iencs = i;
50}
51
52bool GetEncs::getData(double *e)
53{
54 //fprintf(stderr, "Entering getEncs\n");
55 if (iencs)
56 {
57 while(!iencs->getEncoders(e))
58 fprintf(stderr, "Getting bad encoders! \n");
59 return 1;
60 }
61 else
62 {
63 fprintf(stderr, "Interface is not ready! \n");
64 return 0;
65 }
66}
67
68void GetPidRefs::setInterface(IPidControl *i)
69{
70 ipid = i;
71}
72
74{
75 //fprintf(stderr, "Entering getPosErrs\n");
76 if (ipid)
77 {
78 ipid->getPidReferences(PidControlTypeEnum::VOCAB_PIDTYPE_POSITION, e);
79 return 1;
80 }
81 else
82 return 0;
83}
84
85void GetSpeeds::setInterface(IEncoders *i)
86{
87 iencs = i;
88}
89
90bool GetSpeeds::getData(double *e)
91{
92 //fprintf(stderr, "Entering getSpeeds\n");
93 if (iencs)
94 {
95 iencs->getEncoderSpeeds(e);
96 return 1;
97 }
98 else
99 return 0;
100}
101
102void GetAccs::setInterface(IEncoders *i)
103{
104 iencs = i;
105}
106
107bool GetAccs::getData(double *e)
108{
109 //fprintf(stderr, "Entering getAccs\n");
110 if (iencs)
111 {
112 iencs->getEncoderAccelerations(e);
113 return 1;
114 }
115 else
116 return 0;
117}
118
119void GetPosErrs::setInterface(IPidControl *i)
120{
121 ipid = i;
122}
123
125{
126 //fprintf(stderr, "Entering getPosErrs\n");
127 if (ipid)
128 {
129 ipid->getPidErrors(PidControlTypeEnum::VOCAB_PIDTYPE_POSITION,e);
130 return 1;
131 }
132 else
133 return 0;
134}
135
136void GetOuts::setInterface(IPidControl *i)
137{
138 ipid = i;
139}
140
141bool GetOuts::getData(double *e)
142{
143 //fprintf(stderr, "Entering getOuts\n");
144 if (ipid)
145 {
146 ipid->getPidOutputs(PidControlTypeEnum::VOCAB_PIDTYPE_POSITION,e);
147 return 1;
148 }
149 else
150 return 0;
151}
152
153void GetCurrs::setInterface(IAmplifierControl *i)
154{
155 iamp = i;
156}
157
158bool GetCurrs::getData(double *e)
159{
160 //fprintf(stderr, "Entering getOuts\n");
161 if (iamp)
162 {
163 iamp->getCurrents(e);
164 return 1;
165 }
166 else
167 return 0;
168}
169
170void GetTrqs::setInterface(ITorqueControl *i)
171{
172 itrq = i;
173}
174
175bool GetTrqs::getData(double *e)
176{
177 //fprintf(stderr, "Entering getTrqs\n");
178 if (itrq)
179 {
180 itrq->getTorques(e);
181 return 1;
182 }
183 else
184 return 0;
185}
186
187void GetControlModes::setInterface(IControlMode *i, int n_joints)
188{
189 icmd = i;
190 nj=n_joints;
191}
192
194{
195 //fprintf(stderr, "Entering getTrqs\n");
196 std::vector<yarp::dev::ControlModeEnum>tmp(nj);
197 if (icmd)
198 {
199 icmd->getControlModes(tmp);
200 for (int i=0; i<nj; i++)
201 {
202 if (tmp[i] == yarp::dev::ControlModeEnum::VOCAB_CM_POSITION) e[i] = 0;
203 else if (tmp[i] == yarp::dev::ControlModeEnum::VOCAB_CM_POSITION_DIRECT) e[i] = 1;
204 else if (tmp[i] == yarp::dev::ControlModeEnum::VOCAB_CM_VELOCITY) e[i] = 2;
205 else if (tmp[i] == yarp::dev::ControlModeEnum::VOCAB_CM_MIXED) e[i] = 3;
206 else if (tmp[i] == yarp::dev::ControlModeEnum::VOCAB_CM_TORQUE) e[i] = 4;
207 else if (tmp[i] == yarp::dev::ControlModeEnum::VOCAB_CM_PWM) e[i] = 5;
208 else if (tmp[i] == yarp::dev::ControlModeEnum::VOCAB_CM_IDLE) e[i] = 6;
209 else e[i] =-1;
210 }
211 return 1;
212 }
213 else
214 return 0;
215}
216
217void GetInteractionModes::setInterface(IInteractionMode *i, int n_joints)
218{
219 iint = i;
220 nj=n_joints;
221}
222
224{
225 //fprintf(stderr, "Entering getTrqs\n");
226 std::vector<yarp::dev::InteractionModeEnum> tmp;
227 tmp.resize(nj);
228 if (iint)
229 {
230 iint->getInteractionModes(tmp);
231 for (int i=0; i<nj; i++)
232 {
233 if (tmp[i] == VOCAB_IM_STIFF) e[i] = 0;
234 else if (tmp[i] == VOCAB_IM_COMPLIANT) e[i] = 1;
235 else e[i] =-1;
236 }
237 return 1;
238 }
239 else
240 return 0;
241}
242
243void GetTrqErrs::setInterface(IPidControl *i)
244{
245 ipid = i;
246}
247
249{
250 //fprintf(stderr, "Entering getTrqErrs\n");
251 if (ipid)
252 {
253 ipid->getPidErrors(PidControlTypeEnum::VOCAB_PIDTYPE_TORQUE,e);
254 return 1;
255 }
256 else
257 return 0;
258}
259
260void GetTrqRefs::setInterface(ITorqueControl *i)
261{
262 itrq = i;
263}
264
266{
267 //fprintf(stderr, "Entering getTrqRefs\n");
268 if (itrq)
269 {
270 itrq->getRefTorques(e);
271 return 1;
272 }
273 else
274 return 0;
275}
276
277void GetMotEncs::setInterface(IMotorEncoders *i)
278{
279 imotencs = i;
280}
281
283{
284 if (imotencs)
285 {
286 while(!imotencs->getMotorEncoders(e))
287 fprintf(stderr, "Getting bad motor encoders! \n");
288 return 1;
289 }
290 else
291 {
292 fprintf(stderr, "Interface is not ready! \n");
293 return 0;
294 }
295}
296
297
299{
300 imot = i;
301}
302
303bool GetTemps::getData(double *temp)
304{
305 if (imot)
306 {
307 while(!imot->getTemperatures(temp))
308 fprintf(stderr, "Getting bad motortemperatures! \n");
309 return 1;
310 }
311 else
312 {
313 fprintf(stderr, "Interface is not ready! \n");
314 return 0;
315 }
316}
317
318void GetMotSpeeds::setInterface(IMotorEncoders *i)
319{
320 imotencs = i;
321}
322
324{
325 if (imotencs)
326 {
327 while(!imotencs->getMotorEncoderSpeeds(e))
328 fprintf(stderr, "Getting bad motor encoders! \n");
329 return 1;
330 }
331 else
332 {
333 fprintf(stderr, "Interface is not ready! \n");
334 return 0;
335 }
336}
337
338void GetMotAccs::setInterface(IMotorEncoders *i)
339{
340 imotencs = i;
341}
342
344{
345 if (imotencs)
346 {
347 while(!imotencs->getMotorEncoderAccelerations(e))
348 fprintf(stderr, "Getting bad motor encoders! \n");
349 return 1;
350 }
351 else
352 {
353 fprintf(stderr, "Interface is not ready! \n");
354 return 0;
355 }
356}
357
358
359void GetMotPwm::setInterface(IAmplifierControl* i)
360{
361 iamp = i;
362}
363
365{
366 if (!iamp)
367 {
368 return 0;
369 }
370
371 bool ret = true;
372 for(int j=0; j<n_joint_part; j++)
373 {
374 ret &=iamp->getPWM(j, &e[j]);
375 }
376 return ret;
377}
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 *)
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')