Commit Graph

858 Commits (6340421f513de12236e39a970ec061b720c2c0d9)

Author SHA1 Message Date
Yuri D'Elia be30314634 Motion: initialize axes in the same order as the enumeration 2021-07-07 16:59:40 +02:00
Yuri D'Elia 2875e61484 Motion: allow to query the buffer per-axis
We might want to schedule new moves while a single motor is moving.
Allow to do that by introducing per-axis query functions.

The main QueueEmpty() and Full() still function as before:

- Call QueueEmpty() to wait for all moves to finish.
- Use !Full() to know that a Plan() move will never be discarded.
2021-07-07 16:59:40 +02:00
Yuri D'Elia 94f11642e0 PulseGen: perform an extra queue check in Move()
Since scheduling a move on a block which is being executed will jolt the
motors, be extra-safe and perform an extra lower-level check before
committing even if the caller is responsible.

Return the status, which can be useful to build a simple busy loop.
2021-07-07 16:59:40 +02:00
Yuri D'Elia bd8ae62211 PulseGen: cleanup AxisData initialization 2021-07-07 16:59:40 +02:00
Yuri D'Elia 16cf02726b test_speed_table: improve static assertion
Test against the resulting timer speed, not against the CPU clock
2021-07-07 16:59:40 +02:00
Yuri D'Elia d87db1ff76 Revised WIP for the Motion API
- Remove the combined PlanMove(a,b,c,rate) call. If we allow the units
  of the various motors to be changed at compile time, the unit of
  rate can vary between axes.
- Build PlanMove on top of the absolute PlanMoveTo.
- Add required stubs for TMC2130.
- Allow each axis mode to be set independently, since we have this
  feature for free anyway.
- Rework internals to use PulseGen data types and structs.
2021-07-07 16:59:39 +02:00
Yuri D'Elia e990b703e3 CMake: reformat 2021-07-07 16:59:04 +02:00
Yuri D'Elia d7874d5336 PulseGen: implement AbortPlannedMoves 2021-07-07 16:59:04 +02:00
Yuri D'Elia 44a263d334 PulseGen: move Step() to header for inlining 2021-07-07 16:59:04 +02:00
Yuri D'Elia 6f518f1ed2 PulseGen: complete implementation 2021-07-07 16:59:04 +02:00
Yuri D'Elia ed04bd02e2 PulseGen/speed_tables: cleanup constants 2021-07-07 16:59:04 +02:00
Yuri D'Elia 006dfd4abc PulseGen: remove all floating point calculations
Work in steps, steps/s, steps/s2 directly.
2021-07-07 16:59:04 +02:00
Yuri D'Elia cf5be5aade PulseGen: initial version of the ramp/pulse generator 2021-07-07 16:59:04 +02:00
Yuri D'Elia 7d2329cf85 Add src/cmath.h for <math.h> portability between platforms 2021-07-07 16:59:04 +02:00
Yuri D'Elia de88ed4c6b Add initial Axis configuration static structs 2021-07-07 16:59:04 +02:00
Yuri D'Elia ef7c776461 Update Motion for the new TMC2130/pins definitions 2021-07-07 16:59:04 +02:00
Yuri D'Elia 531f60ed27 Add modules::speed_table for acceleration lookup tables 2021-07-07 16:59:04 +02:00
Yuri D'Elia 1d6736cff6 Add modules::math for specialized math functions
Currently include reduced-precision 8x16 and 16x16 multiplication
functions used by the speed lookup tables.
2021-07-07 16:59:04 +02:00
Alan Dragomirecký 996f0f5dc0 Fix formatting of cmake files 2021-07-07 16:33:16 +02:00
Alan Dragomirecký e3d8147890 Ignore .cmake-format.py file by cmake-format 2021-07-07 16:33:16 +02:00
Alan Dragomirecký 9448c04b36 Disable preprocessor code indentation 2021-07-07 16:33:03 +02:00
Yuri D'Elia f95c47638d CircularIndex: fight against type promotion in size checks
To generate optimal code, size itself needs to be of the same type as
the index to avoid promotion to the largest type.

In full(), wrap the subtraction explicity in another type cast to avoid
another automatic type promotion.
2021-07-06 12:51:56 +02:00
Yuri D'Elia f57a1c3b17 CircularIndex: add static checks for index/size limits
The empty/full distinction fails to work if size matches the number of
representable positions for the index type.

Add a static check to ensure this invariant is met where possible.
2021-07-06 12:51:56 +02:00
Yuri D'Elia 4362d77083 CircularIndex: alternate index management for full capacity
Comparing head/tail indexes cannot distinguish between empty/full cases,
so we end up wasting one item in the circular buffer. This also limits
the smallest and efficient size choice to be 4.

If the circular buffer is large, there's no issue, however for the
motion planner the block size is significant, and I was planning to use
exactly a ring buffer of two: one busy block, plus one planned.

Modify the indexer to store the internal "index" (aka cursor) pointer to
be one extra bit deeper than the final index. Comparing the underlying
cursor allow to distinguish the empty/full case due to the extra bit,
while producing the final index requires simple masking.

