--- name: bt-decorator-nodes description: 'Use BT decorator nodes. Use when adding RateController, SpeedController, RecoveryNode, SingleChild, or timeout decorators.' --- # BT Decorator Nodes Decorators wrap exactly one child node and modify its tick behavior, return status, or execution frequency. They are essential for throttling expensive operations, retrying failures, and implementing timeouts. ## RateController Limits child tick frequency to a maximum rate in Hz. Between ticks, returns the child's last status. Use to throttle expensive computations like path planning: ```xml ``` The child is ticked at most once per second. If the parent ticks this decorator at 10 Hz, the planner runs at 1 Hz while the decorator returns RUNNING (or the last result) for the intervening ticks. **Navigation example** — replan at 0.5 Hz while following: ```xml ``` **Warning**: If `hz` is too low and the environment changes rapidly, the robot may follow stale paths. If too high, the planner overloads the CPU. ## DistanceController Only ticks the child when the robot has traveled at least `distance` meters since the last tick. Returns RUNNING otherwise: ```xml ``` Useful in environments where time-based replanning wastes resources while the robot is stationary (e.g., waiting at a door). ## SpeedController Adjusts tick rate based on the robot's current speed. Faster movement → more frequent ticks. Parameters define the mapping: ```xml ``` | Port | Type | Description | |---------------|--------|------------------------------------------| | min_rate | double | Tick rate (Hz) when speed ≤ min_speed | | max_rate | double | Tick rate (Hz) when speed ≥ max_speed | | min_speed | double | Speed below which min_rate applies | | max_speed | double | Speed above which max_rate applies | | filter_coeff | double | Low-pass filter on speed (0–1) | The rate scales linearly between the bounds. At high speed, the robot replans more often to react to close obstacles. ## SingleTrigger Ticks the child exactly once, then returns the cached result on all subsequent ticks: ```xml ``` Use for one-shot initialization actions that should not repeat. After the child returns SUCCESS or FAILURE, that result is returned on every future tick without re-executing the child. ## Inverter Flips SUCCESS to FAILURE and FAILURE to SUCCESS. RUNNING passes through unchanged: ```xml ``` Essential for negating condition nodes. `IsBatteryLow` returns SUCCESS when the battery IS low. Wrapping it in `Inverter` gives a "battery OK" condition. ## ForceSuccess Returns SUCCESS regardless of the child's result (SUCCESS or FAILURE). RUNNING passes through: ```xml ``` Use when a recovery action is "best effort"—you don't want its failure to propagate up and abort the recovery sequence. ## ForceFailure Returns FAILURE regardless of the child's result. RUNNING passes through: ```xml ``` Useful in Fallback nodes where you want a child to always "fail" to ensure the next fallback option runs. ## Repeat Ticks the child N times. Returns SUCCESS after all repetitions complete. Returns FAILURE immediately if the child fails: ```xml ``` The robot spins three times (total ~4.71 radians). If any single spin fails, the Repeat immediately returns FAILURE. **Patrol N laps:** ```xml ``` ## Retry Retries the child up to N times on FAILURE. Returns SUCCESS on the first successful attempt. Returns FAILURE if all retries are exhausted: ```xml ``` If path planning fails, retry up to 3 times before giving up. Combine with recovery actions: ```xml ``` Each retry clears the costmap first, giving the planner fresh data. ## KeepRunningUntilFailure Returns RUNNING as long as the child returns SUCCESS or RUNNING. Only returns FAILURE when the child fails: ```xml