2015-12-30 22:19:52 -04:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
#include <AP_AHRS/AP_AHRS.h>
|
2015-01-30 02:39:31 -04:00
|
|
|
#if AP_AHRS_NAVEKF_AVAILABLE
|
2015-12-30 22:19:52 -04:00
|
|
|
|
|
|
|
#include "AP_Mount_SoloGimbal.h"
|
|
|
|
#include "SoloGimbal.h"
|
|
|
|
#include <DataFlash/DataFlash.h>
|
2015-08-11 03:28:44 -03:00
|
|
|
#include <GCS_MAVLink/GCS_MAVLink.h>
|
2016-05-11 23:39:57 -03:00
|
|
|
#include <GCS_MAVLink/GCS.h>
|
2015-01-08 16:11:26 -04:00
|
|
|
|
2015-12-30 22:19:52 -04:00
|
|
|
extern const AP_HAL::HAL& hal;
|
|
|
|
|
|
|
|
AP_Mount_SoloGimbal::AP_Mount_SoloGimbal(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-12-30 22:19:52 -04:00
|
|
|
_gimbal(frontend._ahrs)
|
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-12-30 22:19:52 -04:00
|
|
|
void AP_Mount_SoloGimbal::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
|
|
|
}
|
|
|
|
|
2015-12-30 22:19:52 -04:00
|
|
|
void AP_Mount_SoloGimbal::update_fast()
|
|
|
|
{
|
|
|
|
_gimbal.update_fast();
|
|
|
|
}
|
|
|
|
|
2015-01-08 16:11:26 -04:00
|
|
|
// update mount position - should be called periodically
|
2015-12-30 22:19:52 -04:00
|
|
|
void AP_Mount_SoloGimbal::update()
|
2015-01-08 16:11:26 -04:00
|
|
|
{
|
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:
|
2015-12-30 22:19:52 -04:00
|
|
|
_gimbal.set_lockedToBody(true);
|
2015-01-15 01:13:59 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
// move mount to a neutral position, typically pointing forward
|
|
|
|
case MAV_MOUNT_MODE_NEUTRAL:
|
2015-12-30 22:19:52 -04:00
|
|
|
{
|
|
|
|
_gimbal.set_lockedToBody(false);
|
|
|
|
const Vector3f &target = _state._neutral_angles.get();
|
|
|
|
_angle_ef_target_rad.x = ToRad(target.x);
|
|
|
|
_angle_ef_target_rad.y = ToRad(target.y);
|
|
|
|
_angle_ef_target_rad.z = ToRad(target.z);
|
|
|
|
}
|
2015-01-15 01:13:59 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
// point to the angles given by a mavlink message
|
|
|
|
case MAV_MOUNT_MODE_MAVLINK_TARGETING:
|
2015-12-30 22:19:52 -04:00
|
|
|
_gimbal.set_lockedToBody(false);
|
2015-01-15 01:13:59 -04:00
|
|
|
// 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:
|
2015-12-30 22:19:52 -04:00
|
|
|
_gimbal.set_lockedToBody(false);
|
2015-01-15 01:13:59 -04:00
|
|
|
// 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:
|
2015-12-30 22:19:52 -04:00
|
|
|
_gimbal.set_lockedToBody(false);
|
2015-01-15 01:13:59 -04:00
|
|
|
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)
|
2015-12-30 22:19:52 -04:00
|
|
|
bool AP_Mount_SoloGimbal::has_pan_control() const
|
2015-01-08 16:11:26 -04:00
|
|
|
{
|
|
|
|
// we do not have yaw control
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set_mode - sets mount's mode
|
2015-12-30 22:19:52 -04:00
|
|
|
void AP_Mount_SoloGimbal::set_mode(enum MAV_MOUNT_MODE mode)
|
2015-01-08 16:11:26 -04:00
|
|
|
{
|
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
|
2015-12-30 22:19:52 -04:00
|
|
|
void AP_Mount_SoloGimbal::status_msg(mavlink_channel_t chan)
|
2015-01-08 16:11:26 -04:00
|
|
|
{
|
2015-12-30 22:19:52 -04:00
|
|
|
if (_gimbal.aligned()) {
|
|
|
|
mavlink_msg_mount_status_send(chan, 0, 0, degrees(_angle_ef_target_rad.y)*100, degrees(_angle_ef_target_rad.x)*100, degrees(_angle_ef_target_rad.z)*100);
|
|
|
|
}
|
2016-05-11 23:39:57 -03:00
|
|
|
|
|
|
|
// block heartbeat from transmitting to the GCS
|
|
|
|
GCS_MAVLINK::disable_channel_routing(chan);
|
2015-01-08 16:11:26 -04:00
|
|
|
}
|
|
|
|
|
2015-01-29 05:01:55 -04:00
|
|
|
/*
|
|
|
|
handle a GIMBAL_REPORT message
|
|
|
|
*/
|
2015-12-30 22:19:52 -04:00
|
|
|
void AP_Mount_SoloGimbal::handle_gimbal_report(mavlink_channel_t chan, mavlink_message_t *msg)
|
2015-01-29 05:01:55 -04:00
|
|
|
{
|
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-12-30 22:19:52 -04:00
|
|
|
|
2016-10-30 02:24:21 -03:00
|
|
|
if(!_params_saved && _frontend._dataflash != nullptr && _frontend._dataflash->logging_started()) {
|
2015-12-30 22:19:52 -04:00
|
|
|
_gimbal.fetch_params(); //last parameter save might not be stored in dataflash so retry
|
|
|
|
_params_saved = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_gimbal.get_log_dt() > 1.0f/25.0f) {
|
|
|
|
_gimbal.write_logs(_frontend._dataflash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AP_Mount_SoloGimbal::handle_param_value(mavlink_message_t *msg)
|
|
|
|
{
|
|
|
|
_gimbal.handle_param_value(_frontend._dataflash, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
handle a GIMBAL_REPORT message
|
|
|
|
*/
|
|
|
|
void AP_Mount_SoloGimbal::handle_gimbal_torque_report(mavlink_channel_t chan, mavlink_message_t *msg)
|
|
|
|
{
|
|
|
|
_gimbal.disable_torque_report();
|
2015-02-16 01:48:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
send a GIMBAL_REPORT message to the GCS
|
|
|
|
*/
|
2015-12-30 22:19:52 -04:00
|
|
|
void AP_Mount_SoloGimbal::send_gimbal_report(mavlink_channel_t chan)
|
2015-02-16 01:48:55 -04:00
|
|
|
{
|
2015-01-29 05:01:55 -04:00
|
|
|
}
|
2015-01-30 02:39:31 -04:00
|
|
|
|
|
|
|
#endif // AP_AHRS_NAVEKF_AVAILABLE
|