Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
fuse_optimizers::FixedLagSmoother Class Reference

A fixed-lag smoother implementation that marginalizes out variables that are older than a defined lag time. More...

#include <fixed_lag_smoother.h>

Inheritance diagram for fuse_optimizers::FixedLagSmoother:
Inheritance graph
[legend]

Classes

struct  TransactionQueueElement
 

Public Types

using ParameterType = FixedLagSmootherParams
 

Public Member Functions

 FixedLagSmoother (fuse_core::Graph::UniquePtr graph, const ros::NodeHandle &node_handle=ros::NodeHandle(), const ros::NodeHandle &private_node_handle=ros::NodeHandle("~"))
 Constructor. More...
 
 FUSE_SMART_PTR_DEFINITIONS (FixedLagSmoother)
 
virtual ~FixedLagSmoother ()
 Destructor. More...
 
- Public Member Functions inherited from fuse_optimizers::Optimizer
 FUSE_SMART_PTR_ALIASES_ONLY (Optimizer)
 
 Optimizer (fuse_core::Graph::UniquePtr graph, const ros::NodeHandle &node_handle=ros::NodeHandle(), const ros::NodeHandle &private_node_handle=ros::NodeHandle("~"))
 Constructor. More...
 
virtual ~Optimizer ()
 Destructor. More...
 

Protected Types

using TransactionQueue = std::vector< TransactionQueueElement >
 Queue of Transaction objects, sorted by timestamp. More...
 
- Protected Types inherited from fuse_optimizers::Optimizer
using AssociatedMotionModels = std::unordered_map< std::string, MotionModelGroup >
 sensor -> motion models group More...
 
using MotionModelGroup = std::vector< std::string >
 A set of motion model names. More...
 
using MotionModels = std::unordered_map< std::string, MotionModelUniquePtr >
 
using MotionModelUniquePtr = class_loader::ClassLoader::UniquePtr< fuse_core::MotionModel >
 
using Publishers = std::unordered_map< std::string, PublisherUniquePtr >
 
using PublisherUniquePtr = class_loader::ClassLoader::UniquePtr< fuse_core::Publisher >
 
using SensorModels = std::unordered_map< std::string, SensorModelInfo >
 
using SensorModelUniquePtr = class_loader::ClassLoader::UniquePtr< fuse_core::SensorModel >
 

Protected Member Functions

void autostart ()
 Automatically start the smoother if no ignition sensors are specified. More...
 
ros::Time computeLagExpirationTime () const
 Compute the oldest timestamp that is part of the configured lag window. More...
 
std::vector< fuse_core::UUIDcomputeVariablesToMarginalize (const ros::Time &lag_expiration)
 Compute the set of variables that should be marginalized from the graph. More...
 
ros::Time getStartTime () const
 Thread-safe read-only access to the optimizer start time. More...
 
void optimizationLoop ()
 Function that optimizes all constraints, designed to be run in a separate thread. More...
 
void optimizerTimerCallback (const ros::TimerEvent &event)
 Callback fired at a fixed frequency to trigger a new optimization cycle. More...
 
void postprocessMarginalization (const fuse_core::Transaction &marginal_transaction)
 Perform any required post-marginalization bookkeeping. More...
 
void preprocessMarginalization (const fuse_core::Transaction &new_transaction)
 Perform any required preprocessing steps before computeVariablesToMarginalize() is called. More...
 
void processQueue (fuse_core::Transaction &transaction, const ros::Time &lag_expiration)
 Generate motion model constraints for pending transactions and combine them into a single transaction. More...
 
void publishStatus (const bool running)
 Publish the optimizer status message. More...
 
bool resetServiceCallback (std_srvs::Empty::Request &, std_srvs::Empty::Response &)
 Service callback that resets the optimizer to its original state. More...
 
void setDiagnostics (diagnostic_updater::DiagnosticStatusWrapper &status) override
 Update and publish diagnotics. More...
 
void setStartTime (const ros::Time &start_time)
 Thread-safe write access to the optimizer start time. More...
 
void start ()
 Start the optimizer. More...
 
