17#include <rclcpp/rclcpp.hpp>
18#include <boost/shared_ptr.hpp>
19#include <geometry_msgs/msg/pose_stamped.hpp>
20#include <geometry_msgs/msg/pose_with_covariance_stamped.hpp>
21#include <boost/optional.hpp>
22#include <autoware_msgs/msg/ndt_stat.hpp>
23#include <tf2/LinearMath/Vector3.h>
24#include <carma_msgs/msg/system_alert.hpp>
25#include <carma_localization_msgs/msg/localization_status_report.hpp>
27#include <unordered_set>
28#include <carma_ros2_utils/timers/Timer.hpp>
29#include <carma_ros2_utils/timers/TimerFactory.hpp>
30#include <carma_ros2_utils/timers/ROSTimerFactory.hpp>
44 using PosePublisher = std::function<void(
const geometry_msgs::msg::PoseStamped &)>;
46 using StatePublisher = std::function<void(
const carma_localization_msgs::msg::LocalizationStatusReport &)>;
62 rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr logger,
63 std::unique_ptr<carma_ros2_utils::timers::TimerFactory> timer_factory);
79 const autoware_msgs::msg::NDTStat::ConstPtr stats);
93 void initialPoseCallback(
const geometry_msgs::msg::PoseWithCovarianceStamped::SharedPtr msg);
157 rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr
logger_;
162 std::unordered_map<uint32_t, std::pair<TimerUniquePtr, bool>>
timers_;
185 double computeFreq(
const rclcpp::Time &old_stamp,
const rclcpp::Time &new_stamp)
const;
Primary logic class for the localization manager node.
void poseAndStatsCallback(const geometry_msgs::msg::PoseStamped::ConstPtr pose, const autoware_msgs::msg::NDTStat::ConstPtr stats)
Synced callback for the NDT reported pose and status messages.
int lidar_init_sequential_timesteps_counter_
void posePubTick()
Timer callback that controls the publication of the selected pose and status report.
void timerCallback(const LocalizationState origin_state)
Callback for timeouts. Used to trigger timeout signals for the state machine.
uint32_t current_timer_id_
rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr logger_
void gnssPoseCallback(const geometry_msgs::msg::PoseStamped::SharedPtr msg)
Callback for new GNSS messages.
uint32_t nextId()
Generates the next id to be used for a timer.
void stateTransitionCallback(LocalizationState prev_state, LocalizationState new_state, LocalizationSignal signal)
Callback for when a new state was triggered. Allows creation of entry/exit behavior for states.
void initialPoseCallback(const geometry_msgs::msg::PoseWithCovarianceStamped::SharedPtr msg)
Callback for the initial pose provided by Rviz or some external localization initializer.
boost::optional< geometry_msgs::msg::PoseStamped > last_raw_gnss_value_
LocalizationManagerConfig config_
std::unique_ptr< carma_ros2_utils::timers::TimerFactory > timer_factory_
double computeFreq(const rclcpp::Time &old_stamp, const rclcpp::Time &new_stamp) const
Helper function to compute the instantaneous frequency between two times.
std::function< void(const carma_localization_msgs::msg::LocalizationStatusReport &)> StatePublisher
void clearTimers()
Clears the expired timers from the memory of this scheduler.
static const std::unordered_set< std::string > LIDAR_FAILURE_STRINGS
The set of strings which mark a lidar failure in a system alert message.
LocalizationTransitionTable transition_table_
StatePublisher state_pub_
rcl_clock_type_t timer_clock_type_
void systemAlertCallback(const carma_msgs::msg::SystemAlert::SharedPtr alert)
Callback for SystemAlert data. Used to check for lidar failure.
std::unique_ptr< carma_ros2_utils::timers::Timer > TimerUniquePtr
boost::optional< tf2::Vector3 > gnss_offset_
LocalizationState getState() const
Returns the current localization state.
boost::optional< rclcpp::Time > prev_ndt_stamp_
boost::optional< geometry_msgs::msg::PoseStamped > current_pose_
std::function< void(const geometry_msgs::msg::PoseStamped &)> PosePublisher
LocalizationManager(PosePublisher pose_pub, StatePublisher state_pub, ManagedInitialPosePublisher initialpose_pub, const LocalizationManagerConfig &config, rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr logger, std::unique_ptr< carma_ros2_utils::timers::TimerFactory > timer_factory)
Constructor.
double computeNDTFreq(const rclcpp::Time &new_stamp)
Helper function to both compute the NDT Frequency and update the previous pose timestamp.
void setConfig(const LocalizationManagerConfig &config)
Set config.
TimerUniquePtr current_timer_
ManagedInitialPosePublisher initialpose_pub_
std::unordered_map< uint32_t, std::pair< TimerUniquePtr, bool > > timers_
std::function< void(const geometry_msgs::msg::PoseWithCovarianceStamped &)> ManagedInitialPosePublisher
Class defining the state transition table behavior for the LocalizationManager.
LocalizationState
Enum describing the possible states of the localization system.
LocalizationSignal
Enum describing the possible signals to change the current LocalizationState.
Struct to store the configuration settings for the LocalizationManager class.