From 170cf69d95808533dc2800decdcc58da996c6342 Mon Sep 17 00:00:00 2001 From: Christopher Dyken Date: Tue, 13 Feb 2018 14:50:47 +0100 Subject: [PATCH 1/2] Fixed compilation errors in unit tests. --- AirLibUnitTests/PixhawkTest.hpp | 4 +--- AirLibUnitTests/RosFlightTest.hpp | 3 +-- AirLibUnitTests/SimpleFlightTest.hpp | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/AirLibUnitTests/PixhawkTest.hpp b/AirLibUnitTests/PixhawkTest.hpp index 0cf4df5cba..d8c039af30 100644 --- a/AirLibUnitTests/PixhawkTest.hpp +++ b/AirLibUnitTests/PixhawkTest.hpp @@ -11,10 +11,8 @@ class PixhawkTest : public TestBase { public: virtual void run() override { - SensorFactory sensor_factory; - //Test PX4 based drones - auto pixhawk = MultiRotorParamsFactory::createConfig("Pixhawk", &sensor_factory); + auto pixhawk = MultiRotorParamsFactory::createConfig("Pixhawk", std::make_shared()); DroneControllerBase* controller = pixhawk->getController(); testAssert(controller != nullptr, "Couldn't get pixhawk controller"); diff --git a/AirLibUnitTests/RosFlightTest.hpp b/AirLibUnitTests/RosFlightTest.hpp index f8c512d734..9864e3112d 100644 --- a/AirLibUnitTests/RosFlightTest.hpp +++ b/AirLibUnitTests/RosFlightTest.hpp @@ -12,8 +12,7 @@ class RosFlightTest : public TestBase { public: virtual void run() override { - SensorFactory sensor_factory; - auto rosFlight = MultiRotorParamsFactory::createConfig("RosFlight", &sensor_factory); + auto rosFlight = MultiRotorParamsFactory::createConfig("RosFlight", std::make_shared()); DroneControllerBase* controller = rosFlight->getController(); testAssert(controller != nullptr, "Couldn't get controller"); diff --git a/AirLibUnitTests/SimpleFlightTest.hpp b/AirLibUnitTests/SimpleFlightTest.hpp index df6784dc5f..0ce98babd0 100644 --- a/AirLibUnitTests/SimpleFlightTest.hpp +++ b/AirLibUnitTests/SimpleFlightTest.hpp @@ -22,7 +22,7 @@ class SimpleFlightTest : public TestBase SensorFactory sensor_factory; - std::unique_ptr params = MultiRotorParamsFactory::createConfig("SimpleFlight", &sensor_factory); + std::unique_ptr params = MultiRotorParamsFactory::createConfig("SimpleFlight", std::make_shared()); MultiRotor vehicle; std::unique_ptr environment; vehicle.initialize(params.get(), Pose(), From 6a1657d72af98a9fe2ef7e1a3de9144d58289969 Mon Sep 17 00:00:00 2001 From: Christopher Dyken Date: Tue, 13 Feb 2018 16:30:49 +0100 Subject: [PATCH 2/2] Check in MavLinkDroneController::update if we actually have a distance sensor --- .../controllers/MavLinkDroneController.hpp | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/AirLib/include/vehicles/multirotor/controllers/MavLinkDroneController.hpp b/AirLib/include/vehicles/multirotor/controllers/MavLinkDroneController.hpp index f0841104df..8cd4b3968d 100644 --- a/AirLib/include/vehicles/multirotor/controllers/MavLinkDroneController.hpp +++ b/AirLib/include/vehicles/multirotor/controllers/MavLinkDroneController.hpp @@ -787,16 +787,20 @@ struct MavLinkDroneController::impl { mag_output.magnetic_field_body, baro_output.pressure * 0.01f /*Pa to Milibar */, baro_output.altitude); - const auto& distance_output = getDistance()->getOutput(); - float pitch, roll, yaw; - VectorMath::toEulerianAngle(distance_output.relative_pose.orientation, pitch, roll, yaw); - - sendDistanceSensor(distance_output.min_distance / 100, //m -> cm - distance_output.max_distance / 100, //m -> cm - distance_output.distance, - 0, //sensor type: //TODO: allow changing in settings? - 77, //sensor id, //TODO: should this be something real? - pitch); //TODO: convert from radians to degrees? + + const auto * distance = getDistance(); + if (distance) { + const auto& distance_output = distance->getOutput(); + float pitch, roll, yaw; + VectorMath::toEulerianAngle(distance_output.relative_pose.orientation, pitch, roll, yaw); + + sendDistanceSensor(distance_output.min_distance / 100, //m -> cm + distance_output.max_distance / 100, //m -> cm + distance_output.distance, + 0, //sensor type: //TODO: allow changing in settings? + 77, //sensor id, //TODO: should this be something real? + pitch); //TODO: convert from radians to degrees? + } const auto gps = getGps(); if (gps != nullptr) {