Skip to content

Commit

Permalink
[RST-10642] Allow the optimizer to remain disabled at startup (#374)
Browse files Browse the repository at this point in the history
* Add ability to leave the fixed-lag smoother stopped on construction
* Don't allow a running instance to be started. Instance must be stopped first.
  • Loading branch information
svwilliams authored Jul 31, 2024
1 parent 89be2bc commit 18d60b4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ namespace fuse_optimizers
struct FixedLagSmootherParams
{
public:
/**
* @brief If true, the state estimator will not start until the start or reset service is called
*/
bool disabled_at_startup { false };

/**
* @brief The duration of the smoothing window in seconds
*/
Expand Down Expand Up @@ -105,6 +110,8 @@ struct FixedLagSmootherParams
void loadFromROS(const ros::NodeHandle& nh)
{
// Read settings from the parameter server
nh.getParam("disabled_at_startup", disabled_at_startup);

fuse_core::getPositiveParam(nh, "lag_duration", lag_duration);

if (nh.hasParam("optimization_frequency"))
Expand Down
2 changes: 2 additions & 0 deletions fuse_optimizers/src/batch_optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ BatchOptimizer::BatchOptimizer(
ros::names::resolve(params_.start_service),
&BatchOptimizer::startServiceCallback,
this);

startPlugins();
}

BatchOptimizer::~BatchOptimizer()
Expand Down
14 changes: 11 additions & 3 deletions fuse_optimizers/src/fixed_lag_smoother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ FixedLagSmoother::FixedLagSmoother(
{
params_.loadFromROS(private_node_handle);

// Test for auto-start
autostart();

// Start the optimization thread
optimization_thread_ = std::thread(&FixedLagSmoother::optimizationLoop, this);

Expand All @@ -117,6 +114,11 @@ FixedLagSmoother::FixedLagSmoother(
ros::names::resolve(params_.start_service),
&FixedLagSmoother::startServiceCallback,
this);

if (!params_.disabled_at_startup)
{
start();
}
}

FixedLagSmoother::~FixedLagSmoother()
Expand Down Expand Up @@ -456,6 +458,12 @@ bool FixedLagSmoother::startServiceCallback(std_srvs::Empty::Request&, std_srvs:

void FixedLagSmoother::start()
{
if (started_)
{
ROS_WARN_STREAM("Requested to start the optimizer while it is already running. Ignoring request.");
return;
}

ROS_INFO_STREAM("Starting optimizer.");
// Tell all the plugins to start
startPlugins();
Expand Down
3 changes: 0 additions & 3 deletions fuse_optimizers/src/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ Optimizer::Optimizer(
loadMotionModels();
loadSensorModels();
loadPublishers();

// Start all the plugins
startPlugins();
}

Optimizer::~Optimizer()
Expand Down

0 comments on commit 18d60b4

Please sign in to comment.