Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include "DynamicFlyTo.hpp"
00009
00010
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
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
00051 return true;
00052 }
00053
00054 void DynamicFlyTo::didBecomeActive(const TKState& currentState, const Behavior& previousBehavior)
00055 {
00056
00057 }
00058
00059 void DynamicFlyTo::willBecomeInActive(const TKState& currentState, const Behavior& nextBehavior)
00060 {
00061
00062 }
00063
00064 void DynamicFlyTo::didBecomeInActive(const TKState& currentState, const Behavior& nextBehavior)
00065 {
00066
00067 }
00068
00069
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
00078 void DynamicFlyTo::trajectoryStepActive(const TKState& currentState, TKTrajectory& generatedTrajInput)
00079 {
00080 Vector3D direction = tFlyToDestination->getValue() - currentState.position;
00081
00082 double velocityFactor = 1.0;
00083 Acceleration3D acceleration = Acceleration3D::Zero();
00084 if (direction.norm() < tFlyToOuterDestinationRadius->getValue()) {
00085
00086
00087 velocityFactor = direction.norm() / tFlyToOuterDestinationRadius->getValue();
00088 acceleration = direction.normalized() * outerRadiusAcceleration;
00089 }
00090
00091 generatedTrajInput.setVelocity( direction.normalized() * tFlyToVelocity->getValue() * velocityFactor,
00092 acceleration);
00093 generatedTrajInput.setYawAngle( yawAngle );
00094 }
00095
00096
00097 void DynamicFlyTo::trajectoryStepTermination(const TKState& currentState, TKTrajectory& generatedTrajInput)
00098 {
00099 generatedTrajInput.setVelocity( Velocity3D::Zero() );
00100 generatedTrajInput.setYawAngle( yawAngle );
00101 }
00102
00103
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 }
00112