00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "musclepair.h"
00025 #include "phyjoint.h"
00026
00027
00028
00029
00030
00031
00032
00033
00034 namespace farsa {
00035
00036 MusclePair::MusclePair( PhyDOF* dof, float ksh, float tmax, float rl, float lmax ) {
00037
00038 this->dof = dof;
00039 this->ksh = ksh;
00040 reduceKsh = 1.0;
00041 this->tmax = tmax;
00042 this->rl = rl;
00043 this->lmax = lmax;
00044 lmin = 2.0f*rl - lmax;
00045 this->ash = (rl*rl) / ( (lmax-rl)*(lmax-rl) );
00046 this->b = 1.0f;
00047 getExtension( last_x1, last_x2 );
00048 this->dx1 = 0.0f;
00049 this->dx2 = 0.0f;
00050 }
00051
00052 void MusclePair::setRestLength( float rl ) {
00053 this->rl = rl;
00054 lmin = 2.0f*rl - lmax;
00055 ash = (rl*rl) / ( (lmax-rl)*(lmax-rl) );
00056 }
00057
00058 float MusclePair::getRestLength() {
00059 return rl;
00060 }
00061
00062 void MusclePair::setMaxTension( float tmax ) {
00063 this->tmax = tmax;
00064 }
00065
00066 float MusclePair::getMaxTension( ) {
00067 return tmax;
00068 }
00069
00070 void MusclePair::setMaxLength( float lmax ) {
00071 this->lmax = lmax;
00072 lmin = 2.0f*rl - lmax;
00073 ash = (rl*rl) / ( (lmax-rl)*(lmax-rl) );
00074 }
00075
00076 float MusclePair::getMaxLength() {
00077 return lmax;
00078 }
00079
00080 float MusclePair::getMinLength() {
00081 return lmin;
00082 }
00083
00084 float MusclePair::getAsh( ) {
00085 return ash;
00086 }
00087
00088 void MusclePair::setAsh( float newash ) {
00089 ash = newash;
00090 }
00091
00092 void MusclePair::setKsh( float ksh, float reduceFactor ) {
00093 this->ksh = ksh;
00094 reduceKsh = reduceFactor;
00095 }
00096
00097 float MusclePair::getKsh( ) {
00098 return ksh;
00099 }
00100
00101 void MusclePair::setViscosity( float b ) {
00102 this->b = b;
00103 }
00104
00105 float MusclePair::getViscosity( ) {
00106 return b;
00107 }
00108
00109 void MusclePair::setActivation( float act1, float act2 ) {
00110
00111
00112 this->act1 = act1;
00113 this->act2 = act2;
00114 }
00115
00116 void MusclePair::getActivation( float& act1, float& act2 ) {
00117 act1 = this->act1;
00118 act2 = this->act2;
00119 }
00120
00121 void MusclePair::getExtension( float& l1, float& l2 ) {
00122 float angle = dof->position();
00123 real lowLim, higLim;
00124 dof->limits( lowLim, higLim );
00125 l1 = linearMap( angle, lowLim, higLim, lmin, lmax );
00126 l2 = invLinearMap( angle, lowLim, higLim, lmin, lmax );
00127 }
00128
00129 float MusclePair::apply() {
00130 float x1, x2;
00131 getExtension( x1, x2 );
00132
00133 float timestep = dof->joint()->world()->timeStep();
00134 dx1 = ( x1 - last_x1 ) / timestep;
00135 dx2 = ( x2 - last_x2 ) / timestep;
00136
00137 float ta1 = act1 * ( -ash*tmax*(x1-rl)*(x1-rl)/(rl*rl) + tmax );
00138 float tp1 = reduceKsh*0.5*tmax * ( exp( ksh*(x1-rl)/(lmax-rl) ) - 1.0f ) / ( exp( ksh ) - 1.0f );
00139 float tv1 = b * dx1;
00140
00141 float ta2 = act2 * ( -ash*tmax*(x2-rl)*(x2-rl)/(rl*rl) + tmax );
00142 float tp2 = reduceKsh*0.5*tmax * ( exp( ksh*(x2-rl)/(lmax-rl) ) - 1.0f ) / ( exp( ksh ) - 1.0f );
00143 float tv2 = b * dx2;
00144
00145 tal1 = ta1;
00146 tal2 = ta2;
00147
00148 last_x1 = x1;
00149 last_x2 = x2;
00150
00151 return -(ta1+tp1+tv1) + (ta2+tp2+tv2);
00152 }
00153
00154 }