Repository navigation
Fix disable_servos() so servos actually go limp - #14
Conversation
disable_servo() only stops a port's control pulses; the 6 V servo rail stays on. Analog servos go limp without pulses, but digital servos, including the ones we use, keep holding their last position, so disable_servos() had no visible effect on them. PE10 drives the enable of U72, the one regulator for all four servo ports, but the firmware never configured it, so R52 kept the rail on. PE10 is now an open-drain output, and the main loop pulls it low when all four servo disable bits in REG_RW_MOT_SRV_ALLSTOP are set and releases it otherwise. Disabling a single servo still only stops its pulses, since the ports share the regulator. Servo power is now off at boot until a program enables a servo, and when a program exits, because libwallaby's cleanup disables all servos.
PE10 is now driven low at the top of init(), before init180MHz() waits for the crystal. The servo rail is on from reset until then, so this shortens the on/off blip after every reset. Servo power is now cut 40 ms after all four servos are disabled. The timer ISRs zero a port's pulse at its next 20 ms update, and compare preload applies that one period later, so cutting power within 1 ms drove up to one more pulse into an unpowered servo. AGENTS.md now lists the servo power check in the main loop's window.
Resolve the main.c conflict with PR #13: call update_servo_power() after spi2_dma_check_sync(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
I tested this on a Wombat. The firmware change does what it says, and disabled servos now go limp. I found four things worth knowing before merging. Two are libwallaby bugs that change what this PR delivers, and two are behaviour changes worth documenting. SetupMaster now has #13, which adds a call at the same spot in What works
What to know1. With libkipr 1.2.4, servos don't go limp when a program ends. Return, In gdb, 2. A misread over the SPI link can now cut the servo rail mid-run. To test this, I enabled servos 1–3 and had a loop call It needs a link slip; there were none in 20,000 healthy frames. The fix belongs in libwallaby: check the result of 3. A re-enabled servo snaps at full speed to its last commanded position. Positions stay in the STM32 until it's reset, and enabling a servo writes only register 61. Before, a held digital servo was already at that position. Now it has gone limp and may have been moved by hand or by gravity. I confirmed it with a servo at 2300 µs: disabled it, moved the horn by hand, re-enabled it, and it snapped back at normal servo speed. The same happens across programs. The next program's 4. The moment of highest undervoltage risk moves later. I ran three motors at raw PWM up to 400, all four servos swinging the full 700↔2300 µs, and CPU load on the Pi, and polled On master the servos are already powered, so the risky window is a reversal within about 50 ms of
So the peak risk is the same, and over the delays I tried this PR tripped less often. A program that starts or reverses motors 100–200 ms after enabling the servos can now trip the flag where it didn't before. It only shows on a weak pack: a fresh one never tripped in 840 cycles at full motor power on either build. There were no STM32 resets and no Pi reboots on either build. I'd add one sentence to the description: "Servo start-up current now arrives about 100–200 ms after Not tested: anything that needs a meter or a scope (the rail voltage at idle, the U72 EN voltage), and heavily loaded or stalled servos. |
What and why
disable_servo()anddisable_servos()only stop a port's control pulses (the firmware sets the pulse width to 0). The 6 V servo rail stays powered. Analog servos go limp without pulses, but digital servos, including the ones we use, keep holding their last position. Sodisable_servos()had no visible effect on them, unlikeoff()for motors.The board can already cut servo power. In
docs/Schematics/, PE10 (SRV_DISABLEinwallaby_r2.h) connects through R66 (0 Ω) to the enable pin of U72, the AP65502 regulator that makesVCC_6V0. That rail feeds only the four servo ports, through the fuses U68–U71. R52 (100 kΩ) pulls the enable up to the battery. The firmware never configured PE10, so the rail was always on.Changes
Firmware/src/wallaby_init.c: configure PE10 as an open-drain output, driven low, at the very start ofinit(). Open-drain because the enable is pulled up to the battery: low turns servo power off, and released (the pin's state until now) turns it on. Servos boot disabled, so power starts off. It runs beforeinit180MHz()waits for the crystal, because the rail is on from reset until the pin is driven.Firmware/src/wallaby_servo.c/.h: addupdate_servo_power(). It cuts power 40 ms after all four servo disable bits (4–7 ofREG_RW_MOT_SRV_ALLSTOP) are set, and restores it as soon as any is cleared. The 40 ms wait is there because the timer ISRs zero a port's pulse at its next 20 ms update, and compare preload applies that one period later. Cutting power sooner would drive the last pulse into an unpowered servo.Firmware/src/main.c: callupdate_servo_power()once per loop pass. It runs in the main loop rather than the servo timer interrupts becauseinit()starts those interrupts beforeinit_tx_buffer()sets the disable bits, so an interrupt would briefly see every servo as enabled and switch the rail on at boot.AGENTS.md: add PE10 to the peripheral table, and the servo power check to the main-loop description.The register map is unchanged, so no libwallaby change or SPI version bump is needed:
disable_servos()already sets the bits the firmware now checks.Behavior changes
disable_servos(), or disabling all four servos one by one, cuts servo power 40 ms later, and the servos go limp.disable_servos(), including fromshut_down_in(), so an arm holding a load drops at the end of a run. This is intended, and judges are aware of it.Verification
build/deleted first) passes. The changed C files compile with no warnings.init()enables the GPIOE clock, writes bit 10 ofBSRRHand callsGPIO_Initbeforeinit180MHz().update_servo_power()reads register 61, masks0xF0, and writesBSRRHonly onceusCount - since >= 40000, or writesBSRRLright away when any servo is enabled.Firmware/src/wallaby_init.c,Firmware/src/wallaby_servo.candFirmware/include/wallaby_servo.h, LF inmain.c).VCC_6V0→ U68–U71 → servo connectors, in the Eagle schematic. R66 is on the rev 4 BOM.enable_servos()and a position command: the servos get power (about 6 V) and move.disable_servos(): all four go limp. Enabling them again works, with no brownout or reset when four loaded servos power up together.disable_servo(0)only: the other three keep working, and servo 0 behaves as it does today.shut_down_in(), goes limp.