CS 551 / CS 651: Computer Animation

Fall 2003

Professor Brogan

 

Assignment 4: Control - Swinger

 

Due: 5:00 Thursday November 20th

 

 

Introduction

 

In this assignment, you will write a control algorithm for a physically simulated girl who must ride a swing.  I have provided a skeleton program (VisStud-ZIP with FLTK, VisStud-ZIP w/o FLTK) for you to use. Compile the code, and execute the program to see what the basic controller accomplishes.

 

You must improve the quality of the controller so the girl leans back in the seat and kicks her legs in order to gain altitude on the swing.  Also, there is a variable that releases her from the swing (you can press 'x' while the program is running to manually force her to jump).  The controller you write must be able to activate the release variable so the girl lands a prespecified distance from the swing. As a user of your system, I will use the user interface to set the value of the variable ls.landingSite and you must control her swinging actions and the release variable to have her hit the ground at that specified location (plus or minus 0.25 meters).  The ls.landingaSite variable may be positive or negative and may be bigger than your swinger can accomplish (select a release point that does the best you can).

 

Details

 

The skeleton code that I have provided uses OpenGL/glut, the machine generated code of a physical simulation toolkit (SD-Fast),  FLTK, and some home-grown code. After executing the swinger program, the FLTK window fires up and you should be able to click on the start button to see the girl start swinging.  There are many files included in this code distribution. You can ignore most of them. In fact, you can do most all of your control system programming solely in the swing.cpp file. You'll end up making changes to FLTK-related files as well when you add additional control states (like FORWARD and BACKWARD)

 

Here are some hints to understand the code. Nearly all variables are global. Please send me your questions before wasting a lot of time learning it.  The variables have cryptic names and I'll cc the class on any explanations 

 

Variable Name Meaning
st State vector array
tau Array of torques applied to the degrees of freedom
st_d Array of desired values for state vector components
ls A freely organized array of useful variables

 

In the swing.cpp code, you'll see that the function swing() does the work of the control system state machine. The function determines desired positions for the shoulder, elbow, hip, and knee joints. The function also updates the current control system state of the character (moving backwards or forwards, etc.). You may (and probably should)  improve the system by adding new states, changing when transitions occur, and by changing what is done in each state. For example, the following variables can be tweaked in the current implementation to achieve different results: ls.shld_folded, ls.shld_unfolded, ls.elb_folded, ls.elb_unfolded, ls.hip_bend, ls.legs_out, ls.knee_bend, ls.knee_out.  But you should ask yourself when you really transition from a tuck to a layout position when swinging.  Is it really at the peaks of the motion?   Additionally, you'll find in this file a function named ramp().  The fourth argument to this function controls how quickly the girl moves to the position indicated by the ls.* variable.  Make the number smaller to make her move more slowly.

 

Also note the variable ls.dynState will release the girl from the swing as soon as it is set to 1.0 (see the keyboard handler event for 'x' in main.cpp).   You'll want to add code to your swing functions that automatically sets this variable to 1.0 at the appropriate time to accomplish the correct jumping distance.  When the girl hits the ground, the simulation stops and her jumping distance (when her center of mass reaches the ground plane) so I can inspect the value of her st.x value, her distance from the swingset.

 

If you want to see the initial values of any of the variables of the character, look in legui.cpp.  Remember that the character's state is defined by the x/y/z of the center of mass, the orientation (quat{1234}) of the center of mass, and the joint rotations of each degree of freedom.  The joints are arranged in a hierarchy, so the shoulder angle moves both the upper and lower arms.  Hopefully the st variables have somewhat intuitive names.  If not, ask me.

 

You will be graded both on how well she hits the desired spot and how long it takes her to get there. I don't care about how long it takes your simulation to execute, but I want to minimize the time in 'simulation seconds.' You can view the variable dynstime.time to see how time passes.

 

Viewer Interface

 

The left mouse button rotates and the right mouse button zooms.

 

Simulation Interface

 

Here is some of the information presented in the user interface.  Note that the ls variables can be changed, but you'll have to stop and start the simulation in order for the change to take effect.  This is because letting fltk check the updated values of the type-in boxes all the time takes compute cycles away from the simulation.

 

Buttons

Start

set ls.run to -1.0 (run indefinitely; set to a positive number to run for n-seconds)

Stop

set ls.run to 0.0 (stop running)

Output Only

Time

dynstime.time

Current State

ls.inx

Current velocity (in world coords)

ls.cmxd, ls.cmyd, ls.cmzd (stands for center of mass {xyz} velocity)

Current velocity of angle of upper swing rope

st.swingl_yd

Current angle of upper swing rope

st.swingl_y

Input Only

Landing Site

ls.landingSite

Input/Output

How straight are upper legs?

ls.legs_out

How straight are lower legs?

ls.knee_out

How bent is upper leg?

ls.hip_bend

How bent is knee?

ls.knee_bend

How folded is upper arm?

ls.shld_folded

How folded is lower arm?

ls.elb_folded

How straight is upper arm?

ls.shld_unfolded

How straight is lower arm?

ls.elb_unfolded

 

 

Turn in

 

Turn in a README that explains what changes you chose to make in the control system of the swinger.  I'm not interested in the values you pick for the variables, rather the conceptual changes.  She has more states, or switches between the states in a novel way. 

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

 

Q & A

  1. Why is the switching condition from FORWARD to BACKWARD: ((ls.cm_zd < 0) && (st.swingl_yd > 0.0))?  This is because the girl switches to the backward-swinging state when the velocity of her center of mass is negative (she's falling) and when the velocity of the swing angle is positive (she is facing the negative y axis and thus this confirms she is swinging backwards).  Without using both of these checks, torques applied to her shoulders could momentarily cause her center of mass to move up or down and at the peak of her swing, the swing velocity could oscillate slightly and cause an incorrect state.

  2. dynstime.time just keeps track of the simulation's version of time. The value at startup isn't important, but the progression of time while running the simulation is important.

  3. Should I worry about the Ramp function at all or just more about adding states and position variables?

    The 'slope' values of the ramp functions are parameters you can play with. Unfortunately, playing with these variables requires a recompile the way the system is set up now.
     

  4. I've tweaked around with all of the limbs, including neck and ankles.  But, I can't get the shoulder to move as I want it to. Is there a constraint set on those limbs within the code? For example, if I wanted her arms to be straight out in front of her, her shoulder would be -pi/2 and her elbow should be 0. But it's not giving me that result.

    Note that the ls.shld_unfolded and ls.elb_unfolded need to be changed in unison. The girl can't straighten her elbows all the way without also changing the angle of her shoulder. To figure out how the two angles change, draw a triangle. The length of one side is
    0.339 (length from hands to the swing seat), another is 0.223 (the length of the upper arm), and the last is 0.167 (the length of the lower arm). Play with the trig to change the angles of
    the triangle while preserving the lengths of the sides. What are the values of individual positions relative to? for example: st.hipr_y, st.kneer_y, etc.

    All the rotational parameters are measured in radians. The 0-angle for these joints occurs where the girl is standing straight up, with her hands at her side and her feet flat on the ground. So, a knee or hip value of 0, should result in the joints making a 0 radian
    angle between the inboard and outboard bodies.