bool startServiceCallback (std_srvs::Empty::Request &, std_srvs::Empty::Response &)
 Service callback that starts the optimizer plugins after they have been stopped. More...
 
void stop ()
 Stop the optimizer. More...
 
bool stopServiceCallback (std_srvs::Empty::Request &, std_srvs::Empty::Response &)
 Service callback that stops the optimizer plugins and clears the existing graph. Essentially performs a reset, but doesn't immediately restart optimization. More...
 
void transactionCallback (const std::string &sensor_name, fuse_core::Transaction::SharedPtr transaction) override
 Callback fired every time the SensorModel plugin creates a new transaction. More...
 
- Protected Member Functions inherited from fuse_optimizers::Optimizer
bool applyMotionModels (const std::string &sensor_name, fuse_core::Transaction &transaction) const
 Given a transaction and some timestamps, augment the transaction with constraints from all associated motion models. More...
 
void clearCallbacks ()
 Clear all of the callbacks inserted into the callback queue by the injectCallback() method. More...
 
void injectCallback (const std::string &sensor_name, fuse_core::Transaction::SharedPtr transaction)
 Inject a transaction callback function into the global callback queue. More...
 
void loadMotionModels ()
 Configure the motion model plugins specified on the parameter server. More...
 
void loadPublishers ()
 Configure the publisher plugins specified on the parameter server. More...
 
void loadSensorModels ()
 Configure the sensor model plugins specified on the parameter server. More...
 
void notify (fuse_core::Transaction::ConstSharedPtr transaction, fuse_core::Graph::ConstSharedPtr graph)
 Send the sensors, motion models, and publishers updated graph information. More...
 
void startPlugins ()
 Start all configured plugins (motion models, publishers, and sensor models) More...
 
void stopPlugins ()
 Stop all configured plugins (motion models, publishers, and sensor models) More...
 

Protected Attributes

std::atomic< bool > ignited_
 
ros::Time lag_expiration_
 The oldest stamp that is inside the fixed-lag smoother window. More...
 
fuse_core::Transaction marginal_transaction_
 The marginals to add during the next optimization cycle. More...
 
ros::Time optimization_deadline_
 The deadline for the optimization to complete. Triggers a warning if exceeded. More...
 
std::mutex optimization_mutex_
 Mutex held while the graph is begin optimized. More...
 
bool optimization_request_
 Flag to trigger a new optimization. More...
 
std::condition_variable optimization_requested_
 
std::mutex optimization_requested_mutex_
 Required condition variable mutex. More...
 
std::atomic< bool > optimization_running_
 Flag indicating the optimization thread should be running. More...
 
std::thread optimization_thread_
 Thread used to run the optimizer as a background process. More...
 
ros::Timer optimize_timer_
 Trigger an optimization operation at a fixed frequency. More...
 
ParameterType params_
 Configuration settings for this fixed-lag smoother. More...
 
TransactionQueue pending_transactions_
 
std::mutex pending_transactions_mutex_
 Synchronize modification of the pending_transactions_ container. More...
 
ros::ServiceServer reset_service_server_
 Service that resets the optimizer to its initial state. More...
 
ros::ServiceServer start_service_server_
 Service that restarts the optimizer. More...
 
ros::Time start_time_
 The timestamp of the first ignition sensor transaction. More...
 
std::mutex start_time_mutex_
 Synchronize modification to the start_time_ variable. More...
 
std::atomic< bool > started_
 Flag indicating the optimizer has received a transaction from an ignition sensor. More...
 
ros::Publisher status_publisher_
 Publishing the started/stopped status of the optimizer. More...
 
ros::ServiceServer stop_service_server_
 Service that stops and clears the optimizer. More...
 
ceres::Solver::Summary summary_
 Optimization summary, written by optimizationLoop and read by setDiagnostics. More...
 
VariableStampIndex timestamp_tracking_
 Object that tracks the timestamp associated with each variable. More...
 
- Protected Attributes inherited from fuse_optimizers::Optimizer
AssociatedMotionModels associated_motion_models_
 Tracks what motion models should be used for each sensor. More...
 
