Get Vehicle Simulation Environment at SourceForge.net. Fast, secure and Free Open Source software downloads

Modeling, Simulation, & Control

with

Java3D Visualization

Sparky

[ VSE | The 3D environment | Requirements & Installation | Download | Simulation Models | License ]

VSE

The Vehicle Simulation Environment (VSE) library consists of classes designed to aid in building and propagating vehicle models. A model is a system of differential equations, and propagation generally means integrating this system over time. The library also contains utilities to display the model state in a Java3D environment (multiple models can be loaded at once). The simulation environment is built as needed to support models of interest. Although this project is very much a work in progress, the decision to make it available is based on the belief that it may be of use to people, especially those in school taking a simulation and controls class. An explanation of a Bare Bones 6DOF model is given here. It is hoped this description, along with comments in the example model's code, will be enough to get someone with little to no knowledge of the Java3D API started.

A quick note on design philosophy: Much of this project is academic in nature. It would probably be implemented differently in the commercial world. The author is exploring aspects of OOD, and some of the design decisions may end up serving more as lessons learned in how not to do things, instead of the best way to do them. That being said, the current structure has resulted in very little time spent debugging. The use of specialized matrix and vector classes, along with the use of enumerations for indexing, has resulted in many potentially difficult to find errors being caught at compile time instead of run time. One of the design goals behind this project is to allow the compiler to do as much of the debugging as possible.

Another design goal is efficiency. First of all, the use of the "new" statement for temporary objects within methods that may occur during every integration step is avoided. Instead, such objects are initialized when the containing classes are instantiated, and reused on each call to the method. Given that most classes are kept relatively small by design, such object "global" variables should not create much confusion, especially since their purpose is generally well documented in the code. While the Java garbage collector is very efficient, there is no reason for continuously placing new objects on the heap when they can be reused. Past experience has shown that memory deallocation tends to be more resource intensive than allocation.

In addition to object reuse, loops are avoided when possible. For example, if an object has three elements, instead of looping for i=1 to 3 to multiply each element by a scalar value, each element is manually multiplied by the scalar:

  a[0] *= b;         for (i=0; i<3; i++) {
  a[1] *= b;   vs.     a[i] *= b;
  a[2] *= b;         }
This method is obviously not employed if it makes the code harder to follow or becomes cumbersome. It is used when convenient because testing has shown a 10:1 improvement in performance (even when using the JIT, which comes standard with Java now days).

The 3D environment

The Java3D API was chosen for visualization primarily because it is well documented. In addition, the object oriented scene graph API is relatively easy to learn for those with no OpenGL programming experience. If the desire is to build a cutting edge modern OpenGL Java game, then the Java bindings for OpenGL, JOGL, would probably be the best solution. For those who are more interested in modeling and simulation (math and physics), and want to display information in a highly configurable, modern OpenGL environment, without spending the time to fully delve into graphics programming, Java3D is the way to go.

Controls for each environment will depend on the model in use. However, unless the mouse has been remapped in the operating system, the left mouse button will rotate the view while the right mouse button will pan. If a scroll wheel is available, it will control zoom - otherwise, the middle mouse button can be used to zoom in and out.

Mesh models have been built with Misfit Model 3D. I am barely competent at using it, so my solid models are very basic....

Requirements & Installation

This project is currently built with Java 1.6.0 and java3D 1.5.1. Java 1.5 should work, as should earlier versions of Java3D (I believe Java3D 1.3.1 is sufficient). Newer versions of Java3D should be compatible with most hardware. Java3D may still report a warning message with older graphics cards, misinterpreting the version of GLX in use. This message can usually be ignored. Installation procedures with respect to Java and Java3D are best handled by the instructions from their respective download pages. Because installation will differ from one OS to another, I will not attempt to describe it here.

To run any of the included models, it is necessary to install the Vehicle Simulation Environment. The VSE filename contains the prefix "vseLib", along with a tag in the form of "-YYYYMMDD", and ends with the filename extension ".jar". For example:

