Robotics Institute 

University of Michigan, Ann Arbor

© 2017 by Bruce Personal Website. 

Updated on 8/21/2017

Arduino Code of MAVLINK_READ

January 21, 2016

#include <EEPROM.h>
#include <FastSerial.h>
#include <AP_Common.h>
#include <AP_Math.h>
#include <math.h>
#include <GCS_MAVLink.h>
#include <LiquidCrystal.h>  
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//
static boolean      mavbeat = 0;
static uint8_t      apm_mav_system; 
static uint8_t      apm_mav_component;
static uint8_t      osd_mode = 0;
static uint8_t      base_mode=0;
static bool         motor_armed = 0;
static bool         bGotHome = 0;
static uint8_t      osd_nav_mode = 0; 
static float        osd_vbat_A = 0;                 // Battery A voltage in milivolt
static int16_t      osd_curr_A = 0;                 // Battery A current
static uint8_t      osd_battery_remaining_A = 0;    // 0 to 100 <=> 0 to 1000
static float        osd_alt_gps = 0;                    // altitude
static float        osd_lat = 0;                    // latidude
static float        osd_lon = 0;                    // longitude
static uint8_t      osd_fix_type = 0;               // GPS lock 0-1=no fix, 2=2D, 3=3D
static uint8_t      osd_satellites_visible = 0;     // number of satelites
static uint16_t     osd_cog;                        // Course over ground
static uint16_t     eph = 0;
static float        osd_airspeed = 0;              // airspeed
static float        osd_groundspeed = 0;            // ground speed;
static float        osd_heading = 0;                // ground course heading from GPS
static uint8_t     osd_throttle = 0;               // throtle
static float        osd_alt_rel = 0;                    // altitude
static float        osd_climb = 0;
static int16_t       osd_pitch = 0;                  // pitch from DCM
static int16_t       osd_roll = 0;                   // roll from DCM
static int16_t       osd_yaw  = 0;
static int16_t        wp_target_bearing = 0; // Bearing to current MISSION/target in degrees
static uint16_t     wp_dist = 0; // Distance to active MISSION in meters
static float        xtrack_error = 0; // Current crosstrack error on x-y plane in meters
static uint8_t      wp_number = 0; // Current waypoint number
static uint16_t     chan1_raw = 0;
static uint16_t     chan2_raw = 0;
static uint16_t     chan3_raw = 0;
static uint16_t     chan4_raw = 0;
static uint16_t     chan5_raw = 0;
static uint16_t     chan6_raw = 0;
static uint16_t     chan7_raw = 0;
static uint16_t     chan8_raw = 0;
static uint8_t      osd_rssi = 0; //raw value from mavlink
static unsigned long mavLinkTimer = 0;
static float        osd_home_lat = 0;               // home latidude
static float        osd_home_lon = 0;               // home longitude
static long         osd_home_distance = 0;          // distance from home
//pin
static uint16_t buttonPin_Left=3,buttonPin_Right=4;
static uint16_t buttonState[4]={0,0,0,0};
static unsigned long buttonTime = 0;

//volt
static uint8_t volt_Pin=A0,VoteIdx=0,DspIndex=0,voltAdj=100;
static uint16_t volt_ary[20],VoteTotal=0,idle_Count=0;
static unsigned long idleTime = 0,voteTime=0,lastMAVBeat=0;

FastSerialPort0(Serial);
//---------------------------------------------------------------------------------------------------------
void setup()
{
  Serial.begin(57600);
  mavlink_comm_0_port = &Serial;
  lcd.begin(16, 2); 
}
void loop() 
{
 read_mavlink();
 volt=ReadVolt();
 lcd.clear();
 lcd.setCursor(0,0);
   lcd.print(osd_roll);
    delay(100);
}
 

Please reload