Commit Graph

30 Commits

Author SHA1 Message Date
Kevin O'Connor 6bd5f4e44e stepcompress: Using normal message priority system during homing
The endstop homing system requires all queue_step commands be in the
MCU's 'move queue' before endstop checking starts.  Use the normal
message priority system to request that stepper queue_step commands
are received prior to the start of the end_stop_home command.  This
simplifies the code and removes the need for special serial queue
flushing.

This also fixes a bug in homing operations that take longer than 2^31
clock ticks.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-30 20:14:48 -05:00
Kevin O'Connor 800d53db6a stepcompress: Rework addfactor integer overflow check
Revert 4a16053c and avoid integer overflows in the addfactor
calculation by exiting the loop early if count > 0x200.  This provides
stronger protection against overflows.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-26 12:47:17 -05:00
Kevin O'Connor 4a16053c00 stepcompress: Fix integer overflow leading to infinite loop
Commit a217c0f3 changed the way the "addfactor" was calculated.
Unfortunately, it was possible for the updated method to cause an
integer overflow and have a negative addfactor.  Fix this by
explicitly casting the addfactor calculation to uint32_t.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-24 12:02:37 -05:00
Kevin O'Connor f3a49604f1 stepcompress: Increase check on max count to 10000000
Some motors have very small step distances and they can generate over
a million steps during a homing operation.  Increase the maximum count
to ten million to avoid triggering the internal sanity check.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-23 23:13:35 -05:00
Kevin O'Connor 1d841eeb87 stepcompress: Prefer greater interval if all else equal
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-19 11:20:39 -05:00
Kevin O'Connor 19d1f83d97 stepcompress: Move check for add=0 sequences out of loop
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-19 11:20:38 -05:00
Kevin O'Connor 6efadf44d0 stepcompress: Favor higher add values when bisecting
Instead of splitting the available "add range" in half, try for add
values closer to the higher end of the range.  This heuristic seems to
result in better choices.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-19 11:20:38 -05:00
Kevin O'Connor e4c4a4628b stepcompress: Use inclusive range on min/maxadd
Change the min/maxadd variables to use an inclusive range instead of
exclusive.  This better matches min/maxinterval.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-19 11:20:38 -05:00
Kevin O'Connor a217c0f394 stepcompress: Be consistent with "point" vs "nextpoint"
Make it clear which variables refer to the best verified point found
so far, and which variables deal with the next (not yet verified)
point.

Also, remove checked_count as bestcount serves the same purpose.

Also, allow minmax_point to be inlined.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-19 11:20:38 -05:00
Kevin O'Connor 1dbd11446c stepcompress: Don't warn on multi-step interval=0 sequences
It is possible to get a valid multi-step sequence with an interval of
zero if the add is non-zero.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-14 11:03:16 -05:00
Kevin O'Connor 83f7d702e7 stepcompress: Encourage add=0 in compress_bisect_add()
Only use a non-zero 'add' if it actually extends the number of steps
the command covers.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-06 19:01:00 -05:00
Kevin O'Connor 4565a73e91 stepcompress: Optimize push_delta_const() for common XY or Z only moves
Most moves are on the XY plane - avoid a few multiplications in the
inner loop in this case.  When there is a Z move, it is almost always
entirely a Z move - avoid the sqrt() call in the inner loop in this
case.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-05 14:40:29 -05:00
Kevin O'Connor 9c932ad514 delta: Rework delta math to avoid using inv_movexy_r
Taking the inverse of the XY move distance can lead to extremely large
values when the XY distance is very small.  This can lead to
saturation of the double precision variables and incorrect results.

Rework the delta kinematic math to avoid using this inverse.  Pass the
closestxy_d value directly to the C functions so that the C code can
calculate its intermediate constants.

