Corentin Chauvin-Hameau – 2019-2020
Coverage Path Planning for an underwater robot surveying a marine farm
cart_control_nodelet.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  *
4  * \brief Declaration of a nodelet for cheated cartesian control of a robot
5  * \author Corentin Chauvin-Hameau
6  * \date 2020
7  */
8 
9 #ifndef CART_CONTROL_NODELET_HPP
10 #define CART_CONTROL_NODELET_HPP
11 
12 #include <nav_msgs/Path.h>
13 #include <geometry_msgs/Pose.h>
14 #include <nodelet/nodelet.h>
15 #include <ros/ros.h>
16 #include <string>
17 #include <vector>
18 #include <csignal>
19 
20 namespace mfcpp {
21 
22 /**
23  * \brief Nodelet for cheated cartesian control of a robot
24  *
25  * The nodelet just teleports the robot along a given path, not taking into
26  * account any physical constraint.
27  */
28 class CartControlNodelet: public nodelet::Nodelet {
29  public:
32 
33  /**
34  * \brief Function called at beginning of nodelet execution
35  */
36  virtual void onInit();
37 
38  private:
39  // Static members
40  // Note: the timers need to be static since stopped by the SIGINT callback
41  static sig_atomic_t volatile b_sigint_; ///< Whether SIGINT signal has been received
42  static ros::Timer main_timer_; ///< Timer callback for the main function
43 
44  // Private members
45  ros::NodeHandle nh_; ///< Node handler (for topics and services)
46  ros::NodeHandle private_nh_; ///< Private node handler (for parameters)
47  ros::Subscriber path_sub_; ///< Subscriber for the desired path
48  ros::Publisher pose_pub_; ///< Publisher for the output pose
49  nav_msgs::Path path_; ///< Desired path
50  bool path_received_; ///< Whether a new path has been received
51  bool path_processed_; ///< Whether the path has been processed
52  bool path_executed_; ///< Whether the previous path has been executed
53  std::vector<geometry_msgs::Pose> waypoints_; ///< Consecutive poses that the robot will be assigned to
54  int idx_waypoints_; ///< Current position in the waypoints list
55 
56  /// \name ROS parameters
57  ///@{
58  float main_freq_; ///< Frequency of the main loop
59  float robot_speed_; ///< Desired robot speed
60  ///@}
61 
62  /**
63  * \brief Main callback which is called by a timer
64  *
65  * \param timer_event Timer event information
66  */
67  void main_cb(const ros::TimerEvent &timer_event);
68 
69  /**
70  * \brief SINGINT (Ctrl+C) callback to stop the nodelet properly
71  */
72  static void sigint_handler(int s);
73 
74  /**
75  * \brief Callback for the desired path
76  *
77  * \note The frame in which the path is expressed should match with the fixed
78  * frame of the robot simulator.
79  */
80  void path_cb(const nav_msgs::PathConstPtr msg);
81 
82  /**
83  * \brief Computes the poses that the controller will assign to the robot
84  *
85  * \param[in] path Path to follow
86  * \param[in] speed Desired speed of the robot
87  * \param[in] dt Time interval between two poses
88  * \param[out] waypoints List of computed waypoints
89  */
90  void compute_waypoints(const nav_msgs::Path &path, float speed, float dt,
91  std::vector<geometry_msgs::Pose> &waypoints) const;
92 
93 
94 };
95 
96 } // namespace mfcpp
97 
98 #endif
float main_freq_
Frequency of the main loop.
void compute_waypoints(const nav_msgs::Path &path, float speed, float dt, std::vector< geometry_msgs::Pose > &waypoints) const
Computes the poses that the controller will assign to the robot.
Definition: common.hpp:23
static sig_atomic_t volatile b_sigint_
Whether SIGINT signal has been received.
std::vector< geometry_msgs::Pose > waypoints_
Consecutive poses that the robot will be assigned to.
nav_msgs::Path path_
Desired path.
bool path_received_
Whether a new path has been received.
ros::Publisher pose_pub_
Publisher for the output pose.
virtual void onInit()
Function called at beginning of nodelet execution.
static ros::Timer main_timer_
Timer callback for the main function.
void main_cb(const ros::TimerEvent &timer_event)
Main callback which is called by a timer.
int idx_waypoints_
Current position in the waypoints list.
void path_cb(const nav_msgs::PathConstPtr msg)
Callback for the desired path.
static void sigint_handler(int s)
SINGINT (Ctrl+C) callback to stop the nodelet properly.
ros::Subscriber path_sub_
Subscriber for the desired path.
ros::NodeHandle private_nh_
Private node handler (for parameters)
bool path_processed_
Whether the path has been processed.
Nodelet for cheated cartesian control of a robot.
ros::NodeHandle nh_
Node handler (for topics and services)
bool path_executed_
Whether the previous path has been executed.