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 'fix/elev_mapping_postprocessor_multiple_functors' into …
…'master' [elevation_mapping] Multiple functors per postprocessing pool, each owning a filter chain GitOrigin-RevId: c972b26f7900420bb71918f55bf74113ea4ee3ab
- Loading branch information
1 parent
5c84a55
commit e0864b5
Showing
7 changed files
with
151 additions
and
52 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
85 changes: 85 additions & 0 deletions
85
elevation_mapping/include/elevation_mapping/postprocessing/PostprocessingWorker.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,85 @@ | ||
/* | ||
* PostprocessingWorker.hpp | ||
* | ||
* Created on: Dec. 21, 2020 | ||
* Author: Yoshua Nava | ||
* Institute: ANYbotics | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <boost/asio.hpp> | ||
#include <boost/thread.hpp> | ||
#include <thread> | ||
|
||
#include <grid_map_core/GridMap.hpp> | ||
|
||
#include "elevation_mapping/postprocessing/PostprocessingPipelineFunctor.hpp" | ||
|
||
namespace elevation_mapping { | ||
|
||
/** | ||
* @brief A wrapper around the postprocessing pipelines functor. | ||
* | ||
* @remark It stores together the functor, grid map data buffer, and thread tooling. | ||
* It is assumed that the members of this function are guarded by an external mutex, | ||
* handled by the owner of this class. | ||
*/ | ||
class PostprocessingWorker { | ||
public: | ||
using GridMap = grid_map::GridMap; | ||
|
||
explicit PostprocessingWorker(ros::NodeHandle nodeHandle); | ||
|
||
/*! @name Accessors */ | ||
///@{ | ||
boost::asio::io_service& ioService() { return ioService_; } | ||
std::thread& thread() { return thread_; } | ||
const GridMap& dataBuffer() { return dataBuffer_; } | ||
void setDataBuffer(GridMap data) { dataBuffer_ = std::move(data); } | ||
///@} | ||
|
||
/*! @name Methods */ | ||
///@{ | ||
/** | ||
* @brief Process the data in the buffer. | ||
* | ||
* @return GridMap Processed grid map. | ||
*/ | ||
GridMap processBuffer(); | ||
|
||
/** | ||
* @brief Publish a given grid map. | ||
* | ||
* @param gridMap The grid map to publish. | ||
*/ | ||
void publish(const GridMap& gridMap) const; | ||
|
||
/** | ||
* @brief Checks whether the worker publisher has any active subscribers. | ||
* | ||
* @return true If there are subscribers to the worker publisher, false otherwise. | ||
*/ | ||
bool hasSubscribers() const; | ||
///@} | ||
|
||
protected: | ||
//! The functor to execute on a given GridMap. | ||
PostprocessingPipelineFunctor functor_; | ||
|
||
//! BOOST Service Worker Infrastructure. | ||
//! The io_service objects provide the interface to post an asynchronous task. | ||
//! The work object ensures that the io_service run() method keeps spinning and accepts tasks. | ||
//! A thread executes the io_service::run() method, which does io_service::work, ie accepting and executing new tasks. | ||
//! IO service for asynchronous operation. | ||
boost::asio::io_service ioService_; | ||
//! IO service work notifier | ||
boost::asio::io_service::work work_; | ||
//! The thread on which this worker runs. | ||
std::thread thread_; | ||
|
||
//! Data container for the worker. | ||
GridMap dataBuffer_; | ||
}; | ||
|
||
} // namespace elevation_mapping |
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
28 changes: 28 additions & 0 deletions
28
elevation_mapping/src/postprocessing/PostprocessingWorker.cpp
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,28 @@ | ||
/* | ||
* PostprocessingWorker.cpp | ||
* | ||
* Created on: Dec. 21, 2020 | ||
* Author: Yoshua Nava | ||
* Institute: ANYbotics | ||
*/ | ||
|
||
#include "elevation_mapping/postprocessing/PostprocessingWorker.hpp" | ||
|
||
namespace elevation_mapping { | ||
|
||
PostprocessingWorker::PostprocessingWorker(ros::NodeHandle nodeHandle) | ||
: functor_(nodeHandle), work_(ioService_), thread_(boost::bind(&boost::asio::io_service::run, &ioService_)) {} | ||
|
||
PostprocessingWorker::GridMap PostprocessingWorker::processBuffer() { | ||
return functor_(dataBuffer_); | ||
} | ||
|
||
void PostprocessingWorker::publish(const GridMap& gridMap) const { | ||
functor_.publish(gridMap); | ||
} | ||
|
||
bool PostprocessingWorker::hasSubscribers() const { | ||
return functor_.hasSubscribers(); | ||
} | ||
|
||
} // namespace elevation_mapping |
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