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

Show use of the yarp::os::PortablePair class, to send messages of mixed type. If the component types follow the YARP network data format, then their composition will also.

/*
* SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
* SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <yarp/os/Bottle.h>
#include <yarp/os/Port.h>
#include <yarp/os/Time.h>
constexpr double loop_delay = 0.25;
int main(int argc, char* argv[])
{
YARP_UNUSED(argc);
YARP_UNUSED(argv);
Network yarp;
Port port;
PortablePair<Bottle, Vector> pp;
port.open("/pp");
pp.head.fromString("this is the bottle part");
int ct = 1;
int ct2 = 1;
while (true) {
Vector v(3);
v[0] = ct;
v[1] = ct2;
v[2] = ct * ct2;
pp.body = v;
port.write(pp);
printf("Sent output to %s...\n", port.getName().c_str());
ct++;
if (ct > 10) {
ct2 = 1 + (ct2 + 1) % 10;
ct = 1;
}
yarp::os::Time::delay(loop_delay);
}
return 0;
}
contains the definition of a Vector type
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:74
Utilities for manipulating the YARP network, including initialization and shutdown.
Definition: Network.h:783
A mini-server for network communication.
Definition: Port.h:47
Group a pair of objects to be sent and received together.
Definition: PortablePair.h:48
void delay(double seconds)
Wait for a certain number of seconds.
Definition: Time.cpp:111
VectorOf< double > Vector
Definition: Vector.h:30
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_UNUSED(var)
Definition: api.h:162
int main(int argc, char *argv[])
Definition: yarpros.cpp:264