Examples

Examples#

While the majority of the kdFlex software is written in C++, Python bindings for the C++ classes are available as Python extensions. Example Python scripts, named notebook.py, are available within each of the subfolders within /usr/share/Karana/Tutorials in your local installation (/opt/homebrew/share/Karana/Tutorials if using macOS). These scripts illustrate the use of the kdFlex Python extension and can be run from within each of these folders by running python3 notebook.py.

There are also Jupyter notebook versions of each of the tutorials, named notebook.ipynb within the same folder. The introduction video shows how to run these notebooks from a remote machine, from a local machine, and as a normal Python script.

Python Tutorial Notebooks#

This section contains tutorial examples on using kdFlex. The Python examples are included here, since the associated Jupyter notebooks can be converted to HTML. One can find these notebooks tutorials under /usr/share/Karana/Tutorials (/opt/homebrew/share/Karana/Tutorials if using macOS). The C++ examples cannot be easily converted to a web format, but are included with the kdflex package as well under /usr/share/Karana/Tutorials/example_cc (or /opt/homebrew/share/Karana/Tutorials/example_cc) if using macOS.

Jupyter notebook

Folder

Description/License tier

Video walkthrough

Importing a rover arm from a URDF file

example_urdf

Illustrates importing a Barrett WAM robot arm multibody model from a URDF file

Video Walkthrough

Importing M2020 rover model from a URDF file

example_m2020

Illustrates importing a Mars 2020 rover model from a URDF file

2 link pendulum (basic)

example_2_link_pendulum

Illustrates the step by step creation of the bodies for a 2-link pendulum, and setting up a time domain simulation for it.

Video Walkthrough

n link pendulum (procedural)

example_n_link_pendulum

Illustrates the procedural creation of an n-link pendulum and a time domain simulation for it.

Video Walkthrough

Spice frames (basic)

example_spice_frames

Illustrates use of the frames layer with planetary body frames

Import/export multibodies

example_import_export

Illustrates importing and exporting multibody models files in various formats; also, the use of units and quantities.

Visualization

example_visualization

Illustrates the capabilities of the 3D graphics layer.

Data logging

example_data_logging

Illustrates basic data logging capabilities.

Slider-crank with loop constraints

example_slider_crank

Illustrates creating a slide-crank system with loop constraints and graph topology.

Double wishbone

example_double_wishbone

Illustrates creating a double-wishbone system with loop constraints and graph topology.

2 link pendulum (collisions)

example_pendulum_collision

Illustrates collision dynamics with a 2-link pendulum example.

Multi-link procedural pendulum (collisions)

example_procedural_collision

Illustrates collision dynamics with a multi-link pendulum example.

Flexible slider-crank

example_flexible_slider_crank

Illustrates a slider-crank with a flexible body. This is a system that has both flexible bodies and closed loops.

Flexible double-wishbone

example_flexible_double_wishbone

Illustrates a double-wishbone with a flexible body. This is a system that has both flexible bodies and closed loops.

Rigid body SOA dynamics performance

example_rigid_timing

Verify O(N) performance of SOA dynamics by measuring computational time with varying number of bodies.

Rigid body SOA dynamics vs fully augmented performance

example_fully_augmented_benchmark

Compare O(N) performance of SOA dynamics with O(N^3) performance of conventional full-augmented (FA) dynamics.

Skid-steered driving

example_atrvjr_drive

Illustrates setting up and driving the ATRV-Jr, a simple skid-steered four wheel vehicle

Cart-pole reinforcement learning

example_cartpole

Integrates kdFlex with gymnasium to train on the classical cart-pole problem

Skid-steered reinforcement learning

example_atrvjr_learning

Integrates kdFlex with gymnasium to drive the ATRV-Jr (a skid-steered four wheel vehicle) to random goals

ROS2 integration

example_atrvjr_ros

Integrates kdFlex with ROS2 to monitor and command a vehicle

Each notebook has a corresponding notebook.py, which is a regular Python script.