Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 #include <behaviors/EmergencyLand.hpp>
00009 
00010 
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         
00045 }
00046 
00047 void EmergencyLand::willBecomeInActive(const TKState& currentState, const Behavior& nextBehavior)
00048 {
00049         
00050 }
00051 
00052 void EmergencyLand::didBecomeInActive(const TKState& currentState, const Behavior& nextBehavior)
00053 {
00054         
00055 }
00056 
00057 
00058 void EmergencyLand::trajectoryStepCreation(const TKState& currentState, TKTrajectory& generatedTrajInput)
00059 {
00060         
00061         trajectoryStepActive(currentState,generatedTrajInput);
00062 }
00063 
00064 
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 
00073 void EmergencyLand::trajectoryStepTermination(const TKState& currentState, TKTrajectory& generatedTrajInput)
00074 {
00075         
00076         generatedTrajInput.setVelocity( Velocity3D::Zero() );
00077         generatedTrajInput.setYawRate(0.0);
00078 }
00079 
00080 
00081 bool EmergencyLand::isValid(const TKState& currentState) const
00082 {
00083         
00084         return currentState.position(2) < MAX_HEIGHT;
00085 }
00086 
00087 }