diagnostic_updater::Updater diagnostic_updater_
 Diagnostic updater. More...
 
ros::Timer diagnostic_updater_timer_
 Diagnostic updater timer. More...
 
double diagnostic_updater_timer_period_ { 1.0 }
 Diagnostic updater timer period in seconds. More...
 
fuse_core::Graph::UniquePtr graph_
 The graph object that holds all variables and constraints. More...
 
pluginlib::ClassLoader< fuse_core::MotionModelmotion_model_loader_
 Pluginlib class loader for MotionModels. More...
 
MotionModels motion_models_
 The set of motion models, addressable by name. More...
 
ros::NodeHandle node_handle_
 Node handle in the public namespace for subscribing and advertising. More...
 
ros::NodeHandle private_node_handle_
 Node handle in the private namespace for reading configuration settings. More...
 
pluginlib::ClassLoader< fuse_core::Publisherpublisher_loader_
 Pluginlib class loader for Publishers. More...
 
Publishers publishers_
 The set of publishers to execute after every graph optimization. More...
 
pluginlib::ClassLoader< fuse_core::SensorModelsensor_model_loader_
 Pluginlib class loader for SensorModels. More...
 
SensorModels sensor_models_
 The set of sensor models, addressable by name. More...
 

Detailed Description

A fixed-lag smoother implementation that marginalizes out variables that are older than a defined lag time.

This implementation assumes that all added variable types are either derived from the fuse_variables::Stamped class, or are directly connected to at least one fuse_variables::Stamped variable via a constraint. The current time of the fixed-lag smoother is determined by the newest stamp of all added fuse_variables::Stamped variables.

During optimization: (1) new variables and constraints are added to the graph (2) the augmented graph is optimized and the variable values are updated (3) all motion models, sensors, and publishers are notified of the updated graph (4) all variables older than "current time - lag duration" are marginalized out.

Optimization is performed at a fixed frequency, controlled by the optimization_frequency parameter. Received sensor transactions are queued while the optimization is processing, then applied to the graph at the start of the next optimization cycle. If the previous optimization is not yet complete when the optimization period elapses, then a warning will be logged but a new optimization will not be started. The previous optimization will run to completion, and the next optimization will not begin until the next scheduled optimization period.

Parameters:

Definition at line 105 of file fixed_lag_smoother.h.

Member Typedef Documentation

◆ ParameterType

Definition at line 109 of file fixed_lag_smoother.h.

◆ TransactionQueue

Queue of Transaction objects, sorted by timestamp.

Note: Because the queue size of the fixed-lag smoother is expected to be small, the sorted queue is implemented using a std::vector. The queue size must exceed several hundred entries before a std::set will outperform a sorted vector.

Also, we sort the queue with the smallest stamp last. This allows us to clear the queue using the more efficient pop_back() operation.

Definition at line 153 of file fixed_lag_smoother.h.

Constructor & Destructor Documentation

◆ FixedLagSmoother()

fuse_optimizers::FixedLagSmoother::FixedLagSmoother ( fuse_core::Graph::UniquePtr  graph,
const ros::NodeHandle node_handle = ros::NodeHandle(),
const ros::NodeHandle private_node_handle = ros::NodeHandle("~") 
)

Constructor.

Parameters
[in]graphThe derived graph object. This allows different graph implementations to be used with the same optimizer code.
[in]node_handleA node handle in the global namespace
[in]private_node_handleA node handle in the node's private namespace

Definition at line 82 of file fixed_lag_smoother.cpp.

◆ ~FixedLagSmoother()

fuse_optimizers::FixedLagSmoother::~FixedLagSmoother ( )
virtual

Destructor.

Definition at line 131 of file fixed_lag_smoother.cpp.

Member Function Documentation

◆ autostart()

void fuse_optimizers::FixedLagSmoother::autostart ( )
protected

Automatically start the smoother if no ignition sensors are specified.

Definition at line 143 of file fixed_lag_smoother.cpp.

◆ computeLagExpirationTime()

ros::Time fuse_optimizers::FixedLagSmoother::computeLagExpirationTime ( ) const
protected

Compute the oldest timestamp that is part of the configured lag window.

