-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvironment.py
64 lines (49 loc) · 1.25 KB
/
environment.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
import vrep_env
import time
class Env:
def __init__(self):
self.env = vrep_env.Environment()
def step(self, action):
# set velocity of left and right motor
v=0.5 #forward velocity
# can make this part more accurate
kp=0.5 #steering gain
steer = 0.5
if action == 0: #FORWARD
vl = v
vr = v
elif action == 1: #LEFT
vl=v-kp*steer
vr=v+kp*steer
elif action == 2: #RIGHT
vl=v+kp*steer
vr=v-kp*steer
#Set velocity of robot
self.env.set_vel(vl,vr)
#Get observation from sensors/images
ob,done = self.env.get_observation()
reward = 0.1 if action == 0 else 0.02 # action 0 is forward, other actions are left and right
return ob, reward, done, {}
def reset(self):
self.env.stop()
self.env.load_scene()
self.env.init_sensors()
self.env.start()
self.env.set_vel(0,0)
time.sleep(1.5)
# env.pause()
#env.remove_bot()
return self.env.get_observation()
def render(self, mode='human', close=False):
# write code to turf off display from code, google , there is a paramter for this
pass
def take_action(self, action):
pass
def get_reward(self):
""" Reward is given for XY. """
if self.status == FOOBAR:
return 1
elif self.status == ABC:
return self.somestate ** 2
else:
return 0