limit_cartesian_speed.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2020, Benjamin Scholz
5  * Copyright (c) 2021, Thies Oelerich
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of the authors nor the names of other
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *********************************************************************/
35 
36 /* Authors: Benjamin Scholz, Thies Oelerich */
37 
40 
41 // Name of logger
42 const char* LOGGER_NAME = "trajectory_processing.cartesian_speed";
43 
44 namespace trajectory_processing
45 {
46 bool limitMaxCartesianLinkSpeed(robot_trajectory::RobotTrajectory& trajectory, const double max_speed,
47  const std::string& link_name)
48 {
49  std::vector<const moveit::core::LinkModel*> links;
50 
51  if (!link_name.empty())
52  {
53  const moveit::core::RobotModel& model{ *trajectory.getRobotModel() };
54  bool found = false;
55  const auto* link = model.getLinkModel(link_name, &found);
56 
57  if (!found)
58  ROS_ERROR_STREAM_NAMED(LOGGER_NAME, "Unknown link model '" << link_name << "'");
59  else
60  links.push_back(link);
61  }
62  // In case the link name is not given but the trajectory belongs to a group,
63  // retrieve the end effectors from that joint model group
64  else if (trajectory.getGroup())
65  {
66  trajectory.getGroup()->getEndEffectorTips(links);
67  if (links.empty())
68  {
69  ROS_ERROR_STREAM_NAMED(LOGGER_NAME, "No link(s) specified");
70  }
71  }
72 
73  // Call function for speed setting using the created link model
74  for (const auto& link : links)
75  {
76  if (!limitMaxCartesianLinkSpeed(trajectory, max_speed, link))
77  return false;
78  }
79 
80  return !links.empty();
81 }
82 
83 bool limitMaxCartesianLinkSpeed(robot_trajectory::RobotTrajectory& trajectory, const double max_speed,
84  const moveit::core::LinkModel* link_model)
85 {
86  if (max_speed <= 0.0)
87  {
88  ROS_ERROR_STREAM_NAMED(LOGGER_NAME, "Link speed must be greater than 0.");
89  return false;
90  }
91 
92  size_t num_waypoints = trajectory.getWayPointCount();
93  if (num_waypoints == 0)
94  return false;
95 
96  // do forward kinematics to get Cartesian positions of link for current waypoint
97  double euclidean_distance, new_time_diff, old_time_diff;
98  std::vector<double> time_diff(num_waypoints - 1, 0.0);
99 
100  for (size_t i = 0; i < num_waypoints - 1; i++)
101  {
102  // get link state for current and next waypoint
103  const Eigen::Isometry3d& current_link_state = trajectory.getWayPointPtr(i)->getGlobalLinkTransform(link_model);
104  const Eigen::Isometry3d& next_link_state = trajectory.getWayPointPtr(i + 1)->getGlobalLinkTransform(link_model);
105 
106  // get Euclidean distance between the two waypoints
107  euclidean_distance = (next_link_state.translation() - current_link_state.translation()).norm();
108 
109  new_time_diff = (euclidean_distance / max_speed);
110  old_time_diff = trajectory.getWayPointDurationFromPrevious(i + 1);
111 
112  // slow-down segment if it was too fast before
113  time_diff[i] = std::max(new_time_diff, old_time_diff);
114  }
115  // update time stamps, velocities and accelerations of the trajectory
117  return true;
118 }
119 } // namespace trajectory_processing
moveit::core::LinkModel
A link from the robot. Contains the constant transform applied to the link and its geometry.
Definition: link_model.h:71
robot_trajectory::RobotTrajectory::getWayPointCount
std::size_t getWayPointCount() const
Definition: robot_trajectory.h:131
robot_trajectory::RobotTrajectory::getGroup
const moveit::core::JointModelGroup * getGroup() const
Definition: robot_trajectory.h:118
trajectory_processing::IterativeParabolicTimeParameterization::updateTrajectory
static void updateTrajectory(robot_trajectory::RobotTrajectory &rob_trajectory, const std::vector< double > &time_diff)
Definition: iterative_time_parameterization.cpp:220
robot_trajectory::RobotTrajectory::getRobotModel
const moveit::core::RobotModelConstPtr & getRobotModel() const
Definition: robot_trajectory.h:113
moveit::core::RobotModel
Definition of a kinematic model. This class is not thread safe, however multiple instances can be cre...
Definition: robot_model.h:143
robot_trajectory::RobotTrajectory
Maintain a sequence of waypoints and the time durations between these waypoints.
Definition: robot_trajectory.h:84
iterative_time_parameterization.h
moveit::core::JointModelGroup::getEndEffectorTips
bool getEndEffectorTips(std::vector< const LinkModel * > &tips) const
Get the unique set of end effector tips included in a particular joint model group as defined by the ...
Definition: joint_model_group.cpp:566
trajectory_processing::limitMaxCartesianLinkSpeed
bool limitMaxCartesianLinkSpeed(robot_trajectory::RobotTrajectory &trajectory, const double speed, const moveit::core::LinkModel *link_model)
Definition: limit_cartesian_speed.cpp:83
ROS_ERROR_STREAM_NAMED
#define ROS_ERROR_STREAM_NAMED(name, args)
trajectory_processing
Definition: iterative_spline_parameterization.h:43
robot_trajectory::RobotTrajectory::getWayPointDurationFromPrevious
double getWayPointDurationFromPrevious(std::size_t index) const
Definition: robot_trajectory.h:179
limit_cartesian_speed.h
robot_trajectory::RobotTrajectory::getWayPointPtr
moveit::core::RobotStatePtr & getWayPointPtr(std::size_t index)
Definition: robot_trajectory.h:151
LOGGER_NAME
const char * LOGGER_NAME
Definition: limit_cartesian_speed.cpp:42


moveit_core
Author(s): Ioan Sucan , Sachin Chitta , Acorn Pooley
autogenerated on Sun Nov 3 2024 03:26:14