Definition at line 167 of file fixed_lag_smoother.cpp.

◆ computeVariablesToMarginalize()

std::vector< fuse_core::UUID > fuse_optimizers::FixedLagSmoother::computeVariablesToMarginalize ( const ros::Time lag_expiration)
protected

Compute the set of variables that should be marginalized from the graph.

This will be called after preprocessMarginalization() and after the graph has been updated with the any previous marginal transactions and new transactions.

Parameters
[in]lag_expirationThe oldest timestamp that should remain in the graph
Returns
A container with the set of variables to marginalize out. Order of the variables is not specified.

Definition at line 176 of file fixed_lag_smoother.cpp.

◆ FUSE_SMART_PTR_DEFINITIONS()

fuse_optimizers::FixedLagSmoother::FUSE_SMART_PTR_DEFINITIONS ( FixedLagSmoother  )

◆ getStartTime()

ros::Time fuse_optimizers::FixedLagSmoother::getStartTime ( ) const
inlineprotected

Thread-safe read-only access to the optimizer start time.

Definition at line 307 of file fixed_lag_smoother.h.

◆ optimizationLoop()

void fuse_optimizers::FixedLagSmoother::optimizationLoop ( )
protected

Function that optimizes all constraints, designed to be run in a separate thread.

This function waits for an optimization or shutdown signal, then either calls optimize() or exits appropriately.

Definition at line 188 of file fixed_lag_smoother.cpp.

◆ optimizerTimerCallback()

void fuse_optimizers::FixedLagSmoother::optimizerTimerCallback ( const ros::TimerEvent event)
protected

Callback fired at a fixed frequency to trigger a new optimization cycle.

This callback checks if a current optimization cycle is still running. If not, a new optimization cycle is started. If so, we simply wait for the next timer event to start another optimization cycle.

Parameters
eventThe ROS timer event metadata

Definition at line 299 of file fixed_lag_smoother.cpp.

◆ postprocessMarginalization()

void fuse_optimizers::FixedLagSmoother::postprocessMarginalization ( const fuse_core::Transaction marginal_transaction)
protected

Perform any required post-marginalization bookkeeping.

The transaction containing the actual changed to the graph is supplied. This will be called before the transaction is actually applied to the graph.

Parameters
[in]marginal_transactionThe actual changes to the graph caused my marginalizing out the requested variables.

Definition at line 183 of file fixed_lag_smoother.cpp.

◆ preprocessMarginalization()

void fuse_optimizers::FixedLagSmoother::preprocessMarginalization ( const fuse_core::Transaction new_transaction)
protected

Perform any required preprocessing steps before computeVariablesToMarginalize() is called.

All new transactions that will be applied to the graph are provided. This does not include the marginal transaction that is computed later.

This method will be called before the graph has been updated.

Parameters
[in]new_transactionAll new, non-marginal-related transactions that will be applied to the graph

Definition at line 162 of file fixed_lag_smoother.cpp.

◆ processQueue()

void fuse_optimizers::FixedLagSmoother::processQueue ( fuse_core::Transaction transaction,
const ros::Time lag_expiration 
)
protected

Generate motion model constraints for pending transactions and combine them into a single transaction.

Transactions are processed sequentially based on timestamp. If motion models are successfully generated for a pending transactions, that transaction is merged into the combined transaction and removed from the pending queue. If motion models fail to generate after the configured transaction_timeout_, the transaction will be deleted from the pending queue and a warning will be displayed.

Parameters
[out]transactionThe transaction object to be augmented with pending motion model and sensor transactions
[in]lag_expirationThe oldest timestamp that should remain in the graph

Definition at line 325 of file fixed_lag_smoother.cpp.

◆ publishStatus()

void fuse_optimizers::FixedLagSmoother::publishStatus ( const bool  running)
protected

Publish the optimizer status message.

Parameters
[in]runningFlag indicating if the optimizer is running

Definition at line 155 of file fixed_lag_smoother.cpp.

◆ resetServiceCallback()

bool fuse_optimizers::FixedLagSmoother::resetServiceCallback ( std_srvs::Empty::Request &  ,
std_srvs::Empty::Response &   
)
protected

