Skip to content

robomechanics/Saltation-Tutorials

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Saltation-Tutorials

This repository contains some starter code for the implementation of some basic saltation methods in MATLAB and python (for SKF only).

Hybrid System Model Definitions

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:

1. Simple Hybrid System

  • Dynamics: Two modes, I and J, with dynamics:

    • Mode I: dx/dt = [1; -1]
    • Mode J: dx/dt = [1; 1]
  • Guards:

    • g_{I → J}: x1 = 0 (transition from I to J occurs when x1 crosses zero).
  • Resets:

    • r_{I → J}: [x1; x2] → [x1; x2] (identity reset for transition from I to J).

2. Bouncing Ball Hybrid System

  • Dynamics: Two modes, I and J, with identical dynamics:

    • Mode I and Mode J: dx/dt = [q_dot; -g], where g is gravitational acceleration.
  • 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], where e is the coefficient of restitution.
    • r_{J → I}: [q; q_dot] → [q; q_dot] (identity reset).

    3. Bouncing Ball with Moving Guard Hybrid System

  • Dynamics: Two modes, I and J, with identical dynamics:

    • Mode I and J: dx/dt = [q_dot; -g], where g is gravitational acceleration.
  • 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], where e is the coefficient of restitution.
    • r_{J → I}: [q; q_dot] → [q; q_dot] (identity reset).

Tutorial Paper Code

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:

Sticking

Sliding

How to Generate the Saltation Matrix and Figures

  1. Run the main.m file 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.

  2. To calculate the saltation matrix for a new system:

    • Add a new subfolder to the Dynamics Files folder and modify the following files with your system's dynamics, guards, and resets:
      • flows.m
      • guards.m
      • resets.m
      • saltation_calc.m
  3. After defining the new system, update the system initialization in the main.m file 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.

Salted Kalman Filter

This code provides an example for implementing the SKF as defined in The Salted Kalman Filter: Kalman Filtering on Hybrid Dynamical Systems.

Models

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:

Simple SKF

Bouncing Ball SKF

Python Structure

To run the examples:

  1. Execute the corresponding Python file:
    • simple_hybrid_system.py
    • bouncing_ball_hybrid_system.py
  2. 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.

MATLAB Structure

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: MATLAB SKF

Hybrid iLQR

This code provides an implementation of the hybrid iLQR algorithm, as defined in our paper iLQR for Piecewise-Smooth Hybrid Dynamical Systems.

Models Used for Trajectory Optimization

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:

Flat Ground

Moving Guard

Structure of the Code

To generate the optimized trajectories and plots:

  1. Run the main.m script. This will perform the trajectory optimization for the 1D bouncing ball system. All resulting plots and animations will be stored in the hilqr_results folder.

  2. 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.m uses 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.

  3. 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.m file and rerun the optimization in main.m. The dynamics files will be stored in the folder titled dynamics_helpers and will be called automatically by maim.m.
  4. Trajectory Optimization:

    • The optimization is performed using the hilqr.m class. 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.m script.

Additional Notes

  • 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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •