-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathantNumericWalk.py
125 lines (97 loc) · 3.01 KB
/
antNumericWalk.py
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import gym
from gym import envs
env = gym.make('Ant-v3')#to test different models change "CartPole-V0" to different models
env.reset()
#print('Initial state: ',env.reset())
#
#print('State space: ',env.observation_space)
#
#print('Action space: ',env.action_space)
#
#print('observation low: ',env.observation_space.low)
#
#print('observation high: ',env.observation_space.high)
#
#maxHeight = 0
#
#minHeight= 1
def quadraticMotion(t): #input 0-1000, get -1 at 0 to 1 at 500 to -1 at 1000
posicion = -0.000008*t*t + 0.008*t-1
return posicion
def linearMotion(t): #input 0-1000, get 0 at 0 to 1 at 1000
position = 0.001*t
return position
for x in range(6000):
env.render()
paso = env.action_space.sample()
#print(paso)
initialStill = 1500
forwardRight = initialStill+1000
forwardLeft = forwardRight+1000
pushOnGround = forwardLeft+1000
rowYourLegs = pushOnGround+1000
if x < initialStill: #move to neutral position
posHip2 = 0
posAnkle2 = -40*linearMotion(x*2/3)
posHip4 = 0
posAnkle4 = 40 *linearMotion(x*2/3)
posAnkle3 = -40*linearMotion(x*2/3)
posAnkle1 = 40*linearMotion(x*2/3)
elif x < forwardRight:
posHip2 = 0
posAnkle2 = -40
posHip4 = 30*linearMotion(x-initialStill)
posAnkle4 = 35-5*quadraticMotion(x-initialStill)
posAnkle3 = -40
posAnkle1 = 40
elif x < forwardLeft:
posHip2 = -30*linearMotion(x-forwardRight)
posAnkle2 = -35+5*quadraticMotion(x-forwardRight)
posHip4 = 30
posAnkle4 = 40
posAnkle3 = -40
posAnkle1 = 40
elif x < pushOnGround:
posHip2 = -30
posAnkle2 = -30*linearMotion(x-forwardLeft)-40
posHip4 = 30
posAnkle4 = 30*linearMotion(x-forwardLeft)+40
posAnkle3 = -40
posAnkle1 = 40
elif x < rowYourLegs: #merrily
posHip2 = 30*linearMotion(x-pushOnGround)-30
posAnkle2 = -70
posHip4 = -30*linearMotion(x-pushOnGround)+30
posAnkle4 = 70
posAnkle3 = -40
posAnkle1 = 40
else: #return to neutral position
posHip2 = 0
posAnkle2 = -70 + 30*linearMotion(x-rowYourLegs)
posHip4 = 0
posAnkle4 = 70 - 30*linearMotion(x-rowYourLegs)
posAnkle3 = -40
posAnkle1 = 40
state = env.data.qpos
centerMass = env.data.subtree_com
print(centerMass)
# inertiaMatrix = mj.data.qm
# print(inertiaMatrix)
# print(pos)
# print(sum([state[3],state[4],state[5]]))
# if minHeight > state[2]:
# minHeight = state[2]
#
# if maxHeight < state[2] and x > 350:
# maxHeight = state[2]
paso = [posHip4,posAnkle4,0,posAnkle1,posHip2,posAnkle2,0,posAnkle3]
# paso =[20]*8
env.step(paso) # take a random action
#print('Min height: ',minHeight)
#print('Max height: ',maxHeight)
env.close()