prinThor 0.0.3

The highly reliable but not necessarily functional 3D Printer firmware
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
//! This feature is being stabilized
use crate::hwa;
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
use embassy_sync::mutex::Mutex;
use printhor_hwa_common::{DeferChannelRef, EventBusRef, EventFlags, EventStatus};
use printhor_hwa_common::{DeferEvent, DeferType};
use crate::control::GCode;
use crate::control::planner::{Constraints, SCurveMotionProfile, CodeExecutionSuccess, CodeExecutionFailure};
use crate::math::{ONE_HUNDRED, Real, ZERO};
use crate::sync::config::Config;
use crate::tgeo::TVector;
use crate::tgeo::CoordSel;

use crate::hwa::controllers::motion::motion_segment::{Segment, SegmentData};

/// The maximum number of movements that can be queued. Warning! each one takes too memory as of now
const SEGMENT_QUEUE_SIZE: u8 = 4;

pub enum ScheduledMove {
    Move(SegmentData, SCurveMotionProfile),
    Homing,
    Dwell,
}

/////
#[allow(unused)]
pub struct MotionConfig {
    pub(crate) microsteps: TVector<u8>,
    pub(crate) max_accel: TVector<u16>,
    pub(crate) max_speed: TVector<u16>,
    pub(crate) max_jerk: TVector<u32>,
    pub(crate) default_travel_speed: u16,
    pub(crate) flow_rate: u8,
    pub(crate) speed_rate: u8,
}

impl MotionConfig {
    pub(crate) const fn new() -> Self {
        Self {
            microsteps: TVector::new(),
            max_accel: TVector::new(),
            max_speed: TVector::new(),
            max_jerk: TVector::new(),
            default_travel_speed: 1,
            flow_rate: 100,
            speed_rate: 100,
        }
    }
}

pub struct MotionStatus {
    #[allow(unused)]
    pub(crate) current_pos_steps: Option<TVector<u32>>,
    pub(crate) last_planned_pos: Option<TVector<Real>>,
    pub(crate) absolute_positioning: bool,
}

impl MotionStatus {
    pub const fn new() -> Self {
        Self {
            current_pos_steps: None,
            last_planned_pos: None,
            absolute_positioning: true,
        }
    }
}


#[allow(unused)]
pub struct MotionPlanner {
    pub event_bus: EventBusRef,
    // The channel to send deferred events
    pub defer_channel: printhor_hwa_common::DeferChannelRef,

    pub(self) ringbuffer: Mutex<CriticalSectionRawMutex, RingBuffer>,
    pub(self) move_planned: Config<CriticalSectionRawMutex, bool>,
    pub(self) available: Config<CriticalSectionRawMutex, bool>,
    pub(self) motion_cfg: Mutex<CriticalSectionRawMutex, MotionConfig>,
    pub(self) motion_st: Mutex<CriticalSectionRawMutex, MotionStatus>,
    pub motion_driver: Mutex<CriticalSectionRawMutex, hwa::drivers::MotionDriver>,
}

#[allow(unused)]
impl MotionPlanner {
    pub const fn new(event_bus: EventBusRef, defer_channel: DeferChannelRef, motion_driver: hwa::drivers::MotionDriver) -> Self {
        Self {
            event_bus,
            defer_channel,
            ringbuffer: Mutex::new(RingBuffer::new()),
            move_planned: Config::new(),
            available: Config::new(),
            motion_cfg: Mutex::new(MotionConfig::new()),
            motion_st: Mutex::new(MotionStatus::new()),
            motion_driver: Mutex::new(motion_driver),
        }
    }

    pub async fn start(&self) {
        self.move_planned.reset();
        self.available.signal(true);
        self.event_bus.publish_event(EventStatus::containing(EventFlags::MOV_QUEUE_EMPTY)).await;
    }

