Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored due to upgrade to YARP-3.5 to deal with changes to *Int, *Double, *Vocab and to use the latest yarp::conf utilities #773

Merged
merged 1 commit into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
option(ICUB_COMPILE_BINDINGS "Compile optional language bindings" FALSE)

set(YCM_REQUIRED_VERSION 0.13.0)
set(YARP_REQUIRED_VERSION 3.3.2)
set(YARP_REQUIRED_VERSION 3.5.1)

find_package(YCM ${YCM_REQUIRED_VERSION} REQUIRED)
find_package(YARP ${YARP_REQUIRED_VERSION} REQUIRED)
Expand Down
32 changes: 16 additions & 16 deletions src/core/emotionInterface/emotionInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,28 @@ class iCub::contrib::IEmotionInterface

};

constexpr yarp::conf::vocab32_t EMOTION_VOCAB_SET = yarp::os::createVocab('s','e','t');
constexpr yarp::conf::vocab32_t EMOTION_VOCAB_GET = yarp::os::createVocab('g','e','t');
constexpr yarp::conf::vocab32_t EMOTION_VOCAB_IS = yarp::os::createVocab('i','s');
constexpr yarp::conf::vocab32_t EMOTION_VOCAB_FAILED = yarp::os::createVocab('f','a','i','l');
constexpr yarp::conf::vocab32_t EMOTION_VOCAB_OK = yarp::os::createVocab('o','k');
constexpr yarp::conf::vocab32_t EMOTION_VOCAB_HELP = yarp::os::createVocab('h','e','l','p');
constexpr yarp::conf::vocab32_t EMOTION_VOCAB_SET = yarp::os::createVocab32('s','e','t');
constexpr yarp::conf::vocab32_t EMOTION_VOCAB_GET = yarp::os::createVocab32('g','e','t');
constexpr yarp::conf::vocab32_t EMOTION_VOCAB_IS = yarp::os::createVocab32('i','s');
constexpr yarp::conf::vocab32_t EMOTION_VOCAB_FAILED = yarp::os::createVocab32('f','a','i','l');
constexpr yarp::conf::vocab32_t EMOTION_VOCAB_OK = yarp::os::createVocab32('o','k');
constexpr yarp::conf::vocab32_t EMOTION_VOCAB_HELP = yarp::os::createVocab32('h','e','l','p');

constexpr yarp::conf::vocab32_t EMOTION_VOCAB_MOUTH = yarp::os::createVocab('m','o','u');
constexpr yarp::conf::vocab32_t EMOTION_VOCAB_EYELIDS = yarp::os::createVocab('e','l','i');
constexpr yarp::conf::vocab32_t EMOTION_VOCAB_LEFTEYEBROW = yarp::os::createVocab('l','e','b');
constexpr yarp::conf::vocab32_t EMOTION_VOCAB_RIGHTEYEBROW = yarp::os::createVocab('r','e','b');
constexpr yarp::conf::vocab32_t EMOTION_VOCAB_ALL = yarp::os::createVocab('a','l','l');
constexpr yarp::conf::vocab32_t EMOTION_VOCAB_RAW = yarp::os::createVocab('r','a','w');
constexpr yarp::conf::vocab32_t EMOTION_VOCAB_COLOR = yarp::os::createVocab('c','o','l');
constexpr yarp::conf::vocab32_t EMOTION_VOCAB_BRIG = yarp::os::createVocab('b','r','i','g');
constexpr yarp::conf::vocab32_t EMOTION_VOCAB_MASK = yarp::os::createVocab('m','a','s','k');
constexpr yarp::conf::vocab32_t EMOTION_VOCAB_MOUTH = yarp::os::createVocab32('m','o','u');
constexpr yarp::conf::vocab32_t EMOTION_VOCAB_EYELIDS = yarp::os::createVocab32('e','l','i');
constexpr yarp::conf::vocab32_t EMOTION_VOCAB_LEFTEYEBROW = yarp::os::createVocab32('l','e','b');
constexpr yarp::conf::vocab32_t EMOTION_VOCAB_RIGHTEYEBROW = yarp::os::createVocab32('r','e','b');
constexpr yarp::conf::vocab32_t EMOTION_VOCAB_ALL = yarp::os::createVocab32('a','l','l');
constexpr yarp::conf::vocab32_t EMOTION_VOCAB_RAW = yarp::os::createVocab32('r','a','w');
constexpr yarp::conf::vocab32_t EMOTION_VOCAB_COLOR = yarp::os::createVocab32('c','o','l');
constexpr yarp::conf::vocab32_t EMOTION_VOCAB_BRIG = yarp::os::createVocab32('b','r','i','g');
constexpr yarp::conf::vocab32_t EMOTION_VOCAB_MASK = yarp::os::createVocab32('m','a','s','k');



