-
Notifications
You must be signed in to change notification settings - Fork 84
[FEA] Add manual call policy according with FIFO and timestamp. #107
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
base: rolling
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| /********************************************************************* | ||
| * Software License Agreement (BSD License) | ||
| * | ||
| * Copyright (c) 2009, Willow Garage, Inc. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in this correct? you can use 2024 and Open Robotics |
||
| * All rights reserved. | ||
| * | ||
| * Redistribution and use in source and binary forms, with or without | ||
| * modification, are permitted provided that the following conditions | ||
| * are met: | ||
| * | ||
| * * Redistributions of source code must retain the above copyright | ||
| * notice, this list of conditions and the following disclaimer. | ||
| * * Redistributions in binary form must reproduce the above | ||
| * copyright notice, this list of conditions and the following | ||
| * disclaimer in the documentation and/or other materials provided | ||
| * with the distribution. | ||
| * * Neither the name of the Willow Garage nor the names of its | ||
| * contributors may be used to endorse or promote products derived | ||
| * from this software without specific prior written permission. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
| * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
| * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
| * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
| * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
| * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| * POSSIBILITY OF SUCH DAMAGE. | ||
| *********************************************************************/ | ||
|
|
||
| #ifndef MESSAGE_FILTERS__SYNC_POLICIES__MANUAL_CALL_H_ | ||
| #define MESSAGE_FILTERS__SYNC_POLICIES__MANUAL_CALL_H_ | ||
|
|
||
| #include <mutex> | ||
| #include <tuple> | ||
|
|
||
| #include <rclcpp/rclcpp.hpp> | ||
|
|
||
| #include "message_filters/connection.h" | ||
| #include "message_filters/message_traits.h" | ||
| #include "message_filters/null_types.h" | ||
| #include "message_filters/signal9.h" | ||
| #include "message_filters/synchronizer.h" | ||
|
Comment on lines
+43
to
+47
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
|
|
||
| namespace message_filters | ||
| { | ||
| namespace sync_policies | ||
| { | ||
|
|
||
| /** | ||
| * The ManualCall policy stores the last received messages and DO NOT call any callback automatically. | ||
| * It is up to the programmer to call #call when it is time to process the information. This policy class | ||
| * is meant to be used in networks where information is processed periodically. | ||
| */ | ||
| template<typename M0, typename M1, typename M2 = NullType, typename M3 = NullType, typename M4 = NullType, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use variadoc templates like in this PR https://github.com/ros2/message_filters/pull/93/files In the others files as well |
||
| typename M5 = NullType, typename M6 = NullType, typename M7 = NullType, typename M8 = NullType> | ||
| struct ManualCall : public PolicyBase<M0, M1, M2, M3, M4, M5, M6, M7, M8> | ||
| { | ||
| typedef Synchronizer<ManualCall> Sync; | ||
| typedef PolicyBase<M0, M1, M2, M3, M4, M5, M6, M7, M8> Super; | ||
| typedef typename Super::Messages Messages; | ||
| typedef typename Super::Signal Signal; | ||
| typedef typename Super::Events Events; | ||
| typedef typename Super::RealTypeCount RealTypeCount; | ||
| typedef typename Super::M0Event M0Event; | ||
| typedef typename Super::M1Event M1Event; | ||
| typedef typename Super::M2Event M2Event; | ||
| typedef typename Super::M3Event M3Event; | ||
| typedef typename Super::M4Event M4Event; | ||
| typedef typename Super::M5Event M5Event; | ||
| typedef typename Super::M6Event M6Event; | ||
| typedef typename Super::M7Event M7Event; | ||
| typedef typename Super::M8Event M8Event; | ||
|
|
||
| ManualCall() | ||
| : parent_(0) | ||
| { | ||
| } | ||
|
|
||
| ManualCall(const ManualCall& e) | ||
| { | ||
| *this = e; | ||
| } | ||
|
|
||
| ManualCall& operator=(const ManualCall& rhs) | ||
| { | ||
| parent_ = rhs.parent_; | ||
| events_ = rhs.events_; | ||
|
|
||
| return *this; | ||
| } | ||
|
|
||
| void initParent(Sync* parent) | ||
| { | ||
| parent_ = parent; | ||
| } | ||
|
|
||
| template<int i> | ||
| void add(const typename std::tuple_element<i, Events>::type& evt) | ||
| { | ||
| RCUTILS_ASSERT(parent_); | ||
|
|
||
| namespace mt = message_filters::message_traits; | ||
|
|
||
| std::lock_guard<std::mutex> lock(mutex_); | ||
| std::get<i>(events_) = evt; | ||
| } | ||
|
|
||
| void call() const | ||
| { | ||
| parent_->signal(std::get<0>(events_), std::get<1>(events_), std::get<2>(events_), | ||
| std::get<3>(events_), std::get<4>(events_), std::get<5>(events_), | ||
| std::get<6>(events_), std::get<7>(events_), std::get<8>(events_)); | ||
| } | ||
|
|
||
| private: | ||
| Sync* parent_; | ||
|
|
||
| Events events_; | ||
|
|
||
| std::mutex mutex_; | ||
| }; | ||
|
|
||
| } // namespace sync_policies | ||
| } // namespace message_filters | ||
|
|
||
| #endif // MESSAGE_FILTERS__SYNC_POLICIES__MANUAL_CALL_H_ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| /********************************************************************* | ||
| * Software License Agreement (BSD License) | ||
| * | ||
| * Copyright (c) 2009, Willow Garage, Inc. | ||
| * All rights reserved. | ||
| * | ||
| * Redistribution and use in source and binary forms, with or without | ||
| * modification, are permitted provided that the following conditions | ||
| * are met: | ||
| * | ||
| * * Redistributions of source code must retain the above copyright | ||
| * notice, this list of conditions and the following disclaimer. | ||
| * * Redistributions in binary form must reproduce the above | ||
| * copyright notice, this list of conditions and the following | ||
| * disclaimer in the documentation and/or other materials provided | ||
| * with the distribution. | ||
| * * Neither the name of the Willow Garage nor the names of its | ||
| * contributors may be used to endorse or promote products derived | ||
| * from this software without specific prior written permission. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
| * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
| * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
| * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
| * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
| * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| * POSSIBILITY OF SUCH DAMAGE. | ||
| *********************************************************************/ | ||
|
|
||
| #ifndef MESSAGE_FILTERS__SYNC_POLICIES__MANUAL_CALL_STAMPED_H_ | ||
| #define MESSAGE_FILTERS__SYNC_POLICIES__MANUAL_CALL_STAMPED_H_ | ||
|
|
||
| #include <mutex> | ||
| #include <tuple> | ||
|
|
||
| #include <rclcpp/rclcpp.hpp> | ||
|
|
||
| #include "message_filters/connection.h" | ||
| #include "message_filters/message_traits.h" | ||
| #include "message_filters/null_types.h" | ||
| #include "message_filters/signal9.h" | ||
| #include "message_filters/synchronizer.h" | ||
|
|
||
| namespace message_filters | ||
| { | ||
| namespace sync_policies | ||
| { | ||
|
|
||
| /** | ||
| * The ManualCallStamped policy stores the ManualCallStamped received messages (based on their timestamp) and DO NOT call any callback automatically. | ||
| * It is up to the programmer to call #call when it is time to process the information. This policy class | ||
| * is meant to be used in networks where information is processed periodically. | ||
| */ | ||
| template<typename M0, typename M1, typename M2 = NullType, typename M3 = NullType, typename M4 = NullType, | ||
| typename M5 = NullType, typename M6 = NullType, typename M7 = NullType, typename M8 = NullType> | ||
| struct ManualCallStamped : public PolicyBase<M0, M1, M2, M3, M4, M5, M6, M7, M8> | ||
| { | ||
| typedef Synchronizer<ManualCallStamped> Sync; | ||
| typedef PolicyBase<M0, M1, M2, M3, M4, M5, M6, M7, M8> Super; | ||
| typedef typename Super::Messages Messages; | ||
| typedef typename Super::Signal Signal; | ||
| typedef typename Super::Events Events; | ||
| typedef typename Super::RealTypeCount RealTypeCount; | ||
| typedef typename Super::M0Event M0Event; | ||
| typedef typename Super::M1Event M1Event; | ||
| typedef typename Super::M2Event M2Event; | ||
| typedef typename Super::M3Event M3Event; | ||
| typedef typename Super::M4Event M4Event; | ||
| typedef typename Super::M5Event M5Event; | ||
| typedef typename Super::M6Event M6Event; | ||
| typedef typename Super::M7Event M7Event; | ||
| typedef typename Super::M8Event M8Event; | ||
|
|
||
| ManualCallStamped() | ||
| : parent_(0) | ||
| { | ||
| } | ||
|
|
||
| ManualCallStamped(const ManualCallStamped& e) | ||
| { | ||
| *this = e; | ||
| } | ||
|
|
||
| ManualCallStamped& operator=(const ManualCallStamped& rhs) | ||
| { | ||
| parent_ = rhs.parent_; | ||
| events_ = rhs.events_; | ||
|
|
||
| return *this; | ||
| } | ||
|
|
||
| void initParent(Sync* parent) | ||
| { | ||
| parent_ = parent; | ||
| } | ||
|
|
||
| template<int i> | ||
| void add(const typename std::tuple_element<i, Events>::type& evt) | ||
| { | ||
| RCUTILS_ASSERT(parent_); | ||
|
|
||
| namespace mt = message_filters::message_traits; | ||
|
|
||
| std::lock_guard<std::mutex> lock(mutex_); | ||
|
|
||
| typedef typename std::tuple_element<i, Messages>::type MessageType; | ||
| auto& evt_old = std::get<i>(events_); | ||
| if (evt_old.getMessage() != nullptr) | ||
| { | ||
| rclcpp::Time stamp_new = mt::TimeStamp<MessageType>::value(*evt.getMessage()); | ||
| rclcpp::Time stamp_old = mt::TimeStamp<MessageType>::value(*evt_old.getMessage()); | ||
| if (stamp_new > stamp_old) { | ||
| evt_old = evt; | ||
| } | ||
| } | ||
| else { | ||
| evt_old = evt; | ||
| } | ||
| } | ||
|
|
||
| void call() const | ||
| { | ||
| parent_->signal(std::get<0>(events_), std::get<1>(events_), std::get<2>(events_), | ||
| std::get<3>(events_), std::get<4>(events_), std::get<5>(events_), | ||
| std::get<6>(events_), std::get<7>(events_), std::get<8>(events_)); | ||
| } | ||
|
|
||
| private: | ||
| Sync* parent_; | ||
|
|
||
| Events events_; | ||
|
|
||
| std::mutex mutex_; | ||
| }; | ||
|
|
||
| } // namespace sync_policies | ||
| } // namespace message_filters | ||
|
|
||
| #endif // MESSAGE_FILTERS__SYNC_POLICIES__MANUAL_CALL_STAMPED_H_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use
hppextension instead ofh.