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) { 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(),