inline bool EMOTION_CHECK_FAIL(bool ok, yarp::os::Bottle& response) {
if (ok) {
if (response.get(0).isVocab() && response.get(0).asVocab() == EMOTION_VOCAB_FAILED) {
if (response.get(0).isVocab32() && response.get(0).asVocab32() == EMOTION_VOCAB_FAILED) {
return false;
}
}
Expand Down
56 changes: 28 additions & 28 deletions src/core/emotionInterface/emotionInterfaceModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*
*/

#include <sstream>
#include <string>
#include <cstdlib>
#include <bitset>
Expand All @@ -25,7 +26,7 @@ std::bitset<32> populateBitset(const yarp::os::Bottle& bt)
{
std::bitset<32> bitSet{};
for(size_t i=0; i<bt.size(); i++){
bitSet.set(bt.get(i).asInt());
bitSet.set(bt.get(i).asInt32());
}
return bitSet;
}
Expand Down Expand Up @@ -74,7 +75,7 @@ void printHelp (yarp::os::Bottle& reply) {
"\tm_name stands for mask name and the availble bitmasks can be consulted/added in faceExpressions/emotions_rfe.ini\n";

reply.clear();
reply.addVocab(Vocab::encode("many"));
reply.addVocab32("many");
reply.addString(helpMessage.c_str());
}

Expand All @@ -83,9 +84,6 @@ EmotionInterfaceModule::EmotionInterfaceModule() : emotionInitReport(this) {

bool EmotionInterfaceModule::configure(ResourceFinder& config){

char name[10];
int i;

std::string modName = config.find("name").asString();
setName(modName.c_str());

Expand All @@ -95,12 +93,12 @@ bool EmotionInterfaceModule::configure(ResourceFinder& config){
return false;
}

_highlevelemotions = config.check("emotions", Value(0), "Number of predefined facial expressions").asInt();
_numberOfColors = config.check("colors", Value(0), "Number of predefined colors").asInt();
_eyebrowmaskemotions = config.check("bitmask_eyebrow_emotions", Value(0), "Number of predefined bitmask eyebrow expressions").asInt();
_mouthmaskemotions = config.check("bitmask_mouth_emotions", Value(0), "Number of predefined bitmask eyebrow expressions").asInt();
_highlevelemotions = config.check("emotions", Value(0), "Number of predefined facial expressions").asInt32();
_numberOfColors = config.check("colors", Value(0), "Number of predefined colors").asInt32();
_eyebrowmaskemotions = config.check("bitmask_eyebrow_emotions", Value(0), "Number of predefined bitmask eyebrow expressions").asInt32();
_mouthmaskemotions = config.check("bitmask_mouth_emotions", Value(0), "Number of predefined bitmask eyebrow expressions").asInt32();
_auto = config.check("auto");
_period = config.check("period", Value(10.0), "Period for expression switching in auto mode").asDouble();
_period = config.check("period", Value(10.0), "Period for expression switching in auto mode").asFloat64();
if(_highlevelemotions == 0)
{
_emotion_table = nullptr;
Expand All @@ -113,28 +111,30 @@ bool EmotionInterfaceModule::configure(ResourceFinder& config){
yError("Memory allocation problem\n");
return false;
}
for(i = 0; i < _highlevelemotions; i++)
for(int i = 0; i < _highlevelemotions; i++)
{
sprintf(name,"E%d",i+1);
std::ostringstream ss;
ss << "E" << i+1;
std::string name = ss.str();
if(!config.check(name))
{
yError("Missing identifier %s.", name);
yError("Missing identifier %s.", name.c_str());
return false;
}
else
{
Bottle& bot = config.findGroup(name);
if( bot.size() < 6 )
{
printf("Invalid parameter list for identifier %s.", name);
printf("Invalid parameter list for identifier %s.", name.c_str());
return false;
}
//first field - name of the expression
std::string n1 = bot.get(1).toString();

if(n1.length()!=3) //must have length 3
{
yError("First field of identifier %s has invalid size (must be 3).", name);
yError("First field of identifier %s has invalid size (must be 3).", name.c_str());
return false;
}
else
Expand All @@ -148,7 +148,7 @@ bool EmotionInterfaceModule::configure(ResourceFinder& config){
const char * sfd = n2.c_str();
if(n2.length()!=3) //must have length 3
{
yError("Second field of identifier %s has invalid size (must be 3).", name);
yError("Second field of identifier %s has invalid size (must be 3).", name.c_str());
return false;
}
else
Expand All @@ -160,7 +160,7 @@ bool EmotionInterfaceModule::configure(ResourceFinder& config){
std::string n3 = bot.get(3).toString();
if(n3.length()!=3) //must have length 3
{
yError("Third field of identifier %s has invalid size (must be 3).", name);
yError("Third field of identifier %s has invalid size (must be 3).", name.c_str());
return false;
}
else
Expand All @@ -173,7 +173,7 @@ bool EmotionInterfaceModule::configure(ResourceFinder& config){
std::string n4 = bot.get(4).toString();
if(n4.length()!=3) //must have length 3
{
yError("Fourth field of identifier %s has invalid size (must be 3).", name);
yError("Fourth field of identifier %s has invalid size (must be 3).", name.c_str());
return false;
}
else
Expand All @@ -186,7 +186,7 @@ bool EmotionInterfaceModule::configure(ResourceFinder& config){
std::string n5 = bot.get(5).toString();
if(n5.length()!=3) //must have length 3
{
yError("Fifth field of identifier %s has invalid size (must be 3).", name);
yError("Fifth field of identifier %s has invalid size (must be 3).", name.c_str());
return false;
}
else
Expand Down Expand Up @@ -354,14 +354,14 @@ bool EmotionInterfaceModule::respond(const Bottle &command,Bottle &reply){
bool ok = false;
bool rec = false; // is the command recognized?

switch (command.get(0).asVocab()) {
switch (command.get(0).asVocab32()) {
case EMOTION_VOCAB_HELP:
printHelp(reply);
return true;
case EMOTION_VOCAB_SET:
rec = true;
{
switch(command.get(1).asVocab()) {
switch(command.get(1).asVocab32()) {
case EMOTION_VOCAB_MOUTH:{
ok = setMouth(command.get(2).toString());
break;
Expand Down Expand Up @@ -407,24 +407,24 @@ bool EmotionInterfaceModule::respond(const Bottle &command,Bottle &reply){
case EMOTION_VOCAB_GET:
rec = true;
/*{
reply.addVocab(VOCAB_IS);
reply.addVocab32(VOCAB_IS);
reply.add(command.get(1));
switch(command.get(1).asVocab()) {
switch(command.get(1).asVocab32()) {
case EGOSPHERE_VOCAB_THRESHOLD_SALIENCE:{
float thr = getThresholdSalience();
reply.addDouble((double)thr);
reply.addFloat64((double)thr);
ok = true;
break;
}
case EGOSPHERE_VOCAB_OUTPUT:{
int v = (int)getOutput();
reply.addInt(v);
reply.addInt32(v);
ok = true;
break;
}
case EGOSPHERE_VOCAB_SALIENCE_DECAY:{
double rate = getSalienceDecay();
reply.addDouble(rate);
reply.addFloat64(rate);
ok = true;
break;
}
Expand All @@ -444,10 +444,10 @@ bool EmotionInterfaceModule::respond(const Bottle &command,Bottle &reply){

if (!ok) {
reply.clear();
reply.addVocab(EMOTION_VOCAB_FAILED);
reply.addVocab32(EMOTION_VOCAB_FAILED);
}
else
reply.addVocab(EMOTION_VOCAB_OK);
reply.addVocab32(EMOTION_VOCAB_OK);

return ok;
}
Expand Down
42 changes: 21 additions & 21 deletions src/libraries/actionPrimitives/src/actionPrimitives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ bool ActionPrimitives::handleTorsoDOF(Property &opt, const string &key)
{
Bottle info;
cartCtrl->getInfo(info);
double hwver=info.find("arm_version").asDouble();
double hwver=info.find("arm_version").asFloat64();
map<string,int> remap{{ACTIONPRIM_TORSO_PITCH,0},{ACTIONPRIM_TORSO_ROLL,1},{ACTIONPRIM_TORSO_YAW,2}};
if (hwver>=3.0)
{
Expand All @@ -432,8 +432,8 @@ bool ActionPrimitives::handleTorsoDOF(Property &opt, const string &key)

cartCtrl->getLimits(j,&min,&max);

min=opt.check(minKey,Value(min)).asDouble();
max=opt.check(maxKey,Value(max)).asDouble();
min=opt.check(minKey,Value(min)).asFloat64();
max=opt.check(maxKey,Value(max)).asFloat64();

cartCtrl->setLimits(j,min,max);
cartCtrl->getLimits(j,&min,&max);
Expand Down Expand Up @@ -485,7 +485,7 @@ bool ActionPrimitives::configHandSeq(Property &opt)
return false;
}

int numSequences=bGeneral.find("numSequences").asInt();
int numSequences=bGeneral.find("numSequences").asInt32();

// SEQUENCE groups
for (int i=0; i<numSequences; i++)
Expand Down Expand Up @@ -596,12 +596,12 @@ bool ActionPrimitives::open(Property &opt)
robot=opt.check("robot",Value("icub")).asString();
local=opt.find("local").asString();
part=opt.check("part",Value(ACTIONPRIM_DEFAULT_PART)).asString();
default_exec_time=opt.check("default_exec_time",Value(ACTIONPRIM_DEFAULT_EXECTIME)).asDouble();
default_exec_time=opt.check("default_exec_time",Value(ACTIONPRIM_DEFAULT_EXECTIME)).asFloat64();
tracking_mode=opt.check("tracking_mode",Value(ACTIONPRIM_DEFAULT_TRACKINGMODE)).asString()=="on"?true:false;
verbose=opt.check("verbosity",Value(ACTIONPRIM_DEFAULT_VERBOSITY)).asString()=="on"?true:false;

int period=opt.check("thread_period",Value(ACTIONPRIM_DEFAULT_PER)).asInt();
double reach_tol=opt.check("reach_tol",Value(ACTIONPRIM_DEFAULT_REACHTOL)).asDouble();
int period=opt.check("thread_period",Value(ACTIONPRIM_DEFAULT_PER)).asInt32();
double reach_tol=opt.check("reach_tol",Value(ACTIONPRIM_DEFAULT_REACHTOL)).asFloat64();

// create the model for grasp detection (if any)
if (!configGraspModel(opt))
Expand Down Expand Up @@ -763,7 +763,7 @@ bool ActionPrimitives::isHandSeqEnded()
// span over fingers
for (int fng=0; fng<5; fng++)
{
double val=pB->get(fng).asDouble();
double val=pB->get(fng).asFloat64();
double thres=curGraspDetectionThres[fng];

// detect contact on the finger
Expand Down Expand Up @@ -1562,7 +1562,7 @@ bool ActionPrimitives::addHandSequence(const string &handSeqKey, const Bottle &s
return false;
}

int numWayPoints=sequence.find("numWayPoints").asInt();
int numWayPoints=sequence.find("numWayPoints").asInt32();
bool ret=false;

for (int j=0; j<numWayPoints; j++)
Expand Down Expand Up @@ -1611,27 +1611,27 @@ bool ActionPrimitives::addHandSequence(const string &handSeqKey, const Bottle &s
Vector poss(bPoss->size());

for (size_t k=0; k<poss.length(); k++)
poss[k]=bPoss->get(k).asDouble();
poss[k]=bPoss->get(k).asFloat64();

Bottle *bVels=bWP.find("vels").asList();
Vector vels(bVels->size());

for (size_t k=0; k<vels.length(); k++)
vels[k]=bVels->get(k).asDouble();
vels[k]=bVels->get(k).asFloat64();

Bottle *bTols=bWP.find("tols").asList();
Vector tols(bTols->size());

for (size_t k=0; k<tols.length(); k++)
tols[k]=bTols->get(k).asDouble();
tols[k]=bTols->get(k).asFloat64();

Bottle *bThres=bWP.find("thres").asList();
Vector thres(bThres->size());

for (size_t k=0; k<thres.length(); k++)
thres[k]=bThres->get(k).asDouble();
thres[k]=bThres->get(k).asFloat64();

double tmo=bWP.find("tmo").asDouble();
double tmo=bWP.find("tmo").asFloat64();

if (addHandSeqWP(handSeqKey,poss,vels,tols,thres,tmo))
ret=true; // at least one WP has been added
Expand Down Expand Up @@ -1695,7 +1695,7 @@ bool ActionPrimitives::getHandSequence(const string &handSeqKey, Bottle &sequenc
// numWayPoints part
Bottle &bNum=sequence.addList();
bNum.addString("numWayPoints");
bNum.addInt((int)handWP.size());
bNum.addInt32((int)handWP.size());

// wayPoints parts
for (unsigned int i=0; i<handWP.size(); i++)
Expand All @@ -1711,33 +1711,33 @@ bool ActionPrimitives::getHandSequence(const string &handSeqKey, Bottle &sequenc
bPoss.addString("poss");
Bottle &bPossVects=bPoss.addList();
for (size_t j=0; j<handWP[i].poss.length(); j++)
bPossVects.addDouble(handWP[i].poss[j]);
bPossVects.addFloat64(handWP[i].poss[j]);

// vels part
Bottle &bVels=bWP.addList();
bVels.addString("vels");
Bottle &bVelsVects=bVels.addList();
for (size_t j=0; j<handWP[i].vels.length(); j++)
bVelsVects.addDouble(handWP[i].vels[j]);
bVelsVects.addFloat64(handWP[i].vels[j]);

// tols part
Bottle &bTols=bWP.addList();
bTols.addString("tols");
Bottle &bTolsVects=bTols.addList();
for (size_t j=0; j<handWP[i].tols.length(); j++)
bTolsVects.addDouble(handWP[i].tols[j]);
bTolsVects.addFloat64(handWP[i].tols[j]);

// thres part
Bottle &bThres=bWP.addList();
bThres.addString("thres");
Bottle &bThresVects=bThres.addList();
for (size_t j=0; j<handWP[i].thres.length(); j++)
bThresVects.addDouble(handWP[i].thres[j]);
bThresVects.addFloat64(handWP[i].thres[j]);

// tmo part
Bottle &bTmo=bWP.addList();
bTmo.addString("tmo");
bTmo.addDouble(handWP[i].tmo);
bTmo.addFloat64(handWP[i].tmo);
}

return true;
Expand Down Expand Up @@ -2251,7 +2251,7 @@ bool ActionPrimitivesLayer2::open(Property &opt)

if (configured)
{
ext_force_thres=opt.check("ext_force_thres",Value(std::numeric_limits<double>::max())).asDouble();
ext_force_thres=opt.check("ext_force_thres",Value(std::numeric_limits<double>::max())).asFloat64();
string wbdynStemName=opt.check("wbdyn_stem_name",Value(ACTIONPRIM_DEFAULT_WBDYN_STEMNAME)).asString();
string wbdynPortName=opt.check("wbdyn_port_name",Value(ACTIONPRIM_DEFAULT_WBDYN_PORTNAME)).asString();

Expand Down
Loading