diff --git a/include/core/problem/problem.h b/include/core/problem/problem.h index 362235b95fed754822e35e8e7082258d5bc194a6..877eacff4195f37cc0a765a294a251c1bfa7e047 100644 --- a/include/core/problem/problem.h +++ b/include/core/problem/problem.h @@ -21,6 +21,7 @@ struct ProcessorParamsBase; #include "core/utils/params_server.hpp" #include "core/sensor/sensor_factory.h" #include "core/processor/processor_factory.h" +#include "core/processor/is_motion.h" // std includes #include <mutex> @@ -45,7 +46,8 @@ class Problem : public std::enable_shared_from_this<Problem> HardwareBasePtr hardware_ptr_; TrajectoryBasePtr trajectory_ptr_; MapBasePtr map_ptr_; - ProcessorMotionPtr processor_motion_ptr_; + IsMotionPtr processor_motion_ptr_; +// IsMotionPtr is_motion_ptr_; std::map<std::pair<StateBlockPtr, StateBlockPtr>, Eigen::MatrixXd> covariances_; SizeEigen state_size_, state_cov_size_, dim_; std::map<FactorBasePtr, Notification> factor_notification_map_; @@ -147,12 +149,12 @@ class Problem : public std::enable_shared_from_this<Problem> * * Set the processor motion. */ - void setProcessorMotion(ProcessorMotionPtr _processor_motion_ptr); - ProcessorMotionPtr setProcessorMotion(const std::string& _unique_processor_name); + void setProcessorMotion(IsMotionPtr _processor_motion_ptr); + IsMotionPtr setProcessorMotion(const std::string& _unique_processor_name); void clearProcessorMotion(); public: - ProcessorMotionPtr& getProcessorMotion(); + IsMotionPtr& getProcessorMotion(); // Trajectory branch ---------------------------------- TrajectoryBasePtr getTrajectory() const; @@ -360,7 +362,7 @@ inline bool Problem::priorIsSet() const return prior_is_set_; } -inline ProcessorMotionPtr& Problem::getProcessorMotion() +inline IsMotionPtr& Problem::getProcessorMotion() { return processor_motion_ptr_; } diff --git a/include/core/processor/is_motion.h b/include/core/processor/is_motion.h index 42139f0ebb1c5fbcfd0293c99c355d5119b8cbaa..410b6dd9e23ea202df035e4d9ce4f5a1e5ac0acd 100644 --- a/include/core/processor/is_motion.h +++ b/include/core/processor/is_motion.h @@ -15,10 +15,12 @@ namespace wolf class TimeStamp; +WOLF_PTR_TYPEDEFS(IsMotion); + class IsMotion { public: - IsMotion(); + virtual ~IsMotion(); // Queries to the processor: @@ -57,10 +59,6 @@ class IsMotion namespace wolf{ -inline IsMotion::IsMotion() -{ -} - inline IsMotion::~IsMotion() { } diff --git a/include/core/processor/processor_motion.h b/include/core/processor/processor_motion.h index f3f0eff35cf4e91925f4a705dea66a60b4a6efbe..6e56fd99ba45bd203f88729b4f8d9b043b2b1b7c 100644 --- a/include/core/processor/processor_motion.h +++ b/include/core/processor/processor_motion.h @@ -11,6 +11,7 @@ // Wolf #include "core/capture/capture_motion.h" #include "core/processor/processor_base.h" +#include "core/processor/is_motion.h" #include "core/common/time_stamp.h" #include "core/utils/params_server.hpp" @@ -164,27 +165,27 @@ class ProcessorMotion : public ProcessorBase, public IsMotion /** \brief Fill a reference to the state integrated so far * \param _x the returned state vector */ - void getCurrentState(Eigen::VectorXd& _x) const; - void getCurrentTimeStamp(TimeStamp& _ts) const { _ts = getBuffer().get().back().ts_; } + virtual void getCurrentState(Eigen::VectorXd& _x) const override; + virtual void getCurrentTimeStamp(TimeStamp& _ts) const override { _ts = getBuffer().get().back().ts_; } /** \brief Get the state integrated so far * \return the state vector */ - Eigen::VectorXd getCurrentState() const; - TimeStamp getCurrentTimeStamp() const; + virtual Eigen::VectorXd getCurrentState() const override; + virtual TimeStamp getCurrentTimeStamp() const override; /** \brief Fill the state corresponding to the provided time-stamp * \param _ts the time stamp * \param _x the returned state * \return if state in the provided time-stamp could be resolved */ - bool getState(const TimeStamp& _ts, Eigen::VectorXd& _x) const; + virtual bool getState(const TimeStamp& _ts, Eigen::VectorXd& _x) const override; /** \brief Get the state corresponding to the provided time-stamp * \param _ts the time stamp * \return the state vector */ - Eigen::VectorXd getState(const TimeStamp& _ts) const; + virtual Eigen::VectorXd getState(const TimeStamp& _ts) const override; /** \brief Gets the delta preintegrated covariance from all integrations so far * \return the delta preintegrated covariance matrix diff --git a/src/problem/problem.cpp b/src/problem/problem.cpp index 7abc062844627db0f38d356e2ccd64b0477aa295..1afab86dfb1267f1007e41de62e060f4e6f705a7 100644 --- a/src/problem/problem.cpp +++ b/src/problem/problem.cpp @@ -291,7 +291,7 @@ SensorBasePtr Problem::getSensor(const std::string& _sensor_name) const return (*sen_it); } -ProcessorMotionPtr Problem::setProcessorMotion(const std::string& _processor_name) +IsMotionPtr Problem::setProcessorMotion(const std::string& _processor_name) { for (auto sen : getHardware()->getSensorList()) // loop all sensors { @@ -322,7 +322,7 @@ ProcessorMotionPtr Problem::setProcessorMotion(const std::string& _processor_nam return nullptr; } -void Problem::setProcessorMotion(ProcessorMotionPtr _processor_motion_ptr) +void Problem::setProcessorMotion(IsMotionPtr _processor_motion_ptr) { processor_motion_ptr_ = _processor_motion_ptr; } @@ -495,16 +495,17 @@ bool Problem::permitAuxFrame(ProcessorBasePtr _processor_ptr) const void Problem::auxFrameCallback(FrameBasePtr _frame_ptr, ProcessorBasePtr _processor_ptr, const double& _time_tolerance) { - if (_processor_ptr) - { - WOLF_DEBUG((_processor_ptr->isMotion() ? "PM " : "PT "), _processor_ptr->getName(), ": AuxF", _frame_ptr->id(), " Callback emitted with ts = ", _frame_ptr->getTimeStamp()); - } - else - { - WOLF_DEBUG("External callback: AuxF", _frame_ptr->id(), " Callback emitted with ts = ", _frame_ptr->getTimeStamp()); - } - - processor_motion_ptr_->keyFrameCallback(_frame_ptr, _time_tolerance); + // TODO +// if (_processor_ptr) +// { +// WOLF_DEBUG((_processor_ptr->isMotion() ? "PM " : "PT "), _processor_ptr->getName(), ": AuxF", _frame_ptr->id(), " Callback emitted with ts = ", _frame_ptr->getTimeStamp()); +// } +// else +// { +// WOLF_DEBUG("External callback: AuxF", _frame_ptr->id(), " Callback emitted with ts = ", _frame_ptr->getTimeStamp()); +// } +// +// processor_motion_ptr_->keyFrameCallback(_frame_ptr, _time_tolerance); } StateBlockPtr Problem::notifyStateBlock(StateBlockPtr _state_ptr, Notification _noti) diff --git a/src/processor/processor_base.cpp b/src/processor/processor_base.cpp index 39b77e59f6980f1a2047db5527a017358572159b..17bc8fffa32576e34184279a5f8d0d70dd8747d3 100644 --- a/src/processor/processor_base.cpp +++ b/src/processor/processor_base.cpp @@ -71,7 +71,7 @@ void ProcessorBase::remove() if (isMotion()) { ProblemPtr P = getProblem(); - if(P && P->getProcessorMotion()->id() == this->id()) + if(P && this->isMotion() && P->getProcessorMotion() == std::dynamic_pointer_cast<IsMotion>(shared_from_this())) P->clearProcessorMotion(); } diff --git a/src/processor/processor_motion.cpp b/src/processor/processor_motion.cpp index c667b7193bc3b566782351371c7d4f314799a93b..73e63e5efbe515b6db54f457cd6f2a541e9e0907 100644 --- a/src/processor/processor_motion.cpp +++ b/src/processor/processor_motion.cpp @@ -1,4 +1,8 @@ + + #include "core/processor/processor_motion.h" + + namespace wolf { diff --git a/test/gtest_problem.cpp b/test/gtest_problem.cpp index d39ce95f7259b1822c4af0b9d7cca5eb0b9903a6..da832729052f2775eb55f132dd6fb64dd0965a1e 100644 --- a/test/gtest_problem.cpp +++ b/test/gtest_problem.cpp @@ -122,7 +122,7 @@ TEST(Problem, Installers) ASSERT_TRUE(P->getProcessorMotion()); // check motion processor is correct - ASSERT_EQ(P->getProcessorMotion(), pm); + ASSERT_EQ(std::dynamic_pointer_cast<ProcessorMotion>(P->getProcessorMotion()), pm); } TEST(Problem, SetOrigin_PO_2D)