rm_control
Loading...
Searching...
No Matches
ros_utilities.h
Go to the documentation of this file.
1/*******************************************************************************
2 * BSD 3-Clause License
3 *
4 * Copyright (c) 2021, Qiayuan Liao
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * * Redistributions of source code must retain the above copyright notice, this
11 * list of conditions and the following disclaimer.
12 *
13 * * Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 *
17 * * Neither the name of the copyright holder nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *******************************************************************************/
33
34//
35// Created by qiayuan on 7/7/20.
36//
37
38#pragma once
39
40#include <ros/ros.h>
41#include <XmlRpcException.h>
42
43template <typename T>
44T getParam(ros::NodeHandle& pnh, const std::string& param_name, const T& default_val)
45{
46 T param_val;
47 pnh.param<T>(param_name, param_val, default_val);
48 return param_val;
49}
50
51inline double xmlRpcGetDouble(XmlRpc::XmlRpcValue& value)
52{
53 if (value.getType() == XmlRpc::XmlRpcValue::TypeInt)
54 {
55 const int tmp = value;
56 return (double)tmp;
57 }
58 else
59 return value;
60}
61
62inline double xmlRpcGetDouble(XmlRpc::XmlRpcValue& value, int field)
63{
64 ROS_ASSERT((value[field].getType() == XmlRpc::XmlRpcValue::TypeDouble) ||
65 (value[field].getType() == XmlRpc::XmlRpcValue::TypeInt));
66 XmlRpc::XmlRpcValue value_xml = value[field];
67 return xmlRpcGetDouble(value[field]);
68}
69
70inline double xmlRpcGetDouble(XmlRpc::XmlRpcValue& value, const std::string& field, double default_value)
71{
72 if (value.hasMember(field))
73 {
74 ROS_ASSERT((value[field].getType() == XmlRpc::XmlRpcValue::TypeDouble) ||
75 (value[field].getType() == XmlRpc::XmlRpcValue::TypeInt));
76 return xmlRpcGetDouble(value[field]);
77 }
78 else
79 return default_value;
80}
double xmlRpcGetDouble(XmlRpc::XmlRpcValue &value)
Definition ros_utilities.h:51
T getParam(ros::NodeHandle &pnh, const std::string &param_name, const T &default_val)
Definition ros_utilities.h:44