    pub async fn get_current_segment_data(&self) -> Option<Segment> {
        loop {
            let _ = self.move_planned.wait().await;
            let mut do_dwell = false;
            {
                let mut rb = self.ringbuffer.lock().await;
                let head = rb.head as usize;
                match rb.data[head] {
                    PlanEntry::Empty => {
                        self.move_planned.reset();
                    },
                    PlanEntry::Dwell => {
                        rb.data[head] = PlanEntry::Executing(MovType::Dwell);
                        do_dwell = true;
                    },
                    PlanEntry::PlannedMove(planned_data) => {
                        hwa::debug!("Exec starting: {} / {} h={}", rb.used, SEGMENT_QUEUE_SIZE, head);
                        rb.data[head] = PlanEntry::Executing(MovType::Move);
                        return Some(planned_data);
                    },
                    PlanEntry::Homing => {
                        self.event_bus.publish_event(EventStatus::containing(EventFlags::HOMMING)).await;
                        rb.data[head] = PlanEntry::Executing(MovType::Homing);
                        return None;
                    },
                    PlanEntry::Executing(_) => {
                        self.move_planned.reset();
                        hwa::error!("Unexpected error");
                    },
                }
            }
            if do_dwell {
                self.consume_current_segment_data().await;
            }
        }
    }

    pub async fn consume_current_segment_data(&self) {

        let mut rb = self.ringbuffer.lock().await;
        let head = rb.head;
        hwa::debug!("Movement completed @rq[{}] (ongoing={})", head, rb.used - 1);
        match & rb.data[head as usize] {
            PlanEntry::Executing(MovType::Homing) => {
                self.event_bus.publish_event(EventStatus::not_containing(EventFlags::HOMMING)).await;
                self.defer_channel.send(DeferEvent::Homing(DeferType::Completed)).await;
            }
            PlanEntry::Executing(MovType::Dwell) => {
                self.defer_channel.send(DeferEvent::Dwell(DeferType::Completed)).await;
            }
            PlanEntry::Executing(MovType::Move) => {
            }
            _ => {
                panic!("cound not happen")
            }
        }
        rb.data[head as usize] = PlanEntry::Empty;
        rb.head = match head + 1 < SEGMENT_QUEUE_SIZE {
            true => head + 1,
            false => 0u8,
        };
        rb.used -= 1;
        hwa::debug!("- used={}, h={} ", rb.used, head);
        if rb.used == 0 {
            self.event_bus.publish_event(EventStatus::containing(EventFlags::MOV_QUEUE_EMPTY)).await;
        }
        self.available.signal(true);
    }

