2015-01-08 16:11:26 -04:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
2015-08-11 03:28:44 -03:00
|
|
|
#include "AP_Mount_MAVLink.h"
|
2015-01-30 02:39:31 -04:00
|
|
|
#if AP_AHRS_NAVEKF_AVAILABLE
|
2015-08-11 03:28:44 -03:00
|
|
|
#include <GCS_MAVLink/GCS_MAVLink.h>
|
2015-03-20 17:19:34 -03:00
|
|
|
#include <stdio.h>
|
2015-08-11 03:28:44 -03:00
|
|
|
#include "AP_Gimbal.h"
|
2015-01-08 16:11:26 -04:00
|
|
|
|
2015-01-30 02:39:31 -04:00
|
|
|
#if MOUNT_DEBUG
|
|
|
|
#include <stdio.h>
|
|
|
|
#endif
|
|
|
|
|
2015-02-01 05:34:12 -04:00
|
|
|
AP_Mount_MAVLink::AP_Mount_MAVLink(AP_Mount &frontend, AP_Mount::mount_state &state, uint8_t instance) :
|
2015-01-30 02:39:31 -04:00
|
|
|
AP_Mount_Backend(frontend, state, instance),
|
2015-03-20 17:19:34 -03:00
|
|
|
_initialised(false),
|
2015-04-20 03:59:49 -03:00
|
|
|
_gimbal(frontend._ahrs, MAV_COMP_ID_GIMBAL, _state._gimbalParams)
|
2015-01-30 02:39:31 -04:00
|
|
|
{}
|
|
|
|
|
2015-01-08 16:11:26 -04:00
|
|
|
// init - performs any required initialisation for this instance
|
2015-01-19 09:39:13 -04:00
|
|
|
void AP_Mount_MAVLink::init(const AP_SerialManager& serial_manager)
|
2015-01-08 16:11:26 -04:00
|
|
|
{
|
2015-02-01 05:34:12 -04:00
|
|
|
_initialised = true;
|
|
|
|
set_mode((enum MAV_MOUNT_MODE)_state._default_mode.get());
|
2015-01-08 16:11:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// update mount position - should be called periodically
|
|
|
|
void AP_Mount_MAVLink::update()
|
|
|
|
{
|
2015-01-19 09:39:13 -04:00
|
|
|
// exit immediately if not initialised
|
|
|
|
if (!_initialised) {
|
|
|
|
return;
|
|
|
|
}
|
2015-01-15 01:13:59 -04:00
|
|
|
|
|
|
|
// update based on mount mode
|
2015-01-29 02:23:16 -04:00
|
|
|
switch(get_mode()) {
|
2015-01-15 01:13:59 -04:00
|
|
|
// move mount to a "retracted" position. we do not implement a separate servo based retract mechanism
|
|
|
|
case MAV_MOUNT_MODE_RETRACT:
|
|
|
|
break;
|
|
|
|
|
|
|
|
// move mount to a neutral position, typically pointing forward
|
|
|
|
case MAV_MOUNT_MODE_NEUTRAL:
|
|
|
|
break;
|
|
|
|
|
|
|
|
// point to the angles given by a mavlink message
|
|
|
|
case MAV_MOUNT_MODE_MAVLINK_TARGETING:
|
|
|
|
// do nothing because earth-frame angle targets (i.e. _angle_ef_target_rad) should have already been set by a MOUNT_CONTROL message from GCS
|
|
|
|
break;
|
|
|
|
|
|
|
|
// RC radio manual angle control, but with stabilization from the AHRS
|
|
|
|
case MAV_MOUNT_MODE_RC_TARGETING:
|
|
|
|
// update targets using pilot's rc inputs
|
|
|
|
update_targets_from_rc();
|
|
|
|
break;
|
|
|
|
|
|
|
|
// point mount to a GPS point given by the mission planner
|
|
|
|
case MAV_MOUNT_MODE_GPS_POINT:
|
|
|
|
if(_frontend._ahrs.get_gps().status() >= AP_GPS::GPS_OK_FIX_2D) {
|
2015-02-01 06:05:41 -04:00
|
|
|
calc_angle_to_location(_state._roi_target, _angle_ef_target_rad, true, true);
|
2015-01-15 01:13:59 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// we do not know this mode so do nothing
|
|
|
|
break;
|
|
|
|
}
|
2015-01-08 16:11:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// has_pan_control - returns true if this mount can control it's pan (required for multicopters)
|
|
|
|
bool AP_Mount_MAVLink::has_pan_control() const
|
|
|
|
{
|
|
|
|
// we do not have yaw control
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set_mode - sets mount's mode
|
|
|
|
void AP_Mount_MAVLink::set_mode(enum MAV_MOUNT_MODE mode)
|
|
|
|
{
|
2015-01-19 09:39:13 -04:00
|
|
|
// exit immediately if not initialised
|
|
|
|
if (!_initialised) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-08 16:11:26 -04:00
|
|
|
// record the mode change
|
2015-01-18 21:40:40 -04:00
|
|
|
_state._mode = mode;
|
2015-01-08 16:11:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// status_msg - called to allow mounts to send their status to GCS using the MOUNT_STATUS message
|
|
|
|
void AP_Mount_MAVLink::status_msg(mavlink_channel_t chan)
|
|
|
|
{
|
2015-04-01 20:39:09 -03:00
|
|
|
Vector3f est = _gimbal.getGimbalEstimateEF();
|
|
|
|
mavlink_msg_mount_status_send(chan, 0, 0, degrees(est.y)*100, degrees(est.x)*100, degrees(est.z)*100);
|
2015-01-08 16:11:26 -04:00
|
|
|
}
|
|
|
|
|
2015-01-29 05:01:55 -04:00
|
|
|
/*
|
|
|
|
handle a GIMBAL_REPORT message
|
|
|
|
*/
|
|
|
|
void AP_Mount_MAVLink::handle_gimbal_report(mavlink_channel_t chan, mavlink_message_t *msg)
|
|
|
|
{
|
2015-03-20 17:43:51 -03:00
|
|
|
_gimbal.update_target(_angle_ef_target_rad);
|
2015-03-20 17:19:34 -03:00
|
|
|
_gimbal.receive_feedback(chan,msg);
|
2015-02-16 01:48:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
send a GIMBAL_REPORT message to the GCS
|
|
|
|
*/
|
|
|
|
void AP_Mount_MAVLink::send_gimbal_report(mavlink_channel_t chan)
|
|
|
|
{
|
2015-05-23 05:39:12 -03:00
|
|
|
_gimbal.send_report(chan);
|
2015-01-29 05:01:55 -04:00
|
|
|
}
|
2015-01-30 02:39:31 -04:00
|
|
|
|
|
|
|
#endif // AP_AHRS_NAVEKF_AVAILABLE
|