TrajectoryController.cpp
Go to the documentation of this file.
00001 /*
00002  * TrajectoryController.cpp
00003  *
00004  *  Created on: Nov 8, 2011
00005  *      Author: mriedel
00006  */
00007 
00008 #include <tk_trajctrl/TrajectoryController.hpp>
00009 
00010 #include <telekyb_base/ROS.hpp>
00011 #include <telekyb_msgs/TKCommands.h>
00012 
00013 //
00014 #include <tk_state/StateEstimatorController.hpp>
00015 
00016 #include <telekyb_defines/physic_defines.hpp>
00017 
00018 namespace TELEKYB_NAMESPACE {
00019 
00020 //TrajectoryController::TrajectoryController()
00021 //      : massEstimation( options.tInitialMass->getValue() ),
00022 //        currentMass( options.tInitialMass->getValue() ),
00023 //        nodeHandle( ROSModule::Instance().getMainNodeHandle() ),
00024 //        commandNodeHandle( nodeHandle, TELEKYB_COMMAND_NODESUFFIX )
00025 //{
00026 //      // Important first create Publisher, before receiving CallBacks
00027 //      tTcCommandsPub = commandNodeHandle.advertise<telekyb_msgs::TKCommands>(options.tCommandsTopic->getValue(),1);
00028 //
00029 //      // CurrentState
00030 //      currentInput.setAcceleration( Acceleration3D(0.0, 0.0, GRAVITY) );
00031 //      currentInput.setYawRate(0.0);
00032 //
00033 //      std::string tkStateTopicName = StateEstimatorController::Instance().getSePublisherTopic();
00034 //      tTcStateSub = nodeHandle.subscribe(tkStateTopicName,1,&TrajectoryController::tkStateCB, this);
00035 //}
00036 
00037 TrajectoryController::TrajectoryController()
00038         : ttLoader( "tk_trajctrl", std::string( TELEKYB_NAMESPACE_STRING ) + "::TrajectoryTracker" ),
00039           activeTrajectoryTracker( NULL ),
00040           nodeHandle( ROSModule::Instance().getMainNodeHandle() )
00041 {
00042 
00043 }
00044 
00045 TrajectoryController::~TrajectoryController()
00046 {
00047         if (activeTrajectoryTracker) {
00048                 activeTrajectoryTracker->destroy();
00049                 delete activeTrajectoryTracker;
00050         }
00051 }
00052 
00053 void TrajectoryController::initialize()
00054 {
00055         try {
00056                 activeTrajectoryTracker = ttLoader.createClassInstance(options.tPluginLookupName->getValue());
00057                 // Currently RunTime Switch is not supported. This has to be changed then.
00058                 activeTrajectoryTracker->initialize();
00059 
00060 
00061                 // only subscribe after successful load
00062                 std::string tkStateTopicName = StateEstimatorController::Instance().getSePublisherTopic();
00063                 tTcStateSub = nodeHandle.subscribe(tkStateTopicName,1,&TrajectoryController::tkStateCB, this);
00064 
00065         } catch (pluginlib::PluginlibException& e) {
00066                 ROS_FATAL("Trajectory Tracker %s failed to load: %s", options.tPluginLookupName->getValue().c_str(), e.what());
00067                 //ROS_BREAK();
00068                 ros::shutdown();
00069         }
00070 }
00071 
00072 
00073 void TrajectoryController::trajInputStep(const TKTrajectory& nextInput)
00074 {
00075         activeTrajectoryTracker->trajectoryCB(nextInput);
00076 }
00077 
00078 //void TrajectoryController::toggleMassEstimation(bool toggleME)
00079 //{
00080 //      if (!options.tCompletelyDisableME->getValue()) {
00081 //              options.tDoMassEstimation->setValue(toggleME);
00082 //      }
00083 //}
00084 
00085 void TrajectoryController::tkStateCB(const telekyb_msgs::TKState::ConstPtr& msg)
00086 {
00087         // new State Message. Triggers control step!
00088         //ROS_INFO("Received new TKState!");
00089         TKState state(*msg);
00090         activeTrajectoryTracker->stateCB(state);
00091 }
00092 
00093 
00094 //---------------
00095 // Singleton Stuff
00096 TrajectoryController* TrajectoryController::instance = NULL;
00097 
00098 TrajectoryController& TrajectoryController::Instance() {
00099         if (!instance) {
00100                 instance = new TrajectoryController();
00101                 instance->initialize();
00102         }
00103         return *instance;
00104 }
00105 
00106 TrajectoryController* TrajectoryController::InstancePtr() {
00107         if (!instance) {
00108                 instance = new TrajectoryController();
00109                 instance->initialize();
00110         }
00111 
00112         return instance;
00113 }
00114 
00115 bool TrajectoryController::HasInstance()
00116 {
00117         return (instance != NULL);
00118 }
00119 
00120 void TrajectoryController::ShutDownInstance() {
00121         if (instance) {
00122                 delete instance;
00123         }
00124 
00125         instance = NULL;
00126 }
00127 
00128 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends


tk_trajctrl
Author(s): Dr. Antonio Franchi and Martin Riedel
autogenerated on Mon Nov 11 2013 11:13:14