00001 /* -*- Mode: C++ -*- 00002 * $Id: AccelerateBallToVelocity.cc,v 1.4 2005/09/08 12:30:31 frehe Exp $ 00003 * 00004 * 00005 * COPYRIGHT INFORMATION 00006 * 00007 * This file is part of RoboSoc created by Fredrik Heintz <frehe@ida.liu.se> 00008 * Copyright (C) 1999, 2000 Fredrik Heintz, Linköping University, Sweden 00009 * 00010 * You are allowed to modify and use this code as long as you retain this 00011 * notice. If you make any changes or have any comments I would appreciate 00012 * it if you send me a message. For more information, please see 00013 * http://www.ida.liu.se/~frehe/RoboCup/RoboSoc/ 00014 * 00015 * 00016 * IDENTIFICATION 00017 * 00018 * Filename: AccelerateBallToVelocity.cc 00019 * Unitname: Framework/skill 00020 * $Revision: 1.4 $ 00021 * Created by: Peter Andersson 2003-08-29 00022 * Last modified by $Author: frehe $ $Date: 2005/09/08 12:30:31 $ 00023 * 00024 * 00025 * HISTORY 00026 * 00027 * $Log: AccelerateBallToVelocity.cc,v $ 00028 * Revision 1.4 2005/09/08 12:30:31 frehe 00029 * Check the applicability in generateStep. 00030 * 00031 * Revision 1.3 2005/09/08 08:58:35 frehe 00032 * Implemented the reset method. 00033 * 00034 * Revision 1.2 2004/08/13 15:39:27 petan 00035 * Moved implementation to generateStep 00036 * 00037 * Revision 1.1 2003/09/03 14:08:43 aip19 00038 * Updated and documented primitive skills 00039 * 00040 */ 00041 00054 #include "AccelerateBallToVelocity.h" 00055 #include "view_constants.h" 00056 #include "KickCommand.h" 00057 #include "rs_error.h" 00058 00059 00060 RS_BEGIN_NAMESPACE 00061 00062 00063 // --- CONSTRUCTORS --- 00064 00065 AccelerateBallToVelocity::AccelerateBallToVelocity(const Vector& vec) 00066 : SkillWithVector(vec), 00067 mAgentView(NULL), 00068 mBallView(NULL), 00069 mKickBallView(NULL) 00070 { 00071 getView(mAgentView, AGENT_VIEW_ID); 00072 getView(mBallView, BALL_VIEW_ID); 00073 getView(mKickBallView, KICKBALL_VIEW_ID); 00074 } 00075 00076 00077 // --- DESTRUCTOR --- 00078 00079 AccelerateBallToVelocity::~AccelerateBallToVelocity() 00080 { 00081 viewManager->releaseView(AGENT_VIEW_ID); 00082 viewManager->releaseView(BALL_VIEW_ID); 00083 viewManager->releaseView(KICKBALL_VIEW_ID); 00084 } 00085 00086 00087 // --- METHODS --- 00088 00089 void AccelerateBallToVelocity::reset() 00090 { 00091 } 00092 00093 Plan AccelerateBallToVelocity::generatePlan() 00094 { 00095 return Plan(generateStep()); 00096 } 00097 00098 AgentStep AccelerateBallToVelocity::generateStep() 00099 { 00100 KickCommand *command; 00101 AgentStep step; 00102 00103 if ( !applicable() ) { 00104 RS_WARNING("Tried to call AccelerateBallToVelocity which isn't applicable"); 00105 return step; 00106 } 00107 00108 Vector wantedBallVector = vector - mBallView->getSpeedVector().getVector(); 00109 00110 const WorldFacts* facts = WorldModelInterface::instance()->getWorldFacts(); 00111 00112 if (wantedBallVector.getLength() <= facts->SP_maxpower) { 00113 FloatUE power = mKickBallView->getKickPowerForSpeed(wantedBallVector.getLength()); 00114 AngleDeg angle = wantedBallVector.getAngle() - mAgentView->getBodyDirection().getAngle(); 00115 00116 command = new KickCommand(power.getValue(), angle); 00117 } 00118 else { 00119 // Recompute vector to give ball maximum speed in desired angle 00120 wantedBallVector = mBallView->getSpeedVector().getVector(); 00121 wantedBallVector.rotate(-vector.getAngle()); 00122 Point point(wantedBallVector); 00123 00124 Float length = facts->SP_maxpower * mKickBallView->kickPowerRate().getValue(); 00125 AngleDeg angle = vector.getAngle() - asin(point.getY()/length); 00126 angle -= mAgentView->getBodyDirection().getAngle(); 00127 00128 command = new KickCommand(facts->SP_maxpower, angle); 00129 } 00130 00131 step.setBodyCommand(command); 00132 return step; 00133 } 00134 00135 FuzzyBool AccelerateBallToVelocity::persistent() 00136 { 00137 // Never persistent. 00138 return FuzzyBool(0.0); 00139 } 00140 00141 FuzzyBool AccelerateBallToVelocity::applicable() 00142 { 00143 return mAgentView->getBodyDirection().isKnown() && 00144 mBallView->getSpeedVector().isKnown() && 00145 mBallView->isBallKickable(); 00146 } 00147 00148 FuzzyBool AccelerateBallToVelocity::succeed() 00149 { 00150 // Has not succeeded yet 00151 return FuzzyBool(0.0); 00152 } 00153 00154 FuzzyBool AccelerateBallToVelocity::failed() 00155 { 00156 // Has not failed yet 00157 return FuzzyBool(0.0); 00158 } 00159 00160 00161 00162 RS_END_NAMESPACE 00163
1.3-rc3