YARP
Yet Another Robot Platform
MobileBaseVelocityControl_nws_ros.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
6#define _USE_MATH_DEFINES
7#include <cmath>
8
11#include <yarp/os/Log.h>
13#include <yarp/os/LogStream.h>
14#include <mutex>
15
18using namespace yarp::dev;
19using namespace yarp::dev::Nav2D;
20using namespace yarp::os;
21using namespace yarp::sig;
22
23namespace {
24 YARP_LOG_COMPONENT(MOBVEL_NWS_ROS, "yarp.device.MobileBaseVelocityControl_nws_ros")
25}
26
27//------------------------------------------------------------------------------------------------------------------------------
28
30{
31 m_iNavVel = _iNavVel;
32}
33
35{
36 m_iNavVel = nullptr;
37}
38
40{
41}
42
44{
45 this->close();
46}
47
49{
50 if (m_iNavVel)
51 {
53 }
54 else
55 {
56 yCError(MOBVEL_NWS_ROS, "Subdevice interface not yet initialized");
57 }
58}
59
60//------------------------------------------------------------------------------------------------------------------------------
61
63{
64 if (config.check("node_name") == true)
65 {
66 m_ros_node_name = config.find("node_name").asString();
67 }
68
69 if (config.check("topic_name") == true)
70 {
71 m_ros_topic_name = config.find("topic_name").asString();
72 }
73
74 //attach subdevice if required
75 if (config.check("subdevice"))
76 {
77 Property p;
78 p.fromString(config.toString(), false);
79 p.put("device", config.find("subdevice").asString());
80
81 if (!m_subdev.open(p) || !m_subdev.isValid())
82 {
83 yCError(MOBVEL_NWS_ROS) << "Failed to open subdevice.. check params";
84 return false;
85 }
86
87 if (!attach(&m_subdev))
88 {
89 yCError(MOBVEL_NWS_ROS) << "Failed to attach subdevice.. check params";
90 return false;
91 }
92 }
93 else
94 {
95 yCInfo(MOBVEL_NWS_ROS) << "Waiting for device to attach";
96 }
97
98 //open the subscriber
101
103 {
104 yCError(MOBVEL_NWS_ROS) << " opening " << m_ros_topic_name << " Topic, check your yarp-ROS network configuration\n";
105 return false;
106 }
107
108 //m_command_subscriber->setStrict();
110
111 return true;
112}
113
115{
117 if (m_ros_node) {delete m_ros_node;}
118 if (m_subdev.isValid()) { m_subdev.close(); }
119 return true;
120}
121
122
123bool MobileBaseVelocityControl_nws_ros::detach()
124{
126 return true;
127}
128
129bool MobileBaseVelocityControl_nws_ros::attach(PolyDriver* driver)
130{
132
133 if (driver->isValid())
134 {
135 driver->view(iNavVel);
136 }
137
138 if (nullptr == iNavVel)
139 {
140 yCError(MOBVEL_NWS_ROS, "Subdevice passed to attach method is invalid");
141 return false;
142 }
143
144 m_command_subscriber->init(iNavVel);
145
146 return true;
147}
bool close() override
Close the DeviceDriver.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
MobileBaseVelocityControl_nws_ros: A device which allows a client application to control the velocity...
yarp::dev::Nav2D::INavigation2DVelocityActions * m_iNavVel
virtual void onRead(yarp::rosmsg::geometry_msgs::Twist &v) override
void init(yarp::dev::Nav2D::INavigation2DVelocityActions *m_iNavVel)
bool view(T *&x)
Get an interface to the device driver.
Definition: DeviceDriver.h:88
virtual bool 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 close() override
Close the DeviceDriver.
Definition: PolyDriver.cpp:173
bool isValid() const
Check if device is valid.
Definition: PolyDriver.cpp:196
bool open(const std::string &txt)
Construct and configure a device by its common name.
Definition: PolyDriver.cpp:140
The Node class.
Definition: Node.h:23
A class for storing options and configuration information.
Definition: Property.h:33
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
Definition: Property.cpp:1063
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
Definition: Property.cpp:1015
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 std::string toString() const =0
Return a standard text representation of the content of the object.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
bool topic(const std::string &name)
Set topic to subscribe to.
Definition: Subscriber.h:62
void useCallback(TypedReaderCallback< T > &callback)
Definition: Subscriber.h:135
virtual std::string asString() const
Get string value.
Definition: Value.cpp:234
yarp::rosmsg::geometry_msgs::Vector3 angular
Definition: Twist.h:33
yarp::rosmsg::geometry_msgs::Vector3 linear
Definition: Twist.h:32
yarp::conf::float64_t y
Definition: Vector3.h:38
yarp::conf::float64_t z
Definition: Vector3.h:39
yarp::conf::float64_t x
Definition: Vector3.h:37
#define M_PI
#define yCInfo(component,...)
Definition: LogComponent.h:171
#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.