2015-03-05 19:31:42 -04:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
|
|
|
/************************************************************
|
2015-04-20 03:51:59 -03:00
|
|
|
* AP_Gimbal -- library to control a 3 axis rate gimbal. *
|
|
|
|
* *
|
|
|
|
* Author: Arthur Benemann, Paul Riseborough; *
|
|
|
|
* *
|
2015-03-05 19:31:42 -04:00
|
|
|
************************************************************/
|
|
|
|
#ifndef __AP_GIMBAL_H__
|
|
|
|
#define __AP_GIMBAL_H__
|
|
|
|
|
2015-08-11 03:28:44 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
#include <AP_AHRS/AP_AHRS.h>
|
2015-04-20 04:53:39 -03:00
|
|
|
|
|
|
|
#if AP_AHRS_NAVEKF_AVAILABLE
|
|
|
|
|
2015-08-11 03:28:44 -03:00
|
|
|
#include <AP_Math/AP_Math.h>
|
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include <AP_GPS/AP_GPS.h>
|
|
|
|
#include <GCS_MAVLink/GCS_MAVLink.h>
|
|
|
|
#include "AP_Mount.h"
|
|
|
|
#include <AP_NavEKF/AP_SmallEKF.h>
|
|
|
|
#include <AP_NavEKF/AP_NavEKF.h>
|
2015-03-05 19:31:42 -04:00
|
|
|
|
|
|
|
class AP_Gimbal
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
//Constructor
|
2015-04-20 03:59:49 -03:00
|
|
|
AP_Gimbal(const AP_AHRS_NavEKF &ahrs, uint8_t compid, const AP_Mount::gimbal_params &gimbalParams) :
|
2015-03-05 19:31:42 -04:00
|
|
|
_ekf(ahrs),
|
2015-03-20 14:32:38 -03:00
|
|
|
_ahrs(ahrs),
|
2015-04-20 03:54:00 -03:00
|
|
|
_gimbalParams(gimbalParams),
|
2015-03-05 19:31:42 -04:00
|
|
|
vehicleYawRateFilt(0.0f),
|
|
|
|
yawRateFiltPole(10.0f),
|
2015-04-20 03:54:00 -03:00
|
|
|
yawErrorLimit(0.1f)
|
2015-03-05 19:31:42 -04:00
|
|
|
{
|
|
|
|
_compid = compid;
|
2015-05-26 22:50:38 -03:00
|
|
|
memset(&_report_msg, 0, sizeof(_report_msg));
|
2015-03-05 19:31:42 -04:00
|
|
|
}
|
2015-03-20 17:43:51 -03:00
|
|
|
|
|
|
|
void update_target(Vector3f newTarget);
|
2015-03-05 19:31:42 -04:00
|
|
|
void receive_feedback(mavlink_channel_t chan, mavlink_message_t *msg);
|
2015-05-23 05:39:12 -03:00
|
|
|
void send_report(mavlink_channel_t chan) const;
|
2015-03-05 19:31:42 -04:00
|
|
|
|
2015-04-01 20:39:09 -03:00
|
|
|
Vector3f getGimbalEstimateEF();
|
|
|
|
|
2015-03-05 19:31:42 -04:00
|
|
|
struct Measurament {
|
|
|
|
float delta_time;
|
|
|
|
Vector3f delta_angles;
|
|
|
|
Vector3f delta_velocity;
|
|
|
|
Vector3f joint_angles;
|
2015-04-20 03:04:37 -03:00
|
|
|
} _measurement;
|
2015-03-05 19:31:42 -04:00
|
|
|
|
|
|
|
SmallEKF _ekf; // state of small EKF for gimbal
|
2015-04-20 03:51:59 -03:00
|
|
|
const AP_AHRS_NavEKF &_ahrs; // Main EKF
|
|
|
|
Vector3f gimbalRateDemVec; // degrees/s
|
|
|
|
Vector3f _angle_ef_target_rad; // desired earth-frame roll, tilt and pan angles in radians
|
2015-03-05 19:31:42 -04:00
|
|
|
|
2015-04-20 03:51:59 -03:00
|
|
|
private:
|
2015-03-30 19:46:19 -03:00
|
|
|
const AP_Mount::gimbal_params &_gimbalParams;
|
2015-03-20 14:32:38 -03:00
|
|
|
|
2015-03-05 19:31:42 -04:00
|
|
|
// filtered yaw rate from the vehicle
|
|
|
|
float vehicleYawRateFilt;
|
|
|
|
|
|
|
|
// circular frequency (rad/sec) constant of filter applied to forward path vehicle yaw rate
|
|
|
|
// this frequency must not be larger than the update rate (Hz).
|
|
|
|
// reducing it makes the gimbal yaw less responsive to vehicle yaw
|
|
|
|
// increasing it makes the gimbal yawe more responsive to vehicle yaw
|
|
|
|
float const yawRateFiltPole;
|
|
|
|
|
|
|
|
// amount of yaw angle that we permit the gimbal to lag the vehicle when operating in slave mode
|
|
|
|
// reducing this makes the gimbal respond more to vehicle yaw disturbances
|
2015-04-20 03:51:59 -03:00
|
|
|
float const yawErrorLimit;
|
2015-03-05 19:31:42 -04:00
|
|
|
|
2015-04-20 03:51:59 -03:00
|
|
|
uint8_t _compid;
|
2015-03-10 18:48:42 -03:00
|
|
|
|
2015-05-23 05:39:12 -03:00
|
|
|
mavlink_gimbal_report_t _report_msg;
|
|
|
|
|
2015-03-05 19:31:42 -04:00
|
|
|
void send_control(mavlink_channel_t chan);
|
|
|
|
void update_state();
|
|
|
|
void decode_feedback(mavlink_message_t *msg);
|
|
|
|
|
2015-04-20 03:51:59 -03:00
|
|
|
bool isCopterFlipped();
|
2015-03-10 19:48:15 -03:00
|
|
|
|
2015-03-05 19:31:42 -04:00
|
|
|
// Control loop functions
|
2015-04-03 17:22:36 -03:00
|
|
|
Vector3f getGimbalRateDemVecYaw(const Quaternion &quatEst);
|
|
|
|
Vector3f getGimbalRateDemVecTilt(const Quaternion &quatEst);
|
|
|
|
Vector3f getGimbalRateDemVecForward(const Quaternion &quatEst);
|
2015-03-05 19:31:42 -04:00
|
|
|
Vector3f getGimbalRateDemVecGyroBias();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2015-04-20 04:53:39 -03:00
|
|
|
#endif // AP_AHRS_NAVEKF_AVAILABLE
|
|
|
|
|
2015-03-05 19:31:42 -04:00
|
|
|
#endif // __AP_MOUNT_H__
|