moveit2
The MoveIt Motion Planning Framework for ROS 2.
collision_check.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * Title : collision_check.h
3  * Project : moveit_servo
4  * Created : 1/11/2019
5  * Author : Brian O'Neil, Andy Zelenak, Blake Anderson
6  *
7  * BSD 3-Clause License
8  *
9  * Copyright (c) 2019, Los Alamos National Security, LLC
10  * All rights reserved.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions are met:
14  *
15  * * Redistributions of source code must retain the above copyright notice, this
16  * list of conditions and the following disclaimer.
17  *
18  * * Redistributions in binary form must reproduce the above copyright notice,
19  * this list of conditions and the following disclaimer in the documentation
20  * and/or other materials provided with the distribution.
21  *
22  * * Neither the name of the copyright holder nor the names of its
23  * contributors may be used to endorse or promote products derived from
24  * this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE
30  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
31  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
35  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  *******************************************************************************/
38 
39 #pragma once
40 
41 #include <mutex>
42 
43 #include <rclcpp/rclcpp.hpp>
44 
47 #include <sensor_msgs/msg/joint_state.hpp>
48 #include <std_msgs/msg/float64.hpp>
49 
51 
52 namespace moveit_servo
53 {
55 {
56 public:
62  CollisionCheck(const rclcpp::Node::SharedPtr& node, const ServoParameters::SharedConstPtr& parameters,
63  const planning_scene_monitor::PlanningSceneMonitorPtr& planning_scene_monitor);
64 
66  {
67  if (timer_)
68  {
69  timer_->cancel();
70  }
71  }
72 
74  void start();
75 
77  void setPaused(bool paused);
78 
79 private:
81  void run();
82 
83  // Pointer to the ROS node
84  const std::shared_ptr<rclcpp::Node> node_;
85 
86  // Parameters from yaml
87  const ServoParameters::SharedConstPtr parameters_;
88 
89  // Pointer to the collision environment
90  planning_scene_monitor::PlanningSceneMonitorPtr planning_scene_monitor_;
91 
92  // Robot state and collision matrix from planning scene
93  std::shared_ptr<moveit::core::RobotState> current_state_;
94 
95  // Scale robot velocity according to collision proximity and user-defined thresholds.
96  // I scaled exponentially (cubic power) so velocity drops off quickly after the threshold.
97  // Proximity decreasing --> decelerate
98  double velocity_scale_ = 1;
99  double self_collision_distance_ = 0;
100  double scene_collision_distance_ = 0;
101  bool collision_detected_ = false;
102  bool paused_ = false;
103 
104  const double self_velocity_scale_coefficient_;
105  const double scene_velocity_scale_coefficient_;
106 
107  // collision request
108  collision_detection::CollisionRequest collision_request_;
109  collision_detection::CollisionResult collision_result_;
110 
111  // ROS
112  rclcpp::TimerBase::SharedPtr timer_;
113  double period_; // The loop period, in seconds
114  rclcpp::Publisher<std_msgs::msg::Float64>::SharedPtr collision_velocity_scale_pub_;
115 
116  mutable std::mutex joint_state_mutex_;
117  sensor_msgs::msg::JointState latest_joint_state_;
118 };
119 } // namespace moveit_servo
CollisionCheck(const rclcpp::Node::SharedPtr &node, const ServoParameters::SharedConstPtr &parameters, const planning_scene_monitor::PlanningSceneMonitorPtr &planning_scene_monitor)
Constructor.
void setPaused(bool paused)
Pause or unpause processing servo commands while keeping the timers alive.
void start()
start the Timer that regulates collision check rate
Representation of a collision checking request.
Representation of a collision checking result.
std::shared_ptr< const ServoParameters > SharedConstPtr