Commit Graph

222 Commits

Author SHA1 Message Date
Kevin O'Connor 5a1ec817d4 stepper: Check if the motor needs to be enabled in the kinematic classes
Check for motor enable in the kinematic classes so it doesn't need to
be checked on every move.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-14 13:40:35 -05:00
Kevin O'Connor 9ad8153d33 stepper: Reset the next step time on a stepper stop
Automatically reset the next step time to zero on a stepper_stop()
call.  This makes the host code simpler as it no longer needs to
schedule an explicit reset_step_clock command on the step after a
homing operation.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-14 13:10:14 -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 1dee1ba64e queuelogger: Add support for background log writing
Writing to the debug log can cause an unbounded delay due to disk IO.
This is particularly so on embedded machines such as the Raspberry Pi
that run on SD cards.  These log writing delays can cause problems for
the main processing threads.

The new "queuelogger" code forwards all the main thread log messages
to a queue, and a background thread writes the log messages from the
queue to the destination file.  This eliminates the IO delay from the
main threads.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-12 22:53:43 -05:00
Kevin O'Connor afecf7ce36 stepper: Default to a high direction pin meaning positive direction
Invert the default meaning of the stepper direction pin.  Instead of
treating a low value as position motion, treat a high value as
positive motion.  This matches what other firmwares do, and it matches
what common stepper motor drivers document.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-08 10:39:32 -05:00
Kevin O'Connor 5e6127869a mcu: Do not invert the direction of pullup pins by default
A pullup setting on an input pin (ie, '^') should enable the hardware
pullup resistor, but it should not invert the trigger level (ie, it
should remain trigger on high).  Those that need to change the trigger
level (ie, trigger on low) must now do that explicitly (ie, '^!').
This makes the code match what other firmwares do.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-08 09:29:38 -05:00
Kevin O'Connor 3b5b895a10 heater: Do not require target temperature be above min_extrude_temp
Only disable the extruder if the last measured temperature is below
the minimum extrude temperature setting.  Verifying the target
temperature is not necessary, and it can incorrectly prevent some
valid moves.  It's not uncommon for scripts to retract filament
immiedietly after setting the extruder temperature to zero.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-08 09:22:43 -05:00
Kevin O'Connor 345fc41482 extruder: Don't do pressure advance on velocity changes due to cornering
Due to the lookahead, small changes in the direction of the toolhead
cause minor changes in toolhead velocity.  These "cornering" velocity
changes cause the current extruder code to trigger pressure advance
and its associated pressure retract.  This causes the extruder to
rapidly "jerk" the filament.

This code change updates the extruder to detect velocity changes due
solely to cornering and avoid pressure advance.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-05 11:06:58 -04:00
Kevin O'Connor 93dd310add extruder: Don't assume start_v matches last end_v in pressure advance
Due to minor differences in the extrude ratio, the last end velocity
of the filament may not exactly match the next move's start velocity
of the filament.  Implement more precise calculations for pressure
advance to take this into account.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-05 11:06:58 -04:00
Kevin O'Connor a201385008 extruder: Consistently use extrude distance in calculations
Avoid mixing the travel distance of the head (and its associated
velocity and acceleration) with the distance the filament moves.
Instead, use the filament travel distance.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-05 11:04:50 -04:00
Kevin O'Connor 9d7aa1e155 toolhead: Support calculation of cornering minimum and maximum
Calculate the next "cornering" minimum and maximum for each move.  The
"cornering minimum" is the lowest speed the head will reach
immediately after this move (with no interleaving acceleration or
cruising).  The "cornering maximum" is the maximum speed the head will
reach after the cornering minimum (with no interleaving deceleration
or cruising).

