Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multicopter hover thrust estimator use vehicle_thrust_setpoint (work in stabilized/manual mode) #19633

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/drivers/gps/devices
Submodule devices updated 2 files
+61 −166 src/nmea.cpp
+3 −2 src/nmea.h
3 changes: 2 additions & 1 deletion src/modules/mc_att_control/mc_att_control.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/****************************************************************************
*
* Copyright (c) 2013-2019 PX4 Development Team. All rights reserved.
* Copyright (c) 2013-2022 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
Expand Down Expand Up @@ -47,6 +47,7 @@
#include <uORB/topics/manual_control_setpoint.h>
#include <uORB/topics/parameter_update.h>
#include <uORB/topics/autotune_attitude_control_status.h>
#include <uORB/topics/hover_thrust_estimate.h>
#include <uORB/topics/vehicle_attitude.h>
#include <uORB/topics/vehicle_attitude_setpoint.h>
#include <uORB/topics/vehicle_control_mode.h>
Expand Down
2 changes: 1 addition & 1 deletion src/modules/mc_att_control/mc_att_control_main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/****************************************************************************
*
* Copyright (c) 2013-2018 PX4 Development Team. All rights reserved.
* Copyright (c) 2013-2022 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,6 @@ void MulticopterHoverThrustEstimator::Run()
}
}

// new local position setpoint needed every iteration
if (!_vehicle_local_position_setpoint_sub.updated()) {
return;
}

// check for parameter updates
if (_parameter_update_sub.updated()) {
// clear update
Expand Down Expand Up @@ -166,10 +161,34 @@ void MulticopterHoverThrustEstimator::Run()

_hover_thrust_ekf.predict(dt);

vehicle_local_position_setpoint_s local_pos_sp;
vehicle_attitude_s vehicle_attitude{};
_vehicle_attitude_sub.copy(&vehicle_attitude);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: use all of these messages (vehicle_local_position, vehicle_attitude, vehicle_thrust_setpoint) on the same timestamp_sample?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we don't take the motor lag into account (the model assumes instant acceleration), I don't think that aligning the data perfectly is important.


vehicle_thrust_setpoint_s vehicle_thrust_setpoint;
control_allocator_status_s control_allocator_status;

if (_vehicle_thrust_setpoint_sub.update(&vehicle_thrust_setpoint)
&& _control_allocator_status_sub.update(&control_allocator_status)
&& (hrt_elapsed_time(&vehicle_thrust_setpoint.timestamp) < 20_ms)
&& (hrt_elapsed_time(&vehicle_attitude.timestamp) < 20_ms)
) {

const matrix::Quatf q_att{vehicle_attitude.q};

matrix::Vector3f thrust_body_sp(vehicle_thrust_setpoint.xyz);
matrix::Vector3f thrust_body_unallocated(control_allocator_status.unallocated_thrust);

thrust_body_sp(0) = 0.f; // ignore for now
thrust_body_sp(1) = 0.f; // ignore for now

thrust_body_unallocated(0) = 0.f; // ignore for now
thrust_body_unallocated(1) = 0.f; // ignore for now


matrix::Vector3f thrust_sp = q_att.rotateVector(thrust_body_sp);
matrix::Vector3f thrust_unallocated = q_att.rotateVector(thrust_body_unallocated);

if (_vehicle_local_position_setpoint_sub.copy(&local_pos_sp)) {
if (PX4_ISFINITE(local_pos_sp.thrust[2])) {
if (PX4_ISFINITE(thrust_sp(2))) {
// Inform the hover thrust estimator about the measured vertical
// acceleration (positive acceleration is up) and the current thrust (positive thrust is up)
// Guard against fast up and down motions biasing the estimator due to large drag and prop wash effects
Expand All @@ -179,7 +198,7 @@ void MulticopterHoverThrustEstimator::Run()
1.f);

_hover_thrust_ekf.setMeasurementNoiseScale(fmaxf(meas_noise_coeff_xy, meas_noise_coeff_z));
_hover_thrust_ekf.fuseAccZ(-local_pos.az, -local_pos_sp.thrust[2]);
_hover_thrust_ekf.fuseAccZ(-local_pos.az, -(thrust_sp(2) - thrust_unallocated(2)));

bool valid = (_hover_thrust_ekf.getHoverThrustEstimateVar() < 0.001f);

Expand All @@ -191,7 +210,7 @@ void MulticopterHoverThrustEstimator::Run()
_valid_hysteresis.set_state_and_update(valid, local_pos.timestamp);
_valid = _valid_hysteresis.get_state();

publishStatus(local_pos.timestamp);
publishStatus(vehicle_thrust_setpoint.timestamp);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@
#include <uORB/SubscriptionCallback.hpp>
#include <uORB/topics/hover_thrust_estimate.h>
#include <uORB/topics/parameter_update.h>
#include <uORB/topics/vehicle_attitude.h>
#include <uORB/topics/vehicle_land_detected.h>
#include <uORB/topics/vehicle_local_position.h>
#include <uORB/topics/vehicle_local_position_setpoint.h>
#include <uORB/topics/vehicle_status.h>
#include <uORB/topics/vehicle_thrust_setpoint.h>
#include <uORB/topics/control_allocator_status.h>

#include "zero_order_hover_thrust_ekf.hpp"

Expand Down Expand Up @@ -101,9 +103,12 @@ class MulticopterHoverThrustEstimator : public ModuleBase<MulticopterHoverThrust

uORB::SubscriptionInterval _parameter_update_sub{ORB_ID(parameter_update), 1_s};

uORB::Subscription _hover_thrust_estimate_sub{ORB_ID(hover_thrust_estimate)};
uORB::Subscription _vehicle_land_detected_sub{ORB_ID(vehicle_land_detected)};
uORB::Subscription _vehicle_status_sub{ORB_ID(vehicle_status)};
uORB::Subscription _vehicle_local_position_setpoint_sub{ORB_ID(vehicle_local_position_setpoint)};
uORB::Subscription _vehicle_attitude_sub{ORB_ID(vehicle_attitude)};
uORB::Subscription _vehicle_thrust_setpoint_sub{ORB_ID(vehicle_thrust_setpoint)};
uORB::Subscription _control_allocator_status_sub{ORB_ID(control_allocator_status)};

hrt_abstime _timestamp_last{0};

Expand Down
Loading