18 yDebug(
"SkinMeshThreadPort running at %d ms.",(
int)(1000.0*getPeriod()));
27 std::string part=
"/skinGui/";
28 std::string part_virtual=
"";
29 if (config.check(
"name"))
32 part+=config.find(
"name").asString();
35 part.append(config.find(
"robotPart").asString());
37 part_virtual.append(
"_virtual");
39 part_virtual.append(
":i");
51 int width =config.find(
"width" ).asInt32();
52 int height=config.find(
"height").asInt32();
54 bool useCalibration = config.check(
"useCalibration");
55 if (useCalibration==
true) yInfo(
"Using calibrated skin values (0-255)");
56 else yDebug(
"Using raw skin values (255-0)");
58 Bottle *color = config.find(
"color").asList();
59 unsigned char r=255, g=0, b=0;
62 if(color->size()<3 || !color->get(0).isInt32() || !color->get(1).isInt32() || !color->get(2).isInt32())
64 yError(
"Error while reading the parameter color: three integer values should be specified (%s).", color->toString().c_str());
68 r = color->get(0).asInt32();
69 g = color->get(1).asInt32();
70 b = color->get(2).asInt32();
71 yInfo(
"Using specified color: %d %d %d", r, g, b);
76 yDebug(
"Using red as default color.");
85 yarp::os::Bottle sensorSetConfig=config.findGroup(
"SENSORS").tail();
87 for (
int t=0; t<sensorSetConfig.size(); ++t)
89 yarp::os::Bottle sensorConfig(sensorSetConfig.get(t).toString());
90 std::string type(sensorConfig.get(0).asString());
92 if (type==
"triangle" ||
94 type==
"fingertip2L" ||
95 type==
"fingertip2R" ||
96 type==
"fingertip3L" ||
97 type==
"fingertip3R" ||
98 type==
"fingertip4L" ||
99 type==
"fingertip4R" ||
100 type==
"fingertipMID" ||
101 type==
"triangle_10pad" ||
106 type ==
"cer_sh_pdl" ||
107 type ==
"cer_sh_pdr" ||
108 type ==
"cer_sh_pp" ||
109 type ==
"cer_sh_td" ||
112 int id=sensorConfig.get(1).asInt32();
113 double xc=sensorConfig.get(2).asFloat64();
114 double yc=sensorConfig.get(3).asFloat64();
115 double th=sensorConfig.get(4).asFloat64();
116 double gain=sensorConfig.get(5).asFloat64();
117 int lrMirror=sensorConfig.get(6).asInt32();
118 int layoutNum=sensorConfig.get(7).asInt32();
120 yDebug(
"%s %d %f",type.c_str(),
id,gain);
126 yError(
"Triangle %d already exists.",
id);
130 if (type==
"triangle")
134 else if (type==
"triangle_10pad")
138 else if (type==
"fingertip")
142 else if (type==
"fingertip2L")
146 else if (type==
"fingertip2R")
150 else if (type==
"fingertip3L")
154 else if (type==
"fingertip3R")
158 else if (type==
"fingertip4L")
162 else if (type==
"fingertip4R")
166 if (type==
"fingertipMID")
170 else if (type==
"quad16")
172 sensor[id]=
new Quad16(xc,yc,th,gain,layoutNum,lrMirror);
174 else if (type ==
"cer_sh_pdl")
178 else if (type==
"palmR")
180 sensor[id]=
new PalmR(xc,yc,th,gain,layoutNum,lrMirror);
182 else if (type==
"fakePalm")
186 else if (type==
"palmL")
188 sensor[id]=
new PalmL(xc,yc,th,gain,layoutNum,lrMirror);
190 else if (type ==
"cer_sh_pdl")
194 else if (type ==
"cer_sh_pdr")
198 else if (type ==
"cer_sh_pp")
202 else if (type ==
"cer_sh_td")
206 else if (type ==
"cer_sh_tp")
217 yWarning(
" %d is invalid triangle Id [0:%d].",
id,
MAX_SENSOR_NUM-1);
222 yWarning(
" sensor type %s unknown, discarded.",type.c_str());
259 std::lock_guard<std::mutex> lck(
mtx);
261 bool gotRealData=
false;
262 bool gotVirtualData=
false;
263 yarp::sig::Vector skin_value;
264 yarp::sig::Vector skin_value_virtual;
265 std::vector<unsigned char> skin_color_virtual;
270 yTrace(
"Reading from real contacts...");
273 skin_value.resize(input->size(),0.0);
274 for (
int i=0; i<input->size(); i++)
276 skin_value[i]=input->get(i).asFloat64();
283 yTrace(
"Reading from virtual contacts...");
286 Bottle *data_virtual = input_virtual->get(0).asList();
287 skin_value_virtual.resize(data_virtual->size(),0.0);
288 Bottle *color_virtual = input_virtual->get(1).asList();
290 for (
int i=0; i<data_virtual->size(); i++)
292 skin_value_virtual[i] = data_virtual->get(i).asFloat64();
295 for (
int i = 0; i<color_virtual->size(); i++)
297 skin_color_virtual.push_back(color_virtual->get(i).asInt32());
300 yTrace(
"Virtual contacts: %s",skin_value_virtual.toString(3,3).c_str());
302 yTrace(
"Virtual contacts color: %i %i %i",skin_color_virtual[0],skin_color_virtual[1],skin_color_virtual[2]);
307 if (
sensor[sensorId]==0)
continue;
310 bool isRealSensorOverThreshold=
false;
317 isRealSensorOverThreshold =
true;
324 bool isVirtualSensorOverThreshold=
false;
331 isVirtualSensorOverThreshold =
true;
341 if (gotRealData && gotVirtualData)
348 if (isRealSensorOverThreshold)
353 else if(isVirtualSensorOverThreshold)
356 sensor[sensorId]->
setColor(skin_color_virtual[0],skin_color_virtual[1],skin_color_virtual[2]);
365 else if (gotRealData || gotVirtualData)
369 if (
sensor[sensorId]==0)
continue;
380 else if (gotVirtualData)
383 sensor[sensorId]->
setColor(skin_color_virtual[0],skin_color_virtual[1],skin_color_virtual[2]);