2012-06-13 15:55:19 -03:00
|
|
|
/************************************************************
|
|
|
|
* AP_mount -- library to control a 2 or 3 axis mount. *
|
|
|
|
* *
|
|
|
|
* Author: Joe Holdsworth; *
|
|
|
|
* Ritchie Wilson; *
|
|
|
|
* Amilcar Lucas; *
|
|
|
|
* Gregory Fletcher; *
|
2015-01-08 16:10:48 -04:00
|
|
|
* heavily modified by Randy Mackay *
|
2012-06-13 15:55:19 -03:00
|
|
|
* *
|
|
|
|
* Purpose: Move a 2 or 3 axis mount attached to vehicle, *
|
|
|
|
* Used for mount to track targets or stabilise *
|
|
|
|
* camera plus other modes. *
|
|
|
|
* *
|
|
|
|
* Usage: Use in main code to control mounts attached to *
|
|
|
|
* vehicle. *
|
|
|
|
* *
|
2012-08-26 19:37:10 -03:00
|
|
|
* Comments: All angles in degrees * 100, distances in meters*
|
2012-06-13 15:55:19 -03:00
|
|
|
* unless otherwise stated. *
|
2012-08-17 03:20:30 -03:00
|
|
|
************************************************************/
|
2016-02-17 21:25:38 -04:00
|
|
|
#pragma once
|
2012-06-13 15:55:19 -03:00
|
|
|
|
2015-08-11 03:28:44 -03:00
|
|
|
#include <AP_Math/AP_Math.h>
|
|
|
|
#include <AP_Common/AP_Common.h>
|
2019-04-04 07:50:00 -03:00
|
|
|
#include <AP_Common/Location.h>
|
2015-08-11 03:28:44 -03:00
|
|
|
#include <GCS_MAVLink/GCS_MAVLink.h>
|
2012-06-13 15:55:19 -03:00
|
|
|
|
2015-01-08 16:10:48 -04:00
|
|
|
// maximum number of mounts
|
|
|
|
#define AP_MOUNT_MAX_INSTANCES 1
|
|
|
|
|
|
|
|
// declare backend classes
|
|
|
|
class AP_Mount_Backend;
|
|
|
|
class AP_Mount_Servo;
|
2015-12-30 22:19:52 -04:00
|
|
|
class AP_Mount_SoloGimbal;
|
2015-01-15 18:47:59 -04:00
|
|
|
class AP_Mount_Alexmos;
|
2015-02-14 08:27:58 -04:00
|
|
|
class AP_Mount_SToRM32;
|
2015-05-26 04:21:12 -03:00
|
|
|
class AP_Mount_SToRM32_serial;
|
2015-01-08 16:10:48 -04:00
|
|
|
|
2015-01-30 02:39:31 -04:00
|
|
|
/*
|
|
|
|
This is a workaround to allow the MAVLink backend access to the
|
|
|
|
SmallEKF. It would be nice to find a neater solution to this
|
|
|
|
*/
|
|
|
|
|
2012-06-13 15:55:19 -03:00
|
|
|
class AP_Mount
|
|
|
|
{
|
2015-01-08 16:10:48 -04:00
|
|
|
// declare backends as friends
|
|
|
|
friend class AP_Mount_Backend;
|
|
|
|
friend class AP_Mount_Servo;
|
2015-12-30 22:19:52 -04:00
|
|
|
friend class AP_Mount_SoloGimbal;
|
2015-01-15 18:47:59 -04:00
|
|
|
friend class AP_Mount_Alexmos;
|
2015-02-14 08:27:58 -04:00
|
|
|
friend class AP_Mount_SToRM32;
|
2015-05-26 04:21:12 -03:00
|
|
|
friend class AP_Mount_SToRM32_serial;
|
2015-01-08 16:10:48 -04:00
|
|
|
|
2012-06-13 15:55:19 -03:00
|
|
|
public:
|
2019-03-26 08:36:36 -03:00
|
|
|
AP_Mount();
|
2017-08-29 16:47:49 -03:00
|
|
|
|
|
|
|
/* Do not allow copies */
|
|
|
|
AP_Mount(const AP_Mount &other) = delete;
|
|
|
|
AP_Mount &operator=(const AP_Mount&) = delete;
|
|
|
|
|
2018-07-24 20:30:23 -03:00
|
|
|
// get singleton instance
|
|
|
|
static AP_Mount *get_singleton() {
|
|
|
|
return _singleton;
|
|
|
|
}
|
2012-08-17 03:20:30 -03:00
|
|
|
|
2015-01-08 16:10:48 -04:00
|
|
|
// Enums
|
2012-08-17 03:20:30 -03:00
|
|
|
enum MountType {
|
2015-01-08 16:10:48 -04:00
|
|
|
Mount_Type_None = 0, /// no mount
|
|
|
|
Mount_Type_Servo = 1, /// servo controlled mount
|
2015-12-30 22:19:52 -04:00
|
|
|
Mount_Type_SoloGimbal = 2, /// Solo's gimbal
|
2015-02-14 08:27:58 -04:00
|
|
|
Mount_Type_Alexmos = 3, /// Alexmos mount
|
2015-05-26 04:21:12 -03:00
|
|
|
Mount_Type_SToRM32 = 4, /// SToRM32 mount using MAVLink protocol
|
|
|
|
Mount_Type_SToRM32_serial = 5 /// SToRM32 mount using custom serial protocol
|
2012-08-17 03:20:30 -03:00
|
|
|
};
|
|
|
|
|
2015-01-08 16:10:48 -04:00
|
|
|
// init - detect and initialise all mounts
|
2019-08-27 03:23:30 -03:00
|
|
|
void init();
|
2015-01-08 16:10:48 -04:00
|
|
|
|
|
|
|
// update - give mount opportunity to update servos. should be called at 10hz or higher
|
|
|
|
void update();
|
|
|
|
|
2015-12-30 22:19:52 -04:00
|
|
|
// used for gimbals that need to read INS data at full rate
|
|
|
|
void update_fast();
|
|
|
|
|
2015-01-08 16:10:48 -04:00
|
|
|
// get_mount_type - returns the type of mount
|
|
|
|
AP_Mount::MountType get_mount_type() const { return get_mount_type(_primary); }
|
|
|
|
AP_Mount::MountType get_mount_type(uint8_t instance) const;
|
|
|
|
|
|
|
|
// has_pan_control - returns true if the mount has yaw control (required for copters)
|
|
|
|
bool has_pan_control() const { return has_pan_control(_primary); }
|
|
|
|
bool has_pan_control(uint8_t instance) const;
|
2014-03-05 03:01:11 -04:00
|
|
|
|
2015-01-08 16:10:48 -04:00
|
|
|
// get_mode - returns current mode of mount (i.e. Retracted, Neutral, RC_Targeting, GPS Point)
|
|
|
|
enum MAV_MOUNT_MODE get_mode() const { return get_mode(_primary); }
|
|
|
|
enum MAV_MOUNT_MODE get_mode(uint8_t instance) const;
|
|
|
|
|
|
|
|
// set_mode - sets mount's mode
|
2015-01-12 07:41:12 -04:00
|
|
|
// returns true if mode is successfully set
|
|
|
|
void set_mode(enum MAV_MOUNT_MODE mode) { return set_mode(_primary, mode); }
|
2015-01-08 16:10:48 -04:00
|
|
|
void set_mode(uint8_t instance, enum MAV_MOUNT_MODE mode);
|
|
|
|
|
2015-01-12 07:41:12 -04:00
|
|
|
// set_mode_to_default - restores the mode to it's default mode held in the MNT_DEFLT_MODE parameter
|
2015-11-03 09:46:29 -04:00
|
|
|
// this operation requires 60us on a Pixhawk/PX4
|
2015-01-08 16:10:48 -04:00
|
|
|
void set_mode_to_default() { set_mode_to_default(_primary); }
|
|
|
|
void set_mode_to_default(uint8_t instance);
|
|
|
|
|
2015-03-21 08:58:57 -03:00
|
|
|
// set_angle_targets - sets angle targets in degrees
|
|
|
|
void set_angle_targets(float roll, float tilt, float pan) { set_angle_targets(_primary, roll, tilt, pan); }
|
|
|
|
void set_angle_targets(uint8_t instance, float roll, float tilt, float pan);
|
|
|
|
|
2015-01-08 16:10:48 -04:00
|
|
|
// set_roi_target - sets target location that mount should attempt to point towards
|
|
|
|
void set_roi_target(const struct Location &target_loc) { set_roi_target(_primary,target_loc); }
|
|
|
|
void set_roi_target(uint8_t instance, const struct Location &target_loc);
|
2012-06-13 15:55:19 -03:00
|
|
|
|
2019-03-16 04:06:02 -03:00
|
|
|
// point at system ID sysid
|
|
|
|
void set_target_sysid(uint8_t instance, const uint8_t sysid);
|
|
|
|
void set_target_sysid(const uint8_t sysid) { set_target_sysid(_primary, sysid); }
|
|
|
|
|
2018-10-11 06:30:03 -03:00
|
|
|
// mavlink message handling:
|
|
|
|
MAV_RESULT handle_command_long(const mavlink_command_long_t &packet);
|
2019-04-30 07:22:48 -03:00
|
|
|
void handle_param_value(const mavlink_message_t &msg);
|
|
|
|
void handle_message(mavlink_channel_t chan, const mavlink_message_t &msg);
|
2015-01-29 05:01:55 -04:00
|
|
|
|
|
|
|
// send a GIMBAL_REPORT message to GCS
|
|
|
|
void send_gimbal_report(mavlink_channel_t chan);
|
|
|
|
|
2018-10-11 06:30:03 -03:00
|
|
|
// send a MOUNT_STATUS message to GCS:
|
|
|
|
void send_mount_status(mavlink_channel_t chan);
|
2015-01-08 16:10:48 -04:00
|
|
|
|
|
|
|
// parameter var table
|
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
2014-07-10 01:01:46 -03:00
|
|
|
|
2015-01-18 21:39:55 -04:00
|
|
|
protected:
|
2018-07-24 20:30:23 -03:00
|
|
|
|
|
|
|
static AP_Mount *_singleton;
|
|
|
|
|
2015-01-08 16:10:48 -04:00
|
|
|
// frontend parameters
|
|
|
|
AP_Int8 _joystick_speed; // joystick gain
|
|
|
|
|
|
|
|
// front end members
|
|
|
|
uint8_t _num_instances; // number of mounts instantiated
|
|
|
|
uint8_t _primary; // primary mount
|
|
|
|
AP_Mount_Backend *_backends[AP_MOUNT_MAX_INSTANCES]; // pointers to instantiated mounts
|
|
|
|
|
|
|
|
// backend state including parameters
|
|
|
|
struct mount_state {
|
|
|
|
// Parameters
|
|
|
|
AP_Int8 _type; // mount type (None, Servo or MAVLink, see MountType enum)
|
2015-01-12 07:41:12 -04:00
|
|
|
AP_Int8 _default_mode; // default mode on startup and when control is returned from autopilot
|
2015-01-08 16:10:48 -04:00
|
|
|
AP_Int8 _stab_roll; // 1 = mount should stabilize earth-frame roll axis, 0 = no stabilization
|
|
|
|
AP_Int8 _stab_tilt; // 1 = mount should stabilize earth-frame pitch axis
|
|
|
|
AP_Int8 _stab_pan; // 1 = mount should stabilize earth-frame yaw axis
|
|
|
|
|
|
|
|
// RC input channels from receiver used for direct angular input from pilot
|
|
|
|
AP_Int8 _roll_rc_in; // pilot provides roll input on this channel
|
|
|
|
AP_Int8 _tilt_rc_in; // pilot provides tilt input on this channel
|
|
|
|
AP_Int8 _pan_rc_in; // pilot provides pan input on this channel
|
|
|
|
|
|
|
|
// Mount's physical limits
|
|
|
|
AP_Int16 _roll_angle_min; // min roll in 0.01 degree units
|
|
|
|
AP_Int16 _roll_angle_max; // max roll in 0.01 degree units
|
|
|
|
AP_Int16 _tilt_angle_min; // min tilt in 0.01 degree units
|
|
|
|
AP_Int16 _tilt_angle_max; // max tilt in 0.01 degree units
|
|
|
|
AP_Int16 _pan_angle_min; // min pan in 0.01 degree units
|
|
|
|
AP_Int16 _pan_angle_max; // max pan in 0.01 degree units
|
|
|
|
|
|
|
|
AP_Vector3f _retract_angles; // retracted position for mount, vector.x = roll vector.y = tilt, vector.z=pan
|
|
|
|
AP_Vector3f _neutral_angles; // neutral position for mount, vector.x = roll vector.y = tilt, vector.z=pan
|
|
|
|
|
|
|
|
AP_Float _roll_stb_lead; // roll lead control gain
|
|
|
|
AP_Float _pitch_stb_lead; // pitch lead control gain
|
|
|
|
|
2015-01-12 07:41:12 -04:00
|
|
|
MAV_MOUNT_MODE _mode; // current mode (see MAV_MOUNT_MODE enum)
|
2015-01-08 16:10:48 -04:00
|
|
|
struct Location _roi_target; // roi target location
|
2019-11-05 19:16:22 -04:00
|
|
|
bool _roi_target_set;
|
2019-03-16 04:06:02 -03:00
|
|
|
|
|
|
|
uint8_t _target_sysid; // sysid to track
|
|
|
|
Location _target_sysid_location; // sysid target location
|
|
|
|
bool _target_sysid_location_set;
|
|
|
|
|
2015-01-08 16:10:48 -04:00
|
|
|
} state[AP_MOUNT_MAX_INSTANCES];
|
2018-10-11 06:30:03 -03:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2019-04-30 07:22:48 -03:00
|
|
|
void handle_gimbal_report(mavlink_channel_t chan, const mavlink_message_t &msg);
|
|
|
|
void handle_mount_configure(const mavlink_message_t &msg);
|
|
|
|
void handle_mount_control(const mavlink_message_t &msg);
|
2018-10-11 06:30:03 -03:00
|
|
|
|
|
|
|
MAV_RESULT handle_command_do_mount_configure(const mavlink_command_long_t &packet);
|
|
|
|
MAV_RESULT handle_command_do_mount_control(const mavlink_command_long_t &packet);
|
2019-03-16 04:06:02 -03:00
|
|
|
void handle_global_position_int(const mavlink_message_t &msg);
|
2012-06-13 15:55:19 -03:00
|
|
|
};
|
2018-07-24 20:30:23 -03:00
|
|
|
|
|
|
|
namespace AP {
|
|
|
|
AP_Mount *mount();
|
|
|
|
};
|