2015-01-08 16:11:00 -04:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
Mount driver backend class. Each supported mount type
|
|
|
|
needs to have an object derived from this class.
|
|
|
|
*/
|
2016-02-17 21:25:38 -04:00
|
|
|
#pragma once
|
2015-01-08 16:11:00 -04:00
|
|
|
|
2015-08-11 03:28:44 -03:00
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include "AP_Mount.h"
|
2019-04-04 07:50:00 -03:00
|
|
|
#include <RC_Channel/RC_Channel.h>
|
2015-01-08 16:11:00 -04:00
|
|
|
|
|
|
|
class AP_Mount_Backend
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Constructor
|
2015-01-18 21:39:55 -04:00
|
|
|
AP_Mount_Backend(AP_Mount &frontend, AP_Mount::mount_state& state, uint8_t instance) :
|
2015-01-08 16:11:00 -04:00
|
|
|
_frontend(frontend),
|
2015-01-18 21:39:55 -04:00
|
|
|
_state(state),
|
2015-01-08 16:11:00 -04:00
|
|
|
_instance(instance)
|
|
|
|
{}
|
|
|
|
|
|
|
|
// Virtual destructor
|
|
|
|
virtual ~AP_Mount_Backend(void) {}
|
|
|
|
|
|
|
|
// init - performs any required initialisation for this instance
|
2015-01-19 09:38:17 -04:00
|
|
|
virtual void init(const AP_SerialManager& serial_manager) = 0;
|
2015-01-08 16:11:00 -04:00
|
|
|
|
|
|
|
// update mount position - should be called periodically
|
|
|
|
virtual void update() = 0;
|
|
|
|
|
2015-12-30 22:19:52 -04:00
|
|
|
// used for gimbals that need to read INS data at full rate
|
|
|
|
virtual void update_fast() {}
|
|
|
|
|
2015-01-08 16:11:00 -04:00
|
|
|
// has_pan_control - returns true if this mount can control it's pan (required for multicopters)
|
|
|
|
virtual bool has_pan_control() const = 0;
|
|
|
|
|
2015-01-12 07:41:28 -04:00
|
|
|
// set_mode - sets mount's mode
|
|
|
|
virtual void set_mode(enum MAV_MOUNT_MODE mode) = 0;
|
|
|
|
|
2015-03-21 08:58:57 -03:00
|
|
|
// set_angle_targets - sets angle targets in degrees
|
|
|
|
virtual void set_angle_targets(float roll, float tilt, float pan);
|
|
|
|
|
2015-01-08 16:11:00 -04:00
|
|
|
// set_roi_target - sets target location that mount should attempt to point towards
|
2015-01-15 03:46:41 -04:00
|
|
|
virtual void set_roi_target(const struct Location &target_loc);
|
2015-01-08 16:11:00 -04:00
|
|
|
|
2015-08-13 02:31:31 -03:00
|
|
|
// control - control the mount
|
2015-09-05 03:42:42 -03:00
|
|
|
virtual void control(int32_t pitch_or_lat, int32_t roll_or_lon, int32_t yaw_or_alt, MAV_MOUNT_MODE mount_mode);
|
2015-08-13 02:31:31 -03:00
|
|
|
|
2018-10-11 06:30:03 -03:00
|
|
|
// process MOUNT_CONFIGURE messages received from GCS:
|
|
|
|
void handle_mount_configure(const mavlink_mount_configure_t &msg);
|
2015-01-08 16:11:00 -04:00
|
|
|
|
2018-10-11 06:30:03 -03:00
|
|
|
// process MOUNT_CONTROL messages received from GCS:
|
|
|
|
void handle_mount_control(const mavlink_mount_control_t &packet);
|
2015-01-08 16:11:00 -04:00
|
|
|
|
2018-10-11 06:30:03 -03:00
|
|
|
// send_mount_status - called to allow mounts to send their status to GCS via MAVLink
|
|
|
|
virtual void send_mount_status(mavlink_channel_t chan) = 0;
|
2015-01-08 16:11:00 -04:00
|
|
|
|
2015-01-29 05:01:55 -04:00
|
|
|
// handle a GIMBAL_REPORT message
|
2018-10-11 06:30:03 -03:00
|
|
|
virtual void handle_gimbal_report(mavlink_channel_t chan, const mavlink_message_t *msg) {}
|
2015-01-29 05:01:55 -04:00
|
|
|
|
2015-12-30 22:19:52 -04:00
|
|
|
// handle a PARAM_VALUE message
|
2018-10-11 06:30:03 -03:00
|
|
|
virtual void handle_param_value(const mavlink_message_t *msg) {}
|
2015-12-30 22:19:52 -04:00
|
|
|
|
2015-01-29 05:01:55 -04:00
|
|
|
// send a GIMBAL_REPORT message to the GCS
|
2018-10-11 06:30:03 -03:00
|
|
|
virtual void send_gimbal_report(const mavlink_channel_t chan) {}
|
2015-01-29 05:01:55 -04:00
|
|
|
|
2015-01-08 16:11:00 -04:00
|
|
|
protected:
|
2015-01-14 23:58:28 -04:00
|
|
|
|
2015-01-15 01:11:17 -04:00
|
|
|
// update_targets_from_rc - updates angle targets (i.e. _angle_ef_target_rad) using input from receiver
|
|
|
|
void update_targets_from_rc();
|
|
|
|
|
2019-04-04 07:50:00 -03:00
|
|
|
// angle_input_rad - convert RC input into an earth-frame target angle
|
2018-10-13 04:41:11 -03:00
|
|
|
float angle_input_rad(const RC_Channel* rc, int16_t angle_min, int16_t angle_max);
|
2015-01-15 01:11:17 -04:00
|
|
|
|
2015-01-14 23:58:28 -04:00
|
|
|
// calc_angle_to_location - calculates the earth-frame roll, tilt and pan angles (and radians) to point at the given target
|
2016-10-27 18:46:27 -03:00
|
|
|
void calc_angle_to_location(const struct Location &target, Vector3f& angles_to_target_rad, bool calc_tilt, bool calc_pan, bool relative_pan = true);
|
2015-01-14 23:58:28 -04:00
|
|
|
|
2015-01-29 02:23:16 -04:00
|
|
|
// get the mount mode from frontend
|
|
|
|
MAV_MOUNT_MODE get_mode(void) const { return _frontend.get_mode(_instance); }
|
|
|
|
|
2015-01-08 16:11:00 -04:00
|
|
|
AP_Mount &_frontend; // reference to the front end which holds parameters
|
2016-05-12 13:57:50 -03:00
|
|
|
AP_Mount::mount_state &_state; // references to the parameters and state for this backend
|
2015-01-08 16:11:00 -04:00
|
|
|
uint8_t _instance; // this instance's number
|
2015-03-20 17:53:22 -03:00
|
|
|
Vector3f _angle_ef_target_rad; // desired earth-frame roll, tilt and vehicle-relative pan angles in radians
|
2018-10-13 04:41:11 -03:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void rate_input_rad(float &out, const RC_Channel *ch, float min, float max) const;
|
2015-01-08 16:11:00 -04:00
|
|
|
};
|