搜档网
当前位置:搜档网 › APM飞控程序解读

APM飞控程序解读

APM飞控程序解读
APM飞控程序解读

/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-

#define THISFIRMWARE "ArduCopter V3.1-rc5"

/*

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 .

*/

/*

* ArduCopter Version 3.0

* Creator: Jason Short

* Lead Developer: Randy Mackay

* Based on code and ideas from the Arducopter team: Pat Hickey, Jose Julio, Jani Hirvinen, Andrew Tridgell, Justin Beech, Adam Rivera, Jean-Louis Naudin, Roberto Navoni

* Thanks to: Chris Anderson, Mike Smith, Jordi Munoz, Doug Weibel, James Goppert, Benjamin Pelletier, Robert Lefebvre, Marco Robustini

*

* Special Thanks for Contributors (in alphabetical order by first name):

*

* Adam M Rivera :Auto Compass Declination

* Amilcar Lucas :Camera mount library

* Andrew Tridgell :General development, Mavlink Support

* Angel Fernandez :Alpha testing

* Doug Weibel :Libraries

* Christof Schmid :Alpha testing

* Dani Saez :V Octo Support

* Gregory Fletcher :Camera mount orientation math

* Guntars :Arming safety suggestion

* HappyKillmore :Mavlink GCS

* Hein Hollander :Octo Support

* Igor van Airde :Control Law optimization

* Leonard Hall :Flight Dynamics, Throttle, Loiter and Navigation Controllers

* Jonathan Challinger :Inertial Navigation

* Jean-Louis Naudin :Auto Landing

* Max Levine :Tri Support, Graphics

* Jack Dunkle :Alpha testing

* James Goppert :Mavlink Support

* Jani Hiriven :Testing feedback

* John Arne Birkeland :PPM Encoder

* Jose Julio :Stabilization Control laws

* Marco Robustini :Lead tester

* Michael Oborne :Mission Planner GCS

* Mike Smith :Libraries, Coding support

* Oliver :Piezo support

* Olivier Adler :PPM Encoder

* Robert Lefebvre :Heli Support & LEDs

* Sandro Benigno :Camera support

*

* And much more so PLEASE PM me on DIYDRONES to add your contribution to the List

*

* Requires modified "mrelax" version of Arduino, which can be found here:

* https://www.sodocs.net/doc/909291225.html,/p/ardupilot-mega/downloads/list

*

////////////////////////////////////////////////////////////////////////////////

// Header includes

////////////////////////////////////////////////////////////////////////////////

#include

#include

#include

// Common dependencies

#include

#include

#include

#include

// AP_HAL

#include

#include

#include

#include

#include

#include

#include

// Application dependencies

#include // MAVLink GCS定义

#include // ArduPilot GPS library

#include // 全球定位系统干扰保护库

#include // ArduPilot Mega Flash Memory Library

#include // ArduPilot Mega Analog to Digital Converter Library

#include

#include

#include // ArduPilot Mega Magnetometer Library

#include // ArduPilot Mega Vector/Matrix math Library

#include // Curve used to linearlise throttle pwm to thrust

#include // ArduPilot Mega Inertial Sensor (accel & gyro) Library #include

#include // PI library

#include // PID library

#include //遥控通道库

#include // AP Motors library

#include // Range finder library

#include // Optical Flow library

#include // Filter library

#include // APM FIFO Buffer

#include // APM relay

#include // Photo or video camera

#include // Camera/Antenna mount

#include // needed for AHRS build

#include // needed for AHRS build

#include // ArduPilot Mega inertial 导航 library

#include // ArduCopter waypoint navigation library

#include // ArduPilot Mega Declination Helper Library

#include // Arducopter Fence library

#include // memory limit checker

#include // software in the loop support

#include // 主循环调度程序

#include // RC input mapping library

#include // Notify library

#include // Battery monitor library

#if SPRAYER == ENABLED

#include // crop sprayer library

//AP_HAL Arduino兼容性层#include "compat.h"

//配置

#include "defines.h"

#include "config.h"

#include "config_channels.h"

// Local modules

#include "Parameters.h"

#include "GCS.h"

//////////////////////////////////////////////////////////////////////////////// // cliSerial

//////////////////////////////////////////////////////////////////////////////// // cliSerial isn't strictly necessary - it is an alias for hal.console. It may // be deprecated in favor of hal.console in later releases.

static AP_HAL::BetterStream* cliSerial;

// N.B. we need to keep a static declaration which isn't guarded by macros

// at the top to cooperate with the prototype mangler.

//////////////////////////////////////////////////////////////////////////////// // AP_HAL instance

//////////////////////////////////////////////////////////////////////////////// const AP_HAL::HAL& hal = AP_HAL_BOARD_DRIVER;

//////////////////////////////////////////////////////////////////////////////// // Parameters

//////////////////////////////////////////////////////////////////////////////// //

// Global parameters are all contained within the 'g' class.

//

static Parameters g;

// main loop scheduler

static AP_Scheduler scheduler;

// AP_Notify instance

static AP_Notify notify;

//////////////////////////////////////////////////////////////////////////////// // prototypes

//////////////////////////////////////////////////////////////////////////////// static void update_events(void);

static void print_flight_mode(AP_HAL::BetterStream *port, uint8_t mode);

//////////////////////////////////////////////////////////////////////////////// // Dataflash

//////////////////////////////////////////////////////////////////////////////// #if CONFIG_HAL_BOARD == HAL_BOARD_APM2

static DataFlash_APM2 DataFlash;

#elif CONFIG_HAL_BOARD == HAL_BOARD_APM1

static DataFlash_APM1 DataFlash;

#elif CONFIG_HAL_BOARD == HAL_BOARD_AVR_SITL

//static DataFlash_File DataFlash("/tmp/APMlogs");

static DataFlash_SITL DataFlash;

#elif CONFIG_HAL_BOARD == HAL_BOARD_PX4

static DataFlash_File DataFlash("/fs/microsd/APM/logs");

#elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX

static DataFlash_File DataFlash("logs");

#else

static DataFlash_Empty DataFlash;

#endif

////////////////////////////////////////////////////////////////////////////////

//运行主循环////////////////////////////////////////////////////////////////////////////////

静态常量AP_InertialSensor:Sample_rate ins_sample_rate = AP_InertialSensor::RATE_100HZ;

////////////////////////////////////////////////////////////////////////////////

// Sensors

////////////////////////////////////////////////////////////////////////////////

//

// There are three basic options related to flight sensor selection.

//

// - Normal flight mode. Real sensors are used.

// - HIL Attitude mode. Most sensors are disabled, as the HIL

// protocol supplies attitude information directly.

// - HIL Sensors mode. Synthetic sensors are configured that

// supply data from the simulation.

//

// All GPS access should be through this pointer.

static GPS *g_gps;

static GPS_Glitch gps_glitch(g_gps);

// flight modes convenience array

static AP_Int8 *flight_modes = &g.flight_mode1;

#if HIL_MODE == HIL_MODE_DISABLED

#if CONFIG_ADC == ENABLED

static AP_ADC_ADS7844 adc;

#endif

#if CONFIG_IMU_TYPE == CONFIG_IMU_MPU6000

static AP_InertialSensor_MPU6000 ins;

#elif CONFIG_IMU_TYPE == CONFIG_IMU_OILPAN

static AP_InertialSensor_Oilpan ins(&adc);

#elif CONFIG_IMU_TYPE == CONFIG_IMU_SITL

static AP_InertialSensor_HIL ins;

#elif CONFIG_IMU_TYPE == CONFIG_IMU_PX4

static AP_InertialSensor_PX4 ins;

#elif CONFIG_IMU_TYPE == CONFIG_IMU_FLYMAPLE

AP_InertialSensor_Flymaple ins;

#elif CONFIG_IMU_TYPE == CONFIG_IMU_L3G4200D

AP_InertialSensor_L3G4200D ins;

#endif

#if CONFIG_HAL_BOARD == HAL_BOARD_AVR_SITL

// When building for SITL we use the HIL barometer and compass drivers

static AP_Baro_HIL barometer;

static AP_Compass_HIL compass;

static SITL sitl;

#else

// Otherwise, instantiate a real barometer and compass driver

#if CONFIG_BARO == AP_BARO_BMP085

static AP_Baro_BMP085 barometer;

#elif CONFIG_BARO == AP_BARO_PX4

static AP_Baro_PX4 barometer;

#elif CONFIG_BARO == AP_BARO_MS5611

#if CONFIG_MS5611_SERIAL == AP_BARO_MS5611_SPI

static AP_Baro_MS5611 barometer(&AP_Baro_MS5611::spi);

#elif CONFIG_MS5611_SERIAL == AP_BARO_MS5611_I2C

static AP_Baro_MS5611 barometer(&AP_Baro_MS5611::i2c);

#else

#error Unrecognized CONFIG_MS5611_SERIAL setting.

#endif

#endif

#if CONFIG_HAL_BOARD == HAL_BOARD_PX4

static AP_Compass_PX4 compass;

#else

static AP_Compass_HMC5843 compass;

#endif

#endif

// real GPS selection

#if GPS_PROTOCOL == GPS_PROTOCOL_AUTO

AP_GPS_Auto g_gps_driver(&g_gps);

#elif GPS_PROTOCOL == GPS_PROTOCOL_NMEA

AP_GPS_NMEA g_gps_driver;

#elif GPS_PROTOCOL == GPS_PROTOCOL_SIRF

AP_GPS_SIRF g_gps_driver;

#elif GPS_PROTOCOL == GPS_PROTOCOL_UBLOX

AP_GPS_UBLOX g_gps_driver;

#elif GPS_PROTOCOL == GPS_PROTOCOL_MTK

AP_GPS_MTK g_gps_driver;

#elif GPS_PROTOCOL == GPS_PROTOCOL_MTK19

AP_GPS_MTK19 g_gps_driver;

#elif GPS_PROTOCOL == GPS_PROTOCOL_NONE

AP_GPS_None g_gps_driver;

#else

#error Unrecognised GPS_PROTOCOL setting.

#endif // GPS PROTOCOL

static AP_AHRS_DCM ahrs(&ins, g_gps);

#elif HIL_MODE == HIL_MODE_SENSORS

// sensor emulators

static AP_ADC_HIL adc;

static AP_Baro_HIL barometer;

static AP_Compass_HIL compass;

static AP_GPS_HIL g_gps_driver;

static AP_InertialSensor_HIL ins;

static AP_AHRS_DCM ahrs(&ins, g_gps);

#if CONFIG_HAL_BOARD == HAL_BOARD_AVR_SITL

// When building for SITL we use the HIL barometer and compass drivers static SITL sitl;

#endif

#elif HIL_MODE == HIL_MODE_ATTITUDE

static AP_ADC_HIL adc;

static AP_InertialSensor_HIL ins;

static AP_AHRS_HIL ahrs(&ins, g_gps);

static AP_GPS_HIL g_gps_driver;

static AP_Compass_HIL compass; // never used

static AP_Baro_HIL barometer;

#if CONFIG_HAL_BOARD == HAL_BOARD_AVR_SITL

// When building for SITL we use the HIL barometer and compass drivers

static SITL sitl;

#endif

#else

#error Unrecognised HIL_MODE setting.

#endif // HIL MODE

////////////////////////////////////////////////////////////////////////////////

// Optical flow sensor

////////////////////////////////////////////////////////////////////////////////

#if OPTFLOW == ENABLED

static AP_OpticalFlow_ADNS3080 optflow;

#else

static AP_OpticalFlow optflow;

#endif

////////////////////////////////////////////////////////////////////////////////

// GCS selection

////////////////////////////////////////////////////////////////////////////////

static GCS_MAVLINK gcs0;

static GCS_MAVLINK gcs3;

////////////////////////////////////////////////////////////////////////////////

// SONAR selection

////////////////////////////////////////////////////////////////////////////////

//

ModeFilterInt16_Size3 sonar_mode_filter(1);

#if CONFIG_SONAR == ENABLED

static AP_HAL::AnalogSource *sonar_analog_source;

static AP_RangeFinder_MaxsonarXL *sonar;

#endif

////////////////////////////////////////////////////////////////////////////////

// User variables

////////////////////////////////////////////////////////////////////////////////

#ifdef USERHOOK_VARIABLES

#include USERHOOK_VARIABLES

#endif

////////////////////////////////////////////////////////////////////////////////

// Global variables

////////////////////////////////////////////////////////////////////////////////

/* Radio values

* Channel assignments

* 1 Ailerons (rudder if no ailerons)

* 2 Elevator

* 3 Throttle

* 4 Rudder (if we have ailerons)

* 5 Mode - 3 position switch

* 6 User assignable

* 7 trainer switch - sets throttle nominal (toggle switch), sets accels to Level (hold > 1 second)

* 8 TBD

* Each Aux channel can be configured to have any of the available auxiliary functions assigned to it.

* See libraries/RC_Channel/RC_Channel_aux.h for more information

*/