    pub async fn schedule_raw_move(&self, move_type: ScheduledMove, blocking: bool) -> Result<CodeExecutionSuccess, CodeExecutionFailure> {

        loop {
            self.available.wait().await;
            {
                let mut rb = self.ringbuffer.lock().await;

                let mut must_defer = true;

                if rb.used < (SEGMENT_QUEUE_SIZE as u8) {
                    let used = rb.used;
                    let head = rb.head;
                    let mut could_replan = false;

                    let (entry, event) = match move_type {
                        ScheduledMove::Move(segment_data, motion_profile) => {
                            could_replan = true;
                            must_defer = false;
                            self.update_last_planned_pos(&segment_data.dest_pos).await;
                            (PlanEntry::PlannedMove(Segment::new(segment_data, motion_profile)), EventStatus::new())
                        }
                        ScheduledMove::Homing => {
                            self.set_last_planned_pos(&TVector::zero()).await;
                            (PlanEntry::Homing, EventStatus::not_containing(EventFlags::HOMMING))
                        }
                        ScheduledMove::Dwell => {
                            (PlanEntry::Dwell, EventStatus::containing(EventFlags::MOV_QUEUE_EMPTY))
                        }
                    };

                    let index = head as u16 + used as u16;

                    let index = match index < SEGMENT_QUEUE_SIZE as u16 {
                        true => index,
                        false => index - SEGMENT_QUEUE_SIZE as u16,
                    } as u8;

                    rb.data[index as usize] = entry;

                    hwa::debug!("Mov queued @{} ({} / {})", index, rb.used + 1, SEGMENT_QUEUE_SIZE);
                    if could_replan && used > 0 {
                        let last_inserted_idx = rb.head as u16 + rb.used as u16 - 1;
                        let last_inserted_idx = match last_inserted_idx < (SEGMENT_QUEUE_SIZE as u16) {
                            true => last_inserted_idx,
                            false => 0,
                        };
                        hwa::debug!(" - check_replan {}", last_inserted_idx);
                        let current_slot = &mut rb.data[last_inserted_idx as usize];
                        match current_slot {
                            PlanEntry::Executing(_) | PlanEntry::Homing | PlanEntry::Empty => {
                                hwa::debug!(" -- not chained")
                            }
                            PlanEntry::PlannedMove(old_data) => {
                                old_data.motion_profile.recalculate();
                                hwa::debug!(" -- chained")
                            }
                            _ => {
                                unreachable!("Could not happen");
                            }
                        }
                    }
                    rb.used += 1;
                    self.event_bus.publish_event(EventStatus::not_containing(EventFlags::MOV_QUEUE_EMPTY)).await;
                    self.move_planned.signal(true);
                    if must_defer || (rb.used == (SEGMENT_QUEUE_SIZE as u8)) {
                        // Shall wait for one deallocation in order to enqueue more
                        return Ok(CodeExecutionSuccess::DEFERRED(event))
                    }
                    else {
                        return Ok(CodeExecutionSuccess::QUEUED)
                    }

                } else {
                    self.available.reset();
                    if !blocking {
                        hwa::warn!("Mov rejected: {} / {} h={}", rb.used, SEGMENT_QUEUE_SIZE, rb.head);
                        return Err(CodeExecutionFailure::BUSY)
                    }
                }
            }
        }
    }

