16
16
class Turn (object ):
17
17
"""This generates a turn that is always starting from angle 0, turning to an angle _delta"""
18
18
19
- def __init__ (self , _params , _delta , _dir ):
19
+ def __init__ (self , _params , _delta ):
20
20
"""
21
21
Parameters
22
22
----------
23
23
_params : TurnParams
24
24
_delta : float
25
- Deflection of th Turn
25
+ Deflection of th Turn; positive = left turn, negative = right turn
26
26
_dir : int
27
27
1 for left turn, -1 for right turn
28
28
"""
29
29
30
30
self .params = _params
31
- self .delta = _delta
32
- self .dir = _dir
31
+ self .delta = math .fabs (_delta )
32
+ self .dir = 1
33
+ if _delta < 0 :
34
+ self .dir = - 1
33
35
34
- assert (_delta > _params .delta_min )
35
- assert (_delta < 2 * math .pi )
36
+ assert (self . delta > _params .delta_min )
37
+ assert (self . delta < 2 * math .pi )
36
38
37
39
def state (self , s ):
38
40
"""
@@ -62,27 +64,27 @@ def state(self, s):
62
64
theta = np .empty (len (s ))
63
65
kappa = np .empty (len (s ))
64
66
65
- first_clotho = self .state_clothoid_first (s [first_clotho_cond ])
67
+ first_clotho = self ._state_clothoid_first (s [first_clotho_cond ])
66
68
x [first_clotho_cond ] = first_clotho .x
67
69
y [first_clotho_cond ] = first_clotho .y
68
70
theta [first_clotho_cond ] = first_clotho .theta
69
71
kappa [first_clotho_cond ] = first_clotho .kappa
70
72
71
- circ_seg = self .state_circular (s [circ_seg_cond ])
73
+ circ_seg = self ._state_circular (s [circ_seg_cond ])
72
74
x [circ_seg_cond ] = circ_seg .x
73
75
y [circ_seg_cond ] = circ_seg .y
74
76
theta [circ_seg_cond ] = circ_seg .theta
75
77
kappa [circ_seg_cond ] = circ_seg .kappa
76
78
77
- second_clotho = self .state_clothoid_second (s [second_clotho_cond ])
79
+ second_clotho = self ._state_clothoid_second (s [second_clotho_cond ])
78
80
x [second_clotho_cond ] = second_clotho .x
79
81
y [second_clotho_cond ] = second_clotho .y
80
82
theta [second_clotho_cond ] = second_clotho .theta
81
83
kappa [second_clotho_cond ] = second_clotho .kappa
82
84
83
- return State (x , y , theta , kappa )
85
+ return State (x , self . dir * y , self . dir * theta , self . dir * kappa )
84
86
85
- def state_circular (self , s ):
87
+ def _state_circular (self , s ):
86
88
# TODO: Fix the two-clothoids-only case:
87
89
assert (self .delta > self .params .delta_min )
88
90
@@ -98,8 +100,9 @@ def state_circular(self, s):
98
100
99
101
return State (x , y , angles , kappa )
100
102
101
- def state_clothoid_first (self , s ):
102
- """
103
+ def _state_clothoid_first (self , s ):
104
+ """ left turn, first clothoid segment
105
+
103
106
Parameters
104
107
----------
105
108
s : np.array
@@ -121,7 +124,7 @@ def state_clothoid_first(self, s):
121
124
122
125
return State (scale * ssa_csa [1 ], scale * ssa_csa [0 ], theta , kappa )
123
126
124
- def state_clothoid_second (self , s ):
127
+ def _state_clothoid_second (self , s ):
125
128
"""
126
129
Parameters
127
130
----------
@@ -145,10 +148,9 @@ def state_clothoid_second(self, s):
145
148
kappa = inv_clothoid_s / self .params .len_clothoid_part * self .params .kappa_max
146
149
147
150
state = State (- scale * ssa_csa [1 ], scale * ssa_csa [0 ], theta , kappa )
148
- state = state .rotate_then_translate (self .delta , self .state_qg .x , self .state_qg .y )
151
+ state = state .rotate_then_translate (self .delta , self ._state_qg .x , self ._state_qg .y )
149
152
return state
150
153
151
-
152
154
@cached_property
153
155
def len (self ):
154
156
return self .len_of_circular_part + 2 * self .params .len_clothoid_part
@@ -165,8 +167,17 @@ def len_of_circular_part(self):
165
167
return 2 * math .pi * self .params .inner_rad * angular_fraction
166
168
167
169
@cached_property
168
- def state_qj (self ):
169
- """Where the inner circle segment intersects the second clothoid"""
170
+ def state_qi (self ):
171
+ """Where the first clothoid intersects the inner circle (l/r-turn)"""
172
+ st = self .params .state_qi
173
+ st .y *= self .dir
174
+ st .theta *= self .dir
175
+ st .kappa *= self .dir
176
+ return st
177
+
178
+ @cached_property
179
+ def _state_qj (self ):
180
+ """Where the inner circle segment intersects the second clothoid (left-turn)"""
170
181
171
182
ang = self .delta - self .params .delta_min / 2
172
183
x = self .params .omega [0 ] + self .params .inner_rad * np .sin (ang )
@@ -175,11 +186,30 @@ def state_qj(self):
175
186
176
187
return State (x , y , ang , kappa )
177
188
189
+ @cached_property
190
+ def state_qj (self ):
191
+ """Where the inner circle segment intersects the second clothoid (l/r-turn)"""
192
+ st = self ._state_qj
193
+ st .y *= self .dir
194
+ st .theta *= self .dir
195
+ st .kappa *= self .dir
196
+ return st
197
+
178
198
@cached_property
179
199
def state_qg (self ):
180
- """The end of the second clothoid"""
200
+ """The end of the second clothoid (turn left | right for dir=1 | -1)"""
201
+ st = self ._state_qg
202
+ st .y *= self .dir
203
+ st .theta *= self .dir
204
+ st .kappa *= self .dir
205
+ return st
206
+
207
+ @cached_property
208
+ def _state_qg (self ):
209
+ """The end of the second clothoid (left-turn)"""
181
210
182
211
st = State (- self .params .omega [0 ], - self .params .omega [1 ], self .delta , 0 )
183
- st = st .rotate_then_translate (self .delta + 2 * self .params .gamma , self .params .omega [0 ], self .params .omega [1 ])
212
+ st = st .rotate_then_translate (self .delta + 2 * self .params .gamma , self .params .omega [0 ], self .params .omega [1 ])
184
213
185
214
return st
215
+
0 commit comments