aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/mcu.py
Commit message (Collapse)AuthorAgeFilesLines
...
* stepcompress: Pass constant velocity and acceleration directly to C codeKevin O'Connor2017-04-071-17/+9
| | | | | | | | Update the C code to take velocity and acceleration directly in step distances and clock ticks. This simplifies the mcu.py python code as it only needs to do unit and axis conversion. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Change mcu_stepper.set_position() to take a location in millimetersKevin O'Connor2017-04-071-3/+7
| | | | | | | | | | Update the set_position() method to convert from millimeters to absolute step position. Also, update PrinterStepper.get_homed_offset() and mcu_stepper.get_commanded_position() to return millimeters. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Don't export the commanded_position variable from mcu_stepperKevin O'Connor2017-04-071-15/+17
| | | | | | | | | | Now that the kinematic classes call the mcu_stepper with millimeters and seconds it is no longer necessary for them to directly access the stepper's position in absolute steps. Rename mcu_stepper.commanded_position to mcu_stepper._commanded_pos to make clear it is not a variable intended to be externally accessed. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Pass delta velocity and acceleration directly to mcu_stepperKevin O'Connor2017-04-071-15/+25
| | | | | | | | Rework the parameters of step_delta_const() and step_delta_accel() so that they take velocity and acceleration directly in millimeters and seconds. This simplifies the delta.py kinematic code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Pass constant velocity and acceleration directly to mcu_stepperKevin O'Connor2017-04-071-12/+28
| | | | | | | | Rename step_sqrt/step_factor to step_accel/step_const and have them directly take the velocity and acceleration in millimeters and seconds. This simplifies the kinematic classes. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Rename self.ffi_lib to self._ffi_libKevin O'Connor2017-04-041-18/+19
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* endstop: Support halting more than one stepper on triggerKevin O'Connor2017-04-031-9/+21
| | | | | | | | Extend the endstop code so that more than one stepper can be halted during endstop homing. Some kinematic setups (eg, corexy) require an endstop to support this. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Log the mcu clock each time print_time is synchronizedKevin O'Connor2017-03-301-1/+4
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Defer MCU_adc register_msg until ready to receive messagesKevin O'Connor2017-03-161-3/+3
| | | | | | Register the callback handler only after it's required state is setup. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* klippy: Eliminate high-level build_config phaseKevin O'Connor2017-03-131-5/+5
| | | | | | | | | | Now that the mcu objects can be created prior to connecting to the mcu, it is no longer necessary to separate the init and build_config phases in the high-level code. Move the mcu objection creation from the build_config phase to the init phase and eliminate the build_config phase. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Delay setting of mcu_stepper.min_stop_intervalKevin O'Connor2017-03-131-18/+25
| | | | | | | | | Create a separate callback for setting the min_stop_interval. Also, move the setting of the stepper max_error from the stepper configs to the mcu config and rename it to max_stepper_error. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Allow each oid object to define its own build_config() methodKevin O'Connor2017-03-131-58/+81
| | | | | | | | Create a build_config() method on each oid object and call it just after connecting to the MCU. Move code that requires a connected state from the oid init to its new build_config method. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Support config mechanism for translating seconds to clock ticksKevin O'Connor2017-03-131-17/+14
| | | | | | | Introduce a TICKS() macro during config parsing that will translate time in seconds to time in clock ticks. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* pins: Simplify pin map alias setupKevin O'Connor2017-03-131-5/+2
| | | | | | | | Use map_pins() to obtain the pin mapping - don't export mcu_to_pins(). The functionality of mcu_to_pins() can be obtained by calling map_pins() with name=None. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* stepper: Introduce stepper_get_position command and remove from endstop.cKevin O'Connor2017-03-091-8/+11
| | | | | | | | Move the logic to calculate and report the stepper's current position from endstop.c to stepper.c. This localizes the stepper code into stepper.c. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Support inverted PWM pinsKevin O'Connor2017-03-091-4/+8
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* klippy: Support FIRMWARE_RESTART commandKevin O'Connor2017-03-081-2/+14
| | | | | | | | Add initial support for micro-controller resets via the Arduino reset mechanism. Also, automatically attempt a firmware restart if the printer CRC does not match. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Improve error messages on failure to config printerKevin O'Connor2017-03-081-2/+9
| | | | | | | Don't report a CRC mismatch if a shutdown or other failure occurs during config - instead report the appropriate details. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* fan: Default to using software PWMKevin O'Connor2017-03-081-5/+5
| | | | | | | Not all hardware has PWM support and there is no compelling reason to use hardware PWM for fans. Change the default to use software PWM. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* heater: Support max_power setting for heatersKevin O'Connor2017-03-031-1/+3
| | | | | | | | Change the mcu PWM value from an integer (0-255) to a float (0. - 1.). Add support for limiting the maximum power (as measured over a sufficiently long duration) to a particular heater. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* toolhead: Rework lookahead flush to be more stable during high cpuKevin O'Connor2017-02-121-1/+1
| | | | | | | | | | | | | | | | | Change the lookahead queue so that it attempts to buffer at least buffer_time_high amount of moves when first starting a print. This helps ensure the buffer is normally always full. If the buffer falls below buffer_time_low then it is either due to the end of a print or because octoprint/klippy is unable to keep up. Change the code so that in this case the lookahead queue will attempt to gather buffer_time_high amount of moves before restarting movement. Update the default buffer_time_low to 1 second and buffer_time_high to 2 seconds. With the above changes a smaller buffer_time_high and a larger buffer_time_low are more practical. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* reactor: Use the system monotonic clock instead of the normal system clockKevin O'Connor2017-02-061-6/+8
| | | | | | | | | | | | | The normal system clock can have sudden jumps if the system clock is changed. Use the system monotonic clock to avoid these sudden changes in time. It appears the Raspbian OS (which is used by OctoPi) is setup to update the system clock upon network connectivity. This could cause sudden system clock changes which could lead to Klippy processing errors. Using the monotonic clock eliminates these issues. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* stepcompress: Propagate errors back to python codeKevin O'Connor2017-02-061-17/+34
| | | | | | | Propagate error codes back to the python code and raise an exception on an error. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* klippy: Warn the user on common errors due to old firmwareKevin O'Connor2017-01-101-5/+5
| | | | | | | | Check for msgproto.error and warn the user about version firmware version mismatch. Raise msgproto.error when extracting firmware constants. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* basecmd: Improve accuracy of stats "sumsq" variableKevin O'Connor2017-01-091-4/+5
| | | | | | | | | | | | Use a base of 256 instead of 65536 when calculating the sum of the square of the clock differences in the stats. This makes the calculation more accurate. Export the new base via DECL_CONSTANT for the host to access. Use DIV_ROUND_UP() when adjusting for the base to ensure no lost ticks. Do the division after multiplication in the common case where the time between stats_task() invocations is less than 64K ticks. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Change the default baud rate to 250000Kevin O'Connor2017-01-021-1/+1
| | | | | | | Update the default baud rate in mcu.py to 250000 (as that is the default in all other places). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* stepcompress: Using normal message priority system during homingKevin O'Connor2016-12-301-5/+6
| | | | | | | | | | | | | | 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>
* mcu: Don't call steppersync_flush if steppersync not createdKevin O'Connor2016-12-281-0/+2
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Log the MCU configuration during connect phaseKevin O'Connor2016-12-241-3/+3
| | | | | | | Log the constants reported by the MCU and log the number of move items allocated after configuration. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Obtain the maximum adc value from the firmwareKevin O'Connor2016-12-231-2/+2
| | | | | | | Don't assume the hardware ADC has 10bit resultion - instead have the firmware define a constant and read that constant in the host. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Rework toolhead stalling to use greenletsKevin O'Connor2016-12-091-0/+2
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Rework homing to use greenletsKevin O'Connor2016-12-091-9/+12
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Rework endstop query to use greenletsKevin O'Connor2016-12-091-1/+7
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* delta: Rework delta math to avoid using inv_movexy_rKevin O'Connor2016-12-051-8/+12
| | | | | | | | | | | | | | | 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>
* gcode: Add support for CLEAR_SHUTDOWN commandKevin O'Connor2016-12-011-1/+5
| | | | | | Add ability to clear the MCU shutdown flag from the console. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Detect if the communication channel to the firmware is lostKevin O'Connor2016-11-301-4/+18
| | | | | | Detect a comms loss and report it to the user. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* klippy: Throw an exception if any required config parameter is missingKevin O'Connor2016-11-301-1/+1
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Raise a config error on an invalid pin name in the config fileKevin O'Connor2016-11-301-2/+8
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* klippy: Improve error reporting during connectKevin O'Connor2016-11-301-3/+2
| | | | | | | Catch exceptions during the connect phase and report them via the gcode interface to the user. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gcode: Support reading from gcode input before mcu is readyKevin O'Connor2016-11-301-1/+1
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Be careful to free memory allocated in C codeKevin O'Connor2016-11-301-2/+8
| | | | | | Free steppersync, stepcompress, and commandqueue objects. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Make SerialReader.send_with_response() blockingKevin O'Connor2016-11-291-35/+18
| | | | | | | Use the greenlet mechanism to wait for the response directly in the send_with_response() method. This simplifies the calling code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Make SerialReader.connect() blockingKevin O'Connor2016-11-291-10/+2
| | | | | | | Use the greenlet mechanism to wait for the connection to come up in the serial connect() method. This simplifies the calling code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* klippy: Run the MCU connect code within the reactorKevin O'Connor2016-11-291-9/+11
| | | | | | | | Setup the reactor and run the MCU connection code as a timer within the reactor. The connection code will make use of reactor greenlets so that it can wait for events during the connection phase. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Rename output_file_mode variable to is_fileoutputKevin O'Connor2016-11-291-3/+5
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* klippy: No need to define __str__ and __init__ methods on exception classesKevin O'Connor2016-11-291-7/+4
| | | | | | The base Exception class already defines these methods. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Handle adc initialization entirely in mcu codeKevin O'Connor2016-11-291-4/+12
| | | | | | | | Don't expose the ADC initialization to the gcode and heater code - instead, register a callback within the MCU_adc class and call it directly from the MCU class after configuration completes. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Track the stepper position in the MCU in the MCU_stepper classKevin O'Connor2016-11-281-1/+11
| | | | | | | Support tracking of both the commanded_position and the mcu_position in the MCU_stepper class. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Store the stepper position in the mcu_stepper classKevin O'Connor2016-11-191-4/+19
| | | | | | | Move the storage of the stepper location from the kinematic classes to the low-level mcu_stepper class. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* homing: Check for timeout during homing operationKevin O'Connor2016-11-181-3/+19
| | | | | | | | Should a homing move complete without hitting the endstop, then disable motors, disable the endstop checking, and report the error to the user. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>