Reinforcement Learning Toolbox 2.0
last updated:
General
Documentation
Manual
Tutorial
Class Reference
Master Thesis
Examples
Related Papers
Downloads
Links
News
mailto:webmaster
Main Page     Class Hierarchy   Compound List   File List   Compound Members   File Members

ccartpolemodel.h

Go to the documentation of this file.
00001 // Copyright (C) 2003
00002 // Gerhard Neumann (gneumann@gmx.net)
00003 // Stephan Neumann (sneumann@gmx.net) 
00004 //                
00005 // This file is part of RL Toolbox.
00006 // http://www.igi.tugraz.at/ril_toolbox
00007 //
00008 // All rights reserved.
00009 // 
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions
00012 // are met:
00013 // 1. Redistributions of source code must retain the above copyright
00014 //    notice, this list of conditions and the following disclaimer.
00015 // 2. Redistributions in binary form must reproduce the above copyright
00016 //    notice, this list of conditions and the following disclaimer in the
00017 //    documentation and/or other materials provided with the distribution.
00018 // 3. The name of the author may not be used to endorse or promote products
00019 //    derived from this software without specific prior written permission.
00020 // 
00021 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00022 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00023 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00024 // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00025 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00026 // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00027 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00028 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00029 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00030 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031 
00032 #ifndef __CCARTPOLE_H
00033 #define __CCARTPOLE_H
00034 
00035 #include "cqtconfig.h"
00036 
00037 #include "ctransitionfunction.h"
00038 #include "crewardfunction.h"
00039 
00040 
00041 #ifdef RL_TOOLBOX_USE_QT
00042 #include "cqtmodelvisualizer.h"
00043 #endif
00044 
00045 class CCartPoleModel : public CLinearActionContinuousTimeTransitionFunction
00046 {
00047 protected:
00048         virtual void doSimulationStep(CState *state, double timestep, CAction *action, CActionData *data);
00049 
00050 
00051 public:
00052         double uMax;
00053         double lengthTrack;
00054         double g;
00055         double massCart;
00056         double massPole;
00057         double lengthPole;
00058         double mu_c; // friction cart
00059         double mu_p; // friction pole
00060 
00061         bool endLeaveTrack;
00062         bool endOverRotate;
00063 
00064         double failedReward;
00065 
00066         CCartPoleModel(double dt, double uMax = 10, double lengthTrack = 4.8, double lengthPole = 0.5, double massCart = 1.0, double massPole = 0.5,  double mu_c = 1.0, double mu_p = 0.1, double g = 9.8, bool endLeaveTrack = true,bool endOverRotate = true);
00067         ~CCartPoleModel();
00068 
00069         virtual Matrix *getB(CState *state);
00070         virtual ColumnVector *getA(CState *state);
00071 
00072         virtual bool isFailedState(CState *state);
00073 
00074         virtual void getResetState(CState *state);
00075 };
00076 
00077 class CCartPoleRewardFunction : public CStateReward
00078 {
00079 protected:
00080         CCartPoleModel *cartpoleModel;
00081 public:
00082         bool useHeighPeak;
00083         bool punishOverRotate;
00084         CCartPoleRewardFunction(CCartPoleModel *model);
00085         ~CCartPoleRewardFunction() {};
00086 
00087         virtual double getStateReward(CState *state);
00088         virtual void getInputDerivation(CState *modelState, ColumnVector *targetState);
00089 
00090 };
00091 
00092 class CCartPoleHeightRewardFunction : public CStateReward
00093 {
00094 protected:
00095         CCartPoleModel *cartpoleModel;
00096 public:
00097         CCartPoleHeightRewardFunction(CCartPoleModel *model);
00098 
00099         virtual double getStateReward(CState *state);
00100         virtual void getInputDerivation(CState *modelState, ColumnVector *targetState);
00101 
00102 };
00103 
00104 #ifdef RL_TOOLBOX_USE_QT
00105 
00106 class CQTCartPoleVisualizer : public CQTModelVisualizer
00107 {
00108 protected:
00109         double phi;
00110         double dphi;
00111         double x;
00112         double dx;
00113 
00114         CCartPoleModel *cartModel;
00115 
00116         virtual void doDrawState( QPainter *painter);
00117 
00118 public:
00119 
00120         CQTCartPoleVisualizer( CCartPoleModel *model, QWidget *parent = NULL, const char *name = NULL);
00121 
00122         virtual void newDrawState(CStateCollection *state);
00123 };
00124 
00125 #endif
00126 
00127 #endif
00128