2015-01-08 16:11:12 -04:00
|
|
|
/*
|
|
|
|
Servo controlled mount backend class
|
|
|
|
*/
|
2016-02-17 21:25:38 -04:00
|
|
|
#pragma once
|
2015-01-08 16:11:12 -04:00
|
|
|
|
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 <AP_AHRS/AP_AHRS.h>
|
|
|
|
#include <GCS_MAVLink/GCS_MAVLink.h>
|
2017-01-05 01:13:02 -04:00
|
|
|
#include <SRV_Channel/SRV_Channel.h>
|
2015-01-08 16:11:12 -04:00
|
|
|
#include "AP_Mount_Backend.h"
|
|
|
|
|
|
|
|
class AP_Mount_Servo : public AP_Mount_Backend
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Constructor
|
2015-02-01 05:32:25 -04:00
|
|
|
AP_Mount_Servo(AP_Mount &frontend, AP_Mount::mount_state &state, uint8_t instance):
|
2015-01-18 21:40:27 -04:00
|
|
|
AP_Mount_Backend(frontend, state, instance),
|
2017-01-05 01:13:02 -04:00
|
|
|
_roll_idx(SRV_Channel::k_none),
|
|
|
|
_tilt_idx(SRV_Channel::k_none),
|
|
|
|
_pan_idx(SRV_Channel::k_none),
|
2018-07-23 00:47:53 -03:00
|
|
|
_open_idx(SRV_Channel::k_none)
|
2015-01-08 16:11:12 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// init - performs any required initialisation for this instance
|
2015-01-19 09:38:32 -04:00
|
|
|
virtual void init(const AP_SerialManager& serial_manager);
|
2015-01-08 16:11:12 -04:00
|
|
|
|
|
|
|
// update mount position - should be called periodically
|
|
|
|
virtual void update();
|
|
|
|
|
|
|
|
// has_pan_control - returns true if this mount can control it's pan (required for multicopters)
|
|
|
|
virtual bool has_pan_control() const { return _flags.pan_control; }
|
|
|
|
|
2015-01-12 07:41:48 -04:00
|
|
|
// set_mode - sets mount's mode
|
|
|
|
virtual void set_mode(enum MAV_MOUNT_MODE mode);
|
|
|
|
|
2015-01-08 16:11:12 -04:00
|
|
|
// status_msg - called to allow mounts to send their status to GCS using the MOUNT_STATUS message
|
|
|
|
virtual void status_msg(mavlink_channel_t chan);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// flags structure
|
|
|
|
struct {
|
|
|
|
bool roll_control :1; // true if mount has roll control
|
|
|
|
bool tilt_control :1; // true if mount has tilt control
|
|
|
|
bool pan_control :1; // true if mount has pan control
|
|
|
|
} _flags;
|
|
|
|
|
2017-01-05 01:13:02 -04:00
|
|
|
// check_servo_map - detects which axis we control (i.e. _flags) using the functions assigned to the servos in the SRV_Channel
|
2015-01-08 16:11:12 -04:00
|
|
|
// should be called periodically (i.e. 1hz or less)
|
|
|
|
void check_servo_map();
|
|
|
|
|
|
|
|
// stabilize - stabilizes the mount relative to the Earth's frame
|
|
|
|
void stabilize();
|
|
|
|
|
|
|
|
// closest_limit - returns closest angle to 'angle' taking into account limits. all angles are in degrees * 10
|
|
|
|
int16_t closest_limit(int16_t angle, int16_t angle_min, int16_t angle_max);
|
|
|
|
|
|
|
|
/// move_servo - moves servo with the given id to the specified angle. all angles are in degrees * 10
|
|
|
|
void move_servo(uint8_t rc, int16_t angle, int16_t angle_min, int16_t angle_max);
|
|
|
|
|
2017-01-05 01:13:02 -04:00
|
|
|
// SRV_Channel - different id numbers are used depending upon the instance number
|
|
|
|
SRV_Channel::Aux_servo_function_t _roll_idx; // SRV_Channel mount roll function index
|
|
|
|
SRV_Channel::Aux_servo_function_t _tilt_idx; // SRV_Channel mount tilt function index
|
|
|
|
SRV_Channel::Aux_servo_function_t _pan_idx; // SRV_Channel mount pan function index
|
|
|
|
SRV_Channel::Aux_servo_function_t _open_idx; // SRV_Channel mount open function index
|
2015-01-08 16:11:12 -04:00
|
|
|
|
2015-01-15 01:11:17 -04:00
|
|
|
Vector3f _angle_bf_output_deg; // final body frame output angle in degrees
|
2015-01-12 07:51:56 -04:00
|
|
|
|
|
|
|
uint32_t _last_check_servo_map_ms; // system time of latest call to check_servo_map function
|
2015-01-08 16:11:12 -04:00
|
|
|
};
|