Brief description of sources, variables & functions used in simulation program

The simulator program is divided into several source files:
  • _spider.irt - contains main simulator routines
  • _simulation.irt - functions that creates two animation sequences (landing & walking)
  • _move.irt - functions that calculates & performs body & leg movements.
  • _misc.irt - miscellanious functions used in simulation.
  • _math.irt - several mathematical functions used in simulation.
  • _model.irt - functions for parsing the 2N-legged model object.
  • _params.irt - functions for getting/setting different leg parameters.
  • _var.irt - global variables used in the simulation process.
  • _ground.irt - functions that create ground surface & target flag. (see General overview of the simulation process).
A more detailed description of each source file is given below.

In addition to the mentioned above files three demo files are included:
  • demo_walk.irt - creates random surface, places a flag at random position and generates an animation of the specified model walking from specified point to the flag.
  • demo_full.irt - creates random surface, places a flag at random position and generates an animation of two ants and one spider walking from different points to the flag.
  • one_period.irt - generates animation of one step of specified model.

_spider.irt

Functions:
  • createSpiderAnim - gets five parameters:
    • m_modelName - the filename of selected 2N-legged model object.
    • m_allowTilt - the list of two boolean variables for enabling/disabling the body's tilt along X & Y axises.
    • m_bodyCoor - the initial position of the model's body.
    • m_bodyXdir - the initial X direction of the model's body.
    • m_timeLimit - the time limit for animation.
    and generates a full animation sequence for the specified model including landing on the ground & walking to the flag. Remark: surface & flag should be generated before calling this function. Returns the model's object with generated animation.

  • createSpiderPeriodAnim - gets one parameter:
    • m_modelName - the filename of selected 2N-legged model object.
    and generates an animation sequence for one full forward step. Returns the model's object with generated animation with "XStepAnim" attribute holding the length of the step.

_simulation.irt

Functions:
  • createLandSpiderAnim - gets a single parameter doLanding. If it's TRUE then this function generates landing animation sequence. Otherwise the function simply places the spider on the ground without animation.

  • getStepDirection - returns a list containing the information about the next step:
    • stepAngle - the angle, which the spider's body should rotate.
    • stepDist - the distanc, which the spider's body should move.
    • stepVec - the vector of the step.


  • createStepSpiderAnim - receives four parameters:
    • stepAngle - the angle, which the spider's body should rotate.
    • stepDist - the distanc, which the spider's body should move.
    • stepVec - the vector of the step.
    • isLastStep - tells weather it's last step in sequence (leg's are placed in initial position after the step).
    and generates appropriate animation sequence that moves the legs and body to make one single step in specified direction.

  • createMoveSpiderAnim - generates walking from landing point to the target flag animation sequence.

_move.irt

Functions:
  • setSpiderAnim - sets the animation curves stored in the bodyAnimSeq, legRotor1AnimSeq, legRotor2AnimSeq, legRotor3AnimSeq variables to the actual objects.

  • moveLeg - gets five parameters:
    • side - the side of the Spider ('-1' for left, '1' - for right)
    • ind - the index of the leg.
    • footCoorNew - a target point for leg's foot.
    • m_animTime - starting time of the animation curve.
    • m_animPeriod - the time period of the animation curve.
    calculates the current and new rotor angles of specified leg and than generates appropriate animation curves for each rotor of specified leg and saves new footCoor as a parameter of the leg in arrLeg array (see _vars.irt and _params.irt)

  • moveLegDir - gets five parameters:
    • side - the side of the Spider ('-1' for left, '1' - for right)
    • ind - the index of the leg.
    • footDir - a vector that tells the direction in which the foot of the specified leg should be moved.
    • m_animTime - starting time of the animation curve.
    • m_animPeriod - the time period of the animation curve.
    calculates the new foot coordinates by adding footDir to the current foot coordinates of specified leg and than calls moveLeg function.

  • moveBody - gets three parameters:
    • bodyCoorNew - a new coordinate of the spider's body.
    • m_animTime - starting time of the animation curve
    • m_animPeriod - the time period of the animation curve.
    generates coresponding animation curves (saves them to bodyAnimSeq variable), and than changes the bodyCoor variable to the specified point.

  • rotateBody - gets four parameters:
    • bodyZdirNew - a new direction for Z axis of the body.
    • bodyXdirNew - a new direction for X axis of the body.
    • m_animTime - starting time of the animation curve
    • m_animPeriod - the time period of the animation curve.
    generates coresponding animation curves (saves them to bodyAnimSeq variable), and than rotates the bodyZdir & bodyXdir in specified direction.

