basicplayer_8c-source.html
来自「仿真人工智能是指用人工的方法和技术」· HTML 代码 · 共 526 行 · 第 1/5 页
HTML
526 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>BasicPlayer.C Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body bgcolor="#ffffff"><!-- Generated by Doxygen 1.2.12 --><center><a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> </center><hr><h1>BasicPlayer.C</h1><a href="BasicPlayer_8C.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">/*</font>00002 <font class="comment">Copyright (c) 2000,2001, Jelle Kok, University of Amsterdam</font>00003 <font class="comment">All rights reserved.</font>00004 <font class="comment"></font>00005 <font class="comment">Redistribution and use in source and binary forms, with or without </font>00006 <font class="comment">modification, are permitted provided that the following conditions are met:</font>00007 <font class="comment"></font>00008 <font class="comment">1. Redistributions of source code must retain the above copyright notice, this </font>00009 <font class="comment">list of conditions and the following disclaimer. </font>00010 <font class="comment"></font>00011 <font class="comment">2. Redistributions in binary form must reproduce the above copyright notice, </font>00012 <font class="comment">this list of conditions and the following disclaimer in the documentation </font>00013 <font class="comment">and/or other materials provided with the distribution. </font>00014 <font class="comment"></font>00015 <font class="comment">3. Neither the name of the University of Amsterdam nor the names of its </font>00016 <font class="comment">contributors may be used to endorse or promote products derived from this </font>00017 <font class="comment">software without specific prior written permission. </font>00018 <font class="comment"></font>00019 <font class="comment">THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" </font>00020 <font class="comment">AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE </font>00021 <font class="comment">IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE </font>00022 <font class="comment">DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE </font>00023 <font class="comment">FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL </font>00024 <font class="comment">DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR </font>00025 <font class="comment">SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER </font>00026 <font class="comment">CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, </font>00027 <font class="comment">OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE </font>00028 <font class="comment">OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</font>00029 <font class="comment">*/</font>00044 <font class="preprocessor">#include "<a class="code" href="BasicPlayer_8h.html">BasicPlayer.h</a>"</font>00045 00046 <font class="comment">/********************** LOW-LEVEL SKILLS *************************************/</font>00047 <a name="l00052"></a><a class="code" href="classBasicPlayer.html#b0">00052</a> <a class="code" href="classSoccerCommand.html">SoccerCommand</a> <a class="code" href="classBasicPlayer.html#b0">BasicPlayer::alignNeckWithBody</a>( )00053 {00054 <font class="keywordflow">return</font> <a class="code" href="classSoccerCommand.html">SoccerCommand</a>( <a class="code" href="SoccerTypes_8h.html#a247a183">CMD_TURNNECK</a>, <a class="code" href="classBasicPlayer.html#n1">WM</a>-><a class="code" href="classWorldModel.html#a36">getAgentBodyAngleRelToNeck</a>( ) );00055 }00056 <a name="l00075"></a><a class="code" href="classBasicPlayer.html#b1">00075</a> <a class="code" href="classSoccerCommand.html">SoccerCommand</a> <a class="code" href="classBasicPlayer.html#b1">BasicPlayer::turnBodyToPoint</a>( <a class="code" href="classVecPosition.html">VecPosition</a> pos, <font class="keywordtype">int</font> iCycles = 1 )00076 {00077 <a class="code" href="classVecPosition.html">VecPosition</a> posGlobal = <a class="code" href="classBasicPlayer.html#n1">WM</a>-><a class="code" href="classWorldModel.html#a108">predictAgentPos</a>(iCycles, 0);00078 <a class="code" href="Geometry_8h.html#a2">AngDeg</a> angTurn = (pos - posGlobal).getDirection();00079 angTurn -= <a class="code" href="classBasicPlayer.html#n1">WM</a>-><a class="code" href="classWorldModel.html#a38">getAgentGlobalBodyAngle</a>();00080 angTurn = <a class="code" href="classVecPosition.html#d1">VecPosition::normalizeAngle</a>( angTurn );00081 angTurn = <a class="code" href="classBasicPlayer.html#n1">WM</a>-><a class="code" href="classWorldModel.html#a149">getAngleForTurn</a>( angTurn, <a class="code" href="classBasicPlayer.html#n1">WM</a>-><a class="code" href="classWorldModel.html#a42">getAgentSpeed</a>() );00082 00083 <font class="keywordflow">return</font> <a class="code" href="classSoccerCommand.html">SoccerCommand</a>( <a class="code" href="SoccerTypes_8h.html#a247a182">CMD_TURN</a>, angTurn );00084 }00085 <a name="l00098"></a><a class="code" href="classBasicPlayer.html#b2">00098</a> <a class="code" href="classSoccerCommand.html">SoccerCommand</a> <a class="code" href="classBasicPlayer.html#b2">BasicPlayer::turnBackToPoint</a>( <a class="code" href="classVecPosition.html">VecPosition</a> pos, <font class="keywordtype">int</font> iCycles = 1 )00099 {00100 <a class="code" href="classVecPosition.html">VecPosition</a> posGlobal = <a class="code" href="classBasicPlayer.html#n1">WM</a>-><a class="code" href="classWorldModel.html#a108">predictAgentPos</a>(iCycles, 0);00101 <a class="code" href="Geometry_8h.html#a2">AngDeg</a> angTurn = (pos - posGlobal).getDirection();00102 angTurn -= (<a class="code" href="classBasicPlayer.html#n1">WM</a>-><a class="code" href="classWorldModel.html#a38">getAgentGlobalBodyAngle</a>() + 180);00103 angTurn = <a class="code" href="classVecPosition.html#d1">VecPosition::normalizeAngle</a>( angTurn );00104 angTurn = <a class="code" href="classBasicPlayer.html#n1">WM</a>-><a class="code" href="classWorldModel.html#a149">getAngleForTurn</a>( angTurn, <a class="code" href="classBasicPlayer.html#n1">WM</a>-><a class="code" href="classWorldModel.html#a42">getAgentSpeed</a>() );00105 00106 <font class="keywordflow">return</font> <a class="code" href="classSoccerCommand.html">SoccerCommand</a>( <a class="code" href="SoccerTypes_8h.html#a247a182">CMD_TURN</a>, angTurn );00107 }00108 <a name="l00130"></a><a class="code" href="classBasicPlayer.html#b3">00130</a> <a class="code" href="classSoccerCommand.html">SoccerCommand</a> <a class="code" href="classBasicPlayer.html#b3">BasicPlayer::turnNeckToPoint</a>(<a class="code" href="classVecPosition.html">VecPosition</a> pos, <a class="code" href="classSoccerCommand.html">SoccerCommand</a> soc)00131 {00132 <a class="code" href="classVecPosition.html">VecPosition</a> posMe, velMe;00133 <a class="code" href="Geometry_8h.html#a2">AngDeg</a> angBody, angNeck, angActual;00134 <a class="code" href="classStamina.html">Stamina</a> sta;00135 00136 <font class="comment">// predict agent information after command 'soc' is performed</font>00137 <font class="comment">// calculate the desired global angle of the neck</font>00138 <font class="comment">// calculate the desired angle of the neck relative to the body</font>00139 <a class="code" href="classBasicPlayer.html#n1">WM</a>-><a class="code" href="classWorldModel.html#a103">predictAgentStateAfterCommand</a>(soc,&posMe,&velMe,&angBody,&angNeck,&sta);00140 <a class="code" href="Geometry_8h.html#a2">AngDeg</a> angDesGlobNeck = (pos - posMe).getDirection();00141 <a class="code" href="Geometry_8h.html#a2">AngDeg</a> angNeckRelToBody = <a class="code" href="classVecPosition.html#d1">VecPosition::normalizeAngle</a>(angDesGlobNeck-angBody);00142 00143 <font class="comment">// calculate the current angle of the body relative to the neck</font>00144 <font class="comment">// check if the desired neck angle relative to the body is possible:</font>00145 <font class="comment">// if angle is smaller than the minimum or larger than the maximum neck angle</font>00146 <font class="comment">// turn neck to the minimum or maximum neck angle + the current neck angle</font>00147 <font class="comment">// else calculate the desired angle relative to the body</font>00148 <a class="code" href="Geometry_8h.html#a2">AngDeg</a> angBodyRelToNeck = <a class="code" href="classVecPosition.html#d1">VecPosition::normalizeAngle</a>(angBody-angNeck);00149 <font class="keywordflow">if</font>( angNeckRelToBody < <a class="code" href="classBasicPlayer.html#n2">SS</a>-><a class="code" href="classServerSettings.html#a108">getMinNeckAng</a>() )00150 angActual = <a class="code" href="classBasicPlayer.html#n2">SS</a>-><a class="code" href="classServerSettings.html#a108">getMinNeckAng</a>() + angBodyRelToNeck;00151 <font class="keywordflow">else</font> <font class="keywordflow">if</font>( angNeckRelToBody > <a class="code" href="classBasicPlayer.html#n2">SS</a>-><a class="code" href="classServerSettings.html#a106">getMaxNeckAng</a>() )00152 angActual = <a class="code" href="classBasicPlayer.html#n2">SS</a>-><a class="code" href="classServerSettings.html#a106">getMaxNeckAng</a>() + angBodyRelToNeck;00153 <font class="keywordflow">else</font>00154 angActual = angNeckRelToBody + angBodyRelToNeck;00155 <font class="keywordflow">return</font> <a class="code" href="classSoccerCommand.html">SoccerCommand</a>( <a class="code" href="SoccerTypes_8h.html#a247a183">CMD_TURNNECK</a>, angActual );00156 }00157 <a name="l00169"></a><a class="code" href="classBasicPlayer.html#b4">00169</a> <a class="code" href="classSoccerCommand.html">SoccerCommand</a> <a class="code" href="classBasicPlayer.html#b4">BasicPlayer::searchBall</a>()00170 {00171 <font class="keyword">static</font> <a class="code" href="classTime.html">Time</a> timeLastSearch;00172 <font class="keyword">static</font> <font class="keywordtype">int</font> iSign = 1;00173 00174 <font class="comment">// calculate maximum turn angle</font>00175 <a class="code" href="Geometry_8h.html#a2">AngDeg</a> ang = 2*<a class="code" href="classSoccerTypes.html#d26">SoccerTypes::getHalfViewAngleValue</a>( <a class="code" href="classBasicPlayer.html#n1">WM</a>-><a class="code" href="classWorldModel.html#a44">getAgentViewAngle</a>() );00176 ang = <a class="code" href="classBasicPlayer.html#n1">WM</a>-><a class="code" href="classWorldModel.html#a149">getAngleForTurn</a>( ang - ang/10.0, <a class="code" href="classBasicPlayer.html#n1">WM</a>-><a class="code" href="classWorldModel.html#a42">getAgentSpeed</a>() );00177 00178 <font class="comment">// calculate whether expected ball position is too the left or right of body</font>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?