mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
mavsdk tests: use tester sleep_for function
the previously used std::this_thread::sleep_for is with respect to host system time which is different from autopilot time if: - speed factor != 1 - something runs slower than realtime regardless of speed factor - debugging or otherwise interrupting PX4 control code tester.sleep_for (which already existed) correctly sleeps w.r.t. px4/simulation time.
This commit is contained in:
parent
d72c2cc378
commit
c0100ed4e7
@ -164,24 +164,6 @@ public:
|
||||
CHECK(_param->set_param_int(param, value) == Param::Result::Success);
|
||||
}
|
||||
|
||||
protected:
|
||||
mavsdk::Param *getParams() const { return _param.get();}
|
||||
mavsdk::Telemetry *getTelemetry() const { return _telemetry.get();}
|
||||
mavsdk::ManualControl *getManualControl() const { return _manual_control.get();}
|
||||
MavlinkPassthrough *getMavlinkPassthrough() const { return _mavlink_passthrough.get();}
|
||||
std::shared_ptr<System> get_system() { return _mavsdk.systems().at(0);}
|
||||
mavsdk::geometry::CoordinateTransformation get_coordinate_transformation();
|
||||
bool ground_truth_horizontal_position_close_to(const Telemetry::GroundTruth &target_pos, float acceptance_radius_m);
|
||||
|
||||
const Telemetry::GroundTruth &getHome()
|
||||
{
|
||||
// Check if home was stored before it is accessed
|
||||
CHECK(_home.absolute_altitude_m != NAN);
|
||||
CHECK(_home.latitude_deg != NAN);
|
||||
CHECK(_home.longitude_deg != NAN);
|
||||
return _home;
|
||||
}
|
||||
|
||||
template<typename Rep, typename Period>
|
||||
void sleep_for(std::chrono::duration<Rep, Period> duration)
|
||||
{
|
||||
@ -207,6 +189,24 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
mavsdk::Param *getParams() const { return _param.get();}
|
||||
mavsdk::Telemetry *getTelemetry() const { return _telemetry.get();}
|
||||
mavsdk::ManualControl *getManualControl() const { return _manual_control.get();}
|
||||
MavlinkPassthrough *getMavlinkPassthrough() const { return _mavlink_passthrough.get();}
|
||||
std::shared_ptr<System> get_system() { return _mavsdk.systems().at(0);}
|
||||
mavsdk::geometry::CoordinateTransformation get_coordinate_transformation();
|
||||
bool ground_truth_horizontal_position_close_to(const Telemetry::GroundTruth &target_pos, float acceptance_radius_m);
|
||||
|
||||
const Telemetry::GroundTruth &getHome()
|
||||
{
|
||||
// Check if home was stored before it is accessed
|
||||
CHECK(_home.absolute_altitude_m != NAN);
|
||||
CHECK(_home.latitude_deg != NAN);
|
||||
CHECK(_home.longitude_deg != NAN);
|
||||
return _home;
|
||||
}
|
||||
|
||||
private:
|
||||
mavsdk::Mission::MissionItem create_mission_item(
|
||||
const mavsdk::geometry::CoordinateTransformation::LocalCoordinate &local_coordinate,
|
||||
@ -282,7 +282,6 @@ private:
|
||||
}
|
||||
|
||||
|
||||
|
||||
mavsdk::Mavsdk _mavsdk{};
|
||||
std::unique_ptr<mavsdk::Action> _action{};
|
||||
std::unique_ptr<mavsdk::Failure> _failure{};
|
||||
|
||||
@ -62,8 +62,7 @@ TEST_CASE("Control Allocation - Remove one motor", "[controlallocation]")
|
||||
tester.check_tracks_mission(5.f);
|
||||
tester.store_home();
|
||||
tester.enable_actuator_output_status();
|
||||
std::this_thread::sleep_for(std::chrono::seconds(
|
||||
1)); // This is necessary for the takeoff altitude to be applied properly
|
||||
tester.sleep_for(std::chrono::seconds(1)); // Necessary for the takeoff altitude to be applied properly
|
||||
|
||||
// Takeoff
|
||||
tester.arm();
|
||||
@ -78,7 +77,7 @@ TEST_CASE("Control Allocation - Remove one motor", "[controlallocation]")
|
||||
const unsigned num_motors = 6; // TODO: get from model
|
||||
tester.inject_failure(mavsdk::Failure::FailureUnit::SystemMotor, mavsdk::Failure::FailureType::Off, motor_instance,
|
||||
mavsdk::Failure::Result::Success);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
tester.sleep_for(std::chrono::seconds(1));
|
||||
tester.ensure_motor_stopped(motor_instance - 1, num_motors);
|
||||
|
||||
tester.execute_mission();
|
||||
@ -115,8 +114,7 @@ TEST_CASE("Control Allocation - Remove two motors", "[controlallocation]")
|
||||
tester.set_rtl_altitude(flight_altitude);
|
||||
tester.check_tracks_mission(5.f);
|
||||
tester.store_home();
|
||||
std::this_thread::sleep_for(std::chrono::seconds(
|
||||
1)); // This is necessary for the takeoff altitude to be applied properly
|
||||
tester.sleep_for(std::chrono::seconds(1)); // Necessary for the takeoff altitude to be applied properly
|
||||
|
||||
tester.arm();
|
||||
tester.takeoff();
|
||||
@ -131,11 +129,11 @@ TEST_CASE("Control Allocation - Remove two motors", "[controlallocation]")
|
||||
tester.inject_failure(mavsdk::Failure::FailureUnit::SystemMotor, mavsdk::Failure::FailureType::Off,
|
||||
first_motor_instance,
|
||||
mavsdk::Failure::Result::Success);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
tester.sleep_for(std::chrono::seconds(1));
|
||||
tester.inject_failure(mavsdk::Failure::FailureUnit::SystemMotor, mavsdk::Failure::FailureType::Off,
|
||||
second_motor_instance,
|
||||
mavsdk::Failure::Result::Success);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
tester.sleep_for(std::chrono::seconds(1));
|
||||
|
||||
tester.execute_mission();
|
||||
tester.stop_checking_altitude();
|
||||
@ -170,8 +168,7 @@ TEST_CASE("Control Allocation - Remove and restore every motor once", "[controla
|
||||
tester.set_rtl_altitude(flight_altitude);
|
||||
tester.check_tracks_mission(5.f);
|
||||
tester.store_home();
|
||||
std::this_thread::sleep_for(std::chrono::seconds(
|
||||
1)); // This is necessary for the takeoff altitude to be applied properly
|
||||
tester.sleep_for(std::chrono::seconds(1)); // Necessary for the takeoff altitude to be applied properly
|
||||
|
||||
tester.arm();
|
||||
tester.takeoff();
|
||||
@ -184,10 +181,10 @@ TEST_CASE("Control Allocation - Remove and restore every motor once", "[controla
|
||||
for (int m = 1; m <= 6; m++) {
|
||||
tester.inject_failure(mavsdk::Failure::FailureUnit::SystemMotor, mavsdk::Failure::FailureType::Off, m,
|
||||
mavsdk::Failure::Result::Success);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
tester.sleep_for(std::chrono::seconds(1));
|
||||
tester.inject_failure(mavsdk::Failure::FailureUnit::SystemMotor, mavsdk::Failure::FailureType::Ok, m,
|
||||
mavsdk::Failure::Result::Success);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
tester.sleep_for(std::chrono::seconds(1));
|
||||
}
|
||||
|
||||
tester.execute_mission();
|
||||
@ -216,8 +213,7 @@ TEST_CASE("Control Allocation - Return home on motor failure", "[controlallocati
|
||||
tester.set_param_com_act_fail_act(3); // RTL on motor failure
|
||||
tester.set_takeoff_altitude(flight_altitude);
|
||||
tester.store_home();
|
||||
std::this_thread::sleep_for(std::chrono::seconds(
|
||||
1)); // This is necessary for the takeoff altitude to be applied properly
|
||||
tester.sleep_for(std::chrono::seconds(1)); // Necessary for the takeoff altitude to be applied properly
|
||||
|
||||
// Takeoff
|
||||
tester.arm();
|
||||
@ -232,7 +228,7 @@ TEST_CASE("Control Allocation - Return home on motor failure", "[controlallocati
|
||||
const int motor_instance = 1;
|
||||
tester.inject_failure(mavsdk::Failure::FailureUnit::SystemMotor, mavsdk::Failure::FailureType::Off, motor_instance,
|
||||
mavsdk::Failure::Result::Success);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
tester.sleep_for(std::chrono::seconds(1));
|
||||
|
||||
// Wait for RTL to trigger automatically
|
||||
std::chrono::seconds until_disarmed_timeout = std::chrono::seconds(180);
|
||||
@ -256,8 +252,7 @@ TEST_CASE("Control Allocation - Terminate on motor failure", "[controlallocation
|
||||
tester.set_param_ca_failure_mode(1); // Enable control allocation handling of failed motor
|
||||
tester.set_param_com_act_fail_act(4); // Terminate on motor failure
|
||||
tester.set_takeoff_altitude(flight_altitude);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(
|
||||
1)); // This is necessary for the takeoff altitude to be applied properly
|
||||
tester.sleep_for(std::chrono::seconds(1)); // Necessary for the takeoff altitude to be applied properly
|
||||
|
||||
// Takeoff
|
||||
tester.arm();
|
||||
@ -269,7 +264,7 @@ TEST_CASE("Control Allocation - Terminate on motor failure", "[controlallocation
|
||||
const int motor_instance = 1;
|
||||
tester.inject_failure(mavsdk::Failure::FailureUnit::SystemMotor, mavsdk::Failure::FailureType::Off, motor_instance,
|
||||
mavsdk::Failure::Result::Success);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
tester.sleep_for(std::chrono::seconds(1));
|
||||
|
||||
// Wait for disarm with a low enough timeout such that it's necessary for the
|
||||
// drone to freefall (terminate) in order to disarm quickly enough:
|
||||
|
||||
@ -44,14 +44,14 @@ TEST_CASE("Figure eight execution clockwise", "[vtol]")
|
||||
tester.store_home();
|
||||
const float takeoff_altitude = 20.f;
|
||||
tester.set_takeoff_altitude(takeoff_altitude);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
tester.sleep_for(std::chrono::seconds(3));
|
||||
tester.arm();
|
||||
tester.takeoff();
|
||||
tester.wait_until_hovering();
|
||||
tester.wait_until_altitude(takeoff_altitude, std::chrono::seconds(30));
|
||||
tester.transition_to_fixedwing();
|
||||
tester.wait_until_fixedwing(std::chrono::seconds(5));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
tester.sleep_for(std::chrono::seconds(1));
|
||||
tester.set_figure_eight(150., 50., 0., 200., 0., 20.);
|
||||
tester.execute_figure_eight();
|
||||
tester.check_tracks_figure_eight(std::chrono::seconds(120), 10.);
|
||||
@ -67,14 +67,14 @@ TEST_CASE("Figure eight execution counterclockwise", "[vtol]")
|
||||
tester.store_home();
|
||||
const float takeoff_altitude = 20.f;
|
||||
tester.set_takeoff_altitude(takeoff_altitude);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
tester.sleep_for(std::chrono::seconds(3));
|
||||
tester.arm();
|
||||
tester.takeoff();
|
||||
tester.wait_until_hovering();
|
||||
tester.wait_until_altitude(takeoff_altitude, std::chrono::seconds(30));
|
||||
tester.transition_to_fixedwing();
|
||||
tester.wait_until_fixedwing(std::chrono::seconds(5));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
tester.sleep_for(std::chrono::seconds(1));
|
||||
tester.set_figure_eight(-150., 50., 30.*M_PI / 180., 200., 0., 20.);
|
||||
tester.execute_figure_eight();
|
||||
tester.check_tracks_figure_eight(std::chrono::seconds(120), 10.);
|
||||
|
||||
@ -56,12 +56,12 @@ TEST_CASE("Fly VTOL Loiter with airspeed failure", "[vtol_airspeed_fail]")
|
||||
|
||||
|
||||
// tester.wait_until_altitude(50.f, std::chrono::seconds(30));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(10));
|
||||
tester.sleep_for(std::chrono::seconds(10));
|
||||
tester.inject_failure(mavsdk::Failure::FailureUnit::SensorAirspeed, mavsdk::Failure::FailureType::Wrong, 0,
|
||||
mavsdk::Failure::Result::Success);
|
||||
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::seconds(10));
|
||||
tester.sleep_for(std::chrono::seconds(10));
|
||||
|
||||
tester.check_airspeed_is_invalid(); // it's enough to check once after landing, as invalidation is permanent
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user