Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RST-10727] Publish the start/stop status of the fixed-lag smoother #375

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fuse_optimizers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set(build_depends
fuse_variables
pluginlib
roscpp
std_msgs
std_srvs
)

Expand Down
8 changes: 8 additions & 0 deletions fuse_optimizers/include/fuse_optimizers/fixed_lag_smoother.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,20 @@ class FixedLagSmoother : public Optimizer
ros::ServiceServer reset_service_server_; //!< Service that resets the optimizer to its initial state
ros::ServiceServer stop_service_server_; //!< Service that stops and clears the optimizer
ros::ServiceServer start_service_server_; //!< Service that restarts the optimizer
ros::Publisher status_publisher_; //!< Publishing the started/stopped status of the optimizer

/**
* @brief Automatically start the smoother if no ignition sensors are specified
*/
void autostart();

/**
* @brief Publish the optimizer status message
*
* @param[in] running Flag indicating if the optimizer is running
*/
void publishStatus(const bool running);

/**
* @brief Perform any required preprocessing steps before \p computeVariablesToMarginalize() is called
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ struct FixedLagSmootherParams
*/
std::string start_service { "~start" };

/**
* @brief The topic name of the started/stopped status topic
*/
std::string status_topic { "~running" };

/**
* @brief The maximum time to wait for motion models to be generated for a received transaction.
*
Expand Down Expand Up @@ -128,6 +133,7 @@ struct FixedLagSmootherParams
nh.getParam("reset_service", reset_service);
nh.getParam("stop_service", stop_service);
nh.getParam("start_service", start_service);
nh.getParam("status_topic", status_topic);

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

Expand Down
1 change: 1 addition & 0 deletions fuse_optimizers/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<depend>fuse_variables</depend>
<depend>pluginlib</depend>
<depend>roscpp</depend>
<depend>std_msgs</depend>
<depend>std_srvs</depend>
<test_depend>fuse_models</test_depend>
<test_depend>geometry_msgs</test_depend>
Expand Down
24 changes: 22 additions & 2 deletions fuse_optimizers/src/fixed_lag_smoother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <fuse_core/uuid.h>
#include <fuse_optimizers/optimizer.h>
#include <ros/ros.h>
#include <std_msgs/Bool.h>

#include <algorithm>
#include <iterator>
Expand Down Expand Up @@ -115,6 +116,12 @@ FixedLagSmoother::FixedLagSmoother(
&FixedLagSmoother::startServiceCallback,
this);

status_publisher_ = node_handle_.advertise<std_msgs::Bool>(
ros::names::resolve(params_.status_topic),
1,
true);
publishStatus(false);

if (!params_.disabled_at_startup)
{
start();
Expand Down Expand Up @@ -145,6 +152,13 @@ void FixedLagSmoother::autostart()
}
}

void FixedLagSmoother::publishStatus(const bool running)
{
auto status = std_msgs::Bool();
status.data = running;
status_publisher_.publish(status);
}

void FixedLagSmoother::preprocessMarginalization(const fuse_core::Transaction& new_transaction)
{
timestamp_tracking_.addNewTransaction(new_transaction);
Expand Down Expand Up @@ -469,7 +483,10 @@ void FixedLagSmoother::start()
startPlugins();
// Test for auto-start
autostart();
ROS_INFO_STREAM("Starting optimizer complete.");
// Update status topic
publishStatus(true);

ROS_INFO_STREAM("Started optimizer.");
}

void FixedLagSmoother::stop()
Expand Down Expand Up @@ -501,7 +518,10 @@ void FixedLagSmoother::stop()
timestamp_tracking_.clear();
lag_expiration_ = ros::Time(0, 0);
}
ROS_INFO_STREAM("Optimizer stopping complete.");
// Update status topic
publishStatus(false);

ROS_INFO_STREAM("Stopped Optimizer.");
}

void FixedLagSmoother::transactionCallback(
Expand Down
Loading