_misc.irt

Functions:
  • getGroundZ - gets X and Y as parameters and returns Z coordinate of the ground surface at the (X,Y) point.

  • getGroundZunderSpider - gets three parameters:
    • m_bodyCoor - the coordinates of the body origin.
    • m_bodyZdir - the direction of the Y axis of the body.
    • m_bodyXdir - the direction of the X axis of the body.
    and returns maximum Z coordinate of the ground under the spider's body with specified body position.

  • getSpiderTiltAngles - gets three parameters:
    • m_bodyCoor - the coordinates of the body origin.
    • m_bodyZdir - the direction of the Y axis of the body.
    • m_bodyXdir - the direction of the X axis of the body.
    and returns a list containing new bodyXdir & bodyZdir according to the inclination of the ground surface.

  • getCoorFootOnGround - gets six parameters:
    • m_bodyCoor - the coordinates of the body origin.
    • m_bodyZdir - the direction of the Y axis of the body.
    • m_bodyXdir - the direction of the X axis of the body.
    • side - the side of the Spider ('-1' for left, '1' - for right)
    • ind - the index of the leg.
    • footCoor - desired coordinate of the foot.
    and returns a point around footCoor where the foot of specified leg can be placed (the function takes in account the form of the surface).


_math.irt

Functions:
  • vectorLength - gets a vector as a parameter and returns its length.
  • vectorAngle - gets two vectors as parameters and returns the angle between them (in radians).
  • vectorDistance - gets two vectors as parameters and returns the length of their subtraction.
  • pointDistance - gets two points as parameters and returns the distance between them.
  • rad2deg - gets numeric value as parameter and converts it from radians to degrees.
  • deg2rad - gets numeric value as parameter and converts it from degrees to radians.
  • sign - gets numeric value as parameter and returns its sign.

  • rotateXYZdecomp - decomposes any rotation matrix into three rotation Euclidian matricies in the following order (rot_x,rot_y,rot_z)
  • rotateZYXdecomp - the same in opposite order.

  • convertSpiderToWorld - gets four parameters:
    • m_bodyCoor - the coordinates of the body origin.
    • m_bodyZdir - the direction of the Y axis of the body.
    • m_bodyXdir - the direction of the X axis of the body.
    • pt - the point with some coordinates.
    converts the coordinates of specified point from spider's coordinate system to the World one.
  • convertWorldToSpider - gets four parameters:
    • m_bodyCoor - the coordinates of the body origin.
    • m_bodyZdir - the direction of the Y axis of the body.
    • m_bodyXdir - the direction of the X axis of the body.
    • pt - the point with some coordinates.
    converts the coordinates of specified point from World coordinate system to spider's one.

  • convertFootRotor2Coor - gets three parameters:
    • side - the side of the Spider ('-1' for left, '1' - for right)
    • ind - the index of the leg.
    • footRotor - a list of three rotor angles: Omega,Alfa,Beta.
    and returns the point with coordinates of the leg's foot that corresponds to specified rotor angles.
  • convertFootCoor2Rotor - gets three parameters:
    • side - the side of the Spider ('-1' for left, '1' - for right)
    • ind - the index of the leg.
    • footCoor - a point with coordinates of the leg's foot.
    and returns the list of three rotor angles that takes leg's foot to the specified point.

_model.irt

Functions:
  • loadModel - loads the model, divides it into separate objects, calculates the body dimensions & altitude above the ground, calls parseLegModel for each of the model leg objects to get geometry & informations about each leg.
  • parseLegModel - calculates "hip" and "shin" length from the coordinates of the leg's origin, leg's knee & leg's foot (saves them as a parameters to the legArr using functions from _params.irt), calculates transformation matricies, which takes the leg parts from the origin to their actual places.