//Documentation of GLobals:

static union {

struct {

uint8_t home_is_set : 1; // 0

uint8_t simple_mode : 2; // 1,2 // This is the state of simple mode : 0 = disabled ; 1 = SIMPLE ;

2 = SUPERSIMPLE

uint8_t pre_arm_rc_check : 1; // 3 // true if rc input pre-arm checks have been completed successfully uint8_t pre_arm_check : 1; // 4 // true if all pre-arm checks (rc, accel calibration, gps lock) have been performed

uint8_t auto_armed : 1; // 5 // stops auto missions from beginning until throttle is raised uint8_t logging_started : 1; // 6 // true if dataflash logging has started

uint8_t do_flip : 1; // 7 // Used to enable flip code

uint8_t takeoff_complete : 1; // 8

uint8_t land_complete : 1; // 9 // true if we have detected a landing

uint8_t new_radio_frame : 1; // 10 // Set true if we have new PWM data to act on from the Radio uint8_t CH7_flag : 2; // 11,12 // ch7 aux switch : 0 is low or false, 1 is center or true, 2 is high

uint8_t CH8_flag : 2; // 13,14 // ch8 aux switch : 0 is low or false, 1 is center or true, 2 is high

uint8_t usb_connected : 1; // 15 // true if APM is powered from USB connection

uint8_t yaw_stopped : 1; // 16 // Used to manage the Yaw hold capabilities

uint8_t disable_stab_rate_limit : 1; // 17 // disables limits rate request from the stability controller

uint8_t rc_receiver_present : 1; // 18 // true if we have an rc receiver present (i.e. if we've ever received an update

};

uint32_t value;

} ap;

////////////////////////////////////////////////////////////////////////////////

// Radio

////////////////////////////////////////////////////////////////////////////////

// This is the state of the flight control system

// There are multiple states defined such as STABILIZE, ACRO,

static int8_t control_mode = STABILIZE;

// Used to maintain the state of the previous control switch position

// This is set to -1 when we need to re-read the switch

static uint8_t oldSwitchPosition;

static RCMapper rcmap;

// receiver RSSI

static uint8_t receiver_rssi;

////////////////////////////////////////////////////////////////////////////////

// Failsafe

////////////////////////////////////////////////////////////////////////////////

static struct {

uint8_t rc_override_active : 1; // 0 // true if rc control are overwritten by ground station

uint8_t radio : 1; // 1 // A status flag for the radio failsafe

uint8_t battery : 1; // 2 // A status flag for the battery failsafe

uint8_t gps : 1; // 3 // A status flag for the gps failsafe

uint8_t gcs : 1; // 4 // A status flag for the ground station failsafe

int8_t radio_counter; // number of iterations with throttle below throttle_fs_value

uint32_t last_heartbeat_ms; // the time when the last HEARTBEAT message arrived from a GCS - used for triggering gcs failsafe

} failsafe;

////////////////////////////////////////////////////////////////////////////////

// Motor Output

////////////////////////////////////////////////////////////////////////////////

#if FRAME_CONFIG == QUAD_FRAME

#define MOTOR_CLASS AP_MotorsQuad

#elif FRAME_CONFIG == TRI_FRAME

#define MOTOR_CLASS AP_MotorsTri

#elif FRAME_CONFIG == HEXA_FRAME

#define MOTOR_CLASS AP_MotorsHexa

#elif FRAME_CONFIG == Y6_FRAME

#define MOTOR_CLASS AP_MotorsY6

#elif FRAME_CONFIG == OCTA_FRAME

#define MOTOR_CLASS AP_MotorsOcta

#elif FRAME_CONFIG == OCTA_QUAD_FRAME

#define MOTOR_CLASS AP_MotorsOctaQuad

#elif FRAME_CONFIG == HELI_FRAME

#define MOTOR_CLASS AP_MotorsHeli

#else

#error Unrecognised frame type

#endif

#if FRAME_CONFIG == HELI_FRAME // helicopter constructor requires more arguments

static MOTOR_CLASS motors(&g.rc_1, &g.rc_2, &g.rc_3, &g.rc_4, &g.rc_8, &g.heli_servo_1, &g.heli_servo_2,

&g.heli_servo_3, &g.heli_servo_4);

#elif FRAME_CONFIG == TRI_FRAME // tri constructor requires additional rc_7 argument to allow tail servo reversing static MOTOR_CLASS motors(&g.rc_1, &g.rc_2, &g.rc_3, &g.rc_4, &g.rc_7);

#else

static MOTOR_CLASS motors(&g.rc_1, &g.rc_2, &g.rc_3, &g.rc_4);

#endif

////////////////////////////////////////////////////////////////////////////////

// PIDs

////////////////////////////////////////////////////////////////////////////////

// This is a convienience accessor for the IMU roll rates. It's currently the raw IMU rates

// and not the adjusted omega rates, but the name is stuck

static Vector3f omega;

// This is used to hold radio tuning values for in-flight CH6 tuning

float tuning_value;

// used to limit the rate that the pid controller output is logged so that it doesn't negatively affect performance static uint8_t pid_log_counter;

////////////////////////////////////////////////////////////////////////////////

// LED output

////////////////////////////////////////////////////////////////////////////////

// Blinking indicates GPS status

static uint8_t copter_leds_GPS_blink;

// Blinking indicates battery status

static uint8_t copter_leds_motor_blink;

// Navigation confirmation blinks

static int8_t copter_leds_nav_blink;

////////////////////////////////////////////////////////////////////////////////

// GPS variables

////////////////////////////////////////////////////////////////////////////////

// This is used to scale GPS values for EEPROM storage

// 10^7 times Decimal GPS means 1 == 1cm

// This approximation makes calculations integer and it's easy to read

static const float t7 = 10000000.0;

// We use atan2 and other trig techniques to calaculate angles

// We need to scale the longitude up to make these calcs work

// to account for decreasing distance between lines of longitude away from the equator

static float scaleLongUp = 1;

// Sometimes we need to remove the scaling for distance calcs

static float scaleLongDown = 1;

////////////////////////////////////////////////////////////////////////////////

// Location & Navigation

////////////////////////////////////////////////////////////////////////////////

// This is the angle from the copter to the next waypoint in centi-degrees

static int32_t wp_bearing;

// The original bearing to the next waypoint. used to point the nose of the copter at the next waypoint static int32_t original_wp_bearing;

// The location of home in relation to the copter in centi-degrees

static int32_t home_bearing;

// distance between plane and home in cm

static int32_t home_distance;

// distance between plane and next waypoint in cm.

static uint32_t wp_distance;

// navigation mode - options include NAV_NONE, NAV_LOITER, NAV_CIRCLE, NAV_WP

static uint8_t nav_mode;

// Register containing the index of the current navigation command in the mission script

static int16_t command_nav_index;

// Register containing the index of the previous navigation command in the mission script

// Used to manage the execution of conditional commands

static uint8_t prev_nav_index;

// Register containing the index of the current conditional command in the mission script

static uint8_t command_cond_index;

// Used to track the required WP navigation information

// options include

// NAV_ALTITUDE - have we reached the desired altitude?

// NAV_LOCATION - have we reached the desired location?

// NAV_DELAY - have we waited at the waypoint the desired time?

static float lon_error, lat_error; // Used to report how many cm we are from the next waypoint or loiter target position

static int16_t control_roll;

static int16_t control_pitch;

static uint8_t rtl_state; // records state of rtl (initial climb, returning home, etc)

static uint8_t land_state; // records state of land (flying to location, descending)

////////////////////////////////////////////////////////////////////////////////

// Orientation

////////////////////////////////////////////////////////////////////////////////

// Convienience accessors for commonly used trig functions. These values are generated

// by the DCM through a few simple equations. They are used throughout the code where cos and sin

// would normally be used.

// The cos values are defaulted to 1 to get a decent initial value for a level state

static float cos_roll_x = 1.0;

static float cos_pitch_x = 1.0;

static float cos_yaw = 1.0;

static float sin_yaw;

static float sin_roll;

static float sin_pitch;

////////////////////////////////////////////////////////////////////////////////

// SIMPLE Mode

////////////////////////////////////////////////////////////////////////////////

// Used to track the orientation of the copter for Simple mode. This value is reset at each arming

// or in SuperSimple mode when the copter leaves a 20m radius from home.

static float simple_cos_yaw = 1.0;

static float simple_sin_yaw;

static int32_t super_simple_last_bearing;

static float super_simple_cos_yaw = 1.0;

static float super_simple_sin_yaw;

// Stores initial bearing when armed - initial simple bearing is modified in super simple mode so not suitable static int32_t initial_armed_bearing;

////////////////////////////////////////////////////////////////////////////////

// Rate contoller targets

////////////////////////////////////////////////////////////////////////////////

static uint8_t rate_targets_frame = EARTH_FRAME; // indicates whether rate targets provided in earth or body frame

static int32_t roll_rate_target_ef;

static int32_t pitch_rate_target_ef;

static int32_t yaw_rate_target_ef;

static int32_t roll_rate_target_bf; // body frame roll rate target

static int32_t pitch_rate_target_bf; // body frame pitch rate target

static int32_t yaw_rate_target_bf; // body frame yaw rate target

////////////////////////////////////////////////////////////////////////////////

// Throttle variables

////////////////////////////////////////////////////////////////////////////////

static int16_t throttle_accel_target_ef; // earth frame throttle acceleration target

static bool throttle_accel_controller_active; // true when accel based throttle controller is active, false when higher level throttle controllers are providing throttle output directly

static float throttle_avg; // g.throttle_cruise as a float

static int16_t desired_climb_rate; // pilot desired climb rate - for logging purposes only

