Click here to Skip to main content
11,481,850 members (62,813 online)
Click here to Skip to main content

Tank Simulator

, 12 Oct 2005 CPOL 179.5K 4.3K 19
Rate this:
Please Sign up or sign in to vote.
It simulates a battle tank based on vehicle dynamics.
Sample Image - Tank.jpg

Introduction

Tank Simulator is a software tool to simulate a battle Tank based on its vehicle dynamics. Vehicle dynamics allow simulations to contain parameters that most clearly approximate the dynamic performance of the vehicle. Tank Simulator is still under development and currently simulates only few vehicle parameters like weight, dimension, velocity, suspension and braking effects. The complete version will be one which will have all the vehicle parameters included and exhibits Track-Terrain interaction. The developmental activity uses a computational engine called Open Dynamics Engine (ODE), which is an industrial standard library to simulate articulated bodies. It provides interactive or real-time simulation. 3D Visual environment of the simulator uses a Graphics Library that is packaged with ODE. Functions have been added to this library to suit the application’s need. The complete software is packaged as an integrated environment in Visual C++.

Overall System Architecture

Interface & Graphics Module: These modules are packaged with ODE under the name drawstuff. It is basically a graphics library which provides function to simulate terrain, provide camera view, etc. The library has been customized to draw 3D tank body parts - wheels, idlers, sprocket-wheels, chassis, chain, & turret and other visual requirements of the simulator.

Simulation Module: This module is responsible for executing the simulation code, which involves creation of dynamic world, integration of tank body, parts using joints, collision handling, governing tank behavior, iterating the simulation loop and finally destroying the dynamic world. This module is built using Open Dynamic Engine (ODE).

How It Works

The graphics part of Tank simulator has been developed using OpenGL. However I will just explain only the simulation part of it which uses ODE. There are two things that are quite central to ODE - bodies and joints. Tank is an assembly of parts like chassis, wheels, turret, chain, etc. These parts are first drawn graphically and later provided with rigid body properties which can have mass and show collision properties. These bodies are then joined together using various types of joints available in ODE to form a complete Tank. Tank now just does not remain a 3D figure on the screen, but becomes a vehicle with physical properties. Here’s one part of code that shows it:

//simulation loop
static void simLoop (int pause)
{
.
.
.
dSpaceCollide (space,0,&nearCallback);   	//checks for collision
dWorldSetQuickStepNumIterations (world,85); 
dWorldQuickStep (world,0.05);    		//advance the simulation
//chassis body     
dsDrawTankBody(dBodyGetPosition(ChassisBody[0]),dBodyGetRotation(ChassisBody[0]),sides);
//turret body
  dsDrawTurret(dBodyGetPosition(TurretBody[0]),dBodyGetRotation(TurretBody[0]),sides);
.
.
.
}

//main function
int main (int argc, char **argv)
{
.
.
.
dMass m;        				//mass variable
// setup pointers to drawstuff callback functions
dsFunctions fn;
.
.
fn.step = &simLoop;        			//call for simulation loop
.
// create world
world = dWorldCreate();
space = dHashSpaceCreate (0);        	//creates space for bodies
contactgroup = dJointGroupCreate (0);
dWorldSetGravity(world, 0,0,GRAVITY);        	//sets gravity 9.81
ground = dCreatePlane (space,0,0,1,0);     	//forms ground
// chassis body
ChassisBody[0] = dBodyCreate (world);
dBodySetPosition (ChassisBody[0],0,0,STARTZ);
dMassSetBox (&m,1,LENGTH,WIDTH,HEIGHT);
dMassAdjust (&m,CMASS);
dBodySetMass (ChassisBody[0],&m);
ChassisBox[0] = dCreateBox (0,LENGTH,WIDTH,HEIGHT);
dGeomSetBody (ChassisBox[0],ChassisBody[0]);
.
.
//chassis -turretjoint
TurretJoint[0] = dJointCreateHinge (world,0);			//creates hinge joint
dJointAttach (TurretJoint[0],ChassisBody[0],TurretBody[0]); 	//attaches joint
const dReal *a1 = dBodyGetPosition (TurretBody[0]);
dJointSetHingeAnchor (TurretJoint[0],a1[0],a1[1],a1[2]);
dJointSetHingeAxis (TurretJoint[0],0,0,1);
dJointSetHingeParam (TurretJoint[0],dParamLoStop,0);
dJointSetHingeParam (TurretJoint[0],dParamHiStop,0);
dJointSetHingeParam (TurretJoint[0],dParamSuspensionERP,ERP);
.
.
.
}

