Geofencing

0. Definition of the Geofencing Interface

 1namespace autopilot {
 2
 3class Geofencing {
 4
 5public:
 6
 7    using SharedPtr = std::shared_ptr<Geofencing>;
 8    using UniquePtr = std::unique_ptr<Geofencing>;
 9    using WeakPtr = std::weak_ptr<Geofencing>;
10
11    // Configuration for the geofencing
12    struct Config {
13        rclcpp::Node::SharedPtr node;                                           // ROS 2 node ptr (in case the mode needs to create publishers, subscribers, etc.)
14        std::function<State()> get_vehicle_state;                               // Function pointer to get the current state of the vehicle
15        std::function<VehicleStatus()> get_vehicle_status;                      // Function pointer to get the current status of the vehicle
16        std::function<VehicleConstants()> get_vehicle_constants;                // Function pointer to get the current constants of the vehicle
17    };
18
19    // Custom constructor like function - as we must have the default constructor for the pluginlib
20    inline void initialize_geofencing(const Geofencing::Config & config) {
21        
22        // Initialialize the node
23        node_ = config.node;
24
25        // Initialize the function pointers
26        get_vehicle_state_ = config.get_vehicle_state;
27        get_vehicle_status_ = config.get_vehicle_status;
28        get_vehicle_constants_ = config.get_vehicle_constants;
29
30        // Perform custom initialization
31        initialize();
32    }
33
34    /** @brief Initialize the custom geofencing object */
35    virtual void initialize() = 0;
36
37    /** 
38     * @brief Checks if a geofencing violation has ocurred.
39     * @return true if a geofencing violation has ocurred, false otherwise
40     */
41    virtual bool check_geofencing_violation() = 0;
42
43protected:
44
45    // Node
46    rclcpp::Node::SharedPtr node_;
47
48    // Function pointers
49    std::function<State()> get_vehicle_state_;
50    std::function<VehicleStatus()> get_vehicle_status_;
51    std::function<VehicleConstants()> get_vehicle_constants_;
52};
53
54} // namespace autopilot