00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "nAxesControllerPosVel.hpp"
00023 #include <rtt/Logger.hpp>
00024 #include <ocl/ComponentLoader.hpp>
00025
00026 #include <assert.h>
00027
00028 namespace OCL
00029 {
00030 using namespace RTT;
00031 using namespace std;
00032
00033 nAxesControllerPosVel::nAxesControllerPosVel(string name)
00034 : TaskContext(name,PreOperational),
00035 p_meas_port("nAxesSensorPosition"),
00036 p_desi_port("nAxesDesiredPosition"),
00037 v_desi_port("nAxesDesiredVelocity"),
00038 v_out_port("nAxesOutputVelocity"),
00039 gain_prop("K", "Proportional Gain"),
00040 num_axes_prop("num_axes","Number of Axes")
00041 {
00042
00043
00044
00045 this->ports()->addPort(&p_meas_port);
00046 this->ports()->addPort(&p_desi_port);
00047 this->ports()->addPort(&v_desi_port);
00048 this->ports()->addPort(&v_out_port);
00049
00050
00051 this->properties()->addProperty(&num_axes_prop);
00052 this->properties()->addProperty(&gain_prop);
00053
00054 }
00055
00056 nAxesControllerPosVel::~nAxesControllerPosVel(){};
00057
00058 bool nAxesControllerPosVel::configureHook(){
00059 num_axes=num_axes_prop.rvalue();
00060 if(gain_prop.value().size()!=num_axes){
00061 Logger::In in(this->getName().data());
00062 log(Error)<<"Size of "<<gain_prop.getName()
00063 <<" does not match "<<num_axes_prop.getName()
00064 <<endlog();
00065 return false;
00066 }
00067
00068 gain=gain_prop.rvalue();
00069
00070
00071 p_meas.resize(num_axes);
00072 p_desi.resize(num_axes);
00073 v_desi.resize(num_axes);
00074
00075
00076 v_out.assign(num_axes,0);
00077 v_out_port.Set(v_out);
00078 return true;
00079
00080 }
00081
00082
00083 bool nAxesControllerPosVel::startHook(){
00084
00085 if(!p_meas_port.ready()){
00086 Logger::In in(this->getName().data());
00087 log(Error)<<p_meas_port.getName()<<" not ready"<<endlog();
00088 return false;
00089 }
00090 if(!p_desi_port.ready()){
00091 Logger::In in(this->getName().data());
00092 log(Error)<<p_desi_port.getName()<<" not ready"<<endlog();
00093 return false;
00094 }
00095 if(!v_desi_port.ready()){
00096 Logger::In in(this->getName().data());
00097 log(Error)<<v_desi_port.getName()<<" not ready"<<endlog();
00098 return false;
00099 }
00100 if(p_meas_port.Get().size()!=num_axes){
00101 Logger::In in(this->getName().data());
00102 log(Error)<<"Size of "<<p_meas_port.getName()<<": "<<p_meas_port.Get().size()<<" != " << num_axes<<endlog();
00103 return false;
00104 }
00105 if(p_desi_port.Get().size()!=num_axes){
00106 Logger::In in(this->getName().data());
00107 log(Error)<<"Size of "<<p_desi_port.getName()<<": "<<p_desi_port.Get().size()<<" != " << num_axes<<endlog();
00108 return false;
00109 }
00110 if(v_desi_port.Get().size()!=num_axes){
00111 Logger::In in(this->getName().data());
00112 log(Error)<<"Size of "<<v_desi_port.getName()<<": "<<v_desi_port.Get().size()<<" != " << num_axes<<endlog();
00113 return false;
00114 }
00115
00116 return true;
00117 }
00118
00119 void nAxesControllerPosVel::updateHook(){
00120
00121 p_meas = p_meas_port.Get();
00122 p_desi = p_desi_port.Get();
00123 v_desi = v_desi_port.Get();
00124
00125 for(unsigned int i=0; i<num_axes; i++)
00126 v_out[i] = (gain[i] * (p_desi[i] - p_meas[i])) + v_desi[i];
00127
00128 v_out_port.Set(v_out);
00129 }
00130
00131 void nAxesControllerPosVel::stopHook(){
00132 for(unsigned int i=0; i<num_axes; i++){
00133 v_out[i] = 0.0;
00134 }
00135 v_out_port.Set(v_out);
00136 }
00137 }
00138 ORO_LIST_COMPONENT_TYPE( OCL::nAxesControllerPosVel )