00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "CartesianControllerVel.hpp"
00022 #include <assert.h>
00023 #include <ocl/ComponentLoader.hpp>
00024
00025 ORO_LIST_COMPONENT_TYPE( OCL::CartesianControllerVel );
00026
00027 namespace OCL
00028 {
00029
00030 using namespace RTT;
00031 using namespace KDL;
00032 using namespace std;
00033
00034
00035 CartesianControllerVel::CartesianControllerVel(string name)
00036 : TaskContext(name,PreOperational),
00037 _gain_local(6,0.0),
00038 _is_initialized(false),
00039 _position_meas("CartesianSensorPosition"),
00040 _velocity_desi("CartesianDesiredVelocity"),
00041 _velocity_out("CartesianOutputVelocity"),
00042 _controller_gain("K", "Proportional Gain",vector<double>(6,0.0))
00043 {
00044
00045
00046
00047 this->ports()->addPort(&_position_meas);
00048 this->ports()->addPort(&_velocity_desi);
00049 this->ports()->addPort(&_velocity_out);
00050
00051
00052 this->properties()->addProperty(&_controller_gain);
00053
00054 }
00055
00056
00057 CartesianControllerVel::~CartesianControllerVel(){};
00058
00059 bool CartesianControllerVel::configureHook()
00060 {
00061
00062
00063
00064 if(_controller_gain.value().size()!=6)
00065 return false;
00066
00067 _gain_local=_controller_gain.value();
00068 return true;
00069 }
00070
00071 bool CartesianControllerVel::startHook()
00072 {
00073 return true;
00074 }
00075
00076 void CartesianControllerVel::updateHook()
00077 {
00078
00079 _position_meas_local = _position_meas.Get();
00080 _velocity_desi_local = _velocity_desi.Get();
00081
00082
00083 if (!_is_initialized){
00084 _is_initialized = true;
00085 _position_integrated = _position_meas_local;
00086 _time_begin = TimeService::Instance()->getTicks();
00087 }
00088
00089
00090 double time_difference = TimeService::Instance()->secondsSince(_time_begin);
00091 _time_begin = TimeService::Instance()->getTicks();
00092 _position_integrated = addDelta(_position_integrated, _velocity_desi_local, time_difference);
00093
00094
00095 _velocity_feedback = diff(_position_meas_local, _position_integrated);
00096 for(unsigned int i=0; i<6; i++)
00097 _velocity_feedback(i) *= _gain_local[i];
00098
00099
00100 _velocity_out_local = _velocity_desi_local + _velocity_feedback;
00101
00102 _velocity_out.Set(_velocity_out_local);
00103 }
00104
00105 void CartesianControllerVel::stopHook()
00106 {
00107 }
00108
00109 void CartesianControllerVel::cleanupHook()
00110 {
00111 }
00112
00113 }
00114
00115
00116