static float target_alt_for_reporting; // target altitude in cm for reporting (logs and ground station)

////////////////////////////////////////////////////////////////////////////////

// ACRO Mode

////////////////////////////////////////////////////////////////////////////////

// Used to control Axis lock

static int32_t acro_roll; // desired roll angle while sport mode

static int32_t acro_roll_rate; // desired roll rate while in acro mode

static int32_t acro_pitch; // desired pitch angle while sport mode

static int32_t acro_pitch_rate; // desired pitch rate while acro mode

static int32_t acro_yaw_rate; // desired yaw rate while acro mode

static float acro_level_mix; // scales back roll, pitch and yaw inversely proportional to input from pilot

// Filters

#if FRAME_CONFIG == HELI_FRAME

//static LowPassFilterFloat rate_roll_filter; // Rate Roll filter

//static LowPassFilterFloat rate_pitch_filter; // Rate Pitch filter

#endif // HELI_FRAME

////////////////////////////////////////////////////////////////////////////////

// Circle Mode / Loiter control

////////////////////////////////////////////////////////////////////////////////

Vector3f circle_center; // circle position expressed in cm from home location. x = lat, y = lon

// angle from the circle center to the copter's desired location. Incremented at circle_rate / second

static float circle_angle;

// the total angle (in radians) travelled

static float circle_angle_total;

// deg : how many times to circle as specified by mission command

static uint8_t circle_desired_rotations;

static float circle_angular_acceleration; // circle mode's angular acceleration

static float circle_angular_velocity; // circle mode's angular velocity

static float circle_angular_velocity_max; // circle mode's max angular velocity

// How long we should stay in Loiter Mode for mission scripting (time in seconds)

static uint16_t loiter_time_max;

// How long have we been loitering - The start time in millis

static uint32_t loiter_time;

////////////////////////////////////////////////////////////////////////////////

// CH7 and CH8 save waypoint control

////////////////////////////////////////////////////////////////////////////////

// This register tracks the current Mission Command index when writing

// a mission using Ch7 or Ch8 aux switches in flight

static int8_t aux_switch_wp_index;

////////////////////////////////////////////////////////////////////////////////

// Battery Sensors

////////////////////////////////////////////////////////////////////////////////

static AP_BattMonitor battery;

////////////////////////////////////////////////////////////////////////////////

// Altitude

////////////////////////////////////////////////////////////////////////////////

// The (throttle) controller desired altitude in cm

static float controller_desired_alt;

// The cm we are off in altitude from next_WP.alt – Positive value means we are below the WP static int32_t altitude_error;

// The cm/s we are moving up or down based on filtered data - Positive = UP

static int16_t climb_rate;

// The altitude as reported by Sonar in cm – Values are 20 to 700 generally.

static int16_t sonar_alt;

static uint8_t sonar_alt_health; // true if we can trust the altitude from the sonar

static float target_sonar_alt; // desired altitude in cm above the ground

// The altitude as reported by Baro in cm – Values can be quite high

static int32_t baro_alt;

static int16_t saved_toy_throttle;

////////////////////////////////////////////////////////////////////////////////

// flight modes

////////////////////////////////////////////////////////////////////////////////

// Flight modes are combinations of Roll/Pitch, Yaw and Throttle control modes

// Each Flight mode is a unique combination of these modes

//

// The current desired control scheme for Yaw

static uint8_t yaw_mode;

// The current desired control scheme for roll and pitch / navigation

static uint8_t roll_pitch_mode;

// The current desired control scheme for altitude hold

static uint8_t throttle_mode;

////////////////////////////////////////////////////////////////////////////////

// flight specific

////////////////////////////////////////////////////////////////////////////////

// An additional throttle added to keep the copter at the same altitude when banking

static int16_t angle_boost;

// counter to verify landings

static uint16_t land_detector;

////////////////////////////////////////////////////////////////////////////////

// 3D Location vectors

////////////////////////////////////////////////////////////////////////////////

// home location is stored when we have a good GPS lock and arm the copter

// Can be reset each the copter is re-armed

static struct Location home;

// Current location of the copter

static struct Location current_loc;

// Holds the current loaded command from the EEPROM for navigation

static struct Location command_nav_queue;

// Holds the current loaded command from the EEPROM for conditional scripts

static struct Location command_cond_queue;

////////////////////////////////////////////////////////////////////////////////

// Navigation Roll/Pitch functions

////////////////////////////////////////////////////////////////////////////////

// all angles are deg * 100 : target yaw angle

// The Commanded ROll from the autopilot.

static int32_t nav_roll;

// The Commanded pitch from the autopilot. negative Pitch means go forward.

static int32_t nav_pitch;

// The Commanded ROll from the autopilot based on optical flow sensor.

static int32_t of_roll;

// The Commanded pitch from the autopilot based on optical flow sensor. negative Pitch means go forward. static int32_t of_pitch;

////////////////////////////////////////////////////////////////////////////////

// Navigation Throttle control

////////////////////////////////////////////////////////////////////////////////

// The Commanded Throttle from the autopilot.

static int16_t nav_throttle; // 0-1000 for throttle control

// This is a simple counter to track the amount of throttle used during flight

// This could be useful later in determining and debuging current usage and predicting battery life static uint32_t throttle_integrator;

////////////////////////////////////////////////////////////////////////////////

// Navigation Yaw control

////////////////////////////////////////////////////////////////////////////////

// The Commanded Yaw from the autopilot.

static int32_t nav_yaw;

static uint8_t yaw_timer;

// Yaw will point at this location if yaw_mode is set to YAW_LOOK_AT_LOCATION

static Vector3f yaw_look_at_WP;

// bearing from current location to the yaw_look_at_WP

static int32_t yaw_look_at_WP_bearing;

// yaw used for YAW_LOOK_AT_HEADING yaw_mode

static int32_t yaw_look_at_heading;

// Deg/s we should turn

static int16_t yaw_look_at_heading_slew;

////////////////////////////////////////////////////////////////////////////////

// Repeat Mission Scripting Command

////////////////////////////////////////////////////////////////////////////////

// The type of repeating event - Toggle a servo channel, Toggle the APM1 relay, etc

static uint8_t event_id;

// Used to manage the timimng of repeating events

static uint32_t event_timer;

// How long to delay the next firing of event in millis

static uint16_t event_delay;

// how many times to fire : 0 = forever, 1 = do once, 2 = do twice

static int16_t event_repeat;

// per command value, such as PWM for servos

static int16_t event_value;

// the stored value used to undo commands - such as original PWM command

static int16_t event_undo_value;

////////////////////////////////////////////////////////////////////////////////

// Delay Mission Scripting Command

////////////////////////////////////////////////////////////////////////////////

static int32_t condition_value; // used in condition commands (eg delay, change alt, etc.)

static uint32_t condition_start;

////////////////////////////////////////////////////////////////////////////////

// IMU variables

////////////////////////////////////////////////////////////////////////////////

// Integration time (in seconds) for the gyros (DCM algorithm)

// Updated with the fast loop

static float G_Dt = 0.02;

////////////////////////////////////////////////////////////////////////////////

// Inertial Navigation

////////////////////////////////////////////////////////////////////////////////

static AP_InertialNav inertial_nav(&ahrs, &barometer, g_gps, gps_glitch);

////////////////////////////////////////////////////////////////////////////////

// Waypoint navigation object

// To-Do: move inertial nav up or other navigation variables down here

////////////////////////////////////////////////////////////////////////////////

static AC_WPNav wp_nav(&inertial_nav, &ahrs, &g.pi_loiter_lat, &g.pi_loiter_lon, &g.pid_loiter_rate_lat, &g.pid_loiter_rate_lon);

////////////////////////////////////////////////////////////////////////////////

// Performance monitoring

////////////////////////////////////////////////////////////////////////////////

// The number of GPS fixes we have had

static uint8_t gps_fix_count;

static int16_t pmTest1;

// System Timers

// --------------

// Time in microseconds of main control loop

static uint32_t fast_loopTimer;

// Counter of main loop executions. Used for performance monitoring and failsafe processing

static uint16_t mainLoop_count;

// Loiter timer - Records how long we have been in loiter

static uint32_t rtl_loiter_start_time;

// prevents duplicate GPS messages from entering system

static uint32_t last_gps_time;

// Used to exit the roll and pitch auto trim function

static uint8_t auto_trim_counter;

// Reference to the relay object (APM1 -> PORTL 2) (APM2 -> PORTB 7)

static AP_Relay relay;

//Reference to the camera object (it uses the relay object inside it)

#if CAMERA == ENABLED

static AP_Camera camera(&relay);

#endif

// a pin for reading the receiver RSSI voltage.

static AP_HAL::AnalogSource* rssi_analog_source;

// Input sources for battery voltage, battery current, board vcc

static AP_HAL::AnalogSource* board_vcc_analog_source;

#if CLI_ENABLED == ENABLED

static int8_t setup_show (uint8_t argc, const Menu::arg *argv);

#endif

// Camera/Antenna mount tracking and stabilisation stuff

// --------------------------------------

#if MOUNT == ENABLED

// current_loc uses the baro/gps soloution for altitude rather than gps only.

// mabe one could use current_loc for lat/lon too and eliminate g_gps alltogether?

static AP_Mount camera_mount(¤t_loc, g_gps, ahrs, 0);

#endif

#if MOUNT2 == ENABLED

// current_loc uses the baro/gps soloution for altitude rather than gps only.

// mabe one could use current_loc for lat/lon too and eliminate g_gps alltogether?

static AP_Mount camera_mount2(¤t_loc, g_gps, ahrs, 1);

#endif

////////////////////////////////////////////////////////////////////////////////

// AC_Fence library to reduce fly-aways

////////////////////////////////////////////////////////////////////////////////

#if AC_FENCE == ENABLED

AC_Fence fence(&inertial_nav);

#endif

////////////////////////////////////////////////////////////////////////////////

// Crop Sprayer

////////////////////////////////////////////////////////////////////////////////

#if SPRAYER == ENABLED

static AC_Sprayer sprayer(&inertial_nav);

#endif

////////////////////////////////////////////////////////////////////////////////

// function definitions to keep compiler from complaining about undeclared functions

////////////////////////////////////////////////////////////////////////////////

void get_throttle_althold(int32_t target_alt, int16_t min_climb_rate, int16_t max_climb_rate); static void pre_arm_checks(bool display_failure);

////////////////////////////////////////////////////////////////////////////////

// Top-level logic

////////////////////////////////////////////////////////////////////////////////

// setup the var_info table

AP_Param param_loader(var_info, WP_START_BYTE);

/*

scheduler table - all regular tasks apart from the fast_loop()

should be listed here, along with how often they should be called

(in 10ms units) and the maximum time they are expected to take (in microseconds)

*/

