-
Notifications
You must be signed in to change notification settings - Fork 0
/
robot.py
46 lines (35 loc) · 1.13 KB
/
robot.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
import numpy as np
from math import ceil
import time
import threading
class Robot:
def __init__(self, dynamics):
self.dynamics = dynamics
self.state = np.zeros((dynamics.get_state_dim(), 1))
self.action = np.zeros((dynamics.get_action_dim(), 1))
self.t = 0
self.goal = None
def set_action(self, action):
self.action = action
def get_action(self):
return self.action
def set_state(self, state):
# first half is joint position, second half is joint velocity
self.state = state
def advance(self):
state = self.state.copy()
state = self.dynamics.advance(state, self.action)
self.state = state
self.t += self.dynamics.dt
def get_t(self):
return self.t
def get_state(self):
return self.state.copy()
def set_t(self, t):
self.t = t
def reset(self):
state = np.zeros((self.dynamics.get_state_dim(), 1)) # position + velocity
state[0] = -np.pi / 2.0
self.set_state(state)
self.set_action(np.zeros((self.dynamics.get_action_dim(), 1)))
self.set_t(0)