forked from ANYbotics/elevation_mapping
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/multiple_inputs_in_elevation_mapping' into 'mas…
…ter' [elevation_mapping] Support multiple inputs GitOrigin-RevId: 7a4b30f9874825bdcb7078ce887e32eb097460eb
- Loading branch information
1 parent
c162ec4
commit f8455a2
Showing
18 changed files
with
763 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
elevation_mapping/include/elevation_mapping/input_sources/Input.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Input.hpp | ||
* | ||
* Created on: Oct 06, 2020 | ||
* Author: Magnus Gärtner | ||
* Institute: ETH Zurich, ANYbotics | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <XmlRpc.h> | ||
#include <ros/ros.h> | ||
#include <string> | ||
|
||
namespace elevation_mapping { | ||
class ElevationMapping; // Forward declare to avoid cyclic import dependency. | ||
|
||
/** | ||
* @brief An Input feeds data to ElevationMapping callbacks. E.g it holds a subscription to an sensor source and registered an appropriate | ||
* ElevationMapping callback. | ||
*/ | ||
class Input { | ||
public: | ||
template <typename MsgT> | ||
using CallbackT = void (ElevationMapping::*)(const boost::shared_ptr<const MsgT>&, bool); | ||
|
||
/** | ||
* @brief Constructor. | ||
* @param nh Reference to the nodeHandle of the manager. Used to subscribe | ||
* to inputs. | ||
*/ | ||
explicit Input(ros::NodeHandle& nh); | ||
|
||
/** | ||
* @brief Configure the input source. | ||
* @param parameters The configuration parameters. | ||
* @return True if configuring was successful. | ||
*/ | ||
bool configure(const XmlRpc::XmlRpcValue& parameters); | ||
|
||
/** | ||
* @brief Registers the corresponding callback in the elevationMap. | ||
* @param map The map we want to link this input source to. | ||
* @param callback The callback to use for incoming data. | ||
* @tparam MsgT The message types of the callback. | ||
*/ | ||
template <typename MsgT> | ||
void registerCallback(ElevationMapping& map, CallbackT<MsgT> callback); | ||
|
||
/** | ||
* @return The topic (as absolute path, with renames) that this input | ||
* subscribes to. | ||
*/ | ||
std::string getSubscribedTopic() const; | ||
|
||
/** | ||
* @return The type of this input source. | ||
*/ | ||
std::string getType() { return type_; } | ||
|
||
private: | ||
// Parameters. | ||
std::string name_; | ||
std::string type_; | ||
uint32_t queueSize_; | ||
std::string topic_; | ||
bool publishOnUpdate_; | ||
|
||
// ROS connection. | ||
ros::Subscriber subscriber_; | ||
ros::NodeHandle& nodeHandle_; | ||
}; | ||
|
||
template <typename MsgT> | ||
void Input::registerCallback(ElevationMapping& map, CallbackT<MsgT> callback) { | ||
subscriber_ = | ||
nodeHandle_.subscribe<MsgT>(topic_, queueSize_, std::bind(callback, std::ref(map), std::placeholders::_1, publishOnUpdate_)); | ||
ROS_INFO("Subscribing to %s: %s, queue_size: %i.", type_.c_str(), topic_.c_str(), queueSize_); | ||
} | ||
|
||
} // namespace elevation_mapping |
Oops, something went wrong.