Skip to content

Commit

Permalink
Add a topic that reports when the optimizer is started or stopped
Browse files Browse the repository at this point in the history
  • Loading branch information
svwilliams committed Aug 4, 2024
1 parent 18d60b4 commit 517f17d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ 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
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,15 @@ FixedLagSmoother::FixedLagSmoother(
&FixedLagSmoother::startServiceCallback,
this);

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

if (!params_.disabled_at_startup)
{
start();
Expand Down Expand Up @@ -469,7 +479,12 @@ void FixedLagSmoother::start()
startPlugins();
// Test for auto-start
autostart();
ROS_INFO_STREAM("Starting optimizer complete.");
// Update status topic
auto status = std_msgs::Bool();
status.data = true;
status_publisher_.publish(status);

ROS_INFO_STREAM("Started optimizer.");
}

void FixedLagSmoother::stop()
Expand Down Expand Up @@ -501,7 +516,12 @@ void FixedLagSmoother::stop()
timestamp_tracking_.clear();
lag_expiration_ = ros::Time(0, 0);
}
ROS_INFO_STREAM("Optimizer stopping complete.");
// Update status topic
auto status = std_msgs::Bool();
status.data = false;
status_publisher_.publish(status);

ROS_INFO_STREAM("Stopped Optimizer.");
}

void FixedLagSmoother::transactionCallback(
Expand Down

0 comments on commit 517f17d

Please sign in to comment.