These cornering calculations will be helpful in the extruder "pressure
advance" code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-05 10:59:36 -04:00
Kevin O'Connor 6285cc6f66 toolhead: Simplify calculation of junction_cruise
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-05 10:59:36 -04:00
Kevin O'Connor 8e165fecc0 toolhead: Calculate maximum junction start when adding moves
Take into account the maximum possible start speed of a move when
calculating junction_start_max.  This simplifies the lookahead logic.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-05 10:56:47 -04:00
Kevin O'Connor 2b7ab290b8 mcu: Remove python checks for stepcompress integer overflow
Now that the C code checks for overflow, it is no longer necessary for
the python code to check.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-02 13:22:35 -04: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 8f331f08d2 extruder: Determine start step offset using last commanded position
The existing code calculates the number of steps in a move and then
spreads them out evenly throughout that move.  Change the code so that
step timing is based on where the head is commanded to be relative to
the stepper step locations.  This makes the timing more accurate - in
particular the stepper velocities will be more accurate during
cornering introduced by the lookahead code.  It also results in
slightly smoother stepper motion which results in better step
compression.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-31 11:14:28 -04:00
Kevin O'Connor f0cefebff7 cartesian.py: Determine start step offset using last commanded position
The existing code calculates the number of steps in a move and then
spreads them out evenly throughout that move.  Change the code so that
step timing is based on where the head is commanded to be relative to
the axis step locations.  This makes the timing more accurate - in
particular the axis velocities will be more accurate during cornering
introduced by the lookahead code.  It also results in slightly
smoother stepper motion which results in better step compression.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-31 11:06:19 -04:00
Kevin O'Connor 2904a0bbac cartesian: Rename step_dist to move_step_d
Don't use step_dist for the "distance along the line of movement per
step" as it's too similar to the stepper.step_dist variable.  Use the
name "move_step_d" instead.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-31 11:05:52 -04:00
Kevin O'Connor 6a96e83ea9 toolhead: Store both the start and end position in the Move class
Store the start position (in addition to the existing end position) in
the Move class.  The start position can be useful to the kinematic
classes.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-25 19:19:29 -04:00
Kevin O'Connor 977aabe038 stepper: Return homing offset in steps instead of an absolute position
Rename get_homed_position() to get_homed_offset() and return the
endstop position delta in steps instead of an absolute position
relative to position_endstop.  The conversion to absolute positions
can be dependent on the type of kinematics in use, so is inappropriate
to do in the low level stepper.py code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-13 10:09:56 -04:00
Kevin O'Connor 3809e4c055 gcode: Reset current position after an endstop error
If the printer is commanded to an invalid location, reset the current
position to the last successfully commanded position.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-11 15:10:19 -04:00
Kevin O'Connor 7f8a94ff48 heater: Make it possible to disable min_extrude_temp for testing
Allow a config file to specify 'min_extrude_temp: 0' to disable the
minimum extrude temperature test.  This makes it easier to perform
testing on the avr simulator.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-11 00:21:30 -04:00
Kevin O'Connor ee56b14faa mcu: Fix endstop query timeout checking
Commit 0685802c changed the query endstop timeout to use host time
instead of the mcu clock.  However, it is possible for an endstop
homing request to be in the future which makes using the host time
inappropriate.  Revert back to using the mcu clock to determine when
to send an endstop query.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-11 00:21:24 -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 9faa0fbd25 extruder: Support a minimum extrude temperature
Allow the config file to specify the minimum temperature for the
extruder and check for that temperature prior to moving the extruder
motor.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-30 21:36:51 -04:00
Kevin O'Connor 3167e8ddbe extruder: Remove unnecessary getsection('extruder') call
The passed in config object is already pointing to the 'extruder'
section.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-30 21:36:51 -04:00
Kevin O'Connor b53da365a1 cartesian: Enforce endstop min and max boundaries
Verify that each move command is within range of the configured
minimum and maximum for each axis.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-30 21:36:51 -04:00
Kevin O'Connor 275b386856 toolhead: Allow kinematics class to verify the move prior to queuing it
Introduce a check_move() method in the extruder and cartesian
kinematic classes.  This allows the lower level classes to verify the
contents of the move prior to queing that move.

The speed and acceleration handling for special Z and extrude only
moves are also moved from the generic toolhead class to the low-level
classes.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-30 21:27:46 -04:00
Kevin O'Connor e9505697fb gcode: Keep a log of incoming gcode data and report it on a shutdown
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-30 21:27:46 -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 0685802cb8 homing: Support querying the current status of endstops
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-22 11:29:27 -04:00
Kevin O'Connor a7b81dc05c toolhead: Force a firmware shutdown on an unhandled exception
Check for unhandled exceptions and force the MCU to shutdown in that
case.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-22 11:15:17 -04:00
Kevin O'Connor 0824d32319 cartesian: Minor change to clarify end stop homing direction code
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-15 12:20:16 -04:00
Kevin O'Connor 94272ed072 heater: Add "ATC Semitec 104GT-2" thermistor definition
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-15 12:16:08 -04:00
Kevin O'Connor 7b2f6f89f0 heater: Remove redundant float conversion
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-15 12:15:35 -04:00
Kevin O'Connor 1bbcb51066 mcu: Write initial config commands when in file output mode
When doing serial file output debugging, write the config commands as
they are often useful to inspect.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-10 20:26:52 -04:00
Kevin O'Connor c5f50e73c2 mcu: Consistently use mcu_freq variable name (instead of clock_freq)
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-08-25 12:09:37 -04:00
Kevin O'Connor 7276c7085a mcu: Internally store _print_start_time instead of _print_start_clock
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-08-25 12:07:08 -04:00
Kevin O'Connor e52113a319 mcu: convert stepper, endstop, and digital_out to take mcu_time
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-08-24 16:42:25 -04:00
Kevin O'Connor 11ecac626d mcu: Convert PWM and ADC objects to take mcu_time instead of clock
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-08-24 15:16:02 -04:00
Kevin O'Connor 654546e338 stepper: Support stepper phase adjustments when homing
Add support for enhancing the precision of endstop switches by also
inspecting the phase of the stepper motor when the endstop triggers.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-07-28 11:22:28 -04:00
Kevin O'Connor 170389ef14 extruder: Add some additional comments
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-07-26 11:17:26 -04:00
Kevin O'Connor 92f81d51f4 homing: Move low-level coordinate manipulation to kinematic class
Rework the code so that the kinematic class (currently just
cartesian.py) has more control over the homing process.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-07-25 23:47:30 -04:00
Kevin O'Connor e9c03f2e4a gcode: Error on G20 (set units to inches) command
Respond with an error to a G20 command (instead of effectively
ignoring the command).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-07-25 22:46:11 -04:00
Kevin O'Connor dc37a07a8e extruder: Add support for "pressure advance" on extrusion
Add a config option to define an amount of additional filament to feed
into the extruder during acceleration and deceleration of the
extruder.  This can help ensure plastic is deposited in the correct
places during a print.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-07-25 21:57:23 -04:00
Kevin O'Connor c847606311 toolhead: Limit lookahead optimization to moves with similar extrude ratios
Only skip acceleration between moves if both moves perform a similar
amount of extrusion.  This ensures the extruder has sufficient time to
accelerate to and from each extrude move.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-07-22 15:42:19 -04:00
Kevin O'Connor 589017a3d6 stepper: Have caller calculate max jerk velocity
Allow the owner of the stepper object to cacluate the maximum step
jerk velocity.  This is used to ensure there is no communication error
between mcu and host.

