iCub-main
skinWrapper.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 iCub Facility, Istituto Italiano di Tecnologia
3  * Authors: Alberto Cardellino
4  * CopyPolicy: Released under the terms of the LGPLv2.1 or later, see LGPL.TXT
5  *
6  */
7 
8 #include <yarp/os/Thread.h>
9 #include <yarp/os/RFModule.h>
10 #include <yarp/os/Os.h>
11 #include <iCub/FactoryInterface.h>
12 
13 #include "skinWrapper.h"
14 
15 using namespace yarp::sig;
16 using namespace yarp::os;
17 
19 {
20  yTrace();
21  multipleWrapper=NULL;
22  analog=NULL;
23  setId("undefinedPartName");
24 }
25 
27 
29 {
30  if (analog)
31  {
32  analog->calibrateSensor();
33  }
34 }
35 
36 bool skinWrapper::open(yarp::os::Searchable &params)
37 {
38  bool correct=true;
39 
40  if(params.check("ports"))
41  {
42  Bottle *ports=params.find("ports").asList();
43  setId(ports->get(0).asString().c_str());
44  numPorts=ports->size();
45  }
46  // Verify minimum set of parameters required
47  if(!params.check("robotName") )
48  {
49  correct=false;
50  yError() << "skinWrapper: missing robot Name, check your configuration file!! Quitting\n";
51  return false;
52  }
53 
54  if (params.check("period"))
55  {
56  period=params.find("period").asInt32();
57  }
58  else
59  {
60  period=20;
61  yDebug() <<"skinWrapper Warning: part "<<id<<" using default period ("<<period<<")\n";
62  }
63 
64  // Read the list of ports
65  int total_taxels=params.find("total_taxels").asInt32();
66  std::string robotName=params.find("robotName").asString().c_str();
67  std::string root_name;
68  root_name+="/";
69  root_name+=robotName;
70  root_name+="/skin";
71 
72 
73  Property option(params.toString().c_str());
74  option.put("name",root_name);
75  option.unput("device");
76  option.put("device","analogServer");
77  option.put("channels",total_taxels);
78  option.unput("total_taxels");
79  if(!driver.open(option))
80  {
81  yError()<<"skinWrapper: unable to open the device";
82  return false;
83  }
84  if(!driver.isValid())
85  {
86  yError()<<"skinWrapper: invalid device";
87  return false;
88  }
89  return true;
90 }
91 
93 {
94  if (NULL != analog)
95  analog=0;
96 
97  if(driver.isValid())
98  driver.close();
99  return true;
100 }
101 
102 // implementare i metodi attach e detach come un vero wrapper che si rispetti!!!!
103 bool skinWrapper::attachAll(const yarp::dev::PolyDriverList &skinDev)
104 {
105  yTrace() ;
106  if (skinDev.size() != 1)
107  {
108  std::cerr<<"skinWrapper: cannot attach more than one device\n";
109  return false;
110  }
111 
112  yarp::dev::PolyDriver * subdevice=skinDev[0]->poly;
113 
114  if (subdevice->isValid())
115  {
116  subdevice->view(analog);
117  }
118  else
119  {
120  yError() << "skinWrapper: subdevice passed to attach method is invalid!!!";
121  return false;
122  }
123  if(NULL == analog)
124  {
125  yError() << "skinWrapper: The analog sensor is not correctly instantiated, cannot attach !!!";
126  return false;
127  }
128  if(driver.isValid())
129  {
130  driver.view(multipleWrapper);
131  }
132  else
133  {
134  yError()<<"skinWrapper: cannot open analog server for skin";
135  return false;
136  }
137  if(multipleWrapper == YARP_NULLPTR)
138  {
139  yError()<<"skinWrapper: cannot call attach function";
140  return false;
141  }
142  multipleWrapper->attachAll(skinDev);
143  return true;
144 }
145 
147 {
148  yTrace();
149  multipleWrapper->detachAll();
150 // analogServer->stop();
151  return true;
152 }
153 
154 
Interface for a factory device; a device that can create objects.
bool detachAll()
bool attachAll(const yarp::dev::PolyDriverList &p)
bool open(yarp::os::Searchable &params)
Definition: skinWrapper.cpp:36
void calibrate()
Definition: skinWrapper.cpp:28
bool close()
Definition: skinWrapper.cpp:92