Friday, November 24, 2017

Flip32/Naze quad controller hacking

I've always wanted to incorporate an inexpensive quad flight controller into this project.  I though I could use it as an autopilot.  Having hacked the Multiwii Serial Protocol (MSP) I now have some much bigger ideas about what it can do.

First... what is a quad controller... Here's a spec sheet for a $30 quad controller:

Flip32+ NAZE 32 10DOF Flight Control board
  • 36x36 mm
  • 3-axis MEMS gyro + accelerometer (MPU6050)
  • 3-axis magnetometer (HMC5883L)*
  • Pressure sensor (MS5611)*
  • Flexible motor outputs, support various airframe types
  • Up to 8 ch RC input-supports standard receivers(PWM), PPM Sum receiver
  • Battery voltage monitoring (up to 16vdc)
  • Modern 32-bit processor running at 3.3V/72MHz(STM32F103CB).
  • MultiWii-based configuration software for easy setup

This is a TON of sensors and a serious processors already supported by somebody else's firmware (I used Cleanflight) and it outputs on a USB VFR direct to an android tablet  running Avare open-source with updates to support it.

So to re-state the list above as fully supported features by somebody else;

  • IMU - Roll, Pitch, Magnetic Heading, Altitude, Variometer (vertical speed), Groundspeed
  • GPS - Supports interfacing with a GPS 
  • AutoPilot - 3-axis Giant-Scale R/C servo ready.  Built in heading-hold, altitude-hold, fly-to-position.
  • Precise Sonar Altitude HCSR04 ( <3.8-meters AGL for auto-land)
  • Battery Voltage

What it does not do that an aircraft would need...
  • Airspeed
  • Angle of Attack
  • Oil Temp
  • Oil Pressure
  • Cylinder Head Temp (x4 or x6)
  • Exhaust Gas Temp (x4 or x6)
  • Fuel Pressure
  • Fuel Flow
  • Fuel Level (x2-4)
  • Ammeter
  • Outside Air Temp

How do you communicate with the controller?  MSP.  For my tests I just wrote a simple C# console app that opened the serial port, sent an MSP_ATTITUDE request and extracted the response as pitch, roll and heading.

Sample:

bufView[0] = 36; // $
bufView[1] = 77; // M
bufView[2] = 60; // <.
bufView[3] = 0; // data length
bufView[4] = 108; // MSP_ATTITUDE
bufView[5] = (byte)(bufView[3] ^ bufView[4]); // checksum

do
{


port.Write(bufView, 0, 6);

System.Threading.Thread.Sleep(1);



// Preamble
if ('$' != port.ReadByte() ||
'M' != port.ReadByte() ||
'>' != port.ReadByte())
continue;

var length = port.ReadByte();
var codeT = port.ReadByte();
var buffT = new byte[length];

port.Read(buffT, 0, length);

var roll = (Int16)(buffT[0] + 256 * buffT[1]) / 10.0;
var pitch = (Int16)(buffT[2] + 256 * buffT[3]) / 10.0;
var yaw = (Int16)(buffT[4] + 256 * buffT[5]);

var crcCalc = (byte)(buffT.Aggregate((a, b) => (byte)(a ^ b)) ^ 
              length ^ codeT);

if (crcCalc != port.ReadByte())
  continue;

Console.WriteLine($"{roll}, {pitch}, {yaw}");

System.Threading.Thread.Sleep(200);
} while (true);


This is really just test code, but it shows how simple it is to send a request and get back some very basic data.  The full MSP spec is here.  This has a lot of possibilities and I will likely incorporate the controller into even a basic system because it adds so much for so little added complexity and cost.

Given the information I've learned, the system design is dramatically simpler...





No comments:

Post a Comment