-
Notifications
You must be signed in to change notification settings - Fork 377
/
Copy pathbasic_control.py
144 lines (119 loc) · 4.16 KB
/
basic_control.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env python
# Copyright (c) 2020 Intel Corporation
#
# This work is licensed under the terms of the MIT license.
# For a copy, see <https://opensource.org/licenses/MIT>.
"""
This module provides the base class for user-defined actor
controllers. All user-defined controls must be derived from
this class.
A user must not modify the module.
"""
class BasicControl(object):
"""
This class is the base class for user-defined actor controllers
All user-defined agents must be derived from this class.
Args:
actor (carla.Actor): Actor that should be controlled by the controller.
Attributes:
_actor (carla.Actor): Controlled actor.
Defaults to None.
_target_speed (float): Logitudinal target speed of the controller.
Defaults to 0.
_init_speed (float): Initial longitudinal speed of the controller.
Defaults to 0.
_waypoints (list of carla.Transform): List of target waypoints the actor
should travel along. A waypoint here is of type carla.Transform!
Defaults to [].
_waypoints_updated (boolean):
Defaults to False.
_reached_goal (boolean):
Defaults to False.
_use_lon_control (boolean):
Use longitudinal component of controller
Defaults to True
_use_lat_control (boolean):
Use lateral component of controller
Defaults to True
"""
_actor = None
_waypoints = []
_waypoints_updated = False
_offset = 0
_offset_updated = False
_target_speed = 0
_reached_goal = False
_init_speed = False
_use_lon_control = True
_use_lat_control = True
def __init__(self, actor):
"""
Initialize the actor
"""
self._actor = actor
def update_target_speed(self, speed):
"""
Update the actor's target speed and set _init_speed to False.
Args:
speed (float): New target speed [m/s].
"""
self._target_speed = speed
self._init_speed = False
def update_waypoints(self, waypoints, start_time=None):
"""
Update the actor's waypoints
Args:
waypoints (List of carla.Transform): List of new waypoints.
"""
self._waypoints = waypoints
self._waypoints_updated = True
def update_offset(self, offset, start_time=None):
"""
Update the actor's waypoints
Args:
waypoints (List of carla.Transform): List of new waypoints.
"""
self._offset = offset
self._offset_updated = True
def set_init_speed(self):
"""
Set _init_speed to True
"""
self._init_speed = True
def change_lon_control(self, enable):
"""
Enable/Disable longitudinal control component
Args:
enable (boolean): Enable/Disable signal
"""
self._use_lon_control = enable
def change_lat_control(self, enable):
"""
Enable/Disable lateral control component
Args:
enable (boolean): Enable/Disable signal
"""
self._use_lat_control = enable
def check_reached_waypoint_goal(self):
"""
Check if the actor reached the end of the waypoint list
returns:
True if the end was reached, False otherwise.
"""
return self._reached_goal
def reset(self):
"""
Pure virtual function to reset the controller. This should be implemented
in the user-defined agent implementation.
"""
raise NotImplementedError(
"This function must be re-implemented by the user-defined actor control."
"If this error becomes visible the class hierarchy is somehow broken")
def run_step(self):
"""
Pure virtual function to run one step of the controllers's control loop.
This should be implemented in the user-defined agent implementation.
"""
raise NotImplementedError(
"This function must be re-implemented by the user-defined actor control."
"If this error becomes visible the class hierarchy is somehow broken")