aboutsummaryrefslogtreecommitdiffstats
path: root/System/system_swingup_test_2.py
diff options
context:
space:
mode:
authorMatt Strapp <matt@mattstrapp.net>2022-01-27 15:29:31 -0600
committerMatt Strapp <matt@mattstrapp.net>2022-01-27 15:29:31 -0600
commit772cff67fd3b491d015ba89601a0a098c69edd69 (patch)
tree7c1f6b3110bb45913bc0b895c0754d5cefda52e0 /System/system_swingup_test_2.py
parentAdd Uploads to the gitignore. (diff)
downloadee4511w-772cff67fd3b491d015ba89601a0a098c69edd69.tar
ee4511w-772cff67fd3b491d015ba89601a0a098c69edd69.tar.gz
ee4511w-772cff67fd3b491d015ba89601a0a098c69edd69.tar.bz2
ee4511w-772cff67fd3b491d015ba89601a0a098c69edd69.tar.lz
ee4511w-772cff67fd3b491d015ba89601a0a098c69edd69.tar.xz
ee4511w-772cff67fd3b491d015ba89601a0a098c69edd69.tar.zst
ee4511w-772cff67fd3b491d015ba89601a0a098c69edd69.zip
Add code that was not committed before
Diffstat (limited to 'System/system_swingup_test_2.py')
-rw-r--r--[-rwxr-xr-x]System/system_swingup_test_2.py23
1 files changed, 18 insertions, 5 deletions
diff --git a/System/system_swingup_test_2.py b/System/system_swingup_test_2.py
index cb646ef..fc02ed6 100755..100644
--- a/System/system_swingup_test_2.py
+++ b/System/system_swingup_test_2.py
@@ -6,7 +6,14 @@ import math
from gym import spaces, logger
from gym.utils import seeding
+###
+import sys
+sys.path.insert(0, '/home/pi/pendulum/System')
+###
+
+
from System.system import System
+#from . import System
import time
from sys import exit
@@ -103,14 +110,20 @@ class SwingUpEnv():
self.last_time = current_time
new_theta, new_x = self.sys.measure()
- theta_dot = (new_theta - theta) / tau
+ if (theta >= 0 and theta < math.pi/2.) and (new_theta > 3.*math.pi/2.):
+ theta_dot = (new_theta - (theta + 2.*math.pi)) / tau
+ elif (new_theta >= 0 and new_theta < math.pi/2.) and (theta > 3.*math.pi/2.):
+ theta_dot = ((new_theta + 2.*math.pi) - theta) / tau
+ else:
+ theta_dot = (new_theta - theta) / tau
x_dot = (new_x - x) / tau
self.state = (new_x, x_dot, new_theta, theta_dot)
self.sys.add_results(new_theta, new_x, force)
- done = theta_dot < -self.theta_dot_threshold \
+ '''done = theta_dot < -self.theta_dot_threshold \
or theta_dot > self.theta_dot_threshold \
- or self.done == True
+ or self.done == True'''
+ done = self.done
'''done = x < -self.x_threshold \
or x > self.x_threshold \
@@ -325,7 +338,7 @@ gamma = .95
agent = deepQagent(5,numActions,20,2,epsilon=5e-2,gamma=gamma,batch_size=20,
c= 100,alpha=1e-4)
-maxSteps = 2e5
+maxSteps = 2e6
# This is a helper to deal with the fact that x[2] is actually an angle
x_to_y = lambda x : np.array([x[0], x[1], np.cos(x[2]), np.sin(x[2]), x[3]])
@@ -379,4 +392,4 @@ except:
exit(-1)
finally:
env.end()
- exit(0) \ No newline at end of file
+ exit(0)