NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgBulletCompressionSpring Class Reference

#include <tgBulletCompressionSpring.h>

Inheritance diagram for tgBulletCompressionSpring:
Collaboration diagram for tgBulletCompressionSpring:

Public Member Functions

 tgBulletCompressionSpring (const std::vector< tgBulletSpringCableAnchor * > &anchors, bool isFreeEndAttached, double coefK, double coefD, double restLength)
 
virtual ~tgBulletCompressionSpring ()
 
virtual void step (double dt)
 
virtual const double getCurrentAnchorDistance () const
 
virtual const double getCurrentSpringLength () const
 
virtual const btVector3 getAnchorDirectionUnitVector () const
 
virtual const btVector3 getSpringEndpoint () const
 
virtual const double getSpringForce () const
 
virtual const double getCoefK () const
 
virtual const double getCoefD () const
 
virtual const double getVelocity () const
 
virtual const double getDampingForce () const
 
virtual const double getRestLength () const
 
virtual const bool isFreeEndAttached () const
 
virtual const std::vector
< const tgSpringCableAnchor * > 
getAnchors () const
 

Protected Member Functions

virtual void calculateAndApplyForce (double dt)
 

Protected Attributes

std::vector
< tgBulletSpringCableAnchor * > 
m_anchors
 
tgBulletSpringCableAnchor *const anchor1
 
tgBulletSpringCableAnchor *const anchor2
 
double m_dampingForce
 
double m_velocity
 
bool m_isFreeEndAttached
 
const double m_coefK
 
const double m_coefD
 
double m_restLength
 
double m_prevLength
 

Detailed Description

This class defines the passive dynamics of a compression spring system, with damping, in the Bullet physics engine.

Definition at line 48 of file tgBulletCompressionSpring.h.

Constructor & Destructor Documentation

tgBulletCompressionSpring::tgBulletCompressionSpring ( const std::vector< tgBulletSpringCableAnchor * > &  anchors,
bool  isFreeEndAttached,
double  coefK,
double  coefD,
double  restLength 
)

The only constructor. Takes a list of anchors, a coefficient of stiffness, a coefficent of damping, and rest length of the spring.

Parameters
[in]anchors- a list of this spring cable's attachements
[in]isFreeEndAttached- boolean flag. If no, the spring only provides compression force. If yes, the spring is "attached" to both anchors, and provides a tension force too when the distance between anchors is greater than rest length.
[in]coefK- the stiffness of the spring. Must be positive
[in]dampingCoefficient- the damping in the spring. Must be non-negative.
[in]restLength- the length of the compression spring when unloaded.

The main constructor for this class

Definition at line 40 of file tgBulletCompressionSpring.cpp.

Here is the call graph for this function:

tgBulletCompressionSpring::~tgBulletCompressionSpring ( )
virtual

The virtual destructor. Deletes all of the anchors including anchor1 and anchor2

Definition at line 87 of file tgBulletCompressionSpring.cpp.

Member Function Documentation

void tgBulletCompressionSpring::calculateAndApplyForce ( double  dt)
protectedvirtual

Calculates the current forces that need to be applied to the rigid bodies, and applies them to the bodies of anchor1 and anchor2

This is the method that does the heavy lifting in this class. Called by step, it calculates what force the spring is experiencing, and applies that force to the rigid bodies it connects to.

Reimplemented in tgBulletUnidirComprSpr.

Definition at line 247 of file tgBulletCompressionSpring.cpp.

Here is the caller graph for this function:

const btVector3 tgBulletCompressionSpring::getAnchorDirectionUnitVector ( ) const
virtual

Return the unit vector in the direction of this spring

Returns the unit vector in the direction of this spring.

Definition at line 181 of file tgBulletCompressionSpring.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

const std::vector< const tgSpringCableAnchor * > tgBulletCompressionSpring::getAnchors ( ) const
virtual

Returns a const vector of const anchors. Currently casts from tgBulletSpringCableAnchors, which makes it impossible to return a reference

Todo:
figure out how to cast and pass by reference

Definition at line 296 of file tgBulletCompressionSpring.cpp.

Here is the caller graph for this function:

virtual const double tgBulletCompressionSpring::getCoefD ( ) const
inlinevirtual

Get the coefficent of damping

Definition at line 124 of file tgBulletCompressionSpring.h.

Here is the caller graph for this function:

virtual const double tgBulletCompressionSpring::getCoefK ( ) const
inlinevirtual

Get the coefficent of stiffness

Definition at line 116 of file tgBulletCompressionSpring.h.

Here is the caller graph for this function:

const double tgBulletCompressionSpring::getCurrentAnchorDistance ( ) const
virtual

Finds the distance between anchor1 and anchor2, and returns the length between them

Returns the distance between the two anchors. This is similar to the getActualLength function in tgBulletSpringCable.

