File size: 1,505 Bytes
bd5cb32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <sawControllers/mtsGravityCompensation.h>
#include <cisstMultiTask/mtsInterfaceRequired.h>
#include <cisstParameterTypes/prmPositionJointGet.h>
#include <cisstParameterTypes/prmForceTorqueJointSet.h>

mtsGravityCompensation::mtsGravityCompensation( const std::string& taskname,
						double period,
						const std::string& robfilename,
						const vctFrame4x4<double>& Rtwb,
						osaCPUMask cpumask ) :
  mtsController( taskname, period, cpumask ),
  GC( NULL ){
  
  GC = new osaGravityCompensation( robfilename, Rtwb );

  mtsInterfaceRequired* input = AddInterfaceRequired( "Input" );
  mtsInterfaceRequired* output = AddInterfaceRequired( "Output" );
  
  input->AddFunction( "GetPositionJoint", GetPositions );
  output->AddFunction( "servo_jf",  SetTorques );

}

mtsGravityCompensation::~mtsGravityCompensation(){

  if( GC != NULL )
    { delete GC; }

}

void mtsGravityCompensation::Configure( const std::string& ){}

void mtsGravityCompensation::Startup(){

}

void mtsGravityCompensation::Run(){
  ProcessQueuedCommands();

  prmPositionJointGet prmq;
  GetPositions( prmq );

  vctDynamicVector<double> tau( prmq.Position().size(), 0.0 );
  if( GC != NULL && IsEnabled() ){

    if( GC->Evaluate( prmq.Position(), tau ) != 
      osaGravityCompensation::ESUCCESS ){
      CMN_LOG_RUN_ERROR << "Faile to evaluate the controller" << std::endl;
    }

    prmForceTorqueJointSet t;
    t.ForceTorque() = tau;
    SetTorques( t );
    
  }

}

void mtsGravityCompensation::Cleanup(){}