# Motan in batch mode

**URL:** <https://klipper.discourse.group/t/motan-in-batch-mode/3993>\
**Category:** Developers\
**Created:** [August 29, 2022, 7:00pm UTC](https://klipper.discourse.group/t/motan-in-batch-mode/3993 "2022-08-29T19:00:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Piezo](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/piezo/32/1110_2.png) [@Piezo](https://klipper.discourse.group/u/Piezo)\
**Post date:** [August 29, 2022, 7:00pm UTC](https://klipper.discourse.group/t/motan-in-batch-mode/3993/1 "2022-08-29T19:00:31Z")

</div>

I’m trying to make it possible to extract trapq data with `[motion_report]` in batch mode.  
This would be helpful to simulate prints on printer that we don’t own, or to generate ground truth for testing tools like klipper\_estimator.

My plan is to use the existing webhooks api of `motion_report` and the `data_logger.py` script. This is simpler than rewriting another serializer just for the debug mode.

There is two issues that need to be overcome:

- In batch mode, Klipper doesn’t run the webhooks server. Also, it doesn’t wait for `data_logger.py` to subscribe. [This can easily be resolved](https://github.com/Piezoid/klipper/commit/30c880581cee3c245b7c6593e464a258cce8550a).
- The trapq and stepper command histories are pulled from `motion_report` at regular intervals when a timer fires. In batch mode, the print\_time goes by a lot faster than event\_time. The histories buffers wraps around in the `API_UPDATE_INTERVAL` since there is too many of moves simulated during this period.

I managed to pull a complete trapq trace (with a sample [here](https://klipper.discourse.group/t/print-head-pausing-at-the-end-of-every-layer/3945/13)) by using a very low `API_UPDATE_INTERVAL`.  
However this is incredibly hacky, as the timer is basically running against the CPU filling the buffers.

Does anyone have a better solution?

---

<div class="post-metadata">

**Author:** ![dmbutyugin](https://avatars.discourse-cdn.com/v4/letter/d/e0b2c6/32.png) [@dmbutyugin](https://klipper.discourse.group/u/dmbutyugin)\
**Post date:** [August 30, 2022, 5:44pm UTC](https://klipper.discourse.group/t/motan-in-batch-mode/3993/2 "2022-08-30T17:44:46Z")

</div>

Hmm, I previously wrote a [simulated](https://github.com/dmbutyugin/klipper/blob/resonance-test-methods-update/klippy/extras/adxl345_simulated.py) adxl345 (that uses trapq capture to simulate what the measurements would be) and I didn’t have the issues you described (at least on the resonance test, but it has a rate of more than 500 moves / sec).

Though I observed that the data may not be flushed in batch mode, which I fixed [this way](https://github.com/Klipper3d/klipper/commit/75808bc92cb3fa266b5277a2e2cce669226dc233). Not sure if it would affect your case.

But I agree that dumping stepper motion might be a lot trickier as there are way more events in the stepq(s).

---

<div class="post-metadata">

**Author:** ![koconnor](https://avatars.discourse-cdn.com/v4/letter/k/aca169/32.png) [@koconnor](https://klipper.discourse.group/u/koconnor)\
**Post date:** [August 31, 2022, 8:35pm UTC](https://klipper.discourse.group/t/motan-in-batch-mode/3993/3 "2022-08-31T20:35:27Z")

</div>

I agree it would be useful to be able to use the motan tools from batch mode. Alas, I’m not sure the best way of doing that… If I come up with an idea, I’ll let you know.

Cheers,  
-Kevin
