feat: add param() references and wrapper GenServer pattern#19
Merged
Conversation
Adds support for passing parameter overrides when starting a robot:
```elixir
# config/runtime.exs
config :my_app, MyRobot,
params: [motion: [max_speed: 2.0]]
# application.ex
opts = Application.get_env(:my_app, MyRobot, [])
{BB.Supervisor, {MyRobot, opts}}
```
Priority order: DSL defaults → persisted values → start_link params
- Add `BB.Parameter.Schema` module for building nested Spark.Options
schemas from flat parameter definitions
- Validate params in `Runtime.init/1` using Spark.Options
- Return `{:stop, reason}` on validation failure
- Add `:startup` source to `BB.Parameter.Changed` message
- Fix lifecycle test expecting wrong state transition for disarm command
Allow DSL topology fields (joint limits, origins, dynamics, etc.) to
reference runtime parameters instead of literal unit values:
```elixir
parameters do
group :motion do
param :max_effort, type: {:unit, :newton_meter}, default: ~u(10 newton_meter)
end
end
topology do
link :base do
joint :shoulder do
limit do
effort(param([:motion, :max_effort]))
end
end
end
end
```
Features:
- Compile-time validation that referenced parameters exist
- Unit type compatibility checking between param and field
- Runtime resolution at robot startup
- Automatic subscription to parameter changes
- Robot struct updates when parameters change
New modules:
- `BB.Dsl.ParamRef` - struct for parameter references
- `BB.Robot.ParamResolver` - runtime resolution and updates
- `BB.Dsl.Verifiers.ValidateParamRefs` - compile-time validation
- `BB.Parameter.Type` - parameter type validation (refactored from DSL)
…ions Implement wrapper GenServer pattern for actuators, sensors, and controllers. User modules now define callbacks only - the framework provides wrapper GenServers that manage parameter resolution and subscriptions. Changes: - Add `BB.Actuator.Server`, `BB.Sensor.Server`, `BB.Controller.Server` wrapper GenServers that delegate to user callback modules - Update behaviours to define callbacks without `use GenServer` - Add `handle_options/2` callback for reacting to parameter changes - Import `BB.Dsl.ParamRef` in actuator/sensor/controller DSL entities - Allow `param([...])` references in child_spec options - Remove component-level parameters feature (wasn't needed) - Update supervisors to use wrapper servers via `BB.Process.child_spec/5` When a parameter changes, the wrapper re-resolves all param refs and calls `handle_options/2` with the new resolved options. Safety registration remains explicit - users call `BB.Safety.register/2` in their `init/1` with the opts needed for stateless `disarm/1`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
param()references in actuator/sensor/controller options with automatic resolution and runtime updatesparam()references for topology fields (joint limits, link origins, etc.)start_linkoptionsWrapper GenServer Pattern
User modules now define callbacks only. Framework-controlled wrapper GenServers (
BB.Actuator.Server,BB.Sensor.Server,BB.Controller.Server) manage the process lifecycle and delegate to user callbacks.param() References
Parameters can now be referenced in actuator/sensor/controller options:
When the parameter changes, the actuator's
handle_options/2callback is invoked.Breaking Changes
@impl GenServer→@impl BB.Actuator(or Controller/Sensor) for all callbacksoptions_schemamoved from callback tousemacro optionBB.Safety.register/2ininit/1Test plan