Goto and AimTo controller functions #25

Closed
opened 2026-08-17 18:55:18 +02:00 by SirStone · 1 comment
Owner

Parent

#24 — PRD: Command abstraction layer for PPO action space

What to build

Pure controller functions that translate spatial targets into per-tick motor commands, independent of the PPO pipeline.

Goto controller — gotoTick(targetX, targetY, botX, botY, direction, speed) → (targetSpeed, turnRate):

  • Compute raw bearing to target using directionTo (Tank Royale north=0° CW convention)
  • If |bearing| > 90°: reverse (negate speed, adjust bearing by 180°)
  • Turn rate: proportional to effective bearing, clamped to calcMaxTurnRate(speed)
  • Speed: dirSign × getNewTargetSpeed(MAX_SPEED, |speed|, distance) for smooth deceleration
  • Reference implementation: GotoTest/GotoTest.nim prototype

AimTo controller — aimToTick(targetX, targetY, botX, botY, gunDirection) → gunTurnRate:

  • Compute bearing from bot to target using directionTo
  • Turn needed: normalizeRelativeAngle(bearing - gunDirection)
  • Clamp to ±MAX_GUN_TURN_RATE (20°/tick)

Both functions use existing utilities: getNewTargetSpeed from utils.nim, calcMaxTurnRate/normalizeRelativeAngle/directionTo from tankroyale_botapi.

Acceptance criteria

  • gotoTick returns positive speed for targets within 90° of heading, negative for targets behind
  • gotoTick decelerates smoothly near target (speed → 0 as distance → 0)
  • gotoTick turn rate never exceeds calcMaxTurnRate(speed)
  • aimToTick returns positive turn for targets to the right of gun, negative for left
  • aimToTick turn rate never exceeds ±20°/tick
  • aimToTick returns near-zero turn rate when gun is already aligned
  • Unit tests cover forward/reverse selection, deceleration, gun shortest-arc

Blocked by

None — can start immediately

## Parent #24 — PRD: Command abstraction layer for PPO action space ## What to build Pure controller functions that translate spatial targets into per-tick motor commands, independent of the PPO pipeline. **Goto controller** — `gotoTick(targetX, targetY, botX, botY, direction, speed) → (targetSpeed, turnRate)`: - Compute raw bearing to target using `directionTo` (Tank Royale north=0° CW convention) - If `|bearing| > 90°`: reverse (negate speed, adjust bearing by 180°) - Turn rate: proportional to effective bearing, clamped to `calcMaxTurnRate(speed)` - Speed: `dirSign × getNewTargetSpeed(MAX_SPEED, |speed|, distance)` for smooth deceleration - Reference implementation: `GotoTest/GotoTest.nim` prototype **AimTo controller** — `aimToTick(targetX, targetY, botX, botY, gunDirection) → gunTurnRate`: - Compute bearing from bot to target using `directionTo` - Turn needed: `normalizeRelativeAngle(bearing - gunDirection)` - Clamp to `±MAX_GUN_TURN_RATE` (20°/tick) Both functions use existing utilities: `getNewTargetSpeed` from `utils.nim`, `calcMaxTurnRate`/`normalizeRelativeAngle`/`directionTo` from `tankroyale_botapi`. ## Acceptance criteria - [ ] `gotoTick` returns positive speed for targets within 90° of heading, negative for targets behind - [ ] `gotoTick` decelerates smoothly near target (speed → 0 as distance → 0) - [ ] `gotoTick` turn rate never exceeds `calcMaxTurnRate(speed)` - [ ] `aimToTick` returns positive turn for targets to the right of gun, negative for left - [ ] `aimToTick` turn rate never exceeds ±20°/tick - [ ] `aimToTick` returns near-zero turn rate when gun is already aligned - [ ] Unit tests cover forward/reverse selection, deceleration, gun shortest-arc ## Blocked by None — can start immediately
SirStone added the ready-for-agent label 2026-08-17 18:55:18 +02:00
Author
Owner

Implemented in commit c713585 on branch research/goto-controller.

Implemented in commit c713585 on branch research/goto-controller.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: SirStone/SirRoboGarage#25