diff --git a/hello_wolf/processor_range_bearing.h b/hello_wolf/processor_range_bearing.h index 527efd1f60afc7f1f688b795dbe0bf7fd4546628..65e87f56e76718036e44d73031329e98c361afe4 100644 --- a/hello_wolf/processor_range_bearing.h +++ b/hello_wolf/processor_range_bearing.h @@ -31,7 +31,7 @@ struct ProcessorParamsRangeBearing : public ProcessorParamsBase { // } - std::string print() + std::string print() const { return "\n" + ProcessorParamsBase::print(); } diff --git a/hello_wolf/sensor_range_bearing.h b/hello_wolf/sensor_range_bearing.h index b7788c27ffb4a06cdbc440ec091553d5b216440a..2e9bcf214d0ea586a6cf3466846ed41ef50f3096 100644 --- a/hello_wolf/sensor_range_bearing.h +++ b/hello_wolf/sensor_range_bearing.h @@ -29,7 +29,7 @@ struct IntrinsicsRangeBearing : public IntrinsicsBase noise_range_metres_std = _server.getParam<Scalar>(_unique_name + "/noise_range_metres_std"); noise_bearing_degrees_std = _server.getParam<Scalar>(_unique_name + "/noise_bearing_degrees_std"); } - std::string print() + std::string print() const { return "" + IntrinsicsBase::print() + "\n" + "noise_range_metres_std: " + std::to_string(noise_range_metres_std) + "\n" diff --git a/include/core/common/params_base.h b/include/core/common/params_base.h index 767ece49d1daa5e55496ba22d71f8cb34c8b8b7d..5295bc0ac17f941503a8f28e462962290a9ee82b 100644 --- a/include/core/common/params_base.h +++ b/include/core/common/params_base.h @@ -13,7 +13,7 @@ namespace wolf { } virtual ~ParamsBase() = default; - std::string print() + std::string print() const { return ""; } diff --git a/include/core/factor/factor_diff_drive.h b/include/core/factor/factor_diff_drive.h index e9501f3b71bdb47c23d5cbd9d5f9bd4f243bfb5c..274c226ed779ced623f5ae8c0eb76c0e5bc4d291 100644 --- a/include/core/factor/factor_diff_drive.h +++ b/include/core/factor/factor_diff_drive.h @@ -86,14 +86,6 @@ class FactorDiffDrive : public FactorAutodiff<FactorDiffDrive, VectorXs residual(); -// /** -// * \brief Returns the jacobians computation method -// **/ -// virtual JacobianMethod getJacobianMethod() const -// { -// return JAC_AUTO; -// } - protected: Eigen::Vector3s calib_preint_; diff --git a/include/core/processor/processor_base.h b/include/core/processor/processor_base.h index 1eee919dea9af66f6bcaf2257c0e7ae58d5ba81b..d57846275c3550cfc208cfb849abdf676ce9d9fc 100644 --- a/include/core/processor/processor_base.h +++ b/include/core/processor/processor_base.h @@ -180,7 +180,7 @@ class BufferPackKeyFrame : public Buffer<PackKeyFramePtr> /**\brief Print buffer information * */ - void print(); + void print() const; /**\brief Alias funct * @@ -224,7 +224,7 @@ struct ProcessorParamsBase : public ParamsBase bool voting_aux_active = false; ///< Whether this processor is allowed to vote for an Auxiliary Frame or not - std::string print() + std::string print() const { return ParamsBase::print() + "\n" + "voting_active: " + std::to_string(voting_active) + "\n" diff --git a/include/core/processor/processor_diff_drive.h b/include/core/processor/processor_diff_drive.h index d4aa5a792ef4d571a057824099d4430696088c86..1192230afa33cbb5814f6fc599e1df17c8290b9b 100644 --- a/include/core/processor/processor_diff_drive.h +++ b/include/core/processor/processor_diff_drive.h @@ -22,7 +22,7 @@ struct ProcessorParamsDiffDrive : public ProcessorParamsOdom2D ProcessorParamsOdom2D(_unique_name, _server) { } - std::string print() + std::string print() const { return "\n" + ProcessorParamsOdom2D::print(); } diff --git a/include/core/processor/processor_motion.h b/include/core/processor/processor_motion.h index 1cd51d36ee2526ee0072dcbbeb31081ab4c69793..41fc77be5711986fadee3e4d16996826d2938373 100644 --- a/include/core/processor/processor_motion.h +++ b/include/core/processor/processor_motion.h @@ -40,7 +40,7 @@ struct ProcessorParamsMotion : public ProcessorParamsBase angle_turned = _server.getParam<Scalar>(_unique_name + "/keyframe_vote/angle_turned"); unmeasured_perturbation_std = _server.getParam<Scalar>(_unique_name + "/unmeasured_perturbation_std"); } - std::string print() + std::string print() const { return "\n" + ProcessorParamsBase::print() + "\n" + "max_time_span: " + std::to_string(max_time_span) + "\n" diff --git a/include/core/processor/processor_odom_2D.h b/include/core/processor/processor_odom_2D.h index 8fca11b3e5913e683a9cfde766ad1e072ef5c32e..2957ec7de8cd0647a45fc1f72c15629b9f42a089 100644 --- a/include/core/processor/processor_odom_2D.h +++ b/include/core/processor/processor_odom_2D.h @@ -30,7 +30,7 @@ struct ProcessorParamsOdom2D : public ProcessorParamsMotion cov_det = _server.getParam<Scalar>(_unique_name + "/keyframe_vote/cov_det"); } - std::string print() + std::string print() const { return "\n" + ProcessorParamsMotion::print() + "\n" + "cov_det: " + std::to_string(cov_det) + "\n"; diff --git a/include/core/processor/processor_odom_3D.h b/include/core/processor/processor_odom_3D.h index bd1e3cf013135ac90bfcb9dec749b9b64a63ce07..1512b996e89a5e5d5c7c6bc294d1dfa495219d41 100644 --- a/include/core/processor/processor_odom_3D.h +++ b/include/core/processor/processor_odom_3D.h @@ -27,7 +27,7 @@ struct ProcessorParamsOdom3D : public ProcessorParamsMotion { // } - std::string print() + std::string print() const { return "\n" + ProcessorParamsMotion::print(); } diff --git a/include/core/processor/processor_tracker.h b/include/core/processor/processor_tracker.h index dc59acee329e3dbe09ba03e25cb1c385347bf8ff..a1e64518606e559ab6c80c4f8b669850e2f46b7f 100644 --- a/include/core/processor/processor_tracker.h +++ b/include/core/processor/processor_tracker.h @@ -27,7 +27,7 @@ struct ProcessorParamsTracker : public ProcessorParamsBase min_features_for_keyframe = _server.getParam<unsigned int>(_unique_name + "/min_features_for_keyframe"); max_new_features = _server.getParam<int>(_unique_name + "/max_new_features"); } - std::string print() + std::string print() const { return ProcessorParamsBase::print() + "\n" + "min_features_for_keyframe: " + std::to_string(min_features_for_keyframe) + "\n" @@ -230,7 +230,7 @@ class ProcessorTracker : public ProcessorBase FeatureBasePtrList& getNewFeaturesListLast(); - std::string print(){ + std::string print() const { return this->params_tracker_->print(); } diff --git a/include/core/sensor/sensor_base.h b/include/core/sensor/sensor_base.h index e9945a9b4ae269b0829651ebf85ed331f1dcaec1..67e0c032d4d21ac4a5d3c5af17383b3b09610871 100644 --- a/include/core/sensor/sensor_base.h +++ b/include/core/sensor/sensor_base.h @@ -74,7 +74,7 @@ struct IntrinsicsBase: public ParamsBase { virtual ~IntrinsicsBase() = default; using ParamsBase::ParamsBase; - std::string print() + std::string print() const { return ""; } diff --git a/include/core/sensor/sensor_diff_drive.h b/include/core/sensor/sensor_diff_drive.h index a36356ed87a3c793a4a8464e4b2a43c16e65043c..9367347e07da6a0f9aaa0708c5db3b939a0deba3 100644 --- a/include/core/sensor/sensor_diff_drive.h +++ b/include/core/sensor/sensor_diff_drive.h @@ -22,8 +22,6 @@ struct IntrinsicsDiffDrive : public IntrinsicsBase Scalar wheel_separation; Scalar ticks_per_wheel_revolution; - Scalar radians_per_tick; ///< Not user-definable -- DO NOT PRETEND TO USE YAML TO SET THIS PARAM. - IntrinsicsDiffDrive() = default; IntrinsicsDiffDrive(std::string _unique_name, const wolf::ParamsServer & _server) : @@ -33,16 +31,14 @@ struct IntrinsicsDiffDrive : public IntrinsicsBase radius_right = _server.getParam<Scalar>(_unique_name + "/radius_right"); wheel_separation = _server.getParam<Scalar>(_unique_name + "/wheel_separation"); ticks_per_wheel_revolution = _server.getParam<Scalar>(_unique_name + "/ticks_per_wheel_revolution"); - radians_per_tick = 2.0 * M_PI / ticks_per_wheel_revolution; } - std::string print() + std::string print() const { return "\n" + IntrinsicsBase::print() + "\n" + "radius_left: " + std::to_string(radius_left) + "\n" + "radius_right: " + std::to_string(radius_right) + "\n" + "wheel_separation: " + std::to_string(wheel_separation) + "\n" - + "ticks_per_wheel_revolution: " + std::to_string(ticks_per_wheel_revolution)+ "\n" - + "radians_per_tick: " + std::to_string(radians_per_tick) + "\n"; + + "ticks_per_wheel_revolution: " + std::to_string(ticks_per_wheel_revolution)+ "\n"; } }; @@ -58,8 +54,15 @@ class SensorDiffDrive : public SensorBase virtual ~SensorDiffDrive(); IntrinsicsDiffDriveConstPtr getParams() const {return params_diff_drive_;} + Scalar getRadiansPerTick() const + { + return radians_per_tick; + } + protected: IntrinsicsDiffDrivePtr params_diff_drive_; + Scalar radians_per_tick; ///< Not user-definable -- DO NOT PRETEND TO USE YAML TO SET THIS PARAM. + }; } /* namespace wolf */ diff --git a/include/core/sensor/sensor_odom_2D.h b/include/core/sensor/sensor_odom_2D.h index 83b776add9b4bba4c1994f047d06dedd3e8e5c1f..463a9c3d95053f3753c3b59b2769cfb669b9a0e7 100644 --- a/include/core/sensor/sensor_odom_2D.h +++ b/include/core/sensor/sensor_odom_2D.h @@ -25,7 +25,7 @@ struct IntrinsicsOdom2D : public IntrinsicsBase k_disp_to_disp = _server.getParam<Scalar>(_unique_name + "/k_disp_to_disp"); k_rot_to_rot = _server.getParam<Scalar>(_unique_name + "/k_rot_to_rot"); } - std::string print() + std::string print() const { return "\n" + IntrinsicsBase::print() + "\n" + "k_disp_to_disp: " + std::to_string(k_disp_to_disp) + "\n" diff --git a/include/core/sensor/sensor_odom_3D.h b/include/core/sensor/sensor_odom_3D.h index 1a727d613d8564c02d02f16abcf63410c96289b2..3e141b93916455d280990d2aed3d27d54d156835 100644 --- a/include/core/sensor/sensor_odom_3D.h +++ b/include/core/sensor/sensor_odom_3D.h @@ -36,7 +36,7 @@ struct IntrinsicsOdom3D : public IntrinsicsBase min_disp_var = _server.getParam<Scalar>(_unique_name + "/min_disp_var"); min_rot_var = _server.getParam<Scalar>(_unique_name + "/min_rot_var"); } - std::string print() + std::string print() const { return "\n" + IntrinsicsBase::print() + "\n" + "k_disp_to_disp: " + std::to_string(k_disp_to_disp) + "\n" diff --git a/src/processor/processor_base.cpp b/src/processor/processor_base.cpp index 1e8b098df1dd882ff16756c3f3345080637a43e0..c89ece40f29e39d36d167cf79c4bf852348f69b6 100644 --- a/src/processor/processor_base.cpp +++ b/src/processor/processor_base.cpp @@ -181,7 +181,7 @@ PackKeyFramePtr BufferPackKeyFrame::selectFirstPackBefore(const CaptureBasePtr _ return selectFirstPackBefore(_capture->getTimeStamp(), _time_tolerance); } -void BufferPackKeyFrame::print(void) +void BufferPackKeyFrame::print(void) const { std::cout << "[ "; for (auto iter : container_) diff --git a/src/processor/processor_diff_drive.cpp b/src/processor/processor_diff_drive.cpp index 8c31ff7a74ee17cdb7674567b03340058304dd01..d0afacb45a6fb235e6d01e7c893ffc612449e6c0 100644 --- a/src/processor/processor_diff_drive.cpp +++ b/src/processor/processor_diff_drive.cpp @@ -38,7 +38,7 @@ void ProcessorDiffDrive::configure(SensorBasePtr _sensor) SensorDiffDriveConstPtr sensor_diff_drive = std::static_pointer_cast<SensorDiffDrive>(_sensor); - radians_per_tick_ = sensor_diff_drive->getParams()->radians_per_tick; + radians_per_tick_ = sensor_diff_drive->getRadiansPerTick(); } diff --git a/src/sensor/sensor_diff_drive.cpp b/src/sensor/sensor_diff_drive.cpp index d8c29515a1113fa65c88fb6ec83ceb29546030f8..369e32919a84d20ab3e7396b67bfcb5e68b514c5 100644 --- a/src/sensor/sensor_diff_drive.cpp +++ b/src/sensor/sensor_diff_drive.cpp @@ -20,7 +20,7 @@ SensorDiffDrive::SensorDiffDrive(const Eigen::VectorXs& _extrinsics, 2), params_diff_drive_(_intrinsics) { - params_diff_drive_->radians_per_tick = 2.0*M_PI / params_diff_drive_->ticks_per_wheel_revolution; + radians_per_tick = 2.0*M_PI / params_diff_drive_->ticks_per_wheel_revolution; getIntrinsic()->setState(Eigen::Vector3s(_intrinsics->radius_left,_intrinsics->radius_right,_intrinsics->wheel_separation)); getIntrinsic()->unfix(); } diff --git a/test/gtest_processor_diff_drive.cpp b/test/gtest_processor_diff_drive.cpp index 46f3a9e3299a8074747a4d07d6e9add8fc49e249..3c15a924d782d331db4b6ef268a2ea123b27db7d 100644 --- a/test/gtest_processor_diff_drive.cpp +++ b/test/gtest_processor_diff_drive.cpp @@ -224,7 +224,6 @@ TEST_F(ProcessorDiffDriveTest, computeCurrentDelta) TEST_F(ProcessorDiffDriveTest, deltaPlusDelta) { - Vector2s data; Matrix2s data_cov; data_cov . setIdentity(); Vector3s calib(1,1,1); @@ -265,7 +264,6 @@ TEST_F(ProcessorDiffDriveTest, deltaPlusDelta) TEST_F(ProcessorDiffDriveTest, statePlusDelta) { - Vector2s data; Matrix2s data_cov; data_cov . setIdentity(); Vector3s calib(1,1,1); @@ -306,7 +304,6 @@ TEST_F(ProcessorDiffDriveTest, statePlusDelta) TEST_F(ProcessorDiffDriveTest, process) { - Vector2s data; Matrix2s data_cov; data_cov . setIdentity(); TimeStamp t = 0.0; @@ -336,6 +333,61 @@ TEST_F(ProcessorDiffDriveTest, process) problem->print(4,1,1,1); } +TEST_F(ProcessorDiffDriveTest, linear) +{ + Vector2s data; + Matrix2s data_cov; data_cov . setIdentity(); + TimeStamp t = 0.0; + Vector3s x(0,0,0); + Matrix3s P; P.setIdentity(); + + auto F0 = problem->setPrior(x, P, t, 0.1); + + // Straight one turn of the wheels, in one go + data(0) = 100.0 ; // one turn of the wheels + data(1) = 100.0 ; + + auto C = std::make_shared<CaptureDiffDrive>(t, sensor, data, data_cov, F0); + + C->process(); + WOLF_TRACE("t = ", t, "; x = ", processor->getCurrentState().transpose()); + + // radius is 1.0m, 100 ticks per revolution, so advanced distance is + Scalar distance = 2 * M_PI * 1.0; + + ASSERT_MATRIX_APPROX(processor->getCurrentState(), Vector3s(distance,0,0), 1e-6) +} + +TEST_F(ProcessorDiffDriveTest, angular) +{ + Vector2s data; + Matrix2s data_cov; data_cov . setIdentity(); + TimeStamp t = 0.0; + Vector3s x(0,0,0); + Matrix3s P; P.setIdentity(); + + auto F0 = problem->setPrior(x, P, t, 0.1); + + // Straight one turn of the wheels, in one go + data(0) = -20.0 ; // one fifth of a turn of the left wheel, in reverse + data(1) = 20.0 ; // one fifth of a turn of the right wheel, forward --> we'll turn left --> positive angle + + auto C = std::make_shared<CaptureDiffDrive>(t, sensor, data, data_cov, F0); + + C->process(); + WOLF_TRACE("t = ", t, "; x = ", processor->getCurrentState().transpose()); + + // this is a turn in place, so distance = 0; + Scalar distance = 0.0; + + // radius is 1.0m, 100 ticks per revolution, and wheel separation is 1m, so turn angle is + Scalar angle = pi2pi(2 * M_PI * 1.0 / 0.5 / 5); + + ASSERT_MATRIX_APPROX(processor->getCurrentState(), Vector3s(distance,0,angle), 1e-6) +} + + + int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); diff --git a/test/gtest_sensor_diff_drive.cpp b/test/gtest_sensor_diff_drive.cpp index 29ccea249acb27a6b0ac3bbbfb88b7bc0516d05c..363847f6c30ea0bcb36fce264f7aabcfe36fc298 100644 --- a/test/gtest_sensor_diff_drive.cpp +++ b/test/gtest_sensor_diff_drive.cpp @@ -30,7 +30,6 @@ TEST(DiffDrive, constructor) TEST(DiffDrive, getParams) { auto intr = std::make_shared<IntrinsicsDiffDrive>(); - intr->radians_per_tick = 1; intr->radius_left = 2; intr->radius_right = 3; intr->ticks_per_wheel_revolution = 4; @@ -42,7 +41,7 @@ TEST(DiffDrive, getParams) ASSERT_NE(sen->getParams(), nullptr); - ASSERT_EQ(sen->getParams()->radians_per_tick, 2.0*M_PI/intr->ticks_per_wheel_revolution); // this is dependent on 'ticks_per_wheel_revolution' + ASSERT_EQ(sen->getRadiansPerTick(), 2.0*M_PI/intr->ticks_per_wheel_revolution); // this is dependent on 'ticks_per_wheel_revolution' ASSERT_EQ(sen->getParams()->radius_left, 2); ASSERT_EQ(sen->getParams()->radius_right, 3); ASSERT_EQ(sen->getParams()->ticks_per_wheel_revolution, 4); @@ -52,7 +51,6 @@ TEST(DiffDrive, getParams) TEST(DiffDrive, create) { auto intr = std::make_shared<IntrinsicsDiffDrive>(); - intr->radians_per_tick = 1; intr->radius_left = 2; intr->radius_right = 3; intr->ticks_per_wheel_revolution = 4; @@ -66,7 +64,7 @@ TEST(DiffDrive, create) ASSERT_NE(sen->getParams(), nullptr); - ASSERT_EQ(sen->getParams()->radians_per_tick, 2.0*M_PI/intr->ticks_per_wheel_revolution); // this is dependent on 'ticks_per_wheel_revolution' + ASSERT_EQ(sen->getRadiansPerTick(), 2.0*M_PI/intr->ticks_per_wheel_revolution); // this is dependent on 'ticks_per_wheel_revolution' ASSERT_EQ(sen->getParams()->radius_left, 2); ASSERT_EQ(sen->getParams()->radius_right, 3); ASSERT_EQ(sen->getParams()->ticks_per_wheel_revolution, 4);