This repository contains some starter code for the implementation of some basic saltation methods in MATLAB and python (for SKF only).
In this tutorial, we consider a variety of hybrid systems to demonstrate the Salted Kalman Filter (SKF) and Hybrid iLQR algorithms. Below we define these such systems:
-
Dynamics: Two modes,
IandJ, with dynamics:- Mode
I:dx/dt = [1; -1] - Mode
J:dx/dt = [1; 1]
- Mode
-
Guards:
g_{I → J}: x1 = 0(transition fromItoJoccurs whenx1crosses zero).
-
Resets:
r_{I → J}: [x1; x2] → [x1; x2](identity reset for transition fromItoJ).
-
Dynamics: Two modes,
IandJ, with identical dynamics:- Mode
Iand ModeJ:dx/dt = [q_dot; -g], wheregis gravitational acceleration.
- Mode
-
Guards:
g_{I → J}: q - 0 = 0(ball impacts the ground).g_{J → I}: q_dot = 0.
-
Resets:
r_{I → J}: [q; q_dot] → [q; -e * q_dot], whereeis the coefficient of restitution.r_{J → I}: [q; q_dot] → [q; q_dot](identity reset).
-
Dynamics: Two modes,
IandJ, with identical dynamics:- Mode
IandJ:dx/dt = [q_dot; -g], wheregis gravitational acceleration.
- Mode
-
Guards:
g_{I → J}: q = 0.25 * sin(4πt)(impact with a moving paddle).g_{J → I}: q_dot = 0.
-
Resets:
r_{I → J}: [q; q_dot] → [q; -e * q_dot], whereeis the coefficient of restitution.r_{J → I}: [q; q_dot] → [q; q_dot](identity reset).
This code provides an example of how to generate Figure 1 (below) from our paper Saltation Matrices: The Essential Tool for Linearizing Hybrid Dynamical Systems. It includes implementations for 3 different toy systems:
- a ball dropping on a slanted surface with frictionless sliding
- a ball dropping on a slanted surface with contrained motion due to static friction
- a bouncing ball on a slanted surface.
Example figures that can be generated with these files:
-
Run the
main.mfile in the home folder and select the system you're interested in by modifiyng the selection variable in line 16. The selection of this parameter will automatically calculate the saltation matrix and generate the plots. -
To calculate the saltation matrix for a new system:
- Add a new subfolder to the
Dynamics Filesfolder and modify the following files with your system's dynamics, guards, and resets:flows.mguards.mresets.msaltation_calc.m
- Add a new subfolder to the
-
After defining the new system, update the system initialization in the
main.mfile and rerun the code.
Note: The saltation matrix is calculated symbolically in the dynamics files, so no further updates are needed for the matrix calculation. If you want to explore other systems or modify the existing ones, simply change the definitions in the respective files mentioned above.
This code provides an example for implementing the SKF as defined in The Salted Kalman Filter: Kalman Filtering on Hybrid Dynamical Systems.
In the MATLAB and python implementations, 2 different systems are considered: a simple 1D switching system and a 1D bouncing ball with a vertical thruster. Key parameters such as initial state q0, process noise W, and measurement noise V can be tuned to improve estimation accuracy. Examples of both filtered systems are shown below:
To run the examples:
- Execute the corresponding Python file:
simple_hybrid_system.pybouncing_ball_hybrid_system.py
- Adjust parameters such as step size, noise covariances, etc., at the bottom of each script before running. :
simulate_timestep()
To simulate a different system's dynamics:
- Edit the expressions for the flows, guards, and resets in:
symbolic_dynamics() - Re-run the file. No other changes are needed because:
- The filter is automatically computed in
skf.py. - The saltation matrix is calculated in
hybrid_helper_functions.py.
- The filter is automatically computed in
To run, execute one of the scripts (e.g., bouncing_ball_hybrid_system.m) to visualize the SKF estimation results for the corresponding hybrid system. Example of output:

This code provides an implementation of the hybrid iLQR algorithm, as defined in our paper iLQR for Piecewise-Smooth Hybrid Dynamical Systems.
The example model used for trajectory optimization is a 1D bouncing ball, as defined in the SFK section above. This module also includes the option to model a time-varying guard, such as a paddle moving up and down to bounce the ball. Below are some examples of optimized trajectories:
To generate the optimized trajectories and plots:
-
Run the
main.mscript. This will perform the trajectory optimization for the 1D bouncing ball system. All resulting plots and animations will be stored in thehilqr_resultsfolder. -
Symbolic Dynamics Calculation: The symbolic dynamics are automatically computed by the
bouncing_dynamics()function at the beginning of the script. No further modification is needed, apart from updating the initial states and control input guesses.bouncing_dynamics.muses the MATLAB symbolic toolbox to generate functions for:- Flows
- Resets
- Guards
- Saltation matrix
These generated functions are named:
calc_A.m,calc_f1.m,calc_salt12.m, etc. Do not modify these directly. -
Modifying or Modeling a New System:
- To model a new system or modify the existing one, you need to update the expressions in the
bouncing_dynamics.mfile and rerun the optimization inmain.m. The dynamics files will be stored in the folder titleddynamics_helpersand will be called automatically bymaim.m.
- To model a new system or modify the existing one, you need to update the expressions in the
-
Trajectory Optimization:
- The optimization is performed using the
hilqr.mclass. This class handles the forwards/backwards passes of the hybrid iLQR algorithm. - Do not modify this file directly, as it relies on a generalized optimization structure input from the
main.mscript.
- The optimization is performed using the
- Ensure you have MATLAB installed to run these scripts.
This code is based on work that was supported in part by the U.S. Army Research Office under Grant W911NF-19-1-0080 and in part by the U.S. National Science Foundation under Grant ECCS-1924723 and Grant CMMI-1943900.







