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

Convert nodes to lifecycle nodes #561

Merged
merged 46 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
a7bc192
feat: modify slam_toolbox_common and dependent code to be buildable w…
kei1107 Dec 11, 2022
b7c2e94
feat: update slam_toolbox_common to LifecycleNode
kei1107 Dec 11, 2022
37d42a1
feat: update online_async_launch.py for auto starting
kei1107 Dec 11, 2022
dbe5d07
fix: fixed cleanup process
kei1107 Dec 11, 2022
caa3ee0
feat: LifecycleNode support for SynchronousSlamToolbox
kei1107 Dec 11, 2022
785166c
fix: remove manual configure
kei1107 Dec 11, 2022
2f03a0b
feat: LifecycleNode support for LocalizationSlamToolbox
kei1107 Dec 11, 2022
b051265
feat: abstraction of some util functions used by merge_maps_kinematic
kei1107 Dec 11, 2022
6434998
feat: abstraction of func missed in b0512656ec6431ab6237545f59f5f922a…
kei1107 Dec 11, 2022
8ac8750
LifecycleNode support for experimental nodes(lifelong/map_and_localiz…
kei1107 Dec 12, 2022
b7120a3
fix: fixed on_shutdown func
kei1107 Dec 12, 2022
49fb007
feat: update solver and laser_utils to use node_interface
kei1107 Dec 12, 2022
650845c
refactor: fixed indent
kei1107 Dec 12, 2022
6d6bea2
feat: update loop_closure_assistant and map_save to use node_interface
kei1107 Dec 12, 2022
b784dcb
feat: update slam_mapper to use node_interface
kei1107 Dec 12, 2022
ef05ccd
fix: revert initialize
kei1107 Dec 12, 2022
78af848
fix: fixed destructor of slam_toolbox_common, add warning when sent_t…
kei1107 Dec 13, 2022
0b8ad82
fix: changed from node_interface to using node template
kei1107 Dec 20, 2022
abff3ef
fix: update CallbackReturn of typedef in slam_toolbox_map_and_localiz…
kei1107 Dec 20, 2022
37648d7
fix: update node template
kei1107 Dec 22, 2022
7f89be2
fix: remove flag. Update to allow joins in lifecycle cleaningup and …
kei1107 Dec 22, 2022
2ea6b34
fix: change logging interface to the logger object.
kei1107 Dec 22, 2022
3997194
fix: pass state argument onto the function
kei1107 Dec 23, 2022
240b36d
fix: update to reset and recreate threads and loop_closure_assistant …
kei1107 Jan 5, 2023
89bcbc8
feat: added mutex to make get_current_state calls thread-safe
kei1107 Dec 30, 2022
d76adf0
feat: merge setParams and configure into on_configure
kei1107 Dec 30, 2022
00a6215
fix: revert reset order
kei1107 Dec 30, 2022
dbdf760
refactor: reformat code
kei1107 Dec 30, 2022
7b213e8
fix: fixed variable name (get_state_id -> state_id)
kei1107 Jan 8, 2023
89d4a12
feat: updated threads join to use boost::interrupt.
kei1107 Jan 24, 2023
bac68a7
chore: install lifelong_slam_toolbox_node
kei1107 Feb 3, 2023
444c5d2
fix: fixed namespace, feat: support autostart
kei1107 Feb 3, 2023
ca2838d
feat: update parameter declaration position
kei1107 Feb 3, 2023
2f3bd62
feat: update set position of processor_type
kei1107 Feb 3, 2023
c0216a9
fix: move reprocessing_transform initialization to activation stage
kei1107 Feb 3, 2023
afcb0c1
feat: use set interfaces function in the activation stage
kei1107 Feb 3, 2023
de89555
fix: create map_and_localization ros interface in the activation stage
kei1107 Feb 3, 2023
027cd7e
fix: fixed reset order
kei1107 Feb 5, 2023
319607f
fixed conflict
kei1107 Nov 30, 2023
c5dcb11
feat: follow the latest changes
kei1107 Nov 30, 2023
f823647
feat: lifecycle support of rviz_plugin
kei1107 Nov 30, 2023
2c4f9ea
fixed conflict
kei1107 Dec 6, 2023
27ace6d
feat: change stack memory within a node for Composable Node
kei1107 Dec 6, 2023
21e9e6b
feat: support of bond connection for lifecycle_manager
kei1107 Dec 8, 2023
1cd071a
feat: change rviz_plugin logging to continuous
kei1107 Jan 4, 2024
e832151
fix: fixed typo, add EOF
kei1107 Jan 4, 2024
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
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ find_package(std_msgs REQUIRED)
find_package(std_srvs REQUIRED)
find_package(builtin_interfaces REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(lifecycle_msgs REQUIRED)
find_package(rclcpp_lifecycle REQUIRED)
find_package(rviz_common REQUIRED)
find_package(rviz_default_plugins REQUIRED)
find_package(rviz_ogre_vendor REQUIRED)
Expand Down Expand Up @@ -52,6 +54,8 @@ set(dependencies
std_msgs
std_srvs
builtin_interfaces
rclcpp_lifecycle
lifecycle_msgs
rviz_common
rviz_default_plugins
rviz_ogre_vendor
Expand Down Expand Up @@ -123,7 +127,7 @@ rosidl_get_typesupport_target(cpp_typesupport_target ${PROJECT_NAME} "rosidl_typ
target_link_libraries(SlamToolboxPlugin "${cpp_typesupport_target}")
target_compile_definitions(SlamToolboxPlugin PUBLIC "PLUGINLIB__DISABLE_BOOST_FUNCTIONS")
target_compile_definitions(SlamToolboxPlugin PRIVATE "RVIZ_DEFAULT_PLUGINS_BUILDING_LIBRARY")
pluginlib_export_plugin_description_file(rviz_common rviz_plugins.xml)
pluginlib_export_plugin_description_file(rviz_common rviz_plugins.xml)

#### Ceres Plugin
add_library(ceres_solver_plugin solvers/ceres_solver.cpp)
Expand Down Expand Up @@ -190,6 +194,7 @@ install(TARGETS async_slam_toolbox_node
sync_slam_toolbox_node
localization_slam_toolbox_node
map_and_localization_slam_toolbox_node
# lifelong_slam_toolbox_node
SteveMacenski marked this conversation as resolved.
Show resolved Hide resolved
merge_maps_kinematic
${libraries}
ARCHIVE DESTINATION lib
Expand Down
2 changes: 2 additions & 0 deletions include/slam_toolbox/experimental/slam_toolbox_lifelong.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class LifelongSlamToolbox : public SlamToolbox
public:
explicit LifelongSlamToolbox(rclcpp::NodeOptions options);
~LifelongSlamToolbox() {}
CallbackReturn on_configure(const rclcpp_lifecycle::State &) override;
CallbackReturn on_cleanup(const rclcpp_lifecycle::State &) override;

// computation metrics
double computeObjectiveScore(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class MapAndLocalizationSlamToolbox : public LocalizationSlamToolbox
virtual ~MapAndLocalizationSlamToolbox() {}
void loadPoseGraphByParams() override;
void configure() override;
CallbackReturn on_configure(const rclcpp_lifecycle::State &) override;
CallbackReturn on_cleanup(const rclcpp_lifecycle::State &) override;

protected:
void laserCallback(
Expand Down
7 changes: 5 additions & 2 deletions include/slam_toolbox/laser_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <vector>

#include "rclcpp/rclcpp.hpp"
#include "rclcpp_lifecycle/lifecycle_node.hpp"
#include "slam_toolbox/toolbox_types.hpp"
#include "tf2/utils.h"

Expand Down Expand Up @@ -75,8 +76,9 @@ class LaserMetadata
class LaserAssistant
{
public:
template<class NodeT>
SteveMacenski marked this conversation as resolved.
Show resolved Hide resolved
LaserAssistant(
rclcpp::Node::SharedPtr node, tf2_ros::Buffer * tf,
std::shared_ptr<NodeT> node, tf2_ros::Buffer * tf,
SteveMacenski marked this conversation as resolved.
Show resolved Hide resolved
const std::string & base_frame);
~LaserAssistant();
LaserMetadata toLaserMetadata(sensor_msgs::msg::LaserScan scan);
Expand All @@ -85,7 +87,8 @@ class LaserAssistant
karto::LaserRangeFinder * makeLaser(const double & mountingYaw);
bool isInverted(double & mountingYaw);

rclcpp::Node::SharedPtr node_;
rclcpp::Logger logger_;
rclcpp::node_interfaces::NodeParametersInterface::SharedPtr parameters_interface_;
tf2_ros::Buffer * tf_;
sensor_msgs::msg::LaserScan scan_;
std::string frame_, base_frame_;
Expand Down
17 changes: 13 additions & 4 deletions include/slam_toolbox/loop_closure_assistant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "tf2_geometry_msgs/tf2_geometry_msgs.hpp"
#include "tf2/utils.h"
#include "rclcpp/rclcpp.hpp"
#include "rclcpp_lifecycle/lifecycle_node.hpp"
#include "interactive_markers/interactive_marker_server.hpp"
#include "interactive_markers/menu_handler.hpp"

Expand All @@ -44,8 +45,9 @@ using namespace ::toolbox_types; // NOLINT
class LoopClosureAssistant
{
public:
template<class NodeT>
LoopClosureAssistant(
rclcpp::Node::SharedPtr node, karto::Mapper * mapper,
std::shared_ptr<NodeT> node, karto::Mapper * mapper,
laser_utils::ScanHolder * scan_holder, PausedState & state,
ProcessType & processor_type);

Expand All @@ -54,15 +56,18 @@ class LoopClosureAssistant
const visualization_msgs::msg::InteractiveMarkerFeedback::ConstSharedPtr feedback);
void publishGraph();
void setMapper(karto::Mapper * mapper);
void on_activate();
void on_deactivate();
bool is_activated();

private:
bool manualLoopClosureCallback(
const std::shared_ptr<rmw_request_id_t> request_header,
const std::shared_ptr<slam_toolbox::srv::LoopClosure::Request> req,
const std::shared_ptr<slam_toolbox::srv::LoopClosure::Request> req,
std::shared_ptr<slam_toolbox::srv::LoopClosure::Response> resp);
bool clearChangesCallback(
const std::shared_ptr<rmw_request_id_t> request_header,
const std::shared_ptr<slam_toolbox::srv::Clear::Request> req,
const std::shared_ptr<slam_toolbox::srv::Clear::Request> req,
std::shared_ptr<slam_toolbox::srv::Clear::Response> resp);
bool interactiveModeCallback(
const std::shared_ptr<rmw_request_id_t> request_header,
Expand All @@ -86,10 +91,14 @@ class LoopClosureAssistant
std::unique_ptr<interactive_markers::InteractiveMarkerServer> interactive_server_;
boost::mutex interactive_mutex_;
bool interactive_mode_, enable_interactive_mode_;
rclcpp::Node::SharedPtr node_;
std::string map_frame_;
PausedState & state_;
ProcessType & processor_type_;

rclcpp::Clock::SharedPtr clock_;
SteveMacenski marked this conversation as resolved.
Show resolved Hide resolved
rclcpp::Logger logger_;
rclcpp::node_interfaces::NodeParametersInterface::SharedPtr parameters_interface_;
bool is_activated_;
};

} // namespace loop_closure_assistant
Expand Down
6 changes: 4 additions & 2 deletions include/slam_toolbox/map_saver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <memory>
#include <chrono>
#include "rclcpp/rclcpp.hpp"
#include "rclcpp_lifecycle/lifecycle_node.hpp"
#include "slam_toolbox/toolbox_msgs.hpp"

namespace map_saver
Expand All @@ -32,7 +33,8 @@ namespace map_saver
class MapSaver
{
public:
MapSaver(rclcpp::Node::SharedPtr node, const std::string & service_name);
template<class NodeT>
MapSaver(std::shared_ptr<NodeT> node, const std::string & map_name);

protected:
bool saveMapCallback(
Expand All @@ -41,7 +43,7 @@ class MapSaver
std::shared_ptr<slam_toolbox::srv::SaveMap::Response> response);

private:
rclcpp::Node::SharedPtr node_;
rclcpp::Logger logger_;
rclcpp::Service<slam_toolbox::srv::SaveMap>::SharedPtr server_;
rclcpp::Subscription<nav_msgs::msg::OccupancyGrid>::SharedPtr sub_;
std::string service_name_, map_name_;
Expand Down
8 changes: 6 additions & 2 deletions include/slam_toolbox/serialization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
#include <sys/stat.h>
#include <vector>
#include <string>
#include <memory>
#include "rclcpp/rclcpp.hpp"
#include "rclcpp_lifecycle/lifecycle_node.hpp"
#include "karto_sdk/Mapper.h"

namespace serialization
Expand All @@ -34,11 +36,12 @@ inline bool fileExists(const std::string & name)
return stat(name.c_str(), &buffer) == 0;
}

template<class NodeT>
inline bool write(
const std::string & filename,
karto::Mapper & mapper,
karto::Dataset & dataset,
rclcpp::Node::SharedPtr node)
std::shared_ptr<NodeT> node)
{
try {
mapper.SaveToFile(filename + std::string(".posegraph"));
Expand All @@ -51,11 +54,12 @@ inline bool write(
}
}

template<class NodeT>
inline bool read(
const std::string & filename,
karto::Mapper & mapper,
karto::Dataset & dataset,
rclcpp::Node::SharedPtr node)
std::shared_ptr<NodeT> node)
{
if (!fileExists(filename + std::string(".posegraph"))) {
RCLCPP_ERROR(node->get_logger(),
Expand Down
5 changes: 4 additions & 1 deletion include/slam_toolbox/slam_mapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <memory>
#include "geometry_msgs/msg/quaternion.hpp"
#include "rclcpp/rclcpp.hpp"
#include "rclcpp_lifecycle/lifecycle_node.hpp"
#include "tf2_geometry_msgs/tf2_geometry_msgs.hpp"
#include "tf2/utils.h"
#include "slam_toolbox/toolbox_types.hpp"
Expand All @@ -46,7 +47,9 @@ class SMapper
// convert TF pose to karto pose
karto::Pose2 toKartoPose(const tf2::Transform & pose) const;

void configure(const rclcpp::Node::SharedPtr & node);
template<class NodeT>
void configure(const std::shared_ptr<NodeT> & node);

void Reset();

// // processors
Expand Down
1 change: 1 addition & 0 deletions include/slam_toolbox/slam_toolbox_async.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class AsynchronousSlamToolbox : public SlamToolbox
public:
explicit AsynchronousSlamToolbox(rclcpp::NodeOptions options);
~AsynchronousSlamToolbox() {}
CallbackReturn on_configure(const rclcpp_lifecycle::State &) override;

protected:
void laserCallback(
Expand Down
22 changes: 17 additions & 5 deletions include/slam_toolbox/slam_toolbox_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
#include <memory>
#include <fstream>

#include "lifecycle_msgs/msg/state.hpp"
#include "rclcpp/rclcpp.hpp"
#include "rclcpp_lifecycle/lifecycle_node.hpp"
#include "rclcpp_lifecycle/lifecycle_publisher.hpp"
#include "message_filters/subscriber.h"
#include "tf2_ros/transform_broadcaster.h"
#include "tf2_ros/transform_listener.h"
Expand All @@ -56,7 +59,7 @@ namespace slam_toolbox
using namespace ::toolbox_types; // NOLINT
using namespace ::karto; // NOLINT

class SlamToolbox : public rclcpp::Node
class SlamToolbox : public rclcpp_lifecycle::LifecycleNode
{
public:
explicit SlamToolbox(rclcpp::NodeOptions);
Expand All @@ -65,6 +68,12 @@ class SlamToolbox : public rclcpp::Node
virtual void configure();
virtual void loadPoseGraphByParams();

CallbackReturn on_configure(const rclcpp_lifecycle::State &) override;
CallbackReturn on_activate(const rclcpp_lifecycle::State &) override;
CallbackReturn on_deactivate(const rclcpp_lifecycle::State &) override;
CallbackReturn on_cleanup(const rclcpp_lifecycle::State &) override;
CallbackReturn on_shutdown(const rclcpp_lifecycle::State & state) override;

protected:
// threads
void publishVisualizations();
Expand Down Expand Up @@ -130,11 +139,13 @@ class SlamToolbox : public rclcpp::Node
std::unique_ptr<tf2_ros::Buffer> tf_;
std::unique_ptr<tf2_ros::TransformListener> tfL_;
std::unique_ptr<tf2_ros::TransformBroadcaster> tfB_;
std::unique_ptr<message_filters::Subscriber<sensor_msgs::msg::LaserScan>> scan_filter_sub_;
std::unique_ptr<message_filters::Subscriber<sensor_msgs::msg::LaserScan,
rclcpp_lifecycle::LifecycleNode>> scan_filter_sub_;
std::unique_ptr<tf2_ros::MessageFilter<sensor_msgs::msg::LaserScan>> scan_filter_;
std::shared_ptr<rclcpp::Publisher<nav_msgs::msg::OccupancyGrid>> sst_;
std::shared_ptr<rclcpp::Publisher<nav_msgs::msg::MapMetaData>> sstm_;
std::shared_ptr<rclcpp::Publisher<geometry_msgs::msg::PoseWithCovarianceStamped>> pose_pub_;
std::shared_ptr<rclcpp_lifecycle::LifecyclePublisher<nav_msgs::msg::OccupancyGrid>> sst_;
std::shared_ptr<rclcpp_lifecycle::LifecyclePublisher<nav_msgs::msg::MapMetaData>> sstm_;
std::shared_ptr<rclcpp_lifecycle::LifecyclePublisher<
geometry_msgs::msg::PoseWithCovarianceStamped>> pose_pub_;
std::shared_ptr<rclcpp::Service<nav_msgs::srv::GetMap>> ssMap_;
std::shared_ptr<rclcpp::Service<slam_toolbox::srv::Pause>> ssPauseMeasurements_;
std::shared_ptr<rclcpp::Service<slam_toolbox::srv::SerializePoseGraph>> ssSerialize_;
Expand Down Expand Up @@ -172,6 +183,7 @@ class SlamToolbox : public rclcpp::Node
ProcessType processor_type_;
std::unique_ptr<karto::Pose2> process_near_pose_;
tf2::Transform reprocessing_transform_;
bool do_threads_clean_up_;
SteveMacenski marked this conversation as resolved.
Show resolved Hide resolved

// pluginlib
pluginlib::ClassLoader<karto::ScanSolver> solver_loader_;
Expand Down
2 changes: 2 additions & 0 deletions include/slam_toolbox/slam_toolbox_localization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class LocalizationSlamToolbox : public SlamToolbox
explicit LocalizationSlamToolbox(rclcpp::NodeOptions options);
virtual ~LocalizationSlamToolbox() {}
virtual void loadPoseGraphByParams();
CallbackReturn on_configure(const rclcpp_lifecycle::State &) override;
CallbackReturn on_cleanup(const rclcpp_lifecycle::State &) override;

protected:
virtual void laserCallback(
Expand Down
2 changes: 2 additions & 0 deletions include/slam_toolbox/slam_toolbox_sync.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class SynchronousSlamToolbox : public SlamToolbox
explicit SynchronousSlamToolbox(rclcpp::NodeOptions options);
~SynchronousSlamToolbox() {}
void run();
CallbackReturn on_configure(const rclcpp_lifecycle::State &) override;
CallbackReturn on_cleanup(const rclcpp_lifecycle::State &) override;

protected:
void laserCallback(sensor_msgs::msg::LaserScan::ConstSharedPtr scan) override;
Expand Down
3 changes: 3 additions & 0 deletions include/slam_toolbox/toolbox_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <unordered_map>
#include <vector>

#include "rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp"
#include "tf2_ros/buffer.h"
#include "tf2_geometry_msgs/tf2_geometry_msgs.hpp"
#include "tf2/transform_datatypes.h"
Expand Down Expand Up @@ -124,6 +125,8 @@ typedef slam_toolbox::srv::DeserializePoseGraph::Request procType;
typedef std::unordered_map<int, Eigen::Vector3d>::iterator GraphIterator;
typedef std::unordered_map<int, Eigen::Vector3d>::const_iterator ConstGraphIterator;

typedef rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn CallbackReturn;

} // namespace toolbox_types

#endif // SLAM_TOOLBOX__TOOLBOX_TYPES_HPP_
13 changes: 9 additions & 4 deletions include/slam_toolbox/visualization_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,28 @@
#define SLAM_TOOLBOX__VISUALIZATION_UTILS_HPP_

#include <string>
#include <memory>

#include "rclcpp/rclcpp.hpp"
#include "rclcpp_lifecycle/lifecycle_node.hpp"
#include "visualization_msgs/msg/marker.hpp"
#include "visualization_msgs/msg/interactive_marker.hpp"
#include "visualization_msgs/msg/interactive_marker_feedback.hpp"

namespace vis_utils
{

template<class ClockHandler>
inline visualization_msgs::msg::Marker toMarker(
const std::string & frame,
const std::string & ns,
const double & scale,
rclcpp::Node::SharedPtr node)
std::shared_ptr<ClockHandler> handler)
SteveMacenski marked this conversation as resolved.
Show resolved Hide resolved
{
visualization_msgs::msg::Marker marker;

marker.header.frame_id = frame;
marker.header.stamp = node->now();
marker.header.stamp = handler->now();
marker.ns = ns;
marker.type = visualization_msgs::msg::Marker::SPHERE;
marker.pose.position.z = 0.0;
Expand All @@ -55,15 +59,16 @@ inline visualization_msgs::msg::Marker toMarker(
return marker;
}

template<class ClockHandler>
inline visualization_msgs::msg::InteractiveMarker toInteractiveMarker(
visualization_msgs::msg::Marker & marker,
const double & scale,
rclcpp::Node::SharedPtr node)
std::shared_ptr<ClockHandler> handler)
{
// marker basics
visualization_msgs::msg::InteractiveMarker int_marker;
int_marker.header.frame_id = marker.header.frame_id;
int_marker.header.stamp = node->now();
int_marker.header.stamp = handler->now();
int_marker.name = std::to_string(marker.id);
int_marker.pose.orientation.w = 1.;
int_marker.pose.position.x = marker.pose.position.x;
Expand Down
Loading