00001 /* -*- Mode: C++ -*- 00002 * $Id: TurnNeckToPoint.cc,v 1.7 2006/09/06 19:08:59 frehe Exp $ 00003 * 00004 * 00005 * COPYRIGHT INFORMATION 00006 * 00007 * This file is part of RoboSoc created by Fredrik Heintzfrehe <@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: TurnNeckToPoint.cc 00019 * Unitname: Framework/skill 00020 * $Revision: 1.7 $ 00021 * Created by: Fredrik Heintz 2003-09-02 00022 * Last modified by $Author: frehe $ $Date: 2006/09/06 19:08:59 $ 00023 * 00024 * 00025 * HISTORY 00026 * 00027 * $Log: TurnNeckToPoint.cc,v $ 00028 * Revision 1.7 2006/09/06 19:08:59 frehe 00029 * Fixed buggy implementations. 00030 * 00031 * Revision 1.6 2005/09/08 08:58:36 frehe 00032 * Implemented the reset method. 00033 * 00034 * Revision 1.5 2004/08/26 17:10:28 frehe 00035 * Fixed bug (generatePlan didn't return anything). 00036 * 00037 * Revision 1.4 2004/08/13 15:39:29 petan 00038 * Moved implementation to generateStep 00039 * 00040 * Revision 1.3 2004/08/13 12:00:39 petan 00041 * Removed couts and fixed bug with turning head outside limits 00042 * 00043 * Revision 1.2 2003/11/07 15:19:29 frehe 00044 * Make sure the neck angles are valid. 00045 * 00046 * Revision 1.1 2003/09/02 17:59:17 frehe 00047 * Added TurnNeckToPoint and TurnNeckToBall. 00048 * 00049 */ 00050 00063 #include "TurnNeckToPoint.h" 00064 #include "CommandStrategy.h" 00065 #include "NewCycleStrategy.h" 00066 #include "WorldModelInterface.h" 00067 #include "TurnNeckCommand.h" 00068 00069 00070 RS_BEGIN_NAMESPACE 00071 00072 00073 // --- CONSTRUCTORS --- 00074 00075 TurnNeckToPoint::TurnNeckToPoint(const Point& pos, ServerCommand* cmd) 00076 : SkillWithPositionAndCommand(pos, cmd) 00077 { 00078 } 00079 00080 00081 // --- DESTRUCTOR --- 00082 00083 TurnNeckToPoint::~TurnNeckToPoint() 00084 { 00085 } 00086 00087 00088 // --- METHODS --- 00089 00090 void 00091 TurnNeckToPoint::reset() 00092 { 00093 } 00094 00095 Plan 00096 TurnNeckToPoint::generatePlan() 00097 { 00098 return Plan(generateStep()); 00099 } 00100 00101 00102 AgentStep 00103 TurnNeckToPoint::generateStep() 00104 { 00105 const CommandStrategy* cmd_strategy 00106 = WorldModelInterface::instance()->getCommandStrategy(); 00107 const NewCycleStrategy* new_cycle_strategy 00108 = WorldModelInterface::instance()->getNewCycleStrategy(); 00109 00110 WorldModel predicted_wm(WorldModelInterface::instance()->getWorld(NOW)); 00111 00112 // Predict the state of the world after executing the command 00113 if ( command != 0 ) { 00114 cmd_strategy->updateAfterCommand(predicted_wm, command); 00115 } 00116 new_cycle_strategy->updateBeforeNewCycle(predicted_wm); 00117 00118 // Now predicted_wm contains the predicted world 00119 AgentObject& agent = predicted_wm.getAgent(); 00120 AngleDegUE turn_dir = agent.getRelativeNeckDirectionToPoint(position); 00121 00122 AgentStep step; 00123 if ( turn_dir.isKnown() ) { 00124 TurnNeckCommand *cmd; 00125 cmd = new TurnNeckCommand(minMax(agent.getMinNeckDirection().getDeg(), 00126 turn_dir.getDeg(), 00127 agent.getMaxNeckDirection().getDeg())); 00128 step.setNeckCommand(cmd); 00129 } 00130 return step; 00131 } 00132 00133 00134 FuzzyBool 00135 TurnNeckToPoint::persistent() 00136 { 00137 // Never persistent. 00138 return FuzzyBool(0.0); 00139 } 00140 00141 00142 FuzzyBool 00143 TurnNeckToPoint::applicable() 00144 { 00145 WorldModel wm(WorldModelInterface::instance()->getWorld(NOW)); 00146 AgentObject& agent = wm.getAgent(); 00147 00148 // Only check body and neck direction since we can't be sure whether 00149 // the ball will be known after prediction even if it's known now. 00150 return agent.getBodyDirection().isKnown() 00151 and agent.getNeckDirection().isKnown(); 00152 } 00153 00154 00155 FuzzyBool 00156 TurnNeckToPoint::succeed() 00157 { 00158 // The skill has not succeeded yet. 00159 return FuzzyBool(0.0); 00160 } 00161 00162 00163 FuzzyBool 00164 TurnNeckToPoint::failed() 00165 { 00166 // The skill has not failed yet. 00167 return FuzzyBool(0.0); 00168 } 00169 00170 00171 00172 RS_END_NAMESPACE
1.3-rc3