Monday, August 14, 2017

PX4FMU + PX4IO + ArduCopter firmware + some VERY useful tricks.

Basic concepts

First of all you should understand, that flight controller is basically set of inputs and outputs. Firmware lets you assign specific function to specific input or output. Remember it, it's important.

/!\ Important note. You can NOT use Arducopter firmware on PX4FMU without PX4IO extension board. (Thanks guys! This hardware is really paying for itself :) )

Hardwiring

In my case I have:
 - PX4FMU + PX4IO stacked on each other,
 - (1) 3D SimpleBGC controller,
 - (2) 3DR (clone) GPS + Compass module,
 - (3) 3DR power module,
 - (4) I2C LED + USB + Buzzer + I2C splitter module,
 - (5) FrSky TFR4: 7PPM + 1 RSSI.
* Numbers are because it's lazy for me to print names over and over again.


General considerations

It is useful to know, that your barometric sensor will work much better if no direct sunlight or wind will hit it. To achieve this, you should simply put piece of foam rubber on top of it.

/!\ IMPORTANT notice for those who assemble firmware manually.
PX4 board should be mounted "upside down", there is a sign "this side up" on the board. The thing is, that in this case sensor becomes inverted and you see ^ sign in mission planner wrong way.
To correct this you should set AHRS_ORIENTATION parameter to 8. This will flip sensor by 180 degrees roll.

(1) Is connected in very specific way

/!\ Most of people who read manuals should be aware, that SimpleBGC works better when it has feedback from flight controller (FC).
Now, I wanted to have FC feedback AND at the same time can use my Ch6 rotating knob to turn camera up and down. The thing is that either you have FC_PITCH from FC or from Ch6.
Here what I did, I put:
Mission planner (initial setup -> optional hardware -> gimbal config)
FC_ROLL -> Ch6 (Roll), stabilize roll: check
FC_PITCH -> Ch5 (Tilt), stabilize tilt: check
RC_PITCH -> Ch7 (Pan) and also Input Ch: Ch6, stabilize pan: unchek.
( i ) Ch5 and Ch7 tilt range better be the same.

Gimbal config soft (RC settings)
RC input mapping
PITCH -> RC_PITCH - PWM (this allows us to turn camera with ch6)
FC_ROLL -> EXT_ROLL - PWM
FC_PICH -> EXT_PITCH - PWM

RC control
Pitch should be in "Angle mode" to follow Ch6 knob rotation.

Basic
Then you should do External FC Gain regulation (assuming you already tuned your PIDs).

(2) Is simple

GPS goes to UART6 port on the back of PX4FMU.
Compass is connected in I2C splitter of (4).

(3) Power module is a bit tricky

Arducopter APM 2.6
Here's best picture I could find. For those who's not fluent in Russian: 4 is Voltage and 3 is current. Rest is self explanatory. 

( i ) when using PX4IO to power your FC, board reads voltage from built in BEC input. (aka pin 100).

PX4FMU + PX4IO - flight controller + expansion board
In my case, I used pin 10 to read current from power module (i.e. connected yellow wire to pin 10).
Then in mission planner -> Config tuning -> Full parameter tree, set: 
BATT_CUR_PIN: 10

I did not use Pin 101 because I could not get it to show anything. 
PX4IO - PX4 expansion board

(4) Too easy

Everything is straightforward. 
I2C -> to I2C port on PX4IO,
Buzzer to PX4FMU near SD,
Button to PX4IO near power plug.
And get rid of USB cables, because it's excessive weight.


PX4, Pixhawk, APM external RGB LED meaning


RGB LED indicationMeaning
●●Flashing blueDisarmed, no GPS lock
●●Solid blueArmed, no GPS lock
●●Flashing greenDisarmed, GPS lock acquired
●●Fast flashing greenDisarmed, SBAS GPS lock acquired (better)
●●Solid greenArmed, GPS lock acquired
●●Single flashing yellowRadio failsafe activated
●●Double flashing yellowPreArm checks failed
●●Flashing yellow with beeping toneBattery failsafe activated
Flashing yellow, blue with quick toneGPS failsafe activated
Flashing red, yellow with rising toneEKF or Inertial Nav failure
Flashing purple, yellowBaro glitch
●●Solid redError
●●Solid red with SOS toneSD card error/missing



(5) Now the "sexy" part

Connecting PPM to PPM port on PX4IO is easy. Tough task is to make RSSI work. 
Issues:
1. FrSky TFR4 claims to have RSSI (PWM) on this port, but it gives me analog voltag which is proportional to signal strength and has range of +3V to +0.05V. Although it was no problem on APM 2.6, PX4 refuses to accept this signal (at least on SBUS port).
2. With a bit of experiments I found that my PX4 accepts RSSI on pin 13 (see figure above).
The issue is that it always shows me 100% and I have a feeling that it's not linear but parabolic. I.e. when I turn off radio, signal is falling, but it really lacks resolution in top (100%) segment.


Hacking

Now techie part. I had 3-d channel burned on my PX4IO, so it was pretty useless on quad or any other copter. Back then I had an idea to switch channels, say 3 to 8 and 8 to 3.
This way I could use Quad, Hexa, and gimbal configs along with many others. 
Quck search told me that people who had such problems lack programming skills or desire to share their results. 
Long story short: I found what and where to change.


Where

Happiness is in: libraries/AP_Motors/AP_Motors_Class.h
assuming you are in root dir of your Arducopter source.

What

In my case, I moved all output channels one pin forward. I.e. physically I connect 1,2,4,5,6,7,8 but logically it's 1,2,3,4,5,6,7 channels. 
physical pinlogical chan
11
22
38
43
54
65
76
87
That's why output 3 (2U) jumped to AP_MOTORS_MOT_8 position.
#define AP_MOTORS_MOT_1 0U
#define AP_MOTORS_MOT_2 1U
#define AP_MOTORS_MOT_3 3U
#define AP_MOTORS_MOT_4 4U
#define AP_MOTORS_MOT_5 5U
#define AP_MOTORS_MOT_6 6U
#define AP_MOTORS_MOT_7 7U
#define AP_MOTORS_MOT_8 2U
#define AP_MOTORS_MOT_9 8U
#define AP_MOTORS_MOT_10 9U
#define AP_MOTORS_MOT_11 10U
#define AP_MOTORS_MOT_12 11U
Pretty simple. 
Compile, upload, rock-n-roll.
A bit information on "how to compile PX4 or ArduCopter firmware" is located here: http://p0rc0-r0ss0.blogspot.com/2015/05/px4-mkbl-esc-px4-software-stack.html

Links

http://ardupilot.org/copter/docs/common-px4fmu-overview.html
http://diydrones.com/forum/topics/how-to-connect-a-current-voltage-sensor-to-px4
http://ardupilot.org/copter/docs/common-leds-pixhawk.html

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> -...