static const AP_Scheduler::Task scheduler_tasks[] PROGMEM = {

{ throttle_loop, 2, 450 },

{ update_GPS, 2, 900 },

{ update_nav_mode, 1, 400 },

{ update_batt_compass, 10, 720 },

{ read_aux_switches, 10, 50 },

{ arm_motors_check, 10, 10 },

{ auto_trim, 10, 140 },

{ update_toy_throttle, 10, 50 },

{ update_altitude, 10, 1000 },

{ run_nav_updates, 10, 800 },

{ three_hz_loop, 33, 90 },

{ compass_accumulate, 2, 420 },

{ barometer_accumulate, 2, 250 },

{ update_notify, 2, 100 },

{ one_hz_loop, 100, 420 },

{ gcs_check_input, 2, 550 },

{ gcs_send_heartbeat, 100, 150 },

{ gcs_send_deferred, 2, 720 },

{ gcs_data_stream_send, 2, 950 },

#if COPTER_LEDS == ENABLED

{ update_copter_leds, 10, 55 },

#endif

{ update_mount, 2, 450 },

{ ten_hz_logging_loop, 10, 260 },

{ fifty_hz_logging_loop, 2, 220 },

{ perf_update, 1000, 200 },

{ read_receiver_rssi, 10, 50 },

#ifdef USERHOOK_FASTLOOP

{ userhook_FastLoop, 1, 100 },

#endif

#ifdef USERHOOK_50HZLOOP

{ userhook_50Hz, 2, 100 },

#endif

#ifdef USERHOOK_MEDIUMLOOP

{ userhook_MediumLoop, 10, 100 },

#endif

#ifdef USERHOOK_SLOWLOOP

{ userhook_SlowLoop, 30, 100 },

#endif

#ifdef USERHOOK_SUPERSLOWLOOP

{ userhook_SuperSlowLoop,100, 100 },

#endif

};

void setup() {

// this needs to be the first call, as it fills memory with

// sentinel values

memcheck_init();

cliSerial = hal.console;

// Load the default values of variables listed in var_info[]s

AP_Param::setup_sketch_defaults();

// initialise notify system

notify.init();

// initialise battery monitor

battery.init();

#if CONFIG_SONAR == ENABLED

#if CONFIG_SONAR_SOURCE == SONAR_SOURCE_ADC

sonar_analog_source = new AP_ADC_AnalogSource(

&adc, CONFIG_SONAR_SOURCE_ADC_CHANNEL, 0.25);

#elif CONFIG_SONAR_SOURCE == SONAR_SOURCE_ANALOG_PIN

sonar_analog_source = hal.analogin->channel(

CONFIG_SONAR_SOURCE_ANALOG_PIN);

#else

#warning "Invalid CONFIG_SONAR_SOURCE"

#endif

sonar = new AP_RangeFinder_MaxsonarXL(sonar_analog_source,

&sonar_mode_filter);

#endif

rssi_analog_source = hal.analogin->channel(g.rssi_pin);

board_vcc_analog_source = hal.analogin->channel(ANALOG_INPUT_BOARD_VCC);

init_ardupilot();

// initialise the main loop scheduler

scheduler.init(&scheduler_tasks[0], sizeof(scheduler_tasks)/sizeof(scheduler_tasks[0])); }

/*

if the compass is enabled then try to accumulate a reading

*/

static void compass_accumulate(void)

{

if (https://www.sodocs.net/doc/909291225.html,pass_enabled) {

compass.accumulate();

}

}

/*

try to accumulate a baro reading

*/

static void barometer_accumulate(void)

{

barometer.accumulate();

}

static void perf_update(void)

{

if (g.log_bitmask & MASK_LOG_PM)

Log_Write_Performance();

if (scheduler.debug()) {

cliSerial->printf_P(PSTR("PERF: %u/%u %lu\n"),

(unsigned)perf_info_get_num_long_running(),

(unsigned)perf_info_get_num_loops(),

(unsigned long)perf_info_get_max_time());

}

perf_info_reset();

gps_fix_count = 0;

pmTest1 = 0;

}

void loop()

{

// wait for an INS sample

if (!ins.wait_for_sample(1000)) {

Log_Write_Error(ERROR_SUBSYSTEM_MAIN, ERROR_CODE_INS_DELAY);

return;

}

uint32_t timer = micros();

// check loop time

perf_info_check_loop_time(timer - fast_loopTimer);

// used by PI Loops

G_Dt = (float)(timer - fast_loopTimer) / 1000000.f;

fast_loopTimer = timer;

// for mainloop failure monitoring

mainLoop_count++;

// Execute the fast loop

// ---------------------

fast_loop();

// tell the scheduler one tick has passed

scheduler.tick();

// run all the tasks that are due to run. Note that we only

// have to call this once per loop, as the tasks are scheduled

// in multiples of the main loop tick. So if they don't run on

// the first call to the scheduler they won't run on a later

// call until scheduler.tick() is called again

uint32_t time_available = (timer + 10000) - micros();

scheduler.run(time_available - 300);

}

// Main loop - 100hz

static void fast_loop()

