Skip to content

Bebop 2 4.7.1 QuadMixRPMController: input roles (static analysis only)

Binary: rootfs/usr/bin/dragon-prog (ARM32, stripped). All addresses are vaddrs (file offset = vaddr - 0x10000 in the first LOAD). Method: llvm-objdump full disassembly, Ghidra (port 8192, read-only), PC-relative string resolution scripts in the scratchpad (strs.py, xr.py). Nothing was executed. Labels: EVIDENCE = read directly from disassembly/strings/config. INFERENCE = my reading, not directly proven.

0. Re-verification of the earlier agent’s claims

Section titled “0. Re-verification of the earlier agent’s claims”
  • Mixer process function 0x2a6e98: CONFIRMED. EVIDENCE: four callers 0x231378, 0x235848, 0x22eae0 and a tail-call thunk at 0x151058 (all do bl 0x1036a8; add r0,r0,#628; bl 0x2a6e98, so the mixer object lives at singleton+628). llvm-objdump labels the address videoAngleRef::initOutput+0x15f38 (nearest symbol, wrong); Ghidra has no function there. The function does what the earlier agent said (sqrt term, linear terms, clamp, desaturation loop).
  • Matrix builder 0x2a78d0: CONFIRMED (called twice from 0x2a8990 at 0x2a8ae4 and 0x2a8d08).
  • “Config reader 0x2a63b0”: PARTLY. It is a shared reader of the motorsParameters block (10 classes xref the “motorA” string at 0x4b64e8), not the mixer’s own config. The mixer’s config sub-struct is built by 0x2b251c (strings: motorsParameters, adcFs, motorsCommandsSlopeForBraking).
  • “Final floats truncated to 16 bits at 0x4177ec”: the address is real but it is NOT in the mixer. It is virtual slot 3 of BLDCMotorController (vtable symbol _ZTVN7Colibry19BLDCMotorController19BLDCMotorControllerE at 0x57a000; slots from 0x57a008 are 0x41781c, 0x4178cc, 0x41762c, 0x4177ec). Ghidra puts “0x4176bc” there as a std::string function because there is no function boundary at 0x4177ec. The mixer itself stores clamped FLOATS.
  • Motor model values: as quoted by the earlier agent (etc/colibry/milosboard/drone.cfg motorsParameters: mass 0.5, Jx 0.001491, Jy 0.001458, Jz 0.003328, rpm 3000..12200, motorA 2.15e-8, motorB (-,+,-,+) 2.85e-10, motorJp 7.94e-6, motorBeta -pi/2, X/Y/Z as given, rpmErrorMargin 1.0).

1. Object layout and the inputs (EVIDENCE: ctor 0x2b2e5c, input sub-ctor 0x2ac19c, output 0x2afba8, params 0x2b251c)

Section titled “1. Object layout and the inputs (EVIDENCE: ctor 0x2b2e5c, input sub-ctor 0x2ac19c, output 0x2afba8, params 0x2b251c)”

Mixer ctor 0x2b2e5c builds three sub-structs: inputs at this+0xc (0x2ac19c), outputs at this+0x28 (0x2afba8), params at this+0x40 (0x2b251c), plus a node control.uSat (type Vector6f, string 0x4cd078) cached at this+0x50.

Input slots (strings resolved from 0x2ac19c; slot order = order of calls in the ctor):

this+ DataManager node Use in 0x2a6e98
0xc control.angularAccelerationRef (vec3) torque channels
0x10 control.weightAccelerationRefBody tilt-compensated thrust
0x14 control.weightAccelerationRefNED base thrust
0x18 control.altitudeAccelerationRefBody altitude correction thrust
0x1c estimation.gamma divisor (kg^-1)
0x20 processedSensors.baro.airDensity only in coefficient rebuild 0x2a8990 (scale = rho/1.225 clamped to [0.5, 2.0])
0x24 control.motorMaxCommandsRPM (4 floats) upper RPM clamp

Outputs (0x2afba8): control.W2u, control.w2u, control.dw2u, control.motorsCommandsRPM, control.commandsAreSaturated, control.wff (this+0x28..0x3c, six pointers). EVIDENCE for the two the process function writes: [this+0x34] receives the 4 clamped RPM floats (0x2a7474-0x2a7488), [this+0x38] receives a byte (strb r11 at 0x2a749c).

The six-vector u (= control.uSat, at [this+0x50]), built at 0x2a6ef4-0x2a6f50 (EVIDENCE)

Section titled “The six-vector u (= control.uSat, at [this+0x50]), built at 0x2a6ef4-0x2a6f50 (EVIDENCE)”
u index value source
u0 -weightAccelerationRefNED vneg at 0x2a6f10
u1 angularAccelerationRef[0] ldr [r2]
u2 angularAccelerationRef[1] ldr [r2,#4]
u3 -(weightAccelerationRefBody - weightAccelerationRefNED) = NED - Body 0x2a6f2c-0x2a6f3c
u4 angularAccelerationRef[2] ldr [r2,#8]
u5 -altitudeAccelerationRefBody vneg at 0x2a6f4c

Per-motor RPM model (EVIDENCE, 0x2a6f64-0x2a719c)

Section titled “Per-motor RPM model (EVIDENCE, 0x2a6f64-0x2a719c)”
  • term0_i = sqrt(u0 * K0_i / gamma), K0 = this+372..384
  • term1_i = u1 * N[i][1] (this+452..464), term2_i = u2 * N[i][2] (468..480), term4_i = u4 * N[i][3] (484..496)
  • term3_i = u3 * N[i][0] / gamma, term5_i = u5 * N[i][0] / gamma (N col0 = this+436..448, shared by u3 and u5)
  • rpm_i = sum of the six terms (stored at this+84+16k+4i), clamped to [params+32+4i, *(this+0x24)[i]] (lower bound ldr [lr,#32+4i] at 0x2a718c; upper bound is input 0x24).

How K0 and N are produced (EVIDENCE, 0x2a8990 and builder 0x2a78d0):

  • Builder column j (one motor), thrust axis u = (cos(beta)cos(alpha), cos(beta)sin(alpha), sin(beta)): F = A_ju, torque = r x F + B_ju. Rows stored: row0 = Fz, row1 = tau_x/Jx, row2 = tau_y/Jy, row3 = tau_z/Jz (divisions by params +4,+8,+12 at 0x2a7a48-0x2a7a50). Row order is therefore (thrust, roll, pitch, yaw). Params offsets (+0 mass, +4/8/12 J, +32 rpmMin, +48 A, +64 B, +80 Jp, +96 alpha, +112 beta, +128 X, +144 Y, +160 Z, +176 margin) are INFERRED from the cfg file order; they fit every use I checked.
  • M1 = build(A, B), inverse stored at this+372 (4x4). K0 = first 4 floats = M1^-1 column 0. At init the hover RPM is sqrt(mass * K0 * -9.81) (0x2a8ba8-0x2a8c1c; constants 0xc11cf5c3 = -9.81 and 0x3f9ccccd = 1.225 at 0x2a8c34 and 0x2a8c30).
  • M2 = build(2A_jrpmHover_j, 2B_jrpmHover_j) (linearisation, 0x2a8cc8-0x2a8d04), plus G (this+308, rotor-inertia matrix), inverse stored at this+436 (4x4, column-major). N = (M2+G)^-1. Columns of N correspond to rows of M: col0 thrust, col1 roll, col2 pitch, col3 yaw.
  • Numerical check I ran with the cfg numbers (numpy, G ignored): hover RPM 7552 for all four motors (inside 3000..12200); N col0 = -769.8 RPM/N; col1 (roll) = (+9.98,-9.98,-9.98,+9.98); col2 (pitch) = (+12.83,+12.83,-12.83,-12.83); col3 (yaw) = (+193.3,-193.3,+193.3,-193.3). Sqrt term check: u0 = -9.81, K0 about -1.16e7, gamma = 2 gives 7552 RPM, which matches the 1/mass reading of gamma.
u Role Evidence
u0 Collective thrust, nonlinear (sqrt) base term. Producer writes +9.81 (0x411cf5c3) in 0x2b95d0, so u0 = -9.81 at hover (negative because thrust is along -z). 0x2a6f10, sqrt at 0x2a6f7c; 0x2b95d0
u1 Roll angular acceleration demand (about +x) N/G row order; G row1 uses u_x and Jx (0x2a7ac8-0x2a7ad4); rotor-inertia pass adds G row1 to u1 (0x2a7620-0x2a7630, 0x2a76a4)
u2 Pitch angular acceleration demand (about +y) same, row2/Jy, added to u2
u3 Extra thrust for tilt: NED - Body weight accel (<= 0 when tilted, so it ADDS thrust). Linearised through N col0 / gamma 0x2a6f2c-0x2a6f3c; producer 0x2b980c
u4 Yaw angular acceleration demand (about +z) same, row3/Jz, added to u4
u5 Altitude-loop thrust correction (body frame), linearised through N col0 / gamma 0x2a6f4c; producer 0x2b97a0

So thrust/lift = u0 + u3 + u5 (all through the thrust column of the inverse; only u0 goes through the sqrt). Roll/pitch/yaw torque = u1 / u2 / u4 in that order. I found no reason for the interleaved order (thrust, roll, pitch, thrust, yaw, thrust); it is what the code does.

Rotor-inertia pre-pass (only when motorJp != 0; flag [this+0x4c] set at 0x2a8ac4): takes the previous-cycle RPM ([this+596..608], floored at rpmMin) times G rows 1..3 (this+312.., 316.., 320..), ADDS the result to u1, u2, u4 before the loop (0x2a76a4-0x2a76b4) and SUBTRACTS it again at the end (0x2a74a0-0x2a74ac). INFERENCE: models rotor spin-up torque so that (M2+G) rpm_new = u + G rpm_prev. G is built at 0x2a7a64-0x2a7b18 via unknown helper 0x23f86c.

Controller registration order in 0x1536d4 (name string, then the next ctor call; EVIDENCE): QuadQuaternionLoopController (ctor 0x29a22c, obj at manager+252), QuadSpeedLoopController (0x2eab38, +396), HeightLoopController (0x2c2c88, +448), QuadMixRPMController (0x2b2e5c, +628), QuadAngleInputController (0x2a0298), …, BLDCMotorController (0x41af3c, heap object stored at manager2+0xfdc), PWMMotorController (0x417550).

  • angularAccelerationRef: output of QuadQuaternionLoopController. EVIDENCE: ctor 0x29a22c calls 0x2941f8 (declares control.angularAccelerationRef) with r0 = this+36; the process function 0x291958 writes three clamped floats through *(this+0x24) (decompile tail: pfVar2 = *(float**)(param_1+0x24); *pfVar2 = ..; pfVar2[1] = ..; pfVar2[2] = ..). Each component is (several gain-weighted terms of the quaternion error x/y/z) clamped by the struct at this+0x34. Component 0 takes gain word [4] (phi), component 1 word [0] (theta), component 2 word [8] (psi). INFERENCE: gain-struct word order follows gainsQuaternionSet in controller.cfg (theta, phi, psi blocks), so component 0 = roll, 1 = pitch, 2 = yaw. That agrees independently with the N/G row order. controller.cfg names: thetaKP 264.74, phiKP 242.54, psiKP 300.0 (Default set).
  • weightAccelerationRefNED, weightAccelerationRefBody, altitudeAccelerationRefBody (and altitudeAccelerationRefNED, unused by the mixer): outputs of HeightLoopController. EVIDENCE: ctor 0x2c2c88 calls 0x2ba0c4 at this+52 (0x34); 0x2ba0c4 declares in order weightAccelerationRefNED (0x34), altitudeAccelerationRefNED (0x38), altitudeAccelerationRefBody (0x3c), weightAccelerationRefBody (0x40). Process variants, all called at manager+448:
    • 0x2b95d0: sets NED, Body and this+0xa4 to 9.81 (0x411cf5c3).
    • 0x2b9a6c: PI loop (error = [0x10]-[0xc], integrator at this+0x9c clamped by 0x23f828, adds feedforward), writes altitudeAccelerationRefNED to *(this+0x38).
    • 0x2b97a0: altitudeAccelerationRefBody (*(this+0x3c)) = clamp(1/sqrt(*(this+0x24))) * this[0xa0].
    • 0x2b980c: weightAccelerationRefBody (*(this+0x40)) = clamp(1/sqrt((this+0x24))) * this[0xa4], clamped to [(this+0x4c), *(this+0x50)]. INFERENCE: *(this+0x24) is cos^2 of tilt, so Body = NED / cos(tilt) and u3 = NED - Body is an added thrust.
    • 0x2b9b64: hold mode, NED = Body = input [0x84], altitude outputs 0.
    • 0x2b9578 and 0x2b9610: takeoff/landing ramps. Normal flight sequence at 0x22eaac-0x22eb48: HeightLoop 0x2b9a6c, 0x2b97a0, 0x2b95d0 (at +448), quaternion loop 0x291958 (+252), then mixer 0x2a6e98.
  • estimation.gamma: not produced here. EVIDENCE: etc/colibry/common/estimator.cfg lines 153-160, units kg^-1, min 1.0, max 3.0, init covariance 0.0667. With mass 0.5, about 2, consistent with u/gamma = force.
  • motorMaxCommandsRPM: declared together with control.motorsCommandsPWM and processedSensors.motorSpeedsRPM in the classes at 0x3a6e84 and 0x3b21d8 (strings at 0x3a6f80/0x3a7014 and 0x3b2548/0x3b2978). Not traced further.

EVIDENCE from builder 0x2a78d0 unless marked.

  • Thrust axis for every motor: alpha = 0, beta = -pi/2, so u = (0,0,-1). Thrust is along -z, so the frame is z-down. The torque is a literal cross product r x F (vnmls at 0x2a7a28-0x2a7a30), so the frame is right-handed.
  • Roll: tau_x,i = Y_i * Fz_i = -A*Y_i. Motors with Y = -0.115 (0 and 3) give +tau_x; motors with Y = +0.115 (1 and 2) give -tau_x. Positive roll about +x lowers the +y side. INFERENCE: with x = nose (FRD), +y is the right side. The mixer arithmetic does not by itself say which end is +x.
  • Pitch: tau_y,i = +A*X_i. Motors with X > 0 (0 and 1) give +tau_y, which raises the +x end (nose-up if x = nose; INFERENCE as above).
  • Yaw: builder adds B_i*u_z with u_z = -1, so tau_z,i = -B_i (the r x F part is zero). With motorB = (-,+,-,+) x 2.85e-10: motors 0 and 2 give +tau_z, motors 1 and 3 give -tau_z (0x2a7a2c-0x2a7a44, and N col3 pattern (+,-,+,-) from the numpy check).
  • Sign table (thrust row, roll, pitch, yaw):
    • motor0 (X+, Y-, B-): -A, +, +, +
    • motor1 (X+, Y+, B+): -A, -, +, -
    • motor2 (X-, Y+, B-): -A, -, -, +
    • motor3 (X-, Y-, B+): -A, +, -, -
  • Yaw convention: positive u4 (angularAccelerationRef[2]) is a +z (z-down) torque demand; in FRD that is nose-right, clockwise from above. It raises motors 0 and 2 and lowers 1 and 3 (N col3). This holds if B enters as torque on the body, which is how the builder uses it. Physical rotor spin direction cannot be derived from the mixer alone.

4. Desaturation priority order (answer to Q3)

Section titled “4. Desaturation priority order (answer to Q3)”

Loop at 0x2a7148-0x2a72e8 plus branches 0x2a7508, 0x2a7568, 0x2a74e0, 0x2a75bc (EVIDENCE, traced instruction by instruction). Per iteration for motor i (cycling 0..3): total_i = sum of the six terms; over = total_i > max_i + margin; under = total_i < min_i - margin (margin = params+176 = rpmErrorMargin). State: r0 = channel index being modified, starts at 5 and only decreases; r5 = iteration counter (stop after 99); r1/r12 = sweep counters; r11 = saturated flag.

  • Over and term_r0[i] > 0: if excess < term, rescale channel r0 so motor i lands exactly on the limit, u[r0] = (term - excess) / C[r0][i], then recompute that channel’s four terms as C[r0][j]*u[r0] (0x2a7508-0x2a7554). C = 6x4 table at this+500 (copies of the N columns, built 0x2a8ed4-0x2a8f80). If the term cannot absorb the excess, set u[r0] = 0 and zero its term row (0x2a7228-0x2a724c), then r0 -= 1 and re-test the same motor.
  • Over and term_r0[i] < 0 (cannot help): next motor, r12 = 1.
  • Under-limit case is the mirror image (needs a negative term to shrink).
  • After four consecutive “ok or cannot help” motors with r12 = 1, r0 is decremented (0x2a727c-0x2a729c); with r12 = 0 the loop ends. It also ends when r0 < 0 or after 99 iterations.
  • control.commandsAreSaturated = r11 = 1 as soon as any scaling/zeroing step happened (set at 0x2a7258, stored by strb at 0x2a749c).

Sacrifice order is by u index DESCENDING: u5 (altitude correction) first, then u4 (yaw), u3 (tilt thrust), u2 (pitch), u1 (roll), and u0 (weight/hover sqrt term) last. Yaw is shed before pitch and roll. After the loop control.uSat (this+0x50) holds the reduced channel values with the inertia pre-add removed on u1, u2, u4 (0x2a7490-0x2a74b0). Caveat (INFERENCE): the C table is the raw N column without the 1/gamma that live terms u3 and u5 carry, and for u0 the live term is a sqrt while the desat treats it as linear. When gamma != 1 the “land exactly on the limit” rescale for u3/u5 is not exact, so the loop iterates. u0 is reached last, so this probably rarely matters.

5. Where the per-motor values go (answer to Q4)

Section titled “5. Where the per-motor values go (answer to Q4)”
  1. Mixer end (EVIDENCE 0x2a73b4-0x2a7488): clamped RPM floats are stored at this+596..608 (next cycle’s “previous RPM”) and copied to *(this+0x34) = control.motorsCommandsRPM (4 floats).
  2. BLDCMotorController (name at 0x4bda90; ctor 0x41af3c; input struct 0x4179a8 declares control.motorsCommandsRPM as VectorNbMotorsf at +0x10; output struct 0x418924 declares actuators.halCommand (HAL_command_t with command.motors_speed etc.) at +0x14). Process = vtable slot 3 = 0x4177ec (EVIDENCE): for 4 motors vcvt.s32.f32 (truncate toward zero) then strh into the int16 array at *(outputs+4). No scaling and no saturation: RPM as signed 16-bit integers. Slot 2 (0x41762c) writes four zero halfwords.
  3. Hand-off function: 0x43d060 (libHAL layer; contains the string “libHAL’s HAL_send_motor_command() : error HAL_motor_write : %d” at 0x4fdc78, xref 0x43d23c). Called from ACQCON_colibry_Thread_Handler (0x4dd18, exported) at 0x4e12c with HAL object [r8+0x228]. It locks a mutex, copies the halfword motor array (strh loop at 0x43d0c8) and calls 0x440fe0, 0x440fe8, 0x43f740, 0x43f6c4 (HAL_motor_write variants). HAL_BLDC_set_ref_speed strings are used in 0x444934 (xrefs 0x444a7c-0x444b28). Stopped here; the I2C protocol is the other agent’s scope.
  4. PWMMotorController (ctor 0x417550, process area 0x41542c) is the alternative path (motorsCommandsRPM to motorsCommandsPWM via pwmMotorsModel). Log strings “colibry send motor command of RPM type” (0x4bdaa4) and “… PWM type” (0x4bdae0), referenced from 0x1536d4, suggest the choice is made at registration. Not traced.
  1. Which motor-output class runs on milosboard (BLDC vs PWM) and the registration condition near 0x158014.
  2. Producer and meaning of control.motorMaxCommandsRPM (classes 0x3a6e84 and 0x3b21d8).
  3. Whether +x is physically the nose and the physical motor numbering (FL, FR, RR, RL is my inference from X/Y signs under an FRD assumption). Rotor spin direction versus the sign of motorB is not derivable from the mixer alone.
  4. Meaning of *(HeightLoop+0x24) (cos^2 of tilt is a guess) and which inputs feed 0x2b9a6c (HeightLoop inputs +0xc, +0x10, +0x14, +0x2c not mapped).
  5. G matrix formula: builder branch 0x2a7a64 calls unknown helper 0x23f86c and reads a scalar through [r5+0x44]; not decoded.
  6. Whether anything outside the mixer consumes control.uSat (only the mixer’s own string reference at 0x2b2f10 was found).
  7. Role of control.W2u, w2u, dw2u and wff (declared at 0x2afba8; 0x2a6e98 writes only motorsCommandsRPM and commandsAreSaturated).
  8. HAL_motor_write internals after 0x43d060 and how actuators.halCommand reaches HAL object [r8+0x228] in the ACQCON thread.
  9. Helper identities 0x77f8c (aligned free), 0x77b08 (aligned malloc), 0x2a83f0 (4x4 inverse into the destination argument) are read from call context only.

Comments

Spotted a mistake, or tried this on your own Bebop? Leave a note. Comments are kept on this site's own server.