2015-12-30 22:19:52 -04:00
|
|
|
/************************************************************
|
|
|
|
* SoloGimbal -- library to control a 3 axis rate gimbal. *
|
|
|
|
* *
|
|
|
|
* Author: Arthur Benemann, Paul Riseborough; *
|
|
|
|
* *
|
|
|
|
************************************************************/
|
2016-02-17 21:25:38 -04:00
|
|
|
#pragma once
|
2015-12-30 22:19:52 -04:00
|
|
|
|
2023-05-26 01:16:12 -03:00
|
|
|
#include "AP_Mount_config.h"
|
|
|
|
|
2020-07-24 14:01:21 -03:00
|
|
|
#if HAL_SOLO_GIMBAL_ENABLED
|
2023-05-26 01:16:12 -03:00
|
|
|
|
|
|
|
#include <AP_AccelCal/AP_AccelCal.h>
|
2015-12-30 22:19:52 -04:00
|
|
|
#include <AP_Common/AP_Common.h>
|
2023-05-26 01:16:12 -03:00
|
|
|
#include <AP_HAL/AP_HAL_Boards.h>
|
|
|
|
#include <AP_Math/AP_Math.h>
|
2015-12-30 22:19:52 -04:00
|
|
|
#include <GCS_MAVLink/GCS_MAVLink.h>
|
|
|
|
|
|
|
|
#include "SoloGimbal_Parameters.h"
|
2023-05-26 01:16:12 -03:00
|
|
|
#include "SoloGimbalEKF.h"
|
2015-12-30 22:19:52 -04:00
|
|
|
|
|
|
|
enum gimbal_state_t {
|
|
|
|
GIMBAL_STATE_NOT_PRESENT = 0,
|
|
|
|
GIMBAL_STATE_PRESENT_INITIALIZING,
|
|
|
|
GIMBAL_STATE_PRESENT_ALIGNING,
|
|
|
|
GIMBAL_STATE_PRESENT_RUNNING
|
|
|
|
};
|
|
|
|
|
|
|
|
enum gimbal_mode_t {
|
|
|
|
GIMBAL_MODE_IDLE = 0,
|
|
|
|
GIMBAL_MODE_POS_HOLD,
|
|
|
|
GIMBAL_MODE_POS_HOLD_FF,
|
|
|
|
GIMBAL_MODE_STABILIZE
|
|
|
|
};
|
|
|
|
|
|
|
|
class SoloGimbal : AP_AccelCal_Client
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
//Constructor
|
2018-10-11 06:30:03 -03:00
|
|
|
SoloGimbal() :
|
2018-11-04 21:07:32 -04:00
|
|
|
_ekf(),
|
2015-12-30 22:19:52 -04:00
|
|
|
_state(GIMBAL_STATE_NOT_PRESENT),
|
|
|
|
_vehicle_yaw_rate_ef_filt(0.0f),
|
|
|
|
_vehicle_to_gimbal_quat(),
|
|
|
|
_vehicle_to_gimbal_quat_filt(),
|
|
|
|
_filtered_joint_angles(),
|
2016-03-01 08:49:19 -04:00
|
|
|
_last_report_msg_ms(0),
|
2015-12-30 22:19:52 -04:00
|
|
|
_max_torque(5000.0f),
|
2016-03-01 08:49:19 -04:00
|
|
|
_ang_vel_mag_filt(0),
|
|
|
|
_lockedToBody(false),
|
2015-12-30 22:19:52 -04:00
|
|
|
_log_dt(0),
|
|
|
|
_log_del_ang(),
|
|
|
|
_log_del_vel()
|
|
|
|
{
|
2022-03-18 04:02:30 -03:00
|
|
|
#if HAL_INS_ACCELCAL_ENABLED
|
2015-12-30 22:19:52 -04:00
|
|
|
AP_AccelCal::register_client(this);
|
2022-03-18 04:02:30 -03:00
|
|
|
#endif
|
2015-12-30 22:19:52 -04:00
|
|
|
}
|
|
|
|
|
2018-12-20 05:12:12 -04:00
|
|
|
void update_target(const Vector3f &newTarget);
|
2019-04-30 07:22:48 -03:00
|
|
|
void receive_feedback(mavlink_channel_t chan, const mavlink_message_t &msg);
|
2015-12-30 22:19:52 -04:00
|
|
|
|
|
|
|
void update_fast();
|
|
|
|
|
|
|
|
bool present();
|
|
|
|
bool aligned();
|
|
|
|
|
|
|
|
void set_lockedToBody(bool val) { _lockedToBody = val; }
|
|
|
|
|
2018-03-13 21:23:01 -03:00
|
|
|
void write_logs();
|
2015-12-30 22:19:52 -04:00
|
|
|
|
2021-02-01 12:26:31 -04:00
|
|
|
float get_log_dt() const { return _log_dt; }
|
2015-12-30 22:19:52 -04:00
|
|
|
|
|
|
|
void disable_torque_report() { _gimbalParams.set_param(GMB_PARAM_GMB_SND_TORQUE, 0); }
|
|
|
|
void fetch_params() { _gimbalParams.fetch_params(); }
|
|
|
|
|
2019-04-30 07:22:48 -03:00
|
|
|
void handle_param_value(const mavlink_message_t &msg) {
|
2018-03-13 21:23:01 -03:00
|
|
|
_gimbalParams.handle_param_value(msg);
|
2015-12-30 22:19:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// private methods
|
|
|
|
void update_estimators();
|
|
|
|
void send_controls(mavlink_channel_t chan);
|
|
|
|
void extract_feedback(const mavlink_gimbal_report_t& report_msg);
|
|
|
|
void update_joint_angle_est();
|
|
|
|
|
|
|
|
Vector3f get_ang_vel_dem_yaw(const Quaternion &quatEst);
|
2020-12-01 17:00:12 -04:00
|
|
|
Vector3f get_ang_vel_dem_roll_tilt(const Quaternion &quatEst);
|
2021-02-01 12:26:31 -04:00
|
|
|
Vector3f get_ang_vel_dem_feedforward(const Quaternion &quatEst) const;
|
2015-12-30 22:19:52 -04:00
|
|
|
Vector3f get_ang_vel_dem_gyro_bias();
|
|
|
|
Vector3f get_ang_vel_dem_body_lock();
|
|
|
|
|
2021-02-01 12:26:31 -04:00
|
|
|
void gimbal_ang_vel_to_joint_rates(const Vector3f& ang_vel, Vector3f& joint_rates) const;
|
|
|
|
void joint_rates_to_gimbal_ang_vel(const Vector3f& joint_rates, Vector3f& ang_vel) const;
|
2015-12-30 22:19:52 -04:00
|
|
|
|
|
|
|
void readVehicleDeltaAngle(uint8_t ins_index, Vector3f &dAng);
|
|
|
|
|
2018-11-07 07:01:07 -04:00
|
|
|
void _acal_save_calibrations() override;
|
|
|
|
bool _acal_get_ready_to_sample() override;
|
|
|
|
bool _acal_get_saving() override;
|
|
|
|
AccelCalibrator* _acal_get_calibrator(uint8_t instance) override;
|
2015-12-30 22:19:52 -04:00
|
|
|
|
|
|
|
gimbal_mode_t get_mode();
|
|
|
|
|
2021-02-01 12:26:31 -04:00
|
|
|
bool joints_near_limits() const;
|
2015-12-30 22:19:52 -04:00
|
|
|
|
|
|
|
// private member variables
|
2016-03-01 08:49:19 -04:00
|
|
|
SoloGimbalEKF _ekf; // state of small EKF for gimbal
|
|
|
|
|
2015-12-30 22:19:52 -04:00
|
|
|
gimbal_state_t _state;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
float delta_time;
|
|
|
|
Vector3f delta_angles;
|
|
|
|
Vector3f delta_velocity;
|
|
|
|
Vector3f joint_angles;
|
|
|
|
} _measurement;
|
|
|
|
|
|
|
|
float _vehicle_yaw_rate_ef_filt;
|
|
|
|
|
|
|
|
static const uint8_t _compid = MAV_COMP_ID_GIMBAL;
|
|
|
|
|
|
|
|
// joint angle filter states
|
|
|
|
Vector3f _vehicle_delta_angles;
|
|
|
|
|
|
|
|
Quaternion _vehicle_to_gimbal_quat;
|
|
|
|
Quaternion _vehicle_to_gimbal_quat_filt;
|
|
|
|
Vector3f _filtered_joint_angles;
|
|
|
|
|
|
|
|
uint32_t _last_report_msg_ms;
|
|
|
|
|
|
|
|
float _max_torque;
|
|
|
|
|
|
|
|
float _ang_vel_mag_filt;
|
|
|
|
|
|
|
|
Vector3f _ang_vel_dem_rads; // rad/s
|
|
|
|
Vector3f _att_target_euler_rad; // desired earth-frame roll, tilt and pan angles in radians
|
|
|
|
|
|
|
|
bool _lockedToBody;
|
|
|
|
|
|
|
|
SoloGimbal_Parameters _gimbalParams;
|
|
|
|
|
|
|
|
AccelCalibrator _calibrator;
|
|
|
|
|
|
|
|
float _log_dt;
|
|
|
|
Vector3f _log_del_ang;
|
|
|
|
Vector3f _log_del_vel;
|
|
|
|
};
|
|
|
|
|
2020-07-24 14:01:21 -03:00
|
|
|
#endif // HAL_SOLO_GIMBAL_ENABLED
|