Skip to content

colgreen/cartpole-physics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 

Repository files navigation

cartpole-physics

C# source code for simulation of the cart and pole balancing task.

For details of this task, including derivations of the equations of motion, see the following technical research paper:

Equations of Motion for the Cart and Pole Control Task

The source code in this repository can be considered to be supplementary material for that paper.

Repository Overview

This repository contains C# source code (src folder) for the cart-pole balancing task, and some R/ggplot2 scripts (r-ggplot2 folder) for creating plots for the above linked research paper.

Source Code Overview

The source is written in C# and targets .NET 10.0. However, the physics/maths code should be easy to port to any other language.

CartPolePhysics

This project contains the maths/physics source code.

  • Double

    • CartSinglePoleEquations.cs
      • Contains the equations of motion for the cart-pole model, giving the horizontal acceleration of the cart and the angular acceleration of the pole for a given model state and external force f (a horizontal force pushing the cart left or right).
    • CartSinglePolePhysics.cs
      • Contains an instance of CartSinglePoleEquations, and applies Euler's method to update the model state from one timestep to the next. This is also the base class for CartSinglePolePhysicsRK2 and CartSinglePolePhysicsRK4.
    • CartSinglePolePhysicsRK2.cs
      • Contains an instance of CartSinglePoleEquations, and applies the standard second-order Runge-Kutta method to update the model state from one timestep to the next.
    • CartSinglePolePhysicsRK4.cs
      • Contains an instance of CartSinglePoleEquations, and applies the classic fourth-order Runge-Kutta method to update the model state from one timestep to the next.
  • Single

    • The classes in this folder/namespace mirror exactly those of the 'Double' folder, but provide physics calculation based on single precision floating point maths.

CartPoleConsole

A small console app that can be used to run a simulation and save a CSV file containing the model state at each timestep. The CSV file can then be used to make plots, e.g. with R and ggplot2.

CartPoleWinForms

A small Windows Forms app. This app runs a simulation and shows a graph on screen of pole angle, cart position, and pole angular velocity over time.

About

C# source code for simulation of the cart and pole balancing task.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors