Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Modules/WalkingEngine/WalkingEngineSelector.h

Go to the documentation of this file.
00001 /**
00002 * @file WalkingEngineSelector.h
00003 * 
00004 * Definition of class WalkingEngineSelector
00005 *
00006 * @author Max Risler
00007 */
00008 
00009 #ifndef __WalkingEngineSelector_h_
00010 #define __WalkingEngineSelector_h_
00011 
00012 #include "Tools/Module/ModuleSelector.h"
00013 
00014 #include "InvKinWalkingParameterSets.h"
00015 #include "GT2005WalkingEngine.h"
00016 #include "GT2004WalkingEngine.h"
00017 
00018 /**
00019 * @class WalkingEngineSelector
00020 *
00021 * A module selector for WalkingEngine modules.
00022 */
00023 class WalkingEngineSelector : public ModuleSelector, public WalkingEngine
00024 {
00025 public:
00026 /**
00027 * Constructor.
00028 * @param handler The module handler of the process.
00029 * @param moduleID The module id of the walking engine.
00030 * @param interfaces The paramters of the MotionControl module.
00031 * @param pInvKinWalkingEngine Pointer to an InvKinWalkingEngine to be used to avoid having different engines for different parameter sets.
00032   */
00033   WalkingEngineSelector(ModuleHandler &handler,
00034     SolutionRequest::ModuleID moduleID,
00035     const WalkingEngineInterfaces& interfaces,
00036     InvKinWalkingEngine* pInvKinWalkingEngine) 
00037     : ModuleSelector(moduleID),
00038     WalkingEngine(interfaces), pInvKinWalkingEngine(pInvKinWalkingEngine)
00039   {
00040     handler.setModuleSelector(moduleID,this);
00041   }
00042   
00043   
00044   /** 
00045   * Is called on start and when the selected solution changes
00046   * to create a specific solution.
00047   * @param id The id of the solution to create
00048   * @return The created solution or 0
00049   */
00050   virtual Module* createSolution(SolutionRequest::ModuleSolutionID id)
00051   {
00052     switch(id) {
00053       case SolutionRequest::gt2005WalkingEngine:
00054         return new GT2005WalkingEngine(*this);
00055 
00056       // "Real" WalkingEngine solutions
00057       //
00058       case SolutionRequest::gt2004WalkingEngine:
00059         return new GT2004WalkingEngine(*this);
00060       
00061       // ParamInvKinWalkingEngines
00062       //
00063       case SolutionRequest::invKinUpsideDownWalkingEngine:
00064         return new ParamInvKinWalkingEngine(new UpsideDownWalkingParameters, pInvKinWalkingEngine);
00065       
00066       case SolutionRequest::invKinTurnWithBallWalkingEngine: 
00067         return new ParamInvKinWalkingEngine(new TurnWithBallWalkingParameters, pInvKinWalkingEngine);
00068 
00069       case SolutionRequest::invKinTurnKickWalkingEngine: 
00070         return new ParamInvKinWalkingEngine(new TurnKickWalkingParameters, pInvKinWalkingEngine);
00071 
00072       default:
00073         return 0;
00074     }
00075   }
00076   
00077   /** Executes the module */
00078   bool executeParameterized(JointData& jointData, const WalkRequest& walkRequest, double positionInWalkingCycle)
00079   {
00080     if (selectedSolution!=0) 
00081     {
00082       return ((WalkingEngine*)selectedSolution)->executeParameterized(jointData, walkRequest, positionInWalkingCycle);
00083     }
00084     else 
00085     {
00086       //if no WE is enabled, 2do:
00087       jointData.data[JointData::neckTilt] = jointDataInvalidValue;
00088       jointData.data[JointData::headPan] = jointDataInvalidValue;
00089       jointData.data[JointData::headTilt] = jointDataInvalidValue;
00090       return false;
00091     }
00092   }
00093     /** Handles a message */
00094   virtual bool handleMessage(InMessage& message)
00095   {
00096     if (selectedSolution!=0) 
00097       return ((WalkingEngine*)selectedSolution)->handleMessage(message);
00098     else return false;
00099   }
00100   
00101   /** The only used InvKinWalkingEngine */
00102   InvKinWalkingEngine* pInvKinWalkingEngine;
00103 };
00104 
00105 #endif // __WalkingEngineSelector_h_

Generated on Mon Mar 20 21:59:59 2006 for GT2005 by doxygen 1.3.6