Disable checking of jerk velocity for extruder stepper motors.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-07-22 15:42:18 -04:00
Kevin O'Connor d3c27c514f toolhead: Add some comments to acceleration code
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-07-16 21:33:35 -04:00
Kevin O'Connor 777a0b817b serialhdl: Calculate baudadjust from MCU's baud instead of host baud
Store the baud rate the MCU is configured for in the "identify" data
and use that rate when calculating the baudadjust parameter.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-07-16 21:33:35 -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 af99ab1645 extruder: Create a new class and python file to track the printer extruder
Create a new python file (extruder.py) to control the extruder heater
and stepper motors.  This separates the extruder control logic from
the cartesian robot code - making it easier to customize both the
kinematic control of the robot as well as the extruder.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-07-10 22:49:02 -04:00
Kevin O'Connor 4a527a46ce stepper: Store max_velocity/max_accel instead of max_step_velocity/accel
All users of max_step_velocity and max_step_accel end up multiplying
by step_dist anyway, so it's easier to store max_velocity and
max_accel.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-07-10 22:49:02 -04:00
Kevin O'Connor 5829aa8bd7 toolhead: Avoid using a dummy_move for an empty move_queue
Explicitly check for when the move_queue is empty and only call
move.calc_junction() when there is a previous move.  This avoids the
need to create a dummy "sentinal" move object and it simplifies the
code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-07-10 22:49:01 -04:00
Kevin O'Connor 9bb1ae079f toolhead: Merge lookahead.py into toolhead.py
Remove the lookahead.py file and move its code directly into
toolhead.py.  The MoveQueue() class is small and tightly coupled to
the toolhead code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-07-10 22:49:01 -04:00
Kevin O'Connor e0a9a1b800 toolhead: Split toolhead code from cartesian.py to new file toolhead.py
Separate out the toolhead logic to its own python file.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-07-10 22:48:59 -04:00
Kevin O'Connor 861f5a5387 cartesian: Separate out cartesian robot handling from ToolHead class
Separate out the low-level stepper motor kinematics handling from the
ToolHead class into its own class.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-07-10 22:47:54 -04:00
Kevin O'Connor 20ae4e5d98 cartesian: Rename CartKinematics class to ToolHead
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-07-10 22:47:13 -04:00
Kevin O'Connor b3e8b430e5 cartesian: Do acceleration and lookahead on requested coordinates
Perform all acceleration calculations and lookahead checks in
millimeters using the cartesian coordinate system of the request.  The
conversion to step coordinates is now done at the time of the step
timing creation.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-07-10 22:47:08 -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 409904c61c pins: Add Arduino Due pin name aliases
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-14 15:41:18 -04:00
Kevin O'Connor cc62a3dbf3 sam3x8e: Add initial support for Arduino Due boards
This adds basic support for running on the Atmel SAM3x8e
micro-controllers that are found in the Arudino Due boards.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-14 14:27:30 -04:00
Kevin O'Connor 343de9c454 serialhdl: Avoid using 1200 baud during serial reset
The Arduino Due uses a 1200 baud connection to signal an erase
sequence, so avoid it during normal serial resets.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-14 14:00:57 -04:00
Kevin O'Connor ff789058df console: Update the debugging console to support setting local varables
Add a "SET varname value" local command to the console.py script.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-13 23:18:58 -04:00
Kevin O'Connor 38f1d78e1b serialqueue: Add debugging helper functions for dumping a binary buffer
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-05 10:52:46 -04:00
Kevin O'Connor 3eafc83458 avr: Initial support for Atmel AT90USB1286 mcu
Add GPIO definitions for the AT90USB1286.  Add code for communicating
over USB port on AT90USB1286.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-05 10:52:45 -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