Skip to content

Commit 2901d86

Browse files
committed
gimbal: add filter
1 parent 6eada5b commit 2901d86

File tree

5 files changed

+32
-1
lines changed

5 files changed

+32
-1
lines changed

src/modules/gimbal/gimbal.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ void update_params(ParameterHandles &param_handles, Parameters &params)
556556
param_get(param_handles.mnt_rc_in_mode, &params.mnt_rc_in_mode);
557557
param_get(param_handles.mnt_lnd_p_min, &params.mnt_lnd_p_min);
558558
param_get(param_handles.mnt_lnd_p_max, &params.mnt_lnd_p_max);
559+
param_get(param_handles.mnt_tau, &params.mnt_tau);
559560
}
560561

561562
bool initialize_params(ParameterHandles &param_handles, Parameters &params)
@@ -579,6 +580,7 @@ bool initialize_params(ParameterHandles &param_handles, Parameters &params)
579580
param_handles.mnt_rc_in_mode = param_find("MNT_RC_IN_MODE");
580581
param_handles.mnt_lnd_p_min = param_find("MNT_LND_P_MIN");
581582
param_handles.mnt_lnd_p_max = param_find("MNT_LND_P_MAX");
583+
param_handles.mnt_tau = param_find("MNT_TAU");
582584

583585
if (param_handles.mnt_mode_in == PARAM_INVALID ||
584586
param_handles.mnt_mode_out == PARAM_INVALID ||
@@ -598,7 +600,8 @@ bool initialize_params(ParameterHandles &param_handles, Parameters &params)
598600
param_handles.mnt_rate_yaw == PARAM_INVALID ||
599601
param_handles.mnt_rc_in_mode == PARAM_INVALID ||
600602
param_handles.mnt_lnd_p_min == PARAM_INVALID ||
601-
param_handles.mnt_lnd_p_max == PARAM_INVALID
603+
param_handles.mnt_lnd_p_max == PARAM_INVALID ||
604+
param_handles.mnt_tau == PARAM_INVALID
602605
) {
603606
return false;
604607
}

src/modules/gimbal/gimbal_params.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,19 @@ PARAM_DEFINE_FLOAT(MNT_RATE_PITCH, 30.0f);
224224
*/
225225
PARAM_DEFINE_FLOAT(MNT_RATE_YAW, 30.0f);
226226

227+
/**
228+
* Alpha filter time constant defining the convergence rate (in seconds) for open-loop AUX mount control.
229+
*
230+
* Use when no angular position feedback is available.
231+
* With MNT_MODE_OUT set to AUX, the mount operates in open-loop and directly commands the servo output.
232+
* Parameters must be tuned for the specific servo to approximate its speed and response.
233+
*
234+
* @min 0.0
235+
* @group Mount
236+
*/
237+
PARAM_DEFINE_FLOAT(MNT_TAU, 0.3f);
238+
239+
227240
/**
228241
* Input mode for RC gimbal input
229242
*

src/modules/gimbal/gimbal_params.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ struct Parameters {
7575
int32_t mnt_rc_in_mode;
7676
float mnt_lnd_p_min;
7777
float mnt_lnd_p_max;
78+
float mnt_tau;
7879
};
7980

8081
struct ParameterHandles {
@@ -97,6 +98,7 @@ struct ParameterHandles {
9798
param_t mnt_rc_in_mode;
9899
param_t mnt_lnd_p_min;
99100
param_t mnt_lnd_p_max;
101+
param_t mnt_tau;
100102
};
101103

102104
} /* namespace gimbal */

src/modules/gimbal/output.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,16 @@ void OutputBase::_calculate_angle_output(const hrt_abstime &t)
286286
math::radians(_parameters.mnt_lnd_p_max));
287287
}
288288
}
289+
290+
_angle_outputs_filtered.setParameters(dt, _parameters.mnt_tau);
291+
matrix::Vector3f filtered_outputs = _angle_outputs_filtered.update(matrix::Vector3f(_angle_outputs));
292+
293+
for (int i = 0; i < 3; i++) {
294+
_angle_outputs[i] = filtered_outputs(i);
295+
}
296+
297+
set_last_valid_setpoint(compensate, euler_vehicle);
298+
289299
}
290300

291301
void OutputBase::set_stabilize(bool roll_stabilize, bool pitch_stabilize, bool yaw_stabilize)

src/modules/gimbal/output.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#include "gimbal_params.h"
3939
#include <drivers/drv_hrt.h>
4040
#include <lib/geo/geo.h>
41+
#include <mathlib/math/filter/AlphaFilter.hpp>
42+
#include <matrix/Vector3.hpp>
4143
#include <uORB/Publication.hpp>
4244
#include <uORB/Subscription.hpp>
4345
#include <uORB/topics/mount_orientation.h>
@@ -92,6 +94,7 @@ class OutputBase
9294
// Pitch and role are by default aligned with the horizon.
9395
// Yaw follows the vehicle (not lock/absolute mode).
9496
bool _absolute_angle[3] = {true, true, false };
97+
AlphaFilter<matrix::Vector3f> _angle_outputs_filtered;
9598

9699
/** calculate the _angle_outputs (with speed) and stabilize if needed */
97100
void _calculate_angle_output(const hrt_abstime &t);

0 commit comments

Comments
 (0)