Commit Graph

845 Commits (3924cb3d4f3fcf868997c5e6b08259fe2dfff259)

Author SHA1 Message Date
D.R.racer 315530ec16 Rebase onto main, reflect FINDA change (ADC->digital pin) in unit tests 2021-09-02 12:15:55 +02:00
D.R.racer 5a53acd802 Force Tool Change to load the filament if same slot but not loaded
MMU-63
2021-09-02 12:15:55 +02:00
Yuri D'Elia 6f3540a14d Fix Motion::SetMode(axis, mode) and introduce SetMode(mode)
Motion::SetMode(axis, mode) was incorrectly looping through all axes,
setting the same axis three times.

Fix this and introduce Motion::SetMode(mode) which actually loops
through all axes (see PR #110)
2021-09-02 12:04:59 +02:00
Yuri D'Elia e7cba346da Use relative paths for panic.h
Avoids adding the main directory as an include path
2021-09-02 12:00:59 +02:00
Yuri D'Elia ee8c80e5c4 Motion: Panic if queue is full
If the queue is full and a new move is queued, panic!

Introduce a new error code QUEUE_FULL to help diagnose situations where
the queue is handled improperly: likely one of the state machines not
waiting for the previous actions to finish.

PulseGen::PlanMove returns a boolean if the queue cannot be moved.
We could extend this to Motion::PlanMove, however all moves would then
have to check for this. Having a global check such as this ensures
we never ignore such situation.
2021-09-02 12:00:59 +02:00
D.R.racer ac78619b5b Cache TMC error flags inside movable_base class 2021-09-02 08:35:56 +02:00
D.R.racer 309d4704b7 Fix return value of TMC2130::Init 2021-09-02 08:35:56 +02:00
D.R.racer b708e67a19 Verify repeated calls to Step do not change from ERRTMCFailed 2021-09-02 08:35:56 +02:00
D.R.racer 161e46b09a Add unit tests for failing TMC
more stuff will follow as these situations seem to cause various issues
2021-09-02 08:35:56 +02:00
D.R.racer 1d884d9099 Make motion::QueueEmpty inline for non-UNITTEST builds 2021-09-02 08:35:56 +02:00
D.R.racer 712b67beb4 Add checking of TMC2130 error states for Idler and Selector
we shall think about the Pulley as well, it looks like it should get its
own class just like Idler and Selector as it behaves very similarly in terms
of stepping and error checking
2021-09-02 08:35:56 +02:00
D.R.racer ffe5bc2807 Make Idler and Selector only wait for their own axis
... and fix the unit tests for this
2021-09-02 08:35:56 +02:00
D.R.racer 5571e77809 Improve/fix some comments 2021-09-02 08:35:56 +02:00
D.R.racer 74629f0103 Fix reporting progress of running commands
The problem was the error state while running a command - we never used the RUNNING error state.
2021-09-02 08:35:56 +02:00
D.R.racer b4d4807971 Add globa Panic() function
The intent is to halt the firmware while retaining the reporting capabilities and blinking LEDs
2021-08-31 14:19:40 +02:00
D.R.racer dc3d8941f7 Fix formatting 2021-08-31 06:59:29 +02:00
3d-gussner 1c565ddc02 Update documentation 2021-08-31 06:59:29 +02:00
3d-gussner 59db864329 Clean up code findaADC.. 2021-08-31 06:59:29 +02:00
3d-gussner 763e33f79a Fix unit test: unload_filament 2021-08-31 06:59:29 +02:00
3d-gussner d5e473f9c9 Fix unit test: tool_change 2021-08-31 06:59:29 +02:00
3d-gussner 12cf25511a Fix unit test: load_filament 2021-08-31 06:59:29 +02:00
3d-gussner 3d121c1ca9 Fix unit test: unload_to_finda 2021-08-31 06:59:29 +02:00
3d-gussner 382a2c8dc0 Fix unit test: feed_to_finda 2021-08-31 06:59:29 +02:00
3d-gussner a7a55b4039 Fix unit test: cut_fillament 2021-08-31 06:59:29 +02:00
3d-gussner 003b2f6899 Change FINDA from ADC to digital
Fix rebase issues
2021-08-31 06:59:29 +02:00
D.R.racer 06c46b20a6 Turn off green LED after load/unload finished successfully
MMU-65
2021-08-30 17:34:46 +02:00
Yuri D'Elia e9e43f744d Correct pulley steps by experimentation
Test performed by moving 500mm of filament back&forth 5 times across 5
pulleys of a MMU2 unit.

The error with this factor is centered around +/- 1.5mm depending on the
pulley and tension on the idler.
2021-08-30 12:49:54 +02:00
Yuri D'Elia f77e426af1 Use the MK2 values for the Pulley 2021-08-30 12:49:54 +02:00
Yuri D'Elia a7d8953519 Fix stepsPerUnit for the Pulley
Also use the correct value multiplied by the current ustep resolution to
make the conversion obvious.
2021-08-30 12:49:54 +02:00
Yuri D'Elia bc36ea4566 PulseGen: fix speed types in functions
Type was incorrectly changed in the last commit while debugging
2021-08-30 12:49:34 +02:00
Yuri D'Elia 04631677cc Motion/PulseGen: implement move chaining and end-speed control
Allow to chain moves by adding one extra parameter to the PlanMove[to]
functions: ending speed.

A move will always be accelerated from the last speed towards end ending
speed. The following:

  PlanMove(100._mm, 50._mm_s, 50._mm_s);
  PlanMove(200._mm, 100._mm_s);

Will first move the axis 100mm, accelerating towards 50mm/s, then
accelerate again to 100mm/s. The move will for then decelerate towards a
full stop after reaching 300mm in total.

Acceleration can be changed for each segment, so that a custom
acceleration curve can be created:

  SetAcceleration(10._mm_s2);
  PlanMove(100._mm, 50._mm_s, 50._mm_s);
  SetAcceleration(100._mm_s2);
  PlanMove(100._mm, 50._mm_s, 50._mm_s);

The ending speed might not always be reached, depending on the current
acceleration settings. The new function "Rate()" will return the ending
feedrate of the last move, if necessary.

AbortPlannedMoves accepts a new "halt" parameter to control how moves
will be chanined when interrupting the current move. By default
(halt=true) the move is completely interrupted.

When halt=false is requested, a subsequent move will be chained starting
at the currently aborted velocity. This allows to chain moves in reponse
to events, for example to accelerate the pulley without stopping as soon
as the FINDA is triggered, it's sufficient to interrupt the current move
followed by a new one:

  PlanMove(maximum_loading_lenght, slow_feedrate);
  ... wait for PINDA trigger ...
  AbortPlannedMoves(true);
  PlanMove(bowden_lenght, fast_feedrate);

will seamlessy continue loading and transition to the fast feedrate.

Jerk control has been simplified. It now handles only the maximal
velocity change of the last segment, which doesn't require reverse
planning.
2021-08-30 12:49:34 +02:00
Yuri D'Elia d55e01bb58 Motion/PulseGen: allow to abort a move for chaining
Add a new parameter "halt" (default to true) to control the stopping
behavior:

- halt=true: no subsequent moves will be planned, motions stops abruptly
- half=false: a new move will be chained after the current one
2021-08-30 12:49:34 +02:00
Yuri D'Elia d18143dff2 PulseGen: store/return the last segment speed 2021-08-30 12:49:34 +02:00
Yuri D'Elia 60c83b0af2 Allow to set axis acceleration with AxisUnit and physical units 2021-08-30 12:49:34 +02:00
Yuri D'Elia 563c8192cd Update motor currents
Use the same values from the original FW as suggested by @leptun
2021-08-30 07:12:24 +02:00
Yuri D'Elia bcf818b8fd Silence motion::Isr() unused variable warning
Move motion.Step() directly inside the __AVR__ code, silencing an unused
variable warning.

Calling motion.Step() without getting or setting the timer is not useful
anyway.
2021-08-30 07:11:29 +02:00
Yuri D'Elia fe621eb280 test_motion_ramp: improve robustness when checking multiple axes
When checking multiple axes together, also reconstruct the step rate, so
that subsequent checks do not fail randomly.
2021-08-30 07:10:54 +02:00
Yuri D'Elia e4af0717f6 test_ramp_gen: cosmetic fixes 2021-08-30 07:10:54 +02:00
Yuri D'Elia bb9e2a075b temp_motion_ramp: test single and multiple axes moving
stepTimerQuantum introduces discretization error, which makes the
acceleration curves noisy.

In rampgen generate ramps for a single moving axis in addition
of two axes moving together.

Then, in test_ramp_gen, test a single axis moving accurately, while
allow for some discretization error when two (or more) axes are running.
2021-08-30 07:10:54 +02:00
Yuri D'Elia 734612238e test_motion_ramp: do not skip tests
Remove a debugging left-over causing just the first ramp to be checked
2021-08-30 07:10:54 +02:00
Yuri D'Elia 9c3b31756e Optimize timer multiplexing and increase stepTimerQuantum
Avoid calling PulseGen::Step() on idle axes by checking for a non-zero
queue size (which is more efficient to compute).

Increase stepTimerQuantum to 128us to ensure acceleration can be
computed in realtime for 3 axes at the same time.

Fix the logic of the static assertion, which was flipped: we need to
create slices larger than the maximal step frequency in order to ensure
no axis is starved while moving.
2021-08-30 07:10:54 +02:00
Yuri D'Elia d23ed53f3c Also fix min/max outside of AVR by using the standard std::min/max 2021-08-30 07:07:19 +02:00
Yuri D'Elia b55c13dec2 Use operators for min/max
Turns out AVR doesn't have __builtin_min/max
2021-08-30 07:07:19 +02:00
Yuri D'Elia 1f2662518b Fix gpio::TogglePin on AVR
TogglePin was incorrectly using the PINx pin for toggling, causing the
current pins (in addition to the requested ones) to be toggled, causing
stepping havoc.
2021-08-30 07:06:28 +02:00
D.R.racer a58450acb6 Extract feedrates of Idler and Selector into config.h 2021-08-27 15:31:20 +02:00
Yuri D'Elia c7f3fae266 Implement an initial Motion ISR for AVR
This is a tentative/crude implementation of an Init and ISR for the MMU
in order to check the motion API.

We remove the "extern void Isr", declaring it "static inline" instead.
We need to inline the ISR here in order to avoid the function call.

Include the missing speed_table data in the executable. This bumps the
code size to ~60% of the flash.

Implemement motion::Init to setup the ISR and timers, and replace the
call in main from tmc::Init to motion::Init. Motion will init each
driver every time the axis is enabled, so there should be no need for
a global module initialization (we need SPI, but this is initialized
earlier on by it's own module anyway).

The timer is currently setup without any HAL or proper TIMER1 wrapper.
This is to be improved later.

The real MMU unit seems to slow down quite a bit during acceleration.
At this point we need to inline some methods in PulseGen to avoid
overhead, however this breaks the stubs.
2021-08-27 10:13:23 +02:00
Yuri D'Elia 1b0a67826a Improve motion::unit tests to handle fractional scaling
Pulley doesn't result in an exact step count due to the fractional
count.result in an exact step count due to the fractional count.

Use Selector instead to test values exacly.

Still check Pulley and Idler, but allowing for a +/-1 step of rounding
error.
2021-08-25 09:16:56 +02:00
Yuri D'Elia 288e74283d Introduce config::MRes and fix (real) axis units
The parameter config::AxisConfig::uSteps was supposed to be
microstepping resolution, but it's instead being used as the driver's
MRES directly.

To avoid a runtime conversion, rename the field to mRes and define a new
enum listing all the possible (and valid) microstepping resolutions.

This simplifies the code and makes clear the stepsPerUnit scale.

Assign correct stepsPerUnit to all axes as a result, including working
limits.
2021-08-25 09:16:56 +02:00
Yuri D'Elia f7f0df4afa Move hal/avr/tmc2130 into hal/ directly
There are no dependencies on AVR in TMC2130, so move into the main tree
2021-08-25 07:57:19 +02:00
Yuri D'Elia 6a9f2a2df9 Motion: test the middle driver's Enabled status too 2021-08-25 07:57:19 +02:00