The simulation module has been developed based on a Simulation Algorithm given in ODE. Please refer to ODE user guide for this. The algorithm starts with creation of a dynamic world in which simulation takes place then adding bodies into it, giving bodies parameters and then joining these bodies to form the vehicle, later on calling collision handler to determine any collision with other objects in the simulation environment and finally destroying the world. The main function explains exactly this. Using dWorldCreate, we create a dynamic world then give this world a gravity of 9.81. We create a plain ground on which the tank moves. Using dBodyCreate, we create bodies, set its position by dBodySetPosition, mass by dBodySetMass and then associate this body with the geometrical figure we have created using dGeomSetBody. There are various types of joints supported by ODE like hinge joint, slider joint etc. dJointCreateHinge creates a hinge joint. Joints are attached between two bodies by dJointAttach. Other functions have been used to set various parameters of joint. Once dynamic world and bodies and joints are created to form the vehicle, a simulation loop simLoop is called. The basic function of this simulation loop is to check for any collision and then advance the simulation given by its stepsize.

References

  • Open Dynamics Engine v0.5 User Guide by Russell Smith.
  • http://www.sourceforge.net provides CVS repositories for ODE and some ODE examples.
  • You can refer to Heavy Vehicle Systems, Vol 9, Nov 2, 2002 by Corina Sandu and Jeffrey S. Freeman to understand Tank Vehicle Dynamics.

I have included a readme file with the source code that contains instructions to setup ODE on your system. Apart from this, I have included three source code folders that show simulator under different development stages. I am currently developing track terrain interaction of tank.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Bidhan Chandra
Software Developer
Ireland Ireland
No Biography provided

Comments and Discussions

 
GeneralCompile using vc 2008 Pin
shabyb24-Feb-09 9:44
membershabyb24-Feb-09 9:44 
Questionmine are falling off too! Pin
de-idioot18-Nov-08 22:10
memberde-idioot18-Nov-08 22:10 
QuestionMy treads are falling off Pin
danharibo17-Aug-07 10:27
memberdanharibo17-Aug-07 10:27 
AnswerRe: My treads are falling off Pin
de-idioot18-Nov-08 22:13
memberde-idioot18-Nov-08 22:13 
GeneralCouldnt open with .NET 2003 Pin
zulka1-Aug-06 23:55
memberzulka1-Aug-06 23:55 
GeneralRe: Couldnt open with .NET 2003 Pin
Bidhan Chandra4-Aug-06 6:32
memberBidhan Chandra4-Aug-06 6:32 
Generalplease please Pin
Anonymous13-Oct-05 12:51
sussAnonymous13-Oct-05 12:51 
Generalplease delete Pin
Anonymous13-Oct-05 5:36
sussAnonymous13-Oct-05 5:36 
Generalsource code modification Pin
Bidhan Chandra10-Oct-05 2:00
memberBidhan Chandra10-Oct-05 2:00 
GeneralRe: source code modification Pin
Abdull Rehman26-Oct-05 17:54
memberAbdull Rehman26-Oct-05 17:54 
General[Message Deleted] Pin
seyedof15-Sep-05 23:58
memberseyedof15-Sep-05 23:58 
GeneralRe: Broken link Pin
SergeVrt19-Sep-05 11:03
memberSergeVrt19-Sep-05 11:03 
General[Message Deleted] Pin
seyedof19-Aug-05 4:36
memberseyedof19-Aug-05 4:36 
GeneralRe: Broken link Pin
Bidhan Chandra22-Aug-05 20:30
memberBidhan Chandra22-Aug-05 20:30 
GeneralRe: Broken link Pin
seyedof23-Aug-05 0:34
memberseyedof23-Aug-05 0:34 
GeneralRe: Broken link Pin
syedhs22-Oct-05 4:51
membersyedhs22-Oct-05 4:51 
GeneralImage missing. Pin
WREY29-Jul-05 10:14
memberWREY29-Jul-05 10:14 
GeneralWell... Pin
Kochise27-Jul-05 23:56
memberKochise27-Jul-05 23:56 
GeneralRe: Well... Pin
norm.net28-Jul-05 2:19
membernorm.net28-Jul-05 2:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150520.1 | Last Updated 13 Oct 2005
Article Copyright 2005 by Bidhan Chandra
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid