DynamicFlyTo.cpp
Go to the documentation of this file.
00001 /*
00002  * DynamicFlyTo.cpp
00003  *
00004  *  Created on: Jan 9, 2012
00005  *      Author: mriedel
00006  */
00007 
00008 #include "DynamicFlyTo.hpp"
00009 
00010 // Declare
00011 PLUGINLIB_DECLARE_CLASS(tk_be_common, DynamicFlyTo, telekyb_behavior::DynamicFlyTo, TELEKYB_NAMESPACE::Behavior);
00012 
00013 namespace telekyb_behavior {
00014 
00015 DynamicFlyTo::DynamicFlyTo()
00016         : Behavior("tk_be_common/DynamicFlyTo", BehaviorType::Air)
00017 {
00018 
00019 }
00020 
00021 void DynamicFlyTo::initialize()
00022 {
00023         tFlyToDestination = addOption<Position3D>("tFlyToDestination",
00024                         "Specifies the Destination of the DynamicFlyTo Behavior",
00025                         Position3D(0.0,0.0,-1.0), false, false);
00026         tFlyToVelocity = addOption<double>("tFlyToVelocity",
00027                         "Defines the Velocity of the DynamicFlyTo Behavior",
00028                         5.0, false, false);
00029         tFlyToInnerDestinationRadius = addOption<double>("tFlyToInnerDestinationRadius",
00030                         "Defines the Radius from the Destination, at which the DynamicFlyTo Behavior turns invalid",
00031                         0.05, false, false);
00032         tFlyToOuterDestinationRadius = addOption<double>("tFlyToOuterDestinationRadius",
00033                         "Defines the Radius at which the QC linearly decreases speed.",
00034                         0.5, false, false);
00035 
00036         //parameterInitialized = true; // not parameter Initialized by default.
00037 }
00038 
00039 void DynamicFlyTo::destroy()
00040 {
00041 
00042 }
00043 
00044 bool DynamicFlyTo::willBecomeActive(const TKState& currentState, const Behavior& previousBehavior)
00045 {
00046         yawAngle = currentState.getEulerRPY()(2);
00047 
00048         outerRadiusAcceleration = (tFlyToVelocity->getValue() * tFlyToVelocity->getValue()) /
00049                         ( 2 * tFlyToOuterDestinationRadius->getValue() );
00050         //ROS_INFO("DynamicFlyTo: Storing yawAngle: %f ", yawAngle);
00051         return true;
00052 }
00053 
00054 void DynamicFlyTo::didBecomeActive(const TKState& currentState, const Behavior& previousBehavior)
00055 {
00056         // not used
00057 }
00058 
00059 void DynamicFlyTo::willBecomeInActive(const TKState& currentState, const Behavior& nextBehavior)
00060 {
00061         // not used
00062 }
00063 
00064 void DynamicFlyTo::didBecomeInActive(const TKState& currentState, const Behavior& nextBehavior)
00065 {
00066         // not used
00067 }
00068 
00069 // called everytime a new TKState is available AND it is the NEW Behavior of an active Switch
00070 void DynamicFlyTo::trajectoryStepCreation(const TKState& currentState, TKTrajectory& generatedTrajInput)
00071 {
00072         Vector3D direction = tFlyToDestination->getValue() - currentState.position;
00073         generatedTrajInput.setVelocity( direction.normalized() * tFlyToVelocity->getValue() );
00074         generatedTrajInput.setYawAngle( yawAngle );
00075 }
00076 
00077 // called everytime a new TKState is available. Should return false if invalid (swtich to next behavior, or Hover if undef).
00078 void DynamicFlyTo::trajectoryStepActive(const TKState& currentState, TKTrajectory& generatedTrajInput)
00079 {
00080         Vector3D direction = tFlyToDestination->getValue() - currentState.position;
00081         // Linearly slow down from tFlyToOuterDestinationRadius.
00082         double velocityFactor = 1.0;
00083         Acceleration3D acceleration = Acceleration3D::Zero();
00084         if (direction.norm() < tFlyToOuterDestinationRadius->getValue()) {
00085                 // Slow down
00086                 //ROS_INFO("Breaking!");
00087                 velocityFactor = direction.norm() / tFlyToOuterDestinationRadius->getValue(); // between 0.0 - 1.0
00088                 acceleration = direction.normalized() * outerRadiusAcceleration;
00089         }
00090 
00091         generatedTrajInput.setVelocity( direction.normalized() * tFlyToVelocity->getValue() * velocityFactor,
00092                         acceleration);
00093         generatedTrajInput.setYawAngle( yawAngle );
00094 }
00095 
00096 // called everytime a new TKState is available AND it is the OLD Behavior of an active Switch
00097 void DynamicFlyTo::trajectoryStepTermination(const TKState& currentState, TKTrajectory& generatedTrajInput)
00098 {
00099         generatedTrajInput.setVelocity( Velocity3D::Zero() );
00100         generatedTrajInput.setYawAngle( yawAngle );
00101 }
00102 
00103 // Return true if the active Behavior is (still) valid. Initiate Switch otherwise
00104 bool DynamicFlyTo::isValid(const TKState& currentState) const
00105 {
00106         Vector3D direction = tFlyToDestination->getValue() - currentState.position;
00107         return direction.norm() > tFlyToInnerDestinationRadius->getValue();
00108 }
00109 
00110 
00111 } /* namespace telekyb_behavior */
00112 
 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