YARP
Yet Another Robot Platform
os/summer/summer.cpp

Add up numbers received on a port, and send the result back out.

/*
* Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
* Copyright (C) 2006-2010 RobotCub Consortium
* All rights reserved.
*
* This software may be modified and distributed under the terms of the
* BSD-3-Clause license. See the accompanying LICENSE file for details.
*/
#include <yarp/os/Bottle.h>
#include <iostream>
int main(int argc, char* argv[])
{
YARP_UNUSED(argc);
YARP_UNUSED(argv);
Network yarp;
BufferedPort<Bottle> port;
port.open("/summer");
while (true) {
yInfo() << "waiting for input";
Bottle* input = port.read();
if (input != nullptr) {
yInfo() << "got " << input->toString().c_str();
double total = 0;
for (size_t i = 0; i < input->size(); i++) {
total += input->get(i).asFloat64();
}
Bottle& output = port.prepare();
output.clear();
output.addString("total");
output.addFloat64(total);
yInfo() << "writing " << output.toString().c_str();
port.write();
}
}
return 0;
}
LogStream.h
yarp::os::Bottle
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
Network.h
main
int main(int argc, char *argv[])
Definition: yarpros.cpp:261
YARP_UNUSED
#define YARP_UNUSED(var)
Definition: api.h:159
yarp::os::BufferedPort
A mini-server for performing network communication in the background.
Definition: BufferedPort.h:64
BufferedPort.h
yarp::os::Network
Utilities for manipulating the YARP network, including initialization and shutdown.
Definition: Network.h:786
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yInfo
#define yInfo(...)
Definition: Log.h:260
Bottle.h