-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathhelper.py
80 lines (62 loc) · 2 KB
/
helper.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
import numpy
import gym_line_follower
import gym
import time
import pybullet as p
import pybullet_data
class LaRoboLigaEnv(gym.Env):
def __init__(self,descr_mode=False):
if descr_mode:
return
self.env = gym.make("LineFollower-v0")
_, self.path = self.env.reset()
def get_full_path(self):
"""
Function Description:
Returns the full path of the environment
Arguments:
None
Returns:
path: list of tuples containing the coordinates of the path
NOTE: The path is returned in the format [(x1, y1), (x2, y2), ...]
"""
return self.path
def reset(self):
"""
Function Description:
Resets the path and the husky to the starting position
Arguments:
None
Returns:
None
NOTE: A new path is generated every time the environment is reset
"""
_, self.path = self.env.reset()
def set_velocity(self, array):
"""
Function Description:
Sets the velocity of the husky
Arguments:
array: array of length 2
array[0] = linear velocity of left front and rear motors
array[1] = linear velocity of right front and rear motors
Returns:
None
"""
self.observation, self.reward, self.done, self.info = self.env.step(
array)
def get_position(self):
"""
Function Description:
Returns the current position of the husky in the environment
Arguments:
None
Returns:
pos: dictionary containing the position of the husky
pos['x'] = x coordinate of the husky
pos['y'] = y coordinate of the husky
pos['yaw'] = yaw of the husky
"""
self.observation, self.reward, self.done, self.info = self.env.step([0,0])
position = self.info
return position