00001
00002 #ifndef KUKA361_TORQUE_SIMULATOR_HPP
00003 #define KUKA361_TORQUE_SIMULATOR_HPP
00004
00005 #include <vector>
00006 #include <typeinfo>
00007 #include "kuka361FwDynnf.hpp"
00008 #include <rtt/Logger.hpp>
00009 #include <rtt/TimeService.hpp>
00010 #include "dev/SimulationAxis.hpp"
00011 #include "dev/TorqueSimulationAxis.hpp"
00012
00013 #include <ocl/OCL.hpp>
00014
00015 #define KUKA361_NUM_AXES 6
00016
00017 namespace OCL
00018 {
00026 class Kuka361TorqueSimulator
00027 {
00028 public:
00029 Kuka361TorqueSimulator(vector<RTT::AxisInterface*> &axes, vector<double> &initialPosition) :
00030 _axes(axes),
00031 _pos_sim(initialPosition),
00032 _vel_sim(KUKA361_NUM_AXES, 0.0),
00033 _acc_sim(KUKA361_NUM_AXES, 0.0),
00034 firststep(6,true)
00035 {};
00036
00037 ~Kuka361TorqueSimulator(){};
00038
00039 void update(vector<double> &_tau_sim) {
00040 _acc_sim = kuka361FWDYN.fwdyn361( _tau_sim, _pos_sim, _vel_sim);
00041 for (int axis=0;axis<KUKA361_NUM_AXES;axis++) {
00042 OCL::TorqueSimulationAxis* sim_axis = dynamic_cast<OCL::TorqueSimulationAxis*>(_axes[axis]);
00043 if(sim_axis!=NULL){
00044 if(!sim_axis->isDriven() || firststep[axis]) {
00045 _acc_sim[axis] = _vel_sim[axis] = 0.0;
00046 if (sim_axis->isDriven()) firststep[axis] = false;
00047 }
00048 ((TorqueSimulationVelocitySensor*) sim_axis->getSensor("Velocity"))->update(_vel_sim[axis], _acc_sim[axis], _previous_time);
00049 ((TorqueSimulationEncoder*) sim_axis->getSensor("Position"))->update(_pos_sim[axis], _vel_sim[axis], _previous_time);
00050 _vel_sim[axis] = sim_axis->getSensor("Velocity")->readSensor();
00051 _pos_sim[axis] = sim_axis->getSensor("Position")->readSensor();
00052
00053 } else {
00054 _vel_sim[axis] = _axes[axis]->getDriveValue();
00055 _pos_sim[axis] = _axes[axis]->getSensor("Position")->readSensor();
00056 _tau_sim[axis] = 0.0;
00057 }
00058 }
00059 _previous_time = TimeService::Instance()->getTicks();
00060
00061 };
00062
00063 private:
00064 vector<RTT::AxisInterface*> _axes;
00065 vector<double> _pos_sim;
00066 vector<double> _vel_sim;
00067 vector<double> _acc_sim;
00068 TimeService::ticks _previous_time;
00069 string type;
00070 vector<bool> firststep;
00071 kuka361FwDynnf kuka361FWDYN;
00072 };
00073 }
00074 #endif // Kuka361TorqueSimulator