Personal scripts for contact-implicit MPC project, including:
- LCM log analysis
- Camera calibration
- Quaternion Hessian-based cost matrix
- Arc repositioning
- Quaternion visualization
- LCS debugging
- URDF inspection
The LCM log analysis script, lcm_log_processing.py, loads and analyzes experiments contained in LCM logs. This script can perform the following functions:
- Calculate time-to-goal statistics.
- Combine statistics from multiple logs.
- Generate videos that overlay helpful meshcat visuals on top of a camera feed.
- Produce single-goal or multi-consecutive-goal videos.
- Produce plots such as cumulative density function (CDF) for time-to-goal per success threshold, error over time with mode switching per goal, etc.
- Detect hardware violations. This is especially helpful for simulation experiments where hardware violations would not have prevented the experiment from continuing.
- Export the results into a pickle file for later retrieval/analysis.
The general format is:
python lcm_log_processing.py [mode] path/to/lcm/folder [optional flags]
🚧 Note: There are some features of this script that are currently unfinished or broken, e.g. the
singlecommand is broken butmultican be used with a single log file. There is additionally the start to producing a demo video, which is presently unfinished.
Below are a few examples. All have other possible flags available.
Can still use the multi command:
python lcm_log_processing.py multi /home/bibit/Videos/franka_experiments/2025/01_29_25/000007 --interactive
List multiple log folders in a row with the same multi command.
This can be done with the same multi command but with the flag --export-name={NAME}. The result will be saved as {NAME}.pickle in the --save-to folder (if not provided as a flag, this will default to the tmp folder). This can be for single- or multi-log analyses.
This requires loading already exported pickle files.
python lcm_log_processing.py mjpc /path/to/pickle/dir
As currently written, this looks into the provided pickle folder for:
ours_sim.pickle- MJPC comparisons of the form
mjpc_ee_vel_0-24.picklewhere the0-24means 0.24 end effector velocity cost weight.
This command then generates plots to compare the approaches.
This is a multi-step process that is recommended for single logs instead of multi-logs. This currently works for jack and push T examples. Correspondences between log files and camera videos need to be known to the code, so these are hard-coded into the LOG_FILEPATHS_TO_VIDEOS dictionary, whose keys are the log folders and whose contents have the long video filepath and a directory to which single-goal videos can be written. For new experiments, new keys and contents need to be added to this dictionary.
- Create trimmed camera videos.
python lcm_log_processing.py multi /log/dir --trim-times- This prints
ffmpegcommands that can be run manually (eventually this could be good to automate). - This also creates a folder which the
ffmpegcommands will store results to.
- This prints
- Create trimmed meshcat goal videos.
python lcm_log_processing.py multi /log/dir --video --trim-times- This saves files which will need to be copied over to the folder.
- Overlay and add final success frame.
python lcm_log_processing.py multi /log/dir --overlay --trim-times- Final results are in the folder with names of the form
overlay_{log_date}_log_{num}_goal_{goal}_success.mp4.
- Final results are in the folder with names of the form
- Create meshcat goal video for the continuous log.
python lcm_log_processing.py multi /log/dir --video- This saves files which will need to be copied over to the folder.
- Overlay and add a goal counter.
python lcm_log_processing.py multi /log/dir --overlay
The camera calibration script, camera_calibration.py, is used to perform extrinsic camera calibration and to store the camera intrinsic parameters reported by the camera. Run via:
python camera_calibration.py
This computes the relative transform between a camera and the world. Currently this script requires:
- The calibration board is an Aruco board with the below description:

- The calibration board is located at a known pose in the world, defined in the script and pictured in the example debug photo below.
- The camera is a RealSense D455 plugged into the computer via USB.
Here's an example of the output debug image from a calibration, with the board in its hard-coded location relative to the robot (i.e. world) frame.

For inspecting the alignment, the script also generates 3D plots to compare the depth returns to known geometries (the calibration board and the table). Examples:

The outputs of the calibration script are saved into a timestamped folder under the (git-ignored) calibrations/ directory.
The scripts quat_hessian_compute.py and quat_hessian_test.py derive and test, respectively, the 4x4 Hessian of the true squared angular error, given a current quaternion and a goal quaternion. The purpose of these single-use files is to automatically generate the quaternion expressions before converting to C++ as part of the 4x4 block of the Q cost matrix corresponding to the quaternion over time. This matrix is almost never PSD, so regularization is required. The C++ implementation is located in dairlib as systems/controllers/quaternion_error_hessian.cc on certain branches (as of 4/25/2025, the branch of interest is sampling_based_c3_dev).
For the
Even for small orientation errors, we note that the desired error
for
poorly captures the true
The arc repositioning test script, arc_repositioning.py, tests a repositioning strategy that follows an arc on a spherical surface. The strategy first moves along a straight line colinear with the end effector's current location and the object's current location towards a specified repositioning radius away from the object, then follows a path along that spherical surface, then follows a straight line towards the sample. The script has 3 hard-coded test cases, which can be selected by setting the TEST_I index.

The quaternion visualization script, quat_visualizer.py, generates and visualizes the 8 stable orientations of the jack. Renders the 8 quaternions as triads in a meshcat window, and prints out the C++ definitions for each of them.

The LCS debugging script, lcs_debugging.py, runs some tests on a hard-coded set of LCS matrices to ensure their compatibility and the accuracy of the derivations.
The URDF inspection script, urdf_inspection.py, loads a URDF file into a Drake plant and prints out some of its properties, such as the mass matrix and center of mass.