23 #include <yarp/os/LogStream.h> 24 #include <yarp/os/Value.h> 25 #include <yarp/os/Property.h> 37 TouchDetectorThread::TouchDetectorThread(BufferedPort<Bottle> *torsoPort, BufferedPort<Bottle> *leftArmPort, BufferedPort<Bottle> *rightArmPort, BufferedPort<Bottle> *leftForearmPort, BufferedPort<Bottle> *rightForearmPort, BufferedPort<Bottle> *leftHandPort, BufferedPort<Bottle> *rightHandPort, BufferedPort<Bottle> *touchPort, BufferedPort<Bottle> *touchPortCleaned,
int period,
string clustersConfFilepath,
double threshold,
int taxelThreshold)
38 : RateThread(period), nbClusters(0), threshold(threshold), taxelThreshold(taxelThreshold), clustersConfFilepath(clustersConfFilepath), torsoPort(torsoPort), leftArmPort(leftArmPort), rightArmPort(rightArmPort), leftForearmPort(leftForearmPort), rightForearmPort(rightForearmPort), leftHandPort(leftHandPort), rightHandPort(rightHandPort), touchPort(touchPort), touchPortCleaned(touchPortCleaned)
43 for (
int j = 0; j <
nbTaxels[i]; ++j)
58 yError() << ex.
what();
68 p.fromConfigFile(filename);
72 Bottle clusters = p.findGroup(
bodyParts[iPart]).tail();
73 for (
unsigned int iCluster = 0; iCluster < clusters.size(); ++iCluster)
76 Bottle *c = clusters.get(iCluster).asList();
77 for (
unsigned int iRange = 0; iRange < c->size(); ++iRange)
79 Bottle *range = c->get(iRange).asList();
80 if (range->size() == 1)
82 int taxel = range->get(0).asInt();
85 if (range->size() >= 2)
87 int first = range->get(0).asInt();
88 int last = range->get(1).asInt();
121 for (
int i = firstTaxel - 1; i < lastTaxel; ++i)
129 vector<int> activations;
131 activations.push_back(0);
151 int activatedTaxelNumber = -1;
155 for (
auto& activation : activations)
158 activatedTaxelNumber = i;
160 output.addInt(activation);
165 if(activatedTaxelNumber >= 0) {
168 outputClean.addInt(activatedTaxelNumber);
175 Bottle *tactileData = port->read(
false);
176 if (tactileData !=
nullptr)
182 yWarning() <<
"Unable to read data for " <<
bodyParts[portNum];
191 Value v = data->get(i);
192 if (v.isNull() || !v.isDouble())
215 std::string return_msg =
"Error parsing line " + std::to_string(line);
216 char* return_msg_char =
new char[return_msg.size() + 1];
217 strcpy(return_msg_char, return_msg.c_str());
218 return return_msg_char;
222 return "Parsing error";
231 msg =
"Bad format encountered ";
233 if (expectedType !=
"")
235 msg +=
"(expecting ";
239 msg +=
"while reading ";
252 return "Bad format encountered";
bool readTaxelsMapping(std::string filename)
readTaxelsMapping Read taxels map from configure file, which relates to nbBodyParts and bodyParts ...
int getBodyPartId(std::string bodyPartName)
getBodyPartId Obtain the ID of body parts, which are "torso", "left_arm", "right_arm", "left_forearm", "right_forearm", "left_hand", "right_hand"
yarp::os::BufferedPort< yarp::os::Bottle > * rightHandPort
Yarp BufferedPort of bottle for input right hand activations.
int taxelThreshold
integer value of touched threshold
void countActivations(int bodyPart, yarp::os::Bottle *data, std::vector< int > &activations)
countActivations Counts number of activations to a body part through a buffered port of that part ...
yarp::os::BufferedPort< yarp::os::Bottle > * leftArmPort
Yarp BufferedPort of bottle for input left arm activations.
yarp::os::BufferedPort< yarp::os::Bottle > * rightForearmPort
Yarp BufferedPort of bottle for input right forearm activations.
yarp::os::BufferedPort< yarp::os::Bottle > * touchPort
Yarp BufferedPort of bottle for output touched activations.
virtual const char * what() const
yarp::os::BufferedPort< yarp::os::Bottle > * leftHandPort
Yarp BufferedPort of bottle for input left hand activations.
yarp::os::BufferedPort< yarp::os::Bottle > * torsoPort
Yarp BufferedPort of bottle for input torso activations.
yarp::os::BufferedPort< yarp::os::Bottle > * rightArmPort
Yarp BufferedPort of bottle for input right arm activations.
static const int noCluster
yarp::os::BufferedPort< yarp::os::Bottle > * touchPortCleaned
Yarp BufferedPort of bottle for output touched taxel.
std::string clustersConfFilepath
string value of the path to configure file of clusters
yarp::os::BufferedPort< yarp::os::Bottle > * leftForearmPort
Yarp BufferedPort of bottle for input left forearm activations.
static const int nbBodyParts
void processPort(int portNum, yarp::os::BufferedPort< yarp::os::Bottle > *port, std::vector< int > &activations)
processPort Process port of body part to receive activations to that body part
static const int nbTaxels[7]
void updateMapping(int bodyPart, int firstTaxel, int lastTaxel, int cluster)
updateMapping Change all taxels of a body part to clusterID
std::vector< int > taxels2Clusters[7]
standard vector of integer containing the taxel IDs in form of cluster ID
static const char * bodyParts[7]
TouchDetectorThread(yarp::os::BufferedPort< yarp::os::Bottle > *torsoPort, yarp::os::BufferedPort< yarp::os::Bottle > *leftArmPort, yarp::os::BufferedPort< yarp::os::Bottle > *rightArmPort, yarp::os::BufferedPort< yarp::os::Bottle > *leftForearmPort, yarp::os::BufferedPort< yarp::os::Bottle > *rightForearmPort, yarp::os::BufferedPort< yarp::os::Bottle > *leftHandPort, yarp::os::BufferedPort< yarp::os::Bottle > *rightHandPort, yarp::os::BufferedPort< yarp::os::Bottle > *touchPort, yarp::os::BufferedPort< yarp::os::Bottle > *touchPortCleaned, int period, std::string clustersConfFilepath, double threshold, int taxelThreshold)