2015-05-12 01:58:56 -03: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/>.
|
|
|
|
*/
|
2016-05-05 19:10:08 -03:00
|
|
|
/*
|
2015-05-12 01:58:56 -03:00
|
|
|
main Rover class, containing all vehicle specific state
|
|
|
|
*/
|
2016-02-17 21:25:59 -04:00
|
|
|
#pragma once
|
2015-05-13 00:16:45 -03:00
|
|
|
|
2016-03-31 18:43:36 -03:00
|
|
|
#include <cmath>
|
2015-05-12 04:00:25 -03:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
// Libraries
|
2015-08-11 03:28:40 -03:00
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2017-08-11 22:28:00 -03:00
|
|
|
#include <AC_PID/AC_P.h>
|
|
|
|
#include <AC_PID/AC_PID.h>
|
|
|
|
#include <AP_AccelCal/AP_AccelCal.h> // interface and maths for accelerometer calibration
|
2016-12-20 09:30:57 -04:00
|
|
|
#include <AP_ADC/AP_ADC.h> // ArduPilot Mega Analog to Digital Converter Library
|
2017-08-11 22:28:00 -03:00
|
|
|
#include <AP_AHRS/AP_AHRS.h> // ArduPilot Mega DCM Library
|
|
|
|
#include <AP_Airspeed/AP_Airspeed.h> // needed for AHRS build
|
2015-08-11 03:28:40 -03:00
|
|
|
#include <AP_Baro/AP_Baro.h>
|
2017-08-11 22:28:00 -03:00
|
|
|
#include <AP_BattMonitor/AP_BattMonitor.h> // Battery monitor library
|
|
|
|
#include <AP_Beacon/AP_Beacon.h>
|
|
|
|
#include <AP_BoardConfig/AP_BoardConfig.h>
|
|
|
|
#include <AP_BoardConfig/AP_BoardConfig_CAN.h>
|
|
|
|
#include <AP_Buffer/AP_Buffer.h> // FIFO buffer library
|
|
|
|
#include <AP_Button/AP_Button.h>
|
|
|
|
#include <AP_Camera/AP_Camera.h> // Camera triggering
|
2016-12-20 09:30:57 -04:00
|
|
|
#include <AP_Compass/AP_Compass.h> // ArduPilot Mega Magnetometer Library
|
2017-08-11 22:28:00 -03:00
|
|
|
#include <AP_Declination/AP_Declination.h> // Compass declination library
|
|
|
|
#include <AP_Frsky_Telem/AP_Frsky_Telem.h>
|
|
|
|
#include <AP_GPS/AP_GPS.h> // ArduPilot GPS library
|
2016-12-20 09:30:57 -04:00
|
|
|
#include <AP_InertialSensor/AP_InertialSensor.h> // Inertial Sensor (uncalibated IMU) Library
|
2017-08-11 22:28:00 -03:00
|
|
|
#include <AP_L1_Control/AP_L1_Control.h>
|
|
|
|
#include <AP_Math/AP_Math.h> // ArduPilot Mega Vector/Matrix math Library
|
|
|
|
#include <AP_Menu/AP_Menu.h>
|
|
|
|
#include <AP_Mission/AP_Mission.h> // Mission command library
|
|
|
|
#include <AP_Mount/AP_Mount.h> // Camera/Antenna mount
|
2015-09-21 02:27:49 -03:00
|
|
|
#include <AP_NavEKF2/AP_NavEKF2.h>
|
2016-11-28 05:49:35 -04:00
|
|
|
#include <AP_NavEKF3/AP_NavEKF3.h>
|
2017-08-11 22:28:00 -03:00
|
|
|
#include <AP_Navigation/AP_Navigation.h>
|
|
|
|
#include <AP_Notify/AP_Notify.h> // Notify library
|
|
|
|
#include <AP_OpticalFlow/AP_OpticalFlow.h> // Optical Flow library
|
|
|
|
#include <AP_Param/AP_Param.h>
|
2015-08-11 03:28:40 -03:00
|
|
|
#include <AP_Rally/AP_Rally.h>
|
2016-12-20 09:30:57 -04:00
|
|
|
#include <AP_RangeFinder/AP_RangeFinder.h> // Range finder library
|
2017-08-11 22:28:00 -03:00
|
|
|
#include <AP_RCMapper/AP_RCMapper.h> // RC input mapping library
|
2016-12-20 09:30:57 -04:00
|
|
|
#include <AP_Relay/AP_Relay.h> // APM relay
|
2017-08-11 22:28:00 -03:00
|
|
|
#include <AP_RSSI/AP_RSSI.h> // RSSI Library
|
|
|
|
#include <AP_Scheduler/AP_Scheduler.h> // main loop scheduler
|
2016-12-20 09:30:57 -04:00
|
|
|
#include <AP_SerialManager/AP_SerialManager.h> // Serial manager library
|
2017-08-11 22:28:00 -03:00
|
|
|
#include <AP_ServoRelayEvents/AP_ServoRelayEvents.h>
|
|
|
|
#include <AP_Stats/AP_Stats.h> // statistics library
|
|
|
|
#include <AP_Terrain/AP_Terrain.h>
|
2016-12-20 09:30:57 -04:00
|
|
|
#include <AP_Vehicle/AP_Vehicle.h> // needed for AHRS build
|
2017-08-11 22:28:00 -03:00
|
|
|
#include <AP_VisualOdom/AP_VisualOdom.h>
|
|
|
|
#include <AP_WheelEncoder/AP_WheelEncoder.h>
|
2017-08-08 02:37:21 -03:00
|
|
|
#include <APM_Control/AR_AttitudeControl.h>
|
2017-11-29 21:58:11 -04:00
|
|
|
#include <AP_SmartRTL/AP_SmartRTL.h>
|
2017-08-11 22:28:00 -03:00
|
|
|
#include <DataFlash/DataFlash.h>
|
|
|
|
#include <Filter/AverageFilter.h> // Mode Filter from Filter library
|
|
|
|
#include <Filter/Butter.h> // Filter library - butterworth filter
|
|
|
|
#include <Filter/Filter.h> // Filter library
|
2017-08-22 08:53:36 -03:00
|
|
|
#include <Filter/LowPassFilter.h>
|
2017-08-11 22:28:00 -03:00
|
|
|
#include <Filter/ModeFilter.h> // Mode Filter from Filter library
|
|
|
|
#include <RC_Channel/RC_Channel.h> // RC Channel Library
|
|
|
|
#include <StorageManager/StorageManager.h>
|
2017-08-16 07:02:56 -03:00
|
|
|
#include <AC_Fence/AC_Fence.h>
|
2017-08-16 07:57:42 -03:00
|
|
|
#include <AP_Proximity/AP_Proximity.h>
|
2017-12-12 02:12:16 -04:00
|
|
|
#include <AC_Avoidance/AC_Avoid.h>
|
2017-08-11 22:28:00 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
|
|
|
#include <SITL/SITL.h>
|
|
|
|
#endif
|
2015-08-11 03:28:40 -03:00
|
|
|
|
2017-08-11 22:28:00 -03:00
|
|
|
// Local modules
|
|
|
|
#include "AP_MotorsUGV.h"
|
2017-07-18 23:19:08 -03:00
|
|
|
#include "mode.h"
|
2016-08-17 01:28:16 -03:00
|
|
|
#include "AP_Arming.h"
|
2015-05-12 04:00:25 -03:00
|
|
|
// Configuration
|
|
|
|
#include "config.h"
|
|
|
|
#include "defines.h"
|
2017-01-30 10:21:55 -04:00
|
|
|
#if ADVANCED_FAILSAFE == ENABLED
|
|
|
|
#include "afs_rover.h"
|
|
|
|
#endif
|
2015-05-12 04:00:25 -03:00
|
|
|
#include "Parameters.h"
|
2016-05-27 10:04:55 -03:00
|
|
|
#include "GCS_Mavlink.h"
|
2017-02-13 07:00:19 -04:00
|
|
|
#include "GCS_Rover.h"
|
2015-05-12 04:00:25 -03:00
|
|
|
|
2015-10-19 15:32:24 -03:00
|
|
|
class Rover : public AP_HAL::HAL::Callbacks {
|
2015-05-12 01:58:56 -03:00
|
|
|
public:
|
2016-05-27 10:04:55 -03:00
|
|
|
friend class GCS_MAVLINK_Rover;
|
2015-05-12 04:00:25 -03:00
|
|
|
friend class Parameters;
|
2017-01-06 06:31:10 -04:00
|
|
|
friend class ParametersG2;
|
2016-08-17 01:28:16 -03:00
|
|
|
friend class AP_Arming_Rover;
|
2017-01-30 10:21:55 -04:00
|
|
|
#if ADVANCED_FAILSAFE == ENABLED
|
|
|
|
friend class AP_AdvancedFailsafe_Rover;
|
|
|
|
#endif
|
2017-02-13 07:00:19 -04:00
|
|
|
friend class GCS_Rover;
|
2017-07-18 23:19:08 -03:00
|
|
|
friend class Mode;
|
2017-11-28 02:59:13 -04:00
|
|
|
friend class ModeAcro;
|
2017-07-18 23:19:08 -03:00
|
|
|
friend class ModeAuto;
|
|
|
|
friend class ModeGuided;
|
|
|
|
friend class ModeHold;
|
|
|
|
friend class ModeSteering;
|
|
|
|
friend class ModeManual;
|
|
|
|
friend class ModeRTL;
|
2017-11-29 21:58:11 -04:00
|
|
|
friend class ModeSmartRTL;
|
2015-05-12 04:00:25 -03:00
|
|
|
|
2015-05-12 01:58:56 -03:00
|
|
|
Rover(void);
|
2015-05-12 04:00:25 -03:00
|
|
|
|
2015-10-19 15:32:24 -03:00
|
|
|
// HAL::Callbacks implementation.
|
|
|
|
void setup(void) override;
|
|
|
|
void loop(void) override;
|
2015-05-12 01:58:56 -03:00
|
|
|
|
|
|
|
private:
|
2017-09-12 15:25:20 -03:00
|
|
|
static const AP_FWVersion fwver;
|
2017-08-19 07:04:56 -03:00
|
|
|
|
2015-05-12 01:58:56 -03:00
|
|
|
// must be the first AP_Param variable declared to ensure its
|
|
|
|
// constructor runs before the constructors of the other AP_Param
|
|
|
|
// variables
|
|
|
|
AP_Param param_loader;
|
|
|
|
|
|
|
|
// all settable parameters
|
|
|
|
Parameters g;
|
2016-10-25 22:37:08 -03:00
|
|
|
ParametersG2 g2;
|
2015-05-12 01:58:56 -03:00
|
|
|
|
|
|
|
// main loop scheduler
|
2017-12-12 21:06:15 -04:00
|
|
|
AP_Scheduler scheduler;
|
2015-05-12 01:58:56 -03:00
|
|
|
|
|
|
|
// mapping between input channels
|
2017-12-12 21:06:15 -04:00
|
|
|
RCMapper rcmap;
|
2015-05-12 01:58:56 -03:00
|
|
|
|
|
|
|
// board specific config
|
2017-12-12 21:06:15 -04:00
|
|
|
AP_BoardConfig BoardConfig;
|
2015-05-12 01:58:56 -03:00
|
|
|
|
2017-05-06 06:11:40 -03:00
|
|
|
#if HAL_WITH_UAVCAN
|
|
|
|
// board specific config for CAN bus
|
2017-12-12 21:06:15 -04:00
|
|
|
AP_BoardConfig_CAN BoardConfig_CAN;
|
2017-05-06 06:11:40 -03:00
|
|
|
#endif
|
|
|
|
|
2015-05-12 01:58:56 -03:00
|
|
|
// primary control channels
|
|
|
|
RC_Channel *channel_steer;
|
|
|
|
RC_Channel *channel_throttle;
|
2017-08-22 04:06:23 -03:00
|
|
|
RC_Channel *channel_aux;
|
2015-05-12 01:58:56 -03:00
|
|
|
|
2016-05-05 19:10:08 -03:00
|
|
|
DataFlash_Class DataFlash;
|
2015-05-12 01:58:56 -03:00
|
|
|
|
|
|
|
// sensor drivers
|
2017-12-12 21:06:15 -04:00
|
|
|
AP_GPS gps;
|
|
|
|
AP_Baro barometer;
|
|
|
|
Compass compass;
|
|
|
|
AP_InertialSensor ins;
|
|
|
|
RangeFinder rangefinder{serial_manager, ROTATION_NONE};
|
2016-07-21 22:24:35 -03:00
|
|
|
AP_Button button;
|
2015-05-12 01:58:56 -03:00
|
|
|
|
|
|
|
// flight modes convenience array
|
2016-12-20 09:30:57 -04:00
|
|
|
AP_Int8 *modes;
|
2015-05-12 01:58:56 -03:00
|
|
|
|
2016-12-20 09:30:57 -04:00
|
|
|
// Inertial Navigation EKF
|
2015-05-12 01:58:56 -03:00
|
|
|
#if AP_AHRS_NAVEKF_AVAILABLE
|
2017-12-12 21:06:15 -04:00
|
|
|
NavEKF2 EKF2{&ahrs, barometer, rangefinder};
|
|
|
|
NavEKF3 EKF3{&ahrs, barometer, rangefinder};
|
2017-12-01 20:28:38 -04:00
|
|
|
AP_AHRS_NavEKF ahrs{ins, barometer, EKF2, EKF3};
|
2015-05-12 01:58:56 -03:00
|
|
|
#else
|
2017-12-01 20:28:38 -04:00
|
|
|
AP_AHRS_DCM ahrs{ins, barometer};
|
2015-05-12 01:58:56 -03:00
|
|
|
#endif
|
|
|
|
|
2016-12-20 09:30:57 -04:00
|
|
|
// Arming/Disarming management class
|
2017-08-16 07:02:56 -03:00
|
|
|
AP_Arming_Rover arming{ahrs, barometer, compass, battery, g2.fence};
|
2015-10-30 02:56:41 -03:00
|
|
|
|
2017-12-12 21:06:15 -04:00
|
|
|
AP_L1_Control L1_controller{ahrs, nullptr};
|
2015-05-12 01:58:56 -03:00
|
|
|
|
|
|
|
// selected navigation controller
|
|
|
|
AP_Navigation *nav_controller;
|
|
|
|
|
|
|
|
// Mission library
|
2017-12-12 21:06:15 -04:00
|
|
|
AP_Mission mission{ahrs,
|
2017-08-28 18:31:45 -03:00
|
|
|
FUNCTOR_BIND_MEMBER(&Rover::start_command, bool, const AP_Mission::Mission_Command&),
|
|
|
|
FUNCTOR_BIND_MEMBER(&Rover::verify_command_callback, bool, const AP_Mission::Mission_Command&),
|
2017-12-12 21:06:15 -04:00
|
|
|
FUNCTOR_BIND_MEMBER(&Rover::exit_mission, void)};
|
2015-05-12 01:58:56 -03:00
|
|
|
|
2015-12-21 20:35:31 -04:00
|
|
|
#if AP_AHRS_NAVEKF_AVAILABLE
|
2017-12-12 21:06:15 -04:00
|
|
|
OpticalFlow optflow{ahrs};
|
2015-12-21 20:35:31 -04:00
|
|
|
#endif
|
2016-12-20 09:30:57 -04:00
|
|
|
|
|
|
|
// RSSI
|
2017-12-12 21:06:15 -04:00
|
|
|
AP_RSSI rssi;
|
2015-05-12 01:58:56 -03:00
|
|
|
|
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
2015-10-22 10:04:42 -03:00
|
|
|
SITL::SITL sitl;
|
2015-05-12 01:58:56 -03:00
|
|
|
#endif
|
|
|
|
|
2017-12-12 21:06:15 -04:00
|
|
|
AP_SerialManager serial_manager;
|
2017-08-28 19:03:27 -03:00
|
|
|
|
2015-05-12 01:58:56 -03:00
|
|
|
// GCS handling
|
2017-02-13 07:00:19 -04:00
|
|
|
GCS_Rover _gcs; // avoid using this; use gcs()
|
|
|
|
GCS_Rover &gcs() { return _gcs; }
|
2015-05-12 01:58:56 -03:00
|
|
|
|
|
|
|
// relay support
|
2017-12-12 21:06:15 -04:00
|
|
|
AP_Relay relay;
|
2015-05-12 01:58:56 -03:00
|
|
|
|
2017-12-12 21:06:15 -04:00
|
|
|
AP_ServoRelayEvents ServoRelayEvents{relay};
|
2015-05-12 01:58:56 -03:00
|
|
|
|
2017-08-29 15:49:08 -03:00
|
|
|
// The rover's current location
|
|
|
|
struct Location current_loc;
|
|
|
|
|
2015-05-12 01:58:56 -03:00
|
|
|
// Camera
|
|
|
|
#if CAMERA == ENABLED
|
2017-12-12 21:06:15 -04:00
|
|
|
AP_Camera camera{&relay, MASK_LOG_CAMERA, current_loc, ahrs};
|
2015-05-12 01:58:56 -03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Camera/Antenna mount tracking and stabilisation stuff
|
|
|
|
#if MOUNT == ENABLED
|
2016-12-20 09:30:57 -04:00
|
|
|
// current_loc uses the baro/gps solution for altitude rather than gps only.
|
2017-12-12 21:06:15 -04:00
|
|
|
AP_Mount camera_mount{ahrs, current_loc};
|
2015-05-12 01:58:56 -03:00
|
|
|
#endif
|
|
|
|
|
2017-06-27 23:32:01 -03:00
|
|
|
// true if initialisation has completed
|
|
|
|
bool initialised;
|
|
|
|
|
2015-05-12 01:58:56 -03:00
|
|
|
// if USB is connected
|
|
|
|
bool usb_connected;
|
|
|
|
|
|
|
|
// This is the state of the flight control system
|
2017-07-18 23:19:08 -03:00
|
|
|
// There are multiple states defined such as MANUAL, AUTO, ...
|
|
|
|
Mode *control_mode;
|
2017-07-24 14:05:59 -03:00
|
|
|
mode_reason_t control_mode_reason = MODE_REASON_INITIALISED;
|
2015-05-12 01:58:56 -03:00
|
|
|
|
|
|
|
// Used to maintain the state of the previous control switch position
|
|
|
|
// This is set to -1 when we need to re-read the switch
|
|
|
|
uint8_t oldSwitchPosition;
|
|
|
|
|
|
|
|
// These are values received from the GCS if the user is using GCS joystick
|
|
|
|
// control and are substituted for the values coming from the RC radio
|
|
|
|
int16_t rc_override[8];
|
|
|
|
|
|
|
|
// A flag if GCS joystick control is in use
|
|
|
|
bool rc_override_active;
|
|
|
|
|
|
|
|
// Failsafe
|
|
|
|
// A tracking variable for type of failsafe active
|
2016-12-20 09:30:57 -04:00
|
|
|
// Used for failsafe based on loss of RC signal or GCS signal. See
|
2015-05-12 01:58:56 -03:00
|
|
|
// FAILSAFE_EVENT_*
|
2015-05-12 04:00:25 -03:00
|
|
|
struct {
|
2015-05-12 01:58:56 -03:00
|
|
|
uint8_t bits;
|
|
|
|
uint32_t rc_override_timer;
|
|
|
|
uint32_t start_time;
|
|
|
|
uint8_t triggered;
|
|
|
|
uint32_t last_valid_rc_ms;
|
|
|
|
} failsafe;
|
|
|
|
|
|
|
|
// notification object for LEDs, buzzers etc (parameter set to false disables external leds)
|
2017-12-12 21:06:15 -04:00
|
|
|
AP_Notify notify;
|
2015-05-12 01:58:56 -03:00
|
|
|
|
|
|
|
// true if we have a position estimate from AHRS
|
|
|
|
bool have_position;
|
|
|
|
|
|
|
|
// receiver RSSI
|
|
|
|
uint8_t receiver_rssi;
|
|
|
|
|
|
|
|
// the time when the last HEARTBEAT message arrived from a GCS
|
|
|
|
uint32_t last_heartbeat_ms;
|
|
|
|
|
|
|
|
// obstacle detection information
|
|
|
|
struct {
|
|
|
|
// have we detected an obstacle?
|
|
|
|
uint8_t detected_count;
|
|
|
|
float turn_angle;
|
2017-07-13 08:36:44 -03:00
|
|
|
uint16_t rangefinder1_distance_cm;
|
|
|
|
uint16_t rangefinder2_distance_cm;
|
2016-12-20 09:30:57 -04:00
|
|
|
|
2015-05-12 01:58:56 -03:00
|
|
|
// time when we last detected an obstacle, in milliseconds
|
|
|
|
uint32_t detected_time_ms;
|
|
|
|
} obstacle;
|
|
|
|
|
|
|
|
// Ground speed
|
|
|
|
// The amount current ground speed is below min ground speed. meters per second
|
2016-12-20 09:30:57 -04:00
|
|
|
float ground_speed;
|
2015-05-12 01:58:56 -03:00
|
|
|
|
2017-08-22 04:06:23 -03:00
|
|
|
// CH7 auxiliary switches last known position
|
|
|
|
aux_switch_pos aux_ch7;
|
2015-05-12 01:58:56 -03:00
|
|
|
|
|
|
|
// Battery Sensors
|
2018-01-16 15:16:44 -04:00
|
|
|
AP_BattMonitor battery{MASK_LOG_CURRENT};
|
2015-05-12 01:58:56 -03:00
|
|
|
|
|
|
|
#if FRSKY_TELEM_ENABLED == ENABLED
|
2016-05-03 12:07:14 -03:00
|
|
|
// FrSky telemetry support
|
2017-12-12 21:06:15 -04:00
|
|
|
AP_Frsky_Telem frsky_telemetry{ahrs, battery, rangefinder};
|
2015-05-12 01:58:56 -03:00
|
|
|
#endif
|
|
|
|
|
2016-10-27 23:20:56 -03:00
|
|
|
uint32_t control_sensors_present;
|
|
|
|
uint32_t control_sensors_enabled;
|
|
|
|
uint32_t control_sensors_health;
|
|
|
|
|
2015-05-12 01:58:56 -03:00
|
|
|
// Conditional command
|
|
|
|
// A value used in condition commands (eg delay, change alt, etc.)
|
|
|
|
// For example in a change altitude command, it is the altitude to change to.
|
|
|
|
int32_t condition_value;
|
|
|
|
// A starting value used to check the status of a conditional command.
|
|
|
|
// For example in a delay command the condition_start records that start time for the delay
|
2016-12-20 09:30:57 -04:00
|
|
|
int32_t condition_start;
|
2015-05-12 01:58:56 -03:00
|
|
|
|
|
|
|
// 3D Location vectors
|
|
|
|
// Location structure defined in AP_Common
|
|
|
|
// The home location used for RTL. The location is set when we first get stable GPS lock
|
|
|
|
const struct Location &home;
|
|
|
|
|
2015-10-30 02:41:06 -03:00
|
|
|
// Flag for if we have g_gps lock and have set the home location in AHRS
|
|
|
|
enum HomeState home_is_set = HOME_UNSET;
|
|
|
|
|
2017-06-05 04:55:24 -03:00
|
|
|
// true if the system time has been set from the GPS
|
|
|
|
bool system_time_set;
|
|
|
|
|
2017-06-06 22:26:51 -03:00
|
|
|
// true if the compass's initial location has been set
|
|
|
|
bool compass_init_location;
|
|
|
|
|
2015-05-12 01:58:56 -03:00
|
|
|
// IMU variables
|
|
|
|
// The main loop execution time. Seconds
|
|
|
|
// This is the time between calls to the DCM algorithm and is the Integration time for the gyros.
|
2016-12-20 09:30:57 -04:00
|
|
|
float G_Dt;
|
2015-05-12 01:58:56 -03:00
|
|
|
|
|
|
|
// Performance monitoring
|
2017-05-17 19:19:58 -03:00
|
|
|
// Timer used to accrue data and trigger recording of the performance monitoring log message
|
2016-12-20 09:30:57 -04:00
|
|
|
int32_t perf_mon_timer;
|
2017-07-15 02:37:52 -03:00
|
|
|
// The maximum main loop execution time, in microseconds, recorded in the current performance monitoring interval
|
2015-05-12 01:58:56 -03:00
|
|
|
uint32_t G_Dt_max;
|
|
|
|
|
|
|
|
// System Timers
|
2016-12-20 09:30:57 -04:00
|
|
|
// Time in microseconds of start of main control loop.
|
2015-05-12 01:58:56 -03:00
|
|
|
uint32_t fast_loopTimer_us;
|
|
|
|
// Number of milliseconds used in last main loop cycle
|
|
|
|
uint32_t delta_us_fast_loop;
|
|
|
|
// Counter of main loop executions. Used for performance monitoring and failsafe processing
|
|
|
|
uint16_t mainLoop_count;
|
|
|
|
|
|
|
|
// set if we are driving backwards
|
|
|
|
bool in_reverse;
|
|
|
|
|
2017-06-29 04:18:08 -03:00
|
|
|
// true if pivoting (set by use_pivot_steering)
|
|
|
|
bool pivot_steering_active;
|
|
|
|
|
2015-05-12 01:58:56 -03:00
|
|
|
static const AP_Scheduler::Task scheduler_tasks[];
|
|
|
|
|
2015-05-12 04:00:25 -03:00
|
|
|
// use this to prevent recursion during sensor init
|
|
|
|
bool in_mavlink_delay;
|
|
|
|
|
|
|
|
static const AP_Param::Info var_info[];
|
2015-05-13 00:16:45 -03:00
|
|
|
static const LogStructure log_structure[];
|
2015-05-12 04:00:25 -03:00
|
|
|
|
2015-07-27 09:10:37 -03:00
|
|
|
// Loiter control
|
2016-12-20 09:30:57 -04:00
|
|
|
uint16_t loiter_duration; // How long we should loiter at the nav_waypoint (time in seconds)
|
2016-10-30 07:42:46 -03:00
|
|
|
uint32_t loiter_start_time; // How long have we been loitering - The start time in millis
|
2016-12-20 09:30:57 -04:00
|
|
|
bool previously_reached_wp; // set to true if we have EVER reached the waypoint
|
2015-07-27 09:10:37 -03:00
|
|
|
|
2015-10-30 02:56:41 -03:00
|
|
|
// time that rudder/steering arming has been running
|
|
|
|
uint32_t rudder_arm_timer;
|
|
|
|
|
2015-10-30 02:20:28 -03:00
|
|
|
// Store the time the last GPS message was received.
|
2016-09-15 09:09:45 -03:00
|
|
|
uint32_t last_gps_msg_ms{0};
|
|
|
|
|
2017-06-01 04:39:49 -03:00
|
|
|
// last visual odometry update time
|
|
|
|
uint32_t visual_odom_last_update_ms;
|
|
|
|
|
2017-07-20 03:12:09 -03:00
|
|
|
// last wheel encoder update times
|
|
|
|
float wheel_encoder_last_angle_rad[WHEELENCODER_MAX_INSTANCES]; // distance in radians at time of last update to EKF
|
|
|
|
uint32_t wheel_encoder_last_update_ms[WHEELENCODER_MAX_INSTANCES]; // system time of last ping from each encoder
|
|
|
|
uint32_t wheel_encoder_last_ekf_update_ms; // system time of last encoder data push to EKF
|
2017-07-20 23:56:39 -03:00
|
|
|
float wheel_encoder_rpm[WHEELENCODER_MAX_INSTANCES]; // for reporting to GCS
|
2017-07-20 03:12:09 -03:00
|
|
|
|
2017-07-14 23:59:28 -03:00
|
|
|
// True when we are doing motor test
|
|
|
|
bool motor_test;
|
|
|
|
|
2017-07-18 23:19:08 -03:00
|
|
|
ModeInitializing mode_initializing;
|
|
|
|
ModeHold mode_hold;
|
|
|
|
ModeManual mode_manual;
|
2017-11-28 02:59:13 -04:00
|
|
|
ModeAcro mode_acro;
|
2017-07-18 23:19:08 -03:00
|
|
|
ModeGuided mode_guided;
|
|
|
|
ModeAuto mode_auto;
|
|
|
|
ModeSteering mode_steering;
|
|
|
|
ModeRTL mode_rtl;
|
2017-11-29 21:58:11 -04:00
|
|
|
ModeSmartRTL mode_smartrtl;
|
2017-07-18 23:19:08 -03:00
|
|
|
|
2017-08-22 08:53:36 -03:00
|
|
|
// cruise throttle and speed learning
|
|
|
|
struct {
|
|
|
|
bool learning;
|
|
|
|
LowPassFilterFloat speed_filt = LowPassFilterFloat(2.0f);
|
|
|
|
LowPassFilterFloat throttle_filt = LowPassFilterFloat(2.0f);
|
|
|
|
} cruise_learn;
|
|
|
|
|
2015-05-12 01:58:56 -03:00
|
|
|
private:
|
2017-08-11 23:05:45 -03:00
|
|
|
|
|
|
|
// APMrover2.cpp
|
|
|
|
void stats_update();
|
2015-05-12 01:58:56 -03:00
|
|
|
void ahrs_update();
|
|
|
|
void mount_update(void);
|
2016-12-20 09:30:57 -04:00
|
|
|
void update_trigger(void);
|
2015-05-12 01:58:56 -03:00
|
|
|
void update_alt();
|
|
|
|
void gcs_failsafe_check(void);
|
|
|
|
void update_compass(void);
|
|
|
|
void update_logging1(void);
|
|
|
|
void update_logging2(void);
|
|
|
|
void update_aux(void);
|
|
|
|
void one_second_loop(void);
|
|
|
|
void update_GPS_50Hz(void);
|
|
|
|
void update_GPS_10Hz(void);
|
|
|
|
void update_current_mode(void);
|
2017-08-11 23:05:45 -03:00
|
|
|
|
|
|
|
// capabilities.cpp
|
|
|
|
void init_capabilities(void);
|
|
|
|
|
|
|
|
// commands_logic.cpp
|
|
|
|
void update_mission(void);
|
|
|
|
bool start_command(const AP_Mission::Mission_Command& cmd);
|
|
|
|
void exit_mission();
|
|
|
|
bool verify_command_callback(const AP_Mission::Mission_Command& cmd);
|
|
|
|
bool verify_command(const AP_Mission::Mission_Command& cmd);
|
|
|
|
void do_RTL(void);
|
2017-12-06 22:42:34 -04:00
|
|
|
void do_nav_wp(const AP_Mission::Mission_Command& cmd, bool always_stop_at_destination);
|
2017-08-11 23:05:45 -03:00
|
|
|
void do_nav_set_yaw_speed(const AP_Mission::Mission_Command& cmd);
|
|
|
|
bool verify_nav_wp(const AP_Mission::Mission_Command& cmd);
|
|
|
|
bool verify_RTL();
|
|
|
|
bool verify_loiter_unlimited(const AP_Mission::Mission_Command& cmd);
|
|
|
|
bool verify_loiter_time(const AP_Mission::Mission_Command& cmd);
|
|
|
|
bool verify_nav_set_yaw_speed();
|
|
|
|
void do_wait_delay(const AP_Mission::Mission_Command& cmd);
|
|
|
|
void do_within_distance(const AP_Mission::Mission_Command& cmd);
|
|
|
|
bool verify_wait_delay();
|
|
|
|
bool verify_within_distance();
|
|
|
|
void do_change_speed(const AP_Mission::Mission_Command& cmd);
|
|
|
|
void do_set_home(const AP_Mission::Mission_Command& cmd);
|
|
|
|
#if CAMERA == ENABLED
|
|
|
|
void do_digicam_configure(const AP_Mission::Mission_Command& cmd);
|
|
|
|
void do_digicam_control(const AP_Mission::Mission_Command& cmd);
|
|
|
|
#endif
|
|
|
|
void do_set_reverse(const AP_Mission::Mission_Command& cmd);
|
|
|
|
|
|
|
|
// commands.cpp
|
|
|
|
void update_home_from_EKF();
|
|
|
|
bool set_home_to_current_location(bool lock);
|
|
|
|
bool set_home(const Location& loc, bool lock);
|
2017-09-18 02:37:37 -03:00
|
|
|
void set_ekf_origin(const Location& loc);
|
2017-08-11 23:05:45 -03:00
|
|
|
void set_system_time_from_GPS();
|
|
|
|
void update_home();
|
|
|
|
|
|
|
|
// compat.cpp
|
|
|
|
void delay(uint32_t ms);
|
|
|
|
|
|
|
|
// control_modes.cpp
|
2017-12-11 20:38:40 -04:00
|
|
|
Mode *mode_from_mode_num(enum mode num);
|
2017-08-11 23:05:45 -03:00
|
|
|
void read_control_switch();
|
|
|
|
uint8_t readSwitch(void);
|
|
|
|
void reset_control_switch();
|
2017-08-22 04:06:23 -03:00
|
|
|
aux_switch_pos read_aux_switch_pos();
|
|
|
|
void init_aux_switch();
|
|
|
|
void read_aux_switch();
|
2017-08-11 23:05:45 -03:00
|
|
|
bool motor_active();
|
|
|
|
|
|
|
|
// crash_check.cpp
|
|
|
|
void crash_check();
|
|
|
|
|
2017-08-22 08:53:36 -03:00
|
|
|
// cruise_learn.cpp
|
|
|
|
void cruise_learn_start();
|
|
|
|
void cruise_learn_update();
|
|
|
|
void cruise_learn_complete();
|
|
|
|
|
2017-08-11 23:05:45 -03:00
|
|
|
// events.cpp
|
|
|
|
void update_events(void);
|
|
|
|
|
|
|
|
// failsafe.cpp
|
|
|
|
void failsafe_trigger(uint8_t failsafe_type, bool on);
|
|
|
|
#if ADVANCED_FAILSAFE == ENABLED
|
|
|
|
void afs_fs_check(void);
|
|
|
|
#endif
|
|
|
|
|
2017-08-16 07:02:56 -03:00
|
|
|
// fence.cpp
|
|
|
|
void fence_check();
|
|
|
|
void fence_send_mavlink_status(mavlink_channel_t chan);
|
|
|
|
|
2017-08-11 23:05:45 -03:00
|
|
|
// GCS_Mavlink.cpp
|
2015-05-12 01:58:56 -03:00
|
|
|
void send_heartbeat(mavlink_channel_t chan);
|
|
|
|
void send_attitude(mavlink_channel_t chan);
|
|
|
|
void send_extended_status1(mavlink_channel_t chan);
|
|
|
|
void send_location(mavlink_channel_t chan);
|
|
|
|
void send_nav_controller_output(mavlink_channel_t chan);
|
|
|
|
void send_servo_out(mavlink_channel_t chan);
|
|
|
|
void send_vfr_hud(mavlink_channel_t chan);
|
|
|
|
void send_simstate(mavlink_channel_t chan);
|
|
|
|
void send_rangefinder(mavlink_channel_t chan);
|
2017-08-11 23:05:45 -03:00
|
|
|
void send_pid_tuning(mavlink_channel_t chan);
|
2017-07-20 23:56:39 -03:00
|
|
|
void send_wheel_encoder(mavlink_channel_t chan);
|
2017-08-16 07:02:56 -03:00
|
|
|
void send_fence_status(mavlink_channel_t chan);
|
2015-05-12 01:58:56 -03:00
|
|
|
void gcs_data_stream_send(void);
|
|
|
|
void gcs_update(void);
|
|
|
|
void gcs_retry_deferred(void);
|
2015-08-06 09:50:52 -03:00
|
|
|
|
2017-08-11 23:05:45 -03:00
|
|
|
// Log.cpp
|
2015-05-12 01:58:56 -03:00
|
|
|
void Log_Write_Performance();
|
|
|
|
void Log_Write_Steering();
|
2017-08-11 23:05:45 -03:00
|
|
|
void Log_Write_Beacon();
|
2015-11-09 18:40:10 -04:00
|
|
|
void Log_Write_Startup(uint8_t type);
|
2017-12-07 08:42:06 -04:00
|
|
|
void Log_Write_Throttle();
|
2015-05-12 01:58:56 -03:00
|
|
|
void Log_Write_Nav_Tuning();
|
2017-08-11 23:05:45 -03:00
|
|
|
void Log_Write_Attitude();
|
2017-07-13 08:36:44 -03:00
|
|
|
void Log_Write_Rangefinder();
|
2017-08-11 23:05:45 -03:00
|
|
|
void Log_Arm_Disarm();
|
2015-05-12 01:58:56 -03:00
|
|
|
void Log_Write_RC(void);
|
2016-11-21 12:08:24 -04:00
|
|
|
void Log_Write_Error(uint8_t sub_system, uint8_t error_code);
|
2015-05-12 01:58:56 -03:00
|
|
|
void Log_Write_Baro(void);
|
2015-07-06 01:17:05 -03:00
|
|
|
void Log_Write_Home_And_Origin();
|
2017-07-13 02:35:08 -03:00
|
|
|
void Log_Write_GuidedTarget(uint8_t target_type, const Vector3f& pos_target, const Vector3f& vel_target);
|
2017-07-11 23:02:51 -03:00
|
|
|
void Log_Write_WheelEncoder();
|
2017-08-16 07:57:42 -03:00
|
|
|
void Log_Write_Proximity();
|
2017-08-11 23:05:45 -03:00
|
|
|
void Log_Read(uint16_t log_num, uint16_t start_page, uint16_t end_page);
|
2015-05-13 00:16:45 -03:00
|
|
|
void log_init(void);
|
2017-08-11 23:05:45 -03:00
|
|
|
void Log_Write_Vehicle_Startup_Messages();
|
2015-08-06 09:50:52 -03:00
|
|
|
|
2017-08-11 23:05:45 -03:00
|
|
|
// Parameters.cpp
|
2015-05-12 01:58:56 -03:00
|
|
|
void load_parameters(void);
|
2017-08-11 23:05:45 -03:00
|
|
|
|
|
|
|
// radio.cpp
|
2015-05-12 01:58:56 -03:00
|
|
|
void set_control_channels(void);
|
|
|
|
void init_rc_in();
|
|
|
|
void init_rc_out();
|
2017-08-11 23:05:45 -03:00
|
|
|
void rudder_arm_disarm_check();
|
2015-05-12 01:58:56 -03:00
|
|
|
void read_radio();
|
|
|
|
void control_failsafe(uint16_t pwm);
|
|
|
|
void trim_control_surfaces();
|
|
|
|
void trim_radio();
|
2017-08-11 23:05:45 -03:00
|
|
|
|
|
|
|
// sensors.cpp
|
|
|
|
void init_compass(void);
|
|
|
|
void compass_accumulate(void);
|
2016-05-23 22:31:27 -03:00
|
|
|
void init_barometer(bool full_calibration);
|
2017-07-13 08:36:44 -03:00
|
|
|
void init_rangefinder(void);
|
2017-04-03 17:46:12 -03:00
|
|
|
void init_beacon();
|
|
|
|
void update_beacon();
|
2017-06-01 04:39:49 -03:00
|
|
|
void init_visual_odom();
|
|
|
|
void update_visual_odom();
|
2017-07-11 23:02:51 -03:00
|
|
|
void update_wheel_encoder();
|
2015-05-12 01:58:56 -03:00
|
|
|
void read_battery(void);
|
|
|
|
void read_receiver_rssi(void);
|
2017-08-11 23:05:45 -03:00
|
|
|
void compass_cal_update(void);
|
|
|
|
void accel_cal_update(void);
|
2017-07-13 08:36:44 -03:00
|
|
|
void read_rangefinders(void);
|
2017-08-11 23:05:45 -03:00
|
|
|
void button_update(void);
|
2017-08-16 07:57:42 -03:00
|
|
|
void init_proximity();
|
|
|
|
void update_proximity();
|
2017-08-11 23:05:45 -03:00
|
|
|
void update_sensor_status_flags(void);
|
|
|
|
|
|
|
|
// Steering.cpp
|
|
|
|
bool use_pivot_steering(float yaw_error_cd);
|
|
|
|
void set_servos(void);
|
|
|
|
|
|
|
|
// system.cpp
|
2015-05-12 01:58:56 -03:00
|
|
|
void init_ardupilot();
|
|
|
|
void startup_ground(void);
|
|
|
|
void set_reverse(bool reverse);
|
2017-08-16 05:35:21 -03:00
|
|
|
bool set_mode(Mode &new_mode, mode_reason_t reason);
|
2017-08-11 23:05:45 -03:00
|
|
|
bool mavlink_set_mode(uint8_t mode);
|
2015-05-12 01:58:56 -03:00
|
|
|
void startup_INS_ground(void);
|
|
|
|
void update_notify();
|
|
|
|
void resetPerfData(void);
|
|
|
|
void check_usb_mux(void);
|
2017-08-11 23:05:45 -03:00
|
|
|
void print_mode(AP_HAL::BetterStream *port, uint8_t mode);
|
2017-11-28 22:35:33 -04:00
|
|
|
void notify_mode(const Mode *new_mode);
|
2015-05-12 01:58:56 -03:00
|
|
|
uint8_t check_digital_pin(uint8_t pin);
|
|
|
|
bool should_log(uint32_t mask);
|
2015-10-30 02:56:41 -03:00
|
|
|
void change_arm_state(void);
|
|
|
|
bool arm_motors(AP_Arming::ArmingMethod method);
|
2017-08-11 23:05:45 -03:00
|
|
|
bool disarm_motors(void);
|
2017-11-29 21:58:11 -04:00
|
|
|
void smart_rtl_update();
|
2017-12-06 22:37:42 -04:00
|
|
|
bool is_boat() const;
|
2017-08-11 23:05:45 -03:00
|
|
|
|
2015-05-12 04:00:25 -03:00
|
|
|
public:
|
|
|
|
void mavlink_delay_cb();
|
|
|
|
void failsafe_check();
|
2015-08-06 09:50:52 -03:00
|
|
|
|
|
|
|
void dataflash_periodic(void);
|
2017-10-03 21:12:49 -03:00
|
|
|
void ins_periodic();
|
2016-07-28 04:31:58 -03:00
|
|
|
void update_soft_armed();
|
2017-07-14 23:59:28 -03:00
|
|
|
// Motor test
|
|
|
|
void motor_test_output();
|
2017-07-15 05:18:46 -03:00
|
|
|
bool mavlink_motor_test_check(mavlink_channel_t chan, bool check_rc, uint8_t motor_seq, uint8_t throttle_type, int16_t throttle_value);
|
2017-11-27 02:19:58 -04:00
|
|
|
MAV_RESULT mavlink_motor_test_start(mavlink_channel_t chan, uint8_t motor_seq, uint8_t throttle_type, int16_t throttle_value, float timeout_sec);
|
2017-07-14 23:59:28 -03:00
|
|
|
void motor_test_stop();
|
2015-05-12 01:58:56 -03:00
|
|
|
};
|
2015-05-12 04:00:25 -03:00
|
|
|
|
2015-05-13 00:16:45 -03:00
|
|
|
extern const AP_HAL::HAL& hal;
|
|
|
|
extern Rover rover;
|
|
|
|
|
2015-11-19 23:04:16 -04:00
|
|
|
using AP_HAL::millis;
|
|
|
|
using AP_HAL::micros;
|