diff --git a/src/modules/mc_pos_control/PositionControl/CMakeLists.txt b/src/modules/mc_pos_control/PositionControl/CMakeLists.txt index 8136317376..72205231ea 100644 --- a/src/modules/mc_pos_control/PositionControl/CMakeLists.txt +++ b/src/modules/mc_pos_control/PositionControl/CMakeLists.txt @@ -41,3 +41,4 @@ target_include_directories(PositionControl PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) px4_add_unit_gtest(SRC ControlMathTest.cpp LINKLIBS PositionControl) px4_add_unit_gtest(SRC PositionControlTest.cpp LINKLIBS PositionControl) +px4_add_unit_gtest(SRC PositionAttitudeTest.cpp LINKLIBS PositionControl AttitudeControl) diff --git a/src/modules/mc_pos_control/PositionControl/PositionAttitudeTest.cpp b/src/modules/mc_pos_control/PositionControl/PositionAttitudeTest.cpp new file mode 100644 index 0000000000..10aecabc13 --- /dev/null +++ b/src/modules/mc_pos_control/PositionControl/PositionAttitudeTest.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** + * + * Copyright (C) 2020 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name PX4 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. + * + ****************************************************************************/ + +#include +#include +#include +#include + +using namespace matrix; + +TEST(PositionControlTest, NavigationYawInfluence) +{ + const Vector3f thrust_setpoint(1.f, 1.f, -.5f); + const float yaw_setpoint = 0.f; + + // Generate attitude + vehicle_attitude_setpoint_s attitude_setpoint{}; + ControlMath::thrustToAttitude(thrust_setpoint, yaw_setpoint, attitude_setpoint); + + // Set up attitude control + AttitudeControl attitude_control; + attitude_control.setProportionalGain(Vector3f(1.f, 1.f, 1.f)); + attitude_control.setRateLimit(Vector3f(100.f, 100.f, 100.f)); + + // Execute on attitude + Quatf qd(attitude_setpoint.q_d); + const Vector3f rate_setpoint = attitude_control.update(Quatf(), qd, 0.f); + rate_setpoint.print(); + + // expect symmetric angular rate command towards thrust direction without any body yaw correction + EXPECT_GT(rate_setpoint(0), 0.f); + EXPECT_LT(rate_setpoint(1), 0.f); + EXPECT_FLOAT_EQ(fabsf(rate_setpoint(0)), fabsf(rate_setpoint(1))); + EXPECT_FLOAT_EQ(rate_setpoint(2), 0.f); +}