Monday, May 25, 2015

PX4FMU + PX4IO + i2c MKBL ESC + PX4FLOW + ArduCopter

"It IS pretty difficult task to make horse bark" - p0rc0_r0ss0

Here I will try to accumulate knowledge on how to make all this tough and expensive hardware make worth money spent.
The road will be long and no one knows where would it lead, but we'll see.

/!\ IMPORTANT! Also see this newer article over here: http://p0rc0-r0ss0.blogspot.com/2017/08/px4fmu-px4io-arducopter-firmware-some.html
Contents of this article give additional information on PX4 + ArduCopter firmware setup.

First things first. Introductions.
  • PX4FMU - is "head" controller module made by Pixhawk guys.
    Key features: Large set of sensors, "all in one" 4 x PWM output style, with no standard servo plugs, powerful CPU, USB port.
  • PX4IO - is extension board which provides expansion up to 8 x PWM outputs, lots of relays and ports, PPM and S-Bus plugs, has it's own BEC.
  • PX4FLOW - is optical sensor with pretty powerful CPU and gyro sensor onboard. As result gives heading vector to FMU.
    Optionally can be equipped with sonar.
  • MKBL ESC - electronic speed controllers used in Mikrokpter project.
    Features: i2c and PWM control input.
  • ArduCopter - is OpenSource drone platform which incorporates virtually any type of vehicle. In this particular case we are talking about Copter branch.

Disclaimer

All information in this blog is for personal use only.

I do not deny it's use in educational purposes, but be aware, that you are using all the information found here on your own risk!




First things last but not least.

In the first place we need Mission Planner which can be found here (latest windows version). Optionally you can explore "downloads" section of ardupilotCom. 
IMPORTANT! Before you install any software, unplug your flight controller from USB.
NOTE. All board drivers are located in \Program Files (x86)\Mission Planner\Drivers directory.

To flash new firmware to your board (I have PX4) go to "Initial setup" -> "Install firmware" section, choose desired firmware and upload it. As this post is just a memo and not tutorial, I will not go deeper into flash process.
IMPORTANT! To flash PX4IO module, PX4FLOW sensor should be disconnected (especially if it is connected with UART and not i2c).

Now, I will not describe actions that could be done by following wizard.
NOTE. For comments on LED and Buzzer meanings, see troubleshooting section below.


Flashing PX4IO

Process is pretty straightforward. When your PX4FMU gets latest firmware it will flash and reboot PX4IO module. 
If for some reason you think, that process needs to be repeated, then:

  1. Disconnect all power from both boards.
  2. Press and hold "safety button" (the one with red LED in it).
  3. Power up system (in my case I power up PX4IO and it feeds PX4FMU and PX4FLOW via own BEC).
  4. Wait till all buzzing and singing action goes by. Completion signal should sound like two sequential "beep" tones.
  5. Release "safety switch".
That's pretty much it.


Flashing and wiring PX4FLOW module

PX4FLOW is flashed via own USB connector is as simple as pie. 
Wiring is pretty simple too, whole process is described here. Just in case I will provide a copy of main thought.
Pixhawk + PX4FLOW - optical flow gyro assisted sensor combined with ultrasonic sonar
The sensor should be connected to the Pixhawk’s the 4-pin I2C port.  In most cases an I2C splitter should be used to allow other I2C devices (like the external RGB LED and GPS/Compass module’s compass) to the same port.

NOTE. i2c splitter is just T wire without any additional electronics. As soon as i2c bus supports up to 127 devices on the same wires, we just need to make this wire connect to consumer. No switches, hubs and misc is needed.


Mounting to the Frame


Mount the flow sensor pointing straight down with the X axis forwards and the Y axis to the right. The FLOW_ORIENT_YAW parameter can be used to account for other yaw orientations. It is important that the flow sensor be mounted where it does not experience angular angular vibration that could blur the image.



