-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbosh_env.py
39 lines (32 loc) · 998 Bytes
/
bosh_env.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
import numpy as np
import math
from collections import deque
from steering_python import SteeringPython
import time
class Environment:
def __init__(self):
self.sp = SteeringPython()
self.sp.set_freq(1)
self.last_dir = None
self.busy = False
self.last_poll = 0
self.stopped = False
def step(self, action, done):
if not self.busy:
if -1 < action < 1:
self.sp.set_freq(action)
if self.last_dir is None:
if action == 1:
self.sp.right()
self.last_dir=1
elif action == -1:
self.sp.left()
self.last_dir=-1
if done and not self.stopped:
self.stopped = True
self.sp.stop()
self.last_poll = time.time()
self.busy = True
else:
if time.time()-self.last_poll > 0.2:
self.busy = False