Skip to content

Commit

Permalink
Added ParamsParser to MobileBaseVelocityControl_nws_ros2
Browse files Browse the repository at this point in the history
Signed-off-by: Ettore Landini <[email protected]>
  • Loading branch information
elandini84 committed Aug 26, 2024
1 parent 584bc88 commit d0cffc7
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 22 deletions.
3 changes: 3 additions & 0 deletions src/devices/mobileBaseVelocityControl_nws_ros2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ yarp_prepare_plugin(mobileBaseVelocityControl_nws_ros2

if(NOT SKIP_mobileBaseVelocityControl_nws_ros2)
yarp_add_plugin(yarp_mobileBaseVelocityControl_nws_ros2)
generateDeviceParamsParser(MobileBaseVelocityControl_nws_ros2 mobileBaseVelocityControl_nws_ros2)

target_sources(yarp_mobileBaseVelocityControl_nws_ros2
PRIVATE
MobileBaseVelocityControl_nws_ros2.cpp
MobileBaseVelocityControl_nws_ros2.h
MobileBaseVelocityControl_nws_ros2_ParamsParser.h
MobileBaseVelocityControl_nws_ros2_ParamsParser.cpp
)
target_sources(yarp_mobileBaseVelocityControl_nws_ros2 PRIVATE $<TARGET_OBJECTS:Ros2Utils>)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,7 @@ namespace {

bool MobileBaseVelocityControl_nws_ros2::open(yarp::os::Searchable& config)
{
// node_name check
if (!config.check("node_name")) {
yCError(MOBVEL_NWS_ROS2) << "missing node_name parameter";
return false;
}
m_node_name = config.find("node_name").asString();

// topic_name name check
if (!config.check("topic_name")) {
yCError(MOBVEL_NWS_ROS2) << "missing topic_name parameter";
return false;
}
m_topic_name = config.find("topic_name").asString();

parseParams(config);
m_node = NodeCreator::createNode(m_node_name);
m_ros2_subscriber = m_node->create_subscription<geometry_msgs::msg::Twist>(m_topic_name,
10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <yarp/dev/WrapperSingle.h>
#include <geometry_msgs/msg/twist.hpp>
#include <rclcpp/rclcpp.hpp>
#include "MobileBaseVelocityControl_nws_ros2_ParamsParser.h"

#include <mutex>
#include <string>
Expand All @@ -39,16 +40,14 @@ class Ros2InitMobVel
* \brief `MobileBaseVelocityControl_nws_ros2`: A device which allows a client application to control the velocity of a mobile base from ros2.
* The device opens a topic of type `::geometry_msgs::msg::Twist` to receive user commands
*
* Parameters required by this device are:
* | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes |
* |:--------------:|:--------------:|:-------:|:--------------:|:------------------------------:|:------------:|:-----------------------------------------------------------------:|:-----:|
* | node_name | - | string | - | - | Yes | Full name of the opened ros2 node | |
* | topic_name | - | string | - | - | Yes | Full name of the opened ros2 topic | |
* Parameters required by this device are shown in class: MobileBaseVelocityControl_nws_ros2_ParamsParser
* The device is a wrapper for the INavigation2DVelocityActions interface.
*/

class MobileBaseVelocityControl_nws_ros2 :
public yarp::dev::DeviceDriver,
public yarp::dev::WrapperSingle
public yarp::dev::WrapperSingle,
MobileBaseVelocityControl_nws_ros2_ParamsParser
{

public:
Expand All @@ -65,8 +64,6 @@ class MobileBaseVelocityControl_nws_ros2 :
// Spinner
Ros2Spinner* m_spinner{nullptr};

std::string m_node_name = "/mobileBase_VelControl_nws_ros2";
std::string m_topic_name = "/velocity_input";
rclcpp::Subscription<geometry_msgs::msg::Twist>::SharedPtr m_ros2_subscriber;
rclcpp::Node::SharedPtr m_node;
yarp::dev::Nav2D::INavigation2DVelocityActions* m_iNavVel = nullptr;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT)
* SPDX-License-Identifier: LGPL-2.1-or-later
*/


// Generated by yarpDeviceParamParserGenerator (1.0)
// This is an automatically generated file. Please do not edit it.
// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON.

// Generated on: Mon Aug 26 14:52:35 2024


#include "MobileBaseVelocityControl_nws_ros2_ParamsParser.h"
#include <yarp/os/LogStream.h>
#include <yarp/os/Value.h>

namespace {
YARP_LOG_COMPONENT(MobileBaseVelocityControl_nws_ros2ParamsCOMPONENT, "yarp.device.MobileBaseVelocityControl_nws_ros2")
}


MobileBaseVelocityControl_nws_ros2_ParamsParser::MobileBaseVelocityControl_nws_ros2_ParamsParser()
{
}


std::vector<std::string> MobileBaseVelocityControl_nws_ros2_ParamsParser::getListOfParams() const
{
std::vector<std::string> params;
params.push_back("node_name");
params.push_back("topic_name");
return params;
}


bool MobileBaseVelocityControl_nws_ros2_ParamsParser::parseParams(const yarp::os::Searchable & config)
{
//Check for --help option
if (config.check("help"))
{
yCInfo(MobileBaseVelocityControl_nws_ros2ParamsCOMPONENT) << getDocumentationOfDeviceParams();
}

std::string config_string = config.toString();
yarp::os::Property prop_check(config_string.c_str());
//Parser of parameter node_name
{
if (config.check("node_name"))
{
m_node_name = config.find("node_name").asString();
yCInfo(MobileBaseVelocityControl_nws_ros2ParamsCOMPONENT) << "Parameter 'node_name' using value:" << m_node_name;
}
else
{
yCError(MobileBaseVelocityControl_nws_ros2ParamsCOMPONENT) << "Mandatory parameter 'node_name' not found!";
yCError(MobileBaseVelocityControl_nws_ros2ParamsCOMPONENT) << "Description of the parameter: name of the ros2 node";
return false;
}
prop_check.unput("node_name");
}

//Parser of parameter topic_name
{
if (config.check("topic_name"))
{
m_topic_name = config.find("topic_name").asString();
yCInfo(MobileBaseVelocityControl_nws_ros2ParamsCOMPONENT) << "Parameter 'topic_name' using value:" << m_topic_name;
}
else
{
yCError(MobileBaseVelocityControl_nws_ros2ParamsCOMPONENT) << "Mandatory parameter 'topic_name' not found!";
yCError(MobileBaseVelocityControl_nws_ros2ParamsCOMPONENT) << "Description of the parameter: name of the topic where the device must publish the data";
return false;
}
prop_check.unput("topic_name");
}

/*
//This code check if the user set some parameter which are not check by the parser
//If the parser is set in strict mode, this will generate an error
if (prop_check.size() > 0)
{
bool extra_params_found = false;
for (auto it=prop_check.begin(); it!=prop_check.end(); it++)
{
if (m_parser_is_strict)
{
yCError(MobileBaseVelocityControl_nws_ros2ParamsCOMPONENT) << "User asking for parameter: "<<it->name <<" which is unknown to this parser!";
extra_params_found = true;
}
else
{
yCWarning(MobileBaseVelocityControl_nws_ros2ParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!";
}
}
if (m_parser_is_strict && extra_params_found)
{
return false;
}
}
*/
return true;
}


std::string MobileBaseVelocityControl_nws_ros2_ParamsParser::getDocumentationOfDeviceParams() const
{
std::string doc;
doc = doc + std::string("\n=============================================\n");
doc = doc + std::string("This is the help for device: MobileBaseVelocityControl_nws_ros2\n");
doc = doc + std::string("\n");
doc = doc + std::string("This is the list of the parameters accepted by the device:\n");
doc = doc + std::string("'node_name': name of the ros2 node\n");
doc = doc + std::string("'topic_name': name of the topic where the device must publish the data\n");
doc = doc + std::string("\n");
doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n");
doc = doc + " yarpdev --device mobileBaseVelocityControl_nws_ros2 --node_name <mandatory_value> --topic_name <mandatory_value>\n";
doc = doc + std::string("Using only mandatory params:\n");
doc = doc + " yarpdev --device mobileBaseVelocityControl_nws_ros2 --node_name <mandatory_value> --topic_name <mandatory_value>\n";
doc = doc + std::string("=============================================\n\n"); return doc;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT)
* SPDX-License-Identifier: LGPL-2.1-or-later
*/


// Generated by yarpDeviceParamParserGenerator (1.0)
// This is an automatically generated file. Please do not edit it.
// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON.

// Generated on: Mon Aug 26 14:52:35 2024


#ifndef MOBILEBASEVELOCITYCONTROL_NWS_ROS2_PARAMSPARSER_H
#define MOBILEBASEVELOCITYCONTROL_NWS_ROS2_PARAMSPARSER_H

#include <yarp/os/Searchable.h>
#include <yarp/dev/IDeviceDriverParams.h>
#include <string>
#include <cmath>

/**
* This class is the parameters parser for class MobileBaseVelocityControl_nws_ros2.
*
* These are the used parameters:
* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes |
* |:----------:|:--------------:|:------:|:-----:|:-------------:|:--------:|:--------------------------------------------------------:|:------------------------------:|
* | - | node_name | string | - | - | 1 | name of the ros2 node | - |
* | - | topic_name | string | - | - | 1 | name of the topic where the device must publish the data | must begin with an initial '/' |
*
* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters):
* \code{.unparsed}
* yarpdev --device mobileBaseVelocityControl_nws_ros2 --node_name <mandatory_value> --topic_name <mandatory_value>
* \endcode
*
* \code{.unparsed}
* yarpdev --device mobileBaseVelocityControl_nws_ros2 --node_name <mandatory_value> --topic_name <mandatory_value>
* \endcode
*
*/

class MobileBaseVelocityControl_nws_ros2_ParamsParser : public yarp::dev::IDeviceDriverParams
{
public:
MobileBaseVelocityControl_nws_ros2_ParamsParser();
~MobileBaseVelocityControl_nws_ros2_ParamsParser() override = default;

public:
const std::string m_device_classname = {"MobileBaseVelocityControl_nws_ros2"};
const std::string m_device_name = {"mobileBaseVelocityControl_nws_ros2"};
bool m_parser_is_strict = false;
struct parser_version_type
{
int major = 1;
int minor = 0;
};
const parser_version_type m_parser_version = {};

const std::string m_node_name_defaultValue = {""};
const std::string m_topic_name_defaultValue = {""};

std::string m_node_name = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters.
std::string m_topic_name = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters.

bool parseParams(const yarp::os::Searchable & config) override;
std::string getDeviceClassName() const override { return m_device_classname; }
std::string getDeviceName() const override { return m_device_name; }
std::string getDocumentationOfDeviceParams() const override;
std::vector<std::string> getListOfParams() const override;
};

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
| | node_name | string | - | - | Yes | name of the ros2 node |
| | topic_name | string | - | - | Yes | name of the topic where the device must publish the data| must begin with an initial '/' |

0 comments on commit d0cffc7

Please sign in to comment.