Hover.cpp
Go to the documentation of this file.
00001 /*
00002  * HoverBehavior.cpp
00003  *
00004  *  Created on: Nov 3, 2011
00005  *      Author: mriedel
00006  */
00007 
00008 #include <behaviors/Hover.hpp>
00009 
00010 #define MAX_INITIAL_VELOCITY 0.05
00011 
00012 
00013 // Declare
00014 PLUGINLIB_DECLARE_CLASS(tk_behavior, Hover, telekyb_behavior::Hover, TELEKYB_NAMESPACE::Behavior);
00015 
00016 namespace telekyb_behavior {
00017 
00018 Hover::Hover()
00019         : Behavior("tk_behavior/Hover",  BehaviorType::Air)
00020 {
00021 
00022 }
00023 
00024 void Hover::initialize()
00025 {
00026         // the Standard Brake Minimal Value should be significantly below this value!
00027         tHoverMaxInitialVelocity = addOption<double>("tHoverMaxInitialVelocity",
00028                         "Defines the Maximal Initial Velocity to be able to switch into Hover",
00029                         0.2, false, true);
00030         //options = new HoverOptions(this);
00031 
00032         // can work with default parameters
00033         parameterInitialized = true;
00034 }
00035 
00036 void Hover::destroy()
00037 {
00038 
00039 }
00040 
00041 
00042 bool Hover::willBecomeActive(const TKState& currentState, const Behavior& previousBehavior)
00043 {
00044         // Error if too fast ? Put as parameter?
00045         if (currentState.linVelocity.norm() > tHoverMaxInitialVelocity->getValue()) {
00046                 ROS_ERROR_STREAM("Too fast to switch into Hover! Current Velocity Norm: " << currentState.linVelocity.norm());
00047                 return false;
00048         }
00049 
00050         hoverPosition = currentState.position;
00051         yawAngle = currentState.getEulerRPY()(2);
00052 
00053         ROS_INFO_STREAM("Setting Position: " << std::endl << currentState.position << " Angle: " << currentState.getEulerRPY()(2));
00054         //ROS_INFO("Hover: Storing yawAngle: %f ", yawAngle);
00055 
00056         return true;
00057 }
00058 
00059 void Hover::didBecomeActive(const TKState& currentState, const Behavior& previousBehavior)
00060 {
00061         // not used
00062 //      ROS_ERROR("Sleeping after Switch to Hover.");
00063 //      usleep(2*1000*1000); // 10 sec
00064 }
00065 
00066 void Hover::willBecomeInActive(const TKState& currentState, const Behavior& nextBehavior)
00067 {
00068         // not used
00069 }
00070 
00071 void Hover::didBecomeInActive(const TKState& currentState, const Behavior& nextBehavior)
00072 {
00073         // not used
00074 }
00075 
00076 // called everytime a new TKState is available AND it is the NEW Behavior of an active Switch
00077 void Hover::trajectoryStepCreation(const TKState& currentState, TKTrajectory& generatedTrajInput)
00078 {
00079         // Same as active
00080         trajectoryStepActive(currentState,generatedTrajInput);
00081 }
00082 
00083 // called everytime a new TKState is available. Should return false if invalid (swtich to next behavior, or Hover if undef).
00084 void Hover::trajectoryStepActive(const TKState& currentState, TKTrajectory& generatedTrajInput)
00085 {
00086         generatedTrajInput.setPosition(hoverPosition);
00087         generatedTrajInput.setYawAngle(yawAngle);
00088 }
00089 
00090 // called everytime a new TKState is available AND it is the OLD Behavior of an active Switch
00091 void Hover::trajectoryStepTermination(const TKState& currentState, TKTrajectory& generatedTrajInput)
00092 {
00093         // Same as active
00094         trajectoryStepActive(currentState,generatedTrajInput);
00095 }
00096 
00097 // Return true if the active Behavior is (still) valid. Initiate Switch otherwise
00098 bool Hover::isValid(const TKState& currentState) const
00099 {
00100         // never turns invalid
00101         return true;
00102 }
00103 
00104 
00105 
00106 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines


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