    pub fn motion_cfg(&self) -> &'_ Mutex<CriticalSectionRawMutex,MotionConfig> {
        &self.motion_cfg
    }

    pub async fn set_absolute_positioning(&self, absolute_is_set: bool) {
        let mut st = self.motion_st.lock().await;
        st.absolute_positioning = absolute_is_set;
    }

    pub async fn is_absolute_positioning(&self) -> bool {
        self.motion_st.lock().await.absolute_positioning
    }

    pub async fn get_last_planned_pos(&self) -> Option<TVector<Real>> {
        self.motion_st.lock().await.last_planned_pos.clone()
    }
    pub async fn set_last_planned_pos(&self, pos: &TVector<Real>) {
        self.motion_st.lock().await.last_planned_pos.replace(pos.map_nan(Real::zero()));
    }

    /***
    Update last planned position. E is always ignored (So far, only relative E moves are implemented)
     */
    pub async fn update_last_planned_pos(&self, updated_position_coords: &TVector<Real>) {
        let mut stg = self.motion_st.lock().await;
        if let Some(last_position) = &mut stg.last_planned_pos {
            last_position.assign_if_set(CoordSel::XYZ, updated_position_coords);
        }
    }

    pub async fn get_flow_rate(&self) -> u8 {
        self.motion_cfg.lock().await.flow_rate
    }

    pub async fn set_flow_rate(&self, rate: u8) {
        self.motion_cfg.lock().await.flow_rate = rate;
    }

    pub async fn get_flow_rate_as_real(&self) -> Real {
        Real::new(self.motion_cfg.lock().await.flow_rate as i64, 0)
    }

    pub async fn get_speed_rate(&self) -> u8 {
        self.motion_cfg.lock().await.speed_rate
    }

    pub async fn set_speed_rate(&self, rate: u8) {
        self.motion_cfg.lock().await.speed_rate = rate;
    }

    pub async fn get_speed_rate_as_real(&self) -> Real {
        Real::new(self.motion_cfg.lock().await.speed_rate as i64, 0)
    }

    pub async fn get_default_travel_speed(&self) -> u16 {
        self.motion_cfg.lock().await.default_travel_speed
    }
    pub async fn set_default_travel_speed(&self, speed: u16) {
        self.motion_cfg.lock().await.default_travel_speed = speed;
    }

    pub async fn get_default_travel_speed_as_real(&self) -> Real {
        Real::new(self.motion_cfg.lock().await.default_travel_speed as i64, 0)
    }

    pub async fn get_max_accel(&self) -> TVector<u16> {
        self.motion_cfg.lock().await.max_accel
    }

    pub async fn get_max_speed(&self) -> TVector<u16> {
        self.motion_cfg.lock().await.max_speed
    }
    pub async fn set_max_speed(&self, speed: TVector<u16>) {
        self.motion_cfg.lock().await.max_speed.assign(CoordSel::all(), &speed);
    }
    pub async fn get_max_speed_as_vreal(&self) -> TVector<Real> {
        self.motion_cfg.lock().await.max_speed.map_coords(|c| Some(Real::new(c as i64, 0)))
    }

    pub async fn set_max_accel(&self, accel: TVector<u16>) {
        self.motion_cfg.lock().await.max_accel.assign(CoordSel::all(), &accel);
    }

    pub async fn get_max_accel_as_vreal(&self) -> TVector<Real> {
        self.motion_cfg.lock().await.max_accel.map_coords(|c| Some(Real::new(c as i64, 0)))
    }

    pub async fn set_max_jerk(&self, jerk: TVector<u32>) {
        self.motion_cfg.lock().await.max_jerk.assign(CoordSel::all(), &jerk);
    }

    pub async fn plan(&self, gc: &GCode, blocking: bool) -> Result<CodeExecutionSuccess, CodeExecutionFailure>{
        match gc {
            GCode::G0(t) => {
                Ok(self.schedule_move(TVector{
                    x: t.x, y: t.y, z: t.z, e: None,
                }, t.f, blocking).await?)
            }
            GCode::G1(t) => {
                Ok(self.schedule_move(TVector{
                    x: t.x, y: t.y, z: t.z, e: t.e
                }, t.f, blocking).await?)
            }
            GCode::G4 => {
                Ok(self.schedule_raw_move(ScheduledMove::Dwell, blocking).await?)
            }
            GCode::G28(_x) => {
                // FIXME Remove when complete
                self.defer_channel.send(DeferEvent::Homing(DeferType::AwaitRequested)).await;
                self.event_bus.publish_event(EventStatus::containing(EventFlags::HOMMING)).await;
                Ok(self.schedule_raw_move(ScheduledMove::Homing, blocking).await?)
            }
            GCode::G29 => {
                Ok(CodeExecutionSuccess::OK)
            }
            GCode::G29_1 => {
                Ok(CodeExecutionSuccess::OK)
            }
            GCode::G29_2 => {
                Ok(CodeExecutionSuccess::OK)
            }
            _ => {
                Err(CodeExecutionFailure::NotYetImplemented)
            }
        }
    }

    async fn schedule_move(&self, p1: TVector<Real>, requested_motion_speed: Option<Real>, blocking: bool) -> Result<CodeExecutionSuccess, CodeExecutionFailure> {

        let t0 = embassy_time::Instant::now();

        let p0 = self.get_last_planned_pos().await.ok_or(CodeExecutionFailure::HomingRequired)?;
        let p1 = if self.is_absolute_positioning().await { p1 } else { p0 + p1 };

        let cfg = self.motion_cfg();
        let cfg_g = cfg.lock().await;
        //----
        let dts = Real::from_lit(cfg_g.default_travel_speed as i64, 0);
        let flow_rate = Real::from_lit(cfg_g.flow_rate as i64, 0) / ONE_HUNDRED;
        let speed_rate = Real::from_lit(cfg_g.speed_rate as i64, 0) / ONE_HUNDRED;
        let max_speed = cfg_g.max_speed.map_coords(|c| Some(Real::from_lit(c as i64, 0)));
        let max_accel = cfg_g.max_accel.map_coords(|c| Some(Real::from_lit(c as i64, 0)));
        let max_jerk = cfg_g.max_jerk.map_coords(|c| Some(Real::from_lit(c as i64, 0)));
        //----
        drop(cfg_g);

        let t1 = embassy_time::Instant::now();

        // Compute distance and decompose as unit vector and module.
        // When dist is zero, value is map to None (NaN).
        // In case o E dimension, flow rate factor is applied
        let (vdir, module_target_distance) = (p1 - p0)
            .map_coord(CoordSel::all(), |coord_value, coord_idx| {
                match coord_idx {
                    CoordSel::X | CoordSel::Y | CoordSel::Z => {
                        match coord_value.is_zero() {
                            true => None,
                            false => Some(coord_value),
                        }
                    },
                    CoordSel::E => {
                        match coord_value.is_zero() {
                            true => None,
                            false => Some(coord_value * flow_rate),
                        }
                    },
                    _ => None,
                }
            }).decompose_normal();

        // Compute the speed module applying speed_rate factor
        let speed_module = requested_motion_speed.unwrap_or(dts) * speed_rate;
        // Compute per-axis distance
        let disp_vector: TVector<Real> = vdir.abs() * speed_module;
        // Clamp per-axis target speed to the physical restrictions
        let clamped_speed = (vdir.map_val(Real::one()) * speed_module).clamp(max_speed);
        // Compute max time
        let max_time = (disp_vector / clamped_speed).max().unwrap_or(ZERO);
        // Finally, per-axis relative speed
        let speed_vector = disp_vector / max_time;

        let module_target_speed = speed_vector.norm2().unwrap_or(ZERO);
        let module_target_accel = (max_accel * speed_vector).norm2().unwrap_or(ZERO);
        let module_target_jerk = (max_jerk * speed_vector).norm2().unwrap_or(ZERO);

        let t2 = embassy_time::Instant::now();

        let move_result = if module_target_distance.is_zero() {
            // TODO: set current speed!
            Ok(CodeExecutionSuccess::OK)
        }
        else {
            let profile = match !module_target_speed.is_zero() && !module_target_accel.is_zero() && !module_target_jerk.is_zero() {
                true => {
                    let _constraints = Constraints {
                        v_max: module_target_speed,
                        a_max: module_target_accel,
                        j_max: module_target_jerk,
                    };
                    let profile = SCurveMotionProfile::compute(module_target_distance.clone(), ZERO, ZERO, &_constraints)?;
                    Some(profile)
                },
                false => {
                    hwa::error!("p0: {}", p0.rdp(4));
                    hwa::error!("p1: {}", p1.rdp(4));
                    hwa::error!("dist: {} mm", module_target_distance.rdp(4));
                    hwa::error!("vdir: {} mm/s", vdir.rdp(4));
                    hwa::error!("speed_vector: {} mm/s", speed_vector.rdp(4));
                    hwa::error!("clamped_speed: {} mm/s", clamped_speed.rdp(4));

                    None
                }
            };
            //
            let t3 = embassy_time::Instant::now();
            hwa::debug!("P0 ({}) mm", p0);
            hwa::debug!("P1 ({}) mm", p1);
            hwa::debug!("MOTION PLAN: dist: {} mm, speed_max: {} mm/s, accel_max: {} mm/s^2, jerk_max: {} mm/s^3",
                module_target_distance.rdp(4),
                module_target_speed.rdp(4),
                module_target_accel.rdp(4),
                module_target_jerk.rdp(4)
            );
            match profile {
                Some(profile) => {
                    let segment_data = SegmentData {
                        speed_enter_mms: 0,
                        speed_exit_mms: 0,
                        displacement_u: (module_target_distance * Real::from_lit(1000, 0)) .to_i32().unwrap_or(0) as u32,
                        vdir,
                        dest_pos: p1,
                    };
                    let r = self.schedule_raw_move(
                        ScheduledMove::Move(segment_data, profile),
                        blocking
                    ).await?;

                    hwa::debug!("speed: {} -> {} ", requested_motion_speed.unwrap_or(Real::zero()).rdp(4), module_target_speed.rdp(4));
                    hwa::debug!("speed_vector: {}", speed_vector.rdp(4));
                    hwa::debug!("clamped_speed: {}", clamped_speed.rdp(4));
                    hwa::debug!("speed_rates: {}", speed_rate.rdp(4));

                    #[cfg(feature = "std")]
                    hwa::debug!("profile: {} {} {} {} {}", profile.t_j1.rdp(4), profile.t_a.rdp(4), profile.t_v.rdp(4), profile.t_d.rdp(4), profile.t_j2.rdp(4));

                    hwa::debug!("Conf retr in: {} us", (t1-t0).as_micros());
                    hwa::debug!("Move prepared in: {} us", (t2-t1).as_micros());
                    hwa::debug!("Move profiled in: {} us", (t3-t2).as_micros());
                    return Ok(r);
                }
                None => {
                    hwa::warn!("Incomplete move");
                }
            }

            hwa::debug!("----");

            Ok(CodeExecutionSuccess::OK)
        };
        match move_result {
            Ok(resp) => Ok(resp),
            Err(err) => match err {
                CodeExecutionFailure::BUSY => {
                    todo!("Delegate to deferrals!!!")
                }
                _ => {
                    Err(err)
                }
            }
        }
    }

    #[inline(always)]
    pub async fn do_homing(&self) -> Result<(), ()>{
        let r = self.motion_driver.lock().await.homing_action().await;
        if r.is_err() {
            self.event_bus.publish_event(EventStatus::containing(EventFlags::SYS_ALARM));
        }
        else {
            self.event_bus.publish_event(EventStatus::not_containing(EventFlags::HOMMING));
        }
        r
    }

    #[cfg(all(feature = "native", feature = "plot-timings"))]
    pub async fn start_segment(&self, ref_time: embassy_time::Instant, real_time: embassy_time::Instant) {
        self.motion_driver.lock().await.start_segment(ref_time, real_time)
    }

    #[cfg(all(feature = "native", feature = "plot-timings"))]
    pub async fn end_segment(&self) {
        self.motion_driver.lock().await.end_segment()
    }

    #[cfg(all(feature = "native", feature = "plot-timings"))]
    pub async fn mark_microsegment(&self) {
        self.motion_driver.lock().await.mark_microsegment();
    }
}


#[allow(unused)]
pub struct RingBuffer {
    pub(self) data: [PlanEntry; SEGMENT_QUEUE_SIZE as usize],
    pub(self) head: u8,
    pub(self) used: u8,
}

impl RingBuffer {
    pub const fn new() -> Self {
        Self {
            data: [PlanEntry::Empty; SEGMENT_QUEUE_SIZE as usize],
            head: 0,
            used: 0,
        }
    }
}

#[derive(Clone, Copy)]
pub enum MovType {
    Move,
    Homing,
    Dwell,
}

#[allow(unused)]
#[derive(Clone, Copy)]
pub enum PlanEntry {
    Empty,
    PlannedMove(Segment),
    Homing,
    Dwell,
    Executing(MovType),
}

impl Default for PlanEntry {
    fn default() -> Self {
        PlanEntry::Empty
    }
}

#[derive(Clone)]
pub struct MotionPlannerRef {
    pub(crate) inner: &'static MotionPlanner
}

//#[cfg(feature = "native")]
unsafe impl Send for MotionPlannerRef {}

impl core::ops::Deref for MotionPlannerRef {
    type Target = MotionPlanner;

    fn deref(&self) -> &Self::Target {
        self.inner
    }
}