-
Notifications
You must be signed in to change notification settings - Fork 1
/
Preprocessing.py
60 lines (44 loc) · 1.53 KB
/
Preprocessing.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
import torch
import numpy as np
class Preprocessing:
def __init__(self, observation, delta=0.01):
self.observation = np.concatenate((observation, np.zeros(14)), axis=0)
self.delta = delta
def calcDeriv(self, p, n):
return (n - p) / self.delta
def GetState(self, obs):
#rot, x, y psn
pelvis = obs[0:3]
# velocity rot, x, y
pelvisV = obs[3:6]
# convert to "relative"
rotAnkle = obs[6:8] - pelvis[0]
rotKnee = obs[8:10] - pelvis[0]
rotHip = obs[10:12] - pelvis[0]
angV = obs[12:18] - pelvisV[0]
psnCenterMass = obs[18:20] - pelvis[1:3]
vCenterMass = obs[20:22] - pelvisV[1:3]
psnOtherParts = obs[22:36] - np.repeat(pelvis[1:3], 7)
vOtherParts = self.calcDeriv(self.observation[22:36], psnOtherParts)
psoasStrength = obs[36:38]
obstacles = obs[38:40] - pelvis[1:3]
self.observation = np.concatenate((
pelvis,
pelvisV,
rotAnkle,
rotKnee,
rotHip,
angV,
psnCenterMass,
vCenterMass,
psnOtherParts,
vOtherParts,
psoasStrength,
obstacles), 0)
return self.observation
def ConvertToTensor(self,s,a,r,sp):
s = torch.from_numpy(s).float()
a = torch.from_numpy(a).float()
r = torch.Tensor([r]).float()
sp = torch.from_numpy(sp).float()
return s,a,r,sp