Browse files

added barrier functions and tuned cartpole ddps

  • Loading branch information...
1 parent ff50928 commit 8b77608f2bda723b895c1c6d96421fd32edae676 @ghorn committed Sep 13, 2011
Showing with 13 additions and 6 deletions.
  1. +6 −2 cartpoleDdp.hs
  2. +7 −4 doubleCartpoleDdp.hs
View
8 cartpoleDdp.hs
@@ -31,10 +31,14 @@ cost state action = fromList [x*x
-- barrier
uUb = 10.1
uLb = -10.1
+ xUb = 2.0
+ xLb = -2.0
mu = 1.0
uBarrierUb = -mu*log( uUb - u )
uBarrierLb = -mu*log( -uLb + u )
- barrier = uBarrierUb + uBarrierLb
+ xBarrierUb = -0.1*mu*log( xUb - x )
+ xBarrierLb = -0.1*mu*log( -xLb + x )
+ barrier = uBarrierUb + uBarrierLb + xBarrierUb + xBarrierLb
drawFun :: (Maybe SpecialKey) -> (DMatrix, DMatrix, ControllerState) -> IO ()
drawFun key (state, action, (xTraj, _)) = do
@@ -55,7 +59,7 @@ dode x u = rk4Step cartpoleDxdt x u dt
-- run ddp
main :: IO ()
-main = do let n = 100
+main = do let n = 60
alpha = 0.01
x0 = fromList [-4,0,0.01,0]
View
11 doubleCartpoleDdp.hs
@@ -33,10 +33,14 @@ cost state action = fromList [100*x*x
-- barrier
uUb = 2.1
uLb = -2.1
+ xUb = 0.4
+ xLb = -0.4
mu = 1.0
uBarrierUb = -mu*log( uUb - u )
uBarrierLb = -mu*log( -uLb + u )
- barrier = sum[ uBarrierUb, uBarrierLb ]
+ xBarrierUb = -0.1*mu*log( xUb - x )
+ xBarrierLb = -0.1*mu*log( -xLb + x )
+ barrier = sum[ uBarrierUb, uBarrierLb, xBarrierUb, xBarrierLb ]
drawFun :: (Maybe SpecialKey) -> (DMatrix, DMatrix, ControllerState) -> IO ()
drawFun key (state, action, (xTraj, _)) = do
@@ -58,22 +62,21 @@ drawFun key (state, action, (xTraj, _)) = do
-- discrete ode
dt :: Floating a => a
-dt = 0.01
+dt = 0.02
timeDialationFactor :: Double
timeDialationFactor = 0.3
dode :: Matrix a b c => a -> a -> a
dode x u = rk4Step doubleCartpoleDxdt x u dt
-
--"how would you derive a cost function from an end constraint xf?"
--"look at d^2/dxdu at optimal point?"
--"include noise?"
-- run ddp
main :: IO ()
-main = do let n = 45
+main = do let n = 25
alpha0 = 0.0
alpha1 = 0.0

0 comments on commit 8b77608

Please sign in to comment.