CS 551 / CS 651: Computer Animation

Fall 2003

Professor Brogan

 

Assignment 3: Control - Cart/Pole

 

Due: 5:00 Wednesday, Nov 12th

 

Introduction

 

You will write a program that controls a cart-pole system.  The only control variable is the force that is applied to the cart.  The response of the pole is computed using physical simuation.

 

Details

 

A working simulation and graphical front end has been provided for you here.  This Visual Studio starter files included in the zip file were created with VS.net (2002).  Here's a brief rundown of the contents of the zip file:

 

viewer.[cpp|h] This is the code that loads a model file and converts is into OpenGL polygons.  I don't think you'll ever need to look at these files
boc_lib.[cpp|h] This is machine-generated code that contributes to the physical simulation of the system.  I don't think you'll ever have to look at these files.
boc_cartpole.[cpp|h] This is the machine generated code that implements the guts of the physical simulation.  You may want to look at this code just for kicks.  It's bound not to make much sense, though, as it was generated to be fast, not human readable.  The manual that describes this code can be downloaded from http://www.sdfast.com/sdfast_install.zip.
cartpole.dat This is the simple data file used by SD/Fast to generate the above simulation code.  Look at this code if you want to see the fundamental properties of the cart/pole system.  We have a license of SD/Fast here at UVa on a machine that you have access to, so let me know if you want to tinker with constructing alternative physical systems.
assign2.cpp This is the main control code.  It draws the objects and calls the simulation algorithms.  A couple things to note... the Display()  function controls how many times the simulation is updated before the screen is updated.  If you have a one-to-one update rate, the application will run very slowly because everything is being redrawn at every simulation DT, which is likely very small.  Another important function of this file is to permit the user to interact with the cart directly.  The intent of this program is for you to write an algorithm that controls the cart automatically, but if you want to use the "l" and "r" keys to manually apply forces, you can do that too.
simulation.[cpp|h] This is the guts of the interface between the main app and the simulation.  In the class constructor, you can can change the timestep, DT.  In the keyboardForce () routine you can control how much force a keyclick imparts on the cart.  The sduforce () function is called every simulation time step and this is the function that actually applies the forces you've calculated.  You'll see in this function that the forces generated by user keyclicks are applied during multiple simulation timesteps.  Alternatively, one could apply a larger force for one timestep, but this will require a smaller DT to preserve numerical accuracy.  In the interest of computational efficiency, the sample code has a larger DT and the force is smaller.  Remember this relationship between force magnitude and DT when writing your controller.  If your controller generates large forces, you may wish to make DT smaller.  All your code for the controller can be written in the controller () routine. The simple controller that I've included accomplishes relatively little.  The initial state of the cart/pole system is set in intializeSimulation ().

 

 

  1. (20 points) Play with the simulation using the keyboard interface to get a feeling for how best to control the orientation of the pole.

  2. (30 points) Consider what variables are the best indicators for making good control decisions.  The obvious ones at your disposal are the pole position, pole velocity, cart position, and cart velocity.  What are the critical values for these variables for when control should change?

  3. (20 points) Initialize your system to have the cart at 0.0 with 0.0 velocity, and the pole to have a slightly non-vertical (-PI/2) position and a 0.0 velocity.  Write a controller that accomplishes a balanced pole without regard to the cart's final position.

  4. (10 points) Start with the same initial conditions as above, but bring the cart back to 0.0 with a velocity of 0.0

  5. (10 points) Start with a random initial configuration and accomplished a user-defined cart pos/vel and pole pos/vel.

  6. (10 points) In each of these tests you'll find that your controller has a particular "capture region" where it works.  Define the limits of the capture region for your controller.

  7. (extra 10 points) Start the system with the pole pointing donward (PI/2).  Write a controller that brings the pole above the cart and balances there.

 

Turnin and Grading

 

Send an email to the TA including the zipped version of your code.

 

The TA will arrange grading sessions when each student will be granted a block of time to conduct a demo of the full functionality of his or her system.  The TA reserves the right to test specific scenarios of his design.  He will have a PC outfitted with Windows Visual Studio.net and Linux to run you code.  Please make sure your code is able to execute on such a machine.  If you desire to bring in a laptop on which your demo runs, please feel free.  

 

Late policy: You have five late days to use during the semester.  Each late day you use will provide you with a 24 hour extension. 

 

Outside Resources

 

You can use books and the web to learn about controlling a cart/pole.  You may also use books and the web to acquire graphics interface libraries, search algorithms, and matrix manipulation code.