00001 //================================================================================================= 00002 // Copyright (c) 2018, Alexander Stumpf, TU Darmstadt 00003 // All rights reserved. 00004 00005 // Redistribution and use in source and binary forms, with or without 00006 // modification, are permitted provided that the following conditions are met: 00007 // * Redistributions of source code must retain the above copyright 00008 // notice, this list of conditions and the following disclaimer. 00009 // * Redistributions in binary form must reproduce the above copyright 00010 // notice, this list of conditions and the following disclaimer in the 00011 // documentation and/or other materials provided with the distribution. 00012 // * Neither the name of the Simulation, Systems Optimization and Robotics 00013 // group, TU Darmstadt nor the names of its contributors may be used to 00014 // endorse or promote products derived from this software without 00015 // specific prior written permission. 00016 00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00018 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00019 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00020 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 00021 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00022 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00023 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00024 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00026 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 //================================================================================================= 00028 00029 #ifndef VIGIR_PATTERN_GENERATOR_H__ 00030 #define VIGIR_PATTERN_GENERATOR_H__ 00031 00032 #include <map> 00033 00034 #include <ros/ros.h> 00035 #include <tf/tf.h> 00036 00037 #include <actionlib/client/simple_action_client.h> 00038 00039 #include <geometry_msgs/Pose.h> 00040 #include <geometry_msgs/PoseStamped.h> 00041 #include <geometry_msgs/PoseWithCovarianceStamped.h> 00042 #include <geometry_msgs/Twist.h> 00043 00044 #include <vigir_footstep_planning_lib/helper.h> 00045 #include <vigir_footstep_planning_msgs/footstep_planning_msgs.h> 00046 #include <vigir_footstep_planning_msgs/step_plan.h> 00047 00048 #include <vigir_pattern_generator/joystick_handler.h> 00049 00050 00051 00052 namespace vigir_footstep_planning 00053 { 00054 class PatternGenerator 00055 { 00056 public: 00057 PatternGenerator(ros::NodeHandle& nh); 00058 virtual ~PatternGenerator(); 00059 00060 void reset(); 00061 void setParams(const msgs::PatternGeneratorParameters& params); 00062 void setEnabled(bool enabled); 00063 bool isEnabled() const; 00064 bool isSimulationMode() const; 00065 00066 bool hasSteps() const; 00067 bool hasNewSteps() const; 00068 void getCompleteStepPlan(msgs::StepPlan& step_plan) const; 00069 void getLastStepSequence(msgs::StepPlan& step_plan) const; 00070 void clearStepPlan(); 00071 00072 int getNextStartStepIndex() const; 00073 00074 void update(const ros::TimerEvent& timer); 00075 void updateFirstChangeableStepIndex(int first_changeable_step_index_); 00076 00077 // simple pattern generator 00078 msgs::ErrorStatus generatePattern(const msgs::StepPlanRequest& step_plan_request, msgs::StepPlan& step_plan); 00079 00080 // typedefs 00081 typedef boost::shared_ptr<PatternGenerator> Ptr; 00082 typedef boost::shared_ptr<PatternGenerator> ConstPtr; 00083 00084 private: 00085 void updateFeetStartPose(const msgs::Foot& foot); 00086 void updateFeetStartPose(const msgs::Feet& feet); 00087 void updateFeetStartPose(const msgs::Step& step); 00088 00089 void generateSteps(unsigned int n); 00090 00091 // handler for joystick input 00092 JoystickHandler::Ptr joystick_handler_; 00093 geometry_msgs::Twist joystick_cmd_; 00094 00095 // limits 00096 double min_vel_x_, max_vel_x_; 00097 double max_vel_y_; 00098 double max_vel_yaw_; 00099 00100 // generator params 00101 std::string world_frame_id_; 00102 unsigned int number_of_steps_needed_; 00103 msgs::PatternGeneratorParameters params_; 00104 00105 // controller feedback 00106 int first_changeable_step_index_; 00107 int next_step_index_needed_; 00108 00109 // state of pattern generator 00110 msgs::Feet::Ptr start_feet_pose_; 00111 unsigned int foot_start_step_index_left_; 00112 unsigned int foot_start_step_index_right_; 00113 mutable bool has_new_steps_; 00114 00115 // generated step plan 00116 StepPlan step_plan_; 00117 msgs::StepPlan last_step_sequence_; 00118 00119 // service clients 00120 ros::ServiceClient generate_feet_pose_client_; 00121 ros::ServiceClient step_plan_request_client_; 00122 ros::ServiceClient stitch_step_plan_client; 00123 00124 // action clients 00125 boost::shared_ptr<actionlib::SimpleActionClient<msgs::ExecuteStepPlanAction>> execute_step_plan_ac_; 00126 }; 00127 } 00128 00129 #endif