This is just as efficient if the size is a power of two with
2-complement wrap-around logic, which is the optimized case. However
the implementation also works for non-power-of-two sizes.

Add tests for more failure cases in the CircularBuffer which is built on
top.

(tecnique described in the Art of Computer Programming by Knuth)
2021-07-06 12:51:56 +02:00
Yuri D'Elia 477539c791 Split CircularBuffer into CircularIndex+CircularBuffer
Allow the lower-level index to be used without an actual container by
splitting off the index management into CircularIndex.

Rebuild CircularBuffer using CircularIndex itself.
2021-07-06 12:51:56 +02:00
D.R.racer 43a423f299 Change buttons' ADC limits into an array
as proposed by @vintagePC

cleaned-up some of the unit tests by this change
2021-07-05 18:07:54 +02:00
D.R.racer 552fec9abf Parametrize Idler and Selector in common config.h 2021-07-05 18:07:54 +02:00
D.R.racer ccda84df80 Make buttons' ADC decision levels "inclusive"
especially because of the zero level, which is very likely to be a valid button0 level
2021-07-05 18:07:54 +02:00
D.R.racer b484eeacb6 Start using config.h
Added some constexpr vars for buttons, finda, fsensor and
applied them in the FW and unit tests accordingly.
2021-07-05 18:07:54 +02:00
Yuri D'Elia dd5c036d38 GPIO: reformat affected files 2021-07-05 15:20:11 +02:00
Yuri D'Elia 3ccfc3adfb GPIO: correctly stub known ports
- Use the correct port name in the #define
- Fully qualify all references
2021-07-05 15:20:11 +02:00
Yuri D'Elia 32b2ec7f8d Remove GPIOI 2021-07-05 15:20:11 +02:00
Yuri D'Elia 067deb7e55 Completely remove PIN macros 2021-07-05 15:20:11 +02:00
Yuri D'Elia 7c7aa95445 Mock GPIO when building tests
Add some conditional statements in gpio.h so that we can mock the GPIO
registers when building tests.
2021-07-05 15:20:11 +02:00
Yuri D'Elia 169665331e Change the pin definitions in order to be valid types
Remove the constructor from GPIO_pin so that we can use brace
initialization at compile time.

Rewrite the contents of pins.h to construct GPIO_pin types directly by
the use of a simple preprocessor macro.

Makes the code type-check and easier to read/extend.
2021-07-05 15:20:11 +02:00
Yuri D'Elia e9627ad0d4 TMC2130: Reformat 2021-07-05 13:34:08 +02:00
Yuri D'Elia f491072614 TMC2130: Make stepping methods static
To keep these methods efficient no member should be accessed away.
That's the reason MotorParams is passed explicitly for each.

Mark all stepping methods as static.
2021-07-05 13:34:08 +02:00
Yuri D'Elia 28c9e55a79 Add vSense to MotorCurrents 2021-07-05 13:34:08 +02:00
Yuri D'Elia c78ed77ccc Revise the TMC2130 interface for stepping
Change the TMC2130 class after starting to review the Motion API.
Move motor mode handling and stepping to this module.

Create a new MotorParams class for compile-time settings (currently
pins, direction, microstepping).

Keep other settings separate, so that we can pass constexpr expressions
while stepping and still get 1 instruction without overhead.
2021-07-05 13:34:08 +02:00
Yuri D'Elia ea8b335f8d progmem: fix for AVR
- Fix header name
- Rename pgm_read_word to read_word since pgm_read_word is a macro
  and cannot be scoped
2021-07-05 13:33:49 +02:00
Yuri D'Elia a9937b94e2 Add initial AVR PROGMEM abstraction in hal::progmem 2021-07-05 13:33:49 +02:00
D.R.racer 9efb127acb Explain and fix the LED states while cutting filament
now the test is correct including LEDs
2021-07-01 08:12:47 +02:00
D.R.racer d81b00a0f8 Test all filament slots 2021-07-01 08:12:47 +02:00
D.R.racer 974c1ba6db Verify Cut filament state machine + update unit tests 2021-07-01 07:03:39 +02:00
D.R.racer 75fe7b20b5 Verify and fix Tool Change state machine + unit tests 2021-07-01 07:03:02 +02:00
vintagepc e2ec745286
Simple config header with example (#39)
Simple config header with example
2021-07-01 06:47:40 +02:00
Yuri D'Elia ab01413116 Call LED::Step() correctly 2021-06-30 12:39:03 +02:00
D.R.racer 9122a33693 Rebase onto upstream/main, adapt to cleaned-up circular buffer interface 2021-06-30 07:39:31 +02:00
D.R.racer ffae941a28 Fix unit tests of load/unload filament 2021-06-30 07:39:31 +02:00
D.R.racer 9a8038ccb6 Add user_input module and use it instead of raw buttons
Encapsulates buttons and commands coming from the communication
2021-06-30 07:39:31 +02:00