@@ -81,9 +81,10 @@ def connect_state(self, state_0: state, state_next: state):
8181 """
8282 if state_0 is None or state_next is None :
8383 return velocity (0 , 0 , 0 , 0 )
84+
8485 travel_direction = np .subtract (
8586 state_next .state_position .get_vec (withExtrusion = True ), state_0 .state_position .get_vec (withExtrusion = True )
86- ) # outdated todo
87+ ) # outdated todo: subtract positions directly
8788 t_distance = np .linalg .norm (travel_direction [:3 ])
8889 e_len = travel_direction [3 ]
8990 if abs (t_distance ) > 0 : # regular travel mixed move
@@ -131,7 +132,7 @@ def trapez(extrusion_only=False):
131132 segment_A = segment (
132133 t_begin = t0 , t_end = t1 , pos_begin = pos_begin , pos_end = pos_end , vel_begin = vel_begin , vel_end = vel_end
133134 )
134- if pos_end .is_travel (pos_begin ) or pos_end .is_extruding (pos_begin ):
135+ if pos_end .is_travel (pos_begin ) or pos_end .is_extruding (pos_begin , ignore_retract = False ):
135136 self .segments .append (segment_A )
136137 # B --
137138 travel_const = distance - travel_ramp_down - travel_ramp_up
@@ -144,7 +145,7 @@ def trapez(extrusion_only=False):
144145 segment_B = segment (
145146 t_begin = t1 , t_end = t2 , pos_begin = pos_begin , vel_begin = vel_begin , pos_end = pos_end , vel_end = vel_end
146147 )
147- if pos_end .is_travel (pos_begin ) or pos_end .is_extruding (pos_begin ):
148+ if pos_end .is_travel (pos_begin ) or pos_end .is_extruding (pos_begin , ignore_retract = False ):
148149 self .segments .append (segment_B )
149150 # C \
150151 t2 = segment_B .t_end
@@ -156,7 +157,7 @@ def trapez(extrusion_only=False):
156157 segment_C = segment (
157158 t_begin = t2 , t_end = t3 , pos_begin = pos_begin , pos_end = pos_end , vel_begin = vel_begin , vel_end = vel_end
158159 )
159- if pos_end .is_travel (pos_begin ) or pos_end .is_extruding (pos_begin ):
160+ if pos_end .is_travel (pos_begin ) or pos_end .is_extruding (pos_begin , ignore_retract = False ):
160161 self .segments .append (segment_C )
161162
162163 self .blcktype = "trapez"
@@ -173,7 +174,7 @@ def triang(extrusion_only=False):
173174 segment_A = segment (
174175 t_begin = t0 , t_end = t1 , pos_begin = pos_begin , pos_end = pos_end , vel_begin = vel_begin , vel_end = vel_end
175176 )
176- if pos_end .is_travel (pos_begin ) or pos_end .is_extruding (pos_begin ):
177+ if pos_end .is_travel (pos_begin ) or pos_end .is_extruding (pos_begin , ignore_retract = False ):
177178 self .segments .append (segment_A )
178179 # C \
179180 t2 = segment_A .t_end
@@ -186,7 +187,7 @@ def triang(extrusion_only=False):
186187 segment_C = segment (
187188 t_begin = t2 , t_end = t3 , pos_begin = pos_begin , pos_end = pos_end , vel_begin = vel_begin , vel_end = vel_end
188189 )
189- if pos_end .is_travel (pos_begin ) or pos_end .is_extruding (pos_begin ):
190+ if pos_end .is_travel (pos_begin ) or pos_end .is_extruding (pos_begin , ignore_retract = False ):
190191 self .segments .append (segment_C )
191192
192193 self .blcktype = "triangle"
@@ -203,7 +204,7 @@ def singl_up():
203204 segment_A = segment (
204205 t_begin = t0 , t_end = t1 , pos_begin = pos_begin , pos_end = pos_end , vel_begin = vel_begin , vel_end = vel_end
205206 )
206- if pos_end .is_travel (pos_begin ) or pos_end .is_extruding (pos_begin ):
207+ if pos_end .is_travel (pos_begin ) or pos_end .is_extruding (pos_begin , ignore_retract = False ):
207208 self .segments .append (segment_A )
208209
209210 self .blcktype = "single"
@@ -220,7 +221,7 @@ def singl_dwn():
220221 segment_C = segment (
221222 t_begin = t0 , t_end = t1 , pos_begin = pos_begin , pos_end = pos_end , vel_begin = vel_begin , vel_end = vel_end
222223 )
223- if pos_end .is_travel (pos_begin ) or pos_end .is_extruding (pos_begin ):
224+ if pos_end .is_travel (pos_begin ) or pos_end .is_extruding (pos_begin , ignore_retract = False ):
224225 self .segments .append (segment_C )
225226
226227 self .blcktype = "single"
@@ -258,20 +259,26 @@ def singl_dwn():
258259 v_end_sing_sqr = v_begin * v_begin - 2 * acc * distance
259260 else :
260261 v_end_sing_sqr = v_begin * v_begin + 2 * acc * distance
261- v_end_sing = np .sqrt (v_end_sing_sqr ) if v_end_sing_sqr >= 0 else None
262+ v_end_sing = (
263+ np .sqrt (v_end_sing_sqr ) if v_end_sing_sqr >= 0 else 0
264+ ) # (todo: verify set to zero, otherwise None is safer)
262265 v_begin_sing = np .sqrt (2 * acc * distance + v_end * v_end )
263266
264267 # select case for planner block and calculate segment vertices
265- if (travel_ramp_down + travel_ramp_up ) < distance :
266- trapez (extrusion_only = extrusion_only )
267- elif v_peak_tri > v_end and v_peak_tri > v_begin :
268- triang ()
269- elif v_end_sing > v_begin :
270- singl_up ()
271- elif v_end_sing < v_begin :
272- singl_dwn ()
273- else :
274- raise NameError ("Segment could not be modeled." )
268+ try :
269+ if (travel_ramp_down + travel_ramp_up ) < distance :
270+ trapez (extrusion_only = extrusion_only )
271+ elif v_peak_tri > v_end and v_peak_tri > v_begin :
272+ triang (extrusion_only = extrusion_only )
273+ elif v_end_sing > v_begin :
274+ singl_up ()
275+ elif v_end_sing < v_begin :
276+ singl_dwn ()
277+ else :
278+ raise NameError ("Segment could not be modeled." )
279+ except TypeError :
280+ print (f"Segment after { self .prev_blck .segments [- 1 ].t_end } could not be modeled.\n " + str (self .state_B ))
281+ print (f"v-begin: { v_begin } / v-end { v_end } " )
275282
276283 def self_correction (self , tolerance = float ("1e-12" )):
277284 """Check for interfacing vel and self correct."""
@@ -347,6 +354,7 @@ def __init__(self, state: state, prev_blck: "planner_block"):
347354 self .state_B = state # to state B
348355 self .prev_blck = prev_blck # nb list prev
349356 self .next_blck = None # nb list next
357+ self .is_extruding = False # default Value
350358
351359 self .segments : List [segment ] = [] # store segments here
352360 self .blcktype = None
0 commit comments