YARP
Yet Another Robot Platform
MobileBaseVelocityControl_nwc_yarp.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
8#include <yarp/os/Log.h>
10#include <yarp/os/LogStream.h>
11#include <mutex>
12#include <cmath>
13
16using namespace yarp::dev;
17using namespace yarp::dev::Nav2D;
18using namespace yarp::os;
19using namespace yarp::sig;
20
21namespace {
22YARP_LOG_COMPONENT(MOBVEL_NWC_YARP, "yarp.device.MobileBaseVelocityControl_nwc_yarp")
23}
24
25//------------------------------------------------------------------------------------------------------------------------------
26
28{
29 m_local_name.clear();
30 m_server_name.clear();
31
32 m_local_name = config.find("local").asString();
33 m_server_name = config.find("server").asString();
34 m_carrier = config.check("carrier", yarp::os::Value("tcp"), "the carrier used for the connection with the server").asString();
35
36 if (m_local_name.empty())
37 {
38 yCError(MOBVEL_NWC_YARP, "open() error you have to provide a valid 'local' param");
39 return false;
40 }
41
42 if (m_server_name.empty())
43 {
44 yCError(MOBVEL_NWC_YARP, "open() error you have to provide a valid 'navigation_server' param");
45 return false;
46 }
47
48 std::string local_rpc_1;
49 std::string remote_rpc_1;
50
51 local_rpc_1 = m_local_name + "/navigation/rpc";
52 remote_rpc_1 = m_server_name + "/rpc";
53
54 if (!m_rpc_port.open(local_rpc_1))
55 {
56 yCError(MOBVEL_NWC_YARP, "open() error could not open rpc port %s, check network", local_rpc_1.c_str());
57 return false;
58 }
59
60 bool ok = true;
61
62 ok = Network::connect(local_rpc_1, remote_rpc_1, m_carrier);
63 if (!ok)
64 {
65 yCError(MOBVEL_NWC_YARP, "open() error could not connect to %s", remote_rpc_1.c_str());
66 return false;
67 }
68
70 {
71 yCError(MOBVEL_NWC_YARP, "Error! Cannot attach the port as a client");
72 return false;
73 }
74
75 return true;
76}
77
79{
81 return true;
82}
83
84bool MobileBaseVelocityControl_nwc_yarp::getLastVelocityCommand(double& x_vel, double& y_vel, double& theta_vel)
85{
86 std::lock_guard <std::mutex> lg(m_mutex);
88 if (!ret.retvalue)
89 {
90 yCError(MOBVEL_NWC_YARP, "Unable to set transformation");
91 return false;
92 }
93 x_vel = ret.x_vel;
94 y_vel = ret.y_vel;
95 theta_vel = ret.theta_vel;
96 return true;
97}
98
99bool MobileBaseVelocityControl_nwc_yarp::applyVelocityCommand(double x_vel, double y_vel, double theta_vel, double timeout)
100{
101 std::lock_guard <std::mutex> lg(m_mutex);
102 return m_RPC.applyVelocityCommandRPC(x_vel,y_vel,theta_vel,timeout);
103}
bool ret
virtual bool applyVelocityCommandRPC(const double x_vel, const double y_vel, const double theta_vel, const double timeout)
virtual return_getLastVelocityCommand getLastVelocityCommandRPC()
bool close() override
Close the DeviceDriver.
bool applyVelocityCommand(double x_vel, double y_vel, double theta_vel, double timeout=0.1) override
Apply a velocity command.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool getLastVelocityCommand(double &x_vel, double &y_vel, double &theta_vel) override
Returns the last applied velocity command.
void close() override
Stop port activity.
Definition: Port.cpp:363
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
Definition: Port.cpp:79
A base class for nested structures that can be searched.
Definition: Searchable.h:63
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
A single value (typically within a Bottle).
Definition: Value.h:43
virtual std::string asString() const
Get string value.
Definition: Value.cpp:234
yarp::os::WireLink & yarp()
Get YARP state associated with this object.
Definition: Wire.h:28
#define yCError(component,...)
Definition: LogComponent.h:213
#define YARP_LOG_COMPONENT(name,...)
Definition: LogComponent.h:76
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.