FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
PythonLinearNonlinearControl/tests/env/test_cartpole.py at develop · NmBoyd/PythonLinearNonlinearControl · GitHub
NmBoyd
PythonLinearNonlinearControl
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
PythonLinearNonlinearControl
/
tests
/
env
/
test_cartpole.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
73 lines (55 loc) · 2.42 KB
Breadcrumbs
PythonLinearNonlinearControl
/
tests
/
env
/
test_cartpole.py
Copy path
File metadata and controls
73 lines (55 loc) · 2.42 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import
pytest
import
numpy
as
np
from
PythonLinearNonlinearControl
.
envs
.
cartpole
import
CartPoleEnv
class
TestCartPoleEnv
():
"""
"""
def
test_step
(
self
):
env
=
CartPoleEnv
()
curr_x
=
np
.
ones
(
4
)
curr_x
[
2
]
=
np
.
pi
/
6.
env
.
reset
(
init_x
=
curr_x
)
u
=
np
.
ones
(
1
)
next_x
,
_
,
_
,
_
=
env
.
step
(
u
)
d_x0
=
curr_x
[
1
]
d_x1
=
(
1.
+
env
.
config
[
"mp"
]
*
np
.
sin
(
np
.
pi
/
6.
) \
*
(
env
.
config
[
"l"
]
*
(
1.
**
2
) \
+
env
.
config
[
"g"
]
*
np
.
cos
(
np
.
pi
/
6.
))) \
/
(
env
.
config
[
"mc"
]
+
env
.
config
[
"mp"
]
*
np
.
sin
(
np
.
pi
/
6.
)
**
2
)
d_x2
=
curr_x
[
3
]
d_x3
=
(
-
1.
*
np
.
cos
(
np
.
pi
/
6.
) \
-
env
.
config
[
"mp"
]
*
env
.
config
[
"l"
]
*
(
1.
**
2
) \
*
np
.
cos
(
np
.
pi
/
6.
)
*
np
.
sin
(
np
.
pi
/
6.
) \
-
(
env
.
config
[
"mp"
]
+
env
.
config
[
"mc"
])
*
env
.
config
[
"g"
] \
*
np
.
sin
(
np
.
pi
/
6.
)) \
/
(
env
.
config
[
"l"
] \
*
(
env
.
config
[
"mc"
] \
+
env
.
config
[
"mp"
]
*
np
.
sin
(
np
.
pi
/
6.
)
**
2
))
expected
=
np
.
array
([
d_x0
,
d_x1
,
d_x2
,
d_x3
])
*
env
.
config
[
"dt"
] \
+
curr_x
assert
next_x
==
pytest
.
approx
(
expected
,
abs
=
1e-5
)
def
test_bound_step
(
self
):
env
=
CartPoleEnv
()
curr_x
=
np
.
ones
(
4
)
curr_x
[
2
]
=
np
.
pi
/
6.
env
.
reset
(
init_x
=
curr_x
)
u
=
np
.
ones
(
1
)
*
1e3
next_x
,
_
,
_
,
_
=
env
.
step
(
u
)
u
=
env
.
config
[
"input_upper_bound"
][
0
]
d_x0
=
curr_x
[
1
]
d_x1
=
(
u
+
env
.
config
[
"mp"
]
*
np
.
sin
(
np
.
pi
/
6.
) \
*
(
env
.
config
[
"l"
]
*
(
1.
**
2
) \
+
env
.
config
[
"g"
]
*
np
.
cos
(
np
.
pi
/
6.
))) \
/
(
env
.
config
[
"mc"
]
+
env
.
config
[
"mp"
]
*
np
.
sin
(
np
.
pi
/
6.
)
**
2
)
d_x2
=
curr_x
[
3
]
d_x3
=
(
-
u
*
np
.
cos
(
np
.
pi
/
6.
) \
-
env
.
config
[
"mp"
]
*
env
.
config
[
"l"
]
*
(
1.
**
2
) \
*
np
.
cos
(
np
.
pi
/
6.
)
*
np
.
sin
(
np
.
pi
/
6.
) \
-
(
env
.
config
[
"mp"
]
+
env
.
config
[
"mc"
])
*
env
.
config
[
"g"
] \
*
np
.
sin
(
np
.
pi
/
6.
)) \
/
(
env
.
config
[
"l"
] \
*
(
env
.
config
[
"mc"
] \
+
env
.
config
[
"mp"
]
*
np
.
sin
(
np
.
pi
/
6.
)
**
2
))
expected
=
np
.
array
([
d_x0
,
d_x1
,
d_x2
,
d_x3
])
*
env
.
config
[
"dt"
] \
+
curr_x
assert
next_x
==
pytest
.
approx
(
expected
,
abs
=
1e-5
)
Back
|
FazBrowse Home
|
New Git URL