{

// IMU DCM Algorithm

// --------------------

read_AHRS();

// reads all of the necessary trig functions for cameras, throttle, etc.

// --------------------------------------------------------------------

update_trig();

// Acrobatic control

if (ap.do_flip) {

if(abs(g.rc_1.control_in) < 4000) {

// calling roll_flip will override the desired roll rate and throttle output roll_flip();

}else{

// force an exit from the loop if we are not hands off sticks.

ap.do_flip = false;

Log_Write_Event(DATA_EXIT_FLIP);

}

}

// run low level rate controllers that only require IMU data

run_rate_controllers();

// write out the servo PWM values

// ------------------------------

set_servos_4();

// Inertial Nav

// --------------------

read_inertia();

// optical flow

// --------------------

#if OPTFLOW == ENABLED

if(g.optflow_enabled) {

update_optical_flow();

}

#endif // OPTFLOW == ENABLED

// Read radio and 3-position switch on radio

// -----------------------------------------

read_radio();

read_control_switch();

// custom code/exceptions for flight modes

// ---------------------------------------

update_yaw_mode();

update_roll_pitch_mode();

//更新目标速度控制器 update_rate_contoller_targets(); }

// throttle_loop——应该运行在50 hz

// ---------------------------

static void throttle_loop()

{

// get altitude and climb rate from inertial lib

read_inertial_altitude();

// Update the throttle ouput

// -------------------------

update_throttle_mode();

// check if we've landed

update_land_detector();

#if TOY_EDF == ENABLED

edf_toy();

#endif

// check auto_armed status

update_auto_armed();

}

// update_mount - update camera mount position

// should be run at 50hz

static void update_mount()

{

#if MOUNT == ENABLED

// update camera mount's position

camera_mount.update_mount_position();

#endif

#if MOUNT2 == ENABLED

// update camera mount's position

camera_mount2.update_mount_position();

#endif

#if CAMERA == ENABLED

camera.trigger_pic_cleanup();

#endif

}

// update_batt_compass - read battery and compass

// should be called at 10hz

static void update_batt_compass(void)

{

// read battery before compass because it may be used for motor interference compensation read_battery();

#if HIL_MODE != HIL_MODE_ATTITUDE // don't execute in HIL mode

if(https://www.sodocs.net/doc/909291225.html,pass_enabled) {

if (compass.read()) {

compass.null_offsets();

}

// log compass information

if (motors.armed() && (g.log_bitmask & MASK_LOG_COMPASS)) {

Log_Write_Compass();

}

}

#endif

// record throttle output

throttle_integrator += g.rc_3.servo_out;

}

// ten_hz_logging_loop

// should be run at 10hz

static void ten_hz_logging_loop()

{

if(motors.armed()) {

if (g.log_bitmask & MASK_LOG_ATTITUDE_MED) {

Log_Write_Attitude();

}

if (g.log_bitmask & MASK_LOG_MOTORS) {

Log_Write_Motors();

}

}

}

// fifty_hz_logging_loop

// should be run at 50hz

static void fifty_hz_logging_loop()

{

#if HIL_MODE != HIL_MODE_DISABLED

// HIL for a copter needs very fast update of the servo values

gcs_send_message(MSG_RADIO_OUT);

#endif

# if HIL_MODE == HIL_MODE_DISABLED

if (g.log_bitmask & MASK_LOG_ATTITUDE_FAST && motors.armed()) {

Log_Write_Attitude();

}

if (g.log_bitmask & MASK_LOG_IMU && motors.armed()) {

DataFlash.Log_Write_IMU(&ins);

}

#endif

}

// three_hz_loop - 3.3hz loop

static void three_hz_loop()

{

// check if we've lost contact with the ground station

failsafe_gcs_check();

#if AC_FENCE == ENABLED

// check if we have breached a fence

fence_check();

#endif // AC_FENCE_ENABLED

#if SPRAYER == ENABLED

sprayer.update();

#endif

update_events();

if(g.radio_tuning > 0)

tuning();

}

// one_hz_loop - runs at 1Hz

static void one_hz_loop()

{

if (g.log_bitmask != 0) {

Log_Write_Data(DATA_AP_STATE, ap.value);

}

// pass latest alt hold kP value to navigation controller

wp_nav.set_althold_kP(g.pi_alt_hold.kP());

// update latest lean angle to navigation controller

wp_nav.set_lean_angle_max(g.angle_max);

// log battery info to the dataflash

if ((g.log_bitmask & MASK_LOG_CURRENT) && motors.armed())

Log_Write_Current();

// perform pre-arm checks

pre_arm_checks(false);

// auto disarm checks

auto_disarm_check();

if (!motors.armed()) {

// make it possible to change ahrs orientation at runtime during initial config

ahrs.set_orientation();

// check the user hasn't updated the frame orientation

motors.set_frame_orientation(g.frame_orientation);

}

#if CONFIG_HAL_BOARD == HAL_BOARD_PX4

update_aux_servo_function(&g.rc_5, &g.rc_6, &g.rc_7, &g.rc_8, &g.rc_9, &g.rc_10, &g.rc_11, &g.rc_12); #elif MOUNT == ENABLED

update_aux_servo_function(&g.rc_5, &g.rc_6, &g.rc_7, &g.rc_8, &g.rc_10, &g.rc_11);

#endif

enable_aux_servos();

#if MOUNT == ENABLED

camera_mount.update_mount_type();

#endif

apm飞控较为详细的入门教程

apm飞控较为详细的入门教程 最近发现很多模友在看了泡泡老师的视频有很多细节没有看懂在群上提问,为了能使刚用上apm的模友一步到位,再来一个文字教程帮助你们快速使用。在此也感谢apm2.8交流群中的冷风群主提供的教程~废话不多说了 硬件安装 1、通过USB接口供电时,如果USB数据处于连接状态,APM会切断数传接口的通讯功能,所以请不要同时使用数传和USB线连接调试APM,USB接口的优先级高于数传接口,仅有供电功能的USB线不在此限; 2、APM板载的加速度传感器受震动影响,会产生不必要的动差,直接影响飞控姿态的计算,条件允许请尽量使用一个减震平台来安装APM主板; 3、APM板载的高精气压计对温度的变化非常敏感,所以请尽量在气压计上覆盖一块黑色海绵用来遮光,以避免阳光直射的室外飞行环境下,光照热辐射对气压计的影响。另外覆盖海绵,也可以避免飞行器自身气流对气压计的干扰。 使用建议 对于初次使用APM自驾仪的用户来说,建议你分步骤完成APM的入门使用: 1、首先安装地面站控制软件及驱动,熟悉地面站界面的各个菜单功能; 2、仅连接USB线学会固件的下载; 3、连接接收机和USB线完成APM的遥控校准、加速度校准和罗盘校准; 4、完成各类参数的设定; 5、组装飞机,完成各类安全检查后试飞; 6、PID参数调整; 7、APM各类高阶应用 地面站调试软件Mission Planner安装 首先,MissionPlanner的安装运行需要微软的Net Framework 4.0组件,所以在安装Mission Planner之前请先下载Net Flamework 4.0并安装 安装完NetFramework后开始下载Mission Planner安装程序包,最新版本的Mission Planner可以点击此处下载,下载页面中每个版本都提供了MSI版和ZIP版可供选择。MSI 为应用程序安装包版,安装过程中会同时安装APM的USB驱动,安装后插上APM的USB 线即可使用。ZIP版为绿色免安装版,解压缩即可使用,但是连接APM后需要你手动安装APM的USB驱动程序,驱动程序在解压后的Driver文件夹中。具体使用哪个版本请自行决定,如果是第一次安装使用,建议你下载MSI版。 以安装MSI版为例(注意:安装前请不要连接APM的USB线),双击下载后的MSI文件,然后一步一步Next即可,只是安装过程中弹出设备驱动程序安装向导时,请点击下一步继续,否则会跳过驱动程序的安装(关于教程的各类文件我会在网盘里共享)

apm飞控入门教程

Apm 飞控较为详细的入门教程

最近发现很多模友在看了泡泡老师的视频有很多细节没有看懂在群上提问,为了能使刚用上apm的模友一步到位,再来一个文字教程帮助你们快速使用。在此也感谢apm2.8交流群中的冷风群主提供的教程~废话不多说了 硬件安装 1、通过USB接口供电时,如果USB数据处于连接状态,APM会切断数传接口的通讯功能,所以请不要同时使用数传和USB线连接调试APM,USB接口的优先级高于数传接口,仅有供电功能的USB线不在此限; 2、APM板载的加速度传感器受震动影响,会产生不必要的动差,直接影响飞控姿态的计算,条件允许请尽量使用一个减震平台来安装APM主板; 3、APM板载的高精气压计对温度的变化非常敏感,所以请尽量在气压计上覆盖一块黑色海 绵用来遮光,以避免阳光直射的室外飞行环境下,光照热辐射对气压计的影响。另外覆盖海绵,也可以避免飞行器自身气流对气压计的干扰。 使用建议 对于初次使用APM自驾仪的用户来说,建议你分步骤完成APM的入门使用: 1、首先安装地面站控制软件及驱动,熟悉地面站界面的各个菜单功能; 2、仅连接USB线学会固件的下载; 3、连接接收机和USB线完成APM的遥控校准、加速度校准和罗盘校准; 4、完成各类参数的设定; 5、组装飞机,完成各类安全检查后试飞; 6、PID参数调整; 7、APM各类高阶应用 地面站调试软件Mission Planner安装 首先,MissionPlanner的安装运行需要微软的Net Framework 4.0组件,所以在安装Mission Planner之前请先下载Net Flamework 4.0并安装 安装完NetFramework后开始下载Mission Planner安装程序包,最新版本的Mission Planner可以点击此处下载,下载页面中每个版本都提供了MSI版和ZIP版可供选择。MSI 为应用程序安装包版,安装过程中会同时安装APM的USB驱动,安装后插上APM的USB 线即可使用。ZIP版为绿色免安装版,解压缩即可使用,但是连接APM后需要你手动安装APM的USB驱动程序,驱动程序在解压后的Driver文件夹中。具体使用哪个版本请自行 决定,如果是第一次安装使用,建议你下载MSI版。 以安装MSI版为例(注意:安装前请不要连接APM的USB线),双击下载后的MSI文件,然后一步一步Next即可,只是安装过程中弹出设备驱动程序安装向导时,请点击下一步继 续,否则会跳过驱动程序的安装(关于教程的各类文件我会在网盘里共享)

apm飞控较为详细的入门教程

APM飞控详细入门教程 目录 一、硬件安装 (1) 二、地面站调试软件Mission Planner安装 (1) 三、认识Misson Planner的界面 (2) 四、固件安装 (3) 五、遥控校准 (6) 六、加速度校准 (8) 七、罗盘校准 (16) 八、解锁需知(重要) (18) 九、飞行模式配置 (18) 十、失控保护 (19) 十一、命令行的使用 (20) 十二、APM飞行模式注解 (23) 十三、APM接口定义说明 (25) 十四、apm pid 调参的通俗理解 (26) 十五、arduino的编译下载最新固件 (28) 俺是收集整理的哦,原作和原文来源 https://www.sodocs.net/doc/909291225.html,/p/2974250475?pn=1 感谢yl494706588

最近发现很多模友在看了泡泡老师的视频有很多细节没有看懂在群上提问,为了能使刚用上apm的模友一步到位,再来一个文字教程帮助你们快速使用。在此也感谢apm2.8交流群中的冷风群主提供的教程~废话不多说了 一、硬件安装 1、通过USB接口供电时,如果USB数据处于连接状态,APM会切断数传接口的通讯功能,所以请不要同时使用数传和USB线连接调试APM,USB接口的优先级高于数传接口,仅有供电功能的USB线不在此限; 2、APM板载的加速度传感器受震动影响,会产生不必要的动差,直接影响飞控姿态的计算,条件允许请尽量使用一个减震平台来安装APM主板; 3、APM板载的高精气压计对温度的变化非常敏感,所以请尽量在气压计上覆盖一块黑色海绵用来遮光,以避免阳光直射的室外飞行环境下,光照热辐射对气压计的影响。另外覆盖海绵,也可以避免飞行器自身气流对气压计的干扰。 使用建议 对于初次使用APM自驾仪的用户来说,建议你分步骤完成APM的入门使用: 1、首先安装地面站控制软件及驱动,熟悉地面站界面的各个菜单功能; 2、仅连接USB线学会固件的下载; 3、连接接收机和USB线完成APM的遥控校准、加速度校准和罗盘校准; 4、完成各类参数的设定; 5、组装飞机,完成各类安全检查后试飞; 6、PID参数调整; 7、APM各类高阶应用 二、地面站调试软件Mission Planner安装 首先,MissionPlanner的安装运行需要微软的Net Framework 4.0组件,所以在安装Mission Planner之前请先下载Net Flamework 4.0并安装安装完NetFramework后开始下载Mission Planner安装程序包,最新版本的Mission Planner可以点击此处下载,下载页面中每个版本都提供了MSI版和ZIP版可供选择。MSI为应用程序安装包版,安装过程中会同时安装APM的USB驱动,安装后插上APM的USB线即可使用。ZIP版为绿色免安装版,解压缩即可使用,但是连接APM后需要你手动安装APM的USB驱动程序,驱动程序在解压后的Driver文件夹中。具体使用哪个版本请自行决定,如果是第一次安装使用,建议你下载MSI版。 以安装MSI版为例(注意:安装前请不要连接APM的USB线),双击下载后的MSI文件,然后一步一步Next即可,只是安装过程中弹出设备驱动程序安装向导时,请点击下一步继续,否则会跳过驱动程序的安装(关于教程的各类文件我会在网盘里共享)

APM飞控介绍要点

APM飞控介绍要点 APM飞控系统介绍 APM飞控系统是国外的一个开源飞控系统,能够支持固定翼,直升机,3轴,4轴,6轴飞行器。在此我只介绍固定翼飞控系统。 APM飞控系统主要结构和功能 组成功能 飞控主芯片 Atmega1280/2560 主控芯片 PPM解码芯片 Atmega168/328 负责监视模式通道的 pwm信号监测,以便在手 动模式和其他模式之间 进行切换。提高系统安全惯性测量单元双轴陀螺,单轴陀螺,三测量三轴角速度,三轴加 轴加速度计速度,配合三轴磁力计或 gps测得方向数据进行校 正,实现方向余弦算法, 计算出飞机姿态。 GPS导航模块 Lea-5h或其他信号gps模测量飞机当前的经纬度, 块高度,航迹方向(track), 地速等信息。三轴磁力计模块 HMC5843/5883模块测量飞机当前的航向 (heading) 空速计 MPXV7002模块测量飞机空速(误差较 大,而且测得数据不稳 定,会导致油门一阵一阵 变化)

空压计 BMP085芯片测量空气压力,用以换 算成高度 AD芯片 ADS7844芯片将三轴陀螺仪、三轴加速 度计、双轴陀螺仪输出温 度、空速计输出的模拟电 压转换成数字量,以供后 续计算 其他模块电源芯片,usb电平转换 芯片等 飞控原理 在APM飞控系统中,采用的是两级PID控制方式,第一级是导航级,第二级是控制级,导航级的计算集中在medium_loop( ) 和fastloop( )的 update_current_flight_mode( )函数中,控制级集中在fastloop( )的 stabilize( )函数中。导航级PID控制就是要解决飞机如何以预定空速飞行在预定高度的问题,以及如何转弯飞往目标问题,通过算法给出飞机需要的俯仰角、油门和横滚角,然后交给控制级进行控制解算。控制级的任务就是依据需要的俯仰角、油门、横滚角,结合飞机当前的姿态解算出合适的舵机控制量,使飞机保持预定的俯仰角,横滚角和方向角。最后通过舵机控制级set_servos_4( )将控制量转换成具体的pwm信号量输出给舵机。值得一提的是,油门的控制量是在导航级确定的。控制级中不对油门控制量进行解算,而直接交给舵机控制级。而对于方向舵的控制,导航级并不给出方向舵量的解算,而是由控制级直接解算方向舵控制量,然后再交给舵机控制级。 以下,我剔除了APM飞控系统的细枝末节,仅仅将飞控系统的重要语句展现,只浅显易懂地说明APM飞控系统的核心工作原理。 一,如何让飞机保持预定高度和空速飞行

APM飞控源码讲解

APM飞控系统介绍 APM飞控系统是国外的一个开源飞控系统,能够支持固定翼,直升机,3轴,4轴,6轴飞行器。在此我只介绍固定翼飞控系统。 APM飞控系统主要结构和功能 组成功能 飞控主芯片Atmega1280/2560 主控芯片 PPM解码芯片Atmega168/328 负责监视模式通道的 pwm信号监测,以便在手 动模式和其他模式之间 进行切换。提高系统安全 惯性测量单元双轴陀螺,单轴陀螺,三 轴加速度计测量三轴角速度,三轴加速度,配合三轴磁力计或gps测得方向数据进行校正,实现方向余弦算法,计算出飞机姿态。 GPS导航模块Lea-5h或其他信号gps模 块测量飞机当前的经纬度,高度,航迹方向(track),地速等信息。 三轴磁力计模块HMC5843/5883模块测量飞机当前的航向 (heading) 空速计MPXV7002模块测量飞机空速(误差较 大,而且测得数据不稳 定,会导致油门一阵一阵 变化) 空压计BMP085芯片测量空气压力,用以换 算成高度 AD芯片ADS7844芯片将三轴陀螺仪、三轴加速 度计、双轴陀螺仪输出温 度、空速计输出的模拟电 压转换成数字量,以供后 续计算 其他模块电源芯片,usb电平转换 芯片等 飞控原理 在APM飞控系统中,采用的是两级PID控制方式,第一级是导航级,第二级是控制级,导航级的计算集中在medium_loop( ) 和fastloop( )的update_current_flight_mode( )函数中,控制级集中在fastloop( )的stabilize( )函数中。导航级PID控制就是要解决飞机如何以预定空速飞行在预定高度的问题,以及如何转弯飞往目标问题,通过算法给出飞机需要的俯仰角、油门和横滚角,然后交给控制级进行控 制解算。控制级的任务就是依据需要的俯仰角、油门、横滚角,结合飞机当前的姿态解

apm飞控较为详细的入门教程

apm飞控较为详细的入门教程 超详细的APM飞控介绍教程,赶紧收了,不错。 APM飞控详细入门教程 目录 一、硬件安装 (1) 二、地面站调试软件Mission Planner安装 (1) 三、认识Misson Planner的界面 (2) 四、固件安装 (3) 五、遥控校准 (6) 六、加速度校准 (8) 七、罗盘校准 (16) 八、解锁需知(重要) (18) 九、飞行模式配置 (18)

十、失控保护 (19) 十一、命令行的使用 (20) 十二、APM飞行模式注解 (23) 十三、APM接口定义说明 (25) 十四、apm pid 调参的通俗理解 (26) 十五、arduino的编译下载最新固件 (28) 俺是收集整理的哦,原作和原文来源 感谢yl494706588 最近发现很多模友在看了泡泡老师的视频有很多细节没有看懂在群上提问,为了能使刚用上apm的模友一步到位,再来一个文字教程帮助你们快速使用。在此也感谢apm2.8交流群中的冷风群主提供的教程~废话不多说了 一、硬件安装 1、通过USB接口供电时,如果USB数据处于连接状态,APM会切断数传接口的通讯功能,所以请不要同时使用数传和USB线连接调试APM,USB接口的优先级高于数传接口,仅有供电功能的USB线不在此限;

条件允许请尽量使用一个减震平台来安装APM主板; 3、APM板载的高精气压计对温度的变化非常敏感,所以请尽量在气压计上覆盖一块黑色海绵用来遮光,以避免阳光直射的室外飞行环境下,光照热辐射对气压计的影响。另外覆盖海绵,也可以避免飞行器自身气流对气压计的干扰。使用建议 对于初次使用APM自驾仪的用户来说,建议你分步骤完成APM的入门使用: 1、首先安装地面站控制软件及驱动,熟悉地面站界面的各个菜单功能; 2、仅连接USB线学会固件的下载; 3、连接接收机和USB线完成APM的遥控校准、加速度校准和罗盘校准; 4、完成各类参数的设定; 5、组装飞机,完成各类安全检查后试飞; 6、PID参数调整; 7、APM各类高阶应用 二、地面站调试软件Mission Planner安装 首先,MissionPlanner的安装运行需要微软的Net Framework 4.0组件,所以在安装Mission Planner之前请先下载Net Flamework 4.0并安装安装完NetFramework后开始下载Mission Planner安装程序包,最新版本的Mission Planner可以点击此处下载,下载页面中每个版本都提供了MSI版和ZIP版可供选择。MSI为应用程序安装包版,安装过程中会同时安装APM 的USB驱动,安装后插上APM的USB线即可使用。ZIP版为绿色免安装版,解压缩即可使用,但是连接APM后需要你手动安装APM的USB驱动程序,驱动程序在解压后的Driver文件夹中。

最新APM飞行模式注解

APM飞行模式注解 1、稳定模式Stabilize 稳定模式是使用得最多的飞行模式,也是最基本的飞行模式,起飞和降落都应该使用此模式。此模式下,飞控会让飞行器保持稳定,是初学者进行一般飞行的首选,也是FPV第一视角飞行的最佳模式。一定要确保遥控器上的开关能很方便无误地拨到该模式,应急时会非常重要。 2、比率控制模式Acro 这个是非稳定模式,这时apm将完全依托遥控器遥控的控制,新手慎用。 3、定高模式ALT_HOLD 定高模式(Alt Hold)是使用自动油门,试图保持目前的高度的稳定模式。定高模式时高度仍然可以通过提高或降低油门控制,但中间会有一个油门死区,油门动作幅度超过这个死区时,飞行器才会响应你的升降动作 当进入任何带有自动高度控制的模式,你目前的油门将被用来作为调整油门保持高度的基准。在进入高度保持前确保你在悬停在一个稳定的高度。飞行器将随着时间补偿不良的数值。只要它不会下跌过快,就不会有什么问题。 离开高度保持模式时请务必小心,油门位置将成为新的油门,如果不是在飞行器的中性悬停位置,将会导致飞行器迅速下降或上升。 在这种模式下你不能降落及关闭马达,因为现在是油门摇杆控制高度,而非马达。请切换到稳定模式,才可以降落和关闭马达。 4、悬停模式Loiter 悬停模式是GPS定点+气压定高模式。应该在起飞前先让GPS定点,避免在空中突然定位发生问题。其他方面跟定高模式基本相同,只是在水平方向上由GPS 进行定位。 5、简单模式Simple Mode 简单模式相当于一个无头模式,每个飞行模式的旁边都有一个Simple Mode复选框可以勾选。勾选简单模式后,飞机将解锁起飞前的机头指向恒定作为遥控器前行摇杆的指向,这种模式下无需担心飞行器的姿态,新手非常有用。 6、自动模式 AUTO 自动模式下,飞行器将按照预先设置的任务规划控制它的飞行 由于任务规划依赖GPS的定位信息,所以在解锁起飞前,必须确保GPS已经完成定位(APM板上蓝色LED常亮) 切换到自动模式有两种情况: 如果使用自动模式从地面起飞,飞行器有一个安全机制防止你误拨到自动模式时误启动发生危险,所以需要先手动解锁并手动推油门起飞。起飞后飞行器会参考

APM飞行模式解说

APM飞行模式注解 ELEV是俯仰或升降 1通道对 Pitch AILE是横滚或副翼 2通道对 Roll THRO是油门 3通道对 Throttl RUDD是方向 4通道对 Yaw 红正黑负白信号,红正棕负橙信号 Pitch 俯仰 Roll 横滚 Throttl 油门 Yaw 方向 1、稳定模式Stabilize 稳定模式是使用得最多的飞行模式,也是最基本的飞行模式,起飞和降落都应该使用此模式。此模式下,飞控会让飞行器保持稳定,是初学者进行一般飞行的首选,也是FPV第一视角飞行的最佳模式。一定要确保遥控器上的开关能很方便无误地拨到该模式,应急时会非常重要。 2、比率控制模式Acro 这个是非稳定模式,这时apm将完全依托遥控器遥控的控制,新手慎用。 3、定高模式ALT_HOLD 定高模式(Alt Hold)是使用自动油门,试图保持目前的高度的稳定模式。定高模式时高度仍然可以通过提高或降低油门控制,但中间会有一个油门死区,油门动作幅度超过这个死区时,飞行器才会响应你的升降动作 当进入任何带有自动高度控制的模式,你目前的油门将被用来作为调整油门保持高度的基准。在进入高度保持前确保你在悬停在一个稳定的高度。飞行器将随着时间补偿不良的数值。只要它不会下跌过快,就不会有什么问题。 离开高度保持模式时请务必小心,油门位置将成为新的油门,如果不是在飞行器的中性悬停位置,将会导致飞行器迅速下降或上升。 在这种模式下你不能降落及关闭马达,因为现在是油门摇杆控制高度,而非马达。请切换到稳定模式,才可以降落和关闭马达。 4、自动模式 AUTO 自动模式下,飞行器将按照预先设置的任务规划控制它的飞行 由于任务规划依赖GPS的定位信息,所以在解锁起飞前,必须确保GPS已经完成定位(APM 板上蓝色LED常亮) 切换到自动模式有两种情况: 如果使用自动模式从地面起飞,飞行器有一个安全机制防止你误拨到自动模式时误启动发生危险,所以需要先手动解锁并手动推油门起飞。起飞后飞行器会参考你最近一次ALT Hold 定高的油门值作为油门基准,当爬升到任务规划的第一个目标高度后,开始执行任务规划飞向目标; 如果是空中切换到自动模式,飞行器首先会爬升到第一目标的高度然后开始执行任务 6、悬停模式Loiter

Pixhawk飞控设置飞行模式教程及LED灯意义

飞行模式中文意思: 0:Stabilize自稳,1:Acro特技,2:AltHold定高,3:Auto自动,4:Guided引导,5:Loiter留待(常叫悬停),6:RTL返航,7:Circle绕圈,9:Land降 落,11:Drift飘移,13:Sport运动,14:Flip翻转,15:AutoTune自动调 参,16:PosHold定点,17:Brake暂停 M:Copter中有14种飞行模式可供选择,有10种是常用的。你可以按照下列流程进行设定: 1.打开你的遥控发射机 2·连接APM/PX4至Mission Planner 3·进入Initial Setup(初始设置)> Mandatory Hardware(必备硬件)> Flight Modes(飞行模式)界面 ·注意下,切换发射机的飞行模式开关(通道5),绿色高光就会移动到不同的位置。 ·使用每行的下拉菜单选择飞行模式应用到这个开关位置上,确保至少有一个开关位置是给自稳的。 ·而且可以为这个开关位置选中简单模式复选框。如果使用的是AC3.1或更新版本,你也可以设为超简单模式。如果简单模式和超简单模式同时被选中,那么会使用超简单模式。建议第一次使用不要打开简单模式或者超简单模式,设置不好飞机会自旋! ·当完成时点击“保存模式”按钮。

飞行模式注解 1、稳定模式Stabilize 稳定模式是使用得最多的飞行模式,也是最基本的飞行模式,起飞和降落都应 该使用此模式。此模式下,飞控会让飞行器保持稳定,是初学者进行一般飞行 的首选,也是FPV第一视角飞行的最佳模式。一定要确保遥控器上的开关能很 方便无误地拨到该模式,应急时会非常重要。 2、比率控制模式Acro 这个是非稳定模式,这时apm将完全依托遥控器遥控的控制,新手慎用。 3、定高模式ALT_HOLD 定高模式(AltHold)是使用自动油门,试图保持目前的高度的稳定模式。定高 模式时高度仍然可以通过提高或降低油门控制,但中间会有一个油门死区,油 门动作幅度超过这个死区时,飞行器才会响应你的升降动作当进入任何带有自 动高度控制的模式,你目前的油门将被用来作为调整油门保持高度的基准。在 进入高度保持前确保你在悬停在一个稳定的高度。飞行器将随着时间补偿不良 的数值。只要它不会下跌过快,就不会有什么问题。离开高度保持模式时请务 必小心,油门位置将成为新的油门,如果不是在飞行器的中性悬停位置,将会 导致飞行器迅速下降或上升。在这种模式下你不能降落及关闭马达,因为现在 是油门摇杆控制高度,而非马达。请切换到稳定模式,才可以降落和关闭马达。 4、悬停模式Loiter 悬停模式是GPS定点+气压定高模式。应该在起飞前先让GPS定点,避免在空 中突然定位发生问题。其他方面跟定高模式基本相同,只是在水平方向上由GPS进行定位。 5、简单模式Simple Mode 简单模式相当于一个无头模式,每个飞行模式的旁边都有一个SimpleMode复 选框可以勾选。勾选简单模式后,飞机将解锁起飞前的机头指向恒定作为遥控 器前行摇杆的指向,这种模式下无需担心飞行器的姿态,新手非常有用。 6、自动模式 AUTO 自动模式下,飞行器将按照预先设置的任务规划控制它的飞行由于任务规划依 赖GPS的定位信息,所以在解锁起飞前,必须确保GPS已经完成定位(APM板 上蓝色LED常亮)切换到自动模式有两种情况:如果使用自动模式从地面起飞,飞行器有一个安全机制防止你误拨到自动模式时误启动发生危险,所以需要先 手动解锁并手动推油门起飞。起飞后飞行器会参考你最近一次ALTHold定高的 油门值作为油门基准,当爬升到任务规划的第一个目标高度后,开始执行任务 规划飞向目标;如果是空中切换到自动模式,飞行器首先会爬升到第一目标的 高度然后开始执行任务

apm飞控飞行模式详解

apm飞控飞行模式详解 1、稳定模式Stabilize 稳定模式是使用得最多的飞行模式,也是最基本的飞行模式,起飞和降落都应 该使用此模式。 此模式下,飞控会让飞行器保持稳定,是初学者进行一般飞行的首选,也是 FPV第一视角飞行的最佳模式。 一定要确保遥控器上的开关能很方便无误地拨到该模式,这对抢救紧急情况十 分重要~ 2、定高模式ALT_HOLD 初次试飞之后就可以尝试定高模式,此模式不需要GPS支持,APM会根据气压 传感器的数据保持当前高度。 定高时如果不会定点,因此飞行器依然会漂移。可以遥控来移动或保持位置。 定高时就是APM控制油门来保持高度。但仍然可以用遥控油门来调整高度,不 可以用来降落,因为油门不会降到0。 稳定模式和定高模式之间切换时,要让遥控发射机的油门在同一位置,避免因 模式切换、油门控制方式发生变化造成飞行器突然上升或者下降。 3、悬停模式Loiter 悬停模式就是GPS定点模式。应该在起飞前先让GPS定点,避免在空中突然定 位发生问题。其他方面跟定高模式基本相同。 4、简单模式Simple Mode 设置过APM飞行模式的朋友都会注意到,软件界面的各个模式旁边,都有个“Simple Mode”简单模式的勾选框。勾了这个框之后的模式,飞行中会更加简单:

不用再管飞行器机头的朝向,可以将飞行器看成一个点,如果升降舵给出俯冲指令,飞行器就会飞得远离操作者;反之如果给出拉杆指令,飞行器会飞回操作者;给出向左滚转的指令,飞行器会向左飞,反之亦然。。。注意,这些前后左右的飞行,是不管当时的机头指向的~ 5、返航模式RTL 返航模式需要GPS定位。GPS在每次ARM前的定位点,就是当前的“家”的位置;GPS如果在起飞前没有定位,在空中首次定位的那个点,就会成为“家”。 进入返航模式后,飞行器会升高到15米,或者如果已经高于15米,就保持当前高度,然后飞回“家”。 还可以设置高级参数选择到“家”后是否自主降落,和悬停多少秒之后自动降落。 6、绕圈模式Circle 当切入绕圈模式时,飞行器会以当前位置为圆心绕圈飞行。而且此时机头会不受遥控器方向舵的控制,始终指向圆心。 如果遥控器给出横滚和俯仰方向上的指令,将会移动圆心。 与定高模式相同,可以通过油门来调整飞行器高度,但是不能降落。 圆的半径可以通过高级参数设置调整。 7、指导模式Guided 此模式需要地面站软件和飞行器之间通信。连接后,在任务规划器Mission Planner软件地图界面上,在地图上任意位置点鼠标右键,选弹出菜单中的“Fly to here”(飞到这里),软件会让你输入一 个高度,然后飞行器会飞到指定位置和高度并保持悬停。 8、跟随模式FollowMe

APM飞控搭配乐迪AT10设置六段开关教程

APM飞控搭配乐迪AT10设置六段开关教程玩APM飞控,玩转它的飞行模式切换是必修的一门课程,否则一块功能强大的APM飞控在你手里,切换不了飞行模式就只能自稳飞飞玩不出花样来,这对APM来说是一种浪费,因此我们必须要学会APM的飞行模式切换。 先了解下APM飞控的飞行模式切换原理。APM有多种飞行模式可供选择,但一次只能选择设置六种飞行模式,设置好的六种飞行模式是通过输入的第五通道来控制的(固定翼是第八通道),与常规遥控的低、中、高开关量不同,APM识别六种飞行模式的开关量是以识别遥控接收机输出的PWM脉宽值的区段为依据的,六个区段分别是0-1230,1231-1360,1361-1490,1491-1620,1621-1749,1750+,这些数值的单位为us,只要五通道输出值分别在这几个区段内的,就可以对应控制开启一个飞行模式,为防止飞行中pwm信号在临界值附近飘移导致误切换飞行模式,所以最佳的六个信号应该是在这六个区段中间,分别是1165,1295,1425,1555,1685,1815这几个值。本文将讲解利用乐迪AT10如何比较精确的设置出这六个信号。 乐迪AT10是深圳乐迪电子新推出的一款10通道模型遥控器,整机外观拥有Futaba 10C的影子,开关旋钮布局合理,操作方便,功能设置上则更优于10C,特别是中文化的操作菜单,更符合国内的使用环境,还支持数据回传,产品定位于专业级遥控,因此,笔者非常推荐使用这款遥控搭配APM使用。 在设置APM的六段开关前,需要对遥控进行一些基本的配置:1、设置为固定翼模式(不管APM的刷的什么固件,包括直升机,与之搭配的遥控必须设为固定翼模式,即每个通道独立输出);2、指定通道开关;3、矫正通道正反相。 现简要说明这几个配置的设置方法: 1、设置固定翼模式。打开遥控开关,长按一下MODE键,系统进入基础菜单,在基础菜单内, 移动导航键至系统功能设置菜单,按压push键进入,然后使用导航键移到机型一栏,使用push键的旋转功能将机型选为固定翼模型,

pixhawk中常出现的种飞行模式

从mission planner中设置pixhawk的飞行模式时,一共给出了13中飞行模式,分别为:Stabilize、Acro、AltHold、Auto、Guided、Loiter、TRL、Circle、Land、Drift、Sport、PosHold、Follow Me。在网上查看了不少资料,所有模式的概括说明都不齐全,所以自己整理了一下。13种飞行模式的注析如下: 1、Stabilize(稳定模式) 稳定模式是使用得最多的飞行模式,也是最基本的飞行模式,起飞和降落都应该使用此模式。此模式下,飞控会让飞行器保持稳定,是初学者进行一般飞行的首选,也是FPV 第一视角飞行的最佳模式。一定要确保遥控器上的开关能很方便无误地拨到该模式,应急时会非常重要。 2、Acro(特技模式) 特技模式是仅基于速率控制的模式。特技模式提供了遥控器摇杆到飞行器电机之间的最直接的控制关系。在特技模式下飞行,就像是不装飞控的遥控直升机一样,需要持续不断的手工摇杆操作。 3、AltHold(定高模式) 定高模式(Alt Hold)是使用自动油门,试图保持目前的高度的稳定模式。定高模式时高度仍然可以通过提高或降低油门控制,但中间会有一个油门死区,油门动作幅度超过这个死区时,飞行器才会响应你的升降动作。当进入任何带有自动高度控制的模式,你目前的油门将被用来作为调整油门保持高度的基准。在进入高度保持前确保你在悬停在一个稳定的高度。飞行器将随着时间补偿不良的数值。只要它不会下跌过快,就不会有什么问题。

离开高度保持模式时请务必小心,油门位置将成为新的油门,如果不是在飞行器的中性悬停位置,将会导致飞行器迅速下降或上升。在这种模式下你不能降落及关闭马达,因为现在是油门摇杆控制高度,而非马达。请切换到稳定模式,才可以降落和关闭马达。 4、Auto(自动模式) 自动模式下,飞行器将按照预先设置的任务规划控制它的飞行。由于任务规划依赖GPS 的定位信息,所以在解锁起飞前,必须确保GPS已经完成定位(APM板上蓝色LED常亮)切换到自动模式有两种情况:一、如果使用自动模式从地面起飞,飞行器有一个安全机制防止你误拨到自动模式时误启动发生危险,所以需要先手动解锁并手动推油门起飞。起飞后飞行器会参考你最近一次ALT Hold定高的油门值作为油门基准,当爬升到任务规划的第一个目标高度后,开始执行任务规划飞向目标;二、如果是空中切换到自动模式,飞行器首先会爬升到第一目标的高度然后开始执行任务。 5、Guided(指导模式) 此模式需要地面站软件和飞行器之间通信。连接后,在任务规划器Mission Planner软件地图界面上,在地图上任意位置点鼠标右键,选弹出菜单中的“Fly to here”(飞到这里),软件会让你输入一个高度,然后飞行器会飞到指定位置和高度并保持悬停。 6、Loiter(光流定点模式) 光流定点,就是利用APM的光流传感器进行定点,这种定点受地形,光照因素影响较大,通常在20米以内定点效果较高。 7、TRL(返航模式)

2 arduplane APM 固定翼 飞行模式

Ardupilot notebook 飞行模式: Manual 手动模式: RC直接控制飞机不经过飞控,除触动failsafe, geo fence 保护外。 Stabilize 增稳: RC经过飞控简单的稳定,如果你放手飞机会自动平飞,相对的飞机的倾斜与机动会变的不容易。 最好使用FBWA模式替代飞机的增稳。 FBWA 线性A增稳: 对于没有经验的飞手是最佳模式。 飞机保持指定的侧倾限制LIM_ROLL_CD(公分-度)及和纵倾限制LIM_PITCH_MAX/ LIM_PITCH_MIN。 需要注意的是控制水平不意味着飞机能控制高度,主要是由飞行速度(油门)控制,如果想要高度保持,需要用FBWB模式。 FBWA油门是手动控制,输出量范围由THR_MIN和THR_MAX限制。 方向舵也是手动及飞控协调混控,即便在地面上可以控制轮子转动。 FBWB 线性B增稳: 类似于FBWA,但能够定高。 侧倾和俯仰同FBWA模式,并利用油门控制空速。 俯仰摇杆变化就会改变高度,放开后飞控试图保持目前的高度。多大的水平角反应依赖于FBWB_CLIMB_RATE参数,默认为2米/秒。 FBWB_ELEV_REV参数的默认值是向后拉摇杆导致飞机攀升。如果设置为1,则动作会相反。如果装了空速计,调整空速范围ARSPD_FBW_MIN到ARSPD_FBW_MAX,当油门最低时飞机将尝试在ARSPD_FBW_MIN飞行。最高时它会尝试在ARSPD_FBW_MAX飞行。 如果没有空速计,油门将调整输出量以达到所需定高要求。油门杆最好大过计算要求的值,也会导致飞的更快 方向舵跟FBWA 一样,是协调混控的。 Acro 特技模式: 能像手动模式做出特技,且又同FBWB能够定高。 做出翻滚及螺旋依赖ACRO_ROLL_RATE及ACRO_PITCH_RATE, 默认值是180度/秒,并响应着摇杆行程量。 飞机会一直保持高度,如果RC输入30度的侧倾及10度的纵倾后放开摇杆,飞机就保持在这个高度上,即便是倒飞的状态下。 所以这个模式很容易失速,需要及时切换到手动模式改出。 Cruise巡航模式:

apm飞控较为详细的入门教程

最近发现很多模友在看了泡泡老师的视频有很多细节没有看懂在群上提问,为了能使刚用上apm的模友一步到位,再来一个文字教程帮助你们快速使用。在此也感谢apm2.8交流群中的冷风群主提供的教程~废话不多说了 硬件安装 1、通过USB接口供电时,如果USB数据处于连接状态,APM会切断数传接口的通讯功能,所以请不要同时使用数传和USB线连接调试APM,USB接口的优先级高于数传接口,仅有供电功能的USB线不在此限; 2、APM板载的加速度传感器受震动影响,会产生不必要的动差,直接影响飞控姿态的计算,条件允许请尽量使用一个减震平台来安装APM主板; 3、APM板载的高精气压计对温度的变化非常敏感,所以请尽量在气压计上覆盖一块黑色海绵用来遮光,以避免阳光直射的室外飞行环境下,光照热辐射对气压计的影响。另外覆盖海绵,也可以避免飞行器自身气流对气压计的干扰。 使用建议 对于初次使用APM自驾仪的用户来说,建议你分步骤完成APM的入门使用: 1、首先安装地面站控制软件及驱动,熟悉地面站界面的各个菜单功能; 2、仅连接USB线学会固件的下载; 3、连接接收机和USB线完成APM的遥控校准、加速度校准和罗盘校准; 4、完成各类参数的设定; 5、组装飞机,完成各类安全检查后试飞; 6、PID参数调整; 7、APM各类高阶应用 地面站调试软件Mission Planner安装 首先,MissionPlanner的安装运行需要微软的Net Framework 4.0组件,所以在安装Mission Planner之前请先下载Net Flamework 4.0并安装 安装完NetFramework后开始下载Mission Planner安装程序包,最新版本的Mission Planner可以点击此处下载,下载页面中每个版本都提供了MSI版和ZIP版可供选择。MSI 为应用程序安装包版,安装过程中会同时安装APM的USB驱动,安装后插上APM的USB 线即可使用。ZIP版为绿色免安装版,解压缩即可使用,但是连接APM后需要你手动安装APM的USB驱动程序,驱动程序在解压后的Driver文件夹中。具体使用哪个版本请自行决定,如果是第一次安装使用,建议你下载MSI版。 以安装MSI版为例(注意:安装前请不要连接APM的USB线),双击下载后的MSI文件,然后一步一步Next即可,只是安装过程中弹出设备驱动程序安装向导时,请点击下一步继续,否则会跳过驱动程序的安装(关于教程的各类文件我会在网盘里共享)

APM飞控简介

APM飞控系统介绍 APM飞控是开源飞控系统,能够支持固定翼,直升机,3轴,4轴,6轴飞行器。在此我只介绍固定翼飞控系统。 飞控原理 在APM飞控系统中,采用的是两级PID控制方式,第一级是导航级,第二级是控制级,导航级的计算集中在medium_loop( ) 和fastloop( )的

update_current_flight_mode( )函数中,控制级集中在fastloop( )的stabilize( )函数中。导航级PID控制就是要解决飞机如何以预定空速飞行在预定高度的问题,以及如何转弯飞往目标问题,通过算法给出飞机需要的俯仰角、油门和横滚角,然后交给控制级进行控制解算。控制级的任务就是依据需要的俯仰角、油门、横滚角,结合飞机当前的姿态解算出合适的舵机控制量,使飞机保持预定的俯仰角,横滚角和方向角。最后通过舵机控制级set_servos_4( )将控制量转换成具体的pwm信号量输出给舵机。值得一提的是,油门的控制量是在导航级确定的。控制级中不对油门控制量进行解算,而直接交给舵机控制级。而对于方向舵的控制,导航级并不给出方向舵量的解算,而是由控制级直接解算方向舵控制量,然后再交给舵机控制级。 以下,我剔除了APM飞控系统的细枝末节,仅仅将飞控系统的重要语句展现,只浅显易懂地说明APM飞控系统的核心工作原理。 一,如何让飞机保持预定高度和空速飞行 要想让飞机在预定高度飞行,飞控必须控制好飞机的升降舵和油门,因此,首先介绍固定翼升降舵和油门的控制,固定翼的升降舵和油门控制方式主要有两种: 一种是高度控制油门,空速控制升降舵方式。实际飞行存在四种情况,第一种情况是飞机飞行过程中,如果高度低于目标高度,飞控就会控制油门加大,从而导致空速加大,然后才导致拉升降舵,飞机爬升;第二种情况与第一种情况相反;第三种情况是飞机在目标高度,但是空速高于目标空速,这种情况飞控会直接拉升降舵,使飞机爬升,降低空速,但是,高度增加了,飞控又会减小油门,导致空速降低,空速低于目标空速后,飞控推升降舵,导致飞机降低高度。这种控制方式的好处是,飞机始终以空速为第一因素来进行控制,因此保证了飞行的安全,特别是当发动机熄火等异常情况发生时,使飞机能继续保持安全,直到高度降低到地面。这种方式的缺点在于对高度的控制是间接控制,因此高度控制可能会有一定的滞后或者波动。 另一种是高度控制升降舵,空速控制油门的方式。这种控制方式的原理是设定好飞机平飞时的迎角,当飞行高度高于或低于目标高度时,在平飞迎角的基础上根据高度与目标高度的差设定一个经过PID控制器输出的限制幅度的爬升角,由飞机当前的俯仰角和爬升角的偏差来控制升降舵面,使飞机迅速达到这个爬升角,而尽快完成高度偏差的消除。但飞机的高度升高或降低后,必然造成空速的变化,因此采用油门来控制飞机的空速,即当空速低于目标空速后,在当前油门的基础上增加油门,当前空速高于目标空速后,在当前油门的基础上减小油门。这种控制方式的好处是能对高度的变化进行第一时间的反应,因此高度控制较好,缺点是当油门失效时,比如发动机熄火发生时,由于高度降低飞控将使飞机保持经过限幅的最大仰角,最终由于动力的缺乏导致失速。 但是以上仅仅是控制理论。在实际控制系统中,由于有些参量并不能较准确地测得,或者测量时数据不稳定,所以并不能完全按照上述的控制理论控制。例如空速的测量时相当不准确的,而且数据波动较严重,这样,就无法完全按照上述理论进行控制,必须在其基础上进行适当修改。以下以使用空速计情况和不使用空速计情况对APM飞控系统进行阐述。 (1),使用空速计情况 在使用空速计的情况下,升降舵是由空速控制。update_current_flight_mode( )调用calc_nav_pitch( )调用nav_pitch = -g.pidNavPitchAirspeed.get_pid(airspeed_error, dTnav)。

APM自动调参讲解

使用自动调参来自动调试 Contents [hide] ? 1 使用自动调参来自动调试 ? 2 自动调参都干什么 ? 3 设置自动调参模式 ? 4 在自动调参模式下飞行 ? 5 别太早停止 ? 6 完成调试 ?7 自动调参日志 ?8 手动调参 VS 自动调参 用APM:Plane的3.0.2发行版的固件,使用者现在可以使用心得自动调参模式,来调适roll和pitch。对于大部分飞机的大多数调试参数,这可以更简单地获得一个起始的合理调试。 自动调参都干什么 自动调参模式是一种飞行模式,与飞FBWA模式相同;但是它通过操纵者的飞行姿态输入的变化,来了解roll和pitch的关键值。所以操纵者可以将遥控器上的模式切换开关切换到自动调参模式,然后飞几分钟飞机。飞行的时候,操纵者需要尽可能多地进行姿态剧变,让自动调参代码可以了解飞机如何反应。 设置自动调参模式 你需要将自动调参模式选为你的遥控器上的飞行模式切换开关能选择的模式来给你的飞机设置自动调参。

你也应该设置AUTOTUNE_LEVEL参数来选择调适的等级,这个参数在你的地面站的高级参数页面里。 AUTOTUNE_LEVEL参数控制了你想要的调适的灵敏度。默认等级是5,这提供了一个很柔和的调适,很适合新手操控者。如果你是一个老手,那你应该选择等级6或者等级7,这会使调适更灵活(更快的姿态改变)。如果你还没有以低于7的等级完成一个起始的调适,高于7的等级是不推荐使用的。因为自动调参模式现在仍是实验性的,我们现在不推荐尝试高于8的等级。 你还需要确认你的飞行器的基础设置都正确了。尤其是确认所有舵面的反向开关都正确了,而且你设置的最低空速合理(自动调参只在飞机空速大于你设定的最低空速时进行)。同时确认你完成了遥控校准,因为只有使用遥控器摇杆能获得全控制行程时,自动调参才会工作。 其他需要确认的东西: ?如果你使用空速计,请确认它工作并且已经完成校准。请查看空速校准。 ?检查重心,确认在手动飞行飞机的时候重心正确。 ?检查舵面微调。你可能想在看完关于TRIM_AUTO选项的文件之后使用这个选项。 ?确认正确设置了失控保护。请尝试将你的飞机放在地上并且关闭遥控器(并且卸下螺旋桨或者做相关安全保护措施)然后检查飞机如何反应。 ?设置一个安全的返航集合点,如果需要的话。

APM for PX4飞控使用手册-第一章:起步-中文翻译

APM for PX4飞控使用手册 第一章:起步——sw笨笨翻译 1.介绍:3D Robotics的开源飞控技术解决方案 APM:Copter,带有高级组织形式的个人自动导航仪技术,能够为飞行器带来易用的自主飞行能力。本手册可以带领您进行第一次的设置、调参和飞行活动。 2.什么是APM:Copter系统 APM:Copter是一种基于APM飞控板和Mission Planner地面站软件的多用途无人系统。APM飞控通过内置的陀螺仪、加速度计和其他电子元件控制多旋翼的飞行。在地面站计算机上使用Mission Planner定制飞行任务并下载到APM。一旦飞行器进入自主飞行模式,APM从GPS模块读取位置信息并执行任务脚本。为了安全起见,APM需要连接一个遥控器,用于对飞行器进行人工遥控。飞行

器使用锂电池作为电源,每次飞行要至少带两块电池。要使得飞行更加有趣,你可以搭载有效载荷:空中拍照,视频片段,或者你自己需要的任务设备。 试飞APM的基本步骤如下: 1)起步:了解APM:Copter以及无人机系统组成。 2)组装:建立你的旋翼系统,包含飞控和GPS模块。 3)地面站设置:在地面站计算机上安装Mission Planner,并向飞控板上传固件。4)设置遥控器:建立遥控器与飞控的连接,设置飞行模式,启动传感器。5)调参(DIY需要):校准电调,核对电机的旋转以及旋转方向,校准性能并调参。 6)建立飞行任务:Mission Planner介绍,创建导航点,下载任务。 7)飞行:启动测试飞行,安全飞行,飞行策略,飞行检验,和应急程序。3.系统构成 要使用APM:Copter你需要如下设备: 1)多旋翼飞行器 (前两句广告略——译者注)新手比较适合使用四旋翼飞行器,相关需求成本较低,使用简单。六旋翼飞行器比四旋翼飞行器稳定,带载荷能力较强。Y6型六旋翼飞行器飞行效率较常规六旋翼略低,但是更加稳定,设计更加有利于前置摄像机,并且能够在单发动机失效的情况下提供裕度。

相关主题