YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
MobileBaseVelocityControl_nws_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_NWS_YARP, "yarp.device.MobileBaseVelocityControl_nws_yarp")
23}
24
25//------------------------------------------------------------------------------------------------------------------------------
26
28{
29 if (m_iVel)
30 {
32 }
33 else
34 {
35 yCError(MOBVEL_NWS_YARP, "received data on streaming port, but no device attached yet");
36 }
37}
38
39
40//------------------------------------------------------------------------------------------------------------------------------
41
43{
44 if (!parseParams(config)) { return false; }
45
46 //rpc block
47 {
48 std::string local_rpc_1;
49 local_rpc_1 = m_local + "/rpc:i";
50
52 {
53 yCError(MOBVEL_NWS_YARP, "open() error could not open rpc port %s, check network", local_rpc_1.c_str());
54 return false;
55 }
56
58 }
59
60 //streaming input block
61 {
62 std::string local_stream_1;
63 local_stream_1 = m_local + "/data:i";
64
66 {
67 yCError(MOBVEL_NWS_YARP, "open() error could not open port %s, check network", local_stream_1.c_str());
68 return false;
69 }
72 }
73
74 yCInfo(MOBVEL_NWS_YARP) << "Waiting for device to attach";
75 return true;
76}
77
86
88{
89 std::lock_guard lock (m_mutex);
90
91 m_iNavVel = nullptr;
92
93 if (m_RPC)
94 {
95 delete m_RPC;
96 m_RPC = nullptr;
97 }
98
99 return true;
100}
101
103{
104 std::lock_guard lock (m_mutex);
105
106 if (driver->isValid())
107 {
108 driver->view(m_iNavVel);
109 }
110
111 if (nullptr == m_iNavVel)
112 {
113 yCError(MOBVEL_NWS_YARP, "Subdevice passed to attach method is invalid");
114 return false;
115 }
117
119
120 yCInfo(MOBVEL_NWS_YARP) << "Attach complete";
121 return true;
122}
123
125{
126 if (!connection.isValid()) { return false;}
127 if (!m_RPC) { return false;}
128
129 std::lock_guard<std::mutex> lock(m_mutex);
130
131 bool b = m_RPC->read(connection);
132 if (b)
133 {
134 return true;
135 }
136 else
137 {
138 yCDebug(MOBVEL_NWS_YARP) << "read() Command failed";
139 return false;
140 }
141}
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
bool detach() override
Detach the object (you must have first called attach).
bool close() override
Close the DeviceDriver.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool attach(yarp::dev::PolyDriver *driver) override
Attach to another object.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
yarp::dev::Nav2D::INavigation2DVelocityActions * m_iNavVel
void onRead(yarp::dev::MobileBaseVelocity &v) override
yarp::dev::Nav2D::INavigation2DVelocityActions * m_iVel
bool view(T *&x)
Get an interface to the device driver.
double vel_theta
angular velocity of the robot [deg/s]
double vel_y
velocity of the robot [m/s]
double vel_x
velocity of the robot [m/s]
virtual yarp::dev::ReturnValue applyVelocityCommand(double x_vel, double y_vel, double theta_vel, double timeout=0.1)=0
Apply a velocity command.
A container for a device driver.
Definition PolyDriver.h:23
bool isValid() const
Check if device is valid.
A mini-server for performing network communication in the background.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
void useCallback(TypedReaderCallback< T > &callback) override
Set an object whose onRead method will be called when data is available.
void setStrict(bool strict=true) override
Call this to strictly keep all messages, or allow old ones to be quietly dropped.
An interface for reading from a network connection.
virtual bool isValid() const =0
void setReader(PortReader &reader) override
Set an external reader for port data.
Definition Port.cpp:511
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:31
#define yCInfo(component,...)
#define yCError(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.