Wednesday, November 19, 2014

MAV_TYPE , MAV_AUTOPILOT

MAV_TYPE describe type of micro air vehicles ex. Quadrotor,Hexrotor,Fixed Wing


MAV_AUTOPILOT describe type of autopilot(Flight Controller board) 
ex. PIXHAWK,ArduPilotMega / ArduCopter


Ref:

Sunday, November 16, 2014

Arducopter Flight Mode

In HEARTBEAT( Msg id 0) consist of Flightmode stored in custom_mode field
but in MAVLink document didn't define this field because it depend on
which flight controller software was using in this case Arducopter
it was define in file "defines.h"

// Auto Pilot modes
// ----------------
#define STABILIZE 0                     // hold level position
#define ACRO 1                          // rate control
#define ALT_HOLD 2                      // Altitude Hold
#define AUTO 3                          // Waypoint
#define GUIDED 4                        // Hold a single location from command
#define LOITER 5                        // Hold a single location
#define RTL 6                           // return to launch
#define CIRCLE 7                        // orbit around a single location
#define LAND 9                          // Landing
#define OF_LOITER 10                    // Hold a single location using optical flow sensor
#define DRIFT 11                        // DRIFT mode (Note: 12 is no longer used)
#define SPORT 13                        // earth frame rate control
#define FLIP        14                  // flip the vehicle on the roll axis
#define AUTOTUNE    15                  // autotune the vehicle's roll and pitch gains
#define POSHOLD     16                  // position hold with manual override
#define NUM_MODES   17

Ref:

Thursday, November 13, 2014

Checking MAVLink Arm/Disarm Status


In HEARTBEAT( Msg id 0) consist of arm/disarm status but it not show directly
arm/disarm these stored in base_mode field describe by MAV_MODE_FLAG

HEARTBEAT Message Structure


MAV_MODE_FLAG

As you can see MAV_MODE_FLAG_SAFETY_ARMED 0b10000000 is arm/disarm bit
so we can write simple code to check arm/disarm status from base_mode like these



base_mode & MOTORS_ARMED) >> 7

output is 1 when armed, 0 when disarm

Ref :
https://pixhawk.ethz.ch/mavlink/

Wednesday, November 12, 2014

MAVLink MAV_DATA_STREAM from Board Ardupilot Mega 2

in MAVLink status from flight controller pack together in MAVLink Message
ex. Msg id #30 ATTITUDE consist of roll,pitch,yaw,roll speed,pitch speed,yaw speed

but in case of requesting these msg from flight controller we need to send request to flight controller for MAV_DATA_STREAM and frequency of these stream

MAV_DATA_STREAM  is collection of different msg id group together