Definition at line 139 of file tgBulletCompressionSpring.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

const double tgBulletCompressionSpring::getCurrentSpringLength ( ) const
virtual

Returns either restLength or current anchor distance, depending on isFreeEndAttached.

Returns the current length of the spring. If isFreeEndAttached, this can be either greater or less than m_restLength. If not, then spring can only exist in compression (less than m_restLength).

Reimplemented in tgBulletUnidirComprSpr.

Definition at line 151 of file tgBulletCompressionSpring.cpp.

virtual const double tgBulletCompressionSpring::getDampingForce ( ) const
inlinevirtual

Get the last value of the damping force

Definition at line 140 of file tgBulletCompressionSpring.h.

virtual const double tgBulletCompressionSpring::getRestLength ( ) const
inlinevirtual

Get the rest length of the spring (we're using these accessor functions per C++ style guidelines.)

Definition at line 149 of file tgBulletCompressionSpring.h.

const btVector3 tgBulletCompressionSpring::getSpringEndpoint ( ) const
virtual

Return the location of the free end of the spring. This is used, in particular, for rendering. See tgBulletRenderer.

Returns the location of the endpoint of the spring in space. The renderer uses this to draw lines more easily.

Reimplemented in tgBulletUnidirComprSpr.

Definition at line 201 of file tgBulletCompressionSpring.cpp.

Here is the caller graph for this function:

const double tgBulletCompressionSpring::getSpringForce ( ) const
virtual

Returns the force currently in the spring, either compression only / a positive force only (if isFreeEndAttached is false), or potentially either + or - force (if isFreeEndAttached == true).

Returns the current force in the spring. If ~isFreeEndAttached, this is zero if the distance between anchors is larger than restLength. Note that this does NOT include the force due to the damper, since that force is only temporary and isn't reallyt "the force in the spring" per se.

Reimplemented in tgBulletUnidirComprSpr.

Definition at line 217 of file tgBulletCompressionSpring.cpp.

virtual const double tgBulletCompressionSpring::getVelocity ( ) const
inlinevirtual

Get the last change in length / time

Definition at line 132 of file tgBulletCompressionSpring.h.

virtual const bool tgBulletCompressionSpring::isFreeEndAttached ( ) const
inlinevirtual

Return the boolean: is the free end attached?

Definition at line 157 of file tgBulletCompressionSpring.h.

void tgBulletCompressionSpring::step ( double  dt)
virtual

Updates this object. Calls calculateAndApplyForce(dt)

Parameters
[in]dt,mustbe positive

Reimplemented in tgBulletUnidirComprSpr.

Definition at line 116 of file tgBulletCompressionSpring.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

tgBulletSpringCableAnchor* const tgBulletCompressionSpring::anchor1
protected

The first attachement point for this spring cable. Storing it seperately makes a number of functions easier

Definition at line 186 of file tgBulletCompressionSpring.h.

tgBulletSpringCableAnchor* const tgBulletCompressionSpring::anchor2
protected

The other permanent attachment for this spring cable.

Definition at line 191 of file tgBulletCompressionSpring.h.

std::vector<tgBulletSpringCableAnchor*> tgBulletCompressionSpring::m_anchors
protected

The list of contact points. tgBulletSpringCable typically has two whereas tgBulletContactSpringCable will have more. Needs to be stored here for consistent rendering. Vector has the convienence of tgCast functions, and we used to need a random iterator to sort

Definition at line 180 of file tgBulletCompressionSpring.h.

const double tgBulletCompressionSpring::m_coefD
protected

The damping coefficient. Units of mass / sec. Must be non-negative

Definition at line 222 of file tgBulletCompressionSpring.h.

const double tgBulletCompressionSpring::m_coefK
protected

The stiffness coefficient Units of mass / sec ^2 Must be positive

Definition at line 215 of file tgBulletCompressionSpring.h.

double tgBulletCompressionSpring::m_dampingForce
protected

The force in the spring due to damping, at the last update step. Stored so we can get it without passing a dt

Definition at line 197 of file tgBulletCompressionSpring.h.

bool tgBulletCompressionSpring::m_isFreeEndAttached
protected

Boolean flag controlling the application of either tension forces or not.

Definition at line 208 of file tgBulletCompressionSpring.h.

double tgBulletCompressionSpring::m_prevLength
protected

The previous actual length of the spring. Used when calculating force and velocity

Definition at line 233 of file tgBulletCompressionSpring.h.

double tgBulletCompressionSpring::m_restLength
protected

The rest length of the spring. Must be non negative

Definition at line 227 of file tgBulletCompressionSpring.h.

double tgBulletCompressionSpring::m_velocity
protected

The velocity of the spring tip at the last update step. Stored so we can get it without passing a dt

Definition at line 203 of file tgBulletCompressionSpring.h.


The documentation for this class was generated from the following files: