TakeOff.cpp
Go to the documentation of this file.
00001 /*
00002  * TakeOff.cpp
00003  *
00004  *  Created on: Nov 3, 2011
00005  *      Author: mriedel
00006  */
00007 
00008 #include <behaviors/TakeOff.hpp>
00009 
00010 
00011 // Declare
00012 PLUGINLIB_DECLARE_CLASS(tk_behavior, TakeOff, telekyb_behavior::TakeOff, TELEKYB_NAMESPACE::Behavior);
00013 
00014 namespace telekyb_behavior {
00015 
00016 TakeOff::TakeOff()
00017         : Behavior("tk_behavior/TakeOff", BehaviorType::TakeOff)
00018 {
00019 
00020 }
00021 
00022 void TakeOff::initialize()
00023 {
00024         tTakeOffDestination = addOption<Position3D>("tTakeOffDestination",
00025                         "Specifies the Destination of the TakeOff Behavior",
00026                         Position3D(0.0,0.0,-1.0), false, false);
00027         tTakeOffVelocity = addOption<double>("tTakeOffVelocity",
00028                         "Defines the Velocity of the TakeOff Behavior",
00029                         0.3, false, false);
00030         tTakeOffDestinationRadius = addOption<double>("tTakeOffDestinationRadius",
00031                         "Defines the Radius from the Destination, at which the TakeOff Behavior turns invalid",
00032                         0.1, false, false);
00033         tTakeOffVertically = addOption<bool>("tTakeOffVertically",
00034                         "Take off vertically to the z-Component of the Destination",
00035                         false, false, false);
00036 
00037         //parameterInitialized = true; // not parameter Initialized by default.
00038 }
00039 
00040 void TakeOff::destroy()
00041 {
00042 
00043 }
00044 
00045 bool TakeOff::willBecomeActive(const TKState& currentState, const Behavior& previousBehavior)
00046 {
00047         // TODO: Out of correctness we should check if currentState is too close to destination.
00048         // -> on the other hand it would return false right after in the trajStep.
00049         if (tTakeOffVertically->getValue()) {
00050                 actualTakeOffDestination = currentState.position;
00051                 actualTakeOffDestination(2) = tTakeOffDestination->getValue()(2);
00052         } else {
00053                 actualTakeOffDestination = tTakeOffDestination->getValue();
00054         }
00055 
00056         yawAngle = currentState.getEulerRPY()(2);
00057         return true;
00058 }
00059 
00060 void TakeOff::didBecomeActive(const TKState& currentState, const Behavior& previousBehavior)
00061 {
00062         // not used
00063 }
00064 
00065 void TakeOff::willBecomeInActive(const TKState& currentState, const Behavior& nextBehavior)
00066 {
00067         // not used
00068 }
00069 
00070 void TakeOff::didBecomeInActive(const TKState& currentState, const Behavior& nextBehavior)
00071 {
00072         // not used
00073 }
00074 
00075 // called everytime a new TKState is available AND it is the NEW Behavior of an active Switch
00076 void TakeOff::trajectoryStepCreation(const TKState& currentState, TKTrajectory& generatedTrajInput)
00077 {
00078         // Same as active
00079         trajectoryStepActive(currentState,generatedTrajInput);
00080 }
00081 
00082 // called everytime a new TKState is available. Should return false if invalid (swtich to next behavior, or Hover if undef).
00083 void TakeOff::trajectoryStepActive(const TKState& currentState, TKTrajectory& generatedTrajInput)
00084 {
00085         Vector3D direction = actualTakeOffDestination - currentState.position;
00086         generatedTrajInput.setVelocity( direction.normalized() * tTakeOffVelocity->getValue() );
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 TakeOff::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 TakeOff::isValid(const TKState& currentState) const
00099 {
00100         Vector3D direction = actualTakeOffDestination - currentState.position;
00101         return direction.norm() > tTakeOffDestinationRadius->getValue();
00102 }
00103 
00104 }
 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