Introduction
Computer simulation of bipedal walkers requires software that can perform the following tasks: - generate the equations of motion,
- export the equations into a compilable form,
- integrate the system of ODEs from initial conditions,
- detect and handle discontinuous events, such as impact with the ground,
- and handle numerical exceptions and physical infeasibilities.
We use Mathematica for the first 2 tasks, and Matlab's Mex API and ode45 for the remaining tasks; if you are unfamiliar with Mathematica, Matlab, C Mex files, or ode45 event detection, see the links to relevant documentation at the end of this page. A working - and documented - snapshot of our simulation code is here. Note that we are continually improving our biped walker simulation but have not decided on how to release future versions.
Significant credit must be given to Arthur Kuo at the University of Michigan, who's bipedal walker simulation pointed us in the right direction. Please direct all technical inquiries or problems regarding the CHESS biped simulation code to Eric D.B. Wendel.
The following instructions serve as both primer to and documentation for the simulation code, and will run through the steps required to verify the results of our most recent paper, "Towards the Geometric Reduction of Controlled Three-Dimensional Bipedal Robotic Walkers," submitted to the IFAC 3rd Workshop on Lagrangian and Hamiltonian Methods for Nonlinear Control, Nagoya, Japan.
How the Simulation Works
We generate the equations of motion in Mathematica, export them as C code, and then compile the code for Matlab as a Mex file. See our modeling page for information on how we derive our equations of motion.
Using Mathematica's built-in Splice command and the Format package created by Mark Sofroniou at Wolfram Research, we then export the equations as C code through a template containing expressions native to the Format package, and are left with a C file.
Compiling the C file is straightforward using the Matlab Mex utilities and the default lcc compiler. For some models the equations were several pages long. Only the lcc compiler is necessary if the Format package is used correctly. Otherwise, a word of caution: do not use the free Borland compiler v5.5, it does not support numerical exception handling. We have successfully compiled our Mex files on Mac and PC, using lcc, Borland, and gcc.
After compiling we are left with a binary file that we treat as a normal Matlab function. The extension of the binary file varies by platform, but the provided code was prepared on a PC running an Intel processor, so all of the compiled Mex files are named eqns2.dll or eqns3.dll. For example, eqns2.dll or eqns3.dll are called as "eqns2(inputs)" or "eqns3(inputs)", or using feval if you have stored a function handle to the dll, as is used in the code: "feval(eqnhandle, inputs)".
Matlab can numerically integrate first order ODEs, that is, systems of equations with the form q' = f(q). The compiled Mex files take q, the state vector, and return q'. We used ode45 with high absolute and relative integration tolerances to calculate the system dynamics.
Holonomic conditions determine contact with the ground. We use a function that returns the foot's height above the ground when holonomic constraints are met, and returns the value 1 otherwise. This is an inelegant but effective solution, since Matlab event detection was not designed with hybrid systems in mind.
Reconstructing from the 2D Bipedal Walker
- Extract chess_biped_code.zip into any directory and "cd" into the extracted 2D directory.
- Type "pop" and then select the option corresponding to the controlled 2D walker with reconstruction. Once you select this option, pop will create several variables in the Matlab global workspace. These variables are the model parameters (hip mass Mp, leg mass M, leg length l, hip width w, acceleration due to gravity g, etc) and other book-keeping variables (modeldir and wd). These variables must exist and be defined inside the global workspace for the simulation to work.
- Type "walk2(xi, 10)" and the simulation will return the last state after 10 steps. Note that the state vector for this model is a Matlab array defined as follows: ["stance angle" "swing angle" "stance angular velocity" "nonstance angular velocity" "roll angle"]. Note that the other 2D models use the same state vector, less the roll angle.
- Now enter "walk2([1 1 1 1 1], 10)". The simulation will complain that the robot walker did not make contact with the ground within the default ode45 integration time; your initial condition [1 1 1 1 1] does not lead to a stable limit cycle and the simulation aborts.
- Now type "walk2(xi, 10, 1)" and study the graphs that appear.
- "walk2(xi, 10, 2)" will produce an animation of the bipedal walking.
- "walk2(xi, 10, 3)" will produce graphs of the reconstructed 3D bipedal robot. You may want to save these graphs to compare them to the full-order bipedal walker.
Simulating the 3D Bipedal Walker
- If you followed the instructions above, you executed all commands from within the extracted 2D/ directory while in Matlab. Type "cd ../3D" to change your working directory to the code for simulating the full-order bipedal walker.
- Type "opp". This clears everything out of all Matlab workspaces, and is useful for switching between models.
- Typing "pop" while in the 3D/ directory will provide a list of 3D models. Currently, only the controlled hipless model is working, so choose that option.
- Notice that xi for this 3D model is the same as that for the 2D model; the state vector is a Matlab array consisting of the following angles and velocities: ["roll angle" "stance angle" "nonstance angle" "roll angular velocity" "stance angular velocity" "nonstance angular velocity"].
- Type "walk3(xi, 10, 1)" and compare the graphs to those of the reconstructed 3D bipedal robot.
Relevant links
Use Format.m to export Mathematica expressions into C, Fortran77, or Maple
Mex API documentation
Mex API function reference (succinct, functions only)
|