TrajectoryInput.cpp
Go to the documentation of this file.
00001 /*
00002  * TrajectoryInput.cpp
00003  *
00004  *  Created on: Mar 2, 2012
00005  *      Author: mriedel
00006  */
00007 
00008 #include "TrajectoryInput.hpp"
00009 
00010 #include <telekyb_base/ROS.hpp>
00011 #include <telekyb_msgs/TKTrajectory.h>
00012 
00013 // Declare
00014 PLUGINLIB_DECLARE_CLASS(tk_be_common, TrajectoryInput, telekyb_behavior::TrajectoryInput, TELEKYB_NAMESPACE::Behavior);
00015 
00016 namespace telekyb_behavior {
00017 
00018 TrajectoryInput::TrajectoryInput()
00019         : Behavior("tk_be_common/TrajectoryInput", BehaviorType::Air)
00020 {
00021 
00022 }
00023 
00024 
00025 TrajectoryInput::~TrajectoryInput()
00026 {
00027 
00028 }
00029 
00030 void TrajectoryInput::trajectoryCB(const telekyb_msgs::TKTrajectory::ConstPtr& msg)
00031 {
00032         timeoutTimer.reset();
00033         // TODO: protect by Mutex
00034         lastMsg.fromTKTrajMsg(*msg);
00035 }
00036 
00037 void TrajectoryInput::initialize()
00038 {
00039 
00040         tTrajectoryTopicName = addOption<std::string>("tTrajectoryTopicName",
00041                         "tTrajectoryTopicName that published telekyb_msgs::TKTrajectory",
00042                         "custom", false, false);
00043         tTrajectoryTimeout = addOption<double>("tTrajectoryTimeout",
00044                         "Timeout. Behavior turns invalid if it does not recv new message within timeout.",
00045                         1.0, false, false);
00046 
00047         nodeHandle = ROSModule::Instance().getMainNodeHandle();
00048 
00049         // no Parameters
00050         //parameterInitialized = true;
00051 }
00052 
00053 void TrajectoryInput::destroy()
00054 {
00055 
00056 }
00057 
00058 bool TrajectoryInput::willBecomeActive(const TKState& currentState, const Behavior& previousBehavior)
00059 {
00060         // Initialize Message to 0 Velocity and 0 YawRate
00061         lastMsg.setVelocity(Velocity3D::Zero());
00062         lastMsg.setYawRate(0.0);
00063 
00064         trajectorySub = nodeHandle.subscribe(tTrajectoryTopicName->getValue()
00065                         , 10, &TrajectoryInput::trajectoryCB, this);
00066 
00067         timeoutTimer.reset();
00068         return true;
00069 }
00070 
00071 void TrajectoryInput::didBecomeActive(const TKState& currentState, const Behavior& previousBehavior)
00072 {
00073         // not used
00074 }
00075 
00076 void TrajectoryInput::willBecomeInActive(const TKState& currentState, const Behavior& nextBehavior)
00077 {
00078         // not used
00079 }
00080 
00081 void TrajectoryInput::didBecomeInActive(const TKState& currentState, const Behavior& nextBehavior)
00082 {
00083         trajectorySub.shutdown();
00084 }
00085 
00086 // called everytime a new TKState is available AND it is the NEW Behavior of an active Switch
00087 void TrajectoryInput::trajectoryStepCreation(const TKState& currentState, TKTrajectory& generatedTrajInput)
00088 {
00089         // Same as active
00090         trajectoryStepActive(currentState,generatedTrajInput);
00091 }
00092 
00093 // called everytime a new TKState is available. Should return false if invalid (swtich to next behavior, or Hover if undef).
00094 void TrajectoryInput::trajectoryStepActive(const TKState& currentState, TKTrajectory& generatedTrajInput)
00095 {
00096         //      ROS_INFO_STREAM("InputVel: " << std::endl << lastVelocityInput);
00097         //      ROS_INFO_STREAM("InputYawRate: " << lastYawRateInput);
00098 
00099         // TODO: protect by Mutex
00100         generatedTrajInput = lastMsg;
00101 }
00102 
00103 // called everytime a new TKState is available AND it is the OLD Behavior of an active Switch
00104 void TrajectoryInput::trajectoryStepTermination(const TKState& currentState, TKTrajectory& generatedTrajInput)
00105 {
00106         generatedTrajInput.setVelocity( Velocity3D::Zero() );
00107         generatedTrajInput.setYawRate( 0.0 );
00108 }
00109 
00110 // Return true if the active Behavior is (still) valid. Initiate Switch otherwise
00111 bool TrajectoryInput::isValid(const TKState& currentState) const
00112 {
00113         return timeoutTimer.getElapsed().toDSec() < tTrajectoryTimeout->getValue();;
00114 }
00115 
00116 
00117 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends


tk_be_common
Author(s): Martin Riedel
autogenerated on Mon Nov 11 2013 11:14:29