Skip to content

Breaking Change: Rewrite Controller API to have less templated components#30

Open
bogidude wants to merge 17 commits intomainfrom
feature/remove_template_specified_timesteps_and_rollouts
Open

Breaking Change: Rewrite Controller API to have less templated components#30
bogidude wants to merge 17 commits intomainfrom
feature/remove_template_specified_timesteps_and_rollouts

Conversation

@bogidude
Copy link
Copy Markdown
Member

Warning

This pull request removes the MAX_TIMESTEPS and NUM_ROLLOUTS integers from the base Controller template.
Controllers will now only be templated upon the Dynamics, Cost Function, Feedback Controller, Sampling Distribution and Controller Params.

Reasoning

These were originally in place so that we could define various fixed-sized Eigen Matrices like control and state trajectories. However, we never do Eigen operations on the full trajectory in this library (we instead pull out a single state or control vector at a given time and then do computation on those vectors alone) that could leverage the fixed-size and this previous formulation ended up limiting the number of samples or timesteps that could be used with MPPI-Generic due to limitations on how large a fixed-size Eigen Matrix can be. We had a half-measure currently in place where we utilized a MAX_TIMESTEPS template parameter and then allowed the useer to adjust the number of timesteps at run-time as long as it was to a number less than or equal to MAX_TIMESTEPS. This was a half-measure because the underlying data structures were still MAX_TIMESTEPS large and we would just zero out the rest of the trajecotory if the timesteps were set to be lower. With this pull request, we instead switch to defining control_trajectory, state_trajectory, etc. to be dynamically-sized Eigen matrices with the first dimension fixed to the relevant size (CONTROL_DIM, STATE_DIM, etc.) and the second dimension being Dynamic.

Instead of template parameters, the base ControllerParams structure fully controls the number of timesteps and rollouts under num_timesteps_ and num_rollouts_ and can be adjusted at run-time. I have added various checks to the controller constructors and setParams() methods to appropriately resize the relevant variables on both the CPU and GPU when these parameters are adjusted. New controller methods setNumTimesteps() and setNumRollouts() have also been added The MPPI, Tube-MPPI, and R-MPPI controllers were all rewritten to follow this new Controller template API. Removing fixed-size Eigen Matrices required a bit of rewriting of the DDP feedback controller which was also depending on compile-time knowledge of the number of timesteps. Finally, examples and unit tests were also rewritten and verified by hand to work with the new Controller API. New unit tests to test adjusting the number of rollouts and timesteps at run-time were also written though I am probably missing some edge cases.

Overall, this change should not reduce run-time performance and should allow users more flexibility such as updating the number of samples from a configuration file instead of requiring compilation with every change. Compilation times might also be reduced slightly as there are less template specializations but no promises on that end.

I think I have removed it properly from all of the library code.
However, nothing will compile at the moment because the examples and
unit tests have not been updated.

Other changes:
- removed commented out code in various places
- Add new sampling distribution method to get the optimal control
  sequence that is located on the GPU. This replaces control_d_ in the
  Controller.
- Adjust Controller::allocateCUDAMemoryHelper() to be less confusing.
  The input is no longer expected to be the number of systems - 1 and
  the unused boolean has been removed. Also added freeing of memory
  before allocating more as we can now adjust the size of some device
  memory.
- Adjust Feedback Controller API a bit to account for more complicated
  memory management associated with variable number of timesteps.
Fixed various compilation errors and bugs in removing num_timesteps as template parameter
All examples now compile and run correctly. Unit tests are going to be
fixed next.
autoformatter script can now take in multiple arguments of directories
to run formatting over
Fixed controller_generic_tests first. Still need to update other
controller and feedback controller unit tests at minimum and probably
others.
It looks like some unit tests are failing due to the changes so those
still need fixing.
Other Changes:
- Rename internal methods for timesteps and rollouts to
  setNumTimestepsHelper() to follow existing convention
- Update Tube-MPPI and R-MPPI to overwrite setNumTimestepsHelper() and
  setNumRolloutsHelper() to also resize their nominal trajectory
  variables
- Change default number of rollouts to cause issues if not set correctly
- Update library compilations to use new controler template syntax
- update examples to use new controller template syntax
Other changes:
- fix setNumTimesteps() to use logic to fill in control trajectory as
  slideControlSequence()
- reset control_ to initial control trajectory when new number of
  timesteps is larger than current timesteps
- fix Tube MPPI constructor unit tests
- Add unit tests to check control trajectories are both proper size and
  filled with linear interpolation between last provided control and
  model's zero control after construction
- Add unit tests to check R-MPPI and Tube-MPPI's nominal control
  trajectories
- Add unit tests for setNumRollouts()
@bogidude bogidude requested a review from JasonGibson274 April 17, 2026 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant