(small) (normal) (large)

## Multiple chained pendulum

Example of quickly generating a multi segment pendulum and simulating it. Here generator syntax (line 19) is used to generate multiple segments in parallel, which are then coupled together in a chain.

 ```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 ``` ```# Includes the codyn physics templates for systems, # bodies and joint models include "physics/physics.cdn" integrator { method = "runge-kutta" } defines { n = 5 } # All models start by defining a node derived from the # physics.system template node "system" : physics.system { # Inside the system, joints are defined by inheriting # from any of the physics.joints.* templates. codyn # provides a large number of general purpose joints. node "p{1:@n}" : physics.joints.revoluteY { # The center of mass com = "[0; 0; -0.5]" # The translation from the parent frame to the frame # of this joint tr = "[0; 0; -1]" # The inertia tensor of the physical body on this # joint I = "Inertia.Box(m, 0.05, 0.05, 1)" # Add some damping in the system on the generalized # force τ = "-20 * dq" } # Override certain variables on the root joint. node "p1" { tr = "[0; 0; 0]" q = "0.2 * pi" } # Create edges between successive nodes inheriting # from the physics.joint template. This chains # joints together to form the articulated rigid # body. edge from "p{1:@n}" to "p\$(@1 + 1)" : physics.joint {} # The physics/model.cdn file should be included at the # end of the model definition and constructs a "model" # node containing global system quantities such as the # center of mass and total mass. It is also responsible # for constructing the required Jacobians if requested. include "physics/model.cdn" # The physics/dynamics.cdn file should be included last # and constructs the equations necessary for forward # simulation of the dynamics. It uses RNEA to construct # C and CRBA to construct H in a new node called # "dynamics". It then derives generalized accelerations # in dynamics.ddq which project back to the individual # joints. include "physics/dynamics.cdn" } ```

⌦ Open in playground