#ifndef TANGENT_PLANNER_RANGE_MSG_TANGENT_PLANNER_H #define TANGENT_PLANNER_RANGE_MSG_TANGENT_PLANNER_H #include #include #include #include #include #include "geometry_msgs/Pose2D.h" #include "sensor_msgs/Range.h" #include "geometry_msgs/Twist.h" #define square(x) pow(x, 2) namespace Planner { struct Map{ std::shared_ptr obstacle; std::shared_ptr robot; std::shared_ptr goal; Map(std::shared_ptr &ob, std::shared_ptr &rb, std::shared_ptr &go){ obstacle = ob; robot = rb; goal = go; } Map(std::shared_ptr &rb, std::shared_ptr &go){ robot = rb; goal = go; } }; class TangentPlanner { public: TangentPlanner(); ~TangentPlanner(); int sign(float number); void normalizeAngle(float &angle); float normalizeAngle(float &&angle); bool computeVelocityCommands(); bool isAtGoal(); bool isAtGoalOrientation(); void resetVariables(); bool foundObstacle(); void calculateErrors(); bool setGoal(); void updateVelocity(); bool foundLocalMinima(); float calculateDistance(std::shared_ptr point, std::shared_ptr target); float convertAtan2(float&& angle); float average(float* array, std::size_t index=2, float av=0.0); void shift(float* array,std::size_t index=2); float goal_orientation_=0.f; float goal_distance_=0.f; float prev_angle_error_=0.f; float valid_dis_to_goal_=0.f; float xy_goal_tolerance_=0.05, yaw_goal_tolerance_=0.05; float heuristic_distance_=0.f, prev_heuristic_distance_=0.f; float dfollowed_=0.f; float robot_front_, robot_back_, robot_width_min_, robot_width_max_; bool turned_around_obs_ = false; // control values for turn controller float kp_=0.f, kp_i_=0.f; float sensor_msg_scale_=1.f; float factor_scale_ = 2.0; float max_trans_vel_=0.f, max_rot_vel_=0.f; // control values for motion controller float c_ = 0.f , b_ = 0.f; // the point to be followed std::vector> global_plan_; std::shared_ptr current_pose_; std::shared_ptr range_msg_; std::shared_ptr cmd_ptr_; private: enum BugState { MotionToGoal = 0, FollowBoundary = 1, TurnToGoal = 2, OrientToGoal = 3, StopAtGoal = 4 } state_; enum Controller { Motion = 0, Turn = 1 } controller_; Controller prev_controller_; int cycle_counter_ = 0; std::shared_ptr start_follow_point_; std::vector> map_; //will be calculated for motion controller float k1_ = 0.f; float k2_ = 0.f; float k3_ = 0.f; float error_angle_=0.f,i_error_angle_=0.f; float error_x_=0.f,i_error_x_=0.f; float error_y_=0.f,i_error_y_=0.f; std::tuple,std::shared_ptr>calculateCenter(); float calculateFactor(); void followBoundaries(); void selectDiscontinuityPoint(); void updateController(); void updateState(); void resetError(){ angle_error_t_ = 0; error_angle_ = 0; error_x_ = 0; error_y_ = 0; i_error_y_ = 0; i_error_x_ = 0; } protected: // log files FILE * tof_logfile; FILE * goal_logfile; FILE * odometry_logfile; FILE * twist_logfile; FILE * state_logfile; FILE * error_logfile; FILE * terminal_logfile; FILE * param_logfile; FILE * center_logfile; FILE * custom_logfile; }; } #endif //TANGENT_PLANNER_RANGE_MSG_TANGENT_PLANNER_H