After this change the move_z special case is no longer necessary as
the regular delta functions now work with movexy_r=0 and movez_r=1.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-05 14:36:02 -05:00
Kevin O'Connor 4f07ee4d92 pyhelper: Add ability to route error messages to python logging
Instead of writing error messages to stderr, route them into the
python code and use the standard python logging system.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-30 21:19:43 -05:00
Kevin O'Connor 7cb71df02c mcu: Be careful to free memory allocated in C code
Free steppersync, stepcompress, and commandqueue objects.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-30 13:33:16 -05:00
Kevin O'Connor 6ab269ceb7 stepcompress: Don't bother loop unrolling in push_sqrt()
It's not necessary to have two loops - checking if factor is greater
than zero in the loop is fine.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-14 15:36:11 -05:00
Kevin O'Connor fd7cb99f47 stepcompress: Optimize safe_sqrt() code
Optimize the code by putting the uncommon case out-of-line.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-14 15:12:53 -05:00
Kevin O'Connor 941427554a delta: Initial support for linear delta kinematics
This adds support for delta based robots.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-14 12:35:36 -05:00
Kevin O'Connor 7554c7f694 stepcompress: Do all step rounding in C code
Commits f0cefebf and 8f331f08 changed the way the code determined what
steps to take on fractional steps.  Unfortunately, it was possible in
some situations for the C code to round differently from the python
code which could result in warnings and lost steps.

Change the code so that all fractional step handling is done in the C
code.  Implementing the step rounding logic in one location avoids any
conflicts.

In order to efficiently handle the step rounding in the C code, the C
code has also been extended to directly send the "set_next_step_dir"
command.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-13 18:29:45 -05:00
Kevin O'Connor 79da35d023 stepcompress: Minor code movement
Move flush() and check_expand() code to a new location so that the
stepcompress_push_X() functions can flush.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-12 22:55:27 -05:00
Kevin O'Connor 508a934d62 stepcompress: Do 32bit integer overflow checks internally in C code
Update the stepcompress C code to check for integer overflow so that
the python code does not need to.  The new checks also handle the
possibility of a single move lasting long enough to cause an overflow.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-02 13:22:35 -04:00
Kevin O'Connor 8025921fc8 stepcompress: Invert the meaning of the min_clock flag
Use a non-zero qm->min_clock value to indicate that the command uses
the move queue and to also store the clock of when that move queue
item will be released.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-02 10:12:26 -04:00
Kevin O'Connor ff6fef927a stepcompress: Store step times using 64bit integers
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-01 19:38:37 -04:00
Kevin O'Connor ab54fcd443 stepcompress: Check for small negative numbers on sqrt() calls
It's theoretically possible for floating point truncation to cause a
math formula to return a small negative number instead of 0.  If
sqrt() is called on this small negative number it could cause a
crash.  Check for this case and return 0.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-10 11:39:26 -04:00
Kevin O'Connor 9fa0a62c8a stepcompress: Eliminate possible infinite loop in compress_bisect_add()
Commit 47f30331 converted compress_bisect_add() to use "best reach"
instead of "best add".  However, that change caused
compress_bisect_add() to behave poorly when passed in invalid data
(negative times).  Change the code to better handle invalid data.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-10 11:31:56 -04:00
Kevin O'Connor 47f303317b stepcompress: Compress for greatest "reach" instead of greatest "add"
Search for the maximum reachable value instead of the maximum "add".
The maximum reachable value encompasses both the maximum count and a
closest step time to the last requested step time.  This allows for
more "add=0" sequences to be generated which the mcu can optimize for.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-24 11:42:06 -04:00
Kevin O'Connor 4988ba9a71 stepcompress: Fix error causing queue to not be expanded in expand_queue()
The test to check if the queue only needed to be moved was not correct
and it could lead to a segfault if clean_queue() was called instead of
actually increasing the queue size.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-07-16 21:33:35 -04:00
Kevin O'Connor 3fa7da804d stepcompress: Check for invalid count in step_factor and step_sqrt
Check for an invalid count and report an error if found.  This
prevents some segfaults when count goes negative.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-07-16 21:33:15 -04:00
Kevin O'Connor ae8d57e650 stepcompress: Fix compress_bisect_add() infinite loop
At high step speeds, it is possible to exit the inner scan due to
integer truncation.  Always update minadd or maxadd so that the outer
loop always terminates.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-07-10 21:46:57 -04:00
Kevin O'Connor f582a36e4d Initial commit of source code.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-05-25 11:37:40 -04:00