vseLib-20080930.jar
If the JAR file is not going to be extracted, it is probably easiest to rename or link it to "vseLib.jar" once downloaded. This way, the CLASSPATH environmental variable does not need to be modified each time a new version is downloaded.

Installation of the library involves copying the JAR file to whatever location you like, and adding it to your CLASSPATH. How you add it to your CLASSPATH will depend, once again, on the operating system you are using and the environment in which Java is run (command line, shortcut, IDE, etc...). From the command line, in Linux (bash), you would add the following line to your .profile (or similar):

export CLASSPATH=.:/usr/local/javalibs/vseLib.jar:$CLASSPATH
This sets your CLASSPATH environmental variable to include the current directory, the path to vseLib.jar (assuming you copied it to /usr/local/javalibs/), and to include the old CLASSPATH.

Each individual model package follows the same naming convention, and is installed in a similar fashion. For example, if the library is installed in /usr/local/javalibs/, and the model is installed in my home directory "kurt", then the update to my CLASSPATH would be:

export CLASSPATH=.:/usr/local/javalibs/vseLib.jar:/home/kurt/modeling/sixdQ.jar:$CLASSPATH
Models, along with classes used to run them in a simulation, are packaged individually as libraries. The actual model typically consists of two classes. The most basic represents a system of differential equations, and does nothing more than take the current time and state vector as inputs, returning the corresponding derivative to that state vector. Another class contains this set of differential equations, and is where the integrator is chosen, the ability to propagate (take a step forward in time) is configured, outputs are generated if necessary, and accessor methods to the state vector, control values, and output values are defined. Both of these classes are very generic and independent of any GUI or graphics libraries. In fact, a set of differential equations for 6DOF simulations exists in the VSE library, eliminating the need to build this class for a large variety of models.

The remaining classes in each package define the simulation environment, and usually contain classes that generate the GUI, set up the 3D environment, select the solid model, and connect the 3D environment to the model being simulated. User input controls (keyboard, mouse, etc...) are configured in one of these classes as well.

The primary class in each model package implements an interface needed to start the simulation. This class either needs to be instantiated within an application to run, or launched directly with the RunVSim application. The JAR file containing this application is called runVSim.jar. This JAR file can either be added to the CLASSPATH, or the RunVSim.class file can be extracted from the jar file with the command:

jar xvf runVSim.jar RunVSim.class
Either way, the simulation can be run with the command:
java RunVSim simulation_primary_class_name
In the above command, if the RunVSim.class was extracted from the runVSim.jar file, then it is assumed this class resides in the current directory. Otherwise, the runVSim.jar file needs to be added to your CLASSPATH. Also, the "simulation_primary_class_name" includes the full package path to the model (see models below for the exact syntax to start each). Note that no class path is needed for the RunVSim application because it was built with the default package.

In Summary, vseLib.jar and runVSim.jar should be downloaded and added to your CLASSPATH to run any of the models included in the project. Note that all source code is included in each JAR file. It is probably easiest to forgo adding individual models to your CLASSPATH because each model is meant to act as a starting point for your own needs. It is probably best to either un-archive each model's JAR file if you code from the command line, or import each jar into your IDE.

Note that two .jar files are available on the download page. One contains the VSE library, and another is used to hold the runVSim.jar file, the example models, and some documentation.

Simulation Models

1DOF Mass Spring Damper Simulation

