A fixed-lag smoother implementation that marginalizes out variables that are older than a defined lag time. More...
#include <fixed_lag_smoother.h>

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::UUID > | computeVariablesToMarginalize (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::MotionModel > | motion_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::Publisher > | publisher_loader_ |
| Pluginlib class loader for Publishers. More... | |
| Publishers | publishers_ |
| The set of publishers to execute after every graph optimization. More... | |
| pluginlib::ClassLoader< fuse_core::SensorModel > | sensor_model_loader_ |
| Pluginlib class loader for SensorModels. More... | |
| SensorModels | sensor_models_ |
| The set of sensor models, addressable by name. More... | |
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.
Definition at line 109 of file fixed_lag_smoother.h.
|
protected |
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.
| 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.
| [in] | graph | The derived graph object. This allows different graph implementations to be used with the same optimizer code. |
| [in] | node_handle | A node handle in the global namespace |
| [in] | private_node_handle | A node handle in the node's private namespace |
Definition at line 82 of file fixed_lag_smoother.cpp.
|
virtual |
Destructor.
Definition at line 131 of file fixed_lag_smoother.cpp.
|
protected |
Automatically start the smoother if no ignition sensors are specified.
Definition at line 143 of file fixed_lag_smoother.cpp.
|
protected |
Compute the oldest timestamp that is part of the configured lag window.
Definition at line 167 of file fixed_lag_smoother.cpp.
|
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.
| [in] | lag_expiration | The oldest timestamp that should remain in the graph |
Definition at line 176 of file fixed_lag_smoother.cpp.
| fuse_optimizers::FixedLagSmoother::FUSE_SMART_PTR_DEFINITIONS | ( | FixedLagSmoother | ) |
|
inlineprotected |
Thread-safe read-only access to the optimizer start time.
Definition at line 307 of file fixed_lag_smoother.h.
|
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.
|
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.
| event | The ROS timer event metadata |
Definition at line 299 of file fixed_lag_smoother.cpp.
|
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.
| [in] | marginal_transaction | The actual changes to the graph caused my marginalizing out the requested variables. |
Definition at line 183 of file fixed_lag_smoother.cpp.
|
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.
| [in] | new_transaction | All new, non-marginal-related transactions that will be applied to the graph |
Definition at line 162 of file fixed_lag_smoother.cpp.
|
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.
| [out] | transaction | The transaction object to be augmented with pending motion model and sensor transactions |
| [in] | lag_expiration | The oldest timestamp that should remain in the graph |
Definition at line 325 of file fixed_lag_smoother.cpp.
|
protected |
Publish the optimizer status message.
| [in] | running | Flag indicating if the optimizer is running |
Definition at line 155 of file fixed_lag_smoother.cpp.
|
protected |
Service callback that resets the optimizer to its original state.
Definition at line 460 of file fixed_lag_smoother.cpp.
|
overrideprotectedvirtual |
Update and publish diagnotics.
| [in] | status | The diagnostic status |
Reimplemented from fuse_optimizers::Optimizer.
Definition at line 652 of file fixed_lag_smoother.cpp.
|
inlineprotected |
Thread-safe write access to the optimizer start time.
Definition at line 316 of file fixed_lag_smoother.h.
|
protected |
Start the optimizer.
Definition at line 480 of file fixed_lag_smoother.cpp.
|
protected |
Service callback that starts the optimizer plugins after they have been stopped.
Definition at line 474 of file fixed_lag_smoother.cpp.
|
protected |
Stop the optimizer.
Definition at line 499 of file fixed_lag_smoother.cpp.
|
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.
|
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.
| [in] | name | The name of the sensor that produced the Transaction |
| [in] | transaction | The populated Transaction object created by the loaded SensorModel plugin |
Implements fuse_optimizers::Optimizer.
Definition at line 534 of file fixed_lag_smoother.cpp.
|
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.
|
protected |
The oldest stamp that is inside the fixed-lag smoother window.
Definition at line 174 of file fixed_lag_smoother.h.
|
protected |
The marginals to add during the next optimization cycle.
Definition at line 175 of file fixed_lag_smoother.h.
|
protected |
The deadline for the optimization to complete. Triggers a warning if exceeded.
Definition at line 181 of file fixed_lag_smoother.h.
|
protected |
Mutex held while the graph is begin optimized.
Definition at line 172 of file fixed_lag_smoother.h.
|
protected |
Flag to trigger a new optimization.
Definition at line 182 of file fixed_lag_smoother.h.
|
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.
|
protected |
Required condition variable mutex.
Definition at line 180 of file fixed_lag_smoother.h.
|
protected |
Flag indicating the optimization thread should be running.
Definition at line 162 of file fixed_lag_smoother.h.
|
protected |
Thread used to run the optimizer as a background process.
Definition at line 156 of file fixed_lag_smoother.h.
|
protected |
Trigger an optimization operation at a fixed frequency.
Definition at line 191 of file fixed_lag_smoother.h.
|
protected |
Configuration settings for this fixed-lag smoother.
Definition at line 157 of file fixed_lag_smoother.h.
|
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.
|
protected |
Synchronize modification of the pending_transactions_ container.
Definition at line 166 of file fixed_lag_smoother.h.
|
protected |
Service that resets the optimizer to its initial state.
Definition at line 192 of file fixed_lag_smoother.h.
|
protected |
Service that restarts the optimizer.
Definition at line 194 of file fixed_lag_smoother.h.
|
protected |
The timestamp of the first ignition sensor transaction.
Definition at line 188 of file fixed_lag_smoother.h.
|
mutableprotected |
Synchronize modification to the start_time_ variable.
Definition at line 187 of file fixed_lag_smoother.h.
|
protected |
Flag indicating the optimizer has received a transaction from an ignition sensor.
Definition at line 163 of file fixed_lag_smoother.h.
|
protected |
Publishing the started/stopped status of the optimizer.
Definition at line 195 of file fixed_lag_smoother.h.
|
protected |
Service that stops and clears the optimizer.
Definition at line 193 of file fixed_lag_smoother.h.
|
protected |
Optimization summary, written by optimizationLoop and read by setDiagnostics.
Definition at line 177 of file fixed_lag_smoother.h.
|
protected |
Object that tracks the timestamp associated with each variable.
Definition at line 176 of file fixed_lag_smoother.h.