00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "nAxesVelocityController.hpp"
00019 #include <ocl/ComponentLoader.hpp>
00020 #include <rtt/Logger.hpp>
00021
00022 namespace OCL
00023 {
00024 using namespace RTT;
00025 using namespace std;
00026
00027 nAxesVelocityController::nAxesVelocityController(string name)
00028 : TaskContext(name,PreOperational),
00029 M_startAllAxes("startAllAxes",&nAxesVelocityController::startAllAxes,this),
00030 M_stopAllAxes("stopAllAxes",&nAxesVelocityController::stopAllAxes,this),
00031 M_unlockAllAxes("unlockAllAxes",&nAxesVelocityController::unlockAllAxes,this),
00032 M_lockAllAxes("lockAllAxes",&nAxesVelocityController::lockAllAxes,this),
00033 D_driveValues("nAxesOutputVelocity"),
00034 D_positionValues("nAxesSensorPosition"),
00035 P_initialPositions("initialPositions","initial positions (rad) for the axes"),
00036 P_naxes("naxes","number of axes")
00037 {
00038 methods()->addMethod(&M_startAllAxes,"start the simulation axes");
00039 methods()->addMethod(&M_stopAllAxes,"stop the simulation axes");
00040 methods()->addMethod(&M_lockAllAxes,"lock the simulation axes");
00041 methods()->addMethod(&M_unlockAllAxes,"unlock the simulation axes");
00042
00043 ports()->addPort(&D_driveValues);
00044 ports()->addPort(&D_positionValues);
00045
00046 properties()->addProperty(&P_initialPositions);
00047 properties()->addProperty(&P_naxes);
00048
00049 }
00050
00051 bool nAxesVelocityController::configureHook()
00052 {
00053 naxes=P_naxes.value();
00054 if(P_initialPositions.value().size()!=naxes){
00055 Logger::In in(this->getName().data());
00056 log(Error)<<"Size of "<<P_initialPositions.getName()
00057 <<" does not match "<<P_naxes.getName()
00058 <<endlog();
00059 return false;
00060 }
00061
00062 driveValues.resize(naxes);
00063 positionValues=P_initialPositions.value();
00064 simulation_axes.resize(naxes);
00065
00066 for (unsigned int i = 0; i<naxes; i++){
00067 simulation_axes[i] = new SimulationAxis(positionValues[i]);
00068 }
00069
00070 D_positionValues.Set(positionValues);
00071
00072 return true;
00073 }
00074
00075 bool nAxesVelocityController::startHook()
00076 {
00077
00078 if(!D_driveValues.ready()){
00079 Logger::In in(this->getName().data());
00080 log(Error)<<D_driveValues.getName()<<" not ready"<<endlog();
00081 return false;
00082 }
00083 if(D_driveValues.Get().size()!=naxes){
00084 Logger::In in(this->getName().data());
00085 log(Error)<<"Size of "<<D_driveValues.getName()<<": "<<D_driveValues.Get().size()<<" != " << naxes<<endlog();
00086 return false;
00087 }
00088
00089 return true;
00090 }
00091
00092 void nAxesVelocityController::updateHook()
00093 {
00094 D_driveValues.Get(driveValues);
00095 for (unsigned int i=0;i<naxes;i++){
00096 positionValues[i]=simulation_axes[i]->getSensor("Position")->readSensor();
00097 if(simulation_axes[i]->isDriven())
00098 simulation_axes[i]->drive(driveValues[i]);
00099 }
00100 D_positionValues.Set(positionValues);
00101 }
00102
00103 void nAxesVelocityController::cleanupHook()
00104 {
00105 simulation_axes.clear();
00106 }
00107
00108 void nAxesVelocityController::stopHook()
00109 {
00110 }
00111
00112 bool nAxesVelocityController::startAllAxes()
00113 {
00114 bool retval=true;
00115 for(vector<SimulationAxis*>::iterator axis=simulation_axes.begin();
00116 axis!=simulation_axes.end();axis++)
00117 retval&=(*axis)->drive(0.0);
00118 return retval;
00119 }
00120
00121 bool nAxesVelocityController::stopAllAxes()
00122 {
00123 bool retval=true;
00124 for(vector<SimulationAxis*>::iterator axis=simulation_axes.begin();
00125 axis!=simulation_axes.end();axis++)
00126 retval&=(*axis)->stop();
00127 return retval;
00128 }
00129
00130 bool nAxesVelocityController::lockAllAxes()
00131 {
00132 bool retval=true;
00133 for(vector<SimulationAxis*>::iterator axis=simulation_axes.begin();
00134 axis!=simulation_axes.end();axis++)
00135 retval&=(*axis)->lock();
00136 return retval;
00137
00138 }
00139
00140 bool nAxesVelocityController::unlockAllAxes()
00141 {
00142 bool retval=true;
00143 for(vector<SimulationAxis*>::iterator axis=simulation_axes.begin();
00144 axis!=simulation_axes.end();axis++)
00145 retval&=(*axis)->unlock();
00146 return retval;
00147 }
00148 }
00149 ORO_CREATE_COMPONENT(OCL::nAxesVelocityController)
00150
00151