TrajectoryProcessorController.cpp
Go to the documentation of this file.
00001 /*
00002  * TrajectoryProcessorController.cpp
00003  *
00004  *  Created on: Dec 13, 2011
00005  *      Author: mriedel
00006  */
00007 
00008 #include <tk_trajprocessor/TrajectoryProcessorController.hpp>
00009 
00010 #include <telekyb_base/ROS.hpp>
00011 
00012 #include <tk_trajctrl/TrajectoryController.hpp>
00013 
00014 namespace TELEKYB_NAMESPACE {
00015 
00016 TrajectoryProcessorController::TrajectoryProcessorController()
00017         : trajProcessorNodeHandle( ROSModule::Instance().getMainNodeHandle(), TELEKYB_TRAJPROC_NODESUFFIX ),
00018           seController( StateEstimatorController::Instance() ),
00019           trajController( TrajectoryController::Instance() ),
00020           active(false),
00021           switcher(NULL)
00022 {
00023 
00024 
00025 }
00026 
00027 TrajectoryProcessorController::~TrajectoryProcessorController()
00028 {
00029 
00030 }
00031 
00032 void TrajectoryProcessorController::initialize()
00033 {
00034         // load Trajectory Modules
00035         std::vector< std::string > trajectoryModulesStrings = options.tTrajectoryModules->getValue();
00036         for (unsigned int i = 0; i < trajectoryModulesStrings.size(); ++i) {
00037                 trajModuleContainer.loadTrajectoryModule(trajectoryModulesStrings[i]);
00038         }
00039 
00040         // did you get at least one state?
00041         if (! seController.waitForFirstState( Time(options.tInitialStateTimeout->getValue()) ) ) {
00042                 // did not receive State
00043                 ROS_ERROR("TrajectoryProcessorController: Did not receive initial TKState within Timeout! Using uninitialized! This is dangerous!");
00044         }
00045 
00046         // this should block till state becomes available
00047         lastState = seController.getLastState();
00048 
00049         // tkStateTopicName is an absolute PATH!
00050         std::string tkStateTopicName = StateEstimatorController::Instance().getSePublisherTopic();
00051         tStateSub = trajProcessorNodeHandle.subscribe(tkStateTopicName,1,&TrajectoryProcessorController::tkStateCB, this);
00052 }
00053 
00054 void TrajectoryProcessorController::setActive(BehaviorSwitcher* switcher_)
00055 {
00056         trajModuleContainer.activateAllTrajectoryModules();
00057 
00058         switcher = switcher_;
00059         active = true;
00060 }
00061 
00062 void TrajectoryProcessorController::setInActive()
00063 {
00064         trajModuleContainer.deactivateAllTrajectoryModules();
00065         active = false;
00066         switcher = NULL;
00067 }
00068 
00069 bool TrajectoryProcessorController::isActive() const
00070 {
00071         return active;
00072 }
00073 
00074 BehaviorSwitcher* TrajectoryProcessorController::getBehaviorSwitcher() const
00075 {
00076         return switcher;
00077 }
00078 
00079 void TrajectoryProcessorController::trajInputStep(const TKTrajectory& input)
00080 {
00081         if (active) {
00082                 TKTrajectory trajToProcess = input;
00083 
00084                 // call accordingly:
00085                 switch (trajToProcess.getGlobalPositionControlType().index()) {
00086                         case GlobalPosControlType::Position:
00087                                 //ROS_INFO("Processing Position Mode");
00088                                 trajModuleContainer.trajectoryStepPosition(lastState, trajToProcess);
00089                                 break;
00090                         case GlobalPosControlType::Velocity:
00091                                 //ROS_INFO("Processing Velocity Mode");
00092                                 trajModuleContainer.trajectoryStepVelocity(lastState, trajToProcess);
00093                                 break;
00094                         case GlobalPosControlType::Acceleration:
00095                                 //ROS_INFO("Processing Acceleration Mode");
00096                                 trajModuleContainer.trajectoryStepAcceleration(lastState, trajToProcess);
00097                                 break;
00098                         case GlobalPosControlType::Mixed:
00099                                 //ROS_INFO("Processing Mixed Mode");
00100                                 trajModuleContainer.trajectoryStepOther(lastState, trajToProcess);
00101                                 break;
00102                         default:
00103                                 break;
00104                 }
00105 
00106                 // send to TrajController
00107                 trajController.trajInputStep(trajToProcess);
00108         } else {
00109                 // inactive just pass on
00110                 trajController.trajInputStep(input);
00111         }
00112 }
00113 
00114 void TrajectoryProcessorController::tkStateCB(const telekyb_msgs::TKState::ConstPtr& tkStateMsg)
00115 {
00116         boost::mutex::scoped_lock lastStateLock(lastStateMutex);
00117         lastState = *tkStateMsg;
00118 }
00119 
00120 
00121 
00122 //---------------
00123 // Singleton Stuff
00124 TrajectoryProcessorController* TrajectoryProcessorController::instance = NULL;
00125 
00126 TrajectoryProcessorController& TrajectoryProcessorController::Instance() {
00127         if (!instance) {
00128                 instance = new TrajectoryProcessorController();
00129                 instance->initialize();
00130         }
00131         return *instance;
00132 }
00133 
00134 const TrajectoryProcessorController* TrajectoryProcessorController::InstancePtr() {
00135         if (!instance) {
00136                 instance = new TrajectoryProcessorController();
00137                 instance->initialize();
00138         }
00139 
00140         return instance;
00141 }
00142 
00143 bool TrajectoryProcessorController::HasInstance()
00144 {
00145         return (instance != NULL);
00146 }
00147 
00148 void TrajectoryProcessorController::ShutDownInstance() {
00149         if (instance) {
00150                 delete instance;
00151         }
00152 
00153         instance = NULL;
00154 }
00155 
00156 
00157 } /* namespace telekyb */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines


tk_trajprocessor
Author(s): Martin Riedel
autogenerated on Mon Nov 11 2013 11:13:29