2024-07-17 21:48:29 -03:00
|
|
|
#include "AP_Mount_config.h"
|
|
|
|
|
2020-07-24 14:01:21 -03:00
|
|
|
#if HAL_SOLO_GIMBAL_ENABLED
|
|
|
|
|
2024-07-17 21:48:29 -03:00
|
|
|
#include "AP_Mount_SoloGimbal.h"
|
|
|
|
|
2015-12-30 22:19:52 -04:00
|
|
|
#include "SoloGimbal.h"
|
2019-01-18 00:23:42 -04:00
|
|
|
#include <AP_Logger/AP_Logger.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
|
|
|
|
2022-08-30 08:15:10 -03:00
|
|
|
AP_Mount_SoloGimbal::AP_Mount_SoloGimbal(AP_Mount &frontend, AP_Mount_Params ¶ms, uint8_t instance) :
|
|
|
|
AP_Mount_Backend(frontend, params, instance),
|
2018-10-11 06:30:03 -03:00
|
|
|
_gimbal()
|
2015-01-30 02:39:31 -04:00
|
|
|
{}
|
|
|
|
|
2015-01-08 16:11:26 -04:00
|
|
|
// init - performs any required initialisation for this instance
|
2019-08-27 03:23:30 -03:00
|
|
|
void AP_Mount_SoloGimbal::init()
|
2015-01-08 16:11:26 -04:00
|
|
|
{
|
2015-02-01 05:34:12 -04:00
|
|
|
_initialised = true;
|
2023-04-20 05:22:59 -03:00
|
|
|
AP_Mount_Backend::init();
|
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
|
|
|
|
2023-12-29 03:10:52 -04:00
|
|
|
// change to RC_TARGETING mode if RC input has changed
|
|
|
|
set_rctargeting_on_rcinput_change();
|
|
|
|
|
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);
|
2023-07-21 03:35:42 -03:00
|
|
|
mnt_target.target_type = MountTargetType::ANGLE;
|
|
|
|
mnt_target.angle_rad.set(Vector3f{0,0,0}, false);
|
2015-01-15 01:13:59 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
// move mount to a neutral position, typically pointing forward
|
2022-06-23 00:39:24 -03:00
|
|
|
case MAV_MOUNT_MODE_NEUTRAL: {
|
2015-12-30 22:19:52 -04:00
|
|
|
_gimbal.set_lockedToBody(false);
|
2022-08-30 08:15:10 -03:00
|
|
|
const Vector3f &target = _params.neutral_angles.get();
|
2023-07-21 03:35:42 -03:00
|
|
|
mnt_target.target_type = MountTargetType::ANGLE;
|
|
|
|
mnt_target.angle_rad.set(target*DEG_TO_RAD, false);
|
2015-01-15 01:13:59 -04:00
|
|
|
break;
|
2022-06-23 00:39:24 -03:00
|
|
|
}
|
2015-01-15 01:13:59 -04:00
|
|
|
|
|
|
|
// point to the angles given by a mavlink message
|
|
|
|
case MAV_MOUNT_MODE_MAVLINK_TARGETING:
|
2023-07-21 03:35:42 -03:00
|
|
|
// targets are stored while handling the incoming mavlink message
|
2015-12-30 22:19:52 -04:00
|
|
|
_gimbal.set_lockedToBody(false);
|
2023-07-21 03:35:42 -03:00
|
|
|
if (mnt_target.target_type == MountTargetType::RATE) {
|
|
|
|
update_angle_target_from_rate(mnt_target.rate_rads, mnt_target.angle_rad);
|
2022-06-23 00:39:24 -03:00
|
|
|
}
|
2015-01-15 01:13:59 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
// RC radio manual angle control, but with stabilization from the AHRS
|
2024-11-08 23:47:30 -04:00
|
|
|
case MAV_MOUNT_MODE_RC_TARGETING:
|
2015-12-30 22:19:52 -04:00
|
|
|
_gimbal.set_lockedToBody(false);
|
2024-11-08 23:47:30 -04:00
|
|
|
update_mnt_target_from_rc_target();
|
2015-01-15 01:13:59 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
// point mount to a GPS point given by the mission planner
|
|
|
|
case MAV_MOUNT_MODE_GPS_POINT:
|
2023-07-21 03:35:42 -03:00
|
|
|
if (get_angle_target_to_roi(mnt_target.angle_rad)) {
|
|
|
|
mnt_target.target_type = MountTargetType::ANGLE;
|
|
|
|
_gimbal.set_lockedToBody(false);
|
|
|
|
}
|
2020-12-21 05:07:43 -04:00
|
|
|
break;
|
|
|
|
|
2023-07-21 03:35:42 -03:00
|
|
|
// point mount to Home location
|
2020-12-21 05:07:43 -04:00
|
|
|
case MAV_MOUNT_MODE_HOME_LOCATION:
|
2023-07-21 03:35:42 -03:00
|
|
|
if (get_angle_target_to_home(mnt_target.angle_rad)) {
|
|
|
|
mnt_target.target_type = MountTargetType::ANGLE;
|
|
|
|
_gimbal.set_lockedToBody(false);
|
|
|
|
}
|
2015-01-15 01:13:59 -04:00
|
|
|
break;
|
|
|
|
|
2023-07-21 03:35:42 -03:00
|
|
|
// point mount to another vehicle
|
2019-03-16 04:06:02 -03:00
|
|
|
case MAV_MOUNT_MODE_SYSID_TARGET:
|
2023-07-21 03:35:42 -03:00
|
|
|
if (get_angle_target_to_sysid(mnt_target.angle_rad)) {
|
|
|
|
mnt_target.target_type = MountTargetType::ANGLE;
|
|
|
|
_gimbal.set_lockedToBody(false);
|
|
|
|
}
|
2019-03-16 04:06:02 -03:00
|
|
|
break;
|
|
|
|
|
2015-01-15 01:13:59 -04:00
|
|
|
default:
|
|
|
|
// we do not know this mode so do nothing
|
|
|
|
break;
|
|
|
|
}
|
2015-01-08 16:11:26 -04:00
|
|
|
}
|
|
|
|
|
2022-07-11 05:07:22 -03:00
|
|
|
// get attitude as a quaternion. returns true on success
|
|
|
|
bool AP_Mount_SoloGimbal::get_attitude_quaternion(Quaternion& att_quat)
|
2015-01-08 16:11:26 -04:00
|
|
|
{
|
2022-07-11 05:07:22 -03:00
|
|
|
if (!_gimbal.aligned()) {
|
|
|
|
return false;
|
2015-12-30 22:19:52 -04:00
|
|
|
}
|
2023-07-21 03:35:42 -03:00
|
|
|
att_quat.from_euler(mnt_target.angle_rad.roll, mnt_target.angle_rad.pitch, mnt_target.angle_rad.get_bf_yaw());
|
2022-07-11 05:07:22 -03:00
|
|
|
return true;
|
2015-01-08 16:11:26 -04:00
|
|
|
}
|
|
|
|
|
2015-01-29 05:01:55 -04:00
|
|
|
/*
|
|
|
|
handle a GIMBAL_REPORT message
|
|
|
|
*/
|
2019-04-30 07:22:48 -03:00
|
|
|
void AP_Mount_SoloGimbal::handle_gimbal_report(mavlink_channel_t chan, const mavlink_message_t &msg)
|
2015-01-29 05:01:55 -04:00
|
|
|
{
|
2023-07-21 03:35:42 -03:00
|
|
|
_gimbal.update_target(Vector3f{mnt_target.angle_rad.roll, mnt_target.angle_rad.pitch, mnt_target.angle_rad.get_bf_yaw()});
|
2015-03-20 17:19:34 -03:00
|
|
|
_gimbal.receive_feedback(chan,msg);
|
2015-12-30 22:19:52 -04:00
|
|
|
|
2023-07-13 21:58:07 -03:00
|
|
|
#if HAL_LOGGING_ENABLED
|
2019-02-11 04:33:19 -04:00
|
|
|
AP_Logger *logger = AP_Logger::get_singleton();
|
|
|
|
if (logger == nullptr) {
|
2018-03-13 21:23:01 -03:00
|
|
|
return;
|
|
|
|
}
|
2023-07-13 21:58:07 -03:00
|
|
|
#endif
|
|
|
|
if(!_params_saved
|
|
|
|
#if HAL_LOGGING_ENABLED
|
|
|
|
&& logger->logging_started()
|
|
|
|
#endif
|
|
|
|
) {
|
2019-02-11 04:33:19 -04:00
|
|
|
_gimbal.fetch_params(); //last parameter save might not be stored in logger so retry
|
2015-12-30 22:19:52 -04:00
|
|
|
_params_saved = true;
|
|
|
|
}
|
|
|
|
|
2023-07-13 21:58:07 -03:00
|
|
|
#if HAL_LOGGING_ENABLED
|
2015-12-30 22:19:52 -04:00
|
|
|
if (_gimbal.get_log_dt() > 1.0f/25.0f) {
|
2018-03-13 21:23:01 -03:00
|
|
|
_gimbal.write_logs();
|
2015-12-30 22:19:52 -04:00
|
|
|
}
|
2023-07-13 21:58:07 -03:00
|
|
|
#endif
|
2015-12-30 22:19:52 -04:00
|
|
|
}
|
|
|
|
|
2019-04-30 07:22:48 -03:00
|
|
|
void AP_Mount_SoloGimbal::handle_param_value(const mavlink_message_t &msg)
|
2015-12-30 22:19:52 -04:00
|
|
|
{
|
2018-03-13 21:23:01 -03:00
|
|
|
_gimbal.handle_param_value(msg);
|
2015-12-30 22:19:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
handle a GIMBAL_REPORT message
|
|
|
|
*/
|
2019-04-30 07:22:48 -03:00
|
|
|
void AP_Mount_SoloGimbal::handle_gimbal_torque_report(mavlink_channel_t chan, const mavlink_message_t &msg)
|
2015-12-30 22:19:52 -04:00
|
|
|
{
|
|
|
|
_gimbal.disable_torque_report();
|
2015-02-16 01:48:55 -04:00
|
|
|
}
|
|
|
|
|
2020-07-24 14:01:21 -03:00
|
|
|
#endif // HAL_SOLO_GIMBAL_ENABLED
|