MAV_DATA_STREAM 
(https://pixhawk.ethz.ch/mavlink/)

for Adupilot Mega 

RAW_SENSOR
(#27) RAW_IMU
(#29) SCALED_PRESSURE

EXTENDED_STATUS
(#1) SYS_STATUS
(#24) GPS_RAW_INT
(#42) MISSION_CURRENT
(#62) NAV_CONTROLLER_OUTPUT

RC_CH
(#35) RC_CHANNELS_RAW
(#36) SERVO_OUTPUT_RAW

POSITION
(#33) GLOBAL_POSITION_INT

EXTRA 1
(#30) ATTITUDE

EXTRA 2
(#74)VFR_HUD

EXTRA 3
(#2) SYSTEM_TIME

Ref :
https://pixhawk.ethz.ch/mavlink/

Sunday, November 9, 2014

Sending single precision floating point over serial

Single Precision Float (32-bit) in IEEE754 standard
consist of sign bit(1 bit),exponent(8 bits) and fraction(23 bits)

http://upload.wikimedia.org/wikipedia/commons/thumb/e/e8/IEEE_754_Single_Floating_Point_Format.svg/2000px-IEEE_754_Single_Floating_Point_Format.svg.png

using typedef union for merge float,byte array into same location

typedef union {
 float floatingPoint;
 byte binary[4];
} binaryFloat;

binaryFloat temp;
temp.floatingPoint = 3.1416;
Serial.write(temp.binary[3]);
Serial.write(temp.binary[2]);
Serial.write(temp.binary[1]);
Serial.write(temp.binary[0]);

Sunday, October 26, 2014

Install PyMAVLink Tool

PyMAVLink is Tool for Bindings MAVLink with Python and also provide number tools for data analysis MAVLink stream logs

Download
git clone git://github.com/mavlink/mavlink.git

For Ubuntu
sudo apt-get install python-matplotlib

After Install Mathplot install PyMAVLink
cd ~
mkdir -p src
cd src
git clone https://github.com/mavlink/mavlink/
cd mavlink/pymavlink
python setup.py install --user

After install PyMAVLink it will show path in status message.It may vary
example : $HOME/.local/lib/python2.6/site-packages/
Edit ~/.bashrc or ~/.bash_profile and add this line:

export PYTHONPATH="$HOME/.local/lib/python2.6/site-packages/:$PYTHONPATH"
export PATH="$HOME/.local/lib/python2.6/bin/:$PATH"

Reference
1.http://qgroundcontrol.org/mavlink/pymavlink
2.http://pixhawk.org/dev/pymavlink

Saturday, October 11, 2014

Fixing QT GUI font Issue on Linux,Windows


Windows 7 version

Ubuntu 12.04 LTS version

with same code of  PyQt application came out with different outcome
this issue case of different in default font family and font size 

fixing by define correctly font in code
self.setStyleSheet('font-size: 8pt; font-family: Tahoma;')

result after fixed problem

Ubuntu 12.04 LTS version (after fixed problem)




Wednesday, September 17, 2014

Update PyMAVLink Library

due lag of update in PyMAVLINK inside ardupilot-sdk-python

I decide to using PyMAVLink Library from MAVLink Github instead

git clone https://github.com/mavlink/pymavlink

this repository come with pre-generate MAVLink basic messages definitions from ardupilotmega.xml,common.xml
This was Simple code modified from mavtester.py (example in PyMAVLink Library) to demonstrate MAVLink Functional by received HEARTBEAT message from Arducopter Board(APM2)
#!/usr/bin/env python

'''
PyMAVLink Test

'''
import sys, os, time
from math import radians

import mavlinkv10 as mavlink
import mavutil

# create a mavlink instance
mav1 = mavutil.mavlink_connection("COM12", 57600)

print("Waiting for HEARTBEAT")
mav1.wait_heartbeat()

print("Heartbeat from APM (system %u component %u)" % (mav1.target_system, mav1.target_component ))

while True:
    mav1.recv_msg()
    #Do Somethings
    time.sleep(0.01)


But this code doesn't run correctly with library from MAVLink Github after examination found that mavutil.py from MAVLink Github looklike it make for support both MAVLink Version 0.9 and Version 1.0
Here are Part of code from mavutil.py

if os.getenv('MAVLINK10'):
    import mavlinkv10 as mavlink
else:
    import mavlink

So I have to set value for MAVLINK10 for make mavutil.py recognize to run MAVLink Version 1.0
Code after add command to set value of MAVLINK10
#!/usr/bin/env python

import sys, os, time
from math import radians

os.environ["MAVLINK10"] = "1" #Set Mavlink Version 1.0

import mavlinkv10 as mavlink
import mavutil


# create a mavlink instance
mav1 = mavutil.mavlink_connection("COM12", 57600)

print("Waiting for HEARTBEAT")
mav1.wait_heartbeat()

print("Heartbeat from APM (system %u component %u)" % (mav1.target_system, mav1.target_component ))

while True:
    mav1.recv_msg()
    #Do Somethings
    time.sleep(0.01)

Saturday, September 13, 2014

Getting started with ardupilot-sdk-python

This ardupilot-sdk-python provided basic function

Sent command to arducopter
arm(),disarm(),takeoff(),land(),flyTo()

Received arducopter status isArmed(),getMode(),getAttitude(),getAltitude(),getHeading(),getSpeed(),getLocation()

First Clone ardupilot-sdk-python from github
git clone https://github.com/drgowen/ardupilot-sdk-python

Adding function for getting Raw IMU in SDK
 def getIMU(self):
   if 'RAW_IMU' not in self.mav.messages:
     raise Error("Haven't received RAW_IMU information yet")
   att = self.mav.messages['RAW_IMU']
   return self.dictCopy(att, ['xacc','yacc','zacc'])


Example for get Attitude,Raw IMU from /dev/ttyUSB0 Baudrate:57600
from ardupilot import ArduPilot
import time as time_ #make sure we don't override time

def millis():
    return int(round(time_.time() * 1000))

ac = ArduPilot("/dev/ttyUSB0",57600)
#ac.arm()
#ac.disarm()
start_time = millis()
while(1):
   if(millis()-start_time > 200):
      print ac.getAttitude()
      print ac.getIMU()
      start_time = millis()     


Reference: https://github.com/drgowen/ardupilot-sdk-python