cob_collision_velocity_filter.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *   http://www.apache.org/licenses/LICENSE-2.0
00009 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 
00018 #ifndef COB_COLLISION_VELOCITY_FILTER_H
00019 #define COB_COLLISION_VELOCITY_FILTER_H
00020 
00021 //##################
00022 //#### includes ####
00023 
00024 // standard includes
00025 //--
00026 
00027 // ROS includes
00028 #include <ros/ros.h>
00029 #include <XmlRpc.h>
00030 
00031 #include <pthread.h>
00032 
00033 // ROS message includes
00034 #include <geometry_msgs/Twist.h>
00035 #include <geometry_msgs/PolygonStamped.h>
00036 #include <geometry_msgs/Polygon.h>
00037 #include <nav_msgs/OccupancyGrid.h>
00038 
00039 #include <boost/tokenizer.hpp>
00040 #include <boost/foreach.hpp>
00041 #include <boost/algorithm/string.hpp>
00042 
00043 // ROS service includes
00044 #include "cob_footprint_observer/GetFootprint.h"
00045 
00046 // dynamic reconfigure includes
00047 #include <dynamic_reconfigure/server.h>
00048 #include <cob_collision_velocity_filter/CollisionVelocityFilterConfig.h>
00049 
00050 // BUT velocity limited marker
00051 #include "velocity_limited_marker.h"
00052 
00053 // Costmap for obstacle detection
00054 #include <tf/transform_listener.h>
00055 #include <costmap_2d/costmap_2d_ros.h>
00061 class CollisionVelocityFilter
00062 {
00063 public:
00064 
00068   CollisionVelocityFilter(costmap_2d::Costmap2DROS * costmap);
00069 
00073   ~CollisionVelocityFilter();
00074 
00080   void joystickVelocityCB(const geometry_msgs::Twist::ConstPtr &twist);
00081 
00086   void readObstacles();
00087 
00091   void getFootprint(const ros::TimerEvent&);
00092 
00098   void dynamicReconfigureCB(const cob_collision_velocity_filter::CollisionVelocityFilterConfig &config,
00099                             const uint32_t level);
00100 
00102   //public
00103   ros::NodeHandle nh_;
00104 
00105   //private
00106   ros::NodeHandle pnh_;
00107 
00109   ros::Timer get_footprint_timer_;
00110 
00112   ros::Publisher topic_pub_command_;
00113   ros::Publisher topic_pub_relevant_obstacles_;
00114 
00116   ros::Subscriber joystick_velocity_sub_, obstacles_sub_;
00117 
00119   dynamic_reconfigure::Server<cob_collision_velocity_filter::CollisionVelocityFilterConfig> dyn_server_;
00120   dynamic_reconfigure::Server<cob_collision_velocity_filter::CollisionVelocityFilterConfig>::CallbackType dynCB_;
00121 
00122 private:
00123   /* core functions */
00124 
00125   costmap_2d::Costmap2DROS* anti_collision_costmap_;
00126   //costmap_2d::Costmap2D costmap;
00131   void performControllerStep();
00132 
00137   void obstacleHandler();
00138 
00139   /* helper functions */
00140 
00144   double sign(double x);
00145 
00151   double getDistance2d(geometry_msgs::Point a, geometry_msgs::Point b);
00152 
00159   bool obstacleValid(double x_obstacle, double y_obstacle);
00160 
00164   void stopMovement();
00165 
00166   pthread_mutex_t m_mutex;
00167 
00168   //obstacle_treshold
00169   int costmap_obstacle_treshold_;
00170 
00171   //frames
00172   std::string global_frame_, robot_frame_;
00173 
00174   //velocity
00175   geometry_msgs::Vector3 robot_twist_linear_, robot_twist_angular_;
00176   double v_max_, vtheta_max_;
00177   double ax_max_, ay_max_, atheta_max_;
00178 
00179   //obstacle avoidance
00180   std::vector<geometry_msgs::Point> robot_footprint_;
00181   double footprint_left_, footprint_right_, footprint_front_, footprint_rear_;
00182   double footprint_left_initial_, footprint_right_initial_, footprint_front_initial_, footprint_rear_initial_;
00183   bool costmap_received_;
00184   nav_msgs::OccupancyGrid last_costmap_received_, relevant_obstacles_;
00185   double influence_radius_, stop_threshold_, obstacle_damping_dist_, use_circumscribed_threshold_;
00186   double closest_obstacle_dist_, closest_obstacle_angle_;
00187 
00188   // variables for slow down behavior
00189   double last_time_;
00190   double kp_, kv_;
00191   double vx_last_, vy_last_, vtheta_last_;
00192   double virt_mass_;
00193 
00194   // BUT velocity limited marker
00195   cob_collision_velocity_filter::VelocityLimitedMarker velocity_limited_marker_;
00196 
00197 };
00198 //CollisionVelocityFilter
00199 
00200 #endif
00201 


cob_collision_velocity_filter
Author(s): Matthias Gruhler, Michal Spanel
autogenerated on Thu Jun 6 2019 21:19:04