NOTE. The default mounting orientation is different to that shown on the ETH PX4FLOW wiki. If you mount the board as shown in the ETH PX4FLOW wiki, you will need to set FLOW_ORIENT_YAW  to -9000.

The sensor can be enabled by connecting with the Mission Planner and then on the Initial Setup | Optional Hardware | Optical Flow page check the Enable checkbox.  Alternatively the FLOW_ENABLE parameter should be set to “1” through the full parameters list.  The sensor will be initialised once the Pixhawk board is rebooted.



WARNING! Disconnect the sensor I2C connection from your flight computer before you connect it to via USB to your computer, Otherwise the sensor will be trying to power the flight computer and it may not have enough voltage to work properly.


Troubleshooting


All Pixhawk products have several informational LEDs that signal what is going on now and then. On top of that, PX4IO expansion adds buzzer with it's sound tones.
Description of LED meanings can be found here.
And description of sound tones here.


Further troubleshooting is possible via log. To have sufficient log output connect to your board, go to Mission Planner -> CONFIG/TUNING -> Full parameter tree (it's convenient for me, you may go other way) and find LOG_BITMASK parameter. See tooltip and set number (only numeric values are allowed) according to how many log output do you want.


Then more we learn then less we know



APM/PX4 software stack anatomy


Don't expect too deep knowledge here, just saying basic things.
As I understand PX4 software consist of layers (Ogres have layers, PX4 soft has layers :) ).
First level is kernel with it's modules, it's function is to handle all the hardware and give away some standard control interface. Such technology is called HAL (hardware abstraction layer), mostly because control software has no need to know anything about hardware and can be ported to any compatible platform, no matter what hardware is there "under the hood".
Second level is control software that does all the math, estimations, controls, holds, loiters and gesundheits :).

MKBL ESC


Mikrokopter ESCs have two control options.
  1. Conventional PWM, which is de-facto RC world standard.
  2. i2c bus - which is much faster.
In first case, all you need is to connect PWM output of your PX4IO to PWM input of your ESC.
IMPORTANT! ESC, PX4 and other systems should have common "ground". One connection to ground per device is sufficient, try to avoid creating ground loops. 



I heard rumors that MKBL ESCs work worse on PWM that on i2c, I can not comment on that subject, but I try to use i2c myself.


To make all ESCs work on the same bus you should give each ESC it's own address. AFAIK MKBL ESC uses 3-bit addressing and allows up to 8 simultaneous ESCs connected.
As lucky as I am, my ESCs had jumpers to configure these addresses. Here is the table:



Addressdip1dip2dip3
1ononon
2offonon
3onoffon
4offoffon
5ononoff
6offonoff
7onoffoff
8offoffoff



MKBL ESC and APM mkblctrl

WARNING! Be sure to test all i2c MKBL configurations without props. While searching info on subject I often come across messages that upon power ON motors start to spin without any control input. i.e. by themselves.
THIS COULD BE DANGEROUS!


To setup APM for ESC use you have to create APM/mkblctrl file on your SD card.
Here's where the fun begin.
We have several information sources:

  1. PX4 wiki over here. Good thing is that they got motor i2c addressing, bad thing is that setup is described for PX4 not Arducopter.
  2. In his post on arducotperCom Marco Bauer writes that he has successfully used ArduCopter with i2c MKBL ESCs, bad thing is that there is no example of mkblctrl configuration file.
  3. During ArduCopter code build there is mentioned mkblctrl driver, but it never help to get closer to config file syntax.
  4. Here's how addressing happens on AfroESC board.

Just in case you want to test motors on PX4 board (not ArduCopter software stack. In fact it will work also, but they got rid of console in their firmware), be advised:

mkblctrl -t


This command will sequentially spin motors in order of their addressing. 

No comments:

VIM cheat sheet

Basic basics :) i - start editing, current symbol a - start editing, next symbol Esc - stop editing :w - write to disk :w <filename> -...