本文整理汇总了C++中Bottle::get方法的典型用法代码示例。如果您正苦于以下问题:C++ Bottle::get方法的具体用法?C++ Bottle::get怎么用?C++ Bottle::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bottle
的用法示例。
在下文中一共展示了Bottle::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read
bool NetworkClock::read(ConnectionReader& reader) {
Bottle bot;
bool ok = bot.read(reader);
if(closing)
{
_time = -1;
return false;
}
if (!ok && !closing)
{
YARP_ERROR(Logger::get(), "Error reading clock port");
return false;
}
timeMutex.lock();
sec = bot.get(0).asInt32();
nsec = bot.get(1).asInt32();
_time = sec + (nsec*1e-9);
initted = true;
timeMutex.unlock();
listMutex.lock();
Waiters* waiters = static_cast<Waiters*>(pwaiters);
Waiters::iterator waiter_i;
waiter_i = waiters->begin();
while (waiter_i != waiters->end())
{
if (waiter_i->first - _time < 1E-12 )
{
Semaphore *waiterSemaphore = waiter_i->second;
waiter_i = waiters->erase(waiter_i);
if (waiterSemaphore)
waiterSemaphore->post();
}
else
++waiter_i;
}
listMutex.unlock();
return true;
}
示例2: run
void Pointing::run(const Bottle &args) {
yInfo() << "Pointing::run";
Bottle *sensation = sensation_port_in.read();
string obj_name, sentence;
bool no_objects = true;
if (args.size()!=0) {
yDebug()<<args.toString() << args.size();
obj_name = args.get(0).asList()->get(0).asString();
yDebug() << "Object selected: " << obj_name;
sentence = "Okay, this is the ";
no_objects=false;
} else {
if(sensation->size()==0) {
iCub->lookAtPartner();
iCub->say("There are no objects I can point at.");
iCub->home();
return;
}
int id = yarp::os::Random::uniform(0, sensation->size() - 1);
obj_name = sensation->get(id).asList()->get(1).asString();
yDebug() << "Randomly selected: " << id << " " << obj_name;
sentence = "I could point to the ";
}
yDebug() << "[pointing]: opc checkout";
iCub->say(sentence + obj_name, false);
bool succeeded = iCub->point(obj_name);
if (no_objects){
bool look_success = iCub->lookAtPartner();
if (succeeded) {
iCub->say("Do you know that this is a " + obj_name, false);
} else {
iCub->say("I couldn't find the " + obj_name, false);
}
if(look_success) {
yarp::os::Time::delay(1.5);
}
}
iCub->home();
}
示例3: testBlob
void testBlob() {
report(0,"testing blob...");
Bottle bot("{4 42 255} 10 20");
checkEqual(bot.size(),3,"plausible parse");
checkTrue(bot.get(0).isBlob(),"blob present");
checkEqual((int)bot.get(0).asBlobLength(),3,"blob length");
checkEqual(bot.get(0).asBlob()[1],42, "blob match");
report(0,"testing blob with internal null...");
char blob[12]="hello\0world";
const Value v ((void*)blob, sizeof(blob));
checkEqual(12,(int)v.asBlobLength(),"value length");
checkFalse(v.isNull(),"value non-null");
Bottle b;
b.add(v);
checkEqual(b.size(),1,"insertion happened");
checkTrue(b.get(0).isBlob(),"insertion is right type");
checkEqual(12,(int)b.get(0).asBlobLength(),"length within bottle");
}
示例4: respond
bool Recognition::respond(const Bottle& command, Bottle& reply) {
if(command.get(0).asString() == "actionStarted"){
actionDone = false;
}
else if (command.get(0).asString() == "actionStoped"){
actionDone = true;
}
if(command.get(0).asString() == "observ"){
lookAtHand = true;
}else if(command.get(0).asString() == "stopObserv"){
lookAtHand = false;
}
reply.clear();
reply.addString("Recongition module over");
return true;
}
示例5: pauseTracker
bool TRACKERManager::pauseTracker(int id)
{
mutex.wait();
bool reply = true;
Bottle ids = getIDs();
bool gotid = false;
for (int i = 0; i <ids.size(); i++)
{
if (id == ids.get(i).asInt())
{
gotid = true;
yDebug()<< "got the ID " << id <<" == "<< ids.get(i).asInt();
}
}
if (gotid)
{
yDebug() << "[TRACKERManager::pauseTracker] attempting to pause tracker id " << id ;
if (workerThreads[id]->isRunning())
{
workerThreads[id]->suspend();
pausedThreads.push_back(id);
yDebug() << "[TRACKERManager::pauseTracker] done pausing tracker id " << id ;
reply = true;
}
else
{
yError() << "[TRACKERManager::pauseTracker] failed to pause tracker id %d " << id << " - Not running.. ";
reply=false;
}
}
else
{
yError() << "[TRACKERManager::pauseTracker] failed to pause tracker id %d " << id << " - Not running.. ";
reply = false;
}
mutex.post();
return reply;
}
示例6: testSerialCopy
void testSerialCopy() {
report(0,"test serialization by copy");
Value v(3.14);
Bottle b;
b.read(v);
checkEqualish(b.get(0).asDouble(),3.14,"copy to bottle succeeded");
Bottle b2;
b.write(b2);
checkEqualish(b2.get(0).asDouble(),3.14,"copy from bottle succeeded");
}
示例7: v
Vector PMPthread::Bottle2Vector(Bottle Bot)
{
Vector v(Bot.size());
for (int i = 0; i < Bot.size(); i++)
{
v(i) = Bot.get(i).asDouble();
}
return v;
}
示例8: onRead
void PointedLocation::onRead(Bottle &b)
{
fprintf(stdout, "got read from points size %d \n",b.size());
if (b.size()>1)
{
loc.x=(int)b.get(0).asDouble();
loc.y=(int)b.get(1).asDouble();
rxTime=Time::now();
}
}
示例9: addKnowledge
/**
* Add a new entity to the timeKnowledge
* input format :
* <string name> <string timeArg1> <string timeArg2>
*/
void timeKnowledge::addKnowledge(Bottle bInput)
{
if (bInput.size() != 3)
{
yInfo() << "\t" << "Error in addKnowledge : fromBottle. Wrong number of inputs (need 3 inputs : <string name> <string timeArg1> <string timeArg2>)" ;
return;
}
if (!(bInput.get(0).isString() && bInput.get(1).isString() && bInput.get(2).isString()))
{
yInfo() << "\t" << "Error in addKnowledge : fromBottle. Wrong format of inputs (need 3 inputs : <string name> <string timeArg1> <string timeArg2>)" ;
return;
}
struct tm tmTimeArg1 = abmReasoningFunction::string2Time(bInput.get(1).asString().c_str()),
tmTimeArg2 = abmReasoningFunction::string2Time(bInput.get(2).asString().c_str());
timeArg1.push_back(tmTimeArg1);
timeArg2.push_back(tmTimeArg2);
}
示例10: execute
//execute action, stop to go out
Bottle learnPrimitive::execute(){
Bottle bOutput ;
Bottle bRecognized, //received FROM speech recog with transfer information (1/0 (bAnswer))
bAnswer, //response from speech recog without transfer information, including raw sentence
bSemantic; // semantic information of the content of the recognition
string sSay = " What do you want me to do?";
yInfo() << sSay;
iCub->say(sSay);
Bottle bCurrentOrder = nodeNameAction("any");
string orderType = bCurrentOrder.get(0).asString();
if(orderType == "stop"){
string sSay = " Allright, thank you for the exercice";
yInfo() << sSay;
iCub->say(sSay);
return bCurrentOrder ;
}
string orderVerb = bCurrentOrder.get(1).asString();
string orderArg = bCurrentOrder.get(2).asString();
sSay = orderVerb + "ing my " + orderArg;
if(orderArg == "one" || orderArg == "two" || orderArg == "three" || orderArg == "four" || orderArg == "five"){
sSay = orderVerb + "ing " + orderArg;
}
sSay = sSay ;
yInfo() << sSay;
iCub->say(sSay);
if(orderType == "proto-action") {
protoCommand(orderVerb, orderArg);
} else if (orderType == "primitive") {
primitiveCommand(orderVerb, orderArg);
} else {
actionCommand(orderVerb, orderArg);
}
yarp::os::Time::delay(6);
return execute();
}
示例11: activate
bool activate(bool force = false) {
if (force) {
// wipe if forced
clear();
}
// return if namespaces already present
if (spaces.size()!=0) return true;
// read namespace list from config file
NameConfig conf;
if (!conf.fromFile()) {
double now = Time::now();
static double last_shown = now-10;
if (now-last_shown>3) {
last_shown = now;
fprintf(stderr,"warning: YARP name server(s) not configured, ports will be anonymous\n");
fprintf(stderr,"warning: check your namespace and settings with 'yarp detect'\n");
}
return false;
}
Bottle ns = conf.getNamespaces();
// loop through namespaces
for (int i=0; i<ns.size(); i++) {
ConstString n = ns.get(i).asString();
NameConfig conf2;
// read configuration of individual namespace
if (!conf2.fromFile(n.c_str())) {
fprintf(stderr, "Could not find namespace %s\n",
n.c_str());
continue;
}
String mode = conf2.getMode();
Contact address = conf2.getAddress().addName(n);
if (mode=="yarp"||mode=="//") {
// add a yarp namespace
NameSpace *ns = new YarpNameSpace(address);
spaces.push_back(ns);
} else if (mode=="ros") {
// add a ros namespace
NameSpace *ns = new RosNameSpace(address);
spaces.push_back(ns);
} else if (mode=="local") {
NameSpace *ns = new YarpDummyNameSpace;
spaces.push_back(ns);
} else {
// shrug
YARP_SPRINTF1(Logger::get(),error,
"cannot deal with namespace of type %s",
mode.c_str());
return false;
}
}
// cache flags
scan();
return true;
}
示例12: storeImageOIDs
bool autobiographicalMemory::storeImageOIDs(int instance) {
Bottle bRequest;
ostringstream osStoreOIDReq;
osStoreOIDReq << "SELECT \"time\", img_provider_port, relative_path FROM visualdata WHERE img_oid IS NULL";
if (instance >= 0) {
osStoreOIDReq << " AND instance = " << instance;
}
bRequest = requestFromString(osStoreOIDReq.str());
if (bRequest.size() > 0 && bRequest.get(0).toString() != "NULL") {
yInfo() << "[storeImageOIDs] This may take a while!";
}
else {
return true;
}
ostringstream osStoreOID;
for (int i = 0; i < bRequest.size(); i++) {
string imgTime = bRequest.get(i).asList()->get(0).toString().c_str();
string imgProviderPort = bRequest.get(i).asList()->get(1).toString().c_str();
string imgRelativePath = bRequest.get(i).asList()->get(2).toString().c_str();
string fullPath = storingPath + "/" + imgRelativePath;
database_mutex.lock();
unsigned int new_img_oid = ABMDataBase->lo_import(fullPath.c_str());
database_mutex.unlock();
osStoreOID << "UPDATE visualdata SET img_oid=" << new_img_oid;
osStoreOID << " WHERE time='" << imgTime << "' and img_provider_port = '" << imgProviderPort << "';";
if (((i+1) % 100 == 0 && i != 0) || i == bRequest.size() - 1) {
requestFromString(osStoreOID.str());
yInfo() << "[storeImageOIDs] Saved " << i+1 << " images out of " << bRequest.size();
osStoreOID.str("");
}
}
yInfo() << "[storeImageOIDs] All images saved.";
return true;
}
示例13: respond
bool respond(const Bottle& command, Bottle& reply)
{
reply.clear();
if (command.get(0).isInt())
{
if (command.get(0).asInt()==0)
{
fprintf(stderr,"Asking recalibration...\n");
if (inv_dyn)
{
inv_dyn->suspend();
inv_dyn->calibrateOffset();
inv_dyn->resume();
}
fprintf(stderr,"Recalibration complete.\n");
reply.addString("Recalibrated");
return true;
}
}
if (command.get(0).isString())
{
if (command.get(0).asString()=="help")
{
reply.addVocab(Vocab::encode("many"));
reply.addString("Available commands:");
reply.addString("calib all");
reply.addString("calib arms");
reply.addString("calib legs");
reply.addString("calib feet");
return true;
}
else if (command.get(0).asString()=="calib")
{
fprintf(stderr,"Asking recalibration...\n");
if (inv_dyn)
{
calib_enum calib_code=CALIB_ALL;
if (command.get(1).asString()=="all") calib_code=CALIB_ALL;
else if (command.get(1).asString()=="arms") calib_code=CALIB_ARMS;
else if (command.get(1).asString()=="legs") calib_code=CALIB_LEGS;
else if (command.get(1).asString()=="feet") calib_code=CALIB_FEET;
inv_dyn->suspend();
inv_dyn->calibrateOffset(calib_code);
inv_dyn->resume();
}
fprintf(stderr,"Recalibration complete.\n");
reply.addString("Recalibrated");
return true;
}
}
reply.addString("Unknown command");
return true;
}
示例14: getTarget
void CubCartThread::getTarget()
{
Bottle command;
printf("current command: left %f %f %f, right %f %f %f\n", Lxd[0], Lxd[1], Lxd[2], Rxd[0], Rxd[1], Rxd[2]);
if(inputPort.read(command))
{
if(command.get(0).asString()=="left")
{
icartR->stopControl(); //stop the right arm
printf("recieved command: left %f %f %f\n", command.get(1).asDouble(), command.get(2).asDouble(), command.get(3).asDouble());
Lxd[0] = command.get(1).asDouble() - 0.065; //left arm negative in front
Lxd[1] = command.get(2).asDouble() - 0.065; //left arm negative on correct side of body (x)
Lxd[2] = command.get(3).asDouble(); //positive from waist up
// sanity check the position before moving there
if(Lxd[0] < -0.5) Lxd[0] = -0.5;
if(Lxd[0] > -0.1) Lxd[0] = -0.1;
if(Lxd[1] < -0.4) Lxd[1] = -0.4;
if(Lxd[1] > 0.1) Lxd[1] = 0.1;
if(Lxd[2] < -0.2) Lxd[2] = -0.2;
if(Lxd[2] > 0.4) Lxd[2] = 0.4;
icartL->goToPose(Lxd,Lod);
Time::delay(3);
icartL->stopControl(); //stop the left arm
}
else if(command.get(0).asString()=="right")
{
icartL->stopControl(); //stop the left arm
printf("recieved command: right %f %f %f\n", command.get(1).asDouble(), command.get(2).asDouble(), command.get(3).asDouble());
Rxd[0] = command.get(1).asDouble() - 0.04; //right arm negative in front
Rxd[1] = command.get(2).asDouble() + 0.05; //right arm positive on correct side of body
Rxd[2] = command.get(3).asDouble(); //positive from waist up
// sanity check the position before moving there
if(Rxd[0] < -0.5) Rxd[0] = -0.5;
if(Rxd[0] > -0.1) Rxd[0] = -0.1;
if(Rxd[1] > 0.4) Rxd[1] = 0.4;
if(Rxd[1] < 0.0) Rxd[1] = 0.0;
if(Rxd[2] < -0.2) Rxd[2] = -0.2;
if(Rxd[2] > 0.4) Rxd[2] = 0.4;
icartR->goToPose(Rxd,Rod);
Time::delay(3);
icartR->stopControl(); //stop the right arm
}
}
}
示例15: recogMSR
Bottle VisuoThread::recogMSR(string &obj_name)
{
Bottle bDetect;
Bottle *bMSR=recMSRPort.read(false);
if(bMSR!=NULL)
{
bDetect=*bMSR;
obj_name=bDetect.get(0).asString().c_str();
}
return bDetect;
}