joint_limits_rosparam.h
Go to the documentation of this file.
1 // Copyright (C) 2013, PAL Robotics S.L.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright notice,
7 // this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name of PAL Robotics S.L. nor the names of its
12 // contributors may be used to endorse or promote products derived from
13 // this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 // POSSIBILITY OF SUCH DAMAGE.
27 
29 
30 #pragma once
31 
32 
33 #include <string>
34 
35 #include <ros/ros.h>
37 
38 namespace joint_limits_interface
39 {
40 
75 inline bool getJointLimits(const std::string& joint_name, const ros::NodeHandle& nh, JointLimits& limits)
76 {
77  // Node handle scoped where the joint limits are defined
78  ros::NodeHandle limits_nh;
79  try
80  {
81  const std::string limits_namespace = "joint_limits/" + joint_name;
82  if (!nh.hasParam(limits_namespace))
83  {
84  ROS_DEBUG_STREAM("No joint limits specification found for joint '" << joint_name <<
85  "' in the parameter server (namespace " << nh.getNamespace() + "/" + limits_namespace << ").");
86  return false;
87  }
88  limits_nh = ros::NodeHandle(nh, limits_namespace);
89  }
90  catch(const ros::InvalidNameException& ex)
91  {
92  ROS_ERROR_STREAM(ex.what());
93  return false;
94  }
95 
96  // Position limits
97  bool has_position_limits = false;
98  if(limits_nh.getParam("has_position_limits", has_position_limits))
99  {
100  if (!has_position_limits) {limits.has_position_limits = false;}
101  double min_pos, max_pos;
102  if (has_position_limits && limits_nh.getParam("min_position", min_pos) && limits_nh.getParam("max_position", max_pos))
103  {
104  limits.has_position_limits = true;
105  limits.min_position = min_pos;
106  limits.max_position = max_pos;
107  }
108 
109  bool angle_wraparound;
110  if (!has_position_limits && limits_nh.getParam("angle_wraparound", angle_wraparound))
111  {
112  limits.angle_wraparound = angle_wraparound;
113  }
114  }
115 
116  // Velocity limits
117  bool has_velocity_limits = false;
118  if(limits_nh.getParam("has_velocity_limits", has_velocity_limits))
119  {
120  if (!has_velocity_limits) {limits.has_velocity_limits = false;}
121  double max_vel;
122  if (has_velocity_limits && limits_nh.getParam("max_velocity", max_vel))
123  {
124  limits.has_velocity_limits = true;
125  limits.max_velocity = max_vel;
126  }
127  }
128 
129  // Acceleration limits
130  bool has_acceleration_limits = false;
131  if(limits_nh.getParam("has_acceleration_limits", has_acceleration_limits))
132  {
133  if (!has_acceleration_limits) {limits.has_acceleration_limits = false;}
134  double max_acc;
135  if (has_acceleration_limits && limits_nh.getParam("max_acceleration", max_acc))
136  {
137  limits.has_acceleration_limits = true;
138  limits.max_acceleration = max_acc;
139  }
140  }
141 
142  // Jerk limits
143  bool has_jerk_limits = false;
144  if(limits_nh.getParam("has_jerk_limits", has_jerk_limits))
145  {
146  if (!has_jerk_limits) {limits.has_jerk_limits = false;}
147  double max_jerk;
148  if (has_jerk_limits && limits_nh.getParam("max_jerk", max_jerk))
149  {
150  limits.has_jerk_limits = true;
151  limits.max_jerk = max_jerk;
152  }
153  }
154 
155  // Effort limits
156  bool has_effort_limits = false;
157  if(limits_nh.getParam("has_effort_limits", has_effort_limits))
158  {
159  if (!has_effort_limits) {limits.has_effort_limits = false;}
160  double max_effort;
161  if (has_effort_limits && limits_nh.getParam("max_effort", max_effort))
162  {
163  limits.has_effort_limits = true;
164  limits.max_effort = max_effort;
165  }
166  }
167 
168  return true;
169 }
170 
194 inline bool getSoftJointLimits(const std::string& joint_name, const ros::NodeHandle& nh, SoftJointLimits& soft_limits)
195 {
196  // Node handle scoped where the soft joint limits are defined
197  ros::NodeHandle limits_nh;
198  try
199  {
200  const std::string limits_namespace = "joint_limits/" + joint_name;
201  if (!nh.hasParam(limits_namespace))
202  {
203  ROS_DEBUG_STREAM("No soft joint limits specification found for joint '" << joint_name <<
204  "' in the parameter server (namespace " << nh.getNamespace() + "/" + limits_namespace << ").");
205  return false;
206  }
207  limits_nh = ros::NodeHandle(nh, limits_namespace);
208  }
209  catch(const ros::InvalidNameException& ex)
210  {
211  ROS_ERROR_STREAM(ex.what());
212  return false;
213  }
214 
215  // Override soft limits if complete specification is found
216  bool has_soft_limits;
217  if(limits_nh.getParam("has_soft_limits", has_soft_limits))
218  {
219  if(has_soft_limits && limits_nh.hasParam("k_position") && limits_nh.hasParam("k_velocity") && limits_nh.hasParam("soft_lower_limit") && limits_nh.hasParam("soft_upper_limit"))
220  {
221  limits_nh.getParam("k_position", soft_limits.k_position);
222  limits_nh.getParam("k_velocity", soft_limits.k_velocity);
223  limits_nh.getParam("soft_lower_limit", soft_limits.min_position);
224  limits_nh.getParam("soft_upper_limit", soft_limits.max_position);
225  return true;
226  }
227  }
228 
229  return false;
230 }
231 
232 }
joint_limits_interface::JointLimits::has_jerk_limits
bool has_jerk_limits
Definition: joint_limits.h:48
joint_limits_interface::JointLimits::max_velocity
double max_velocity
Definition: joint_limits.h:40
joint_limits_interface::JointLimits
Definition: joint_limits.h:36
ROS_ERROR_STREAM
#define ROS_ERROR_STREAM(args)
joint_limits_interface::JointLimits::max_jerk
double max_jerk
Definition: joint_limits.h:42
joint_limits_interface::SoftJointLimits::min_position
double min_position
Definition: joint_limits.h:55
joint_limits_interface::SoftJointLimits::max_position
double max_position
Definition: joint_limits.h:56
ros::NodeHandle::getParam
bool getParam(const std::string &key, bool &b) const
ros.h
joint_limits_interface::getJointLimits
bool getJointLimits(const std::string &joint_name, const ros::NodeHandle &nh, JointLimits &limits)
Populate a JointLimits instance from the ROS parameter server.
Definition: joint_limits_rosparam.h:75
joint_limits_interface
Definition: joint_limits.h:33
joint_limits_interface::JointLimits::max_position
double max_position
Definition: joint_limits.h:39
joint_limits_interface::SoftJointLimits::k_position
double k_position
Definition: joint_limits.h:57
ROS_DEBUG_STREAM
#define ROS_DEBUG_STREAM(args)
joint_limits_interface::SoftJointLimits::k_velocity
double k_velocity
Definition: joint_limits.h:58
joint_limits_interface::JointLimits::max_effort
double max_effort
Definition: joint_limits.h:43
ros::NodeHandle::hasParam
bool hasParam(const std::string &key) const
joint_limits.h
joint_limits_interface::JointLimits::angle_wraparound
bool angle_wraparound
Definition: joint_limits.h:50
joint_limits_interface::JointLimits::has_velocity_limits
bool has_velocity_limits
Definition: joint_limits.h:46
joint_limits_interface::JointLimits::min_position
double min_position
Definition: joint_limits.h:38
joint_limits_interface::JointLimits::has_acceleration_limits
bool has_acceleration_limits
Definition: joint_limits.h:47
ros::InvalidNameException
joint_limits_interface::JointLimits::max_acceleration
double max_acceleration
Definition: joint_limits.h:41
ros::NodeHandle::getNamespace
const std::string & getNamespace() const
joint_limits_interface::SoftJointLimits
Definition: joint_limits.h:53
joint_limits_interface::getSoftJointLimits
bool getSoftJointLimits(const std::string &joint_name, const ros::NodeHandle &nh, SoftJointLimits &soft_limits)
Populate a SoftJointLimits instance from the ROS parameter server.
Definition: joint_limits_rosparam.h:194
joint_limits_interface::JointLimits::has_position_limits
bool has_position_limits
Definition: joint_limits.h:45
joint_limits_interface::JointLimits::has_effort_limits
bool has_effort_limits
Definition: joint_limits.h:49
ros::NodeHandle


joint_limits_interface
Author(s): Adolfo Rodriguez Tsouroukdissian
autogenerated on Fri Nov 3 2023 02:08:07