EmergencyLand.cpp
Go to the documentation of this file.
00001 /*
00002  * EmergencyLand.cpp
00003  *
00004  *  Created on: Dec 14, 2011
00005  *      Author: mriedel
00006  */
00007 
00008 #include <behaviors/EmergencyLand.hpp>
00009 
00010 // Declare
00011 PLUGINLIB_DECLARE_CLASS(tk_behavior, EmergencyLand, telekyb_behavior::EmergencyLand, TELEKYB_NAMESPACE::Behavior);
00012 
00013 #define MAX_HEIGHT -0.3 // Z DOWN!
00014 #define LANDING_VELOCITY 0.7
00015 #define LANDING_POS_Z 0.0
00016 
00017 namespace telekyb_behavior {
00018 
00019 EmergencyLand::EmergencyLand()
00020         : Behavior("tk_behavior/EmergencyLand", BehaviorType::Land)
00021 {
00022 
00023 }
00024 
00025 void EmergencyLand::initialize()
00026 {
00027         parameterInitialized = true;
00028 }
00029 
00030 void EmergencyLand::destroy()
00031 {
00032 
00033 }
00034 
00035 bool EmergencyLand::willBecomeActive(const TKState& currentState, const Behavior& previousBehavior)
00036 {
00037         landingPosition = currentState.position;
00038         landingPosition(2) = LANDING_POS_Z;
00039         return true;
00040 }
00041 
00042 void EmergencyLand::didBecomeActive(const TKState& currentState, const Behavior& previousBehavior)
00043 {
00044         // not used
00045 }
00046 
00047 void EmergencyLand::willBecomeInActive(const TKState& currentState, const Behavior& nextBehavior)
00048 {
00049         // not used
00050 }
00051 
00052 void EmergencyLand::didBecomeInActive(const TKState& currentState, const Behavior& nextBehavior)
00053 {
00054         // not used
00055 }
00056 
00057 // called everytime a new TKState is available AND it is the NEW Behavior of an active Switch
00058 void EmergencyLand::trajectoryStepCreation(const TKState& currentState, TKTrajectory& generatedTrajInput)
00059 {
00060         // Same as active
00061         trajectoryStepActive(currentState,generatedTrajInput);
00062 }
00063 
00064 // called everytime a new TKState is available. Should return false if invalid (swtich to next behavior, or Hover if undef).
00065 void EmergencyLand::trajectoryStepActive(const TKState& currentState, TKTrajectory& generatedTrajInput)
00066 {
00067         Vector3D direction = landingPosition - currentState.position;
00068         generatedTrajInput.setVelocity( direction.normalized() * LANDING_VELOCITY );
00069         generatedTrajInput.setYawRate(0.0);
00070 }
00071 
00072 // called everytime a new TKState is available AND it is the OLD Behavior of an active Switch
00073 void EmergencyLand::trajectoryStepTermination(const TKState& currentState, TKTrajectory& generatedTrajInput)
00074 {
00075         // Velocity 0
00076         generatedTrajInput.setVelocity( Velocity3D::Zero() );
00077         generatedTrajInput.setYawRate(0.0);
00078 }
00079 
00080 // Return true if the active Behavior is (still) valid. Initiate Switch otherwise
00081 bool EmergencyLand::isValid(const TKState& currentState) const
00082 {
00083         // Break condition
00084         return currentState.position(2) < MAX_HEIGHT;
00085 }
00086 
00087 }
 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