This is a very simple single degree of freedom model representing the classic mass, spring, damper system. MassSpDp3D is the main class, and can be run with the following statement from the command line:
java RunVSim com.motekew.msd3d.MassSpDp3D
When run, it will ask for the mass, spring constant, and dampening properties, along with the initial conditions. The following are reasonable values to start with:
Mass (Kg):  5.0
Spring constant (N/m):  1.0
Dampening (N/(m/s)):  0.5
Initial position (m):  7.5
Initial velocity (m/s):  0.0
Start time (s):  0.0
There is only one control for this model - the right arrow will increment a constant force in the positive X direction, and the left arrow will increment the force in the negative X direction. This force is set to zero at the start of the simulation. The above initial conditions can be replicated by setting the initial position to zero, and incrementing the force with the right arrow 15 times. This results in 7.5 units of force, that will pull the mass 7.5 units along the X-axis. Once the system dampens out, either the up or down arrow will zero the force, causing the mass to be released so it can oscillate about the origin.

Screenshot Download

Bare Bones 6DOF Simulation

As the title suggests, this is a bare bones six degree of freedom simulation. The vehicle model is for a spacecraft in empty space under no external influences (gravity, drag, solar pressure, etc...). The spacecraft can thrust only along its longitudinal axis, propelling the vehicle in a forward direction - the attitude of the vehicle must be changed to alter direction. Torques can be applied about each axis (via thrusters, reaction wheels, magic, take your pick). Note that gyroscopic coupling results in an acceleration about a third axis when there are angular rates about two others. In addition, a single plane of symmetry in the spacecraft mass distribution means torques can be applied about only one axis (y-axis/pitch) without affecting the other axes. This coupling can make the vehicle very difficult to control if the angular rates are anything but slow.

More detailed information on the structure of this model can be found here.

SixDQ is the main class, and can be run from the command line with the statement:

java RunVSim com.motekew.sixdq.SixDQ
Currently, all physical characteristics (mass, inertia tensor, thrust/torque levels) of the vehicle are hard coded. The vehicle can be controlled with the following commands:
E           Pitch Down
D           Pitch Up
F           Roll Right Wing Down
S           Roll Left Wing Down
G           Yaw Right
A           Yaw Left
UP_ARROW    Increase Thrust
DOWN_ARROW  Decrease Thrust (minimum value of zero - no negative thrust)
SPACE BAR   Show/Hide Model State Viewer window
Q           Zero Thrusts & Torques
R           Zero All Rotation Rates
T           Zero All Translational Velocity

The 'R' and 'T' commands are there to help one recover from an out of control situation. These two commands simply zero the appropriate terms in the state vector. Eventually, a control system will be added to perform such tasks correctly.

The Model State Viewer is a window that shows the current simulation time, the model state vector, the controls, and the output vector. The State Vector is as follows:

X:   X-axis position
Y:   Y-axis position
Z:   Z-axis position
DX:  X-axis velocity
DY:  Y-axis velocity
DZ:  Z-axis velocity
Q0:  Scalar component of Quaternion attitude
QI:  1st vector component of Quaternion attitude
QJ:  2nd vector component of Quaternion attitude
QK:  3rd vector component of Quaternion attitude
P:   Rotation rate about body X-axis (rad/sec)
Q:   Rotation rate about body Y-axis (rad/sec)
R:   Rotation rate about body Z-axis (rad/sec)
Everything has been normalized to some extent. The spacecraft is two distance units wide. Torques and rotations all follow the right hand rule. The Control vector contains the following elements:
FX:   X-axis force
FY:   Y-axis force
FZ:   Z-axis force
TX:   Torque about X-axis
TY:   Torque about Y-axis
TZ:   Torque about Z-axis
The Output Vector:
BANK:   Bank (deg)
ELEV:   Elevation (deg)
HEAD:   Heading (deg)
The state vector labels are automatically generated from the Enumerations used to represent them.

Screenshot Download

License

The entire VSE library is licensed under the GNU Lesser General Public License (LGPL). Each model is packaged into its own jar file and is also licensed under the LGPL. The RunVSim application is licensed under the GNU General Public License (GPL). Currently, GPL 2.0 and LGPL 2.1 are in use. I may change to GPL/LGPL 3.0 in the future, if I can come to understand them better.
Last updated: Feb 25, 2009
Kurt Motekew -- email: <motekew at earthlink · net>