Service callback that resets the optimizer to its original state.

Definition at line 460 of file fixed_lag_smoother.cpp.

◆ setDiagnostics()

void fuse_optimizers::FixedLagSmoother::setDiagnostics ( diagnostic_updater::DiagnosticStatusWrapper status)
overrideprotectedvirtual

Update and publish diagnotics.

Parameters
[in]statusThe diagnostic status

Reimplemented from fuse_optimizers::Optimizer.

Definition at line 652 of file fixed_lag_smoother.cpp.

◆ setStartTime()

void fuse_optimizers::FixedLagSmoother::setStartTime ( const ros::Time start_time)
inlineprotected

Thread-safe write access to the optimizer start time.

Definition at line 316 of file fixed_lag_smoother.h.

◆ start()

void fuse_optimizers::FixedLagSmoother::start ( )
protected

Start the optimizer.

Definition at line 480 of file fixed_lag_smoother.cpp.

◆ startServiceCallback()

bool fuse_optimizers::FixedLagSmoother::startServiceCallback ( std_srvs::Empty::Request &  ,
std_srvs::Empty::Response &   
)
protected

Service callback that starts the optimizer plugins after they have been stopped.

Definition at line 474 of file fixed_lag_smoother.cpp.

◆ stop()

void fuse_optimizers::FixedLagSmoother::stop ( )
protected

Stop the optimizer.

Definition at line 499 of file fixed_lag_smoother.cpp.

◆ stopServiceCallback()

bool fuse_optimizers::FixedLagSmoother::stopServiceCallback ( std_srvs::Empty::Request &  ,
std_srvs::Empty::Response &   
)
protected

Service callback that stops the optimizer plugins and clears the existing graph. Essentially performs a reset, but doesn't immediately restart optimization.

Definition at line 468 of file fixed_lag_smoother.cpp.

◆ transactionCallback()

void fuse_optimizers::FixedLagSmoother::transactionCallback ( const std::string &  sensor_name,
fuse_core::Transaction::SharedPtr  transaction 
)
overrideprotectedvirtual

Callback fired every time the SensorModel plugin creates a new transaction.

This callback is responsible for ensuring all associated motion models are applied before any other processing takes place. See Optimizer::applyMotionModels() for a helper function that does just that.

This implementation shares ownership of the transaction object.

Parameters
[in]nameThe name of the sensor that produced the Transaction
[in]transactionThe populated Transaction object created by the loaded SensorModel plugin

Implements fuse_optimizers::Optimizer.

Definition at line 534 of file fixed_lag_smoother.cpp.

Member Data Documentation

◆ ignited_

std::atomic<bool> fuse_optimizers::FixedLagSmoother::ignited_
protected

Flag indicating the optimizer has received a transaction from an ignition sensor and it is queued but not processed yet

Definition at line 160 of file fixed_lag_smoother.h.

◆ lag_expiration_

ros::Time fuse_optimizers::FixedLagSmoother::lag_expiration_
protected

The oldest stamp that is inside the fixed-lag smoother window.

Definition at line 174 of file fixed_lag_smoother.h.

◆ marginal_transaction_

fuse_core::Transaction fuse_optimizers::FixedLagSmoother::marginal_transaction_
protected

The marginals to add during the next optimization cycle.

Definition at line 175 of file fixed_lag_smoother.h.

◆ optimization_deadline_

ros::Time fuse_optimizers::FixedLagSmoother::optimization_deadline_
protected

The deadline for the optimization to complete. Triggers a warning if exceeded.

Definition at line 181 of file fixed_lag_smoother.h.

◆ optimization_mutex_

std::mutex fuse_optimizers::FixedLagSmoother::optimization_mutex_
protected

Mutex held while the graph is begin optimized.

Definition at line 172 of file fixed_lag_smoother.h.

◆ optimization_request_

bool fuse_optimizers::FixedLagSmoother::optimization_request_
protected

Flag to trigger a new optimization.

Definition at line 182 of file fixed_lag_smoother.h.

◆ optimization_requested_

