iCub-main
Loading...
Searching...
No Matches
SkinMeshClient.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) 2009 RobotCub Consortium
5 * Author: Marco Randazzo, Marco Maggiali, Alessandro Scalzo, Jacopo Losi
6 * CopyPolicy: Released under the terms of the GNU GPL v2.0.
7 *
8 */
9
11
12#include <algorithm>
13
14#include <yarp/os/LogComponent.h>
15#include <yarp/os/LogStream.h>
16#include <yarp/os/Time.h>
17
18#define SKIN_THRESHOLD 15.0
19
20namespace {
21
22YARP_LOG_COMPONENT(SKINMESHCLIENT, "yarp.tools.skinmeshclient")
23
24constexpr double noSkinPatchWarningPeriod = 60.0;
25
26std::string makeLocalPrefix(yarp::os::Searchable& config)
27{
28 std::string prefix = "/skinGui";
29 if (config.check("name"))
30 {
31 prefix = "/";
32 prefix += config.find("name").asString();
33 }
34
35 if (config.check("robotPart"))
36 {
37 prefix += "/";
38 prefix += config.find("robotPart").asString();
39 }
40
41 return prefix;
42}
43
44}
45
46SkinMeshClient::SkinMeshClient(Searchable& config,int period)
47{
48 m_period = static_cast<double>(period) / 1000.0;
49 m_config.fromString(config.toString());
50 yCDebug(SKINMESHCLIENT) << "SkinMeshClient running at" << static_cast<int>(1000.0 * getPeriod()) << "ms.";
51 mbSimpleDraw=false;
52
53 sensorsNum=0;
54 for (int t=0; t<MAX_SENSOR_NUM; ++t)
55 {
56 sensor[t]=NULL;
57 }
58}
59
60bool SkinMeshClient::configureFromSearchable(yarp::os::Searchable& config)
61{
62 if (m_configured)
63 {
64 return true;
65 }
66
67 mbSimpleDraw=config.check("light");
68
69 const std::string localPrefix = makeLocalPrefix(config);
70 const std::string part_virtual = localPrefix + "_virtual:i";
71
72 // Ideally, we would use a --virtual flag. since this would make the skinmanager xml file unflexible,
73 // let's keep the code structure without incurring in any problem whatsoever
74 // if (config.check("virtual"))
75 if (true)
76 {
77 skin_port_virtual.open(part_virtual);
78 }
79
80 if (!configureSkinClient(config, localPrefix))
81 {
82 return false;
83 }
84
85 int width =config.check("width") ? config.find("width").asInt32() : 320;
86 int height=config.check("height") ? config.find("height").asInt32() : 320;
87
88 bool useCalibration = config.check("useCalibration");
89 if (useCalibration)
90 {
91 yCInfo(SKINMESHCLIENT) << "Using calibrated skin values (0-255)";
92 }
93 else
94 {
95 yCDebug(SKINMESHCLIENT) << "Using raw skin values (255-0)";
96 }
97
98 Bottle *color = config.find("color").asList();
99 unsigned char r=255, g=0, b=0;
100 if(color)
101 {
102 if(color->size()<3 || !color->get(0).isInt32() || !color->get(1).isInt32() || !color->get(2).isInt32())
103 {
104 yCError(SKINMESHCLIENT) << "Error while reading the parameter color: three integer values should be specified"
105 << color->toString();
106 }
107 else
108 {
109 r = color->get(0).asInt32();
110 g = color->get(1).asInt32();
111 b = color->get(2).asInt32();
112 yCInfo(SKINMESHCLIENT) << "Using specified color:" << r << g << b;
113 }
114 }
115 else
116 {
117 yCDebug(SKINMESHCLIENT) << "Using red as default color.";
118 }
119 defaultColor.push_back(r);
120 defaultColor.push_back(g);
121 defaultColor.push_back(b);
122
123 skinThreshold = config.check("skinThreshold")?config.find("skinThreshold").asFloat64():SKIN_THRESHOLD;
124 yCDebug(SKINMESHCLIENT) << "Skin threshold set to" << skinThreshold;
125
126 yarp::os::Bottle sensorSetConfig=config.findGroup("SENSORS").tail();
127
128 for (int t=0; t<sensorSetConfig.size(); ++t)
129 {
130 yarp::os::Bottle sensorConfig(sensorSetConfig.get(t).toString());
131 std::string type(sensorConfig.get(0).asString());
132
133 if (type=="triangle" ||
134 type=="fingertip" ||
135 type=="fingertip2L" ||
136 type=="fingertip2R" ||
137 type=="fingertip3L" ||
138 type=="fingertip3R" ||
139 type=="fingertip4L" ||
140 type=="fingertip4R" ||
141 type=="fingertipMID" ||
142 type=="triangle_10pad" ||
143 type=="quad16" ||
144 type=="palmR" ||
145 type=="fakePalm" ||
146 type=="palmL" ||
147 type == "cer_sh_pdl" ||
148 type == "cer_sh_pdr" ||
149 type == "cer_sh_pp" ||
150 type == "cer_sh_td" ||
151 type == "cer_sh_tp")
152 {
153 int id=sensorConfig.get(1).asInt32();
154 double xc=sensorConfig.get(2).asFloat64();
155 double yc=sensorConfig.get(3).asFloat64();
156 double th=sensorConfig.get(4).asFloat64();
157 double gain=sensorConfig.get(5).asFloat64();
158 int lrMirror=sensorConfig.get(6).asInt32();
159 int layoutNum=sensorConfig.get(7).asInt32();
160
161 yCDebug(SKINMESHCLIENT) << type << id << gain;
162
163 if (id>=0 && id<MAX_SENSOR_NUM)
164 {
165 if (sensor[id])
166 {
167 yCError(SKINMESHCLIENT) << "Triangle" << id << "already exists.";
168 }
169 else
170 {
171 if (type=="triangle")
172 {
173 sensor[id]=new Triangle(xc,yc,th,gain,layoutNum,lrMirror);
174 }
175 else if (type=="triangle_10pad")
176 {
177 sensor[id]=new Triangle_10pad(xc,yc,th,gain,layoutNum,lrMirror);
178 }
179 else if (type=="fingertip")
180 {
181 sensor[id]=new Fingertip(xc,yc,th,gain,layoutNum,lrMirror);
182 }
183 else if (type=="fingertip2L")
184 {
185 sensor[id]=new Fingertip2L(xc,yc,th,gain,layoutNum,lrMirror);
186 }
187 else if (type=="fingertip2R")
188 {
189 sensor[id]=new Fingertip2R(xc,yc,th,gain,layoutNum,lrMirror);
190 }
191 else if (type=="fingertip3L")
192 {
193 sensor[id]=new Fingertip3L(xc,yc,th,gain,layoutNum,lrMirror);
194 }
195 else if (type=="fingertip3R")
196 {
197 sensor[id]=new Fingertip3R(xc,yc,th,gain,layoutNum,lrMirror);
198 }
199 else if (type=="fingertip4L")
200 {
201 sensor[id]=new Fingertip4L(xc,yc,th,gain,layoutNum,lrMirror);
202 }
203 else if (type=="fingertip4R")
204 {
205 sensor[id]=new Fingertip4R(xc,yc,th,gain,layoutNum,lrMirror);
206 }
207 if (type=="fingertipMID")
208 {
209 sensor[id]=new FingertipMID(xc,yc,th,gain,layoutNum,lrMirror);
210 }
211 else if (type=="quad16")
212 {
213 sensor[id]=new Quad16(xc,yc,th,gain,layoutNum,lrMirror);
214 }
215 else if (type == "cer_sh_pdl")
216 {
217 sensor[id] = new CER_SH_PDL(xc, yc, th, gain, layoutNum, lrMirror);
218 }
219 else if (type=="palmR")
220 {
221 sensor[id]=new PalmR(xc,yc,th,gain,layoutNum,lrMirror);
222 }
223 else if (type=="fakePalm")
224 {
225 sensor[id]=new fakePalm(xc,yc,th,gain,layoutNum,lrMirror);
226 }
227 else if (type=="palmL")
228 {
229 sensor[id]=new PalmL(xc,yc,th,gain,layoutNum,lrMirror);
230 }
231 else if (type == "cer_sh_pdl")
232 {
233 sensor[id] = new CER_SH_PDL(xc, yc, th, gain, layoutNum, lrMirror);
234 }
235 else if (type == "cer_sh_pdr")
236 {
237 sensor[id] = new CER_SH_PDR(xc, yc, th, gain, layoutNum, lrMirror);
238 }
239 else if (type == "cer_sh_pp")
240 {
241 sensor[id] = new CER_SH_PP(xc, yc, th, gain, layoutNum, lrMirror);
242 }
243 else if (type == "cer_sh_td")
244 {
245 sensor[id] = new CER_SH_TD(xc, yc, th, gain, layoutNum, lrMirror);
246 }
247 else if (type == "cer_sh_tp")
248 {
249 sensor[id] = new CER_SH_TP(xc, yc, th, gain, layoutNum, lrMirror);
250 }
251
252 sensor[id]->setCalibrationFlag(useCalibration);
253 ++sensorsNum;
254 }
255 }
256 else
257 {
258 yCWarning(SKINMESHCLIENT) << id << "is invalid triangle Id [0:" << MAX_SENSOR_NUM - 1 << "].";
259 }
260 }
261 else
262 {
263 yCWarning(SKINMESHCLIENT) << "Sensor type" << type << "unknown, discarded.";
264 }
265 }
266
267 int max_tax=0;
268 for (int t=0; t<MAX_SENSOR_NUM; ++t)
269 {
270
271 if (sensor[t])
272 {
273 sensor[t]->min_tax=max_tax;
274 max_tax = sensor[t]->min_tax+sensor[t]->get_nTaxels();
275 sensor[t]->max_tax=max_tax-1;
276 sensor[t]->setColor(r, g, b);
277 }
278 else
279 {
280 //this deals with the fact that some traingles can be not present,
281 //but they anyway broadcast an array of zeros...
282 max_tax += 12;
283 }
284 }
285
286 resize(width,height);
287
288 m_configured = true;
289 return true;
290}
291
292bool SkinMeshClient::configureSkinClient(yarp::os::Searchable& config, const std::string& localPrefix)
293{
294 const std::string local = config.check("local") ? config.find("local").asString() : localPrefix;
295 const bool externalConnection = config.check("externalConnection") ? config.find("externalConnection").asBool() : true;
296 m_externalConnection = externalConnection;
297
298 if (!externalConnection && !config.check("remote"))
299 {
300 yCError(SKINMESHCLIENT) << "SkinMeshClient: externalConnection false requires a remote MAS server prefix.";
301 return false;
302 }
303
304 yarp::os::Property clientOptions;
305 clientOptions.put("device", "multipleanalogsensorsclient");
306 clientOptions.put("local", local);
307 clientOptions.put("remote", externalConnection ? local : config.find("remote").asString());
308 clientOptions.put("timeout", config.check("timeout") ? config.find("timeout").asFloat64() : getPeriod() * 2.0);
309 clientOptions.put("externalConnection", externalConnection);
310 if (config.check("carrier")) //TODO: check carrier if it is the correct one - for now we are using default tcp
311 {
312 clientOptions.put("carrier", config.find("carrier").asString());
313 }
314
315 if (!_multipleAnalogSensorsClientDevice.open(clientOptions))
316 {
317 yCError(SKINMESHCLIENT) << "SkinMeshClient: unable to open multipleanalogsensorsclient with options"
318 << clientOptions.toString();
319 return false;
320 }
321
322 yarp::dev::ISkinPatches* clientSkinPatches = nullptr;
323 if (!_multipleAnalogSensorsClientDevice.view(clientSkinPatches) || clientSkinPatches == nullptr)
324 {
325 yCError(SKINMESHCLIENT) << "SkinMeshClient: unable to view ISkinPatches from multipleanalogsensorsclient.";
326 return false;
327 }
328
329 if (externalConnection)
330 {
331 remappedMASInterfaces.iskinPatchesSensors = clientSkinPatches;
332 yCInfo(SKINMESHCLIENT) << "Waiting for external MAS streaming connection on" << local + "/measures:i";
333 yCInfo(SKINMESHCLIENT) << "Internal MultipleAnalogSensorsRemapper is not used with externalConnection true"
334 << "because MultipleAnalogSensorsClient metadata is unavailable in that mode.";
335 return true;
336 }
337
338 yarp::os::Bottle skinPatchNames;
339 const size_t skinPatchCount = clientSkinPatches->getNrOfSkinPatches();
340 yCDebug(SKINMESHCLIENT) << "Number of skin patches available from the multipleanalogsensorsclient:" << skinPatchCount;
341
342 if (skinPatchCount == 0)
343 {
344 yCError(SKINMESHCLIENT) << "SkinMeshClient: no skin patches available from the multipleanalogsensorsclient.";
345 return false;
346 }
347
348 for (size_t skinPatchIndex = 0; skinPatchIndex < skinPatchCount; ++skinPatchIndex)
349 {
350 std::string skinPatchName;
351 if (!clientSkinPatches->getSkinPatchName(skinPatchIndex, skinPatchName))
352 {
353 yCError(SKINMESHCLIENT) << "SkinMeshClient: unable to retrieve name for skin patch"
354 << skinPatchIndex
355 << "from multipleanalogsensorsclient.";
356 return false;
357 }
358
359 yCDebug(SKINMESHCLIENT) << "Name of found skin patch:" << skinPatchName;
360 skinPatchNames.addString(skinPatchName);
361 }
362
363 if (skinPatchNames.size() != static_cast<int>(skinPatchCount))
364 {
365 yCError(SKINMESHCLIENT) << "SkinMeshClient: inconsistent skin patch metadata. Expected"
366 << skinPatchCount
367 << "names but collected"
368 << skinPatchNames.size();
369 return false;
370 }
371
372 yarp::os::Property remapperOptions;
373 remapperOptions.put("device", "multipleanalogsensorsremapper");
374
375 yarp::os::Bottle skinPatchNamesOption;
376 yarp::os::Bottle& skinPatchNamesList = skinPatchNamesOption.addList();
377 for (int i = 0; i < skinPatchNames.size(); ++i)
378 {
379 skinPatchNamesList.addString(skinPatchNames.get(i).asString());
380 }
381 remapperOptions.put("SkinPatchesNames", skinPatchNamesOption.get(0));
382
383 if (!_multipleAnalogSensorsRemapperDevice.open(remapperOptions))
384 {
385 yCError(SKINMESHCLIENT) << "SkinMeshClient: unable to open multipleanalogsensorsremapper with options"
386 << remapperOptions.toString();
387 return false;
388 }
389
390 if (!_multipleAnalogSensorsRemapperDevice.view(remappedMASInterfaces.imultwrap) ||
391 remappedMASInterfaces.imultwrap == nullptr)
392 {
393 yCError(SKINMESHCLIENT) << "SkinMeshClient: unable to view IMultipleWrapper from multipleanalogsensorsremapper.";
394 return false;
395 }
396
397 yarp::dev::PolyDriverList clientDeviceList;
398 clientDeviceList.push(&_multipleAnalogSensorsClientDevice, "skin_mas_client");
399 if (!remappedMASInterfaces.imultwrap->attachAll(clientDeviceList))
400 {
401 yCError(SKINMESHCLIENT) << "SkinMeshClient: unable to attach multipleanalogsensorsclient to remapper.";
402 return false;
403 }
404
405 if (!_multipleAnalogSensorsRemapperDevice.view(remappedMASInterfaces.iskinPatchesSensors) ||
406 remappedMASInterfaces.iskinPatchesSensors == nullptr)
407 {
408 yCError(SKINMESHCLIENT) << "SkinMeshClient: unable to view ISkinPatches from multipleanalogsensorsremapper.";
409 return false;
410 }
411
412 const size_t remappedSkinPatchCount = remappedMASInterfaces.iskinPatchesSensors->getNrOfSkinPatches();
413 if (remappedSkinPatchCount != skinPatchCount)
414 {
415 yCError(SKINMESHCLIENT) << "SkinMeshClient: MultipleAnalogSensorsRemapper exposes"
416 << remappedSkinPatchCount
417 << "skin patches, expected"
418 << skinPatchCount;
419 return false;
420 }
421
422 yCInfo(SKINMESHCLIENT) << "Reading skin patches through MultipleAnalogSensorsRemapper:" << skinPatchNames.toString();
423 return true;
424}
425
426bool SkinMeshClient::readSkinPatches(yarp::sig::Vector& skinValue) const
427{
428 if (remappedMASInterfaces.iskinPatchesSensors == nullptr)
429 {
430 return false;
431 }
432
433 const size_t skinPatchCount = remappedMASInterfaces.iskinPatchesSensors->getNrOfSkinPatches();
434 if (skinPatchCount == 0)
435 {
436 const double now = yarp::os::Time::now();
437 if (now - m_lastNoSkinPatchWarningTime >= noSkinPatchWarningPeriod)
438 {
440 {
441 yCWarning(SKINMESHCLIENT) << "SkinMeshClient: no skin patches available yet from the MAS client."
442 << "Waiting for the external streaming connection.";
443 }
444 else
445 {
446 //TODO: decide this implementation detail: if externalConnection is false, it means that we are using the internal remapper, which should always expose the same skin patches as the client, so if we have no skin patches it means that the client has no skin patches, and this is something that we want to warn about. If externalConnection is true, instead, we are relying on an external streaming connection, so it might be the case that the client has skin patches but we haven't established the streaming connection yet, so in that case we want to warn about the fact that we have no skin patches available yet and we are waiting for the streaming connection to be established.
447 // thus in this case it should an Error and the sw should exit, but for now let's keep it as a warning and let's wait for the streaming connection, because this is what happens in the current implementation of the skinmanager xml file, and we don't want to break it without a good reason.
448 yCWarning(SKINMESHCLIENT) << "SkinMeshClient: no skin patches available from the active MAS skin patches interface.";
449 }
451 }
452 return false;
453 }
454
455 std::vector<size_t> skinPatchSizes(skinPatchCount, 0);
456 size_t totalSkinPatchSize = 0;
457 for (size_t skinPatchIndex = 0; skinPatchIndex < skinPatchCount; ++skinPatchIndex)
458 {
459 skinPatchSizes[skinPatchIndex] = remappedMASInterfaces.iskinPatchesSensors->getSkinPatchSize(skinPatchIndex);
460 totalSkinPatchSize += skinPatchSizes[skinPatchIndex];
461 }
462
463 skinValue.resize(totalSkinPatchSize, 0.0);
464 size_t skinValueOffset = 0;
465 bool gotAnyPatch = false;
466
467 for (size_t skinPatchIndex = 0; skinPatchIndex < skinPatchCount; ++skinPatchIndex)
468 {
469 if (remappedMASInterfaces.iskinPatchesSensors->getSkinPatchStatus(skinPatchIndex) != yarp::dev::MAS_OK)
470 {
471 skinValueOffset += skinPatchSizes[skinPatchIndex];
472 continue;
473 }
474
475 yarp::sig::Vector skinPatchValue;
476 double timestamp = 0.0;
477 if (!remappedMASInterfaces.iskinPatchesSensors->getSkinPatchMeasure(skinPatchIndex, skinPatchValue, timestamp))
478 {
479 skinValueOffset += skinPatchSizes[skinPatchIndex];
480 continue;
481 }
482
483 const size_t taxelsToCopy = std::min(skinPatchSizes[skinPatchIndex], skinPatchValue.size());
484 for (size_t i = 0; i < taxelsToCopy; ++i)
485 {
486 skinValue[skinValueOffset + i] = skinPatchValue[i];
487 }
488
489 skinValueOffset += skinPatchSizes[skinPatchIndex];
490 gotAnyPatch = true;
491 }
492
493 return gotAnyPatch;
494}
495
497{
498 if (!configureFromSearchable(m_config))
499 {
500 close();
501 return false;
502 }
503
504 return runModuleThreaded() == 0;
505}
506
508{
509 stopModule(true);
510}
511
512bool SkinMeshClient::configure(yarp::os::ResourceFinder &rf)
513{
514 return configureFromSearchable(rf);
515}
516
518{
519 return m_period;
520}
521
523{
524 std::lock_guard<std::mutex> lck(mtx);
525
526 bool gotRealData=false;
527 bool gotVirtualData=false;
528 yarp::sig::Vector skin_value;
529 yarp::sig::Vector skin_value_virtual;
530 std::vector<unsigned char> skin_color_virtual;
531
532 if (readSkinPatches(skin_value))
533 {
534 yCTrace(SKINMESHCLIENT) << "Reading real contacts from ISkinPatches...";
535 gotRealData=true;
536 }
537
538 // Read data from the virtual contacts
539 if (Bottle *input_virtual=skin_port_virtual.read(false))
540 {
541 Bottle *data_virtual = input_virtual->get(0).asList();
542 Bottle *color_virtual = input_virtual->get(1).asList();
543 if (data_virtual != nullptr && color_virtual != nullptr && color_virtual->size() >= 3)
544 {
545 yCTrace(SKINMESHCLIENT) << "Reading from virtual contacts...";
546 gotVirtualData=true;
547
548 skin_value_virtual.resize(data_virtual->size(),0.0);
549
550 for (int i=0; i<data_virtual->size(); i++)
551 {
552 skin_value_virtual[i] = data_virtual->get(i).asFloat64();
553 }
554
555 for (int i = 0; i<color_virtual->size(); i++)
556 {
557 skin_color_virtual.push_back(color_virtual->get(i).asInt32());
558 }
559
560 yCTrace(SKINMESHCLIENT) << "Virtual contacts:" << skin_value_virtual.toString(3,3);
561 yCTrace(SKINMESHCLIENT) << "Virtual contacts color:" << skin_color_virtual[0] << skin_color_virtual[1] << skin_color_virtual[2];
562 }
563 }
564
565 if (!gotRealData && !gotVirtualData)
566 {
567 for (int sensorId = 0; sensorId < MAX_SENSOR_NUM; sensorId++)
568 {
569 if (sensor[sensorId] != nullptr)
570 {
571 sensor[sensorId]->clearActivation();
572 }
573 }
574 return true;
575 }
576
577 for (int sensorId=0; sensorId<MAX_SENSOR_NUM; sensorId++)
578 {
579 if (sensor[sensorId]==0) continue;
580
581 // First, let's see if this touchSensor is over threshold in the real skin
582 bool isRealSensorOverThreshold=false;
583 if (gotRealData)
584 {
585 for (int i=sensor[sensorId]->min_tax; i<=sensor[sensorId]->max_tax && i<static_cast<int>(skin_value.size()); i++)
586 {
587 if (skin_value[i]>skinThreshold)
588 {
589 isRealSensorOverThreshold = true;
590 break;
591 }
592 }
593 }
594
595 // Second, let's see if this touchSensor is over threshold in the virtual skin
596 bool isVirtualSensorOverThreshold=false;
597 if (gotVirtualData)
598 {
599 for (int i=sensor[sensorId]->min_tax; i<=sensor[sensorId]->max_tax && i<static_cast<int>(skin_value_virtual.size()); i++)
600 {
601 if (skin_value_virtual[i]>skinThreshold)
602 {
603 isVirtualSensorOverThreshold = true;
604 break;
605 }
606 }
607 }
608
609 // Then, let's process the sensor with either the real or the virtual (or none)
610 // EVerything will be clearly decoupled, a couple lines more do not hurt
611
612 // If there are both, handle them
613 if (gotRealData && gotVirtualData)
614 {
615 // Then, let's process the sensor with either the real or the virtual skin
616 for (int i=sensor[sensorId]->min_tax; i<=sensor[sensorId]->max_tax; i++)
617 {
618 int curr_tax = i-sensor[sensorId]->min_tax;
619
620 // The GUI layout can describe more taxels than the current MAS sample carries,
621 // especially while clients are connecting or when only a subset of patches is available.
622 if (isRealSensorOverThreshold && i<static_cast<int>(skin_value.size()))
623 {
624 sensor[sensorId]->setActivationFromPortData(skin_value[i],curr_tax);
625 sensor[sensorId]->setColor(defaultColor[0],defaultColor[1],defaultColor[2]);
626 }
627 else if(isVirtualSensorOverThreshold && i<static_cast<int>(skin_value_virtual.size()))
628 {
629 sensor[sensorId]->setActivationFromPortData(skin_value_virtual[i],curr_tax);
630 sensor[sensorId]->setColor(skin_color_virtual[0],skin_color_virtual[1],skin_color_virtual[2]);
631 }
632 else if (i<static_cast<int>(skin_value.size()))
633 {
634 sensor[sensorId]->setActivationFromPortData(skin_value[i],curr_tax);
635 sensor[sensorId]->setColor(defaultColor[0],defaultColor[1],defaultColor[2]);
636 }
637 }
638 }
639 else if (gotRealData || gotVirtualData)
640 {
641 for (int i=sensor[sensorId]->min_tax; i<=sensor[sensorId]->max_tax; i++)
642 {
643 int curr_tax = i-sensor[sensorId]->min_tax;
644
645 if (gotRealData && i<static_cast<int>(skin_value.size()))
646 {
647 sensor[sensorId]->setActivationFromPortData(skin_value[i],curr_tax);
648 sensor[sensorId]->setColor(defaultColor[0],defaultColor[1],defaultColor[2]);
649 }
650 else if (gotVirtualData && i<static_cast<int>(skin_value_virtual.size()))
651 {
652 sensor[sensorId]->setActivationFromPortData(skin_value_virtual[i],curr_tax);
653 sensor[sensorId]->setColor(skin_color_virtual[0],skin_color_virtual[1],skin_color_virtual[2]);
654 }
655 }
656 }
657 }
658
659 return true;
660}
661
663{
664 yCDebug(SKINMESHCLIENT) << "SkinMeshClient releasing...";
665
666 if (remappedMASInterfaces.imultwrap != nullptr)
667 {
668 remappedMASInterfaces.imultwrap->detachAll();
669 }
670 remappedMASInterfaces.imultwrap = nullptr;
671 remappedMASInterfaces.iskinPatchesSensors = nullptr;
672
673 _multipleAnalogSensorsRemapperDevice.close();
674 _multipleAnalogSensorsClientDevice.close();
675
676 skin_port.close();
677 skin_port_virtual.close();
678
679 m_configured = false;
680 yCDebug(SKINMESHCLIENT) << "SkinMeshClient released.";
681 return true;
682}
#define SKIN_THRESHOLD
SkinMeshClient(Searchable &config, int period)
BufferedPort< Bottle > skin_port
TouchSensor * sensor[MAX_SENSOR_NUM]
static const int MAX_SENSOR_NUM
virtual bool configure(yarp::os::ResourceFinder &rf) override
std::vector< unsigned char > defaultColor
virtual double getPeriod() override
void resize(int width, int height)
double m_lastNoSkinPatchWarningTime
virtual bool updateModule() override
BufferedPort< Bottle > skin_port_virtual
virtual bool close() override