_params.irt

Functions:
  • getShinOriginMatrix/setShinOriginMatrix - gets the spider's side (-1 for left, 1 for right) and leg index as parameter and returns/sets the matrix that takes corresponding "shin" part of the leg from the origin to its actual place.
  • getLegOriginMatrix/setLegOriginMatrix - gets the spider's side (-1 for left, 1 for right) and leg index as parameter and returns/sets the matrix that takes the corresponding leg from the origin to its actual place.
  • getLenHip/setLenHip - gets the spider's side (-1 for left, 1 for right) and leg index as parameter and returns/sets the length of the corresponding "hip".
  • getLenShin/setLenShin - gets the spider's side (-1 for left, 1 for right) and leg index as parameter and returns/sets the length of the corresponding "shin".
  • getCoorLeg/setCoorLeg - gets the spider's side (-1 for left, 1 for right) and leg index as parameter and returns/sets the coordinates of the corresponding leg's origin.
  • getCoorKnee/setCoorKnee - gets the spider's side (-1 for left, 1 for right) and leg index as parameter and returns/sets the coordinates of the corresponding leg's knee (i.e. the joint point between "hip" and "shin")
  • getCoorFoot/setCoorFoot - gets the spider's side (-1 for left, 1 for right) and leg index as parameter and returns/sets the current coordinates of the corresponding leg's foot.
  • getCoorFootOrig/setCoorFootOrig - gets the spider's side (-1 for left, 1 for right) and leg index as parameter and returns/sets the original coordinates of the corresponding leg's foot.

_var.irt

Constants:
  • modelName - filename of selected 2N-legged model object.
  • timeLimit - animation time limit (to make the simulation process shorter).
  • allowTilt - enables/disables spider's tilt according to the inclination of the ground surface.
  • groundCellSize & groundNumCell - defines the area of the surface (as well as the surface complexity).
  • groundHills - the height of hills and the depth of pits.
Variables:
  • srfGround - the ground surface object.
  • objFlag - the target flag object.
  • objSpider - the spider object.
  • objScene - the object that contains all objects in a scene.

  • bodyWidth,bodyLength,bodyHeight - the dimensions of the Spider's body.
  • aboveGround - the body altitude above the ground.
  • numLeg - the number of legs on each side of the Spider.

  • flagCoor - the coordinates of the target flag.

  • bodyCoor - the current coordinates of the Spider.
  • bodyXdir - the current direction of the X axis of the Spider.
  • bodyZdir - the current direction of the Z axis of the Spider.

  • coefStepRotate - numeric value from 0 to 1 that defines "rotation" step length
  • coefStepWalk - numeric value from 0 to 1 that defines "walking" step length
  • minStepAngle - numeric value that defines the angle of model "rotation" step
    (see Mathematical description of trajectory calculation)
  • stepType - string value that defines step type ("cross" or "parallel")


  • animTime - current time of the simulated animation
  • bodyAnimSeq - the list of animation curves for the Spider's Body
  • legRotor1AnimSeq - the array of the lists of animation curves for the 1st rotor of each leg (that controls Omega angle)
  • legRotor2AnimSeq - the same for 2nd rotor (that controls Alfa angle)
  • legRotor3AnimSeq - the same for 3rd rotor (that controls Beta angle)
    (see Mathematical description of leg movement)

  • curLegMove - '0' if the 'even' legs should be moved at the next step, '1' - for 'odd' legs.
  • arrLeg - the array of leg parameters like hip & shin length, leg, knee amp; foot coordinates. For more details see the description of the functions in _params.irt file.

_ground.irt

Functions:
  • groundCreate - gets four parameters:
    • m_randomInit - the random seed number
    • m_groundNumCell - the number of cells in ground surface mesh.
    • m_groundCellSize - the size of cells.
    • m_groundHills - the height of hills and the depth of pits.
    and generates the random ground surface.
  • flagCreate - generates target flag object at random place.