std::condition_variable fuse_optimizers::FixedLagSmoother::optimization_requested_
protected

Condition variable used by the optimization thread to wait until a new optimization is requested by the main thread

Definition at line 183 of file fixed_lag_smoother.h.

◆ optimization_requested_mutex_

std::mutex fuse_optimizers::FixedLagSmoother::optimization_requested_mutex_
protected

Required condition variable mutex.

Definition at line 180 of file fixed_lag_smoother.h.

◆ optimization_running_

std::atomic<bool> fuse_optimizers::FixedLagSmoother::optimization_running_
protected

Flag indicating the optimization thread should be running.

Definition at line 162 of file fixed_lag_smoother.h.

◆ optimization_thread_

std::thread fuse_optimizers::FixedLagSmoother::optimization_thread_
protected

Thread used to run the optimizer as a background process.

Definition at line 156 of file fixed_lag_smoother.h.

◆ optimize_timer_

ros::Timer fuse_optimizers::FixedLagSmoother::optimize_timer_
protected

Trigger an optimization operation at a fixed frequency.

Definition at line 191 of file fixed_lag_smoother.h.

◆ params_

ParameterType fuse_optimizers::FixedLagSmoother::params_
protected

Configuration settings for this fixed-lag smoother.

Definition at line 157 of file fixed_lag_smoother.h.

◆ pending_transactions_

TransactionQueue fuse_optimizers::FixedLagSmoother::pending_transactions_
protected

The set of received transactions that have not been added to the optimizer yet. Transactions are added by the main thread, and removed and processed by the optimization thread.

Definition at line 167 of file fixed_lag_smoother.h.

◆ pending_transactions_mutex_

std::mutex fuse_optimizers::FixedLagSmoother::pending_transactions_mutex_
protected

Synchronize modification of the pending_transactions_ container.

Definition at line 166 of file fixed_lag_smoother.h.

◆ reset_service_server_

ros::ServiceServer fuse_optimizers::FixedLagSmoother::reset_service_server_
protected

Service that resets the optimizer to its initial state.

Definition at line 192 of file fixed_lag_smoother.h.

◆ start_service_server_

ros::ServiceServer fuse_optimizers::FixedLagSmoother::start_service_server_
protected

Service that restarts the optimizer.

Definition at line 194 of file fixed_lag_smoother.h.

◆ start_time_

ros::Time fuse_optimizers::FixedLagSmoother::start_time_
protected

The timestamp of the first ignition sensor transaction.

Definition at line 188 of file fixed_lag_smoother.h.

◆ start_time_mutex_

std::mutex fuse_optimizers::FixedLagSmoother::start_time_mutex_
mutableprotected

Synchronize modification to the start_time_ variable.

Definition at line 187 of file fixed_lag_smoother.h.

◆ started_

std::atomic<bool> fuse_optimizers::FixedLagSmoother::started_
protected

Flag indicating the optimizer has received a transaction from an ignition sensor.

Definition at line 163 of file fixed_lag_smoother.h.

◆ status_publisher_

ros::Publisher fuse_optimizers::FixedLagSmoother::status_publisher_
protected

Publishing the started/stopped status of the optimizer.

Definition at line 195 of file fixed_lag_smoother.h.

◆ stop_service_server_

ros::ServiceServer fuse_optimizers::FixedLagSmoother::stop_service_server_
protected

Service that stops and clears the optimizer.

Definition at line 193 of file fixed_lag_smoother.h.

◆ summary_

ceres::Solver::Summary fuse_optimizers::FixedLagSmoother::summary_
protected

Optimization summary, written by optimizationLoop and read by setDiagnostics.

Definition at line 177 of file fixed_lag_smoother.h.

◆ timestamp_tracking_

VariableStampIndex fuse_optimizers::FixedLagSmoother::timestamp_tracking_
protected

Object that tracks the timestamp associated with each variable.

Definition at line 176 of file fixed_lag_smoother.h.


The documentation for this class was generated from the following files:


fuse_optimizers
Author(s): Stephen Williams , Tom Moore
autogenerated on Thu Apr 24 2025 02:19:11