493 Commits

Author SHA1 Message Date
Kevin O'Connor
bee179eab4 docs: Update release notes for v0.6.0 release
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-31 14:04:39 -04:00
Kevin O'Connor
039bb9f10f docs: Add Patreon link to FAQ page
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-31 13:55:41 -04:00
Kevin O'Connor
b0b4bc8958 heater: Add some comments to the thermistor math
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-29 16:40:26 -04:00
Kevin O'Connor
a6553538e6 docs: Update G-Codes.md with recent output_pin changes
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-28 15:11:10 -04:00
Kevin O'Connor
019666a6f6 docs: Add a section on adding new host modules to Code_Overview.md
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-28 13:12:41 -04:00
Kevin O'Connor
7579b9671b stepstats: Add documentation clarification
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-23 10:51:11 -04:00
Kevin O'Connor
99f3c99238 display: Round temperature and position to nearest whole number
The "%d" formatting truncates a floating point number - use "%.0f" to
show a rounded number.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-19 15:17:53 -04:00
Kevin O'Connor
aba04bf3bd display: Remove unneeded semicolons from file
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-19 15:16:01 -04:00
Kevin O'Connor
f5c67baac2 docs: Recommend running PID_CALIBRATE in Config_checks.md
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-18 12:43:41 -04:00
Kevin O'Connor
973ef97143 pid_calibrate: Move PID calibration logic from heater.py to new file
Drop support for M303 and PID_TUNE, and replace it with a new
PID_CALIBRATE command.  Move the logic for this command from heater.py
to a new pid_calibrate.py file in the extras/ directory.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-18 12:02:30 -04:00
Kevin O'Connor
310cdf88cc config: Remove tabs from printer-wanhao-duplicator-i3-v2.1-2017.cfg
Remove tabs from example config file and replace with spaces.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-18 11:44:56 -04:00
Kevin O'Connor
5c05a24947 docs: Fix typo in M220 description in G-Codes.md
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-18 11:44:56 -04:00
Kevin O'Connor
c93dad8eba config: Update generic-cramps.cfg with P9_23 machine enable
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-18 10:33:40 -04:00
Kevin O'Connor
fb3065cfa7 config: Change pullup_resistor to 2000 in generic-cramps.cfg
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-17 14:18:49 -04:00
Kevin O'Connor
e3f9ff6701 probe: Add z_offset parameter
Move the probe_z_offset parameter from delta_calibrate and
bed_tilt_calibrate to a z_offset parameter within the probe config
section.  It's easier to understand the z offset setting when it is in
the probe config section.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-17 14:07:15 -04:00
Kevin O'Connor
c95cc3fb66 bed_tilt: Take into account the XY position used with z_virtual_endstop
If a z_virtual_endstop is in use, then record the last XY position
that is used when the Z is homed.  Use that XY position to report what
change is needed to the z position_endstop.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-17 13:47:31 -04:00
Kevin O'Connor
1dda4628a0 bed_tilt: Require at least 3 probing points for bed_tilt_calibrate
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-17 13:47:31 -04:00
Kevin O'Connor
36612fd544 probe: Default z_position to the configured minimum position on Z axis
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-17 13:47:31 -04:00
Kevin O'Connor
ef8c464d97 output_pin: Move pwm and digital output pins to new module in extras/
Rename the digital_output, pwm_output, and static_pwm_output config
sections to output_pin and move to a new module in the extras/
directory.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-17 13:46:36 -04:00
Kevin O'Connor
66eefa1da8 static_digital_output: Add static_digital_output section to extras/
Move the code for the static_digital_output config section from
chipmisc.py to a new file in the extras/ directory.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-17 13:06:51 -04:00
Kevin O'Connor
e78377eebd replicape: Add config controls for the servo[01]_enable lines
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-17 12:55:48 -04:00
Kevin O'Connor
451f7d5672 gcode: Position returned by M114 should be relative to last G92
It looks like OctoPrint is expecting the result from M114 to be
relative to the last G92 command.  Also, introduce GET_POSITION to
report the actual location that the printer is at.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-15 20:00:51 -04:00
Kevin O'Connor
ef820d98f6 docs: Add "will heaters be turned off on a crash" item to FAQ
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-13 11:36:45 -04:00
Kevin O'Connor
9dfe612516 verify_heater: Provide additional information on a heater error
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-12 23:31:17 -04:00
Kevin O'Connor
830cfc5414 klippy: Rework starting error message
Commit 9bc4239e now emphasizes the first line of a multi-line error
message, so rework startup_message to conform to that.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-12 23:15:22 -04:00
Kevin O'Connor
45afa04578 probe: Add some hints for common errors during PROBE
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-12 23:00:50 -04:00
Kevin O'Connor
9bc4239e9c gcode: On a multi-line error message, report the first line twice
Report the first line of a multi-line error message twice - once as
part of the informational content, and once with the "!!" error
prefix.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-12 22:56:31 -04:00
Kevin O'Connor
3a1cdc7d70 virtual_sdcard: Fix typo in seek error handling
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-12 22:36:39 -04:00
Kevin O'Connor
3a75748762 config: Reword the min_temp/max_temp description in example.cfg
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-12 14:37:02 -04:00
Kevin O'Connor
e336c24665 heater: Allow min_temp to go below zero
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-12 14:36:45 -04:00
Kevin O'Connor
849f4ed25f verify_heater: Scale hysteresis duration check
If a heater falls out of the target range, accumulate the temperature
differences to determine if an error should be raised.  This should
make it less likely to report an error for heaters that drift slightly
out of range, and it should make error reporting faster for heaters
that rapidly fall out of range.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-11 19:21:32 -04:00
Kevin O'Connor
57d342b455 verify_heater: Change default hysteresis to 10 degrees
A default of 4 degrees and 10 seconds may be too aggressive - change
the default to 10 degrees and 15 seconds.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-11 13:29:28 -04:00
Kevin O'Connor
5208fc38ed verify_heater: Add initial support for verifying heaters and sensors
Add runtime checks to heaters and temperature sensors to check for
possible hardware faults.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-11 00:49:11 -05:00
Kevin O'Connor
b549c3927e klippy: Allow external callers of try_load_module()
It can be useful to automatically pull in a module in the extras/
directory.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-11 00:04:30 -05:00
Kevin O'Connor
e53a589ac3 docs: Add SET_DUAL_CARRIAGE command to G-Codes.md
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-10 20:22:13 -05:00
Kevin O'Connor
4d48c111d8 cartesian: Initial support for dual carriages
Add support for additional carriages on cartesian printers.  This is
used by some printers to handle multiple extruders.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-09 10:26:21 -05:00
Kevin O'Connor
6c1e1dcc8d display: Use separate hd44780 screen drawing
Separate out the hd44780 screen drawing from the st7920 code.  Use a
layout that takes advantage of the 20 columns.  Add custom hd44780
fonts.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-08 22:44:40 -05:00
Kevin O'Connor
ddcf9a7ff7 docs: Add Tx command to G-Codes.md
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-08 14:40:26 -05:00
Kevin O'Connor
05ec7ca7ff docs: Add a G-Codes.md file with the list of available commands
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-08 14:11:20 -05:00
ghandye
ef0c80af51 config: Add working printer configuration for Wanhao Duplicator i3 v2.1
Working printer configuration for a Wanhao Duplicator i3 v2.1 and its
clones, including Monoprice Maker Select and Cocoon Create. Includes a
working config for the st7920-based front panel LCD.

Signed-off-by: Andy Ellsworth <andy+github@dar.net>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-08 10:26:21 -05:00
christian mock
d997821e58 config: Add LCD configuration to printer-trony-x5s-2017.cfg
I've added the LCD configuration for the Tronxy X5S printer and its
Melzi board and 128x64 LCD. This is tested and works.

I've also added the pins for the encoder, but that is untested.

Signed-off-by: christian mock <cm@tahina.priv.at>
2018-03-07 15:56:07 -05:00
Kevin O'Connor
385e6b67d9 config: Add display section to creality cr10 config
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-07 13:40:33 -05:00
Marcio Teixeira
04602b2470 display: Choose arrow character based on display
Choose the arrow character based on whether the display is ST7920 or
HD44780.

Signed-off-by: Marcio Teixeira <marcio@alephobjects.com>
2018-03-06 14:01:10 -05:00
cruwaller
923954772f homing: allow to disable homing retract
Homing retract can be disabled by setting homing_retract_dist to 0.

Signed-off-by: Petri Honkala <cruwaller@gmail.com>
2018-03-06 13:45:48 -05:00
Kevin O'Connor
5a16863465 config: Fix hd44780 typo in rambo and ramps example configs
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-06 13:15:09 -05:00
Kevin O'Connor
08a5f8a5ff display: Add initial support for LCD screens attached to an MCU
Add support for displaying basic status information on ST7920 and
HD44780 based LCDs that are attached directly to a micro-controller.

Signed-off-by: Marcio Teixeira <marcio@alephobjects.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-06 11:30:46 -05:00
Kevin O'Connor
43ac56766e serialqueue: Support sending messages at a background priority
Support low-priority message transmits.  This may be useful for bulk
commands that should be delayed util the comms are otherwise idle.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-06 11:30:41 -05:00
Kevin O'Connor
afc9bcf27b lcd_hd44780: Add micro-controller code for the HD44780 LCD chip
Add support for passing messages to an HD44780 chip via a 4-bit
bit-banging interface.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-06 11:30:34 -05:00
Kevin O'Connor
9140f36d99 lcd_st7920: Add micro-controller code for the ST7920 LCD chip
Add support for passing messages to an ST7920 chip via a SPI
bit-banging interface.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-06 11:30:30 -05:00
Kevin O'Connor
fa07be9346 mathutil: Move coordinate_descent() to new file
Add a new python file (mathutil.py) and move the coordinate_descent()
code to it.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-04 09:56:50 -05:00
Kevin O'Connor
7290ed5f73 clocksync: Fix multi-mcu frequency adjustments with long moves
Commit 02ae2ab9 had a typo causing the new long move handling logic to
not take effect.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-03 21:54:25 -05:00
Kevin O'Connor
fc60bda4d1 virtual_sdcard: Remove trailing '*' checksum indicator from M23 command
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-02 11:58:00 -05:00
Kevin O'Connor
82a65e9f4a docs: Note the use of the virtual_sdcard feature
Note that virtual_sdcard helps on slower machines.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-02 11:28:01 -05:00
Kevin O'Connor
b139a8561f serialhdl: Add a wrapper around the results of lookup_command()
Add a lookup_command() method to the SerialReader class that provides
a wrapper that stores the serial and commandqueue references.  This
makes it easier to run the send() method.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-27 21:06:16 -05:00
Kevin O'Connor
8518da9824 config: Move description of phase adjusted endstops to config-extra.cfg
Move the description of stepper phase adjusted endstops to a new
section in config-extra.cfg.  This keeps the main example config file
a little more concise.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-27 09:34:25 -05:00
Kevin O'Connor
656cb2c417 build: Use git describe --always
Add --always flag to "git describe" command to get a build identifier
even if one checks out the repo with a depth parameter that prunes out
the last tagged version.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-26 21:50:05 -05:00
Kevin O'Connor
239c1ad5c9 serialqueue: Don't clear must_exit flag at start of pollreactor_run()
Avoid a timing race where must_exit is set before pollreactor_run() is
started.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-26 16:21:10 -05:00
Kevin O'Connor
7733e1d832 test: Add travis_fold markers to build output
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-26 15:21:39 -05:00
Kevin O'Connor
99b4122901 test: Add compile tests for at90usb1286 and atmega1284p chips
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-26 15:03:05 -05:00
Kevin O'Connor
28d70eaf0c test: Update travis build to include a basic klippy host test
Move the travis installation steps from the travis-build.sh script to
a new script (scripts/travis-install.sh).  Move the travis-build.sh
script to the scripts/ directory as well.

The data dictionaries built in the compile tests are useful during
host software testing, so run all the compile tests sequentially in a
single VM and save the data dictionaries after each build.  Also,
build all the config files found in the test/configs/ directory.

Create the python virtualenv environment during the install phase and
invoke the klippy.py host software in the build phase to perform a
basic host software sanity check.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-26 14:58:49 -05:00
Kevin O'Connor
5d635c5252 config: Use .0025 as the default z step_distance in sample configs
Don't use tiny step distances on the Z as that could cause a surprise
to users that copy the config without updating all the settings.  (A Z
step distance that is too small would cause a high motor velocity.)  A
step distance of .0025 is very popular in practice, so change the
default example configs to use that.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-25 16:00:55 -05:00
Kevin O'Connor
22d7e48aa2 config: Add an example config file that uses multiple MCUs
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-25 12:59:09 -05:00
Sebastian Meyer
a6b0649cb1 test: Add travis CI
Signed-off-by: Sebastian Meyer <ich@sebmeyer.de>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-25 10:54:59 -05:00
Sebastian Meyer
58dd6d9106 build: Link objects ahead of libraries to avoid failures on some platforms
Signed-off-by: Sebastian Meyer <ich@sebmeyer.de>
2018-02-25 10:39:06 -05:00
Douglas Hammond
d139389267 avr: Add at90usb646 support
Signed-off-by: Douglas Hammond wizhippo@gmail.com
2018-02-25 10:23:00 -05:00
Kevin O'Connor
e99c0f53f8 graphstats: Support selecting an mcu to graph from the command-line
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-19 23:12:14 -05:00
Kevin O'Connor
02ae2ab984 clocksync: Rework multi-mcu adjust to better handle long moves
The multi-mcu clock syncing code relies on the ability to periodically
update the mcu clock adjustments.  If a series of very long moves are
submitted then it is possible the adjustments could become unstable.
For example, if an adjustment is made to reduce a clock error over the
next couple of seconds, but it is applied to a longer period because
the next move lasts many seconds, then this would result in a bigger
adjustment for the following move, which would result in an even
bigger error when that move lasts many seconds.  This can repeat until
the system destabilizes.

Check for cases where the print_time is far in the future of the
current estimated print time and average over a longer period in that
case.  That should reduce the possibility of the adjustment code
becoming unstable.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-19 22:13:28 -05:00
Kevin O'Connor
97f7735c6a graphstats: Set size on frequency graph
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-18 20:42:28 -05:00
Kevin O'Connor
69486e45c1 ad5206: Warn if ad5206 enable pin is inverted
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-17 23:18:10 -05:00
Kevin O'Connor
5e8aaed41f docs: Add tips for porting to new kinematics to Code_Overview.md
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-17 13:48:53 -05:00
Kevin O'Connor
c128a9dfd5 probe: Increase calibration log level from debug to info
Output more information by default from the bed_tilt and
delta_calibrate commands.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-16 13:30:49 -05:00
Kevin O'Connor
6dc623b35d config: Expand homing_override description in sample-bltouch.cfg
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-13 15:29:49 -05:00
Kevin O'Connor
8fc3487a8a config: Reword description of set_position_x paramter in homing_override
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-11 15:35:10 -05:00
Kevin O'Connor
82db072151 config: Add a config snippet for the BLTouch probe
Add an example to help users with a BLTouch probe.  This is based on
information from @mediumo and @riddlez666.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-11 15:11:11 -05:00
Kevin O'Connor
41f73d0c8c config: Add a "printer-" prefix to example printer config files
Add a prefix to the example printer config files so that a sorted
directory listing shows all the samples bundled together.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-11 14:58:48 -05:00
Kevin O'Connor
08a1183a01 virtual_sdcard: Initial support for virtual sdcard
Add support for directly printing from a local file on the host.  This
may be useful if the host cpu is not fast enough to run OctoPrint
well.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-11 14:13:12 -05:00
Kevin O'Connor
f77e1b67f6 gcode: Introduce request_restart() method
Use request_restart() method instead of prep_restart() and
motor_heater_off().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-11 14:11:33 -05:00
Kevin O'Connor
11c7c110a1 gcode: Extract special cases from process_data()
Handle the unlikely case of pending commands in a new method
process_pending().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-11 14:10:09 -05:00
Dave Bacon
5abea041b4 mcu: Fix PWM static start value setup
config_setup uses ._start_value instead of ._static_value which isn't defined.

Signed-off-by: Dave Bacon <drb.github@mrbacon.com>
2018-02-10 13:00:22 -05:00
Dave Bacon
268d1cb27c docs: Update Config_checks.md
Navigation should be to the temperature tab to find the Tool temperature box.

Signed-off-by: Dave Bacon <drb.github@mrbacon.com>
2018-02-07 22:24:32 -05:00
Kevin O'Connor
561c84dd93 pins: Warn on invalid pin format
Raise an error if a pin description isn't formatted correctly.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-07 16:09:25 -05:00
Kevin O'Connor
955d940b60 bed_tilt: Negate parameters reported by bed_tilt_calibrate
The bed_tilt_calibrate command determines the tilt of the bed.
However, we need to report the tilt compensation which is the negative
of the bed tilt.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-05 14:52:38 -05:00
Kevin O'Connor
6ea36de9f2 config: Add a pointer to example-extras.cfg at the end of example.cfg
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-05 14:34:05 -05:00
Kevin O'Connor
e0cedfb853 heater: Report stats whenever the heater is active
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-05 13:55:59 -05:00
Kevin O'Connor
0a5b07f9da klippy: Allow any stats producer to determine when stats are needed
Instead of using the toolhead class to determine if stats should be
reported, allow every printer object with a stats() callback to
determine if stats are needed.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-05 13:52:05 -05:00
Kevin O'Connor
08874b9c91 clocksync: Respond faster to clock changes
Average clock sync times over approximately 30 seconds instead of 120
seconds so that the clock prediction responds to changes faster.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-05 12:33:29 -05:00
Kevin O'Connor
8121a4a29f avrsim: Rework pacing mechanism
Rework the pacing mechanism to make it more stable.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-05 11:38:13 -05:00
Kevin O'Connor
d1c209c689 graphstats: Fix multi-mcu parsing with reordered stats
The mcu stats (that contain a prefix) may occur before some other
stats - make sure to only apply the stats prefix to those stats that
need it.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-03 18:43:52 -05:00
Kevin O'Connor
f4bfce260a klippy: Introduce load_config_prefix() for modules that take parameters
Use both load_config() and load_config_prefix() functions when
dynamically loading a module from the extras directory - if the config
section name has parameters in it then use load_config_prefix().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-03 12:53:11 -05:00
Kevin O'Connor
7e3adde542 klippy: No need to store fileconfig in main printer object
Just pass the fileconfig reference to the ConfigWrapper instances.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-03 12:17:42 -05:00
Kevin O'Connor
33bdc2fc32 util: Call set_nonblock() in create_pty()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-02 18:32:03 -05:00
Kevin O'Connor
0b76864453 gcode: Make sure need_ack is always restored on run_script()
Restore need_ack even on a G-Code exception.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-02 18:32:03 -05:00
Kevin O'Connor
56bfb3280a gcode: Keep reading input to check for M112 (emergency stop)
OctoPrint (and other software) will sometimes send additional commands
even if the previous command has not yet responded with an "ok".
Change the g-code input reading code to keep reading input so that an
M112 can be detected (and processed out-of-order).  To avoid the
extreme case where one writes an entire g-code file to the input
without any pacing, disable the input reading if more than 20 commands
are pending.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-02 11:00:46 -05:00
Kevin O'Connor
3ddbd34a7c gcode: Propagate errors from run_script()
If the script being run raises an error, then stop running that script
and return the error to the caller.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-01 12:18:47 -05:00
Kevin O'Connor
67f9c4948d gcode: Ack even empty lines
An empty input line should still return an "ok" message.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-02-01 11:03:49 -05:00
Kevin O'Connor
7d3600f918 docs: Add github issue template
Add an issue template requesting the klippy log file.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-31 14:30:05 -05:00
Kevin O'Connor
21df21b7af fan: Clarify hardware_pwm and allow cycle_time to be set on software pwm
Specify hardware pwm cycle times using the same method as software pwm
(in seconds, not clock ticks).  Allow the fan code to be configured
with an explicit cycle time even when using software pwm.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-29 13:08:15 -05:00
Kevin O'Connor
b7b216af7f avr: Round hardware pwm clock ticks to nearest divisor
Instead of rounding down to the nearest supported pwm divisor, round
to the nearest divisor.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-29 11:54:15 -05:00
Kevin O'Connor
077a56c2ca mcu: Default the restart method to 'command' on non-serial ports
If the mcu supports command restarts and it does not appear to use a
real serial port, then default the restart method to 'command'.  This
is a better default on boards with native USB support.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-29 10:25:25 -05:00
Kevin O'Connor
a67306c76b msgproto: Support default values in get_constant() calls
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-29 10:10:27 -05:00
Kevin O'Connor
6eefbe5e30 heater: Add stats reporting
Report the current temperature, current pwm setting, and target
temperature as statistics in the log.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-28 23:37:56 -05:00
Kevin O'Connor
650d55d7b2 docs: Remove bed level probe from todo
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-28 20:36:04 -05:00
Kevin O'Connor
03bcae8a98 config: Add SeeMeCNC Rostock Max V2 Delta Printer Config
As provided by @FEsmondeWhite

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-28 20:31:15 -05:00
Kevin O'Connor
1a67902858 homing_override: Allow moves prior to homing an axis
Add support for disabling homing checks via the homing_override
mechanism.  This may be useful to move an axis prior to homing it.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-28 12:19:26 -05:00
Kevin O'Connor
01bb4b291e probe: Create a probe:z_virtual_endstop pin
Create a virtual pin that may be used as the z endstop pin on
cartesian printers that use the probe in place of a z endstop.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-28 12:19:26 -05:00
Kevin O'Connor
e38c7df064 probe: Support activate/deactivate scripts on each probe
Allow a set of g-code scripts to be run on each probe invocation.
This may be useful for probes that need to be setup before they are
useful (eg, with servo actuated probes).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-28 12:19:26 -05:00
Kevin O'Connor
3001a089c0 homing_override: Add basic support for running custom g-code on G28
Allow users to override the behavior of G28 using a new
"homing_override" config section.  This may be used on printers that
require specific steps during the homing process.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-28 12:19:26 -05:00
Kevin O'Connor
39d62556b1 bed_tilt: Add support for automatic bed tilt move transformation
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-28 12:19:26 -05:00
Kevin O'Connor
434341d074 delta_calibrate: Add initial support for a DELTA_CALIBRATE command
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-28 12:19:26 -05:00
Kevin O'Connor
ce9db609ad probe: Initial support for Z-Probe hardware
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-28 12:19:26 -05:00
Kevin O'Connor
6c252d30f5 delta: Allow the user to specify a minimum z position
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-28 12:19:26 -05:00
Kevin O'Connor
978777f09f replicape: Move the replicape code from chipmisc.py to extras directory
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-28 12:19:26 -05:00
Kevin O'Connor
5db84779c6 ad5206: Move the ad5206 code from chipmisc.py to extras directory
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-28 12:19:26 -05:00
Kevin O'Connor
1e3a03fbee servo: Move the servo code from chipmisc.py to extras directory
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-28 12:19:26 -05:00
Kevin O'Connor
01a89b951a multi_pin: Move the multi_pin code from chipmisc.py to extras directory
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-28 12:19:26 -05:00
Kevin O'Connor
d166d1f692 fan: Move fan code to extras directory
The print cooling fan and printer heater_fan are independent modules
that can reside in the extras directory.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-28 12:19:26 -05:00
Kevin O'Connor
9399911490 klippy: Add support for dynamic loading of python modules
Check if a config section matches a python filename in the
klippy/extras/ directory.  If it does, load that python code to handle
the config section.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-28 12:19:26 -05:00
Kevin O'Connor
d3665699f1 klippy: Support generic printer_state() and stats() callbacks
Instead of hardcoding which objects are called on state transitions,
allow any "printer object" to be invoked if it has a printer_state()
method.  Convert connect, ready, shutdown, and disconnect callbacks to
this mechanism.

Similarly, allow all printer objects to provide a stats() callback.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-28 12:19:26 -05:00
Kevin O'Connor
81013ba5c8 klippy: Add access methods and avoid peeking into the printer classes
Add get_reactor(), lookup_object(), lookup_module_objects(), and
set_rollover_info() to the main Printer class so that callers do not
need to peek into the class' members.  Similarly, add get_printer()
and get_name() methods to the ConfigWrapper class.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-28 12:19:26 -05:00
Kevin O'Connor
f0a754e496 gcode: Add a run_script() helper method to run g-code scripts
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-28 12:19:26 -05:00
Kevin O'Connor
51e1085dbc gcode: Extend register_command() so that it can also unregister a command
If register_command() is passed None as the function to call, then
treat it as an unregister command request.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-28 12:19:26 -05:00
Kevin O'Connor
47bb8b7cc2 graphstats: Fix for print_stall detection
The print_stall logic could cause large portions of the graph to show
up as 100% host utilized.  Rework the logic to avoid that.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-28 10:50:52 -05:00
Kevin O'Connor
33893ece1d logextract: Fix error in config file name print
Fix typo causing an error during the printing of the config file name.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-28 10:50:43 -05:00
Kevin O'Connor
1b3ef8a8fb config: Update anycubic-i3-mega-2017.cfg with stepstick fan
Based on conversation with Marcin Jedliński.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-22 11:28:20 -05:00
Kevin O'Connor
09eec3710d extruder: Add support for extruders sharing the same heater
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-21 23:25:11 -05:00
Kevin O'Connor
6fa95e12ea config: Update wanhao-duplicator-i3-plus-2017.cfg heater settings
Update config based on discussion with Max Holden and Josh Sutinen.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-21 18:52:14 -05:00
Kevin O'Connor
7a11b78fd4 config: Update anycubic-i3-mega-2017.cfg heater settings
Updates to heater settings.  Based on discussion with @bartolomeus and
Marcin Jedliński.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-21 18:47:34 -05:00
Kevin O'Connor
3d26bf6635 logextract: Better handle the case of a missing config section
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-21 15:56:13 -05:00
Kevin O'Connor
08444a8b89 docs: Try to make the klippy.log bug reporting more clear
Emphasize that the log file needs to be attached to the issue.
Encourage M112 to be issued on every bug report.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-21 13:08:31 -05:00
Kevin O'Connor
84c623e705 config: Add example generic-mini-rambo.cfg config file
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-17 01:00:20 -05:00
Douglas Hammond
72074078f9 config: Add tronxy x5s config
Signed-off-by: Douglas Hammond <wizhippo@gmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-16 22:20:55 -05:00
Kevin O'Connor
1d11c4e74d gcode: Use reset_last_position() from cmd_G28()
Use the existing reset_last_position() code in cmd_G28() instead of
manually implementing the logic.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-16 21:46:42 -05:00
Kevin O'Connor
f8bb383e9a extruder: Remove unused variable self.config
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-16 21:40:53 -05:00
Cymen Vig
8e5d228555 Add a CR-10S configuration file.
Signed-off-by: Cymen Vig <cymenvig@gmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-16 18:29:45 -05:00
Kevin O'Connor
6770aa96c9 graphstats: Use alpha transparency when plotting the stats
Use an alpha transparency on each of the stats, so that it is possible
to see how the values overlap.

Also, always enable the "awake time" stat - just use a lower alpha
transparency for it.

Also, explicitly set the graph size as some version of matplotlib have
a different default.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-14 10:46:48 -05:00
Kevin O'Connor
896c31fd05 graphstats: Fix filtering of normal buffer_time runoff stats
Update the mechanism to filter out cases where buffer_time is below
MAXBUFFER so that it works with the statistics currently generated.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-14 10:16:16 -05:00
Kevin O'Connor
054cbbe094 docs: Add a FAQ item on steps to upgrade the software
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-12 18:38:49 -05:00
Kevin O'Connor
0d8ddcadbb toolhead: Improve tracking of print_stall
The previous code increases print_stall if a move is proactively
flushed due to buffer_time_low and a follow up move is ready to send
before the existing moves are fully retired.  However, this would not
track the case where a move is proactively flushed and it takes an
extended amount of time to get sufficient moves to refill the queue.

Change the code so that print_stall increases anytime a new move is
queued after a proactive flush and there are existing moves not yet
fully retired.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-12 16:56:31 -05:00
Kevin O'Connor
d3eda337a9 logextract: Fix parsing of "is_shutdown" messages
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-12 16:44:21 -05:00
Kevin O'Connor
138f3c2646 config: Update avrsim.cfg to use unique pins
Commit 3833669c added checking that each pin is used once in the
config.  This exposed an error in the avrsim.cfg testing config -
analog1 conflicts with ar25.  Use analog7 to avoid this.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-12 16:44:21 -05:00
Kevin O'Connor
f1222565b8 docs: Update Debugging.md with information on logextract
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-11 13:48:40 -05:00
Kevin O'Connor
5caff594c5 heater: Report PID tuning results via the g-code terminal
Determine the median period from the pin tuning tests and use that to
recommend a set of PID parameters.  Report the results over the g-code
terminal.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-10 22:58:12 -05:00
Kevin O'Connor
5a68c636da chipmisc: Enable replicape steppers dynamically
Enable all the steppers via the shift registers when the first stepper
is enabled, and disable all the steppers once all steppers are
disabled.  This avoids having to enable all the steppers all of the
time.  Note that, this support is independent from the current control
for each stepper, which is still done individually.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-10 19:30:57 -05:00
Kevin O'Connor
02b141ac43 chipmisc: Fix replicape enable line setup
The enable lines are not one per stepper - instead there are 5
distinct enable settings.  Handle them properly.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-10 19:30:51 -05:00
Kevin O'Connor
47e458210e chipmisc: Support start values on pca9685 pins
Default the pca9685 enable line on if any of the pins attached to it
have a non-zero start value.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-10 19:30:47 -05:00
Kevin O'Connor
3833669c3a pins: Check if the same pin is referenced via different aliases
Change the update_command() call to use a new PinResolver class.  In
that new class, verify that the same pin isn't referenced in two
different parts of the config using different aliases for the pin.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-10 19:26:06 -05:00
Kevin O'Connor
df6528715e stepper: Automatically detect and handle shared stepper enable lines
It's common for multiple steppers to use the same stepper enable
line.  Detect this and only create a single digital_out oid on the
micro-controller.

Also, prohibit any other pin from being used multiple times in the
config file.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-10 19:10:26 -05:00
Kevin O'Connor
265b9097d5 pins: Rename parse_pin_desc() to lookup_pin()
Always set the pin_params['type'] field on a pin lookup.  Rename
parse_pin_desc() to lookup_pin() to make the change more clear.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-10 14:21:25 -05:00
mjedlinski
a6025686b6 config: Config file for Anycubic i3 Mega
Signed-off-by: Marcin Jedliński <mjedlinski@gmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-08 23:11:41 -05:00
Kevin O'Connor
ed80b92b59 mcu: Setup static values via setup_start_value() call
Add an "is_static" setting to setup_start_value() and remove the
setup_static() method.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-08 21:21:30 -05:00
nerobot
45e65580f7 config: Create creality-cr10
Signed-off-by: Steven Daglish <s.c.daglish@gmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-08 18:48:03 -05:00
Kevin O'Connor
f6f174ab36 extruder: Fix pressure advance on tiny moves with over extrusions
The extruder check_move() code will permit moves with huge extrusion
ratios if the amount extruded is tiny.  (Some slicers emit these silly
moves - they are allowed because they are harmless.)  Unfortunately,
the pressure advance code did not handle the huge extrusion ratios -
it would result in a massive, near instantaneous, extruder move in an
attempt to build pressure in the extruder.  Catch this case and limit
the impact to the pressure advance code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-08 14:39:19 -05:00
Kevin O'Connor
0cf06ee69a docs: Note pressure_advance over 0.20 is unlikely to improve quality
Update the pressure advance tuning document to note that 0.20 is
likely the ceiling of a useful pressure advance setting.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-08 11:07:26 -05:00
Kevin O'Connor
ed9dee4602 mcu: Only report an MCU timeout once
Don't flood the log with timeout messages.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-08 10:55:37 -05:00
tilsonm
f183871e28 config: Adopt Anet A8 cfg, Anet v1.0-1.5 Boards
This configuration file should work as a base for Anet A8 printers
using the stock Anet v1.0-1.5 boards from late 2016-2017, which are
based around the AVR atmega1284p. Minor tweaks may be required to such
things as /dev/serial/by-id/, thermistor sensor types, and offsets for
carriage and bed.

Signed-off-by: Matt Tilson <tilsonm09@gmail.com>
2018-01-07 22:22:08 -05:00
Kevin O'Connor
d891baa860 avr: Clear the TCNT1 register on timer startup
Just to be safe, clear the TCNT1 register during init.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-07 22:22:08 -05:00
Kevin O'Connor
f6cd51bfb7 avr: Clear the ADCSRA/ADCSRB registers on ADC init
When initializing the ADC, explicitly clear the registers (instead of
logically or'ing them with their previous values).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-07 22:13:39 -05:00
Kevin O'Connor
83e9e92b9a docs: Add a table of contents to the FAQ
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-05 11:42:00 -05:00
Kevin O'Connor
9e4eb050f9 config: Note the need to flash a bootloader on the Melzi
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-05 10:23:58 -05:00
Kevin O'Connor
5a86391f78 avr: Only use the avrdude "wiring" protocol on atmega2560 devices
It appears the most common type of avrdude protocol for devices other
than the atmega2560 is the "arduino" protocol.  Update the build to
select a different protocol based on the avr processor type.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-05 10:02:15 -05:00
Kevin O'Connor
29c83cec22 docs: Update installation document with pointers to FAQ
Add some pointers to the FAQ for common pitfalls during installation.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-04 13:29:17 -05:00
Josh Sutinen
db927bd822 config: Added Wanhao Duplicator i3 Plus configuration
The Wanhao Duplicator i3 Plus (aka Maker Select Plus,
Microcenter Powerspec Plus, and others) uses an
atmega2560 AVR. The config is based on generic-ramps.cfg
with pin numbers updated from the official Wanhao Marlin
sources at https://github.com/garychen99/Duplicator-i3-plus

Signed-off-by: Josh Sutinen <josh@damagedgoodz.net>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-04 12:10:01 -05:00
Chris Lee
cb969527bc config: Update TAZ6 defaults for hotend
Use values from Lulzbot fork of Marlin.

Signed-off-by: Chris Lee <clee@mg8.org>
2018-01-04 10:58:47 -05:00
Kevin O'Connor
3ab9a8d26c gcode: Add support for M221 (set extrude factor) g-code command
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-03 17:12:31 -05:00
Kevin O'Connor
5db4886c9c gcode: Add support for M220 (set speed factor) g-code command
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-03 17:12:26 -05:00
Andy Silverman
b22a81cd34 heater: Added config for heater PWM cycle time.
Added the pwm_cycle_time option for heater config sections.  Defaults
to previous value of 0.100 seconds, but may be reduced to shorter times
at the expense of MCU workload and possible MOSFET heating, depending on
controller design.  Some printers that need bed PID to be enabled,
notably the Felixprinters series, are known to benefit from shorter
cycle times, as the default 10hz rate results in excessive voltage
supply droop.

While this option can be used on extruder heaters as well, there
is not expected to be any particular benefit from doing so unless
the extruder heater presents a particularly large load.

Signed-off-by: Andy Silverman <andrewsi@outlook.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-03 12:32:11 -05:00
Chris Lee
9fc5506c83 config: Add Lulzbot TAZ6 printer configuration
Signed-off-by: Chris Lee <clee@mg8.org>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-03 12:10:40 -05:00
Kevin O'Connor
bba22ab7f0 heater: Provide symbolic names for pid check_busy (aka M109 / M190)
Add PID_SETTLE_DELTA and PID_SETTLE_SLOPE constants to the code to try
and make it a little more clear how the wait for temperature code
works.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-03 10:44:01 -05:00
Kevin O'Connor
a0b4cdb5c4 gcode: Don't wait for temperature if the temperature is disabled
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-03 10:33:10 -05:00
Kevin O'Connor
e4129a7e53 docs: Minor update to square.scad
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-02 21:56:29 -05:00
Kevin O'Connor
00ea3934ee logextract: Add support for extracting shutdown info on multiple mcus
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-02 21:48:25 -05:00
Kevin O'Connor
cf4c31cb88 graphstats: Add support for generating a graph of mcu frequency
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-30 18:29:58 -05:00
Kevin O'Connor
f10bd5726d graphstats: Use a smaller font in the graph legend
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-30 18:27:44 -05:00
Kevin O'Connor
7db6fa7bfc graphstats: Fix case where an Xwindows display may not be available
Matplotlib will try to open a display by default - tell it not to do
that so that it can run in batch mode on headless machines.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-30 18:26:49 -05:00
Kevin O'Connor
b05eb1e8e3 logextract: Fix handling of messages with retransmits
Properly handle the case where the original sequence number of a
message is not known.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-29 15:25:39 -05:00
Kevin O'Connor
1bdebeaebf docs: Add an initial configuration checklist document
Provide a document with basic steps that a user can run to verify that
the pins in the configuration file are set correctly.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-26 20:54:37 -05:00
Kevin O'Connor
479772ca00 docs: Add a CONTRIBUTING document
Add an initial document detailing best practices for contributing to
the document.  Add the "developer certificate of origin" document.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-24 12:33:01 -05:00
Kevin O'Connor
1d276d160f gcode: Dump internal g-code state in dump_debug()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-21 22:27:49 -05:00
Kevin O'Connor
9313e58123 gcode: Group similar G-Code commands together
Group commands by category instead of listing them in numerical
order.  This is just code movement; no code changes.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-21 20:58:25 -05:00
Kevin O'Connor
d778ae1846 build: Add gcc and binutils version to mcu data dictionary
Store the gcc and binutils versions used in the compilation of the
firmware in the firmware data dictionary.  Forward that information to
the log so it is available during debugging.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-21 20:32:10 -05:00
Kevin O'Connor
522093ef00 docs: Offer alternatives to ssh/scp/sftp
Try to make the Installation document more friendly to users not
familiar with the Linux command-line.  Offer some hints on how to
obtain ssh and how to edit the config file remotely.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-21 17:34:35 -05:00
Kevin O'Connor
d303e556ad sched: Interrupts must be disabled during setjmp() call
On the AVR platform (and possibly others) the longjmp() call will
restore the interrupt state saved during the setjmp() call.  So, the
setjmp() call must be invoked with interrupts disabled to ensure that
shutdown handling is run with interrupts disabled.  This fixes
potential corruption of the shutdown processing on AVR.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-21 12:54:33 -05:00
Kevin O'Connor
1d21bf66c6 homing: Handle speed rounding when homing speed greater than max_velocity
Commit 002dc0df added rounding to the homing speed, but it did not
work if the configured homing speed was less than the printer's
maximum velocity.  Move the speed rounding from stepper.py to
homing.py and make sure the rounded speed is less than the maximum
speed.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-20 14:41:20 -05:00
Kevin O'Connor
1b07505973 chipmisc: Add multi_pin capability
Add the ability to alias multiple output pins from a single pin alias.
This makes it possible to support some cases where a single logical
output is driven by multiple output pins.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-18 21:00:06 -05:00
Kevin O'Connor
3c5649219f chipmisc: Add support for output pins set at runtime
Add the ability to define output pins that may be set at runtime with
a new SET_PIN extended g-code command.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-18 20:59:07 -05:00
Kevin O'Connor
68d03e4a3e mcu: Allow both shutdown and startup values to be set for output pins
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-18 20:45:00 -05:00
Kevin O'Connor
e6e0a21b06 toolhead: Allow junction_deviation to be set to zero
Allow lookahead to be effectively disabled by setting
junction_deviation to zero.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-18 20:44:59 -05:00
Kevin O'Connor
0e0780a460 logextract: Update file comment
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-18 12:14:10 -05:00
Kevin O'Connor
9a4425c85a docs: Update square test print to contain notches on inside of square
Add additional notches and move them to the inside of the square where
they will not impact the outside perimeter test.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-17 12:18:25 -05:00
Kevin O'Connor
57c27f75ae gpiocmds: Clear SPF_NEXT_* flags on new schedule_soft_pwm_out
Properly handle the (unlikely) case that a schedule_soft_pwm_out
command is received before a previous command is fully processed,

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-16 20:21:38 -05:00
Kevin O'Connor
8d62318c5f clocksync: The clock estimate should add the rtt time not subtract it
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-16 20:21:38 -05:00
Kevin O'Connor
add528532e logextract: Rename extractconfig.py to logextract.py and add shutdown parsing
Add initial support for extracting out shutdown information from a
klippy.log file.  The shutdown dump will be reordered into the
sequence that they occurred, and timestamps/sequence numbers in the
mcu message dump will be expanded.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-16 20:21:34 -05:00
Kevin O'Connor
8944e2104d docs: Add FAQ item on AVR watchdog restart failures
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-11 18:17:14 -05:00
Kevin O'Connor
319221ee23 docs: Provide additional information on "make flash" failures
Add some additional information on "make flash" problems.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-11 17:33:29 -05:00
Kevin O'Connor
4a5801bb2e pins: Fix atmega168/328 mappings
The atmega168 and atmega328 need to define PE0 and PE1 in order to
support the 2 extra analog pins.

Also, support the arduino mappings for the atmega328.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-09 11:48:26 -05:00
Kevin O'Connor
f8acf0f54f delta: Default stepper_b/c position_endstop to stepper_a's
If the position_endstop is not set for stepper_b or stepper_c then use
the value from stepper_a.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-08 18:20:04 -05:00
Kevin O'Connor
bc5d900e61 delta: Support different arm lengths for each tower
Change the config file so that the delta arm length is specified
per-tower.  This makes it possible to support advanced calibration.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-08 18:20:04 -05:00
Kevin O'Connor
efb4a5daa1 delta: Rework actuator_to_cartesian() using trilateration
Use the formulas for trilateration (instead of the circumcenter
formulas) when calculating the position of the nozzle from the
position of the carriages.  The trilateration formula is more general
and it allows each tower to have a different arm length.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-08 18:09:19 -05:00
Kevin O'Connor
e0c947e188 mcu: Store MCU_stepper commanded_pos as a float
It's valid to consider the stepper at a position that is not on a step
interval - only the "mcu position" needs to be an integer.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-07 18:14:50 -05:00
Kevin O'Connor
3ffab763c0 stepper: Only align the stepper motor to a full step when requested
Add a new config option 'homing_endstop_align_zero' to enable the
alignment of the endstop to a stepper full step.  It's possible one
may wish to specify a homing_endstop_phase while not aligning the
endstop.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-07 17:35:19 -05:00
Kevin O'Connor
ef09ac5a7f extractconfig: Add helper script that extracts config files from a log
Add a helper script that can read a klippy.log file and extract the
printer.cfg files from it.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-06 21:23:24 -05:00
Kevin O'Connor
f6d4284d5c homing: Directly interact with the kinematic class on query_endstops()
Move the query_endstop logic out of toolhead.py and into homing.py.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-06 19:13:54 -05:00
Kevin O'Connor
8d9ca6f2dd homing: Directly interact with the kinematic class when homing
Move the homing logic out of toolhead.py and into homing.py.  This
simplifies the toolhead logic and centralizes the homing code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-06 19:13:54 -05:00
Kevin O'Connor
1d6af72de5 mcu: Remove unneeded MCU_digital_out.get_last_setting() method
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-06 19:13:54 -05:00
Kevin O'Connor
2a8dd5c51f mcu: Reset the stepper step clock on init - not after each motor on
Reset the last step clock during the init phase and after each home -
this simplifies the runtime code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-06 19:13:54 -05:00
Kevin O'Connor
c78f66b8e8 mcu: Be sure all moves are completed before raising a home timeout
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-06 19:13:54 -05:00
Kevin O'Connor
b340fdcc4a homing: Make sure to clean up homing state even if homing fails
Make sure to always call MCU_endstop.home_wait() if
MCU_endstop.home_start() is invoked.  Rename
MCU_stepper.note_homing_triggered() to note_homing_end() and make sure
it is always called if MCU_stepper.note_homing_start() is invoked.

With these changes, MCU_endstop.home_finalize() is no longer needed.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-06 19:13:53 -05:00
Kevin O'Connor
7785d3a87d homing: Pass list of endstops (not steppers) to the homing code
The homing code wants the list of endstops to enable during a homing
operation - it's confusing to pass the steppers.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-06 18:49:14 -05:00
Kevin O'Connor
31db4cc772 mcu: Make sure steppers added to an endstop are on the same mcu
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-06 18:35:51 -05:00
Kevin O'Connor
7932de11a7 mcu: Make sure all endstop objects are disabled on a reconnect
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-06 18:35:51 -05:00
Kevin O'Connor
bc9cbc8133 gcode: Move SET_SERVO command from gcode.py to chipmisc.py
Now that commands can be registered dynamically, move the code for
SET_SERVO from gcode.py to the PrinterServo() class in chipmisc.py.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-06 18:35:51 -05:00
Kevin O'Connor
b5a41d0dd1 gcode: Rework gcode handler setup to allow dynamic command registration
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-06 18:35:51 -05:00
Kevin O'Connor
64a091fb98 gcode: Add a get_str() method
Add a get_str() method that can extract a required parameter from a
g-code command.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-06 18:35:51 -05:00
Kevin O'Connor
80f23441dd gcode: Simplify exception handling
Translate caught exceptions into a gcode.error() exception.  This way
there is one standard place to invoke respond_error().  Also, always
reset the last_position on a handled error.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-06 18:35:51 -05:00
Kevin O'Connor
3a2d16abb3 gcode: Always allow M112 command
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-06 18:35:49 -05:00
Kevin O'Connor
c70cc8fadb klippy: Always recommend a FIRMWARE_RESTART on a shutdown event
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-03 19:52:25 -05:00
Kevin O'Connor
10e11950ae stepper: get_homed_offset() should return a float
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-03 19:48:47 -05:00
Kevin O'Connor
37788c1e55 docs: Add a FAQ document
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-11-30 15:19:40 -05:00
Kevin O'Connor
6d6638826c stepcompress: Fix proactive queue flushing on move with 64K+ steps
Commit e05c6354 changed the internal step compress queue from 64bit
integers to 32bit integers.  However, that commit broke the proactive
flushing of moves that could produce more than 64K steps.  This could
lead to large memory allocations and cpu slow downs on printers that
had a very large Z axis - possibly leading to a "Timer too close" mcu
shutdown.  Correct the code so that it properly generates a 64bit
flush clock.

Also, be sure to only expand / memmove the queue when there is no room
for a new element at the end.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-11-29 20:24:50 -05:00
Kevin O'Connor
6930a7de8d homing: Base homing cpu delay on estimated number of steps needed
Instead of adding 250ms to each homing operation add a time relative
to the number of estimated steps that are to be generated.  This
scales the delay to really large axes without adding a delay for
normal users.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-11-29 19:55:25 -05:00
Kevin O'Connor
6bbb84326d docs: Add further details on how to report a bug
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-11-21 18:27:22 -05:00
Kevin O'Connor
8c2fa2e2d6 stepper: Support for multiple steppers controlling a single axis
Allow multiple steppers to be defined for a single cartesian axis.
This adds support for dual-z setups.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-11-18 17:37:04 -05:00
Kevin O'Connor
38643f52c9 stepper: Add get_endstops() / set_position wrappers
Add wrappers around mcu_endstop and mcu_stepper so that the kinematic
classes do not need to directly access these low-level classes.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-11-18 17:36:45 -05:00
Kevin O'Connor
eecf3b6ea8 stepper: Store pointers to step_const and step_delta in PrinterStepper
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-11-18 17:29:23 -05:00
Kevin O'Connor
fc1d690d75 stepper: Remove unused variables from PrinterStepper class
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-11-18 17:29:23 -05:00
Kevin O'Connor
d10380e73f stepper: Additional code comments
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-11-18 17:29:23 -05:00
Kevin O'Connor
aaeda540b6 stepper: Calculate the stepper name directly from the config section
There is no need to pass the name to the PrinterStepper class as it
can determine the name itself.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-11-18 17:29:22 -05:00
Kevin O'Connor
fda988889b heater: Avoid math errors on extreme ADC readings
Avoid log(0) and divide by zero errors in the thermistor calc_temp()
method.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-11-13 11:07:20 -05:00
Kevin O'Connor
b58a897b70 config: List E1 micro-step pins in order in generic-rambo.cfg
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-11-08 11:14:37 -05:00
Kevin O'Connor
84d8cf9b7e config: Add a generic-printrboard.cfg file
Add an example config file for the Printrboard board.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-30 10:56:08 -04:00
Kevin O'Connor
8463a83324 graphstats: Fix graphing script
Update the graphstats.py graphing script so that it works with recent
stats changes - the stats can now contain groups that end with a ':'
and the print_time is no longer reset to zero on a new print.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-29 20:36:33 -04:00
Kevin O'Connor
fc0e016a6d docs: Note version 0.5.0 release
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-25 11:27:20 -04:00
Kevin O'Connor
f5c0148665 config: Warn Beaglebone PRU users that pinmux settings are not updated
The Beaglebone hardware prevents the PRU from updating the pinmux
board settings.  As a result, the PRU can't directly change the pin
direction or change the pullup resistor settings.  Warn the Beaglebone
users of this limitation.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-25 11:01:36 -04:00
Kevin O'Connor
3d78a99758 docs: Update Installation document to recommend latest octoprint version
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-25 10:44:49 -04:00
Kevin O'Connor
03e97c2d95 linux: Remove unneeded includes from timer.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-23 22:20:53 -04:00
Kevin O'Connor
eaacb928fc pru: Force load the ADC module during PRU startup
Make sure the ADC module gets loaded during startup - it's normally
loaded by the cape manager eeprom, but there's no harm in requesting
it explicitly.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-18 13:23:10 -04:00
Kevin O'Connor
75ba375b8a pru: Don't reset the ADC reset complete flag if a shutdown occurs
Only set the have_done_reset flag if the reset completes successfully.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-18 13:05:36 -04:00
Kevin O'Connor
cbd06f1433 linux: Fix typo causing config_reset to not fully restart
A typo in the code caused the wrong config_reset code to be run.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-15 21:05:08 -04:00
Kevin O'Connor
1c59a0d30a linux: Open watchdog device after console
Only open the watchdog device after the console has been opened.  The
machine should not reboot in the unlikely event the console can't be
opened.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-15 21:05:08 -04:00
Kevin O'Connor
d222ec1024 linux: Make sure to close fd on analog/pca9685 init failure
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-14 00:22:21 -04:00
Kevin O'Connor
674f584190 pca9685: Fix missing devices_count increment
The devices_count was not being incremented on each device add.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-13 22:05:19 -04:00
Kevin O'Connor
77fea562c4 clocksync: Start with adjusted_freq of 1.0
Avoid setting adjusted_freq to 0.0 as that can cause divide by zero
failures at startup.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-13 21:07:32 -04:00
Kevin O'Connor
e0f275cddf serialhdl: Don't open port at 1200 baud
The 1200 baud trick on the Arduino Due does both a reset and an
erase.  The erase is not desired.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-12 21:46:09 -04:00
Kevin O'Connor
07a69df62f mcu: Fix command restart
Fix omission in commit f8750b14 that broke restarts via Klipper
command.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-12 21:43:33 -04:00
Kevin O'Connor
f8750b142f klippy: Rework shutdown handling
If an MCU signals a shutdown from the background thread, notify the
main thread and handle the shutdown there.  Dispatch shutdown handling
from the main Printer() class instead of from the Toolhead class.
This simplifies the shutdown logic.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-12 16:28:53 -04:00
Kevin O'Connor
3033b03789 config: Add generic-melzi.cfg file for Melzi boards
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-12 12:43:13 -04:00
Kevin O'Connor
3506d1e994 fan: Enable heater_fan objects on an MCU shutdown event
Should the MCU go into an error state, set the heater_fan to
max_power.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-12 11:59:27 -04:00
Kevin O'Connor
3c4d14bfa9 pca9685: Support default values
Allow the pwm pin to have a non-zero default value.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-12 11:59:27 -04:00
Kevin O'Connor
db97f36631 gpiocmds: Allow the start value for a pin to differ from the default_value
Allow the start value to be different from the default/shutdown value
for the pin.  This will be useful for "heater fans" that should
startup in the off state, and transition to full on in a shutdown
state.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-12 11:59:27 -04:00
Kevin O'Connor
d03cf2b83f adccmds: Continue to query analog inputs after a shutdown
Continue to sample the ADC input pins even if the MCU goes into a
shutdown state.  This enables the printer to continue reporting
temperatures even on an mcu error.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-12 11:59:27 -04:00
Kevin O'Connor
744c6d114e sched: Don't shutdown on a "timer in the past" if already shutdown
A shutdown will not help if the mcu is already in a shutdown state.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-12 11:59:27 -04:00
Kevin O'Connor
3b9b4e4d6f endstop: Eliminate end_stop_set_oversample command
Pass the sample_ticks and sample_count parameters directly in the
end_stop_home command instead.  This simplifies the code.

Also, simplify calculation of next wakeup time in
end_stop_oversample_event().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-12 11:59:27 -04:00
Kevin O'Connor
78ba7064a7 clocksync: Initialize clock_est in connect_file()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-12 11:59:27 -04:00
Kevin O'Connor
cc7c99a4a4 cartesian: Fix min_stop_interval calculation error
It is possible to have an acceleration greater than max_z_accel on
XY+Z moves.  That needs to be taken into account when calculating the
min_stop_interval.  This prevents spurious "No next step" MCU errors.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-12 01:16:11 -04:00
Kevin O'Connor
d3eb148cfa docs: Point to beaglebone.md from the main installation document
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-11 21:03:13 -04:00
Kevin O'Connor
00d541b767 docs: Octoprint should not run at a higher priority than Klipper on beaglebone
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-11 20:23:58 -04:00
Kevin O'Connor
ecf2596469 gcode: Don't warn on fan not present if input is from a file
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-11 14:28:19 -04:00
Kevin O'Connor
6a2eaeae40 docs: Add mailing list to Contact.md
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-10 14:24:04 -04:00
Kevin O'Connor
ce7cc798dc docs: Add Contact.md file with developer contact information
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-10 12:43:44 -04:00
Kevin O'Connor
0ec7eda11b pins: Add pin mapping for atmega1284p
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-05 16:57:44 -04:00
Kevin O'Connor
fb0f344346 avr: Add support for atmega1284p
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-05 13:51:05 -04:00
Kevin O'Connor
afac81c161 pru: Update start script to always unbind the PRU before binding it
It appears some versions of Debian will load the PRU with firmware on
boot, so make sure to always deactivate the PRU before attempting to
activate it with new firmware.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-05 13:50:12 -04:00
Kevin O'Connor
5c982c90f3 docs: Add a notch to the default square.stl test object
Place a small notch on one side of the square.  The notch provides
interesting information on the extruder performance, and it makes it
easier to compare with previous prints of the object.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-03 22:08:36 -04:00
Kevin O'Connor
381304aa6f stepper: If homing_endstop_phase is configured, make 0.0 be at a full step
If the stepper phases are known then it is possible to arrange for the
0.0 position to occur at a full step.  On cartesian style printer,
this makes it possible for the Z levels to occur at full steps (which
may help reduce "Z ribbing").

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-03 22:06:51 -04:00
Kevin O'Connor
ce9523fb90 gcode: Report the raw MCU position from the M114 command
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-03 22:03:52 -04:00
Kevin O'Connor
06420b0ddf gcode: Carry over #original and #command in get_extended_params()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-02 22:06:43 -04:00
Kevin O'Connor
c2e1c53356 clocksync: Implement a floor on the prediction filter
Don't discard samples that are less than 500us from the prediction
regardless of the prediction variance.  Also, don't use the prediction
variance in the external time estimate.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-02 11:00:24 -04:00
Kevin O'Connor
eaeb831107 endstop: Fix typo in comment
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-02 11:00:23 -04:00
Kevin O'Connor
459695e9d7 docs: Remove items from Todo.md
Several items were recently implemented.  Remove the "cubic vs
quadratic" item as investigations into cubic compression weren't
promising.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-01 19:34:00 -04:00
Kevin O'Connor
ece1f71c64 endstop: Support oversampling of the endstop
Some printers can show occasional noise on the endstop pin.  Support
sampling the endstop pin multiple times to attempt to filter out this
noise.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-01 19:15:55 -04:00
Kevin O'Connor
776d8f9f79 clocksync: Update clock synchronization code to use a linear regression
Implement a "moving" linear regression between the reported mcu clock
and the sent_time of the get_status message that generated that
report.  Use this linear regression to make predictions on the
relationship between the system time and the mcu clock.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-30 19:37:37 -04:00
Kevin O'Connor
61ee63f358 serialqueue: Don't report sent_time on responses that are retransmitted
On a retransmit, the sent_time of the command associated with the
given response message isn't accurate.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-30 19:37:20 -04:00
Kevin O'Connor
6f65ba9214 clocksync: Don't update prev_est on min rtt updates
Average frequency changes over the longer interval on a sample that
causes a minimum rtt update.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-28 01:09:18 -04:00
Kevin O'Connor
ba837c2641 clocksync: Fix serialqueue.set_clock_est() - don't track min_freq
Revert commit f37fc775.  It is not valid to pass a conservative
frequency to serialqueue.set_clock_est() as that function may not be
called for extended periods - a too low frequency would eventually
lead to "Timer too close" mcu errors.

Instead, increase the 1ms time offset to 5ms to avoid corner cases
that could lead to a message arriving too soon.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-28 00:51:48 -04:00
Kevin O'Connor
1518032606 clocksync: Default mcu_freq to 1 instead of 0
This prevents divide by zero errors during stats output if the stats
are generated before a connection completes.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-27 20:07:46 -04:00
Kevin O'Connor
6469cce2bc toolhead: Make sure reset_print_time() doesn't go backwards in time
Update the homing code to pass in the start of the homing operation to
toolhead.reset_print_time().  This prevents an error when batch
processing gcode files that contain multiple homing operations.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-27 19:21:26 -04:00
Kevin O'Connor
4c40b50fb5 docs: Add a section on time handling to Code_Overview.md
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-27 15:11:15 -04:00
Kevin O'Connor
a0f0911a95 docs: Reword performance paragraph in Features.md
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-27 13:59:47 -04:00
Kevin O'Connor
f658819862 clocksync: Add support for dumping internal state for debugging
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-27 13:13:38 -04:00
Kevin O'Connor
8d5a9143bb klippy: Avoid using '%' syntax when calling logging module
The logging module can build strings directly from printf syntax - no
need to build the string first.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-27 12:38:20 -04:00
Kevin O'Connor
8f8951b4c1 serialhdl: Make dump_debug() output atomic
Build a single (very large) logging message with the debug state.
This prevents the output from being fragmented.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-27 12:38:20 -04:00
Kevin O'Connor
6e5bcc69bc gcode: Make dump_debug() output atomic
Build a single (very large) logging message with the debug state.
This prevents the output from being fragmented.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-27 11:58:21 -04:00
Kevin O'Connor
8d04d3d8fd gcode: Exit if a shutdown occurs while running in batch mode
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-27 10:05:11 -04:00
Kevin O'Connor
f37fc775e5 clocksync: Be conservative when setting serialqueue.set_clock_est()
Accuracy is not as important as ensuring a message is never sent
before it can be received in the serialqueue code.  So, use the
smallest frequency ever seen and add the minimum rtt time when setting
set_clock_est().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-27 09:10:41 -04:00
Kevin O'Connor
ead99cf647 docs: Update Features.md document for multiple micro-controllers
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-26 22:27:25 -04:00
Kevin O'Connor
3982b5030e serialqueue: Take baud_adjust into account when calculating receive_time
Use baud_adjust when determining the receive_time of a message read
from the serial port.  This improves the accuracy of the clock
synchronization code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-26 22:27:25 -04:00
Kevin O'Connor
d9fe4b6944 clocksync: Rework clock synchronization algorithm
Instead of tracking the minimum frequency ever observed, attempt to
track the actual frequency of the micro-controller (relative to the
host clock).  This improves the stability of the secondary mcu clocks
when multiple mcus are configured.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-26 22:27:25 -04:00
Kevin O'Connor
387cab27bd mcu: Separate restart_microcontroller() into multiple functions
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-20 16:04:41 -04:00
Kevin O'Connor
6dcc44ce2d chipmisc: Add initial support for servos
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-20 14:21:36 -04:00
Kevin O'Connor
3b4088c23f chipmisc: Add support for Replicape board
Add support for configuring and controlling the hardware specific to
the revision "B3" Replicape board.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-20 13:18:07 -04:00
Kevin O'Connor
5a85c1667a pru: Update installation and flash scripts
Update the scripts used to install and "flash" the pru
micro-controller code.  Also, add a "flash" script for the linux
micro-controller code.  This makes it easier to install Klipper on a
Beaglebone board that uses a Replicape.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-20 12:55:28 -04:00
Kevin O'Connor
16d2ec3a90 linux: Add support for analog IIO devices
Add support for reading analog values via the standard Linux IIO
interface.  This can be used on Replicape boards to sample analog
input pins.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-20 12:55:28 -04:00
Kevin O'Connor
4d60567bc6 linux: Add support for spidev devices
Add support for sending SPI messages to devices via the standard Linux
SPI interface.  This can be used to configure the shift registers on
Replicape boards.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-20 12:55:28 -04:00
Kevin O'Connor
73a1c9d249 linux: Add support for pca9685 i2c pwm devices
Add support for controlling pca9685 PWM drivers using the standard
Linux I2C interface.  The pca9685 device is found on Replicape boards.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-20 12:55:28 -04:00
Kevin O'Connor
d851882278 linux: Initial support for running Klipper in a Linux real-time process
Add support for compiling the Klipper micro-controller code as a
real-time process capable of running on standard Linux systems.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-20 12:55:28 -04:00
Kevin O'Connor
3ccecc568d mcu: Initial support for multiple micro-controllers
Add initial support for controlling multiple independent
micro-controllers from a single Klippy host instance.  Add basic
support for synchronizing the clocks of the additional mcus to the
main mcu's clock.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-20 12:45:00 -04:00
Kevin O'Connor
cee200e509 mcu: Move code around in MCU class to keep like code together
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-19 17:27:18 -04:00
Kevin O'Connor
f1b315e04f mcu: Move print_time to clock conversion code to clocksync.py
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-19 17:27:18 -04:00
Kevin O'Connor
94bcd9735a mcu: Add mcu wrapper functions and avoid direct acccess to mcu variables
Don't directly access any of the mcu class variables externally from
the class.  Add wrapper functions for those external callers that need
access to some internal state.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-19 17:25:43 -04:00
Kevin O'Connor
f662445766 stepcompress: Implement print time to clock conversion in C code
Implement the conversion from print_time to the local mcu's clock
within the C code.  This simplifies the python code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-19 17:25:43 -04:00
Kevin O'Connor
008be18f41 clocksync: Don't export get_last_clock()
Everywhere the data in get_last_clock() is used can be done just as
easily with estimated_print_time().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-19 17:25:43 -04:00
Kevin O'Connor
13812aa1c9 clocksync: Move clock synchronization code into new file
Move the low-level clock synchronization code from serialhdl.py to a
new file clocksync.py.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-19 17:25:42 -04:00
Kevin O'Connor
2089f19670 toolhead: Separate is_active() code from stats() code
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-19 17:25:42 -04:00
Kevin O'Connor
593741919f mcu: Update file purpose comment
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-19 17:25:42 -04:00
Kevin O'Connor
9d0fcca8a9 serialhdl: Reduce calculations done while holding the lock
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-19 17:25:42 -04:00
Kevin O'Connor
857eb01bfa homing: Move query_endstop() code from kinematic classes to homing.py
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-19 17:25:42 -04:00
Kevin O'Connor
a100f174f9 mcu: Pass print_time directly to MCU calls
Now that the print_time is always synchronized with the mcu_time,
there is no longer a need to track mcu_time as a separate quantity.
Eliminate references to mcu_time from the code and pass print_time
directly in its place.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-19 17:25:42 -04:00
Kevin O'Connor
5dfe4e1eb9 toolhead: Synchronize print_time to main mcu's time
Instead of starting the print_time at zero, start it at the estimated
time of the main mcu's clock.  This simplifies the code and it ensures
that print_time never goes backwards.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-19 17:25:38 -04:00
Kevin O'Connor
b9586bad18 mcu: Use is_fileoutput() externally
Use mcu.is_fileoutput() instead of looking up the "debugoutput" flag
in the start args.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-19 17:22:29 -04:00
Kevin O'Connor
f1c2f789b6 klippy: Do not start stats timer until after connect completes
Generating stats during connect leads to potential use of not yet
initialized variables.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-19 17:22:29 -04:00
Kevin O'Connor
123719bf92 stepper: Fix bug causing 'enable_pin' to be required
Make sure to initialize mcu_enable to None so that it is initialized
if no 'enable_pin' config value is provided.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-19 17:20:41 -04:00
Kevin O'Connor
14810d7e80 stepcompress: Return number of steps traveled from stepcompress_push()
Return the same information from stepcompress_push() that is returned
from stepcompress_push_const() and stpcompress_push_delta().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-13 09:24:27 -04:00
Kevin O'Connor
52156d2c41 pins: Don't pass mcu_freq to update_command()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-13 09:16:58 -04:00
Kevin O'Connor
2a6a9eb52f pru: Avoid calling "slp" instruction on pru0
If pru0 waits in sleep mode then a full beaglebone reboot is needed to
reprogram the pru0 firmware.  For now, avoid using the "slp"
instruction as a workaround.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-11 13:12:18 -04:00
Kevin O'Connor
bf85c61b48 corexy: Fix max_xy_halt_velocity calculation on corexy
On corexy, the stepper velocity of a diagonal move could be greater
than the maximum printer velocity.  Account for that when setting the
maximum xy halt velocity in the mcu stepper config.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-09 14:45:10 -04:00
Kevin O'Connor
dba488f30a extruder: Remove unused set_max_jerk() call
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-08 19:34:30 -04:00
Kevin O'Connor
d618affd63 pru: Batch outgoing writes
Allow pru0 to gather multiple outgoing message blocks into a single
rpmsg.  This can reduce communication overhead.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-08 11:50:21 -04:00
Kevin O'Connor
121c747cc8 pru: Fix race condition in clearing of irq flags
Each irq flag must only be cleared after it has been serviced.  This
fixes a race condition that could cause incoming commands to be
delayed for extended period.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-08 11:50:21 -04:00
Kevin O'Connor
91b9634198 serialqueue: Fix off-by-one error in retransmit sequence number tracking
Commit 4655a6bf allowed naks to be honored if receive_seq was greater
than the last retransmitted sequence.  However, receive_seq is the
receiver's next sequence number, so a nak should only be processed if
it is one greater than that.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-08 11:50:21 -04:00
Kevin O'Connor
7d17002b33 fan: Allow heater_fan to work with heater_bed
Fix order of init error preventing heater_fan from being used with
heater_bed.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-07 11:19:27 -04:00
Kevin O'Connor
477b3941a6 console: Add support for SUPPRESS command
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-07 11:19:27 -04:00
Kevin O'Connor
36dd7e7609 console: Add support for a FLOOD command
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-07 11:19:27 -04:00
Kevin O'Connor
167a65d826 util: Fix reporting of git version of klippy code
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-07 11:19:27 -04:00
Kevin O'Connor
c9cd8cea66 mcu: Limit value range of PWM and digital outputs prior to transmission
Make sure schedule_digital_out and schedule_pwm_out commands always go
out with a value that is in range for the particular command.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-06 12:04:05 -04:00
Kevin O'Connor
dfdcbece53 mcu: Improve error descriptions in Common_MCU_errors
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-06 12:03:49 -04:00
Kevin O'Connor
5b62f15c6d extruder: Provide more details on extruder errors
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-05 22:12:15 -04:00
Kevin O'Connor
09e32d1b84 mcu: Provide some further help on common MCU shutdown errors
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-05 22:12:15 -04:00
Kevin O'Connor
68fc6abf74 avr: Check that FLASH_DEVICE is set on "make flash" command
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-05 22:12:15 -04:00
Kevin O'Connor
ff56c0fb74 extruder: Fix typo in init
Commit 7a81bfc4 broke extrude only moves due to a typo in the commit.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-05 22:12:15 -04:00
Kevin O'Connor
36de6118c1 mcu: Limit ADC min/max range to a 16bit integer
Make sure the ADC range sent to the MCU can be encoded into a 16bit
integer.  Otherwise, if the provided min_temp/max_temp was outside the
range of possible values it could result in a spurious mcu shutdown.
In particular, the AD595 could not properly encode a min_temp of zero.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-05 18:22:21 -04:00
Kevin O'Connor
7083a33ecd pru: Support config_reset command to manually reset mcu
Add support for resetting the MCU via a software only mechanism.  This
is useful on the PRU.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-03 23:16:38 -04:00
Kevin O'Connor
7b7f57e01c pru: Only sleep the pru0 if the incoming queue is fully empty
It's possible for multiple blocks to be pending on the incoming
"rpmsg" stream.  Don't sleep unless the input is confirmed to be
empty.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-03 23:15:49 -04:00
Kevin O'Connor
8d0ef49e8f toolhead: Permit look-ahead between Z moves
Extend the look-ahead mechanism to work between moves that contain Z
movement.  This improves Klipper's handling of g-code produced in
"vase mode".

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-03 15:46:48 -04:00
Kevin O'Connor
7a81bfc4a4 toolhead: Eliminate set_max_jerk() from kinematic classes
Allow the kinematic classes to query the max velocity, max accel, and
max halt velocity from the toolhead class instead of having the
toolhead class call into the kinematic classes with those values.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-03 15:45:04 -04:00
Kevin O'Connor
0d13834293 gcode: Fix error that could cause commands to be processed out of order
Commit d0932009 changed the way command handling was performed, and
commit 95950949 fixed a defect in that commit.  Unfortunately, the fix
was incomplete.

If multiple commands were sent to Klippy without waiting for an "ok"
response from Klippy, then it was possible for those additional
commands to be queued and processed after subsequent commands.  This
would result in commands being processed out of order.

Fix this by only reregistering the input fd in the greenlet that
performs the unregistration of the fd.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-02 12:05:51 -04:00
Kevin O'Connor
ac53806e04 gcode: Add an ECHO command for debugging purposes
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-02 12:05:51 -04:00
Kevin O'Connor
026b9c336c stepcompress: Minor performance tweaks for rpi
Invert the if conditional in queue_append() and change the order of
reads in minmax_point() - gcc on the rpi seems to do generate better
code this way.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-31 10:17:01 -04:00
Kevin O'Connor
60c77fff06 docs: Update Code_Overview.md - step compress queue no longer 64 bit
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-31 10:07:17 -04:00
Kevin O'Connor
588ecbe868 stepcompress: Use addition instead of multiplication on queue add
Replace multiplication with addition where possible.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-31 02:15:32 -04:00
Kevin O'Connor
e05c635489 stepcompreses: Change the step queue to use 32bit integers
The RaspberryPi processor implements 'double to int32' conversions
much faster than 'double to int64' conversions.  Rework the code so
that steps stored in the queue are always a small offset from the last
sent step time.  (In the unlikely event that a step is far from the
last step time, then the queue is flushed to maintain this invariant.)

This simplifies the step compression code as well - it no longer needs
to check for integer overflows.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-31 00:27:43 -04:00
Kevin O'Connor
f5cc355044 stepcompress: Refactor queue insertion to use a cursor
Create an insertion "cursor" for adding items to the step compression
queue.  This makes the calling code simpler and it makes it easier to
update the queue memory management in the future.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-31 00:15:03 -04:00
Kevin O'Connor
78f4c25a14 homing: Add a small delay before each homing operation
The homing operation can be cpu intensive for the host software.  Add
a small (250ms) delay before homing so that the host has additional
time to process the command before it is due on the mcu.  This is
intended to work around some reports of "timer too close" errors
during Z homing on RPi2 hosts and printers with high precision Z
positioning.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-29 18:02:36 -04:00
Kevin O'Connor
002dc0dfaf stepper: Adjust homing_speed so that it's an even number of ticks per step
Adjust the configured homing speed so that it always results in a
speed that is an even number of mcu ticks per step.  This ensures that
the code can always get good step compression during homing, which is
important as the entire homing operation must be able to fit within
the mcu's move queue.  This fixes some "move queue empty" mcu shutdown
errors that could occur when the Z step distance was an unusual size.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-29 18:00:17 -04:00
Kevin O'Connor
68d6788413 mcu: Add get_mcu() call to the mcu oid objects
Allow external code to obtain the mcu object that controls a pin setup
with setup_pin().  Also, don't bother defining print_to_mcu_time() and
system_to_mcu_time() on each pin object as they can be obtained via
the new get_mcu() method.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-29 17:59:27 -04:00
Kevin O'Connor
c7c551369f mcu: Fix bug causing corexy to not work (introduced in 9d75c3b0)
Commit 9d75c3b0 changed the order of allocation for mcu oid integer
ids.  However, the stepper oids must always be allocated before
endstop oids so that corexy can register multiple steppers on a single
endstop.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-29 17:59:15 -04:00
Kevin O'Connor
0c2919b534 klippy: Move restart logic into Printer() class
Move the restart logic out of main() and into Printer.run().  This
simplifies the code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-26 18:27:21 -04:00
Kevin O'Connor
d8c75fc608 klippy: Rename internal functions so that they are prefaced with "_"
Preface the internal functions to make it more clear which functions
are interfaces to external code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-26 18:27:21 -04:00
Kevin O'Connor
a42cb4fecf toolhead: Avoid directly accessing the printer.mcu field
Lookup the mcu object from the printer objects and store it locally in
the toolhead class.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-26 18:27:21 -04:00
Kevin O'Connor
68ba3d5106 mcu: Drop support for TICKS() expansion in mcu config commands
It's no longer necessary to use the TICKS() hack as the config
commands are now all generated after the mcu speed is known.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-26 18:27:21 -04:00
Kevin O'Connor
80dc1dfcc1 docs: Remove documentation for "custom" command blocks
It should no longer be necessary to configure "custom" commands during
mcu setup.  The ad5206 and static_digital_output config sections
should provide similar functionality.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-26 18:27:21 -04:00
Kevin O'Connor
931811ab59 chipmisc: Add support for configuring ad5206 digipots
Support an "ad5206" config section so that one can configure the
digipots found on Reprap "RAMBo" boards.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-26 18:27:21 -04:00
Kevin O'Connor
9d75c3b0ca chipmisc: Add support for statically configured output pins
Allow digital and PWM output pins to be setup via new config
sections.  This makes it easier to setup pin configurations.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-26 18:27:20 -04:00
Kevin O'Connor
6ab8567d51 mcu: Track stepqueues separately from steppers
The MCU() class needs to track the stepqueues so that it can
initialize the steppersync object.  Track the stepqueues directly
instead of via the list of steppers.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-25 20:45:54 -04:00
Kevin O'Connor
c727ed3592 mcu: Track oids separately from objects requiring a build_config() callback
Track the oid count separately from the configurable object count -
this way it is possible to have internal objects that don't require an
oid in the mcu.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-25 20:44:51 -04:00
Kevin O'Connor
c72ca983ba mcu: Eliminate "init callback" phase during connect
It's not necessary to register and execute "init callbacks" when
configuring the mcu.  Instead, have each mcu object produce its init
messages in the build_config() callback.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-25 20:41:09 -04:00
Kevin O'Connor
ec7990796a pins: Support registering arbitrary chips that supply configurable pins
Allow multiple chips to provide pin mappings (not just the main mcu
chip).  Move the pin parsing from the mcu.py code to pins.py and
support mapping from pin descriptions to their corresponding chips and
parameters.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-25 20:38:55 -04:00
Kevin O'Connor
268834e4ae klippy: Store printer startup parameters in new "start_args" dictionary
Store pertinent information from the software startup in a dictionary
that the various printer components can access instead of in
individual variables in the Printer() class.  This makes it easier to
add future command-line options.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-25 19:27:05 -04:00
Kevin O'Connor
b80c488d36 heater: Another minor cleanup to Steinhart-Hart math
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-20 12:42:50 -04:00
Kevin O'Connor
f25cb33367 heater: Minor cleanup to Steinhart-Hart math
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-18 13:28:04 -04:00
Kevin O'Connor
4b5f3bec4b heater: Add support for a generic "NTC 100K beta 3950" thermistor
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-17 15:12:51 -04:00
Kevin O'Connor
1f4c6443ef heater: Calibrate thermistor directly from temperature and resistance
Store the underlying temperature and resistance values instead of the
Steinhart-Hart coefficents obtained from them.  This makes it easier
to add new thermistors.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-17 13:26:51 -04:00
Kevin O'Connor
0adea120cd pru: Compile the irq_poll() function with -O2 optimization
Compile the PRU binary with -Os optimization, but request that the
timer dispatch code be compiled with -O2 optimization.  This improves
the performance of timers slightly.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-15 11:05:30 -04:00
Kevin O'Connor
71bb7acb8e pru: Compile with -Os instead of -O2
The gcc -Os option significantly reduces the size of the PRU binary
and it has little impact on performance.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-14 21:08:28 -04:00
Kevin O'Connor
4b5109c1b9 serialqueue: Make sure fds are in non-blocking mode
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-14 21:08:28 -04:00
Kevin O'Connor
085817d332 serialhdl: Sometimes we get an IOError when serial port not found
Catch IOError when opening the serial port.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-14 21:07:26 -04:00
Kevin O'Connor
f8bd8b97be command: Don't pass max_size to command_encodef()
The command_encodef() can read the max_size parameter directly from
the 'struct command_encoder' passed into it.  Also, there is no need
to check that a message will fit in a buffer if the buffer is declared
to be MESSAGE_MAX in size.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-14 18:32:15 -04:00
Kevin O'Connor
f3da473285 docs: Update Code_Overview.md with PRU and command_dispatch() changes
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-11 12:06:19 -04:00
Kevin O'Connor
f0f4ab7abe docs: Update benchmarks in Features document
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-11 11:40:54 -04:00
Kevin O'Connor
d8225642fa stepper: Revert f8b0c884
Go back to scheduling the unstep time instead of busy waiting in the
timer dispatch.  With the unstep time increased to 2us, it no longer
makes sense to spin while waiting for the unstep.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-11 10:36:02 -04:00
Kevin O'Connor
8ebba6d27a avr: Make sure timer_high and timer_event() stay in sync
Schedule the next wakeup time of timer_event() using timer_high.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-11 09:32:06 -04:00
Kevin O'Connor
1051a52755 timer_irq: Rework timer irq handler to check for tasks pending
Allow timer_dispatch_many() to run for extended periods if there are
no tasks pending.  This reduces the amount of lost cpu time spent
entering and exiting the irq handler.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-09 21:08:40 -04:00
Kevin O'Connor
5583b050a0 graphstats: Increase maximum expected task duration
Now that tasks are only run when needed it's common for there to be a
larger variation in task execution time.  When graphing load, consider
a 99-percentile task duration of 2.5ms to be 100% loaded (up from
1ms).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-09 19:12:27 -04:00
Kevin O'Connor
a38082016d sched: Reduce the amount of time irqs are disabled in sleep check
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-09 12:55:44 -04:00
Kevin O'Connor
156e9b7556 sched: Write out a message on startup
Send a "startup" message after completing the mcu init functions.
This may help detect mcu reboots during debugging.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-08 00:27:28 -04:00
Kevin O'Connor
5e6acf7dbc console: Add support for a STATS command
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-08 00:27:28 -04:00
Kevin O'Connor
58811b5c44 console: Add LIST command that shows available commands and variables
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-08 00:27:28 -04:00
Kevin O'Connor
86a762b2b7 console: Add a HELP command
Show available features at startup.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-08 00:27:28 -04:00
Kevin O'Connor
f886212b44 avr: Rework timer irq handler to check for tasks pending
Allow the timer dispatch irq handler to run for extended periods if
there are no tasks pending.  This reduces the amount of lost cpu time
spent entering and exiting the irq handler.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-08 00:27:28 -04:00
Kevin O'Connor
2c272f99a3 sched: Implement generic sleep mechanism based on tasks pending
Track when tasks are pending and spin in irq_wait() when no tasks are
pending.  This improves the mechanism for sleeping the processor -
it's simpler for the board specific code and it reduces the
possibility of the processor sleeping when tasks are busy.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-08 00:27:28 -04:00
Kevin O'Connor
a9982beacf sched: Introduce sched_wake_tasks() function to wake up tasks
Add function to indicate when tasks need to be run.  This will allow
the scheduler code to know if there are any tasks that need to be
processed.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-08 00:27:28 -04:00
Kevin O'Connor
e9d2ec7c41 avr: Tune the low-level timer entry and exit heuristics
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-08 00:27:28 -04:00
Kevin O'Connor
78982ebb51 avr: Implement internal avr specific timer to handle 16bit overflows
Don't rely on the generic scheduler code to always have a timer no
more than 1ms in the future.  Instead, create an avr specific timer
that will be called every 0x8000 ticks.  This simplifies the generic
code and it reduces the amount of code that needs to be run every
millisecond.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-08 00:27:28 -04:00
Kevin O'Connor
6a63c27542 sched: Support adding timers to the start of timer_list
If sched_add_timer() is called on a timer that would make it the new
head of the list, then add it and signal the board code that the timer
should be rescheduled.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-08 00:27:27 -04:00
Kevin O'Connor
62f77f6bc5 sched: Don't count milliseconds in the periodic timer
It's not necessary to keep a millisecond counter.  Replace the two
users of sched_check_periodic() with explicit task wakeup flags.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-08 00:27:27 -04:00
Kevin O'Connor
88a10fb31c sam3x8e: Fix watchdog timeout calculation
Fix error causing the watchdog to be set to an ~4ms timeout instead of
500ms.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-08 00:27:27 -04:00
Kevin O'Connor
e12527b895 avr: Move prescaler and sleep initialization from timer.c to main.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-07 19:39:57 -04:00
Kevin O'Connor
114c8c5b6d avr: Enable watchdog code even on simulavr
The simulavr simulator will warn when writing to the watchdog
registers, but running code closer to what real hardware runs is worth
a few extra warnings.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-07 19:39:57 -04:00
Kevin O'Connor
d50f4e23e0 pwmcmds: Update event prototypes to use uint_fast8_t
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-06 20:24:22 -04:00
Kevin O'Connor
dca0fc91ea pru: Improve comments in pru0.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-02 11:02:45 -04:00
Kevin O'Connor
981c53682f stepper: Use a sane default for homing_positive_dir
Use the endstop position to determine a sane default for
homing_positive_dir.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-24 14:31:46 -04:00
Kevin O'Connor
143b7cccf4 stepper: Separate out homing code to its own PrinterHomingStepper class
Keep the homing code separate from the main stepper class.  This makes
it easier to verify the correct config parameters are provided.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-24 13:54:46 -04:00
Kevin O'Connor
8ce042bf04 config: Add additional pin definitions to ramps and rambo configs
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-24 13:18:45 -04:00
Kevin O'Connor
85a1e1118f config: Change default pins defined in example.cfg to use RAMPS pins
Change the example.cfg file to use the pins of a RAMPS config as that
is a very common setup.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-24 13:05:00 -04:00
Kevin O'Connor
51baeb3c2c config: Reduce max_z_velocity in example-delta.cfg to 150
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-24 11:47:25 -04:00
Kevin O'Connor
959a20888c serialhdl: Dump serial stats in dump_debug()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-24 11:43:54 -04:00
Kevin O'Connor
7bf0ec2fe7 gcode: Don't wait for moves to finish if both debug input and output
Don't wait for moves to finish if the output is going to a debug file.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-23 21:32:26 -04:00
Kevin O'Connor
c6231a16e3 serialqueue: Improve limit on number of in-flight bytes
Instead of limiting the amount of non-acked messages to 50ms, limit
the amount to one round-trip-time.  This should make it less likely
that the mcu will be overloaded and it should make retransmits faster.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-23 20:47:08 -04:00
Kevin O'Connor
a619aacfc6 serialqueue: Further retransmit timing fixes
The first message always has a sync byte with it, so its size should
be one larger.  Also, the idle_time should always be the minimum time
that the message could be received, so it should always be reset to
eventtime on a retransmit.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-23 19:32:42 -04:00
Kevin O'Connor
d469db84ee serialqueue: Allow a second nak after a retransmit
If a nak message causes a retransmission then also accept a second nak
message as long as it is for a sequence greater than the first nak.
This should allow faster retransmits when there are multiple
transmission errors in a small time period.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-21 23:49:44 -04:00
Kevin O'Connor
4655a6bfef serialqueue: Fix off-by-one error in retransmit sequence number tracking
Track the sequence number of the message last retransmitted (not the
sequence number of the next message to be transmitted).  This fixes a
small possibility of a valid nak not being honored.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-21 23:43:48 -04:00
Kevin O'Connor
61325c0a14 serialqueue: Improve timing of multiple retransmits
If a retransmit is triggered by a nak, then it is not necessary to
increase the rto.  The next retransmit time should be based on the
expected reception of the first retransmitted message, not the last.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-21 21:26:14 -04:00
Kevin O'Connor
7faa5fe233 gcode: Improve end-of-file handling when input is a debug file
Wait for any pending moves to be fully handled before exiting.  Make
sure the wait is done inside the "self.is_processing_data" check to
avoid infinite recursion.  Don't keep reading from the file while
waiting to exit.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-21 21:22:12 -04:00
Kevin O'Connor
19090bdd5b graphstats: Fix so that older files (predating mcu_awake) still work
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-21 14:19:59 -04:00
Kevin O'Connor
4a6254fac3 build: Allow boards to disable digital input/output support
Allow the micro-controller code to be built without support for
regular gpio pins.  In this case, the code for endstops, steppers, and
gpiocmds will be disabled.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-20 10:44:31 -04:00
Kevin O'Connor
649d26e093 basecmd: Move low-level alloc code into basecmd.c
Implement new dynmem_start() and dynmem_end() functions instead of
alloc_chunk() and alloc_chunks() in the board code.  This simplifies
the board code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-20 10:44:31 -04:00
Kevin O'Connor
2ee42997e4 docs: Update Kinematics.md with regards to stepper torque limits
It is not necessary to limit stepper acceleration - only the limiting
of stepper torque is important.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-19 19:09:14 -04:00
Kevin O'Connor
17a3e25036 docs: Improve description of delta stepper acceleration limits
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-19 14:14:01 -04:00
Kevin O'Connor
c4b8d3ea8b graphstats: Support graphing "mcu_awake" statistic
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-19 14:14:01 -04:00
Kevin O'Connor
118fd21cb8 irq: Support sleeping when mcu is idle
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-17 15:02:43 -04:00
Kevin O'Connor
969485c754 fan: Add support for heater_fan objects
Add support for fans designed to cool the components of an extruder or
heater.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-17 11:35:52 -04:00
Kevin O'Connor
519e81d0fa mcu: Support converting from a system time to an mcu time
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-17 11:35:48 -04:00
Kevin O'Connor
12ca45a264 gcode: Log g-code error responses
Be sure to log g-code errors even if debug logging is not enabled.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-17 11:24:15 -04:00
Kevin O'Connor
3ac60b31a2 pru: Move peripheral init from pru0 to pru1
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-17 11:16:55 -04:00
Kevin O'Connor
c105ff1c51 pru: Move ADC code from gpio.c to new file adc.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-12 23:03:14 -04:00
Kevin O'Connor
ae9bc93ccc avr: Fix readl() typo in serial.c
The code should have used a readb() call instead of readl().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-12 23:03:12 -04:00
Kevin O'Connor
afc665d7c8 config: Update PRU based configs to use the correct serial device
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-06 12:04:26 -04:00
Kevin O'Connor
2d173f51b1 pru: Add documentation and install scripts for running on the PRU
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-05 14:21:32 -04:00
Kevin O'Connor
b32ba3727b pru: Add support for "make flash" rule
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-05 12:50:54 -04:00
Kevin O'Connor
5793271308 fan: Support setting a max_power attribute for the print cooling fan
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-05 10:43:34 -04:00
Kevin O'Connor
09140a51d5 sched: Pass shutdown reason code via longjmp() parameter
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-04 12:49:58 -04:00
Kevin O'Connor
cf662b842b msgproto: Catch exceptions during identify data parsing
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-04 12:49:58 -04:00
Kevin O'Connor
0ac518040b msgproto: Export static_strings from mcu to host as a dictionary
Export the static strings as a dictionary instead of as a list.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-02 14:11:10 -04:00
Kevin O'Connor
067fac05a8 serialqueue: Rename clock estimation variable names
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-30 20:15:36 -04:00
Kevin O'Connor
c7d0358c41 serialhdl: Rework mcu clock synchronization
The existing clock synchronization code has two flaws: intermittent
transmission latency during get_status requests can cause the
estimated clock to be too low, and the estimated clock calculation did
not take into account possible clock drift between samples.  The
former could potentially lead to "Timer too close" errors and the
latter could potentially lead to "Move queue empty" errors.

Rework the code to avoid the above problems.  It's not necessary to
estimate the micro-controller clock as an excellent estimate is
reported by the micro-controller (via the CLOCK_FREQ constant).
Account for a small drift from the reported value, and check on each
sample if the drift exceeds the expected limits.  With a good starting
estimated clock, only the offset needs to be calculated.  Use previous
offsets (and the estimated clock) in calculation of new offsets to
avoid intermittent latency from badly skewing the results.  Finally,
add an additional time offset of one millisecond to account for any
minor inaccuracies.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-30 20:15:36 -04:00
Kevin O'Connor
c957e4ba86 serialqueue: Clarify code that associates sent messages to received messages
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-30 20:15:36 -04:00
Kevin O'Connor
c8dca0a56c pru: Use a pointer when working with send_data array items
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-30 19:54:40 -04:00
Kevin O'Connor
da3569c490 pru: Add hack to shutdown the PRU from a simple command request
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-30 19:54:33 -04:00
Kevin O'Connor
e8356afa26 pru: Rework command processing so that most of it is done on pru0
Change the command dispatch and response generation so that most of
the work is done on pru0 instead of pru1.  This allows more code to
fit into the limited space on pru1.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-30 19:53:04 -04:00
Kevin O'Connor
c1bd628ce5 command: Directly call command_sendf() for ack/nak messages
Don't use the sendf() macro for ack and nak messages - directly call
the command_sendf() code instead.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-29 13:33:59 -04:00
Kevin O'Connor
849096d5f3 sam3x8e: Integrate serial console functions
Now that console_get_input(), console_pop_input(),
console_get_output() and console_push_output() are local functions,
integrate them into their callers.  This simplifies the code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-29 13:33:59 -04:00
Kevin O'Connor
e681369a1a avr: Integrate usb serial console functions
Now that console_get_input(), console_pop_input(),
console_get_output() and console_push_output() are local functions,
integrate them into their callers.  This simplifies the code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-29 13:33:59 -04:00
Kevin O'Connor
faa29c8062 avr: Integrate serial console functions
Now that console_get_input(), console_pop_input(),
console_get_output() and console_push_output() are local functions,
integrate them into their callers.  This simplifies the code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-29 13:33:58 -04:00
Kevin O'Connor
44f2a2a952 command: Move low-level sendf transmission into board code
Export a new console_sendf() function from the board code instead of
console_get_output() and console_push_output().  This enables more
flexibility in how the board specific code produces output.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-29 13:33:58 -04:00
Kevin O'Connor
292453d306 command: Move command_task() to board specific code
Move the command_task() code from the generic code to the board
specific code.  This enables more flexibility in how the board
specific code processes input.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-29 13:33:58 -04:00
Kevin O'Connor
1ae78d08e9 command: Encode MESSAGE_MIN in command_parser->max_size
Add the message minimum into the stored constant so it does not need
to be added at run-time.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-29 13:33:58 -04:00
Kevin O'Connor
1c3cbe9456 command: Refactor message block generation
Separate out the buffer management, message encoding, and message
framing code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-29 13:33:58 -04:00
Kevin O'Connor
88f4c38dca command: Refactor the command reading task
Refactor the code so that message block framing, command parsing, and
command dispatch are distinct.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-29 13:33:58 -04:00
Kevin O'Connor
b7b368a1ed build: Default to python2 in the Makefile
Set PYTHON=python2 instead of python as some systems point python to
python3.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-28 10:52:05 -04:00
Kevin O'Connor
d2fafbdd9e build: Request python2 for all directly executed python binaries
Some systems point python to python3 instead of python2 - explicitly
request python2 to avoid conflicts.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-27 20:26:02 -04:00
Kevin O'Connor
d981973096 heater: Fix auto-tune code
Make sure the heater.target_temp is set during the auto-tune test so
that the heater.set_pwm() command will allow the heater to be turned
on.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-22 12:09:55 -04:00
Kevin O'Connor
b310501970 sam3x8e: Use readl/writel instead of readb/writeb() in serial.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-22 10:51:49 -04:00
Kevin O'Connor
e92ce565dd console: Support new artificial DELAY command
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-22 10:51:49 -04:00
Kevin O'Connor
da4f2c5ea0 checkstack: Continue to accumulate stack usage on misc instructions
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-22 10:51:49 -04:00
Kevin O'Connor
bd48c3a083 pru: Remove unnecessary barrier() calls
The writel() call already implements a barrier() internally.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-16 14:26:37 -04:00
Kevin O'Connor
ba58e0446d install-octopi: Add python-virtualdev to package list
Add python-virtualdev to the list of system packages to be installed -
it's usually already installed, but it doesn't hurt to add it to the
list in case it isn't already installed.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-15 10:41:21 -04:00
Kevin O'Connor
c03b4921c3 klippy: Make sure to always sleep before retrying next stats() call
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-15 09:37:57 -04:00
Kevin O'Connor
c60e4aceed stepper: Increase the step delay time from 1us to 2us
Increase the step delay time so that it works with the common DRV8825
stepper drivers.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-13 11:53:10 -04:00
Kevin O'Connor
156de2e4c2 delta: Fix support for different endstop_position settings on each stepper
The endstop_position is intended to support different values for each
stepper so that the individual tower heights can be configured.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-11 12:48:51 -04:00
Kevin O'Connor
959509496a gcode: Fix regression causing lost asynchronous commands
Commit d0932009 introduced an error that could cause lost input in
cases where the sender did not wait for an "ok" message before sending
the next command.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-11 12:42:11 -04:00
Kevin O'Connor
8419e152bb klippy: Remove some obscure python2 dependencies
Don't modify dictionaries while iterating them and be careful to use
// when doing an integer divide.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-10 00:12:14 -04:00
Kevin O'Connor
1bc3e0a678 klippy: Use newer "except XYZError as e" python syntax
Use the newer syntax for python exceptions.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-10 00:08:06 -04:00
Kevin O'Connor
d093200966 gcode: Support running arbitrary gcode on extruder change
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-09 18:55:33 -04:00
Kevin O'Connor
72dc21fb1a gcode: Support for querying and setting multiple extruder heaters
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-09 18:55:30 -04:00
Kevin O'Connor
24b8f4ebc1 extruder: Add initial support for multi-extruders
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-09 18:54:38 -04:00
Kevin O'Connor
136dccbcdf klippy: Allow each module to define their config sections
Create add_printer_objects() functions in the fan, heater, extruder,
and toolhead modules.  Create the necessary printer component objects
from this call instead of placing the code directly in klippy.py.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-09 18:54:34 -04:00
Kevin O'Connor
d0e6a0928b pins: Fix typo in at90usb1286 support so PF0-7 pins are defined
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-09 18:46:07 -04:00
Kevin O'Connor
46846d4297 avr: Enable CLEAR_PRESCALER by default on at90usb1286
It appears this option is commonly needed on the at90usb1286 avr chip
(the printrboard requires it), so default it on.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-09 18:42:40 -04:00
Kevin O'Connor
01ee9e16c5 klippy: Prefer python dictionary comprehension to dict() call
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-06 12:35:13 -04:00
Kevin O'Connor
38411fd2e7 delta: Add support for specifying the angle each tower is at
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-05 18:05:45 -04:00
Kevin O'Connor
b8094de129 avr: Support using serial instead of usb on AT90USB1286
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-05 12:30:49 -04:00
Kevin O'Connor
73207a12ba avr: Allow atmega328 to select a cpu speed of 20Mhz
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-29 14:24:18 -04:00
Kevin O'Connor
3af87e1c42 avr: Add SIMULAVR build option; don't show WATCHDOG or SERIAL_BAUD_U2X
Add a CONFIG_SIMULAVR option to the Kbuild menus and don't directly
prompt users for CONFIG_WATCHDOG or CONFIG_SERIAL_BAUD_U2X.  The only
reason to disable these options would be if one were running on
simulavr.  This simplifies the user visible menu options.

Also, only show CONFIG_CLEAR_PRESCALER for at90usb1286 chips.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-28 11:04:59 -04:00
Kevin O'Connor
d2547ce6b0 avr: Add support for atmega328 chip
The atmega328 is basically the same as the atmega168 - it just adds
some additional memory.  Allow the chip to be selected during the
build.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-28 10:45:32 -04:00
Kevin O'Connor
7e3d7e071f avr: Reorder Kconfig entries so that atmega2560 at 16mhz is default
Reorder the MCU list so that newer chips are at the top of the list.
This causes the very popular atmega2560 to be the default chip
selected.

Reorder the frequency list so that higher frequencies are at the top
of the list.  Restrict the 20Mhz frequency to only chips that support
that speed.  This causes the popular 16Mhz frequency to be the default
speed on AVR.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-28 09:59:51 -04:00
Kevin O'Connor
d4bed025ed command: Store the command parsing information directly in array
Instead of defining an array of pointers, just define the array
directly.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-26 13:25:51 -04:00
Kevin O'Connor
a82e949c00 build: Use compile_time_request system for init, tasks, and shutdown
Avoid using linker magic to define the init, task, and shutdown
functions.  Instead, use the compile_time_request system.  This
simplifies the build and produces more efficient code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-26 12:39:34 -04:00
Kevin O'Connor
ca9756413f sched: Allow shutdown_reason to be uint8
Store the shutdown_reason code in an 8-bit integer - this produces
better code on AVR.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-26 12:32:05 -04:00
Kevin O'Connor
b9940f0e0d build: Avoid linker magic in compile_time_request.c unique id generation
Avoid generating unique ids via memory locations and linker scripts.
Instead, generate them using code produced by buildcommands.py.
Utilize gcc's ability to perform static string comparisons at compile
time to produce a unique id for each unique string.

This fixes a build failure on ARM introduced in 142b92b8.  It also
reduces the complexity of the build.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-26 12:32:02 -04:00
Kevin O'Connor
f91a49c65d docs: Note how to handle odd corner in Pressure_Advance.md
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-25 13:39:16 -04:00
Kevin O'Connor
4b8ad3fc03 docs: Add a prerequisites section to Pressure_advance.md
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-22 12:32:20 -04:00
Kevin O'Connor
e8aabbb40b docs: Add Todo item for supporting custom fan and pin config sections
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-22 11:55:41 -04:00
Kevin O'Connor
02a5fa2c79 config: Make it clear the "fan" section represents the print cooling fan
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-21 11:52:02 -04:00
Kevin O'Connor
944c121a00 config: Add periods to end of sentences in example configs
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-21 11:51:58 -04:00
Kevin O'Connor
c9b6662138 pru: Add support for ADC input
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-17 19:46:12 -04:00
Kevin O'Connor
b85755c0ff pru: Move communication code to second PRU
Perform input and output in the second PRU so that more space is
available in the primary PRU.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-17 10:46:38 -04:00
Kevin O'Connor
b6f24e78ac pyhelper: Fix GETHEX() macro used in dump_string() debugging
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-17 09:57:09 -04:00
Kevin O'Connor
fc24aa041b pins: Add pin mappings for Beaglebone boards
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-15 15:15:52 -04:00
Kevin O'Connor
c9b44b5bb6 serialhdl: Support working with pseudo serial devices
Support working with devices that aren't really serial ports and thus
do not have a baud rate.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-15 15:15:52 -04:00
Kevin O'Connor
2255176228 pru: Initial support for the Beaglebone PRU
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-15 15:15:52 -04:00
Kevin O'Connor
ccaa25eaa5 pru: Add initial pru_rpmsg library code for Beaglebone PRU
Add external code for using RPMsg on the Beaglebone PRU.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-15 15:00:52 -04:00
Kevin O'Connor
969ee4c8f9 irq: Add an irq_poll() stub for board code
Allow the board specific code to run checks prior to running each
task.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-15 15:00:45 -04:00
Kevin O'Connor
c35278e217 build: Avoid using noinline in common code
It's not necessary to use noinline for parsef() and stop_steppers().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-15 14:02:59 -04:00
Kevin O'Connor
039d3f0523 stepper: It is not necessary to ensure gpio_out_write value is 0 or 1
The gpio_out_write() and gpio_out_setup() calls will check for zero
and non-zero, so it is not necessary to explicitly convert to 0/1 in
the stepper.c code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-15 14:02:59 -04:00
Kevin O'Connor
d56f8407a5 debugcmds: Move debugging commands from basecmd.c to new file
Move the implementation of debug commands to their own file.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-15 14:02:59 -04:00
Kevin O'Connor
142b92b883 command: Use "i" instead of "m" constraint in _DECL_REQUEST_ID
On some architectures, gcc will allocate a register for inline
assembler with an "m" constraint.  Use "i" to avoid that.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-15 14:02:59 -04:00
Kevin O'Connor
c292006421 gpiocmds: Change MAX_SOFT_PWM from 255 to 256
Change the range of values used for software PWM to avoid doing an
integer division in the main code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-15 14:02:59 -04:00
Kevin O'Connor
5c4cc0d646 pwmcmds: Export the maximum PWM value
Instead of assuming the maximum PWM value is 255, export a constant
from the firmware to the host with the maximum value.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-15 14:02:59 -04:00
Kevin O'Connor
a361b92184 gpio: Fix off-by-one in declaration of ADC_MAX
The maximum value for the ADC is 1023 for 10bit samples and 4095 for
12bit samples.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-15 14:02:59 -04:00
Kevin O'Connor
37572bc217 command: Only implement 16bit signed conversion on AVR
On regular 32bit machines there is no need to implement explicit
signed conversion on 16bit integers.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-15 14:02:04 -04:00
Kevin O'Connor
233adfe660 build: Add __visible to variables in compile_time_request.c
Add __visible to generated code in compile_time_request.c so that the
main code can be compiled with -fwhole-program.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-15 14:02:04 -04:00
Kevin O'Connor
450c14b286 build: Rename makefile CFLAGS-y to CFLAGS and LDFLAGS-y to CFLAGS_klipper.elf
Rename some makefile variables.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-15 14:01:56 -04:00
Kevin O'Connor
33dfc386c9 avr: Merge misc.c into main.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-11 13:56:21 -04:00
Kevin O'Connor
f331936969 basecmd: Avoid calling malloc() from main code
Introduce a new board function alloc_chunk() to allocate dynamic
memory.  This allows the board code to implement memory allocations
without using the standard malloc() interface.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-11 13:56:21 -04:00
194 changed files with 17569 additions and 3343 deletions

13
.travis.yml Normal file
View File

@@ -0,0 +1,13 @@
# This is a travis-ci.org continuous integration configuration file.
language: c
addons:
apt:
packages:
- gcc-avr
- avr-libc
- wget
install: ./scripts/travis-install.sh
script: ./scripts/travis-build.sh

View File

@@ -1,6 +1,6 @@
# Klipper build system
#
# Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
# Copyright (C) 2016,2017 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
@@ -22,7 +22,7 @@ OBJCOPY=$(CROSS_PREFIX)objcopy
OBJDUMP=$(CROSS_PREFIX)objdump
STRIP=$(CROSS_PREFIX)strip
CPP=cpp
PYTHON=python
PYTHON=python2
# Source files
src-y =
@@ -32,18 +32,15 @@ dirs-y = src
cc-option=$(shell if test -z "`$(1) $(2) -S -o /dev/null -xc /dev/null 2>&1`" \
; then echo "$(2)"; else echo "$(3)"; fi ;)
CFLAGS-y := -I$(OUT) -Isrc -I$(OUT)board-generic/ -O2 -MD -g \
CFLAGS := -I$(OUT) -Isrc -I$(OUT)board-generic/ -O2 -MD -g \
-Wall -Wold-style-definition $(call cc-option,$(CC),-Wtype-limits,) \
-ffunction-sections -fdata-sections
CFLAGS-y += -flto -fwhole-program -fno-use-linker-plugin
CFLAGS += -flto -fwhole-program -fno-use-linker-plugin
LDFLAGS-y := -Wl,--gc-sections -fno-whole-program
CFLAGS_klipper.elf = $(CFLAGS) -Wl,--gc-sections
CPPFLAGS = -I$(OUT) -P -MD -MT $@
CFLAGS = $(CFLAGS-y)
LDFLAGS = $(LDFLAGS-y)
# Default targets
target-y := $(OUT)klipper.elf
@@ -77,23 +74,18 @@ $(OUT)board-link: $(KCONFIG_CONFIG)
$(Q)mkdir -p $(OUT)board-generic
$(Q)ln -Tsf $(PWD)/src/generic $(OUT)board-generic/board
$(OUT)declfunc.lds: src/declfunc.lds.S
@echo " Precompiling $@"
$(Q)$(CPP) $(CPPFLAGS) -D__ASSEMBLY__ $< -o $@
$(OUT)%.o.ctr: $(OUT)%.o
$(Q)$(OBJCOPY) -j '.compile_time_request' -O binary $^ $@
$(OUT)klipper.o: $(patsubst %.c, $(OUT)src/%.o,$(src-y)) $(OUT)declfunc.lds
@echo " Linking $@"
$(Q)$(CC) $(CFLAGS) $(CFLAGS_klipper.o) -Wl,-r -Wl,-T,$(OUT)declfunc.lds -nostdlib $(patsubst %.c, $(OUT)src/%.o,$(src-y)) -o $@
$(OUT)compile_time_request.o: $(OUT)klipper.o ./scripts/buildcommands.py
$(OUT)compile_time_request.o: $(patsubst %.c, $(OUT)src/%.o.ctr,$(src-y)) ./scripts/buildcommands.py
@echo " Building $@"
$(Q)$(OBJCOPY) -j '.compile_time_request' -O binary $< $(OUT)klipper.o.compile_time_request
$(Q)$(PYTHON) ./scripts/buildcommands.py -d $(OUT)klipper.dict $(OUT)klipper.o.compile_time_request $(OUT)compile_time_request.c
$(Q)cat $(patsubst %.c, $(OUT)src/%.o.ctr,$(src-y)) > $(OUT)klipper.compile_time_request
$(Q)$(PYTHON) ./scripts/buildcommands.py -d $(OUT)klipper.dict -t "$(CC);$(AS);$(LD);$(OBJCOPY);$(OBJDUMP);$(STRIP)" $(OUT)klipper.compile_time_request $(OUT)compile_time_request.c
$(Q)$(CC) $(CFLAGS) -c $(OUT)compile_time_request.c -o $@
$(OUT)klipper.elf: $(OUT)klipper.o $(OUT)compile_time_request.o
$(OUT)klipper.elf: $(patsubst %.c, $(OUT)src/%.o,$(src-y)) $(OUT)compile_time_request.o
@echo " Linking $@"
$(Q)$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@
$(Q)$(CC) $^ $(CFLAGS_klipper.elf) -o $@
################ Kconfig rules

View File

@@ -46,7 +46,7 @@ nozzle_diameter: 0.500
filament_diameter: 3.500
heater_pin: ar4
sensor_type: EPCOS 100K B57560G104F
sensor_pin: analog1
sensor_pin: analog7
control: pid
pid_Kp: 22.2
pid_Ki: 1.08

View File

@@ -8,38 +8,35 @@
# FIRST. Incorrectly configured parameters may cause damage.
# The stepper_x section is used to describe the X axis as well as the
# stepper controlling the X+Y movement
# stepper controlling the X+Y movement.
[stepper_x]
step_pin: ar54
dir_pin: ar55
enable_pin: !ar38
step_distance: .01
endstop_pin: ^ar2
homing_speed: 50.0
position_min: 0
endstop_pin: ^ar3
position_endstop: 0
position_max: 200
homing_speed: 50
# The stepper_y section is used to describe the Y axis as well as the
# stepper controlling the X-Y movement
# stepper controlling the X-Y movement.
[stepper_y]
step_pin: ar60
dir_pin: ar61
enable_pin: !ar56
step_distance: .01
endstop_pin: ^ar15
homing_speed: 50.0
position_min: 0
endstop_pin: ^ar14
position_endstop: 0
position_max: 200
homing_speed: 50
[stepper_z]
step_pin: ar46
dir_pin: ar48
enable_pin: !ar62
step_distance: .01
endstop_pin: ^ar19
position_min: 0.1
step_distance: .0025
endstop_pin: ^ar18
position_endstop: 0.5
position_max: 200

View File

@@ -16,28 +16,40 @@ dir_pin: ar55
enable_pin: !ar38
step_distance: .01
endstop_pin: ^ar2
homing_speed: 50.0
homing_speed: 50
position_endstop: 297.05
# Distance (in mm) between the nozzle and the bed when the nozzle is
# in the center of the build area and the endstop triggers. This
# parameter must be provided for stepper_a; for stepper_b and
# stepper_c this parameter defaults to the value specified for
# stepper_a.
arm_length: 333.0
# Length (in mm) of the diagonal rod that connects this tower to the
# print head. This parameter must be provided for stepper_a; for
# stepper_b and stepper_c this parameter defaults to the value
# specified for stepper_a.
#angle:
# This option specifies the angle (in degrees) that the tower is
# at. The default is 210 for stepper_a, 330 for stepper_b, and 90
# for stepper_c.
# The stepper_b section describes the stepper controlling the front
# right tower (at 330 degrees)
# right tower (at 330 degrees).
[stepper_b]
step_pin: ar60
dir_pin: ar61
enable_pin: !ar56
step_distance: .01
endstop_pin: ^ar15
position_endstop: 297.05
# The stepper_c section describes the stepper controlling the rear
# tower (at 90 degrees)
# tower (at 90 degrees).
[stepper_c]
step_pin: ar46
dir_pin: ar48
enable_pin: !ar62
step_distance: .01
endstop_pin: ^ar19
position_endstop: 297.05
[extruder]
step_pin: ar26
@@ -64,7 +76,7 @@ control: watermark
min_temp: 0
max_temp: 130
# Extruder print fan (omit section if fan not present)
# Print cooling fan (omit section if fan not present).
#[fan]
#pin: ar9
@@ -77,27 +89,43 @@ kinematics: delta
# This option must be "delta" for linear delta printers.
max_velocity: 300
# Maximum velocity (in mm/s) of the toolhead relative to the
# print. This limits the velocity of the toolhead relative to the
# print - at the extreme end of the print envelope the delta axis
# steppers themselves may briefly exceed this speed by up to 3
# times. This parameter must be specified.
# print. This parameter must be specified.
max_accel: 3000
# Maximum acceleration (in mm/s^2) of the toolhead relative to the
# print. This limits the acceleration of the toolhead relative to
# the print - at the extreme end of the print envelope the delta
# axis steppers may briefly exceed this acceleration by up to 3
# times. This parameter must be specified.
max_z_velocity: 200
# print. This parameter must be specified.
max_z_velocity: 150
# For delta printers this limits the maximum velocity (in mm/s) of
# moves with z axis movement. This setting can be used to reduce the
# maximum speed of up/down moves (which require a higher step rate
# than other moves on a delta printer). The default is to use
# max_velocity for max_z_velocity.
delta_arm_length: 333.0
# Length (in mm) of the diagonal rods that connect the linear axes
# to the print head. This parameter must be provided.
#minimum_z_position: 0
# The minimum Z position that the user may command the head to move
# to. The default is 0.
delta_radius: 174.75
# Radius (in mm) of the horizontal circle formed by the three linear
# axis towers. This parameter may also be calculated as:
# delta_radius = smooth_rod_offset - effector_offset - carriage_offset
# This parameter must be provided.
# The delta_calibrate section enables a DELTA_CALIBRATE extended
# g-code command that can calibrate the tower endstop positions and
# angles.
[delta_calibrate]
radius: 50
# Radius (in mm) of the area that may be probed. This is typically
# the size of the printer bed. This parameter must be provided.
#speed: 50
# The speed (in mm/s) of non-probing moves during the
# calibration. The default is 50.
#horizontal_move_z: 5
# The height (in mm) that the head should be commanded to move to
# just prior to starting a probe operation. The default is 5.
#manual_probe:
# If true, then DELTA_CALIBRATE will perform manual probing. If
# false, then a PROBE command will be run at each probe
# point. Manual probing is accomplished by manually jogging the Z
# position of the print head at each probe point and then issuing a
# NEXT extended g-code command to record the position at that
# point. The default is false if a [probe] config section is present
# and true otherwise.

400
config/example-extras.cfg Normal file
View File

@@ -0,0 +1,400 @@
# This file serves as documentation for config parameters of
# additional devices that may be configured on a printer. The snippets
# in this file may be copied into the main printer.cfg file. See the
# "example.cfg" file for description of common config parameters.
#
# Note, where an extra config section creates additional pins, the
# section defining the pins must be listed in the config file before
# any sections using those pins.
# Z height probe. One may define this section to enable Z height
# probing hardware. When this section is enabled, PROBE and
# QUERY_PROBE extended g-code commands become available. The probe
# section also creates a virtual probe:z_virtual_endstop pin. One may
# set the stepper_z endstop_pin to this virtual pin on cartesian style
# printers that use the probe in place of a z endstop.
#[probe]
#pin: ar15
# Probe detection pin. This parameter must be provided.
#z_offset:
# The distance (in mm) between the bed and the nozzle when the probe
# triggers. This parameter must be provided.
#speed: 5.0
# Speed (in mm/s) of the Z axis when probing. The default is 5mm/s.
#activate_gcode:
# A list of G-Code commands (one per line) to execute prior to each
# probe attempt. This may be useful if the probe needs to be
# activated in some way. The default is to not run any special
# G-Code commands on activation.
#deactivate_gcode:
# A list of G-Code commands (one per line) to execute after each
# probe attempt completes. The default is to not run any special
# G-Code commands on deactivation.
# Bed tilt compensation. One may define a [bed_tilt] config section to
# enable move transformations that account for a tilted bed.
#[bed_tilt]
#x_adjust: 0
# The amount to add to each move's Z height for each mm on the X
# axis. The default is 0.
#y_adjust: 0
# The amount to add to each move's Z height for each mm on the Y
# axis. The default is 0.
# The remaining parameters control a BED_TILT_CALIBRATE extended
# g-code command that may be used to calibrate appropriate x and y
# adjustment parameters.
#points:
# A newline separated list of X,Y points that should be probed
# during a BED_TILT_CALIBRATE command. The default is to not enable
# the command.
#speed: 50
# The speed (in mm/s) of non-probing moves during the
# calibration. The default is 50.
#horizontal_move_z: 5
# The height (in mm) that the head should be commanded to move to
# just prior to starting a probe operation. The default is 5.
#manual_probe:
# If true, then BED_TILT_CALIBRATE will perform manual probing. If
# false, then a PROBE command will be run at each probe
# point. Manual probing is accomplished by manually jogging the Z
# position of the print head at each probe point and then issuing a
# NEXT extended g-code command to record the position at that
# point. The default is false if a [probe] config section is present
# and true otherwise.
# In a multi-extruder printer add an additional extruder section for
# each additional extruder. The additional extruder sections should be
# named "extruder1", "extruder2", "extruder3", and so on. See the
# "extruder" section in example.cfg for a description of available
# parameters.
#[extruder1]
#step_pin: ar36
#dir_pin: ar34
#...
#shared_heater:
# If this extruder uses the same heater already defined for another
# extruder then place the name of that extruder here. For example,
# should extruder3 and extruder4 share a heater then the extruder3
# config section should define the heater and the extruder4 section
# should specify "shared_heater: extruder3". The default is to not
# reuse an existing heater.
#deactivate_gcode:
# A list of G-Code commands (one per line) to execute on a G-Code
# tool change command (eg, "T1") that deactivates this extruder and
# activates some other extruder. It only makes sense to define this
# section on multi-extruder printers. The default is to not run any
# special G-Code commands on deactivation.
#activate_gcode:
# A list of G-Code commands (one per line) to execute on a G-Code
# tool change command (eg, "T0") that activates this extruder. It
# only makes sense to define this section on multi-extruder
# printers. The default is to not run any special G-Code commands on
# activation.
# Support for cartesian printers with dual carriages on a single
# axis. The active carriage is set via the SET_DUAL_CARRIAGE extended
# g-code command. The "SET_DUAL_CARRIAGE CARRIAGE=1" command will
# activate the carriage defined in this section (CARRIAGE=0 will
# return activation to the primary carriage). Dual carriage support is
# typically combined with extra extruders - use the SET_DUAL_CARRIAGE
# command in the activate_gcode / deactivate_gcode section of the
# appropriate extruder. Be sure to also use that mechanism to park the
# carriages during deactivation.
#[dual_carriage]
#axis:
# The axis this extra carriage is on (either x or y). This parameter
# must be provided.
#step_pin:
#dir_pin:
#enable_pin:
#step_distance:
#endstop_pin:
#position_endstop:
#position_min:
#position_max:
# See the example.cfg for the definition of the above parameters.
# Heater and temperature sensor verification. Heater verification is
# automatically enabled for each heater that is configured on the
# printer. Use verify_heater sections to change the default settings.
#[verify_heater heater_config_name]
#heating_gain: 2
# The minimum temperature (in Celsius) that the heater must increase
# by when approaching a new target temperature. The default is 2.
#check_gain_time:
# The amount of time (in seconds) that the heating_gain must be met
# in before an error is raised. The default is 20 seconds for
# extruders and 60 seconds for heater_bed.
#hysteresis: 5
# The difference between the target temperature and the current
# temperature for the heater to be considered within range of the
# target temperature. The default is 5.
#max_error: 120
# The maximum temperature difference a heater that falls outside the
# target temperature range may accumulate before an error is
# raised. For example, if the target temperature is 200, the
# hysteresis is 5, the max_error is 120, and the temperature is
# reported at 185 degrees for 12 seconds then an error would be
# raised (or 24 seconds at 190, or 120 seconds at 194, etc.). The
# default is 120.
# Multi-stepper axes. On a cartesian style printer, the stepper
# controlling a given axis may have additional config blocks defining
# steppers that should be stepped in concert with the primary
# stepper. One may define any number of sections with a numeric suffix
# starting at 1 (for example, "stepper_z1", "stepper_z2", etc.).
#[stepper_z1]
#step_pin: ar36
#dir_pin: ar34
#enable_pin: !ar30
#step_distance: .005
# See the example.cfg for the definition of the above parameters.
#endstop_pin: ^ar19
# If an endstop_pin is defined for the additional stepper then the
# stepper will home until the endstop is triggered. Otherwise, the
# endstop will home until the endstop on the primary stepper for the
# axis is triggered.
# Stepper phase adjusted endstops. The following additional parameters
# may be added to a stepper axis definition to improve the accuracy of
# endstop switches.
#[stepper_z]
#homing_stepper_phases:
# One may set this to the number of phases of the stepper motor
# driver (which is the number of micro-steps multiplied by
# four). This parameter must be provided if using stepper phase
# adjustments.
#homing_endstop_accuracy: 0.200
# Sets the expected accuracy (in mm) of the endstop. This represents
# the maximum error distance the endstop may trigger (eg, if an
# endstop may occasionally trigger 100um early or up to 100um late
# then set this to 0.200 for 200um). The default is
# homing_stepper_phases*step_distance.
#homing_endstop_phase:
# This specifies the phase of the stepper motor driver to expect
# when hitting the endstop. Only set this value if one is sure the
# stepper motor driver is reset every time the mcu is reset. If this
# is not set, then the stepper phase will be detected on the first
# home and that phase will be used on all subsequent homes.
#homing_endstop_align_zero: False
# If true then the code will arrange for the zero position on the
# axis to occur at a full step on the stepper motor. (If used on the
# Z axis and the print layer height is a multiple of a full step
# distance then every layer will occur on a full step.) The default
# is False.
# Heater cooling fans (one may define any number of sections with a
# "heater_fan" prefix). A "heater fan" is a fan that will be enabled
# whenever its associated heater is active. In the event of an MCU
# software error the heater_fan will be set to its max_power.
#[heater_fan my_nozzle_fan]
# See the "fan" section for fan configuration parameters.
#pin: ar4
# The remaining variables are specific to heater_fan.
#heater: extruder
# Name of the config section defining the heater that this fan is
# associated with. The default is "extruder".
#heater_temp: 50.0
# A temperature (in Celsius) that the heater must drop below before
# the fan is disabled. The default is 50 Celsius.
#fan_speed:
# The fan speed (expressed as a value from 0.0 to 1.0) that the fan
# will be set to when its associated heater is enabled. The default
# is max_power.
# Additional micro-controllers (one may define any number of sections
# with an "mcu" prefix). Additional micro-controllers introduce
# additional pins that may be configured as heaters, steppers, fans,
# etc.. For example, if an "[mcu extra_mcu]" section is introduced,
# then pins such as "extra_mcu:ar9" may then be used elsewhere in the
# config (where "ar9" is a hardware pin name or alias name on the
# given mcu).
#[mcu my_extra_mcu]
# See the "mcu" section in example.cfg for configuration parameters.
# Servos (one may define any number of sections with a "servo"
# prefix). The servos may be controlled using the SET_SERVO g-code
# command. For example: SET_SERVO SERVO=my_servo ANGLE=180
#[servo my_servo]
#pin: ar7
# PWM output pin controlling the servo. This parameter must be
# provided.
#maximum_servo_angle: 180
# The maximum angle (in degrees) that this servo can be set to. The
# default is 180 degrees.
#minimum_pulse_width: 0.001
# The minimum pulse width time (in seconds). This should correspond
# with an angle of 0 degrees. The default is 0.001 seconds.
#maximum_pulse_width: 0.002
# The maximum pulse width time (in seconds). This should correspond
# with an angle of maximum_servo_angle. The default is 0.002
# seconds.
# Statically configured digital output pins (one may define any number
# of sections with a "static_digital_output" prefix). Pins configured
# here will be setup as a GPIO output during MCU configuration. They
# can not be changed at run-time.
#[static_digital_output my_output_pins]
#pins:
# A comma separated list of pins to be set as GPIO output pins. The
# pin will be set to a high level unless the pin name is prefaced
# with "!". This parameter must be provided.
# Run-time configurable output pins (one may define any number of
# sections with an "output_pin" prefix). Pins configured here will be
# setup as output pins and one may modify them at run-time using the
# "SET_PIN PIN=my_pin VALUE=.1" extended g-code command.
#[output_pin my_pin]
#pin:
# The pin to configure as an output. This parameter must be
# provided.
#pwm: False
# Set if the output pin should be capable of
# pulse-width-modulation. If this is true, the value fields should
# be between 0 and 1; if it is false the value fields should be
# either 0 or 1. The default is False.
#static_value:
# If this is set, then the pin is assigned to this value at startup
# and the pin can not be changed during runtime. A static pin uses
# slightly less ram in the micro-controller. The default is to use
# runtime configuration of pins.
#value:
# The value to initially set the pin to during MCU
# configuration. The default is 0 (for low voltage).
#shutdown_value:
# The value to set the pin to on an MCU shutdown event. The default
# is 0 (for low voltage).
#cycle_time: 0.100
# The amount of time (in seconds) per PWM cycle. It is recommended
# this be 10 milliseconds or greater when using software based
# PWM. The default is 0.100 seconds for pwm pins.
#hardware_pwm: False
# Enable this to use hardware PWM instead of software PWM. The
# default is False.
#scale:
# This parameter can be used to alter how the 'value' and
# 'shutdown_value' parameters are interpreted for pwm pins. If
# provided, then the 'value' parameter should be between 0.0 and
# 'scale'. This may be useful when configuring a PWM pin that
# controls a stepper voltage reference. The 'scale' can be set to
# the equivalent stepper amperage if the PWM were fully enabled, and
# then the 'value' parameter can be specified using the desired
# amperage for the stepper. The default is to not scale the 'value'
# parameter.
# Multiple pin outputs (one may define any number of sections with a
# "multi_pin" prefix). A multi_pin output creates an internal pin
# alias that can modify multiple output pins each time the alias pin
# is set. For example, one could define a "[multi_pin my_fan]" object
# containing two pins and then set "pin=multi_pin:my_fan" in the
# "[fan]" section - on each fan change both output pins would be
# updated. These aliases may not be used with stepper motor pins.
#[multi_pin my_multi_pin]
#pins:
# A comma separated list of pins associated with this alias. This
# parameter must be provided.
# Statically configured AD5206 digipots connected via SPI bus (one may
# define any number of sections with an "ad5206" prefix).
#[ad5206 my_digipot]
#enable_pin:
# The pin corresponding to the AD5206 chip select line. This pin
# will be set to low at the start of SPI messages and raised to high
# after the message completes. This parameter must be provided.
#channel_1:
#channel_2:
#channel_3:
#channel_4:
#channel_5:
#channel_6:
# The value to statically set the given AD5206 channel to. This is
# typically set to a number between 0.0 and 1.0 with 1.0 being the
# highest resistance and 0.0 being the lowest resistance. However,
# the range may be changed with the 'scale' parameter (see
# below). If a channel is not specified then it is left
# unconfigured.
#scale:
# This parameter can be used to alter how the 'channel_x' parameters
# are interpreted. If provided, then the 'channel_x' parameters
# should be between 0.0 and 'scale'. This may be useful when the
# AD5206 is used to set stepper voltage references. The 'scale' can
# be set to the equivalent stepper amperage if the AD5206 were at
# its highest resistance, and then the 'channel_x' parameters can be
# specified using the desired amperage value for the stepper. The
# default is to not scale the 'channel_x' parameters.
# Homing override. One may use this mechanism to run a series of
# g-code commands in place of a G28 found in the normal g-code input.
# This may be useful on printers that require a specific procedure to
# home the machine.
#[homing_override]
#gcode:
# A list of G-Code commands (one per line) to execute in place of
# all G28 commands found in the normal g-code input. If a G28 is
# contained in this list of commands then it will invoke the normal
# homing procedure for the printer. The commands listed here must
# home all axes. This parameter must be provided.
#set_position_x:
#set_position_y:
#set_position_z:
# If specified, the printer will assume the axis is at the specified
# position prior to running the above g-code commands. Setting this
# disables homing checks for that axis. This may be useful if the
# head must move prior to invoking the normal G28 mechanism for an
# axis. The default is to not force a position for an axis.
# A virtual sdcard may be useful if the host machine is not fast
# enough to run OctoPrint well. It allows the Klipper host software to
# directly print gcode files stored in a directory on the host using
# standard sdcard G-Code commands (eg, M24).
#[virtual_sdcard]
#path: ~/.octoprint/uploads/
# The path of the local directory on the host machine to look for
# g-code files. This is a read-only directory (sdcard file writes
# are not supported). One may point this to OctoPrint's upload
# directory (generally ~/.octoprint/uploads/ ). This parameter must
# be provided.
# Support for a display attached to the micro-controller.
#[display]
#lcd_type:
# The type of LCD chip in use. This may be either "hd44780" (which
# is used in "RepRapDiscount 2004 Smart Controller" type displays)
# or "st7920" (which is used in "RepRapDiscount 12864 Full Graphic
# Smart Controller" type displays). This parameter must be
# provided.
#rs_pin:
#e_pin:
#d4_pin:
#d5_pin:
#d6_pin:
#d7_pin:
# The pins connected to an hd44780 type lcd. These parameters must
# be provided when using an hd44780 display.
#cs_pin:
#sclk_pin:
#sid_pin:
# The pins connected to an st7920 type lcd. These parameters must
# be provided when using an st7920 display.
# Replicape support - see the generic-replicape.cfg file for further
# details.
#[replicape]

View File

@@ -0,0 +1,87 @@
# This file contains an example configuration with three
# micro-controllers simultaneously controlling a single printer.
# See both the example.cfg and example-extras.cfg file for a
# description of available parameters.
# The main micro-controller is used as the timing source for all the
# micro-controllers on the printer. Typically, both the X and Y axes
# are connected to the main micro-controller.
[mcu]
serial: /dev/ttyACM0
pin_map: arduino
# The "zboard" micro-controller will be used to control the Z axis.
[mcu zboard]
serial: /dev/ttyACM1
pin_map: arduino
# The "auxboard" micro-controller will be used to control the heaters.
[mcu auxboard]
serial: /dev/ttyACM2
pin_map: arduino
[stepper_x]
step_pin: ar54
dir_pin: ar55
enable_pin: !ar38
step_distance: .0125
endstop_pin: ^ar3
position_endstop: 0
position_max: 200
homing_speed: 50
[stepper_y]
step_pin: ar60
dir_pin: !ar61
enable_pin: !ar56
step_distance: .0125
endstop_pin: ^ar14
position_endstop: 0
position_max: 200
homing_speed: 50
[stepper_z]
step_pin: zboard:ar46
dir_pin: zboard:ar48
enable_pin: !zboard:ar62
step_distance: .0025
endstop_pin: ^zboard:ar18
position_endstop: 0.5
position_max: 200
[extruder]
step_pin: auxboard:ar26
dir_pin: auxboard:ar28
enable_pin: !auxboard:ar24
step_distance: .002
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: auxboard:ar10
sensor_type: EPCOS 100K B57560G104F
sensor_pin: auxboard:analog13
control: pid
pid_Kp: 22.2
pid_Ki: 1.08
pid_Kd: 114
min_temp: 0
max_temp: 250
[heater_bed]
heater_pin: auxboard:ar8
sensor_type: EPCOS 100K B57560G104F
sensor_pin: auxboard:analog14
control: watermark
min_temp: 0
max_temp: 130
[fan]
pin: auxboard:ar9
[printer]
kinematics: cartesian
max_velocity: 300
max_accel: 3000
max_z_velocity: 5
max_z_accel: 100

View File

@@ -2,7 +2,8 @@
# copy and edit this file to configure a new cartesian style
# printer. For delta style printers, see the "example-delta.cfg"
# file. For corexy/h-bot style printers, see the "example-corexy.cfg"
# file.
# file. Only common config sections are described here - see the
# "example-extras.cfg" file for configuring less common devices.
# DO NOT COPY THIS FILE WITHOUT CAREFULLY READING AND UPDATING IT
# FIRST. Incorrectly configured parameters may cause damage.
@@ -18,53 +19,24 @@
# The stepper_x section is used to describe the stepper controlling
# the X axis in a cartesian robot
# the X axis in a cartesian robot.
[stepper_x]
step_pin: ar29
step_pin: ar54
# Step GPIO pin (triggered high). This parameter must be provided.
dir_pin: !ar28
dir_pin: ar55
# Direction GPIO pin (high indicates positive direction). This
# parameter must be provided.
enable_pin: !ar25
enable_pin: !ar38
# Enable pin (default is enable high; use ! to indicate enable
# low). If this parameter is not provided then the stepper motor
# driver must always be enabled.
step_distance: .0225
# Distance in mm that each step causes the axis to travel. This
# parameter must be provided.
endstop_pin: ^ar0
endstop_pin: ^ar3
# Endstop switch detection pin. This parameter must be provided for
# the X, Y, and Z steppers on cartesian style printers.
#homing_speed: 5.0
# Maximum velocity (in mm/s) of the stepper when homing. The default
# is 5mm/s.
#homing_retract_dist: 5.0
# Distance to backoff (in mm) before homing a second time during
# homing. The default is 5mm.
#homing_positive_dir: False
# If true, homes in a positive direction (away from zero). The
# default is False.
#homing_stepper_phases: 0
# One may optionally set this to the number of phases of the stepper
# motor driver (which is the number of micro-steps multiplied by
# four). When set, the phase of the stepper driver will be used
# during homing to improve the accuracy of the endstop switch.
#homing_endstop_accuracy: 0.200
# Sets the expected accuracy (in mm) of the endstop. This represents
# the maximum error distance the endstop may trigger (eg, if an
# endstop may occasionally trigger 100um early or up to 100um late
# then set this to 0.200 for 200um). This setting is used with
# homing_stepper_phases and is only useful if that parameter is also
# configured.
#homing_endstop_phase: 0
# This specifies the phase of the stepper motor driver to expect
# when hitting the endstop. This setting is only meaningful if
# homing_stepper_phases is also set. Only set this value if one is
# sure the stepper motor driver is reset every time the mcu is
# reset. If this is not set, but homing_stepper_phases is set, then
# the stepper phase will be detected on the first home and that
# phase will be used on all subsequent homes.
position_min: -0.25
#position_min: 0
# Minimum valid distance (in mm) the user may command the stepper to
# move to. The default is 0mm.
position_endstop: 0
@@ -74,30 +46,39 @@ position_max: 200
# Maximum valid distance (in mm) the user may command the stepper to
# move to. This parameter must be provided for the X, Y, and Z
# steppers on cartesian style printers.
#homing_speed: 5.0
# Maximum velocity (in mm/s) of the stepper when homing. The default
# is 5mm/s.
#homing_retract_dist: 5.0
# Distance to backoff (in mm) before homing a second time during
# homing. The default is 5mm.
#homing_positive_dir:
# If true, homing will cause the stepper to move in a positive
# direction (away from zero); if false, home towards zero. The
# default is true if position_endstop is near position_max and false
# if near position_min.
# The stepper_y section is used to describe the stepper controlling
# the Y axis in a cartesian robot. It has the same settings as the
# stepper_x section
# stepper_x section.
[stepper_y]
step_pin: ar27
dir_pin: ar26
enable_pin: !ar25
step_pin: ar60
dir_pin: !ar61
enable_pin: !ar56
step_distance: .0225
endstop_pin: ^ar1
position_min: -0.25
endstop_pin: ^ar14
position_endstop: 0
position_max: 200
# The stepper_z section is used to describe the stepper controlling
# the Z axis in a cartesian robot. It has the same settings as the
# stepper_x section
# stepper_x section.
[stepper_z]
step_pin: ar23
dir_pin: !ar22
enable_pin: !ar25
step_pin: ar46
dir_pin: ar48
enable_pin: !ar62
step_distance: .005
endstop_pin: ^ar2
position_min: 0.1
endstop_pin: ^ar18
position_endstop: 0.5
position_max: 200
@@ -105,11 +86,11 @@ position_max: 200
# controlling the printer extruder and the heater parameters for the
# nozzle. The stepper configuration has the same settings as the
# stepper_x section and the heater configuration has the same settings
# as the heater_bed section
# as the heater_bed section (described below).
[extruder]
step_pin: ar19
dir_pin: ar18
enable_pin: !ar25
step_pin: ar26
dir_pin: ar28
enable_pin: !ar24
step_distance: .004242
nozzle_diameter: 0.500
# Diameter of the nozzle orifice (in mm). This parameter must be
@@ -119,9 +100,10 @@ filament_diameter: 3.500
# extruder. This parameter must be provided.
#max_extrude_cross_section:
# Maximum area of the cross section of an extrusion line (in
# mm^2). If a move requests an extrusion rate that would exceed this
# value it will cause an error to be returned. The default is: 4.0 *
# nozzle_diameter^2
# mm^2). This setting prevents excessive amounts of extrusion during
# relatively small XY moves. If a move requests an extrusion rate
# that would exceed this value it will cause an error to be
# returned. The default is: 4.0 * nozzle_diameter^2
#max_extrude_only_distance: 50.0
# Maximum length (in mm of raw filament) that an extrude only move
# may be. If an extrude only move requests a distance greater than
@@ -151,8 +133,8 @@ filament_diameter: 3.500
# buildup. This setting only applies if pressure_advance is
# non-zero. The default is 0.010 (10 milliseconds).
#
# The remaining variables describe the extruder heater
heater_pin: ar4
# The remaining variables describe the extruder heater.
heater_pin: ar10
# PWM output pin controlling the heater. This parameter must be
# provided.
#max_power: 1.0
@@ -164,8 +146,9 @@ heater_pin: ar4
# periods) to the heater. The default is 1.0.
sensor_type: EPCOS 100K B57560G104F
# Type of sensor - this may be "EPCOS 100K B57560G104F", "ATC
# Semitec 104GT-2", or "AD595". This parameter must be provided.
sensor_pin: analog1
# Semitec 104GT-2", "NTC 100K beta 3950", or "AD595". This parameter
# must be provided.
sensor_pin: analog13
# Analog input pin connected to the sensor. This parameter must be
# provided.
#pullup_resistor: 4700
@@ -194,22 +177,31 @@ pid_Kd: 114
#pid_integral_max:
# The maximum "windup" the integral term may accumulate. The default
# is to use the same value as max_power.
#pwm_cycle_time: 0.100
# Time in seconds for each software PWM cycle of the heater. It is
# not recommended to set this unless there is an electrical
# requirement to switch the heater faster than 10 times a second.
# The default is 0.100 seconds.
#min_extrude_temp: 170
# The minimum temperature (in Celsius) at which extruder move
# commands may be issued. The default is 170 Celsius.
min_temp: 0
# Minimum temperature in Celsius (mcu will shutdown if not
# met). This parameter must be provided.
max_temp: 210
# Maximum temperature (mcu will shutdown if temperature is above
# this value). This parameter must be provided.
# The maximum range of valid temperatures (in Celsius) that the
# heater must remain within. This controls a safety feature
# implemented in the micro-controller code - should the measured
# temperature ever fall outside this range then the micro-controller
# will go into a shutdown state. This check can help detect some
# heater and sensor hardware failures. Set this range just wide
# enough so that reasonable temperatures do not result in an
# error. These parameters must be provided.
# The heater_bed section describes a heated bed (if present - omit
# section if not present).
[heater_bed]
heater_pin: ar3
heater_pin: ar8
sensor_type: EPCOS 100K B57560G104F
sensor_pin: analog0
sensor_pin: analog14
control: watermark
#max_delta: 2.0
# On 'watermark' controlled heaters this is the number of degrees in
@@ -219,22 +211,30 @@ control: watermark
min_temp: 0
max_temp: 110
# Extruder print fan (omit section if fan not present)
# Print cooling fan (omit section if fan not present).
[fan]
pin: ar14
pin: ar9
# PWM output pin controlling the fan. This parameter must be
# provided.
#hard_pwm: 0
# Set this value to force hardware PWM instead of software PWM. Set
# to 1 to force a hardware PWM at the fastest rate; set to a higher
# number to force hardware PWM with the given cycle time in clock
# ticks. The default is 0 which enables software PWM with a cycle
# time of 10ms.
#max_power: 1.0
# The maximum power (expressed as a value from 0.0 to 1.0) that the
# pin may be set to. The value 1.0 allows the pin to be set fully
# enabled for extended periods, while a value of 0.5 would allow the
# pin to be enabled for no more than half the time. This setting may
# be used to limit the total power output (over extended periods) to
# the fan. The default is 1.0.
#cycle_time: 0.010
# The amount of time (in seconds) for each PWM power cycle to the
# fan. It is recommended this be 10 milliseconds or greater when
# using software based PWM. The default is 0.010 seconds.
#hardware_pwm: False
# Enable this to use hardware PWM instead of software PWM. The
# default is False.
#kick_start_time: 0.100
# Time (in seconds) to run the fan at full speed when first enabling
# it (helps get the fan spinning). The default is 0.100 seconds.
# Micro-controller information
# Micro-controller information.
[mcu]
serial: /dev/ttyACM0
# The serial port to connect to the MCU. The default is /dev/ttyS0
@@ -243,24 +243,19 @@ serial: /dev/ttyACM0
pin_map: arduino
# This option may be used to enable Arduino pin name aliases. The
# default is to not enable the aliases.
#restart_method: arduino
#restart_method:
# This controls the mechanism the host will use to reset the
# micro-controller. The choices are 'arduino', 'rpi_usb', and
# 'command'. The 'arduino' method (toggle DTR; set baud to 1200) is
# common on Arduino boards and clones. The 'rpi_usb' method is
# useful on Raspberry Pi boards with micro-controllers powered over
# USB - it briefly disables power to all USB ports to accomplish a
# micro-controller reset. The 'command' method involves sending a
# Klipper command to the micro-controller so that it can reset
# itself. The default is 'arduino'.
custom:
# This option may be used to specify a set of custom
# micro-controller commands to be sent at the start of the
# connection. It may be used to configure the initial settings of
# LEDs, to configure micro-stepping pins, to configure a digipot,
# etc.
# 'command'. The 'arduino' method (toggle DTR) is common on Arduino
# boards and clones. The 'rpi_usb' method is useful on Raspberry Pi
# boards with micro-controllers powered over USB - it briefly
# disables power to all USB ports to accomplish a micro-controller
# reset. The 'command' method involves sending a Klipper command to
# the micro-controller so that it can reset itself. The default is
# 'arduino' if the micro-controller communicates over a serial port,
# 'command' otherwise.
# The printer section controls high level printer settings
# The printer section controls high level printer settings.
[printer]
kinematics: cartesian
# This option must be "cartesian" for cartesian printers.
@@ -294,3 +289,6 @@ max_z_accel: 30
# centripetal velocity cornering algorithm. A larger number will
# permit higher "cornering speeds" at the junction of two moves. The
# default is 0.02mm.
# Looking for more options? Check the example-extras.cfg file.

86
config/generic-cramps.cfg Normal file
View File

@@ -0,0 +1,86 @@
# This file contains an example configuration for a Beaglebone PRU
# micro-controller attached to a CRAMPS board.
# THIS FILE HAS NOT BEEN TESTED - PROCEED WITH CAUTION!
# NOTE: Klipper does not alter the input/output state of the
# Beaglebone pins and it does not control their pull-up resistors. In
# order to set the pin state one must use a "device tree overlay" or
# use the config-pin program.
# See the example.cfg file for a description of available parameters.
[stepper_x]
step_pin: P8_13
dir_pin: P8_12
enable_pin: !P9_14
step_distance: .0125
endstop_pin: ^P8_8
position_endstop: 0
position_max: 200
homing_speed: 50
[stepper_y]
step_pin: P8_15
dir_pin: P8_14
enable_pin: !P9_14
step_distance: .0125
endstop_pin: ^P8_10
position_endstop: 0
position_max: 200
homing_speed: 50
[stepper_z]
step_pin: P8_19
dir_pin: P8_18
enable_pin: !P9_14
step_distance: .0025
endstop_pin: ^P9_13
position_endstop: 0
position_max: 200
[extruder]
step_pin: P9_16
dir_pin: P9_12
enable_pin: !P9_14
step_distance: .002
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: P9_15
sensor_type: EPCOS 100K B57560G104F
pullup_resistor: 2000
sensor_pin: P9_36
control: pid
pid_Kp: 22.2
pid_Ki: 1.08
pid_Kd: 114
min_temp: 0
max_temp: 250
[heater_bed]
heater_pin: P8_11
sensor_type: EPCOS 100K B57560G104F
pullup_resistor: 2000
sensor_pin: P9_33
control: watermark
min_temp: 0
max_temp: 130
[fan]
pin: P9_41
[mcu]
serial: /dev/rpmsg_pru30
pin_map: beaglebone
[printer]
kinematics: cartesian
max_velocity: 300
max_accel: 3000
max_z_velocity: 5
max_z_accel: 100
[output_pin machine_enable]
pin: P9_23
value: 1
shutdown_value: 0

79
config/generic-melzi.cfg Normal file
View File

@@ -0,0 +1,79 @@
# This file contains common pin mappings for Melzi v2.0 boards. To use
# this config, the firmware should be compiled for the AVR
# atmega1284p.
# Note, a number of Melzi boards are shipped without a bootloader. In
# that case, an external programmer will be needed to flash a
# bootloader to the board (for example, see
# http://www.instructables.com/id/Flashing-a-Bootloader-to-the-CR-10/
# ). Once that is done, one should be able to use the standard "make
# flash" command to flash Klipper.
# See the example.cfg file for a description of available parameters.
[stepper_x]
step_pin: PD7
dir_pin: PC5
enable_pin: !PD6
step_distance: .0125
endstop_pin: ^!PC2
position_endstop: 0
position_max: 200
homing_speed: 50
[stepper_y]
step_pin: PC6
dir_pin: PC7
enable_pin: !PD6
step_distance: .0125
endstop_pin: ^!PC3
position_endstop: 0
position_max: 200
homing_speed: 50
[stepper_z]
step_pin: PB3
dir_pin: !PB2
enable_pin: !PA5
step_distance: .0025
endstop_pin: ^!PC4
position_endstop: 0.5
position_max: 200
[extruder]
step_pin: PB1
dir_pin: PB0
enable_pin: !PD6
step_distance: .002
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: PD5
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PA7
control: pid
pid_Kp: 22.2
pid_Ki: 1.08
pid_Kd: 114
min_temp: 0
max_temp: 250
[heater_bed]
heater_pin: PD2
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PA6
control: watermark
min_temp: 0
max_temp: 130
[fan]
pin: PB4
[mcu]
serial: /dev/ttyUSB0
[printer]
kinematics: cartesian
max_velocity: 300
max_accel: 3000
max_z_velocity: 5
max_z_accel: 100

View File

@@ -0,0 +1,109 @@
# This file contains common pin mappings for Mini-RAMBo boards. To use
# this config, the firmware should be compiled for the AVR atmega2560.
# See the example.cfg file for a description of available parameters.
[stepper_x]
step_pin: PC0
dir_pin: PL1
enable_pin: !PA7
step_distance: .005
endstop_pin: ^PB6
#endstop_pin: ^PC7
position_endstop: 0
position_max: 250
[stepper_y]
step_pin: PC1
dir_pin: !PL0
enable_pin: !PA6
step_distance: .005
endstop_pin: ^PB5
#endstop_pin: ^PA2
position_endstop: 0
position_max: 210
[stepper_z]
step_pin: PC2
dir_pin: PL2
enable_pin: !PA5
step_distance: .0025
endstop_pin: ^PB4
#endstop_pin: ^PA1
position_endstop: 0.5
position_max: 200
[extruder]
step_pin: PC3
dir_pin: PL6
enable_pin: !PA4
step_distance: .002
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: PE5
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PF0
control: pid
pid_Kp: 22.2
pid_Ki: 1.08
pid_Kd: 114
min_temp: 0
max_temp: 250
[heater_bed]
heater_pin: PG5
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PF2
control: watermark
min_temp: 0
max_temp: 130
[fan]
pin: PH5
#[heater_fan nozzle_cooling_fan]
#pin: PH3
[mcu]
serial: /dev/ttyACM0
[printer]
kinematics: cartesian
max_velocity: 300
max_accel: 3000
max_z_velocity: 5
max_z_accel: 100
[output_pin stepper_xy_current]
pin: PL3
pwm: True
scale: 2.0
cycle_time: .002
hardware_pwm: True
static_value: 1.3
[output_pin stepper_z_current]
pin: PL4
pwm: True
scale: 2.0
cycle_time: .002
hardware_pwm: True
static_value: 1.3
[output_pin stepper_e_current]
pin: PL5
pwm: True
scale: 2.0
cycle_time: .002
hardware_pwm: True
static_value: 1.25
[static_digital_output stepper_config]
pins:
PG1, PG0,
PK7, PG2,
PK6, PK5,
PK3, PK4
[static_digital_output yellow_led]
pins: !PB7

View File

@@ -0,0 +1,76 @@
# This file contains common pin mappings for Printrboard boards (rev B
# through D). To use this config the firmware should be compiled for
# the AVR at90usb1286.
# Note that the "make flash" command is unlikely to work on the
# Printrboard. See the RepRap Printrboard wiki page for instructions
# on flashing.
# See the example.cfg file for a description of available parameters.
[stepper_x]
step_pin: PA0
dir_pin: !PA1
enable_pin: !PE7
step_distance: .0125
endstop_pin: ^PE3
position_endstop: 0
position_max: 200
homing_speed: 50
[stepper_y]
step_pin: PA2
dir_pin: PA3
enable_pin: !PE6
step_distance: .0125
endstop_pin: ^PB0
position_endstop: 0
position_max: 200
homing_speed: 50
[stepper_z]
step_pin: PA4
dir_pin: !PA5
enable_pin: !PC7
step_distance: .0025
endstop_pin: ^PE4
position_endstop: 0.5
position_max: 200
[extruder]
step_pin: PA6
dir_pin: PA7
enable_pin: !PC3
step_distance: .002
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: PC5
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PF1
control: pid
pid_Kp: 22.2
pid_Ki: 1.08
pid_Kd: 114
min_temp: 0
max_temp: 250
[heater_bed]
heater_pin: PC4
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PF0
control: watermark
min_temp: 0
max_temp: 130
[fan]
pin: PC6
[mcu]
serial: /dev/ttyACM0
[printer]
kinematics: cartesian
max_velocity: 300
max_accel: 3000
max_z_velocity: 5
max_z_accel: 100

View File

@@ -9,9 +9,10 @@ dir_pin: PL1
enable_pin: !PA7
step_distance: .0125
endstop_pin: ^PB6
homing_speed: 50
#endstop_pin: ^PA2
position_endstop: 0
position_max: 200
homing_speed: 50
[stepper_y]
step_pin: PC1
@@ -19,18 +20,19 @@ dir_pin: !PL0
enable_pin: !PA6
step_distance: .0125
endstop_pin: ^PB5
homing_speed: 50
#endstop_pin: ^PA1
position_endstop: 0
position_max: 200
homing_speed: 50
[stepper_z]
step_pin: PC2
dir_pin: PL2
enable_pin: !PA5
step_distance: 0.00025
step_distance: .0025
endstop_pin: ^PB4
homing_speed: 5
position_endstop: 0
#endstop_pin: ^PC7
position_endstop: 0.5
position_max: 200
[extruder]
@@ -50,6 +52,14 @@ pid_Kd: 114
min_temp: 0
max_temp: 250
#[extruder1]
#step_pin: PC4
#dir_pin: PL7
#enable_pin: !PA3
#heater_pin: PH4
#sensor_pin: PF1
#...
[heater_bed]
heater_pin: PE5
sensor_type: EPCOS 100K B57560G104F
@@ -61,26 +71,11 @@ max_temp: 130
[fan]
pin: PH5
#[heater_fan nozzle_cooling_fan]
#pin: PH3
[mcu]
serial: /dev/ttyACM0
custom:
# Turn off yellow led
set_digital_out pin=PB7 value=0
# Stepper micro-step pins
set_digital_out pin=PG1 value=1
set_digital_out pin=PG0 value=1
set_digital_out pin=PK7 value=1
set_digital_out pin=PG2 value=1
set_digital_out pin=PK6 value=1
set_digital_out pin=PK5 value=1
set_digital_out pin=PK3 value=1
set_digital_out pin=PK4 value=1
# Initialize digipot
send_spi_message pin=PD7 msg=0487 # X = ~0.75A
send_spi_message pin=PD7 msg=0587 # Y = ~0.75A
send_spi_message pin=PD7 msg=0387 # Z = ~0.75A
send_spi_message pin=PD7 msg=00A5 # E0
send_spi_message pin=PD7 msg=017D # E1
[printer]
kinematics: cartesian
@@ -88,3 +83,44 @@ max_velocity: 300
max_accel: 3000
max_z_velocity: 5
max_z_accel: 100
[ad5206 stepper_digipot]
enable_pin: PD7
# Scale the config so that the channel value can be specified in amps.
# (For Rambo v1.0d boards, use 1.56 instead.)
scale: 2.08
# Channel 1 is E0, 2 is E1, 3 is unused, 4 is Z, 5 is X, 6 is Y
channel_1: 1.34
channel_2: 1.0
channel_4: 1.1
channel_5: 1.1
channel_6: 1.1
# Enable 16 micro-steps on steppers X, Y, Z, E0, E1
[static_digital_output stepper_config]
pins:
PG1, PG0,
PK7, PG2,
PK6, PK5,
PK3, PK4,
PK1, PK2
[static_digital_output yellow_led]
pins: !PB7
# "RepRapDiscount 2004 Smart Controller" type displays
#[display]
#lcd_type: hd44780
#rs_pin: PG4
#e_pin: PG3
#d4_pin: PJ2
#d5_pin: PJ3
#d6_pin: PJ7
#d7_pin: PJ4
# "RepRapDiscount 128x64 Full Graphic Smart Controller" type displays
#[display]
#lcd_type: st7920
#cs_pin: PG4
#sclk_pin: PJ2
#sid_pin: PG3

View File

@@ -10,9 +10,10 @@ dir_pin: ar55
enable_pin: !ar38
step_distance: .0125
endstop_pin: ^ar3
homing_speed: 50
#endstop_pin: ^ar2
position_endstop: 0
position_max: 200
homing_speed: 50
[stepper_y]
step_pin: ar60
@@ -20,18 +21,19 @@ dir_pin: !ar61
enable_pin: !ar56
step_distance: .0125
endstop_pin: ^ar14
homing_speed: 50
#endstop_pin: ^ar15
position_endstop: 0
position_max: 200
homing_speed: 50
[stepper_z]
step_pin: ar46
dir_pin: ar48
enable_pin: !ar62
step_distance: 0.00025
step_distance: .0025
endstop_pin: ^ar18
homing_speed: 5
position_endstop: 0
#endstop_pin: ^ar19
position_endstop: 0.5
position_max: 200
[extruder]
@@ -51,6 +53,14 @@ pid_Kd: 114
min_temp: 0
max_temp: 250
#[extruder1]
#step_pin: ar36
#dir_pin: ar34
#enable_pin: !ar30
#heater_pin: ar9
#sensor_pin: analog15
#...
[heater_bed]
heater_pin: ar8
sensor_type: EPCOS 100K B57560G104F
@@ -72,3 +82,20 @@ max_velocity: 300
max_accel: 3000
max_z_velocity: 5
max_z_accel: 100
# "RepRapDiscount 2004 Smart Controller" type displays
#[display]
#lcd_type: hd44780
#rs_pin: ar16
#e_pin: ar17
#d4_pin: ar23
#d5_pin: ar25
#d6_pin: ar27
#d7_pin: ar29
# "RepRapDiscount 128x64 Full Graphic Smart Controller" type displays
#[display]
#lcd_type: st7920
#cs_pin: ar16
#sclk_pin: ar23
#sid_pin: ar17

View File

@@ -0,0 +1,134 @@
# This file contains an example configuration for the Replicape rev B3
# board. To use this config, one must compile and install the
# micro-controller code for the "Beaglebone PRU", and then compile and
# install the micro-controller code a second time for a "Linux
# process".
# NOTE: Klipper does not alter the input/output state of the
# Beaglebone pins and it does not control their pull-up resistors.
# Typically the correct settings are automatically applied when the
# Beaglebone detects the Replicape board, but if changes are needed
# they must be specified in a "device tree overlay" or via the
# config-pin program.
# See the example.cfg file for a description of available parameters.
[mcu]
serial: /dev/rpmsg_pru30
pin_map: beaglebone
[mcu host]
serial: /tmp/klipper_host_mcu
# The "replicape" config section adds "replicape:stepper_x_enable"
# virtual stepper enable pins (for steppers x, y, z, e, and h) and
# "replicape:power_x" PWM output pins (for hotbed, e, h, fan0, fan1,
# fan2, and fan3) that may then be used elsewhere in the config file.
[replicape]
revision: B3
# The replicape hardware revision. Currently only revision "B3" is
# supported. This parameter must be provided.
#enable_pin: !P9_41
# The replicape global enable pin. The default is !P9_41.
host_mcu: host
# The name of the mcu config section that communicates with the
# Klipper "linux process" mcu instance. This parameter must be
# provided.
#standstill_power_down: False
# This parameter controls the CFG6_ENN line on all stepper
# motors. True sets the enable lines to "open". The default is
# False.
#servo0_enable: False
# This parameter controls whether end_stop_X_2 is used for endstops
# (via P9_11) or for servo_0 (via P9_14). The default is False.
#servo1_enable: False
# This parameter controls whether end_stop_Y_2 is used for endstops
# (via P9_28) or for servo_1 (via P9_16). The default is False.
stepper_x_microstep_mode: spread16
# This parameter controls the CFG1 and CFG2 pins of the given
# stepper motor driver. Available options are: disable, 1, 2,
# spread2, 4, 16, spread4, spread16, stealth4, and stealth16. The
# default is disable.
stepper_x_current: 0.5
# The configured maximum current (in Amps) of the stepper motor
# driver. This parameter must be provided if the stepper is not in a
# disable mode.
#stepper_x_chopper_off_time_high: False
# This parameter controls the CFG0 pin of the stepper motor driver
# (True sets CFG0 high, False sets it low). The default is False.
#stepper_x_chopper_hysteresis_high: False
# This parameter controls the CFG4 pin of the stepper motor driver
# (True sets CFG4 high, False sets it low). The default is False.
#stepper_x_chopper_blank_time_high: True
# This parameter controls the CFG5 pin of the stepper motor driver
# (True sets CFG5 high, False sets it low). The default is True.
stepper_y_microstep_mode: spread16
stepper_y_current: 0.5
stepper_z_microstep_mode: spread16
stepper_z_current: 0.5
stepper_e_microstep_mode: 16
stepper_e_current: 0.5
[stepper_x]
step_pin: P8_17
dir_pin: P8_26
enable_pin: replicape:stepper_x_enable
step_distance: .0125
endstop_pin: ^P9_25
position_endstop: 0
position_max: 200
homing_speed: 50
[stepper_y]
step_pin: P8_12
dir_pin: P8_19
enable_pin: replicape:stepper_y_enable
step_distance: .0125
endstop_pin: ^P9_23
position_endstop: 0
position_max: 200
homing_speed: 50
[stepper_z]
step_pin: P8_13
dir_pin: P8_14
enable_pin: replicape:stepper_z_enable
step_distance: .0025
endstop_pin: ^P9_13
position_endstop: 0
position_max: 200
[printer]
kinematics: cartesian
max_velocity: 300
max_accel: 3000
max_z_velocity: 25
max_z_accel: 30
[extruder]
step_pin: P9_12
dir_pin: P8_15
enable_pin: replicape:stepper_e_enable
step_distance: .002
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: replicape:power_e
sensor_type: EPCOS 100K B57560G104F
sensor_pin: host:analog4
control: pid
pid_Kp: 22.2
pid_Ki: 1.08
pid_Kd: 114
min_temp: 0
max_temp: 250
[heater_bed]
heater_pin: replicape:power_hotbed
sensor_type: EPCOS 100K B57560G104F
sensor_pin: host:analog6
control: watermark
min_temp: 0
max_temp: 130
[fan]
pin: replicape:power_fan0

View File

@@ -0,0 +1,79 @@
# This file contains common pin mappings for Anet A8 printer from 2016
# and 2017. To use this config, the firmware should be compiled for
# the AVR atmega1284p.
# Note that the "make flash" command does not work with Anet boards -
# the boards are typically flashed with this command:
# avrdude -p atmega1284p -c arduino -b 57600 -P /dev/ttyUSB0 -U out/klipper.elf.hex
# See the example.cfg file for a description of available parameters.
[stepper_x]
step_pin: PD7
dir_pin: PC5
enable_pin: !PD6
step_distance: .01
endstop_pin: ^!PC2
position_endstop: -30
position_max: 220
position_min: -30
homing_speed: 50
[stepper_y]
step_pin: PC6
dir_pin: PC7
enable_pin: !PD6
step_distance: .01
endstop_pin: ^!PC3
position_endstop: -8
position_min: -8
position_max: 220
homing_speed: 50
[stepper_z]
step_pin: PB3
dir_pin: !PB2
enable_pin: !PA5
step_distance: .0025
endstop_pin: ^!PC4
position_endstop: 0.5
position_max: 240
homing_speed: 20
[extruder]
step_pin: PB1
dir_pin: PB0
enable_pin: !PD6
step_distance: .0105
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: PD5
sensor_type: ATC Semitec 104GT-2
sensor_pin: PA7
control: pid
pid_Kp: 2.151492
pid_Ki: 0.633897
pid_Kd: 230.042965
min_temp: 0
max_temp: 250
[heater_bed]
heater_pin: PD4
sensor_type: ATC Semitec 104GT-2
sensor_pin: PA6
control: watermark
min_temp: 0
max_temp: 130
[fan]
pin: PB4
[mcu]
serial: /dev/ttyUSB0
[printer]
kinematics: cartesian
max_velocity: 300
max_accel: 1000
max_z_velocity: 20
max_z_accel: 100

View File

@@ -0,0 +1,93 @@
# This file contains pin mappings for the Anycubic i3 Mega with
# Ultrabase from 2017. (This config may work on an Anycubic i3 Mega v1
# prior to the Ultrabase if you comment out the definition of the
# endstop_pin in the stepper_z1 section.) To use this config, the
# firmware should be compiled for the AVR atmega2560.
# See the example.cfg file for a description of available parameters.
[stepper_x]
step_pin: ar54
dir_pin: !ar55
enable_pin: !ar38
step_distance: .0125
endstop_pin: ^!ar3
position_min: -5
position_endstop: -5
position_max: 210
homing_speed: 30.0
[stepper_y]
step_pin: ar60
dir_pin: ar61
enable_pin: !ar56
step_distance: .0125
endstop_pin: ^!ar42
position_endstop: 0
position_max: 210
homing_speed: 30.0
[stepper_z]
step_pin: ar46
dir_pin: ar48
enable_pin: !ar62
step_distance: .0025
endstop_pin: ^!ar18
position_endstop: 0.0
position_max: 205
homing_speed: 5.0
[stepper_z1]
step_pin: ar36
dir_pin: ar34
enable_pin: !ar30
step_distance: .0025
endstop_pin: ^!ar43
[extruder]
step_pin: ar26
dir_pin: ar28
enable_pin: !ar24
step_distance: .010799
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: ar10
sensor_type: ATC Semitec 104GT-2
sensor_pin: analog13
control: pid
pid_Kp: 15.717
pid_Ki: 0.569
pid_Kd: 108.451
min_temp: 0
max_temp: 245
[heater_fan extruder_fan]
pin: ar44
[heater_bed]
heater_pin: ar8
sensor_type: EPCOS 100K B57560G104F
sensor_pin: analog14
control: pid
pid_Kp: 74.883
pid_Ki: 1.809
pid_Kd: 775.038
min_temp: 0
max_temp: 110
[fan]
pin: ar9
[mcu]
serial: /dev/ttyUSB0
pin_map: arduino
[printer]
kinematics: cartesian
max_velocity: 300
max_accel: 3000
max_z_velocity: 10
max_z_accel: 60
[heater_fan stepstick_fan]
pin: ar7

View File

@@ -0,0 +1,88 @@
# This file contains common pin mappings for the 2017 Creality
# CR-10. To use this config, the firmware should be compiled for the
# AVR atmega1284p.
# Note, a number of Melzi boards are shipped without a bootloader. In
# that case, an external programmer will be needed to flash a
# bootloader to the board (for example, see
# http://www.instructables.com/id/Flashing-a-Bootloader-to-the-CR-10/
# ). Once that is done, one should be able to use the standard "make
# flash" command to flash Klipper.
# See the example.cfg file for a description of available parameters.
[stepper_x]
step_pin: PD7
dir_pin: !PC5
enable_pin: !PD6
step_distance: .0125
endstop_pin: ^PC2
position_endstop: 0
position_max: 300
homing_speed: 50
[stepper_y]
step_pin: PC6
dir_pin: !PC7
enable_pin: !PD6
step_distance: .0125
endstop_pin: ^PC3
position_endstop: 0
position_max: 300
homing_speed: 50
[stepper_z]
step_pin: PB3
dir_pin: PB2
enable_pin: !PA5
step_distance: .0025
endstop_pin: ^PC4
position_endstop: 0.0
position_max: 400
[extruder]
step_pin: PB1
dir_pin: !PB0
enable_pin: !PD6
step_distance: 0.010526
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: PD5
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PA7
control: pid
pid_Kp: 22.57
pid_Ki: 1.72
pid_Kd: 73.96
min_temp: 0
max_temp: 250
[heater_bed]
heater_pin: PD4
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PA6
control: pid
pid_Kp: 426.68
pid_Ki: 78.92
pid_Kd: 576.71
min_temp: 0
max_temp: 130
[fan]
pin: PB4
[mcu]
serial: /dev/ttyUSB0
[printer]
kinematics: cartesian
max_velocity: 300
max_accel: 3000
max_z_velocity: 5
max_z_accel: 100
[display]
lcd_type: st7920
cs_pin: PA3
sclk_pin: PA1
sid_pin: PC1

View File

@@ -0,0 +1,75 @@
# This file contains pin mappings for the 2017 Creality CR-10S. To use
# this config, the firmware should be compiled for the AVR atmega2560.
# See the example.cfg file for a description of available parameters.
[stepper_x]
step_pin: ar54
dir_pin: ar55
enable_pin: !ar38
step_distance: .0125
endstop_pin: ^ar3
position_endstop: 0
position_max: 300
homing_speed: 50
[stepper_y]
step_pin: ar60
dir_pin: ar61
enable_pin: !ar56
step_distance: .0125
endstop_pin: ^ar14
position_endstop: 0
position_max: 300
homing_speed: 50
[stepper_z]
step_pin: ar46
dir_pin: !ar48
enable_pin: !ar62
step_distance: .0025
endstop_pin: ^ar18
position_endstop: 0.5
position_max: 200
[extruder]
step_pin: ar26
dir_pin: ar28
enable_pin: !ar24
step_distance: .010526
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: ar10
sensor_type: EPCOS 100K B57560G104F
sensor_pin: analog13
control: pid
pid_Kp: 22.2
pid_Ki: 1.08
pid_Kd: 114
min_temp: 0
max_temp: 250
[heater_bed]
heater_pin: ar8
sensor_type: EPCOS 100K B57560G104F
sensor_pin: analog14
control: pid
pid_Kp: 690.34
pid_Ki: 111.47
pid_Kd: 1068.83
min_temp: 0
max_temp: 130
[fan]
pin: ar9
[mcu]
serial: /dev/ttyUSB0
pin_map: arduino
[printer]
kinematics: cartesian
max_velocity: 300
max_accel: 3000
max_z_velocity: 5
max_z_accel: 100

View File

@@ -0,0 +1,116 @@
# This file contains pin mappings for the Lulzbot TAZ 6 circa 2017. To
# use this config, the firmware should be compiled for the AVR
# atmega2560.
# See the example.cfg file for a description of available parameters.
[stepper_x]
step_pin: PC0
dir_pin: PL1
enable_pin: !PA7
step_distance: .010000
endstop_pin: ^PB6
position_endstop: -20
position_min: -20
position_max: 300
homing_speed: 50
[stepper_y]
step_pin: PC1
dir_pin: !PL0
enable_pin: !PA6
step_distance: .010000
endstop_pin: ^PA1
position_endstop: 306
position_min: -20
position_max: 306
homing_speed: 50
[stepper_z]
step_pin: PC2
dir_pin: PL2
enable_pin: !PA5
step_distance: 0.000625
endstop_pin: ^!PB4
position_endstop: -0.7
position_min: -1.5
position_max: 270
homing_speed: 1
[extruder]
step_pin: PC3
dir_pin: !PL6
enable_pin: !PA4
step_distance: 0.001182
nozzle_diameter: 0.400
filament_diameter: 2.920
heater_pin: PH6
sensor_type: ATC Semitec 104GT-2
sensor_pin: PF0
control: pid
pid_Kp: 28.79
pid_Ki: 1.91
pid_Kd: 108.51
min_temp: 0
max_temp: 300
min_extrude_temp: 140
#[extruder1]
#step_pin: PC4
#dir_pin: PL7
#enable_pin: !PA3
#heater_pin: PH4
#sensor_pin: PF1
#...
[heater_bed]
heater_pin: PE5
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PF2
control: watermark
min_temp: 0
max_temp: 130
[fan]
pin: PH5
[heater_fan nozzle_cooling_fan]
pin: PH3
[mcu]
serial: /dev/ttyACM0
[printer]
kinematics: cartesian
max_velocity: 300
max_accel: 3000
max_z_velocity: 2
max_z_accel: 10
[ad5206 stepper_digipot]
enable_pin: PD7
scale: 2.08
# Channel 1 is E0, 2 is E1, 3 is unused, 4 is Z, 5 is X, 6 is Y
channel_1: 1.34
channel_2: 1.0
channel_4: 1.1
channel_5: 1.1
channel_6: 1.1
# Enable 16 micro-steps on steppers X, Y, Z, E0, E1
[static_digital_output stepper_config]
pins:
PG1, PG0,
PK7, PG2,
PK6, PK5,
PK3, PK4,
PK1, PK2
[static_digital_output yellow_led]
pins: !PB7
[display]
lcd_type: st7920
cs_pin: PG4
sclk_pin: PJ2
sid_pin: PG3

View File

@@ -9,12 +9,11 @@ dir_pin: !PL1
enable_pin: !PA7
step_distance: .0225
endstop_pin: ^!PB6
homing_speed: 50.0
homing_stepper_phases: 32
homing_endstop_accuracy: .200
position_min: -0.25
position_endstop: 0.0
position_max: 200
homing_speed: 50
homing_stepper_phases: 32
homing_endstop_accuracy: .200
[stepper_y]
step_pin: PC1
@@ -22,12 +21,11 @@ dir_pin: PL0
enable_pin: !PA6
step_distance: .0225
endstop_pin: ^!PB5
homing_speed: 50.0
homing_stepper_phases: 32
homing_endstop_accuracy: .200
position_min: -0.25
position_endstop: 0.0
position_max: 250
homing_speed: 50
homing_stepper_phases: 32
homing_endstop_accuracy: .200
[stepper_z]
step_pin: PC2
@@ -35,13 +33,12 @@ dir_pin: !PL2
enable_pin: !PA5
step_distance: .005
endstop_pin: ^!PB4
homing_speed: 4.0
homing_retract_dist: 2.0
homing_stepper_phases: 32
homing_endstop_accuracy: .050
position_min: 0.1
position_endstop: 0.7
position_max: 200
homing_retract_dist: 2.0
homing_stepper_phases: 32
homing_endstop_accuracy: .070
[extruder]
step_pin: PC3
@@ -72,28 +69,14 @@ max_temp: 100
[fan]
pin: PH5
[heater_fan nozzle_fan]
pin: PH3
max_power: 0.61
cycle_time: .000030
hardware_pwm: True
[mcu]
serial: /dev/ttyACM0
custom:
# Nozzle fan
set_pwm_out pin=PH3 cycle_ticks=1 value=155
# Turn off yellow led
set_digital_out pin=PB7 value=0
# Stepper micro-step pins
set_digital_out pin=PG1 value=1
set_digital_out pin=PG0 value=1
set_digital_out pin=PK7 value=1
set_digital_out pin=PG2 value=1
set_digital_out pin=PK6 value=1
set_digital_out pin=PK5 value=1
set_digital_out pin=PK3 value=1
set_digital_out pin=PK4 value=1
# Initialize digipot
send_spi_message pin=PD7 msg=0487 # X = ~0.75A
send_spi_message pin=PD7 msg=0587 # Y = ~0.75A
send_spi_message pin=PD7 msg=0387 # Z = ~0.75A
send_spi_message pin=PD7 msg=00A5 # E0
send_spi_message pin=PD7 msg=017D # E1
[printer]
kinematics: cartesian
@@ -101,3 +84,25 @@ max_velocity: 500
max_accel: 3000
max_z_velocity: 25
max_z_accel: 30
[ad5206 stepper_digipot]
enable_pin: PD7
# Scale the config so that the channel value can be specified in amps
scale: 1.56
# Channel 1 is E0, 2 is E1, 3 is unused, 4 is Z, 5 is X, 6 is Y
channel_1: 1.0
channel_2: 0.75
channel_4: 0.82
channel_5: 0.82
channel_6: 0.82
# Enable 8 micro-steps on steppers X, Y, Z, E0
[static_digital_output stepper_config]
pins:
PG1, PG0,
PK7, PG2,
PK6, PK5,
PK3, PK4
[static_digital_output yellow_led]
pins: !PB7

View File

@@ -0,0 +1,94 @@
# This file constains the pin mappings for the SeeMeCNC Rostock Max
# (version 2) delta printer from 2015. To use this config, the
# firmware should be compiled for the AVR atmega2560.
# See the example.cfg file for a description of available parameters.
[stepper_a]
step_pin: PC0
dir_pin: !PL1
enable_pin: !PA7
step_distance: .0125
endstop_pin: ^PA2
homing_speed: 50
position_endstop: 380
arm_length: 290.800
[stepper_b]
step_pin: PC1
dir_pin: PL0
enable_pin: !PA6
step_distance: .0125
endstop_pin: ^PA1
[stepper_c]
step_pin: PC2
dir_pin: !PL2
enable_pin: !PA5
step_distance: .0125
endstop_pin: ^PC7
[extruder]
step_pin: PC3
dir_pin: !PL6
enable_pin: !PA4
step_distance: .010793
nozzle_diameter: 0.500
filament_diameter: 1.750
heater_pin: PH6
sensor_type: ATC Semitec 104GT-2
sensor_pin: PF0
control: pid
pid_Kp: 20.9700
pid_Ki: 1.3400
pid_Kd: 80.5600
min_temp: 0
max_temp: 300
[heater_bed]
heater_pin: PE5
sensor_type: ATC Semitec 104GT-2
sensor_pin: PF2
control: pid
pid_Kp: 46.510
pid_Ki: 1.040
pid_Kd: 500.000
min_temp: 0
max_temp: 300
[fan]
pin: PH5
[heater_fan nozzle_cooling_fan]
pin: PH4
heater: extruder
[mcu]
serial: /dev/ttyACM0
[printer]
kinematics: delta
max_velocity: 300
max_accel: 3000
max_z_velocity: 150
delta_radius: 174.75
[ad5206 stepper_digipot]
enable_pin: PD7
scale: 2.08
channel_1: 1.34
channel_2: 1.0
channel_4: 1.1
channel_5: 1.1
channel_6: 1.1
[static_digital_output stepper_config]
pins:
PG1, PG0,
PK7, PG2,
PK6, PK5,
PK3, PK4,
PK1, PK2
[static_digital_output yellow_led]
pins: !PB7

View File

@@ -0,0 +1,89 @@
# This file contains pin mappings for the Tronxy X5S (circa 2017). To
# use this config, the firmware should be compiled for the AVR
# atmega1284p.
# Note, a number of Melzi boards are shipped without a bootloader. In
# that case, an external programmer will be needed to flash a
# bootloader to the board (for example, see
# http://www.instructables.com/id/Flashing-a-Bootloader-to-the-CR-10/
# ). Once that is done, one should be able to use the standard "make
# flash" command to flash Klipper.
# See the example.cfg file for a description of available parameters.
[stepper_x]
step_pin: PD7
dir_pin: !PC5
enable_pin: !PD6
step_distance: .0125
endstop_pin: ^!PC2
position_endstop: 0
position_max: 330
homing_speed: 50
[stepper_y]
step_pin: PC6
dir_pin: !PC7
enable_pin: !PD6
step_distance: .0125
endstop_pin: ^!PC3
position_endstop: 0
position_max: 310
homing_speed: 50
[stepper_z]
step_pin: PB3
dir_pin: PB2
enable_pin: !PD6
step_distance: .0025
endstop_pin: ^!PC4
position_endstop: 0.5
position_max: 400
[extruder]
step_pin: PB1
dir_pin: PB0
enable_pin: !PD6
step_distance: .0111
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: PD5
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PA7
control: pid
pid_Kp: 22.2
pid_Ki: 1.08
pid_Kd: 114
min_temp: 0
max_temp: 275
[heater_bed]
heater_pin: PD4
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PA6
control: watermark
min_temp: 0
max_temp: 150
[fan]
pin: PB4
[mcu]
serial: /dev/ttyUSB0
[printer]
kinematics: corexy
max_velocity: 300
max_accel: 1000
max_z_velocity: 20
max_z_accel: 100
[display]
lcd_type: st7920
cs_pin: PA1
sclk_pin: PC0
sid_pin: PA3
# buttons are:
# PD2, PD3: encoder
# PA5: click

View File

@@ -0,0 +1,78 @@
# This file contains pin mappings for the Wanhao Duplicator i3 Plus
# (circa 2017). To use this config, the firmware should be compiled
# for the AVR atmega2560.
# Pin numbers and other parameters were extracted from the
# official Marlin source available at:
# https://github.com/garychen99/Duplicator-i3-plus
# See the example.cfg file for a description of available parameters.
[stepper_x]
step_pin: PF7
dir_pin: !PK0
enable_pin: !PF6
step_distance: .0125
endstop_pin: ^!PF0
position_endstop: 0
position_max: 200
homing_speed: 30.0
[stepper_y]
step_pin: PK2
dir_pin: !PK3
enable_pin: !PK1
step_distance: .0125
endstop_pin: ^!PA2
position_endstop: 0
position_max: 200
homing_speed: 30.0
[stepper_z]
step_pin: PK5
dir_pin: PK7
enable_pin: !PK4
step_distance: .0025
endstop_pin: ^!PA1
position_endstop: 0.5
position_max: 180
[extruder]
step_pin: PF4
dir_pin: PF5
enable_pin: !PF3
step_distance: 0.010417
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: PG5
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PF1
control: pid
pid_Kp: 30.850721
pid_Ki: .208175
pid_Kd: 192.298728
min_temp: 0
max_temp: 260
[heater_bed]
heater_pin: PE5
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PK6
control: pid
pid_Kp: 64.095903
pid_Ki: 1.649830
pid_Kd: 622.531455
min_temp: 0
max_temp: 110
[fan]
pin: PE3
[mcu]
serial: /dev/ttyUSB0
[printer]
kinematics: cartesian
max_velocity: 300
max_accel: 800
max_z_velocity: 5
max_z_accel: 100

View File

@@ -0,0 +1,159 @@
# This file contains pin mappings and other appropriate default parameters
# for a Wanhao Duplicator i3 v2.1 and its clones
# (Monoprice Maker Select, Cocoon Create, etc.)
# See the files example.cfg and example-extras.cfg for a description of available parameters.
#
# This will probably work on older revisions (v1.0, v2.0) of the printer
# but is untested on those versions.
#
# For best results with klipper and the Wanhao Duplicator i3, follow these
# guidelines:
#
# - Flash a bootloader to the Melzi board in the printer
# See http://www.instructables.com/id/Using-an-Arduino-to-Flash-the-Melzi-Board-Wanhao-I/
#
# - Make sure the auto-reset jumper is *enabled* on the Melzi board
# (See step 1 in the bootloader tutorial above)
#
# - Locate the USB serial port for your printer in /dev/serial/by-id/ format.
# See https://github.com/KevinOConnor/klipper/blob/master/docs/FAQ.md#wheres-my-serial-port
# It will be something like:
# /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_ABCD1234-if00-port0
#
# - Configure klipper to compile firmware for the AVR atmega1284p
#
# - At this point, "make flash FLASH_DEVICE=..." should successfully
# flash your printer board. Use the /dev/serial/by-id/ format for
# FLASH_DEVICE to ensure consistent results.
# See https://github.com/KevinOConnor/klipper/blob/master/docs/FAQ.md#the-make-flash-command-doesnt-work
# if you have problems.
#
# - Copy this sample file you are currently reading to ~/printer.cfg,
# and customize the following parameters:
# * [extruder] > step_distance
#
# This is the inverse of "E steps" (extruder steps per mm) from the stock
# Wanhao Repetier-based firmware.
# (See https://3dprinterwiki.info/extruder-steps/ )
#
# For example, if your E-steps are set to 107.0 steps per mm,
# then step_distance should be (1 / 107.0) ~= .009346
#
# * [extruder] > PID parameters (pid_Kp, pid_Ki, pid_Kd)
# * [heater_bed] > PID parameters (pid_Kp, pid_Ki, pid_Kd)
#
# PID values from stock Wanhao firmware (Repetier) do not
# translate directly to klipper. You will need to run klipper's
# PID autotune function for the extruder and bed. After getting the
# klipper firmware up and running, run the PID_CALIBRATE procedures
# by sending these commands via octoprint terminal (one per autotune):
#
# extruder: PID_CALIBRATE HEATER=extruder TARGET=<temp>
# heated bed: PID_CALIBRATE HEATER=heater_bed TARGET=<temp>
#
# After the autotune process completes, PID parameter results
# can be found in the Octoprint terminal tab (if you're quick)
# or in /tmp/klippy.log.
#
# Enter the PID parameters into the appropriate sections of ~/printer.cfg .
#
# * [extruder] > max_temp
# * [heater_bed] > max_temp
#
# The max temps included in this printer config are limited to 230 for extruder
# and 70 for heated bed. If your printer has been modified to handle higher temps
# (like an upgraded hot end or a separate MOSFET for your heated bed), you may
# want to increase these values.
#
# * [mcu] > serial
#
# Enter the USB serial port of the printer in /dev/serial/by-id/ format
# for best results.
#
# - Power cycle the Wanhao Duplicator i3
#
# - Issue the command "RESTART" via the Octoprint terminal tab (similar to
# how you would send a manual gcode command, but send the word RESTART).
# This tells klipper to reload its config file and do an internal reset.
# You should then see a status screen appear on the printer's LCD.
#
# - Be sure to follow these instructions before attempting any prints:
# https://github.com/KevinOConnor/klipper/blob/master/docs/Config_checks.md
[stepper_x]
step_pin: PD7
dir_pin: PC5
enable_pin: !PD6
step_distance: .0125
endstop_pin: ^!PC2
position_endstop: 0
position_max: 200
homing_speed: 40
[stepper_y]
step_pin: PC6
dir_pin: PC7
enable_pin: !PD6
step_distance: .0125
endstop_pin: ^!PC3
position_endstop: 0
position_max: 200
homing_speed: 40
[stepper_z]
step_pin: PB3
dir_pin: !PB2
enable_pin: !PA5
step_distance: 0.0025
endstop_pin: ^!PC4
position_endstop: 0.5
position_max: 180
homing_speed: 2
[extruder]
step_pin: PB1
dir_pin: !PB0
enable_pin: !PD6
step_distance: .009346
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: PD5
sensor_type: NTC 100K beta 3950
sensor_pin: PA7
control: pid
pid_Kp: 18.214030
pid_Ki: 0.616380
pid_Kd: 134.556146
min_temp: 0
max_temp: 230
[heater_bed]
heater_pin: PD4
sensor_type: NTC 100K beta 3950
sensor_pin: PA6
control: pid
pid_Kp: 71.321
pid_Ki: 1.989
pid_Kd: 639.210
min_temp: 0
max_temp: 70
[fan]
pin: PB4
[mcu]
serial: /dev/ttyUSB0
restart_method: command
[printer]
kinematics: cartesian
max_velocity: 200
max_accel: 1000
max_z_velocity: 2
max_z_accel: 100
[display]
lcd_type: st7920
cs_pin: PC1
sclk_pin: PD3
sid_pin: PC0

56
config/sample-bltouch.cfg Normal file
View File

@@ -0,0 +1,56 @@
# This file provides example config file settings for the BLTouch
# automatic bed leveling sensor. This file is just a "snippet" of
# sections specific to the BLTouch - it must be added to a config file
# containing the configuration of the rest of the printer.
# Be sure to review and update this config with the appropriate pins
# and coordinates for your printer.
# See the "example.cfg" and "example-extras.cfg" files for a
# description of config parameters.
# Define the BLTouch servo
[servo bltouch]
pin: ar32
maximum_servo_angle: 180
minimum_pulse_width: 0.0006
maximum_pulse_width: 0.0024
# Define a probe using the BLTouch
[probe]
pin: ar30
activate_gcode:
SET_SERVO SERVO=bltouch ANGLE=10
SET_SERVO SERVO=bltouch ANGLE=60
G4 P200
deactivate_gcode:
SET_SERVO SERVO=bltouch ANGLE=90
# Example bed_tilt config section
[bed_tilt]
#x_adjust:
#y_adjust:
points:
100,100
10,10
10,100
10,190
100,10
100,190
190,10
190,100
190,190
probe_z_offset: 2.345
# If the BLTouch is used to home the Z axis, then define a
# homing_override section, use probe:z_virtual_endstop as the
# endstop_pin in the stepper_z section, and set the endstop_position
# in the stepper_z section to match the probe's probe_z_offset.
#[homing_override]
#set_position_z: 5
#gcode:
# ; G90 ; Uncomment these 2 lines to blindly lift the Z 2mm at start
# ; G1 Z7 F600
# G28 X0 Y0
# G1 X100 Y100 F3600
# G28 Z0

38
docs/CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,38 @@
# Contributing to Klipper
Thank you for contributing to Klipper! Please take a moment to read
this document.
## Creating a new issue
Please see the [contact page](Contact.md) for information on creating
an issue. In particular, **we need the klippy.log file** attached to
bug reports. Also, be sure to read the [FAQ](FAQ.md) to see if a
similar issue has already been raised.
## Submitting a pull request
Contributions of Code and documentation are managed through github
pull requests. Each commit should have a commit message formatted
similar to the following:
```
module: Capitalized, short (50 chars or less) summary
More detailed explanatory text, if necessary. Wrap it to about 75
characters or so. In some contexts, the first line is treated as the
subject of an email and the rest of the text as the body. The blank
line separating the summary from the body is critical (unless you omit
the body entirely); tools like rebase can get confused if you run the
two together.
Further paragraphs come after blank lines..
Signed-off-by: My Name <myemail@example.org>
```
It is important to have a "Signed-off-by" line on each commit - it
certifies that you agree to the
[developer certificate of origin](developer-certificate-of-origin). It
must contain your real name (sorry, no pseudonyms or anonymous
contributions) and contain a current email address.

View File

@@ -8,13 +8,14 @@ The **src/** directory contains the C source for the micro-controller
code. The **src/avr/** directory contains specific code for Atmel
ATmega micro-controllers. The **src/sam3x8e/** directory contains code
specific to the Arduino Due style ARM micro-controllers. The
**src/simulator/** contains code stubs that allow the micro-controller
to be test compiled on other architectures. The **src/generic/**
directory contains helper code that may be useful across different
host architectures. The build arranges for includes of
"board/somefile.h" to first look in the current architecture directory
(eg, src/avr/somefile.h) and then in the generic directory (eg,
src/generic/somefile.h).
**src/pru/** directory contains code specific to the Beaglebone's
on-board PRU micro-controller. The **src/simulator/** contains code
stubs that allow the micro-controller to be test compiled on other
architectures. The **src/generic/** directory contains helper code
that may be useful across different host architectures. The build
arranges for includes of "board/somefile.h" to first look in the
current architecture directory (eg, src/avr/somefile.h) and then in
the generic directory (eg, src/generic/somefile.h).
The **klippy/** directory contains the C and Python source for the
host part of the software.
@@ -28,6 +29,8 @@ files.
The **scripts/** directory contains build-time scripts useful for
compiling the micro-controller code.
The **test/** directory contains automated test cases.
During compilation, the build may create an **out/** directory. This
contains temporary build time objects. The final micro-controller
object that is built is **out/klipper.elf.hex** on AVR and
@@ -43,10 +46,12 @@ all functions that have been tagged with the DECL_INIT() macro. It
then goes on to repeatedly run all functions tagged with the
DECL_TASK() macro.
One of the main task functions is command_task() located in
**src/command.c**. This function processes incoming serial commands
and runs the associated command function for them. Command functions
are declared using the DECL_COMMAND() macro.
One of the main task functions is command_dispatch() located in
**src/command.c**. This function is called from the board specific
input/output code (eg, **src/avr/serial.c**) and it runs the command
functions associated with the commands found in the input
stream. Command functions are declared using the DECL_COMMAND() macro
(see the [protocol](Protocol.md) document for more information).
Task, init, and command functions always run with interrupts enabled
(however, they can temporarily disable interrupts if needed). These
@@ -74,7 +79,7 @@ interrupts disabled.
Much of the functionality of the micro-controller involves working
with General-Purpose Input/Output pins (GPIO). In order to abstract
the low-level architecture specific code from the high-level task
code, all GPIO events are implemented in architectures specific
code, all GPIO events are implemented in architecture specific
wrappers (eg, **src/avr/gpio.c**). The code is compiled with gcc's
"-flto -fwhole-program" optimization which does an excellent job of
inlining functions across compilation units, so most of these tiny
@@ -145,7 +150,7 @@ provides further information on the mechanics of moves.
start/crusing/end velocity, and distance traveled during
acceleration/cruising/deceleration. All the information is stored in
the Move() class and is in cartesian space in units of millimeters
and seconds. Times are stored relative to the start of the print.
and seconds.
The move is then handed off to the kinematics classes: `Move.move()
-> kin.move()`
@@ -171,14 +176,13 @@ provides further information on the mechanics of moves.
stepcompress_push_const()`, or for delta kinematics:
`DeltaKinematics.move() -> MCU_Stepper.step_delta() ->
stepcompress_push_delta()`. The MCU_Stepper code just performs unit
and axis transformation (seconds to clock ticks and millimeters to
step distances), and calls the C code. The C code calculates the
stepper step times for each movement and fills an array (struct
stepcompress.queue) with the corresponding micro-controller clock
counter times (in 64bit integers) for every step. Here the
"micro-controller clock counter" value directly corresponds to the
micro-controller's hardware counter - it is relative to when the
micro-controller was last powered up.
and axis transformation (millimeters to step distances), and calls
the C code. The C code calculates the stepper step times for each
movement and fills an array (struct stepcompress.queue) with the
corresponding micro-controller clock counter times for every
step. Here the "micro-controller clock counter" value directly
corresponds to the micro-controller's hardware counter - it is
relative to when the micro-controller was last powered up.
* The next major step is to compress the steps: `stepcompress_flush()
-> compress_bisect_add()` (in stepcompress.c). This code generates
@@ -209,3 +213,223 @@ movement. However, the only really interesting parts are in the
ToolHead and kinematic classes. It's this part of the code which
specifies the movements and their timings. The remaining parts of the
processing is mostly just communication and plumbing.
Adding a host module
====================
The Klippy host code has a dynamic module loading capability. If a
config section named "[my_module]" is found in the printer config file
then the software will automatically attempt to load the python module
klippy/extras/my_module.py . This module system is the preferred
method for adding new functionality to Klipper.
The easiest way to add a new module is to use an existing module as a
reference - see **klippy/extras/servo.py** as an example.
The following may also be useful:
* Execution of the module starts in the module level `load_config()`
function (for config sections of the form [my_module]) or in
`load_config_prefix()` (for config sections of the form
[my_module my_name]). This function is passed a "config" object and
it must return a new "printer object" associated with the given
config section.
* During the process of instantiating a new printer object, the config
object can be used to read parameters from the given config
section. This is done using `config.get()`, `config.getfloat()`,
`config.getint()`, etc. methods. Be sure to read all values from the
config during the construction of the printer object - if the user
specifies a config parameter that is not read during this phase then
it will be assumed it is a typo in the config and an error will be
raised.
* Use the `config.get_printer()` method to obtain a reference to the
main "printer" class. This "printer" class stores references to all
the "printer objects" that have been instantiated. Use the
`printer.lookup_object()` method to find references to other printer
objects. Almost all functionality (even core kinematic modules) are
encapsulated in one of these printer objects. Note, though, that
when a new module is instantiated, not all other printer objects
will have been instantiated. The "gcode" and "pins" modules will
always be available, but for other modules it is a good idea to
defer the lookup.
* Define a `printer_state()` method if the code needs to be called
during printer setup and/or shutdown. This method is called twice
during setup (with "connect" and then "ready") and may also be
called at run-time (with "shutdown" or "disconnect"). It is common
to perform "printer object" lookup during the "connect" and "ready"
phases.
* If there is an error in the user's config, be sure to raise it
during the `load_config()` or `printer_state("connect")` phases. Use
either `raise config.error("my error")` or `raise
printer.config_error("my error")` to report the error.
* Use the "pins" module to configure a pin on a micro-controller. This
is typically done with something similar to
`printer.lookup_object("pins").setup_pin("pwm",
config.get("my_pin"))`. The returned object can then be commanded at
run-time.
* If the module needs access to system timing or external file
descriptors then use `printer.get_reactor()` to obtain access to the
global "event reactor" class. This reactor class allows one to
schedule timers, wait for input on file descriptors, and to "sleep"
the host code.
* Do not use global variables. All state should be stored in the
printer object returned from the `load_config()` function. This is
important as otherwise the RESTART command may not perform as
expected. Also, for similar reasons, if any external files (or
sockets) are opened then be sure to close them from the
`printer_state("disconnect")` callback.
* Avoid accessing the internal member variables (or calling methods
that start with an underscore) of other printer objects. Observing
this convention makes it easier to manage future changes.
* If submitting the module for inclusion in the main Klipper code, be
sure to place a copyright notice at the top of the module. See the
existing modules for the preferred format.
Adding new kinematics
=====================
This section provides some tips on adding support to Klipper for
additional types of printer kinematics. This type of activity requires
excellent understanding of the math formulas for the target
kinematics. It also requires software development skills - though one
should only need to update the host software (which is written in
Python).
Useful steps:
1. Start by studying the [above section](#code-flow-of-a-move-command)
and the [Kinematics document](Kinematics.md).
2. Review the existing kinematic classes in cartesian.py, corexy.py,
and delta.py. The kinematic classes are tasked with converting a
move in cartesian coordinates to the movement on each stepper. One
should be able to copy one of these files as a starting point.
3. Implement the `get_postion()` method in the new kinematics
class. This method converts the current stepper position of each
stepper axis (stored in millimeters) to a position in cartesian
space (also in millimeters).
4. Implement the `set_postion()` method. This is the inverse of
get_position() - it sets each axis position (in millimeters) given
a position in cartesian coordinates.
5. Implement the `move()` method. The goal of the move() method is to
convert a move defined in cartesian space to a series of stepper
step times that implement the requested movement.
* The `move()` method is passed a "print_time" parameter (which
stores a time in seconds) and a "move" class instance that fully
defines the movement. The goal is to repeatedly invoke the
`stepper.step()` method with the time (relative to print_time)
that each stepper should step at to obtain the desired motion.
* One "trick" to help with the movement calculations is to imagine
there is a physical rail between `move.start_pos` and
`move.end_pos` that confines the print head so that it can only
move along this straight line of motion. Then, if the head is
confined to that imaginary rail, the head is at `move.start_pos`,
only one stepper is enabled (all other steppers can move freely),
and the given stepper is stepped a single step, then one can
imagine that the head will move along the line of movement some
distance. Determine the formula converting this step distance to
distance along the line of movement. Once one has the distance
along the line of movement, one can figure out the time that the
head should be at that position (using the standard formulas for
velocity and acceleration). This time is the ideal step time for
the given stepper and it can be passed to the `stepper.step()`
method.
* The `stepper.step()` method must always be called with an
increasing time for a given stepper (steps must be scheduled in
the order they are to be executed). A common error during
kinematic development is to receive an "Internal error in
stepcompress" failure - this is generally due to the step()
method being invoked with a time earlier than the last scheduled
step. For example, if the last step in move1 is scheduled at a
time greater than the first step in move2 it will generally
result in the above error.
* Fractional steps. Be aware that a move request is given in
cartesian space and it is not confined to discreet
locations. Thus a move's start and end locations may translate to
a location on a stepper axis that is between two steps (a
fractional step). The code must handle this. The preferred
approach is to schedule the next step at the time a move would
position the stepper axis at least half way towards the next
possible step location. Incorrect handling of fractional steps is
a common cause of "Internal error in stepcompress" failures.
6. Other methods. The `home()`, `check_move()`, and other methods
should also be implemented. However, at the start of development
one can use empty code here.
7. Implement test cases. Create a g-code file with a series of moves
that can test important cases for the given kinematics. Follow the
[debugging documentation](Debugging.md) to convert this g-code file
to micro-controller commands. This is useful to exercise corner
cases and to check for regressions.
8. Optimize if needed. One may notice that the existing kinematic
classes do not call `stepper.step()`. This is purely an
optimization - the inner loop of the kinematic calculations were
moved to C to reduce load on the host cpu. All of the existing
kinematic classes started development using `stepper.step()` and
then were later optimized. The g-code to mcu command translation
(described in the previous step) is a useful tool during
optimization - if a code change is purely an optimization then it
should not impact the resulting text representation of the mcu
commands (though minor changes in output due to floating point
rounding are possible). So, one can use this system to detect
regressions.
Time
====
Fundamental to the operation of Klipper is the handling of clocks,
times, and timestamps. Klipper executes actions on the printer by
scheduling events to occur in the near future. For example, to turn on
a fan, the code might schedule a change to a GPIO pin in a 100ms. It
is rare for the code to attempt to take an instantaneous action. Thus,
the handling of time within Klipper is critical to correct operation.
There are three types of times tracked internally in the Klipper host
software:
* System time. The system time uses the system's monotonic clock - it
is a floating point number stored as seconds and it is (generally)
relative to when the host computer was last started. System times
have limited use in the software - they are primarily used when
interacting with the operating system. Within the host code, system
times are frequently stored in variables named *eventtime* or
*curtime*.
* Print time. The print time is synchronized to the main
micro-controller clock (the micro-controller defined in the "[mcu]"
config section). It is a floating point number stored as seconds and
is relative to when the main mcu was last restarted. It is possible
to convert from a "print time" to the main micro-controller's
hardware clock by multiplying the print time by the mcu's statically
configured frequency rate. The high-level host code uses print times
to calculates almost all physical actions (eg, head movement, heater
changes, etc.). Within the host code, print times are generally
stored in variables named *print_time* or *move_time*.
* MCU clock. This is the hardware clock counter on each
micro-controller. It is stored as an integer and its update rate is
relative to the frequency of the given micro-controller. The host
software translates its internal times to clocks before transmission
to the mcu. The mcu code only ever tracks time in clock
ticks. Within the host code, clock values are tracked as 64bit
integers, while the mcu code uses 32bit integers. Within the host
code, clocks are generally stored in variables with names containing
*clock* or *ticks*.
Conversion between the different time formats is primarily implemented
in the **klippy/clocksync.py** code.
Some things to be aware of when reviewing the code:
* 32bit and 64bit clocks: To reduce bandwidth and to improve
micro-controller efficiency, clocks on the micro-controller are
tracked as 32bit integers. When comparing two clocks in the mcu
code, the `timer_is_before()` function must always be used to ensure
integer rollovers are handled properly. The host software converts
32bit clocks to 64bit clocks by appending the high-order bits from
the last mcu timestamp it has received - no message from the mcu is
ever more than 2^31 clock ticks in the future or past so this
conversion is never ambiguous. The host converts from 64bit clocks
to 32bit clocks by simply truncating the high-order bits. To ensure
there is no ambiguity in this conversion, the
**klippy/serialqueue.c** code will buffer messages until they are
within 2^31 clock ticks of their target time.
* Multiple micro-controllers: The host software supports using
multiple micro-controllers on a single printer. In this case, the
"MCU clock" of each micro-controller is tracked separately. The
clocksync.py code handles clock drift between micro-controllers by
modifying the way it converts from "print time" to "MCU clock". On
secondary mcus, the mcu frequency that is used in this conversion is
regularly updated to account for measured drift.

147
docs/Config_checks.md Normal file
View File

@@ -0,0 +1,147 @@
This document provides a list of steps to help confirm the pin
settings in the Klipper printer.cfg file. It is a good idea to run
through these steps after following the steps in the
[installation document](Installation.md).
During this guide, it may be necessary to make changes to the Klipper
config file. Be sure to issue a RESTART command after every change to
the config file to ensure that the change takes effect (type "restart"
in the Octoprint terminal tab and then click "Send"). It's also a good
idea to issue a STATUS command after every RESTART to verify that the
config file is successfully loaded.
### Verify temperature
Start by verifying that temperatures are being properly
reported. Navigate to the Octoprint temperature tab.
![octoprint-temperature](img/octoprint-temperature.png)
Verify that the temperature of the nozzle and bed (if applicable) are
present and not increasing. If it is increasing, remove power from the
printer. If the temperatures are not accurate, review the
"sensor_type" and "sensor_pin" settings for the nozzle and/or bed.
### Verify M112
Navigate to the Octoprint terminal tab and issue an M112 command in
the terminal box. This command requests Klipper to go into a
"shutdown" state. It will cause Octoprint to disconnect from Klipper -
navigate to the Connection area and click on "Connect" to cause
Octoprint to reconnect. Then navigate to the Octoprint temperature tab
and verify that temperatures continue to update and the temperatures
are not increasing. If temperatures are increasing, remove power from
the printer.
The M112 command causes Klipper to go into a "shutdown" state. To
clear this state, issue a FIRMWARE_RESTART command in the Octoprint
terminal tab.
### Verify heaters
Navigate to the Octoprint temperature tab and type in 50 followed by
enter in the "Tool" temperature box. The extruder temperature in the
graph should start to increase (within about 30 seconds or so). Then
go to the "Tool" temperature drop-down box and select "Off". After
several minutes the temperature should start to return to its initial
room temperature value. If the temperature does not increase then
verify the "heater_pin" setting in the config.
If the printer has a heated bed then perform the above test again with
the bed.
### Verify stepper motor enable pin
Verify that all of the printer axes can manually move freely (the
stepper motors are disabled). If not, issue an M84 command to disable
the motors. If any of the axes still can not move freely, then verify
the stepper "enable_pin" configuration for the given axis. On most
commodity stepper motor drivers, the motor enable pin is "active low"
and therefore the enable pin should have a "!" before the pin (for
example, "enable_pin: !ar38").
### Verify endstops
Manually move all the printer axes so that none of them are in contact
with an endstop. Send a QUERY_ENDSTOPS command via the Octoprint
terminal tab. It should respond with the current state of all of the
configured endstops and they should all report a state of "open". For
each of the endstops, rerun the QUERY_ENDSTOPS command while manually
triggering the endstop. The QUERY_ENDSTOPS command should report the
endstop as "TRIGGERED".
If the endstop appears inverted (it reports "open" when triggered and
vice-versa) then add a "!" to the pin definition (for example,
"endstop_pin: ^!ar3"), or remove the "!" if there is already one
present.
If the endstop does not change at all then it generally indicates that
the endstop is connected to a different pin. However, it may also
require a change to the pullup setting of the pin (the '^' at the
start of the endstop_pin name - most printers will use a pullup
resistor and the '^' should be present).
### Verify stepper motor direction
Make sure the printer.cfg file does not have "homing_speed" set for
any axis (or set it to a value of 5 or less).
On cartesian style printers, manually move the X axis to a midway
point, issue a G28X0 command, and verify that the X motor moves slowly
towards the endstop defined for that axis. If the motor moves in the
wrong direction issue an M112 command to abort the move. A wrong
direction generally indicates that the "dir_pin" for the axis needs to
be inverted. This is done by adding a '!' to the "dir_pin" in the
printer config file (or removing it if one is already there). For
example, change "dir_pin: xyz" to "dir_pin: !xyz". Then RESTART and
retest the axis. If the axis does not move at all, then verify the
"enable_pin" and "step_pin" settings for the axis. For cartesian style
printers, repeat the test for the Y and Z axis with G28Y0 and G28Z0.
For delta style printers, manually move all three carriages to a
midway point and then issue a G28 command. Verify all three motors
move simultaneously upwards. If not, issue an M112 command and follow
the troubleshooting steps in the preceding paragraph.
### Verify extruder motor
To test the extruder motor it will be necessary to heat the extruder
to a printing temperature. Navigate to the Octoprint temperature tab
and select a target temperature from the temperature drop-down box (or
manually enter an appropriate temperature). Wait for the printer to
reach the desired temperature. Then navigate to the Octoprint control
tab and click the "Extrude" button. Verify that the extruder motor
turns in the correct direction. If it does not, see the
troubleshooting tips in the previous section to confirm the
"enable_pin", "step_pin", and "dir_pin" settings for the extruder.
### Calibrate PID settings
Klipper supports
[PID control](https://en.wikipedia.org/wiki/PID_controller) for the
extruder and bed heaters. In order to use this control mechanism it is
necessary to calibrate the PID settings on each printer. (PID settings
found in other firmwares or in the example configuration files often
work poorly.)
To calibrate the extruder, navigate to the OctoPrint terminal tab and
run the PID_CALIBRATE command. For example: `PID_CALIBRATE
HEATER=extruder TARGET=170`
At the completion of the tuning test, update the printer.cfg file with
the recommended pid_Kp, pid_Ki, and pid_Kd values.
If the printer has a heated bed and it supports being driven by PWM
(Pulse Width Modulation) then it is recommended to use PID control for
the bed. (When the bed heater is controlled using the PID algorithm it
may turn on and off ten times a second, which may not be suitable for
heaters using a mechanical switch.) A typical bed PID calibration
command is: `PID_CALIBRATE HEATER=heater_bed TARGET=60`
### Next steps
This guide is intended to help with basic verification of pin settings
in the Klipper configuration file. It may be necessary to perform
detailed printer calibration - a number of guides are available online
to help with this (for example, do a web search for "3d printer
calibration").

51
docs/Contact.md Normal file
View File

@@ -0,0 +1,51 @@
This page provides information on how to contact the Klipper
developers.
Issue reporting
===============
In order to report a problem or request a change in behavior, it is
necessary to collect the Klipper log file. The first step is to
**issue an M112 command** in the OctoPrint terminal window immediately
after the undesirable event occurs. This causes Klipper to go into a
"shutdown state" and it will cause additional debugging information to
be written to the log file.
Issue requests are submitted through Github. **All issues must
include the full /tmp/klippy.log log file from the session that
produced the error.** An "scp" and/or "sftp" utility is needed to
acquire this log file. The "scp" utility comes standard with Linux and
MacOS desktops. There are freely available scp utilities for other
desktops (eg, WinSCP).
Use the scp utility to copy the `/tmp/klippy.log` file from the host
machine to your desktop. It is a good idea to compress the klippy.log
file before posting it (eg, using zip or gzip). Open a new issue at
https://github.com/KevinOConnor/klipper/issues , provide a description
of the problem, and **attach the `klippy.log` file to the issue**:
![attach-issue](img/attach-issue.png)
Mailing list
============
There is a mailing list for general discussions on Klipper. In order
to send am email to the list, one must first subscribe:
https://www.freelists.org/list/klipper . Once subscribed, emails may
be sent to `klipper@freelists.org`.
Archives of the mailing list are available at:
https://www.freelists.org/archive/klipper/
IRC
===
One may join the #klipper channel on freenode.net (
irc://chat.freenode.net:6667 ).
To communicate in this IRC channel one will need an IRC
client. Configure it to connect to chat.freenode.net on port 6667 and
join the #klipper channel (`/join #klipper`).
If asking a question on IRC, be sure to ask the question and then stay
connected to the channel to receive responses. Due to timezone
differences, it may take several hours before receiving a response.

View File

@@ -75,10 +75,10 @@ cd /patch/to/klipper
make menuconfig
```
and compile the micro-controller software for an AVR atmega644p,
disable the AVR watchdog timer, and set the MCU frequency
to 20000000. Then one can compile Klipper (run `make`) and then start
the simulation with:
and compile the micro-controller software for an AVR atmega644p, set
the MCU frequency to 20Mhz, and select SIMULAVR software emulation
support. Then one can compile Klipper (run `make`) and then start the
simulation with:
```
PYTHONPATH=/path/to/simulavr/src/python/ ./scripts/avrsim.py -m atmega644 -s 20000000 -b 250000 out/klipper.elf
@@ -115,17 +115,20 @@ gtkwave avrsim.vcd
```
Manually sending commands to the micro-controller
-------------------------------------------------
=================================================
Normally, Klippy would be used to translate gcode commands to Klipper
commands. However, it's also possible to manually send Klipper
commands (functions marked with the DECL_COMMAND() macro in the
Klipper source code). To do so, run:
Normally, the host klippy.py process would be used to translate gcode
commands to Klipper micro-controller commands. However, it's also
possible to manually send these MCU commands (functions marked with
the DECL_COMMAND() macro in the Klipper source code). To do so, run:
```
~/klippy-env/bin/python ./klippy/console.py /tmp/pseudoserial 250000
```
See the "HELP" command within the tool for more information on its
functionality.
Generating load graphs
======================
@@ -148,3 +151,23 @@ Then graphs can be produced with:
```
One can then view the resulting **loadgraph.png** file.
Extracting information from the klippy.log file
===============================================
The Klippy log file (/tmp/klippy.log) also contains debugging
information. There is a logextract.py script that may be useful when
analyzing a micro-controller shutdown or similar problem. It is
typically run with something like:
```
mkdir work_directory
cd work_directory
cp /tmp/klippy.log .
~/klipper/scripts/logextract.py ./klippy.log
```
The script will extract the printer config file and will extract MCU
shutdown information. The information dumps from an MCU shutdown (if
present) will be reordered by timestamp to assist in diagnosing cause
and effect scenarios.

252
docs/FAQ.md Normal file
View File

@@ -0,0 +1,252 @@
Frequently asked questions
==========================
1. [How can I donate to the project?](#how-can-i-donate-to-the-project)
2. [How do I calculate the step_distance parameter in the printer config file?](#how-do-i-calculate-the-step_distance-parameter-in-the-printer-config-file)
3. [Where's my serial port?](#wheres-my-serial-port)
4. [The "make flash" command doesn't work](#the-make-flash-command-doesnt-work)
5. [How do I change the serial baud rate?](#how-do-i-change-the-serial-baud-rate)
6. [Can I run Klipper on something other than a Raspberry Pi 3?](#can-i-run-klipper-on-something-other-than-a-raspberry-pi-3)
7. [Why can't I move the stepper before homing the printer?](#why-cant-i-move-the-stepper-before-homing-the-printer)
8. [Why is the Z position_endstop set to 0.5 in the default configs?](#why-is-the-z-position_endstop-set-to-05-in-the-default-configs)
9. [I converted my config from Marlin and the X/Y axes work fine, but I just get a screeching noise when homing the Z axis](#i-converted-my-config-from-marlin-and-the-xy-axes-work-fine-but-i-just-get-a-screeching-noise-when-homing-the-z-axis)
10. [When I set "restart_method=command" my AVR device just hangs on a restart](#when-i-set-restart_methodcommand-my-avr-device-just-hangs-on-a-restart)
11. [Will the heaters be left on if the Raspberry Pi crashes?](#will-the-heaters-be-left-on-if-the-raspberry-pi-crashes)
12. [How do I upgrade to the latest software?](#how-do-i-upgrade-to-the-latest-software)
### How can I donate to the project?
Thanks. Kevin has a Patreon page at: https://www.patreon.com/koconnor
### How do I calculate the step_distance parameter in the printer config file?
If you know the steps per millimeter for the axis then use a
calculator to divide 1.0 by steps_per_mm. Then round this number to
six decimal places and place it in the config (six decimal places is
nano-meter precision).
The step_distance defines the distance that the axis will travel on
each motor driver pulse. It can also be calculated from the axis
pitch, motor step angle, and driver microstepping. If unsure, do a web
search for "calculate steps per mm" to find an online calculator.
### Where's my serial port?
The general way to find a USB serial port is to run `ls -l
/dev/serial/by-id/` from an ssh terminal on the host machine. It will
likely produce output similar to the following:
```
lrwxrwxrwx 1 root root 13 Jan 3 22:15 usb-UltiMachine__ultimachine.com__RAMBo_12345678912345678912-if00 -> ../../ttyACM0
```
The name found in the above command is stable and it is possible to
use it in the config file and while flashing the micro-controller
code. For example, a flash command might look similar to:
```
sudo service klipper stop
make flash FLASH_DEVICE=/dev/serial/by-id/usb-UltiMachine__ultimachine.com__RAMBo_12345678912345678912-if00
sudo service klipper start
```
and the updated config might look like:
```
[mcu]
serial: /dev/serial/by-id/usb-UltiMachine__ultimachine.com__RAMBo_12345678912345678912-if00
```
Be sure to copy-and-paste the name from the "ls" command that you ran
above as the name will be different for each printer.
### The "make flash" command doesn't work
The code attempts to flash the device using the most common method for
each platform. Unfortunately, there is a lot of variance in flashing
methods, so the "make flash" command may not work on all boards.
If you're having an intermittent failure or you do have a standard
setup, then double check that Klipper isn't running when flashing
(sudo service klipper stop), make sure OctoPrint isn't trying to
connect directly to the device (open the Connection tab in the web
page and click Disconnect if the Serial Port is set to the device),
and make sure FLASH_DEVICE is set correctly for your board (see the
[question above](#wheres-my-serial-port)).
However, if "make flash" just doesn't work for your board, then you
will need to manually flash. See if there is a config file in the
[config directory](../config) with specific instructions for flashing
the device. Also, check the board manufacturer's documentation to see
if it describes how to flash the device. Finally, on AVR devices, it
may be possible to manually flash the device using
[avrdude](http://www.nongnu.org/avrdude/) with custom command-line
parameters - see the avrdude documentation for further information.
### How do I change the serial baud rate?
The default baud rate is 250000 in both the Klipper micro-controller
configuration and in the Klipper host software. This works on almost
all micro-controllers and it is the recommended setting. (Most online
guides that refer to a baud rate of 115200 are outdated.)
If you need to change the baud rate, then the new rate will need to be
configured in the micro-controller (during **make menuconfig**) and
that updated code will need to be flashed to the micro-controller. The
Klipper printer.cfg file will also need to be updated to match that
baud rate (see the example.cfg file for details). For example:
```
[mcu]
baud: 250000
```
The baud rate shown on the OctoPrint web page has no impact on the
internal Klipper micro-controller baud rate. Always set the OctoPrint
baud rate to 250000 when using Klipper.
### Can I run Klipper on something other than a Raspberry Pi 3?
The recommended hardware is a Raspberry Pi 2 or a Raspberry
Pi 3.
Klipper will run on a Raspberry Pi 1 and on the Raspberry Pi Zero, but
these boards don't have enough processing power to run OctoPrint
well. It's not uncommon for print stalls to occur on these slower
machines (the printer may move faster than OctoPrint can send movement
commands) when printing directly from OctoPrint. If you wish to run on
one one of these slower boards anyway, consider using the
"virtual_sdcard" feature (see
[config/example-extras.cfg](../config/example-extras.cfg) for details)
when printing.
For running on the Beaglebone, see the
[Beaglebone specific installation instructions](beaglebone.md).
Klipper has been run on other machines. The Klipper host software
only requires Python running on a Linux (or similar)
computer. However, if you wish to run it on a different machine you
will need Linux admin knowledge to install the system prerequisites
for that particular machine. See the
[install-octopi.sh](../scripts/install-octopi.sh) script for further
information on the necessary Linux admin steps.
### Why can't I move the stepper before homing the printer?
The code does this to reduce the chance of accidentally commanding the
head into the bed or a wall. Once the printer is homed the software
attempts to verify each move is within the position_min/max defined in
the config file. If the motors are disabled (via an M84 or M18
command) then the motors will need to be homed again prior to
movement.
If you want to move the head after canceling a print via OctoPrint,
consider changing the OctoPrint cancel sequence to do that for
you. It's configured in OctoPrint via a web browser under:
Settings->GCODE Scripts
If you want to move the head after a print finishes, consider adding
the desired movement to the "custom g-code" section of your slicer.
### Why is the Z position_endstop set to 0.5 in the default configs?
For cartesian style printers the Z position_endstop specifies how far
the nozzle is from the bed when the endstop triggers. If possible, it
is recommended to use a Z-max endstop and home away from the bed (as
this reduces the potential for bed collisions). However, if one must
home towards the bed then it is recommended to position the endstop so
it triggers when the nozzle is still a small distance away from the
bed. This way, when homing the axis, it will stop before the nozzle
touches the bed.
Almost all mechanical switches can still move a small distance
(eg, 0.5mm) after they are triggered. So, for example, if the
position_endstop is set to 0.5mm then one may still command the
printer to move to Z0.2. The position_min config setting (which
defaults to 0) is used to specify the minimum Z position one may
command the printer to move to.
Note, the Z position_endstop specifies the distance from the nozzle to
the bed when the nozzle and bed (if applicable) are hot. It is typical
for thermal expansion to cause nozzle expansion of around .1mm, which
is also the typical thickness of a sheet of printer paper. Thus, it is
common to use the "paper test" to confirm calibration of the Z
height - check that the bed and nozzle are at room temperature, check
that there is no plastic on the head or bed, home the printer, place a
piece of paper between the nozzle and bed, and repeatedly command the
head to move closer to the bed checking each time if you feel a small
amount of friction when sliding the paper between bed and nozzle - if
all is calibrated well a small amount of friction would be felt when
the height is at Z0.
### I converted my config from Marlin and the X/Y axes work fine, but I just get a screeching noise when homing the Z axis
Short answer: Try reducing the max_z_velocity setting in the printer
config. Also, if the Z stepper is moving in the wrong direction, try
inverting the dir_pin setting in the config (eg, "dir_pin: !xyz"
instead of "dir_pin: xyz").
Long answer: In practice Marlin can typically only step at a rate of
around 10000 steps per second. If it is requested to move at a speed
that would require a higher step rate then Marlin will generally just
step as fast as it can. Klipper is able to achieve much higher step
rates, but the stepper motor may not have sufficient torque to move at
a higher speed. So, for a Z axis with a very precise step_distance the
actual obtainable max_z_velocity may be smaller than what is
configured in Marlin.
### When I set "restart_method=command" my AVR device just hangs on a restart
Some old versions of the AVR bootloader have a known bug in watchdog
event handling. This typically manifests when the printer.cfg file has
restart_method set to "command". When the bug occurs, the AVR device
will be unresponsive until power is removed and reapplied to the
device (the power or status LEDs may also blink repeatedly until the
power is removed).
The workaround is to use a restart_method other than "command" or to
flash an updated bootloader to the AVR device. Flashing a new
bootloader is a one time step that typically requires an external
programmer - search the web to find the instructions for your
particular device.
### Will the heaters be left on if the Raspberry Pi crashes?
The software has been designed to prevent that. Once the host enables
a heater, the host software needs to confirm that enablement every 5
seconds. If the micro-controller does not receive a confirmation every
5 seconds it goes into a "shutdown" state which is designed to turn
off all heaters and stepper motors.
See the "config_digital_out" command in the
[MCU commands](MCU_Commands.md) document for further details.
### How do I upgrade to the latest software?
The general way to upgrade is to ssh into the Raspberry Pi and run:
```
cd ~/klipper
git pull
~/klipper/scripts/install-octopi.sh
```
Then one can recompile and flash the micro-controller code. For
example:
```
sudo service klipper stop
make flash FLASH_DEVICE=/dev/ttyACM0
sudo service klipper start
```
However, it's often the case that only the host software changes. In
this case, one can update and restart just the host software with:
```
cd ~/klipper
git pull
sudo service klipper restart
```
If after using this shortcut the software warns about needing to
reflash the micro-controller or some other unusual error occurs, then
follow the full upgrade steps outlined above. Note that the RESTART
and FIRMWARE_RESTART g-code commands do not load new software - the
above "sudo service klipper restart" and "make flash" commands are
needed for a software change to take effect.

View File

@@ -15,10 +15,10 @@ Klipper has several compelling features:
* Best in class performance. Klipper is able to achieve high stepping
rates on both new and old micro-controllers. Even an old 8bit AVR
micro-controller can obtain rates over 175K steps per second. On
more recent ARM micro-controllers, rates over 450K steps per second
are possible. Higher stepper rates enable higher print
velocities. The stepper event timing remains precise even at high
speeds which improves overall stability.
more recent micro-controllers, rates over 500K steps per second are
possible. Higher stepper rates enable higher print velocities. The
stepper event timing remains precise even at high speeds which
improves overall stability.
* Configuration via simple config file. There's no need to reflash the
micro-controller to change a setting. All of Klipper's configuration
@@ -40,6 +40,14 @@ Klipper has several compelling features:
* Klipper implements the "pressure advance" algorithm for
extruders. When properly tuned, pressure advance reduces extruder
ooze.
* Klipper supports printers with multiple micro-controllers. For
example, one micro-controller could be used to control an
extruder, while another could control the printer's heaters, while
a third controls the rest of the printer. The Klipper host
software implements clock synchronization to account for clock
drift between micro-controllers. No special code is needed to
enable multiple micro-controllers - it just requires a few extra
lines in the config file.
* Klipper also implements a novel "stepper phase endstop" algorithm
that can dramatically improve the accuracy of typical endstop
switches. When properly tuned it can improve a print's first layer
@@ -81,8 +89,14 @@ Step Benchmarks
Below are the results of stepper performance tests. The numbers shown
represent total number of steps per second on the micro-controller.
| Micro-controller | 1 stepper active | 3 steppers active |
| ----------------- | ---------------- | ----------------- |
| 20Mhz AVR | 177K | 117K |
| 16Mhz AVR | 140K | 93K |
| Arduino Due (ARM) | 462K | 406K |
| Micro-controller | Fastest step rate | 3 steppers active |
| ----------------- | ----------------- | ----------------- |
| 20Mhz AVR | 189K | 125K |
| 16Mhz AVR | 151K | 100K |
| Arduino Due (ARM) | 382K | 337K |
| Beaglebone PRU | 689K | 689K |
On AVR platforms, the highest achievable step rate is with just one
stepper stepping. On the Due, the highest step rate is with two
simultaneous steppers stepping. On the PRU, the highest step rate is
with three simultaneous steppers.

131
docs/G-Codes.md Normal file
View File

@@ -0,0 +1,131 @@
This document describes the commands that Klipper supports. These are
commands that one may enter into the OctoPrint terminal tab.
# G-Code commands
Klipper supports the following standard G-Code commands:
- Move (G0 or G1): `G1 [X<pos>] [Y<pos>] [Z<pos>] [E<pos>] [F<speed>]`
- Dwell: `G4 P<milliseconds>`
- Move to origin: `G28 [X] [Y] [Z]`
- Turn off motors: `M18` or `M84`
- Wait for current moves to finish: `M400`
- Select tool: `T<index>`
- Use absolute/relative distances for extrusion: `M82`, `M83`
- Use absolute/relative coordinates: `G90`, `G91`
- Set position: `G92 [X<pos>] [Y<pos>] [Z<pos>] [E<pos>]`
- Set speed factor override percentage: `M220 S<percent>`
- Set extrude factor override percentage: `M221 S<percent>`
- Get extruder temperature: `M105`
- Set extruder temperature: `M104 [T<index>] [S<temperature>]`
- Set extruder temperature and wait: `M109 [T<index>] S<temperature>`
- Set bed temperature: `M140 [S<temperature>]`
- Set bed temperature and wait: `M190 S<temperature>`
- Set fan speed: `M106 S<value>`
- Turn fan off: `M107`
- Emergency stop: `M112`
- Get current position: `M114`
- Get firmware version: `M115`
- Set home offset: `M206 [X<pos>] [Y<pos>] [Z<pos>]`
For further details on the above commands see the
[RepRap G-Code documentation](http://reprap.org/wiki/G-code).
Klipper's goal is to support the G-Code commands produced by common
3rd party software (eg, OctoPrint, Printrun, Slic3r, Cura, etc.) in
their standard configurations. It is not a goal to support every
possible G-Code command. Instead, Klipper prefers human readable
["extended G-Code commands"](#extended-g-code-commands).
## G-Code SD card commands
Klipper also supports the following standard G-Code commands if the
"virtual_sdcard" config section is enabled:
- List SD card: `M20`
- Initialize SD card: `M21`
- Select SD file: `M23 <filename>`
- Start/resume SD print: `M24`
- Pause SD print: `M25`
- Set SD position: `M26 S<offset>`
- Report SD print status: `M27`
# Extended G-Code Commands
Klipper uses "extended" G-Code commands for general configuration and
status. These extended commands all follow a similar format - they
start with a command name and may be followed by one or more
parameters. For example: `SET_SERVO SERVO=myservo ANGLE=5.3`. In this
document, the commands and parameters are shown in uppercase, however
they are not case sensitive. (So, "SET_SERVO" and "set_servo" both run
the same command.)
The following standard commands are supported:
- `QUERY_ENDSTOPS`: Probe the axis endstops and report if they are
"triggered" or in an "open" state. This command is typically used to
verify that an endstop is working correctly.
- `GET_POSITION`: Return information on the current location of the
toolhead.
- `PID_CALIBRATE HEATER=<config_name> TARGET=<temperature>
[WRITE_FILE=1]`: Perform a PID calibration test. The specified
heater will be enabled until the specified target temperature is
reached, and then the heater will be turned off and on for several
cycles. If the WRITE_FILE parameter is enabled, then the file
/tmp/heattest.txt will be created with a log of all temperature
samples taken during the test.
- `RESTART`: This will cause the host software to reload its config
and perform an internal reset. This command will not clear error
state from the micro-controller (see FIRMWARE_RESTART) nor will it
load new software (see
[the FAQ](FAQ.md#how-do-i-upgrade-to-the-latest-software)).
- `FIRMWARE_RESTART`: This is similar to a RESTART command, but it
also clears any error state from the micro-controller.
- `STATUS`: Report the Klipper host software status.
- `HELP`: Report the list of available extended G-Code commands.
## Custom Pin Commands
The following command is available when an "output_pin" config section
is enabled:
- `SET_PIN PIN=config_name VALUE=<value>`
## Servo Commands
The following commands are available when a "servo" config section is
enabled:
- `SET_SERVO SERVO=config_name WIDTH=<seconds>`
- `SET_SERVO SERVO=config_name ANGLE=<degrees>`
## Probe
The following commands are available when a "probe" config section is
enabled:
- `PROBE`: Move the nozzle downwards until the probe triggers.
- `QUERY_PROBE`: Report the current status of the probe ("triggered"
or "open").
## Delta Calibration
The following commands are available when the "delta_calibrate" config
section is enabled:
- `DELTA_CALIBRATE`: This command will probe seven points on the bed
and recommend updated endstop positions, tower angles, and radius.
- `NEXT`: If manual bed probing is enabled, then one can use this
command to move to the next probing point during a DELTA_CALIBRATE
operation.
## Bed Tilt
The following commands are available when the "bed_tilt" config
section is enabled:
- `BED_TILT_CALIBRATE`: This command will probe the points specified
in the config and then recommend updated x and y tilt adjustments.
- `NEXT`: If manual bed probing is enabled, then one can use this
command to move to the next probing point during a
BED_TILT_CALIBRATE operation.
## Dual Carriages
The following command is available when the "dual_carriage" config
section is enabled:
- `SET_DUAL_CARRIAGE CARRIAGE=[0|1]`: This command will set the active
carriage. It is typically invoked from the activate_gcode and
deactivate_gcode fields in a multiple extruder configuration.

View File

@@ -1,29 +1,32 @@
These instructions assume the software will run on a Raspberry Pi
computer in conjunction with OctoPrint. It is recommended that a
Raspberry Pi 2 or Raspberry Pi 3 computer be used as the host
machine.
Raspberry Pi 2 or Raspberry Pi 3 computer be used as the host machine
(see the
[FAQ](FAQ.md#can-i-run-klipper-on-something-other-than-a-raspberry-pi-3)
for other machines).
It should be possible to run the Klipper host software on any computer
running a recent Linux distribution, but doing so will require Linux
admin knowledge to translate these installation instructions to the
particulars of that machine.
Klipper currently supports Atmel ATmega based micro-controllers and
Arduino Due (Atmel SAM3x8e ARM micro-controller) printers.
Klipper currently supports Atmel ATmega based micro-controllers,
Arduino Due (Atmel SAM3x8e ARM micro-controller), and
[Beaglebone PRU](beaglebone.md) based printers.
Prepping an OS image
====================
Start by installing [OctoPi](https://github.com/guysoft/OctoPi) on the
Raspberry Pi computer. Use OctoPi v0.13.0 or later - see the
Raspberry Pi computer. Use OctoPi v0.14.0 or later - see the
[octopi releases](https://github.com/guysoft/OctoPi/releases) for
release information. One should verify that OctoPi boots and that the
OctoPrint web server works. After connecting to the OctoPrint web
page, follow the prompt to upgrade OctoPrint to v1.3.2 or later.
page, follow the prompt to upgrade OctoPrint to v1.3.5 or later.
After installing OctoPi and upgrading OctoPrint, ssh into the target
machine (ssh pi@octopi -- password is "raspberry") and run the
following commands:
After installing OctoPi and upgrading OctoPrint, it will be necessary
to ssh into the target machine to run a handful of system commands. If
using a Linux or MacOS desktop, then the "ssh" software should already
be installed on the desktop. There are free ssh clients available for
other desktops (eg,
[PuTTY](https://www.chiark.greenend.org.uk/~sgtatham/putty/)). Use the
ssh utility to connect to the Raspberry Pi (ssh pi@octopi -- password
is "raspberry") and run the following commands:
```
git clone https://github.com/KevinOConnor/klipper
@@ -38,15 +41,18 @@ minutes to complete.
Building and flashing the micro-controller
==========================================
To compile the micro-controller code, start by configuring it:
To compile the micro-controller code, start by running these commands
on the Raspberry Pi:
```
cd ~/klipper/
make menuconfig
```
Select the appropriate micro-controller and serial baud rate. Once
configured, run:
Select the appropriate micro-controller and review any other options
provided. For boards with serial ports, the default baud rate is
250000 (see the [FAQ](FAQ.md#how-do-i-change-the-serial-baud-rate) if
changing). Once configured, run:
```
make
@@ -60,25 +66,11 @@ make flash FLASH_DEVICE=/dev/ttyACM0
sudo service klipper start
```
Configuring Klipper
===================
The Klipper configuration is stored in a text file on the Raspberry
Pi. Take a look at the example config files in the
[config directory](../config/). The
[example.cfg](../config/example.cfg) file contains documentation on
command parameters and it can also be used as an initial config file
template. However, for most printers, one of the other config files
may be a more concise starting point. The next step is to copy and
edit one of these config files - for example:
```
cp ~/klipper/config/example.cfg ~/printer.cfg
nano ~/printer.cfg
```
Make sure to review and update each setting that is appropriate for
the hardware.
When flashing for the first time, make sure that OctoPrint is not
connected directly to the printer (from the OctoPrint web page, under
the "Connection" section, click "Disconnect"). The most common
communication device is **/dev/ttyACM0** - see the
[FAQ](FAQ.md#wheres-my-serial-port) for other possibilities.
Configuring OctoPrint to use Klipper
====================================
@@ -103,13 +95,47 @@ try reloading the page.)
Once connected, navigate to the "Terminal" tab and type "status"
(without the quotes) into the command entry box and click "Send". The
terminal window will likely report there is an error opening the
config file - issue a "restart" command in the OctoPrint terminal to
load the config. A "status" command will report the printer is ready
if the Klipper config file is successfully read and the
micro-controller is successfully found and configured. It is not
unusual to have configuration errors during the initial setup - update
the printer config file and issue "restart" until "status" reports the
printer is ready.
config file - that means OctoPrint is successfully communicating with
Klipper. Proceed to the next section.
Configuring Klipper
===================
The Klipper configuration is stored in a text file on the Raspberry
Pi. Take a look at the example config files in the
[config directory](../config/). The
[example.cfg](../config/example.cfg) file contains documentation on
command parameters and it can also be used as an initial config file
template. However, for most printers, one of the other config files
may be a more concise starting point.
Arguably the easiest way to update the Klipper configuration file is
to use a desktop editor that supports editing files over the "scp"
and/or "sftp" protocols. There are freely available tools that support
this (eg, Notepad++, WinSCP, and Cyberduck). Use one of the example
config files as a starting point and save it as a file named
"printer.cfg" in the home directory of the pi user (ie,
/home/pi/printer.cfg).
Alternatively, one can also copy and edit the file directly on the
Raspberry Pi via ssh - for example:
```
cp ~/klipper/config/example.cfg ~/printer.cfg
nano ~/printer.cfg
```
Make sure to review and update each setting that is appropriate for
the hardware.
After creating and editing the file it will be necessary to issue a
"restart" command in the OctoPrint web terminal to load the config. A
"status" command will report the printer is ready if the Klipper
config file is successfully read and the micro-controller is
successfully found and configured. It is not unusual to have
configuration errors during the initial setup - update the printer
config file and issue "restart" until "status" reports the printer is
ready.
Klipper reports error messages via the OctoPrint terminal tab. The
"status" command can be used to re-report error messages. The default
@@ -119,3 +145,14 @@ provides more detailed information.
In addition to common g-code commands, Klipper supports a few extended
commands - "status" and "restart" are examples of these commands. Use
the "help" command to get a list of other extended commands.
After Klipper reports that the "printer is ready" go on to the
[config check document](Config_checks.md) to perform some basic checks
on the pin definitions in the config file.
Contacting the developers
=========================
Be sure to see the [FAQ](FAQ.md) for answers to some common questions.
See the [contact page](Contact.md) to report a bug or to contact the
developers.

View File

@@ -18,12 +18,12 @@ rapid jerking of the head can cause disruption of recently deposited
filament. Limiting speed changes of the print head (relative to the
print) reduces risks of disrupting the print.
It is also important to enforce a maximum acceleration of the stepper
motors to ensure they do not skip or put excessive stress on the
machine. Klipper limits the acceleration of each stepper by virtue of
limiting the acceleration of the print head. Enforcing acceleration at
the print head naturally also enforces acceleration at the steppers
that control that print head (the inverse is not always true).
It is also important to limit acceleration so that the stepper motors
do not skip or put excessive stress on the machine. Klipper limits the
torque on each stepper by virtue of limiting the acceleration of the
print head. Enforcing acceleration at the print head naturally also
limits the torque of the steppers that move the print head (the
inverse is not always true).
Klipper implements constant acceleration. The key formula for constant
acceleration is:
@@ -88,9 +88,9 @@ The junction speeds are determined using "approximated centripetal
acceleration". Best
[described by the author](https://onehossshay.wordpress.com/2011/09/24/improving_grbl_cornering_algorithm/).
Klipper implements look-ahead between moves contained in the XY plane
that have similar extruder flow rates. Other moves are relatively rare
and implementing look-ahead between them is unnecessary.
Klipper implements look-ahead between moves that have similar extruder
flow rates. Other moves are relatively rare and implementing
look-ahead between them is unnecessary.
Key formula for look-ahead:
```
@@ -211,13 +211,18 @@ With delta kinematics it is possible for a move that is accelerating
in cartesian space to require an acceleration on a particular stepper
motor greater than the move's acceleration. This can occur when a
stepper arm is more horizontal than vertical and the line of movement
is near that stepper's tower.
passes near that stepper's tower. Although these moves could require a
stepper motor acceleration greater than the printer's maximum
configured move acceleration, the effective mass moved by that stepper
would be smaller. Thus the higher stepper acceleration does not result
in significantly higher stepper torque and it is therefore considered
harmless.
Klipper does enforce a maximum ceiling on stepper acceleration that is
three times the maximum acceleration of a move in cartesian
space. (Similarly, the maximum velocity of the stepper is limited to
three times the maximum move velocity.) In order to enforce this
limit, moves at the extreme edge of the build envelope (where a
However, to avoid extreme cases, Klipper enforces a maximum ceiling on
stepper acceleration of three times the printer's configured maximum
move acceleration. (Similarly, the maximum velocity of the stepper is
limited to three times the maximum move velocity.) In order to enforce
this limit, moves at the extreme edge of the build envelope (where a
stepper arm may be nearly horizontal) will have a lower maximum
acceleration and velocity.

View File

@@ -4,10 +4,8 @@ by the Klipper micro-controller software. This document is not an
authoritative reference for these commands, nor is it an exclusive
list of all available commands.
This document may be useful for users needing to configure a set of
hardware actions that their printer may require at startup (via the
"custom" field in the printer config file), and it may be useful for
developers wishing to obtain a high-level feel for low-level commands.
This document may be useful for developers interested in understanding
the low-level micro-controller commands.
See the [protocol](Protocol.md) document for more information on the
format of commands and their transmission. The commands here are
@@ -25,22 +23,13 @@ commands available for that purpose. Unlike most micro-controller
commands, these commands run as soon as they are received and they do
not require any particular setup.
These commands are most useful in the "custom" block of the "mcu"
section of the printer configuration file. This feature is typically
used to configure the initial settings of LEDs, to configure
micro-stepping pins, to configure a digipot, etc.
Several of these commands will take a "pin=%u" parameter. The
low-level micro-controller software uses integer encodings of the
hardware pin numbers, but to make things more readable the host will
translate human readable pin names (eg, "PA3") to their equivalent
integer encodings. By convention, any parameter named "pin" or that
has a "_pin" suffix will use pin name translation by the
host. Similarly, several commands take time parameters specified in
clock ticks. One can specify a value for these parameters in seconds
using the "TICKS()" macro - for example "cycle_ticks=TICKS(0.001)"
would result in "cycle_ticks=16000" on a micro-controller with a 16Mhz
clock.
host.
Common startup commands:
@@ -50,7 +39,7 @@ Common startup commands:
may be useful for configuring the initial value of LEDs and for
configuring the initial value of stepper driver micro-stepping pins.
* `set_pwm_out pin=%u cycle_ticks=%u value=%c` : This command will
* `set_pwm_out pin=%u cycle_ticks=%u value=%hu` : This command will
immediately configure the given pin to use hardware based
pulse-width-modulation (PWM) with the given number of
cycle_ticks. The "cycle_ticks" is the number of MCU clock ticks each
@@ -129,16 +118,16 @@ Common micro-controller objects
This section lists some commonly used config commands.
* `config_digital_out oid=%c pin=%u default_value=%c
* `config_digital_out oid=%c pin=%u value=%c default_value=%c
max_duration=%u` : This command creates an internal micro-controller
object for the given GPIO 'pin'. The pin will be configured in
digital output mode and set to an initial value as specified by
'default_value' (0 for low, 1 for high). Creating a digital_out
object allows the host to schedule GPIO updates for the given pin at
'value' (0 for low, 1 for high). Creating a digital_out object
allows the host to schedule GPIO updates for the given pin at
specified times (see the schedule_digital_out command described
below). Should the micro-controller software go into shutdown mode
then all configured digital_out objects will be set back to their
default values. The 'max_duration' parameter is used to implement a
then all configured digital_out objects will be set to
'default_value'. The 'max_duration' parameter is used to implement a
safety check - if it is non-zero then it is the maximum number of
clock ticks that the host may set the given GPIO to a non-default
value without further updates. For example, if the default_value is
@@ -148,23 +137,23 @@ This section lists some commonly used config commands.
feature can be used with heater pins to ensure the host does not
enable the heater and then go off-line.
* `config_pwm_out oid=%c pin=%u cycle_ticks=%u default_value=%c
max_duration=%u` : This command creates an internal object for
hardware based PWM pins that the host may schedule updates for. Its
usage is analogous to config_digital_out - see the description of
the 'set_pwm_out' and 'config_digital_out' commands for parameter
description.
* `config_pwm_out oid=%c pin=%u cycle_ticks=%u value=%hu
default_value=%hu max_duration=%u` : This command creates an
internal object for hardware based PWM pins that the host may
schedule updates for. Its usage is analogous to config_digital_out -
see the description of the 'set_pwm_out' and 'config_digital_out'
commands for parameter description.
* `config_soft_pwm_out oid=%c pin=%u cycle_ticks=%u default_value=%c
max_duration=%u` : This command creates an internal micro-controller
object for software implemented PWM. Unlike hardware pwm pins, a
software pwm object does not require any special hardware support
(other than the ability to configure the pin as a digital output
GPIO). Because the output switching is implemented in the
micro-controller software, it is recommended that the cycle_ticks
parameter correspond to a time of 10ms or greater. See the
description of the 'set_pwm_out' and 'config_digital_out' commands
for parameter description.
* `config_soft_pwm_out oid=%c pin=%u cycle_ticks=%u value=%c
default_value=%c max_duration=%u` : This command creates an internal
micro-controller object for software implemented PWM. Unlike
hardware pwm pins, a software pwm object does not require any
special hardware support (other than the ability to configure the
pin as a digital output GPIO). Because the output switching is
implemented in the micro-controller software, it is recommended that
the cycle_ticks parameter correspond to a time of 10ms or
greater. See the description of the 'set_pwm_out' and
'config_digital_out' commands for parameter description.
* `config_analog_in oid=%c pin=%u` : This command is used to configure
a pin in analog input sampling mode. Once configured, the pin can be
@@ -205,11 +194,11 @@ only of interest to developers looking to gain insight into Klipper.
same 'oid' parameter must have been issued during micro-controller
configuration.
* `schedule_pwm_out oid=%c clock=%u value=%c` : Schedules a change to
* `schedule_pwm_out oid=%c clock=%u value=%hu` : Schedules a change to
a hardware PWM output pin. See the 'schedule_digital_out' and
'config_pwm_out' commands for more info.
* `schedule_soft_pwm_out oid=%c clock=%u value=%c` : Schedules a
* `schedule_soft_pwm_out oid=%c clock=%u value=%hu` : Schedules a
change to a software PWM output pin. See the 'schedule_digital_out'
and 'config_soft_pwm_out' commands for more info.
@@ -266,13 +255,15 @@ Stepper commands
number of steps generated with dir=1 minus the total number of steps
generated with dir=0.
* `end_stop_home oid=%c clock=%u rest_ticks=%u pin_value=%c` : This
command is used during stepper "homing" operations. To use this
command a 'config_end_stop' command with the same 'oid' parameter
must have been issued during micro-controller configuration. When
this command is invoked, the micro-controller will sample the
endstop pin every 'rest_ticks' clock ticks and check if it has a
value equal to 'pin_value'. If the value matches then the movement
* `end_stop_home oid=%c clock=%u sample_ticks=%u sample_count=%c
rest_ticks=%u pin_value=%c` : This command is used during stepper
"homing" operations. To use this command a 'config_end_stop' command
with the same 'oid' parameter must have been issued during
micro-controller configuration. When this command is invoked, the
micro-controller will sample the endstop pin every 'rest_ticks'
clock ticks and check if it has a value equal to 'pin_value'. If the
value matches (and it continues to match for 'sample_count'
additional samples spread 'sample_ticks' apart) then the movement
queue for the associated stepper will be cleared and the stepper
will come to an immediate halt. The host uses this command to
implement homing - the host instructs the endstop to sample for the

View File

@@ -4,7 +4,9 @@ machine. The host code is intended to run on a low-cost
general-purpose machine such as a Raspberry Pi, while the
micro-controller code is intended to run on commodity micro-controller
chips. Read [features](Features.md) for reasons to use Klipper. See
[installation](Installation.md) to get started with Klipper.
[installation](Installation.md) to get started with Klipper. See
[config checks](Config_checks.md) for a guide to verify basic pin
settings in the config file.
The Klipper configuration is stored in a simple text file on the host
machine. The [config/example.cfg](../config/example.cfg) file serves
@@ -13,10 +15,13 @@ as a reference for the config file. The
on tuning the pressure advance config.
The [kinematics](Kinematics.md) document provides some technical
details on how Klipper implements motion.
details on how Klipper implements motion. The [FAQ](FAQ.md) answers
some common questions. The [G-Codes](G-Codes.md) document lists
currently supported run-time commands.
The history of Klipper releases is available at
[releases](Releases.md).
[releases](Releases.md). See [contact](Contact.md) for information on
bug reporting and general communication with the developers.
Developer Documentation
=======================
@@ -24,7 +29,8 @@ Developer Documentation
There are also several documents available for developers interested
in understanding how Klipper works. Start with the
[code overview](Code_Overview.md) document - it provides information
on the structure and layout of the Klipper code.
on the structure and layout of the Klipper code. See the
[contributing](CONTRIBUTING.md) document to submit improvements to Klipper.
See [protocol](Protocol.md) for information on the low-level messaging
protocol between host and micro-controller. See also

View File

@@ -4,6 +4,18 @@ pressure advance feature can be helpful in reducing ooze. For more
information on how pressure advance is implemented see the
[kinematics](Kinematics.md) document.
Prerequisites
=============
In order to tune the pressure advance setting the printer must be
configured and operational. The tuning test involves printing objects
and inspecting the differences between objects. In particular, the
extruder
[E steps](http://reprap.org/wiki/Triffid_Hunter%27s_Calibration_Guide#E_steps)
and
[nozzle temperature](http://reprap.org/wiki/Triffid_Hunter%27s_Calibration_Guide#Nozzle_Temperature)
should be tuned prior to tuning pressure advance.
Tuning pressure advance
=======================
@@ -35,11 +47,13 @@ object. (Be sure to issue RESTART between each config change.) The
goal is to attempt to eliminate the blobbing during cornering. (With
pressure advance, the extruder will retract when the head slows down,
thus countering the pressure buildup and ideally eliminate the
blobbing.) If a test run is done with a pressure_advance setting that
is too high, one typically sees a dimple in the corner followed by
possible blobbing after the corner (too much filament is retracted
during slow down and then too much filament is extruded during the
following speed up after cornering):
blobbing.)
If a test run is done with a pressure_advance setting that is too
high, one typically sees a dimple in the corner followed by possible
blobbing after the corner (too much filament is retracted during slow
down and then too much filament is extruded during the following speed
up after cornering):
![corner-dimple](img/corner-dimple.jpg)
@@ -49,7 +63,16 @@ in good quality corners:
![corner-good](img/corner-good.jpg)
Typical pressure_advance values are between 0.05 and 0.20 (the high
end usually only with bowden extruders).
end usually only with bowden extruders). If there is no significant
improvement seen after increasing pressure_advance to 0.20, then
pressure advance is unlikely to improve the quality of prints. Return
to a default configuration with pressure_advance disabled.
It is not unusual for one corner of the test print to be consistently
different than the other three corners. This typically occurs when the
slicer arranges to always change Z height at that corner. If this
occurs, then ignore that corner and tune pressure_advance using the
other three corners.
Once a good pressure_advance value is found, return
pressure_advance_lookahead_time to its default (0.010). This parameter

View File

@@ -1,6 +1,57 @@
History of Klipper releases. Please see
[installation](Installation.md) for information on installing Klipper.
Klipper 0.6.0
=============
Available on 20180331. Major changes in this release:
* Enhanced heater and thermistor hardware failure checks
* Support for Z probes
* Initial support for automatic parameter calibration on deltas (via a
new delta_calibrate command)
* Initial support for bed tilt compensation (via bed_tilt_calibrate
command)
* Initial support for "safe homing" and homing overrides
* Initial support for displaying status on RepRapDiscount style 2004
and 12864 displays
* New multi-extruder improvements:
* Support for shared heaters
* Initial support for dual carriages
* Support for configuring multiple steppers per axis (eg, dual Z)
* Support for custom digital and pwm output pins (with a new SET_PIN command)
* Initial support for a "virtual sdcard" that allows printing directly
from Klipper (helps on machines too slow to run OctoPrint well)
* Support for setting different arm lengths on each tower of a delta
* Support for G-Code M220/M221 commands (speed factor override /
extrude factor override)
* Several documentation updates:
* Many new example config files for common off-the-shelf printers
* New multiple MCU config example
* New bltouch sensor config example
* New FAQ, config check, and G-Code documents
* Initial support for continuous integration testing on all github commits
* Several bug fixes and code cleanups
Klipper 0.5.0
=============
Available on 20171025. Major changes in this release:
* Support for printers with multiple extruders.
* Initial support for running on the Beaglebone PRU. Initial support
for the Replicape board.
* Initial support for running the micro-controller code in a real-time
Linux process.
* Support for multiple micro-controllers. (For example, one could
control an extruder with one micro-controller and the rest of the
printer with another.) Software clock synchronization is implemented
to coordinate actions between micro-controllers.
* Stepper performance improvements (20Mhz AVRs up to 189K steps per
second).
* Support for controlling servos and support for defining nozzle
cooling fans.
* Several bug fixes and code cleanups
Klipper 0.4.0
=============

View File

@@ -44,10 +44,6 @@ Safety features
endstop detection is a good idea because of spurious signals caused
by electrical noise.)
* Support validating that heaters are heating at expected rates. This
can be useful to detect a sensor failure (eg, thermistor short) that
could otherwise cause the PID to command excessive heating.
Testing features
================
@@ -60,8 +56,6 @@ Testing features
Documentation
=============
* Document and test running the host software on a Beagle Bone Black.
* Add documentation describing how to perform bed-leveling accurately
in Klipper. Improve description of stepper phase based bed leveling.
@@ -69,32 +63,19 @@ Hardware features
=================
* Port to additional micro-controller architectures:
* Beagle Bone Black PRU
* Smoothieboard / NXP LPC1769 (ARM cortex-M3)
* Unix based scheduling; Unix based real-time scheduling
* Support for additional kinematics: scara, etc.
* Support shared motor enable GPIO lines.
* Support for multiple extruders.
* Support for bed-level probes.
* Possible support for touch panels attached to the micro-controller.
(In general, it would be preferable to attach touch panels to the
host system and have octoprint interact with the panel directly, but
it would also be useful to handle panels already hardwired to the
micro-controller.)
* Possibly support printers using multiple micro-controllers.
Misc features
=============
* Possibly use cubic functions instead of quadratic functions in step
compression code.
* Possibly support a "feed forward PID" that takes into account the
amount of plastic being extruded. If the extrude rate changes
significantly during a print it can cause heating bumps that the PID

103
docs/beaglebone.md Normal file
View File

@@ -0,0 +1,103 @@
This document describes the process of running Klipper on a Beaglebone
PRU.
Building an OS image
====================
Start by installing the
[latest Jessie IoT](https://beagleboard.org/latest-images) image
(2017-03-19 or later). One may run the image from either a micro-SD
card or from builtin eMMC. If using the eMMC, install it to eMMC now
by following the instructions from the above link.
Then ssh into the beaglebone machine (ssh debian@beaglebone --
password is "temppwd") and install Klipper by running the following
commands:
```
git clone https://github.com/KevinOConnor/klipper
./klipper/scripts/install-beaglebone.sh
```
Install Octoprint
=================
One may then install Octoprint:
```
git clone https://github.com/foosel/OctoPrint.git
cd OctoPrint/
virtualenv venv
./venv/bin/python setup.py install
```
And setup OctoPrint to start at bootup:
```
sudo cp ~/OctoPrint/scripts/octoprint.init /etc/init.d/octoprint
sudo chmod +x /etc/init.d/octoprint
sudo cp ~/OctoPrint/scripts/octoprint.default /etc/default/octoprint
sudo update-rc.d octoprint defaults
```
It is necessary to modify OctoPrint's **/etc/default/octoprint**
configuration file. One must change the OCTOPRINT_USER user to
"debian", change NICELEVEL to 0, uncomment the BASEDIR, CONFIGFILE,
and DAEMON settings and change the references from "/home/pi/" to
"/home/debian/":
```
sudo nano /etc/default/octoprint
```
Then start the Octoprint service:
```
sudo systemctl start octoprint
```
Make sure the octoprint web server is accessible - it should be at:
[http://beaglebone:5000/](http://beaglebone:5000/)
Building the micro-controller code
==================================
To compile the Klipper micro-controller code, start by configuring it
for the "Beaglebone PRU":
```
cd ~/klipper/
make menuconfig
```
To build and install the new micro-controller code, run:
```
sudo service klipper stop
make flash
sudo service klipper start
```
For the Replicape, it is also necessary to compile and install the
micro-controller code for a Linux host process. Run "make menuconfig"
a second time and configure it for a "Linux process":
```
make menuconfig
```
Then install this micro-controller code as well:
```
sudo service klipper stop
make flash
sudo service klipper start
```
Remaining configuration
=======================
Complete the installation by configuring Klipper and Octoprint
following the instructions in
[the main installation document](Installation.md#configuring-klipper).
Printing on the Beaglebone
==========================
Unfortunately, the Beaglebone processor can sometimes struggle to run
OctoPrint well. Print stalls have been known to occur on complex
prints (the printer may move faster than OctoPrint can send movement
commands). If this occurs, consider using the "virtual_sdcard" feature
(see [config/example-extras.cfg](../config/example-extras.cfg) for
details) to print directly from Klipper.

View File

@@ -0,0 +1,37 @@
Developer Certificate of Origin
Version 1.1
Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129
Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.
Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or
(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or
(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.
(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.

BIN
docs/img/attach-issue.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

2
docs/issue_template.md Normal file
View File

@@ -0,0 +1,2 @@
<!-- Klipper do something undesirable? YOU MUST ATTACH THE KLIPPER LOG FILE.
See: https://github.com/KevinOConnor/klipper/blob/master/docs/Contact.md -->

View File

@@ -7,8 +7,39 @@ square_width = 5;
square_size = 60;
square_height = 5;
module hollow_square() {
difference() {
cube([square_size, square_size, square_height]);
translate([square_width, square_width, -1])
cube([square_size-2*square_width, square_size-2*square_width, square_height+2]);
cube([square_size-2*square_width, square_size-2*square_width,
square_height+2]);
}
}
module notch() {
CUT = 0.01;
depth = .5;
width = 1;
translate([-depth, -width, -CUT])
cube([2*depth, 2*width, square_height + 2*CUT]);
}
module square_with_notches() {
difference() {
// Start with initial square
hollow_square();
// Remove four notches on inside perimeter
translate([square_width, square_size/2 - 4, 0])
notch();
translate([square_size/2, square_size - square_width, 0])
rotate([0, 0, 90])
notch();
translate([square_size - square_width, square_size/2, 0])
notch();
translate([square_size/2, square_width, 0])
rotate([0, 0, 90])
notch();
}
}
square_with_notches();

View File

@@ -13,60 +13,172 @@ solid OpenSCAD_Model
vertex 0 0 5
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 5 25 5
vertex 4.5 25 5
vertex 5 5 5
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 29 5 5
vertex 5 5 5
vertex 29 4.5 5
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 60 60 5
vertex 55 55 5
vertex 55.5 31 5
vertex 60 0 5
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 60 60 5
vertex 5 55 5
vertex 55 55 5
vertex 55.5 31 5
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 60 60 5
vertex 31 55.5 5
vertex 55 55 5
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 60 60 5
vertex 29 55.5 5
vertex 31 55.5 5
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 29 55.5 5
vertex 5 55 5
vertex 29 55 5
endloop
endfacet
facet normal -0 0 1
outer loop
vertex 0 60 5
vertex 29 55.5 5
vertex 60 60 5
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 5 55 5
vertex 4.5 27 5
vertex 5 27 5
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 0 0 5
vertex 4.5 27 5
vertex 0 60 5
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 5 55 5
vertex 0 60 5
vertex 5 5 5
endloop
endfacet
facet normal -0 0 1
outer loop
vertex 0 60 5
vertex 5 55 5
vertex 60 60 5
endloop
endfacet
facet normal -0 0 1
outer loop
vertex 55 5 5
vertex 60 0 5
vertex 55 55 5
endloop
endfacet
facet normal -0 0 1
outer loop
vertex 5 5 5
vertex 60 0 5
vertex 55 5 5
vertex 4.5 27 5
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 29 55.5 5
vertex 0 60 5
vertex 5 55 5
endloop
endfacet
facet normal -0 0 1
outer loop
vertex 55.5 29 5
vertex 60 0 5
vertex 55.5 31 5
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 55 5 5
vertex 55.5 29 5
vertex 55 29 5
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 55.5 29 5
vertex 55 5 5
vertex 60 0 5
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 31 4.5 5
vertex 55 5 5
vertex 31 5 5
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 55 5 5
vertex 31 4.5 5
vertex 60 0 5
endloop
endfacet
facet normal -0 0 1
outer loop
vertex 29 4.5 5
vertex 60 0 5
vertex 31 4.5 5
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 0 0 5
vertex 29 4.5 5
vertex 5 5 5
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 4.5 27 5
vertex 0 0 5
vertex 4.5 25 5
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 29 4.5 5
vertex 0 0 5
vertex 60 0 5
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 4.5 25 5
vertex 0 0 5
vertex 5 5 5
vertex 0 60 5
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 55.5 31 5
vertex 55 55 5
vertex 55 31 5
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 55 55 5
vertex 31 55.5 5
vertex 31 55 5
endloop
endfacet
facet normal 1 -0 0
@@ -99,60 +211,172 @@ solid OpenSCAD_Model
endfacet
facet normal 0 0 -1
outer loop
vertex 60 0 0
vertex 5 27 0
vertex 4.5 27 0
vertex 5 55 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 29 55 0
vertex 5 55 0
vertex 29 55.5 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 60 0 0
vertex 55.5 29 0
vertex 60 60 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 60 0 0
vertex 5 5 0
vertex 55 5 0
vertex 55.5 29 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 60 0 0
vertex 31 4.5 0
vertex 55 5 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 60 0 0
vertex 29 4.5 0
vertex 31 4.5 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 29 4.5 0
vertex 5 5 0
vertex 29 5 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 0 0 0
vertex 29 4.5 0
vertex 60 0 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 5 5 0
vertex 4.5 25 0
vertex 5 25 0
endloop
endfacet
facet normal -0 0 -1
outer loop
vertex 4.5 25 0
vertex 0 0 0
vertex 4.5 27 0
endloop
endfacet
facet normal -0 0 -1
outer loop
vertex 5 5 0
vertex 0 0 0
vertex 5 55 0
vertex 4.5 25 0
endloop
endfacet
facet normal 0 0 -1
facet normal -0 0 -1
outer loop
vertex 29 4.5 0
vertex 0 0 0
vertex 5 5 0
vertex 60 0 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 55.5 31 0
vertex 60 60 0
vertex 55.5 29 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 55 55 0
vertex 60 60 0
vertex 55 5 0
vertex 55.5 31 0
vertex 55 31 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 5 55 0
vertex 60 60 0
vertex 55.5 31 0
vertex 55 55 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 5 55 0
vertex 0 60 0
vertex 60 60 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 31 55.5 0
vertex 55 55 0
vertex 31 55 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 55 55 0
vertex 31 55.5 0
vertex 60 60 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 29 55.5 0
vertex 60 60 0
vertex 31 55.5 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 0 60 0
vertex 29 55.5 0
vertex 5 55 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 0 60 0
vertex 4.5 27 0
vertex 0 0 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 29 55.5 0
vertex 0 60 0
vertex 60 60 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 4.5 27 0
vertex 0 60 0
vertex 5 55 0
endloop
endfacet
facet normal -0 0 -1
outer loop
vertex 55.5 29 0
vertex 55 5 0
vertex 55 29 0
endloop
endfacet
facet normal -0 0 -1
outer loop
vertex 55 5 0
vertex 31 4.5 0
vertex 31 5 0
endloop
endfacet
facet normal 0 -1 0
outer loop
vertex 0 0 0
@@ -170,6 +394,20 @@ solid OpenSCAD_Model
facet normal 1 -0 0
outer loop
vertex 5 5 5
vertex 5 25 0
vertex 5 25 5
endloop
endfacet
facet normal 1 0 0
outer loop
vertex 5 25 0
vertex 5 5 5
vertex 5 5 0
endloop
endfacet
facet normal 1 -0 0
outer loop
vertex 5 27 5
vertex 5 55 0
vertex 5 55 5
endloop
@@ -177,13 +415,27 @@ solid OpenSCAD_Model
facet normal 1 0 0
outer loop
vertex 5 55 0
vertex 5 5 5
vertex 5 5 0
vertex 5 27 5
vertex 5 27 0
endloop
endfacet
facet normal -1 0 0
outer loop
vertex 55 5 0
vertex 55 29 5
vertex 55 29 0
endloop
endfacet
facet normal -1 -0 0
outer loop
vertex 55 29 5
vertex 55 5 0
vertex 55 5 5
endloop
endfacet
facet normal -1 0 0
outer loop
vertex 55 31 0
vertex 55 55 5
vertex 55 55 0
endloop
@@ -191,36 +443,232 @@ solid OpenSCAD_Model
facet normal -1 -0 0
outer loop
vertex 55 55 5
vertex 55 5 0
vertex 55 5 5
vertex 55 31 0
vertex 55 31 5
endloop
endfacet
facet normal 0 1 -0
outer loop
vertex 55 5 0
vertex 29 5 0
vertex 5 5 5
vertex 55 5 5
vertex 29 5 5
endloop
endfacet
facet normal 0 1 0
outer loop
vertex 5 5 5
vertex 55 5 0
vertex 29 5 0
vertex 5 5 0
endloop
endfacet
facet normal 0 1 -0
outer loop
vertex 55 5 0
vertex 31 5 5
vertex 55 5 5
endloop
endfacet
facet normal 0 1 0
outer loop
vertex 31 5 5
vertex 55 5 0
vertex 31 5 0
endloop
endfacet
facet normal 0 -1 0
outer loop
vertex 5 55 0
vertex 55 55 5
vertex 29 55 5
vertex 5 55 5
endloop
endfacet
facet normal 0 -1 -0
outer loop
vertex 55 55 5
vertex 29 55 5
vertex 5 55 0
vertex 29 55 0
endloop
endfacet
facet normal 0 -1 0
outer loop
vertex 31 55 0
vertex 55 55 5
vertex 31 55 5
endloop
endfacet
facet normal 0 -1 -0
outer loop
vertex 55 55 5
vertex 31 55 0
vertex 55 55 0
endloop
endfacet
facet normal 1 -0 0
outer loop
vertex 4.5 25 5
vertex 4.5 27 0
vertex 4.5 27 5
endloop
endfacet
facet normal 1 0 0
outer loop
vertex 4.5 27 0
vertex 4.5 25 5
vertex 4.5 25 0
endloop
endfacet
facet normal 0 -1 0
outer loop
vertex 4.5 27 0
vertex 5 27 5
vertex 4.5 27 5
endloop
endfacet
facet normal 0 -1 -0
outer loop
vertex 5 27 5
vertex 4.5 27 0
vertex 5 27 0
endloop
endfacet
facet normal 0 1 -0
outer loop
vertex 5 25 0
vertex 4.5 25 5
vertex 5 25 5
endloop
endfacet
facet normal 0 1 0
outer loop
vertex 4.5 25 5
vertex 5 25 0
vertex 4.5 25 0
endloop
endfacet
facet normal 0 -1 0
outer loop
vertex 29 55.5 0
vertex 31 55.5 5
vertex 29 55.5 5
endloop
endfacet
facet normal 0 -1 -0
outer loop
vertex 31 55.5 5
vertex 29 55.5 0
vertex 31 55.5 0
endloop
endfacet
facet normal 1 -0 0
outer loop
vertex 29 55 5
vertex 29 55.5 0
vertex 29 55.5 5
endloop
endfacet
facet normal 1 0 0
outer loop
vertex 29 55.5 0
vertex 29 55 5
vertex 29 55 0
endloop
endfacet
facet normal -1 0 0
outer loop
vertex 31 55 0
vertex 31 55.5 5
vertex 31 55.5 0
endloop
endfacet
facet normal -1 -0 0
outer loop
vertex 31 55.5 5
vertex 31 55 0
vertex 31 55 5
endloop
endfacet
facet normal -1 0 0
outer loop
vertex 55.5 29 0
vertex 55.5 31 5
vertex 55.5 31 0
endloop
endfacet
facet normal -1 -0 0
outer loop
vertex 55.5 31 5
vertex 55.5 29 0
vertex 55.5 29 5
endloop
endfacet
facet normal 0 -1 0
outer loop
vertex 55 31 0
vertex 55.5 31 5
vertex 55 31 5
endloop
endfacet
facet normal 0 -1 -0
outer loop
vertex 55.5 31 5
vertex 55 31 0
vertex 55.5 31 0
endloop
endfacet
facet normal 0 1 -0
outer loop
vertex 55.5 29 0
vertex 55 29 5
vertex 55.5 29 5
endloop
endfacet
facet normal 0 1 0
outer loop
vertex 55 29 5
vertex 55.5 29 0
vertex 55 29 0
endloop
endfacet
facet normal 0 1 -0
outer loop
vertex 31 4.5 0
vertex 29 4.5 5
vertex 31 4.5 5
endloop
endfacet
facet normal 0 1 0
outer loop
vertex 29 4.5 5
vertex 31 4.5 0
vertex 29 4.5 0
endloop
endfacet
facet normal -1 0 0
outer loop
vertex 31 4.5 0
vertex 31 5 5
vertex 31 5 0
endloop
endfacet
facet normal -1 -0 0
outer loop
vertex 31 5 5
vertex 31 4.5 0
vertex 31 4.5 5
endloop
endfacet
facet normal 1 -0 0
outer loop
vertex 29 4.5 5
vertex 29 5 0
vertex 29 5 5
endloop
endfacet
facet normal 1 0 0
outer loop
vertex 29 5 0
vertex 29 4.5 5
vertex 29 4.5 0
endloop
endfacet
endsolid OpenSCAD_Model

View File

@@ -9,28 +9,52 @@ import stepper, homing
StepList = (0, 1, 2)
class CartKinematics:
def __init__(self, printer, config):
self.steppers = [stepper.PrinterStepper(
printer, config.getsection('stepper_' + n), n)
def __init__(self, toolhead, printer, config):
self.printer = printer
self.steppers = [stepper.LookupMultiHomingStepper(
printer, config.getsection('stepper_' + n))
for n in ['x', 'y', 'z']]
max_velocity, max_accel = toolhead.get_max_velocity()
self.max_z_velocity = config.getfloat(
'max_z_velocity', 9999999.9, above=0.)
'max_z_velocity', max_velocity, above=0., maxval=max_velocity)
self.max_z_accel = config.getfloat(
'max_z_accel', 9999999.9, above=0.)
'max_z_accel', max_accel, above=0., maxval=max_accel)
self.need_motor_enable = True
self.limits = [(1.0, -1.0)] * 3
def set_max_jerk(self, max_xy_halt_velocity, max_velocity, max_accel):
self.steppers[0].set_max_jerk(max_xy_halt_velocity, max_accel)
self.steppers[1].set_max_jerk(max_xy_halt_velocity, max_accel)
self.steppers[2].set_max_jerk(0., self.max_z_accel)
def set_position(self, newpos):
# Setup stepper max halt velocity
max_halt_velocity = toolhead.get_max_axis_halt()
self.steppers[0].set_max_jerk(max_halt_velocity, max_accel)
self.steppers[1].set_max_jerk(max_halt_velocity, max_accel)
self.steppers[2].set_max_jerk(
min(max_halt_velocity, self.max_z_velocity), max_accel)
# Check for dual carriage support
self.dual_carriage_axis = None
self.dual_carriage_steppers = []
if config.has_section('dual_carriage'):
dc_config = config.getsection('dual_carriage')
self.dual_carriage_axis = dc_config.getchoice(
'axis', {'x': 0, 'y': 1})
dc_stepper = stepper.LookupMultiHomingStepper(printer, dc_config)
dc_stepper.set_max_jerk(max_halt_velocity, max_accel)
self.dual_carriage_steppers = [
self.steppers[self.dual_carriage_axis], dc_stepper]
printer.lookup_object('gcode').register_command(
'SET_DUAL_CARRIAGE', self.cmd_SET_DUAL_CARRIAGE,
desc=self.cmd_SET_DUAL_CARRIAGE_help)
def get_steppers(self, flags=""):
if flags == "Z":
return [self.steppers[2]]
return list(self.steppers)
def get_position(self):
return [s.mcu_stepper.get_commanded_position() for s in self.steppers]
def set_position(self, newpos, homing_axes):
for i in StepList:
self.steppers[i].mcu_stepper.set_position(newpos[i])
def home(self, homing_state):
# Each axis is homed independently and in order
for axis in homing_state.get_axes():
s = self.steppers[axis]
self.limits[axis] = (s.position_min, s.position_max)
s = self.steppers[i]
s.set_position(newpos[i])
if i in homing_axes:
self.limits[i] = (s.position_min, s.position_max)
def _home_axis(self, homing_state, axis, stepper):
s = stepper
# Determine moves
if s.homing_positive_dir:
pos = s.position_endstop - 1.5*(
@@ -43,36 +67,51 @@ class CartKinematics:
rpos = s.position_endstop + s.homing_retract_dist
r2pos = rpos + s.homing_retract_dist
# Initial homing
homing_speed = s.homing_speed
if axis == 2:
homing_speed = min(homing_speed, self.max_z_velocity)
homepos = [None, None, None, None]
homepos[axis] = s.position_endstop
coord = [None, None, None, None]
coord[axis] = pos
homing_state.home(list(coord), homepos, [s], s.homing_speed)
homing_state.home(coord, homepos, s.get_endstops(), homing_speed)
# Retract
coord[axis] = rpos
homing_state.retract(list(coord), s.homing_speed)
homing_state.retract(coord, homing_speed)
# Home again
coord[axis] = r2pos
homing_state.home(
list(coord), homepos, [s], s.homing_speed/2.0, second_home=True)
homing_state.home(coord, homepos, s.get_endstops(),
homing_speed/2.0, second_home=True)
# Set final homed position
coord[axis] = s.position_endstop + s.get_homed_offset()
homing_state.set_homed_position(coord)
def motor_off(self, move_time):
def home(self, homing_state):
# Each axis is homed independently and in order
for axis in homing_state.get_axes():
if axis == self.dual_carriage_axis:
dc1, dc2 = self.dual_carriage_steppers
altc = self.steppers[axis] == dc2
self._activate_carriage(0)
self._home_axis(homing_state, axis, dc1)
self._activate_carriage(1)
self._home_axis(homing_state, axis, dc2)
self._activate_carriage(altc)
else:
self._home_axis(homing_state, axis, self.steppers[axis])
def motor_off(self, print_time):
self.limits = [(1.0, -1.0)] * 3
for stepper in self.steppers:
stepper.motor_enable(move_time, 0)
stepper.motor_enable(print_time, 0)
for stepper in self.dual_carriage_steppers:
stepper.motor_enable(print_time, 0)
self.need_motor_enable = True
def _check_motor_enable(self, move_time, move):
def _check_motor_enable(self, print_time, move):
need_motor_enable = False
for i in StepList:
if move.axes_d[i]:
self.steppers[i].motor_enable(move_time, 1)
self.steppers[i].motor_enable(print_time, 1)
need_motor_enable |= self.steppers[i].need_motor_enable
self.need_motor_enable = need_motor_enable
def query_endstops(self, print_time):
endstops = [(s, s.query_endstop(print_time)) for s in self.steppers]
return [(s.name, es.query_endstop_wait()) for s, es in endstops]
def _check_endstops(self, move):
end_pos = move.end_pos
for i in StepList:
@@ -97,15 +136,15 @@ class CartKinematics:
z_ratio = move.move_d / abs(move.axes_d[2])
move.limit_speed(
self.max_z_velocity * z_ratio, self.max_z_accel * z_ratio)
def move(self, move_time, move):
def move(self, print_time, move):
if self.need_motor_enable:
self._check_motor_enable(move_time, move)
self._check_motor_enable(print_time, move)
for i in StepList:
axis_d = move.axes_d[i]
if not axis_d:
continue
mcu_stepper = self.steppers[i].mcu_stepper
mcu_time = mcu_stepper.print_to_mcu_time(move_time)
step_const = self.steppers[i].step_const
move_time = print_time
start_pos = move.start_pos[i]
axis_r = abs(axis_d) / move.move_d
accel = move.accel * axis_r
@@ -114,19 +153,38 @@ class CartKinematics:
# Acceleration steps
if move.accel_r:
accel_d = move.accel_r * axis_d
mcu_stepper.step_const(
mcu_time, start_pos, accel_d, move.start_v * axis_r, accel)
step_const(move_time, start_pos, accel_d,
move.start_v * axis_r, accel)
start_pos += accel_d
mcu_time += move.accel_t
move_time += move.accel_t
# Cruising steps
if move.cruise_r:
cruise_d = move.cruise_r * axis_d
mcu_stepper.step_const(
mcu_time, start_pos, cruise_d, cruise_v, 0.)
step_const(move_time, start_pos, cruise_d, cruise_v, 0.)
start_pos += cruise_d
mcu_time += move.cruise_t
move_time += move.cruise_t
# Deceleration steps
if move.decel_r:
decel_d = move.decel_r * axis_d
mcu_stepper.step_const(
mcu_time, start_pos, decel_d, cruise_v, -accel)
step_const(move_time, start_pos, decel_d, cruise_v, -accel)
# Dual carriage support
def _activate_carriage(self, carriage):
toolhead = self.printer.lookup_object('toolhead')
toolhead.get_last_move_time()
dc_stepper = self.dual_carriage_steppers[carriage]
dc_axis = self.dual_carriage_axis
self.steppers[dc_axis] = dc_stepper
extruder_pos = toolhead.get_position()[3]
toolhead.set_position(self.get_position() + [extruder_pos])
if self.limits[dc_axis][0] <= self.limits[dc_axis][1]:
self.limits[dc_axis] = (
dc_stepper.position_min, dc_stepper.position_max)
self.need_motor_enable = True
cmd_SET_DUAL_CARRIAGE_help = "Set which carriage is active"
def cmd_SET_DUAL_CARRIAGE(self, params):
gcode = self.printer.lookup_object('gcode')
carriage = gcode.get_int('CARRIAGE', params)
if carriage not in (0, 1):
raise gcode.error("Invalid carriage")
self._activate_carriage(carriage)
gcode.reset_last_position()

View File

@@ -25,7 +25,7 @@ defs_stepcompress = """
int stepcompress_set_homing(struct stepcompress *sc, uint64_t homing_clock);
int stepcompress_queue_msg(struct stepcompress *sc, uint32_t *data, int len);
int stepcompress_push(struct stepcompress *sc, double step_clock
int32_t stepcompress_push(struct stepcompress *sc, double step_clock
, int32_t sdir);
int32_t stepcompress_push_const(struct stepcompress *sc, double clock_offset
, double step_offset, double steps, double start_sv, double accel);
@@ -36,6 +36,8 @@ defs_stepcompress = """
struct steppersync *steppersync_alloc(struct serialqueue *sq
, struct stepcompress **sc_list, int sc_num, int move_num);
void steppersync_free(struct steppersync *ss);
void steppersync_set_time(struct steppersync *ss
, double time_offset, double mcu_freq);
int steppersync_flush(struct steppersync *ss, uint64_t move_clock);
"""
@@ -59,8 +61,8 @@ defs_serialqueue = """
, uint64_t min_clock, uint64_t req_clock);
void serialqueue_pull(struct serialqueue *sq, struct pull_queue_message *pqm);
void serialqueue_set_baud_adjust(struct serialqueue *sq, double baud_adjust);
void serialqueue_set_clock_est(struct serialqueue *sq, double est_clock
, double last_ack_time, uint64_t last_ack_clock);
void serialqueue_set_clock_est(struct serialqueue *sq, double est_freq
, double last_clock_time, uint64_t last_clock);
void serialqueue_get_stats(struct serialqueue *sq, char *buf, int len);
int serialqueue_extract_old(struct serialqueue *sq, int sentq
, struct pull_queue_message *q, int max);
@@ -88,7 +90,7 @@ def check_build_code(srcdir, target, sources, cmd, other_files=[]):
src_times = get_mtimes(srcdir, sources + other_files)
obj_times = get_mtimes(srcdir, [target])
if not obj_times or max(src_times) > min(obj_times):
logging.info("Building C code module %s" % (target,))
logging.info("Building C code module %s", target)
srcfiles = [os.path.join(srcdir, fname) for fname in sources]
destlib = os.path.join(srcdir, target)
os.system(cmd % (destlib, ' '.join(srcfiles)))

219
klippy/clocksync.py Normal file
View File

@@ -0,0 +1,219 @@
# Micro-controller clock synchronization
#
# Copyright (C) 2016,2017 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging, threading, math
COMM_TIMEOUT = 3.5
RTT_AGE = .000010 / (60. * 60.)
DECAY = 1. / 30.
TRANSMIT_EXTRA = .001
class ClockSync:
def __init__(self, reactor):
self.reactor = reactor
self.serial = None
self.status_timer = self.reactor.register_timer(self._status_event)
self.status_cmd = None
self.mcu_freq = 1.
self.last_clock = 0
self.clock_est = (0., 0., 0.)
# Minimum round-trip-time tracking
self.min_half_rtt = 999999999.9
self.min_rtt_time = 0.
# Linear regression of mcu clock and system sent_time
self.time_avg = self.time_variance = 0.
self.clock_avg = self.clock_covariance = 0.
self.prediction_variance = 0.
self.last_prediction_time = 0.
def connect(self, serial):
self.serial = serial
self.mcu_freq = serial.msgparser.get_constant_float('CLOCK_FREQ')
# Load initial clock and frequency
get_uptime_cmd = serial.lookup_command('get_uptime')
params = get_uptime_cmd.send_with_response(response='uptime')
self.last_clock = (params['high'] << 32) | params['clock']
self.clock_avg = self.last_clock
self.time_avg = params['#sent_time']
self.clock_est = (self.time_avg, self.clock_avg, self.mcu_freq)
self.prediction_variance = (.001 * self.mcu_freq)**2
# Enable periodic get_status timer
self.status_cmd = serial.lookup_command('get_status')
for i in range(8):
params = self.status_cmd.send_with_response(response='status')
self._handle_status(params)
self.reactor.pause(0.100)
serial.register_callback(self._handle_status, 'status')
self.reactor.update_timer(self.status_timer, self.reactor.NOW)
def connect_file(self, serial, pace=False):
self.serial = serial
self.mcu_freq = serial.msgparser.get_constant_float('CLOCK_FREQ')
self.clock_est = (0., 0., self.mcu_freq)
freq = 1000000000000.
if pace:
freq = self.mcu_freq
serial.set_clock_est(freq, self.reactor.monotonic(), 0)
# MCU clock querying (status callback invoked from background thread)
def _status_event(self, eventtime):
self.status_cmd.send()
return eventtime + 1.0
def _handle_status(self, params):
# Extend clock to 64bit
last_clock = self.last_clock
clock = (last_clock & ~0xffffffff) | params['clock']
if clock < last_clock:
clock += 0x100000000
self.last_clock = clock
# Check if this is the best round-trip-time seen so far
sent_time = params['#sent_time']
if not sent_time:
return
receive_time = params['#receive_time']
half_rtt = .5 * (receive_time - sent_time)
aged_rtt = (sent_time - self.min_rtt_time) * RTT_AGE
if half_rtt < self.min_half_rtt + aged_rtt:
self.min_half_rtt = half_rtt
self.min_rtt_time = sent_time
logging.debug("new minimum rtt %.3f: hrtt=%.6f freq=%d",
sent_time, half_rtt, self.clock_est[2])
# Filter out samples that are extreme outliers
exp_clock = ((sent_time - self.time_avg) * self.clock_est[2]
+ self.clock_avg)
clock_diff2 = (clock - exp_clock)**2
if (clock_diff2 > 25. * self.prediction_variance
and clock_diff2 > (.000500 * self.mcu_freq)**2):
if clock > exp_clock and sent_time < self.last_prediction_time + 10.:
logging.debug("Ignoring clock sample %.3f:"
" freq=%d diff=%d stddev=%.3f",
sent_time, self.clock_est[2], clock - exp_clock,
math.sqrt(self.prediction_variance))
return
logging.info("Resetting prediction variance %.3f:"
" freq=%d diff=%d stddev=%.3f",
sent_time, self.clock_est[2], clock - exp_clock,
math.sqrt(self.prediction_variance))
self.prediction_variance = (.001 * self.mcu_freq)**2
else:
self.last_prediction_time = sent_time
self.prediction_variance = (
(1. - DECAY) * (self.prediction_variance + clock_diff2 * DECAY))
# Add clock and sent_time to linear regression
diff_sent_time = sent_time - self.time_avg
self.time_avg += DECAY * diff_sent_time
self.time_variance = (1. - DECAY) * (
self.time_variance + diff_sent_time**2 * DECAY)
diff_clock = clock - self.clock_avg
self.clock_avg += DECAY * diff_clock
self.clock_covariance = (1. - DECAY) * (
self.clock_covariance + diff_sent_time * diff_clock * DECAY)
# Update prediction from linear regression
new_freq = self.clock_covariance / self.time_variance
pred_stddev = math.sqrt(self.prediction_variance)
self.serial.set_clock_est(new_freq, self.time_avg + TRANSMIT_EXTRA,
int(self.clock_avg - 3. * pred_stddev))
self.clock_est = (self.time_avg + self.min_half_rtt,
self.clock_avg, new_freq)
#logging.debug("regr %.3f: freq=%.3f d=%d(%.3f)",
# sent_time, new_freq, clock - exp_clock, pred_stddev)
# clock frequency conversions
def print_time_to_clock(self, print_time):
return int(print_time * self.mcu_freq)
def clock_to_print_time(self, clock):
return clock / self.mcu_freq
def get_adjusted_freq(self):
return self.mcu_freq
# system time conversions
def get_clock(self, eventtime):
sample_time, clock, freq = self.clock_est
return int(clock + (eventtime - sample_time) * freq)
def estimated_print_time(self, eventtime):
return self.clock_to_print_time(self.get_clock(eventtime))
# misc commands
def clock32_to_clock64(self, clock32):
last_clock = self.last_clock
clock_diff = (last_clock - clock32) & 0xffffffff
if clock_diff & 0x80000000:
return last_clock + 0x100000000 - clock_diff
return last_clock - clock_diff
def is_active(self, eventtime):
print_time = self.estimated_print_time(eventtime)
last_clock_print_time = self.clock_to_print_time(self.last_clock)
return print_time < last_clock_print_time + COMM_TIMEOUT
def dump_debug(self):
sample_time, clock, freq = self.clock_est
return ("clocksync state: mcu_freq=%d last_clock=%d"
" clock_est=(%.3f %d %.3f) min_half_rtt=%.6f min_rtt_time=%.3f"
" time_avg=%.3f(%.3f) clock_avg=%.3f(%.3f)"
" pred_variance=%.3f" % (
self.mcu_freq, self.last_clock, sample_time, clock, freq,
self.min_half_rtt, self.min_rtt_time,
self.time_avg, self.time_variance,
self.clock_avg, self.clock_covariance,
self.prediction_variance))
def stats(self, eventtime):
sample_time, clock, freq = self.clock_est
return "freq=%d" % (freq,)
def calibrate_clock(self, print_time, eventtime):
return (0., self.mcu_freq)
# Clock syncing code for secondary MCUs (whose clocks are sync'ed to a
# primary MCU)
class SecondarySync(ClockSync):
def __init__(self, reactor, main_sync):
ClockSync.__init__(self, reactor)
self.main_sync = main_sync
self.clock_adj = (0., 1.)
self.last_sync_time = 0.
def connect(self, serial):
ClockSync.connect(self, serial)
self.clock_adj = (0., self.mcu_freq)
curtime = self.reactor.monotonic()
main_print_time = self.main_sync.estimated_print_time(curtime)
local_print_time = self.estimated_print_time(curtime)
self.clock_adj = (main_print_time - local_print_time, self.mcu_freq)
self.calibrate_clock(0., curtime)
def connect_file(self, serial, pace=False):
ClockSync.connect_file(self, serial, pace)
self.clock_adj = (0., self.mcu_freq)
# clock frequency conversions
def print_time_to_clock(self, print_time):
adjusted_offset, adjusted_freq = self.clock_adj
return int((print_time - adjusted_offset) * adjusted_freq)
def clock_to_print_time(self, clock):
adjusted_offset, adjusted_freq = self.clock_adj
return clock / adjusted_freq + adjusted_offset
def get_adjusted_freq(self):
adjusted_offset, adjusted_freq = self.clock_adj
return adjusted_freq
# misc commands
def dump_debug(self):
adjusted_offset, adjusted_freq = self.clock_adj
return "%s clock_adj=(%.3f %.3f)" % (
ClockSync.dump_debug(self), adjusted_offset, adjusted_freq)
def stats(self, eventtime):
adjusted_offset, adjusted_freq = self.clock_adj
return "%s adj=%d" % (ClockSync.stats(self, eventtime), adjusted_freq)
def calibrate_clock(self, print_time, eventtime):
# Calculate: est_print_time = main_sync.estimatated_print_time()
ser_time, ser_clock, ser_freq = self.main_sync.clock_est
main_mcu_freq = self.main_sync.mcu_freq
est_main_clock = (eventtime - ser_time) * ser_freq + ser_clock
est_print_time = est_main_clock / main_mcu_freq
# Determine sync1_print_time and sync2_print_time
sync1_print_time = max(print_time, est_print_time)
sync2_print_time = max(sync1_print_time + 4., self.last_sync_time,
print_time + 2.5 * (print_time - est_print_time))
# Calc sync2_sys_time (inverse of main_sync.estimatated_print_time)
sync2_main_clock = sync2_print_time * main_mcu_freq
sync2_sys_time = ser_time + (sync2_main_clock - ser_clock) / ser_freq
# Adjust freq so estimated print_time will match at sync2_print_time
sync1_clock = self.print_time_to_clock(sync1_print_time)
sync2_clock = self.get_clock(sync2_sys_time)
adjusted_freq = ((sync2_clock - sync1_clock)
/ (sync2_print_time - sync1_print_time))
adjusted_offset = sync1_print_time - sync1_clock / adjusted_freq
# Apply new values
self.clock_adj = (adjusted_offset, adjusted_freq)
self.last_sync_time = sync2_print_time
return self.clock_adj

View File

@@ -1,12 +1,31 @@
#!/usr/bin/env python
#!/usr/bin/env python2
# Script to implement a test console with firmware over serial port
#
# Copyright (C) 2016,2017 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import sys, optparse, os, re, logging
import reactor, serialhdl, pins, util, msgproto, clocksync
import reactor, serialhdl, pins, util, msgproto
help_txt = """
This is a debugging console for the Klipper micro-controller.
In addition to mcu commands, the following artificial commands are
available:
PINS : Load pin name aliases (eg, "PINS arduino")
DELAY : Send a command at a clock time (eg, "DELAY 9999 get_uptime")
FLOOD : Send a command many times (eg, "FLOOD 22 .01 get_uptime")
SUPPRESS : Suppress a response message (eg, "SUPPRESS stats")
SET : Create a local variable (eg, "SET myvar 123.4")
STATS : Report serial statistics
LIST : List available mcu commands, local commands, and local variables
HELP : Show this text
All commands also support evaluation by enclosing an expression in { }.
For example, "reset_step_clock oid=4 clock={clock + freq}". In addition
to user defined variables (via the SET command) the following builtin
variables may be used in expressions:
clock : The current mcu clock time (as estimated by the host)
freq : The mcu clock frequency
"""
re_eval = re.compile(r'\{(?P<eval>[^}]*)\}')
@@ -14,6 +33,7 @@ class KeyboardReader:
def __init__(self, ser, reactor):
self.ser = ser
self.reactor = reactor
self.clocksync = clocksync.ClockSync(self.reactor)
self.fd = sys.stdin.fileno()
util.set_nonblock(self.fd)
self.mcu_freq = 0
@@ -21,41 +41,109 @@ class KeyboardReader:
self.data = ""
reactor.register_fd(self.fd, self.process_kbd)
self.connect_timer = reactor.register_timer(self.connect, reactor.NOW)
self.local_commands = { "PINS": self.set_pin_map, "SET": self.set_var }
self.local_commands = {
"PINS": self.command_PINS, "SET": self.command_SET,
"DELAY": self.command_DELAY, "FLOOD": self.command_FLOOD,
"SUPPRESS": self.command_SUPPRESS, "STATS": self.command_STATS,
"LIST": self.command_LIST, "HELP": self.command_HELP,
}
self.eval_globals = {}
def connect(self, eventtime):
self.output(help_txt)
self.output("="*20 + " attempting to connect " + "="*20)
self.ser.connect()
self.clocksync.connect(self.ser)
self.ser.handle_default = self.handle_default
self.mcu_freq = self.ser.msgparser.get_constant_float('CLOCK_FREQ')
mcu = self.ser.msgparser.get_constant('MCU')
self.pins = pins.get_pin_map(mcu)
mcu_type = self.ser.msgparser.get_constant('MCU')
self.pins = pins.PinResolver(mcu_type, validate_aliases=False)
self.reactor.unregister_timer(self.connect_timer)
self.output("="*20 + " connected " + "="*20)
return self.reactor.NEVER
def output(self, msg):
sys.stdout.write("%s\n" % (msg,))
sys.stdout.flush()
def handle_default(self, params):
self.output(self.ser.msgparser.format_params(params))
def handle_suppress(self, params):
pass
def update_evals(self, eventtime):
self.eval_globals['freq'] = self.mcu_freq
self.eval_globals['clock'] = self.ser.get_clock(eventtime)
def set_pin_map(self, parts):
mcu = self.ser.msgparser.get_constant('MCU')
self.pins = pins.get_pin_map(mcu, parts[1])
def set_var(self, parts):
self.eval_globals['clock'] = self.clocksync.get_clock(eventtime)
def command_PINS(self, parts):
self.pins.update_aliases(parts[1])
def command_SET(self, parts):
val = parts[2]
try:
val = float(val)
except ValueError:
pass
self.eval_globals[parts[1]] = val
def command_DELAY(self, parts):
try:
val = int(parts[1])
except ValueError as e:
self.output("Error: %s" % (str(e),))
return
try:
self.ser.send(' '.join(parts[2:]), minclock=val)
except msgproto.error as e:
self.output("Error: %s" % (str(e),))
return
def command_FLOOD(self, parts):
try:
count = int(parts[1])
delay = float(parts[2])
except ValueError as e:
self.output("Error: %s" % (str(e),))
return
msg = ' '.join(parts[3:])
delay_clock = int(delay * self.mcu_freq)
msg_clock = int(self.clocksync.get_clock(self.reactor.monotonic())
+ self.mcu_freq * .200)
try:
for i in range(count):
next_clock = msg_clock + delay_clock
self.ser.send(msg, minclock=msg_clock, reqclock=next_clock)
msg_clock = next_clock
except msgproto.error as e:
self.output("Error: %s" % (str(e),))
return
def command_SUPPRESS(self, parts):
oid = None
try:
name = parts[1]
if len(parts) > 2:
oid = int(parts[2])
except ValueError as e:
self.output("Error: %s" % (str(e),))
return
self.ser.register_callback(self.handle_suppress, name, oid)
def command_STATS(self, parts):
curtime = self.reactor.monotonic()
self.output(' '.join([self.ser.stats(curtime),
self.clocksync.stats(curtime)]))
def command_LIST(self, parts):
self.update_evals(self.reactor.monotonic())
mp = self.ser.msgparser
out = "Available mcu commands:"
out += "\n ".join([""] + sorted([
mp.messages_by_id[i].msgformat for i in mp.command_ids]))
out += "\nAvailable artificial commands:"
out += "\n ".join([""] + [n for n in sorted(self.local_commands)])
out += "\nAvailable local variables:"
out += "\n ".join([""] + ["%s: %s" % (k, v)
for k, v in sorted(self.eval_globals.items())])
self.output(out)
def command_HELP(self, parts):
self.output(help_txt)
def translate(self, line, eventtime):
evalparts = re_eval.split(line)
if len(evalparts) > 1:
self.update_evals(eventtime)
try:
for i in range(1, len(evalparts), 2):
e = eval(evalparts[i], self.eval_globals)
e = eval(evalparts[i], dict(self.eval_globals))
if type(e) == type(0.):
e = int(e)
evalparts[i] = str(e)
@@ -66,8 +154,7 @@ class KeyboardReader:
self.output("Eval: %s" % (line,))
if self.pins is not None:
try:
line = pins.update_command(
line, self.mcu_freq, self.pins).strip()
line = self.pins.update_command(line).strip()
except:
self.output("Unable to map pin: %s" % (line,))
return None
@@ -76,12 +163,7 @@ class KeyboardReader:
if parts[0] in self.local_commands:
self.local_commands[parts[0]](parts)
return None
try:
msg = self.ser.msgparser.create_command(line)
except msgproto.error, e:
self.output("Error: %s" % (str(e),))
return None
return msg
return line
def process_kbd(self, eventtime):
self.data += os.read(self.fd, 4096)
@@ -96,7 +178,11 @@ class KeyboardReader:
msg = self.translate(line.strip(), eventtime)
if msg is None:
continue
try:
self.ser.send(msg)
except msgproto.error as e:
self.output("Error: %s" % (str(e),))
return None
self.data = kbdlines[-1]
def main():

View File

@@ -3,37 +3,54 @@
# Copyright (C) 2017 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging
import logging, math
import stepper, homing
StepList = (0, 1, 2)
class CoreXYKinematics:
def __init__(self, printer, config):
self.steppers = [stepper.PrinterStepper(
printer, config.getsection('stepper_' + n), n)
for n in ['x', 'y', 'z']]
def __init__(self, toolhead, printer, config):
self.steppers = [
stepper.PrinterHomingStepper(
printer, config.getsection('stepper_x')),
stepper.PrinterHomingStepper(
printer, config.getsection('stepper_y')),
stepper.LookupMultiHomingStepper(
printer, config.getsection('stepper_z'))]
self.steppers[0].mcu_endstop.add_stepper(self.steppers[1].mcu_stepper)
self.steppers[1].mcu_endstop.add_stepper(self.steppers[0].mcu_stepper)
max_velocity, max_accel = toolhead.get_max_velocity()
self.max_z_velocity = config.getfloat(
'max_z_velocity', 9999999.9, above=0.)
'max_z_velocity', max_velocity, above=0., maxval=max_velocity)
self.max_z_accel = config.getfloat(
'max_z_accel', 9999999.9, above=0.)
'max_z_accel', max_accel, above=0., maxval=max_accel)
self.need_motor_enable = True
self.limits = [(1.0, -1.0)] * 3
def set_max_jerk(self, max_xy_halt_velocity, max_velocity, max_accel):
# Setup stepper max halt velocity
max_halt_velocity = toolhead.get_max_axis_halt()
max_xy_halt_velocity = max_halt_velocity * math.sqrt(2.)
self.steppers[0].set_max_jerk(max_xy_halt_velocity, max_accel)
self.steppers[1].set_max_jerk(max_xy_halt_velocity, max_accel)
self.steppers[2].set_max_jerk(0., self.max_z_accel)
def set_position(self, newpos):
self.steppers[2].set_max_jerk(
min(max_halt_velocity, self.max_z_velocity), self.max_z_accel)
def get_steppers(self, flags=""):
if flags == "Z":
return [self.steppers[2]]
return list(self.steppers)
def get_position(self):
pos = [s.mcu_stepper.get_commanded_position() for s in self.steppers]
return [0.5 * (pos[0] + pos[1]), 0.5 * (pos[0] - pos[1]), pos[2]]
def set_position(self, newpos, homing_axes):
pos = (newpos[0] + newpos[1], newpos[0] - newpos[1], newpos[2])
for i in StepList:
self.steppers[i].mcu_stepper.set_position(pos[i])
s = self.steppers[i]
s.set_position(pos[i])
if i in homing_axes:
self.limits[i] = (s.position_min, s.position_max)
def home(self, homing_state):
# Each axis is homed independently and in order
for axis in homing_state.get_axes():
s = self.steppers[axis]
self.limits[axis] = (s.position_min, s.position_max)
# Determine moves
if s.homing_positive_dir:
pos = s.position_endstop - 1.5*(
@@ -46,40 +63,40 @@ class CoreXYKinematics:
rpos = s.position_endstop + s.homing_retract_dist
r2pos = rpos + s.homing_retract_dist
# Initial homing
homing_speed = s.homing_speed
if axis == 2:
homing_speed = min(homing_speed, self.max_z_velocity)
homepos = [None, None, None, None]
homepos[axis] = s.position_endstop
coord = [None, None, None, None]
coord[axis] = pos
homing_state.home(list(coord), homepos, [s], s.homing_speed)
homing_state.home(coord, homepos, s.get_endstops(), homing_speed)
# Retract
coord[axis] = rpos
homing_state.retract(list(coord), s.homing_speed)
homing_state.retract(coord, homing_speed)
# Home again
coord[axis] = r2pos
homing_state.home(
list(coord), homepos, [s], s.homing_speed/2.0, second_home=True)
homing_state.home(coord, homepos, s.get_endstops(),
homing_speed/2.0, second_home=True)
if axis == 2:
# Support endstop phase detection on Z axis
coord[axis] = s.position_endstop + s.get_homed_offset()
homing_state.set_homed_position(coord)
def motor_off(self, move_time):
def motor_off(self, print_time):
self.limits = [(1.0, -1.0)] * 3
for stepper in self.steppers:
stepper.motor_enable(move_time, 0)
stepper.motor_enable(print_time, 0)
self.need_motor_enable = True
def _check_motor_enable(self, move_time, move):
def _check_motor_enable(self, print_time, move):
if move.axes_d[0] or move.axes_d[1]:
self.steppers[0].motor_enable(move_time, 1)
self.steppers[1].motor_enable(move_time, 1)
self.steppers[0].motor_enable(print_time, 1)
self.steppers[1].motor_enable(print_time, 1)
if move.axes_d[2]:
self.steppers[2].motor_enable(move_time, 1)
self.steppers[2].motor_enable(print_time, 1)
need_motor_enable = False
for i in StepList:
need_motor_enable |= self.steppers[i].need_motor_enable
self.need_motor_enable = need_motor_enable
def query_endstops(self, print_time):
endstops = [(s, s.query_endstop(print_time)) for s in self.steppers]
return [(s.name, es.query_endstop_wait()) for s, es in endstops]
def _check_endstops(self, move):
end_pos = move.end_pos
for i in StepList:
@@ -104,9 +121,9 @@ class CoreXYKinematics:
z_ratio = move.move_d / abs(move.axes_d[2])
move.limit_speed(
self.max_z_velocity * z_ratio, self.max_z_accel * z_ratio)
def move(self, move_time, move):
def move(self, print_time, move):
if self.need_motor_enable:
self._check_motor_enable(move_time, move)
self._check_motor_enable(print_time, move)
sxp = move.start_pos[0]
syp = move.start_pos[1]
move_start_pos = (sxp + syp, sxp - syp, move.start_pos[2])
@@ -118,8 +135,8 @@ class CoreXYKinematics:
axis_d = axes_d[i]
if not axis_d:
continue
mcu_stepper = self.steppers[i].mcu_stepper
mcu_time = mcu_stepper.print_to_mcu_time(move_time)
step_const = self.steppers[i].step_const
move_time = print_time
start_pos = move_start_pos[i]
axis_r = abs(axis_d) / move.move_d
accel = move.accel * axis_r
@@ -128,19 +145,17 @@ class CoreXYKinematics:
# Acceleration steps
if move.accel_r:
accel_d = move.accel_r * axis_d
mcu_stepper.step_const(
mcu_time, start_pos, accel_d, move.start_v * axis_r, accel)
step_const(move_time, start_pos, accel_d,
move.start_v * axis_r, accel)
start_pos += accel_d
mcu_time += move.accel_t
move_time += move.accel_t
# Cruising steps
if move.cruise_r:
cruise_d = move.cruise_r * axis_d
mcu_stepper.step_const(
mcu_time, start_pos, cruise_d, cruise_v, 0.)
step_const(move_time, start_pos, cruise_d, cruise_v, 0.)
start_pos += cruise_d
mcu_time += move.cruise_t
move_time += move.cruise_t
# Deceleration steps
if move.decel_r:
decel_d = move.decel_r * axis_d
mcu_stepper.step_const(
mcu_time, start_pos, decel_d, cruise_v, -accel)
step_const(move_time, start_pos, decel_d, cruise_v, -accel)

View File

@@ -12,127 +12,115 @@ StepList = (0, 1, 2)
SLOW_RATIO = 3.
class DeltaKinematics:
def __init__(self, printer, config):
self.config = config
self.steppers = [stepper.PrinterStepper(
printer, config.getsection('stepper_' + n), n)
def __init__(self, toolhead, printer, config):
stepper_configs = [config.getsection('stepper_' + n)
for n in ['a', 'b', 'c']]
stepper_a = stepper.PrinterHomingStepper(printer, stepper_configs[0])
stepper_b = stepper.PrinterHomingStepper(
printer, stepper_configs[1],
default_position=stepper_a.position_endstop)
stepper_c = stepper.PrinterHomingStepper(
printer, stepper_configs[2],
default_position=stepper_a.position_endstop)
self.steppers = [stepper_a, stepper_b, stepper_c]
self.need_motor_enable = self.need_home = True
self.max_velocity = self.max_z_velocity = self.max_accel = 0.
radius = config.getfloat('delta_radius', above=0.)
arm_length = config.getfloat('delta_arm_length', above=radius)
self.arm_length2 = arm_length**2
self.radius = radius = config.getfloat('delta_radius', above=0.)
arm_length_a = stepper_configs[0].getfloat('arm_length', above=radius)
self.arm_lengths = arm_lengths = [
sconfig.getfloat('arm_length', arm_length_a, above=radius)
for sconfig in stepper_configs]
self.arm2 = [arm**2 for arm in arm_lengths]
self.endstops = [s.position_endstop + math.sqrt(arm2 - radius**2)
for s, arm2 in zip(self.steppers, self.arm2)]
self.limit_xy2 = -1.
tower_height_at_zeros = math.sqrt(self.arm_length2 - radius**2)
self.max_z = max([s.position_endstop for s in self.steppers])
self.limit_z = self.max_z - (arm_length - tower_height_at_zeros)
self.max_z = min([s.position_endstop for s in self.steppers])
self.min_z = config.getfloat('minimum_z_position', 0, maxval=self.max_z)
self.limit_z = min([ep - arm
for ep, arm in zip(self.endstops, arm_lengths)])
logging.info(
"Delta max build height %.2fmm (radius tapered above %.2fmm)" % (
self.max_z, self.limit_z))
sin = lambda angle: math.sin(math.radians(angle))
cos = lambda angle: math.cos(math.radians(angle))
self.towers = [
(cos(210.)*radius, sin(210.)*radius),
(cos(330.)*radius, sin(330.)*radius),
(cos(90.)*radius, sin(90.)*radius)]
# Setup stepper max halt velocity
self.max_velocity, self.max_accel = toolhead.get_max_velocity()
self.max_z_velocity = config.getfloat(
'max_z_velocity', self.max_velocity,
above=0., maxval=self.max_velocity)
max_halt_velocity = toolhead.get_max_axis_halt()
for s in self.steppers:
s.set_max_jerk(max_halt_velocity, self.max_accel)
# Determine tower locations in cartesian space
self.angles = [sconfig.getfloat('angle', angle)
for sconfig, angle in zip(stepper_configs,
[210., 330., 90.])]
self.towers = [(math.cos(math.radians(angle)) * radius,
math.sin(math.radians(angle)) * radius)
for angle in self.angles]
# Find the point where an XY move could result in excessive
# tower movement
half_min_step_dist = min([s.step_dist for s in self.steppers]) * .5
min_arm_length = min(arm_lengths)
def ratio_to_dist(ratio):
return (ratio * math.sqrt(self.arm_length2 / (ratio**2 + 1.)
return (ratio * math.sqrt(min_arm_length**2 / (ratio**2 + 1.)
- half_min_step_dist**2)
+ half_min_step_dist)
self.slow_xy2 = (ratio_to_dist(SLOW_RATIO) - radius)**2
self.very_slow_xy2 = (ratio_to_dist(2. * SLOW_RATIO) - radius)**2
self.max_xy2 = min(radius, arm_length - radius,
self.max_xy2 = min(radius, min_arm_length - radius,
ratio_to_dist(4. * SLOW_RATIO) - radius)**2
logging.info(
"Delta max build radius %.2fmm (moves slowed past %.2fmm and %.2fmm)"
% (math.sqrt(self.max_xy2), math.sqrt(self.slow_xy2),
math.sqrt(self.very_slow_xy2)))
self.set_position([0., 0., 0.])
def set_max_jerk(self, max_xy_halt_velocity, max_velocity, max_accel):
self.max_velocity = max_velocity
max_z_velocity = self.config.getfloat(
'max_z_velocity', max_velocity, above=0.)
self.max_z_velocity = min(max_velocity, max_z_velocity)
self.max_accel = max_accel
for stepper in self.steppers:
stepper.set_max_jerk(max_xy_halt_velocity, max_accel)
self.set_position([0., 0., 0.], ())
def get_steppers(self, flags=""):
return list(self.steppers)
def _cartesian_to_actuator(self, coord):
return [math.sqrt(self.arm_length2
- (self.towers[i][0] - coord[0])**2
return [math.sqrt(self.arm2[i] - (self.towers[i][0] - coord[0])**2
- (self.towers[i][1] - coord[1])**2) + coord[2]
for i in StepList]
def _actuator_to_cartesian(self, pos):
# Based on code from Smoothieware
tower1 = list(self.towers[0]) + [pos[0]]
tower2 = list(self.towers[1]) + [pos[1]]
tower3 = list(self.towers[2]) + [pos[2]]
s12 = matrix_sub(tower1, tower2)
s23 = matrix_sub(tower2, tower3)
s13 = matrix_sub(tower1, tower3)
normal = matrix_cross(s12, s23)
magsq_s12 = matrix_magsq(s12)
magsq_s23 = matrix_magsq(s23)
magsq_s13 = matrix_magsq(s13)
inv_nmag_sq = 1.0 / matrix_magsq(normal)
q = 0.5 * inv_nmag_sq
a = q * magsq_s23 * matrix_dot(s12, s13)
b = -q * magsq_s13 * matrix_dot(s12, s23) # negate because we use s12 instead of s21
c = q * magsq_s12 * matrix_dot(s13, s23)
circumcenter = [tower1[0] * a + tower2[0] * b + tower3[0] * c,
tower1[1] * a + tower2[1] * b + tower3[1] * c,
tower1[2] * a + tower2[2] * b + tower3[2] * c]
r_sq = 0.5 * q * magsq_s12 * magsq_s23 * magsq_s13
dist = math.sqrt(inv_nmag_sq * (self.arm_length2 - r_sq))
return matrix_sub(circumcenter, matrix_mul(normal, dist))
def set_position(self, newpos):
return actuator_to_cartesian(self.towers, self.arm2, pos)
def get_position(self):
spos = [s.mcu_stepper.get_commanded_position() for s in self.steppers]
return self._actuator_to_cartesian(spos)
def set_position(self, newpos, homing_axes):
pos = self._cartesian_to_actuator(newpos)
for i in StepList:
self.steppers[i].mcu_stepper.set_position(pos[i])
self.steppers[i].set_position(pos[i])
self.limit_xy2 = -1.
if tuple(homing_axes) == StepList:
self.need_home = False
def home(self, homing_state):
# All axes are homed simultaneously
homing_state.set_axes([0, 1, 2])
endstops = [es for s in self.steppers for es in s.get_endstops()]
s = self.steppers[0] # Assume homing speed same for all steppers
self.need_home = False
# Initial homing
homing_speed = min(s.homing_speed, self.max_z_velocity)
homepos = [0., 0., self.max_z, None]
coord = list(homepos)
coord[2] = -1.5 * math.sqrt(self.arm_length2-self.max_xy2)
homing_state.home(list(coord), homepos, self.steppers, s.homing_speed)
coord[2] = -1.5 * math.sqrt(max(self.arm2)-self.max_xy2)
homing_state.home(coord, homepos, endstops, homing_speed)
# Retract
coord[2] = homepos[2] - s.homing_retract_dist
homing_state.retract(list(coord), s.homing_speed)
homing_state.retract(coord, homing_speed)
# Home again
coord[2] -= s.homing_retract_dist
homing_state.home(list(coord), homepos, self.steppers
, s.homing_speed/2.0, second_home=True)
homing_state.home(coord, homepos, endstops,
homing_speed/2.0, second_home=True)
# Set final homed position
coord = [s.mcu_stepper.get_commanded_position() + s.get_homed_offset()
for s in self.steppers]
homing_state.set_homed_position(self._actuator_to_cartesian(coord))
def motor_off(self, move_time):
spos = [ep + s.get_homed_offset()
for ep, s in zip(self.endstops, self.steppers)]
homing_state.set_homed_position(self._actuator_to_cartesian(spos))
def motor_off(self, print_time):
self.limit_xy2 = -1.
for stepper in self.steppers:
stepper.motor_enable(move_time, 0)
stepper.motor_enable(print_time, 0)
self.need_motor_enable = self.need_home = True
def _check_motor_enable(self, move_time):
def _check_motor_enable(self, print_time):
for i in StepList:
self.steppers[i].motor_enable(move_time, 1)
self.steppers[i].motor_enable(print_time, 1)
self.need_motor_enable = False
def query_endstops(self, print_time):
endstops = [(s, s.query_endstop(print_time)) for s in self.steppers]
return [(s.name, es.query_endstop_wait()) for s, es in endstops]
def check_move(self, move):
end_pos = move.end_pos
xy2 = end_pos[0]**2 + end_pos[1]**2
@@ -144,7 +132,7 @@ class DeltaKinematics:
limit_xy2 = self.max_xy2
if end_pos[2] > self.limit_z:
limit_xy2 = min(limit_xy2, (self.max_z - end_pos[2])**2)
if xy2 > limit_xy2 or end_pos[2] < 0. or end_pos[2] > self.max_z:
if xy2 > limit_xy2 or end_pos[2] < self.min_z or end_pos[2] > self.max_z:
raise homing.EndstopMoveError(end_pos)
if move.axes_d[2]:
move.limit_speed(self.max_z_velocity, move.accel)
@@ -162,9 +150,9 @@ class DeltaKinematics:
move.limit_speed(max_velocity * r, self.max_accel * r)
limit_xy2 = -1.
self.limit_xy2 = min(limit_xy2, self.slow_xy2)
def move(self, move_time, move):
def move(self, print_time, move):
if self.need_motor_enable:
self._check_motor_enable(move_time)
self._check_motor_enable(print_time)
axes_d = move.axes_d
move_d = move.move_d
movexy_r = 1.
@@ -196,30 +184,42 @@ class DeltaKinematics:
towery_d = self.towers[i][1] - origy
vt_startxy_d = (towerx_d*axes_d[0] + towery_d*axes_d[1])*inv_movexy_d
tangentxy_d2 = towerx_d**2 + towery_d**2 - vt_startxy_d**2
vt_arm_d = math.sqrt(self.arm_length2 - tangentxy_d2)
vt_arm_d = math.sqrt(self.arm2[i] - tangentxy_d2)
vt_startz = origz
# Generate steps
mcu_stepper = self.steppers[i].mcu_stepper
mcu_time = mcu_stepper.print_to_mcu_time(move_time)
step_delta = self.steppers[i].step_delta
move_time = print_time
if accel_d:
mcu_stepper.step_delta(
mcu_time, accel_d, move.start_v, accel,
step_delta(move_time, accel_d, move.start_v, accel,
vt_startz, vt_startxy_d, vt_arm_d, movez_r)
vt_startz += accel_d * movez_r
vt_startxy_d -= accel_d * movexy_r
mcu_time += move.accel_t
move_time += move.accel_t
if cruise_d:
mcu_stepper.step_delta(
mcu_time, cruise_d, cruise_v, 0.,
step_delta(move_time, cruise_d, cruise_v, 0.,
vt_startz, vt_startxy_d, vt_arm_d, movez_r)
vt_startz += cruise_d * movez_r
vt_startxy_d -= cruise_d * movexy_r
mcu_time += move.cruise_t
move_time += move.cruise_t
if decel_d:
mcu_stepper.step_delta(
mcu_time, decel_d, cruise_v, -accel,
step_delta(move_time, decel_d, cruise_v, -accel,
vt_startz, vt_startxy_d, vt_arm_d, movez_r)
# Helper functions for DELTA_CALIBRATE script
def get_stable_position(self):
return [int((ep - s.mcu_stepper.get_commanded_position())
/ s.mcu_stepper.get_step_dist() + .5)
* s.mcu_stepper.get_step_dist()
for ep, s in zip(self.endstops, self.steppers)]
def get_calibrate_params(self):
return {
'endstop_a': self.steppers[0].position_endstop,
'endstop_b': self.steppers[1].position_endstop,
'endstop_c': self.steppers[2].position_endstop,
'angle_a': self.angles[0], 'angle_b': self.angles[1],
'angle_c': self.angles[2], 'radius': self.radius,
'arm_a': self.arm_lengths[0], 'arm_b': self.arm_lengths[1],
'arm_c': self.arm_lengths[2] }
######################################################################
@@ -237,8 +237,49 @@ def matrix_dot(m1, m2):
def matrix_magsq(m1):
return m1[0]**2 + m1[1]**2 + m1[2]**2
def matrix_add(m1, m2):
return [m1[0] + m2[0], m1[1] + m2[1], m1[2] + m2[2]]
def matrix_sub(m1, m2):
return [m1[0] - m2[0], m1[1] - m2[1], m1[2] - m2[2]]
def matrix_mul(m1, s):
return [m1[0]*s, m1[1]*s, m1[2]*s]
def actuator_to_cartesian(towers, arm2, pos):
# Find nozzle position using trilateration (see wikipedia)
carriage1 = list(towers[0]) + [pos[0]]
carriage2 = list(towers[1]) + [pos[1]]
carriage3 = list(towers[2]) + [pos[2]]
s21 = matrix_sub(carriage2, carriage1)
s31 = matrix_sub(carriage3, carriage1)
d = math.sqrt(matrix_magsq(s21))
ex = matrix_mul(s21, 1. / d)
i = matrix_dot(ex, s31)
vect_ey = matrix_sub(s31, matrix_mul(ex, i))
ey = matrix_mul(vect_ey, 1. / math.sqrt(matrix_magsq(vect_ey)))
ez = matrix_cross(ex, ey)
j = matrix_dot(ey, s31)
x = (arm2[0] - arm2[1] + d**2) / (2. * d)
y = (arm2[0] - arm2[2] - x**2 + (x-i)**2 + j**2) / (2. * j)
z = -math.sqrt(arm2[0] - x**2 - y**2)
ex_x = matrix_mul(ex, x)
ey_y = matrix_mul(ey, y)
ez_z = matrix_mul(ez, z)
return matrix_add(carriage1, matrix_add(ex_x, matrix_add(ey_y, ez_z)))
def get_position_from_stable(spos, params):
angles = [params['angle_a'], params['angle_b'], params['angle_c']]
radius = params['radius']
radius2 = radius**2
towers = [(math.cos(angle) * radius, math.sin(angle) * radius)
for angle in map(math.radians, angles)]
arm2 = [a**2 for a in [params['arm_a'], params['arm_b'], params['arm_c']]]
endstops = [params['endstop_a'], params['endstop_b'], params['endstop_c']]
pos = [es + math.sqrt(a2 - radius2) - p
for es, a2, p in zip(endstops, arm2, spos)]
return actuator_to_cartesian(towers, arm2, pos)

View File

@@ -0,0 +1,5 @@
# Package definition for the extras directory
#
# Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.

32
klippy/extras/ad5206.py Normal file
View File

@@ -0,0 +1,32 @@
# AD5206 digipot code
#
# Copyright (C) 2017,2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import pins
class ad5206:
def __init__(self, config):
printer = config.get_printer()
enable_pin_params = pins.get_printer_pins(printer).lookup_pin(
'digital_out', config.get('enable_pin'))
if enable_pin_params['invert']:
raise pins.error("ad5206 can not invert pin")
self.mcu = enable_pin_params['chip']
self.pin = enable_pin_params['pin']
self.mcu.add_config_object(self)
scale = config.getfloat('scale', 1., above=0.)
self.channels = [None] * 6
for i in range(len(self.channels)):
val = config.getfloat('channel_%d' % (i+1,), None,
minval=0., maxval=scale)
if val is not None:
self.channels[i] = int(val * 256. / scale + .5)
def build_config(self):
for i, val in enumerate(self.channels):
if val is not None:
self.mcu.add_config_cmd(
"send_spi_message pin=%s msg=%02x%02x" % (self.pin, i, val))
def load_config_prefix(config):
return ad5206(config)

113
klippy/extras/bed_tilt.py Normal file
View File

@@ -0,0 +1,113 @@
# Bed tilt compensation
#
# Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging
import probe, mathutil
class BedTilt:
def __init__(self, config):
self.printer = config.get_printer()
self.x_adjust = config.getfloat('x_adjust', 0.)
self.y_adjust = config.getfloat('y_adjust', 0.)
if config.get('points', None) is not None:
BedTiltCalibrate(config, self)
self.toolhead = None
gcode = self.printer.lookup_object('gcode')
gcode.set_move_transform(self)
def printer_state(self, state):
if state == 'connect':
self.toolhead = self.printer.lookup_object('toolhead')
def get_position(self):
x, y, z, e = self.toolhead.get_position()
return [x, y, z - x*self.x_adjust - y*self.y_adjust, e]
def move(self, newpos, speed):
x, y, z, e = newpos
self.toolhead.move([x, y, z + x*self.x_adjust + y*self.y_adjust, e],
speed)
# Helper script to calibrate the bed tilt
class BedTiltCalibrate:
def __init__(self, config, bedtilt):
self.bedtilt = bedtilt
self.printer = config.get_printer()
points = config.get('points').split('\n')
try:
points = [line.split(',', 1) for line in points if line.strip()]
self.points = [(float(p[0].strip()), float(p[1].strip()))
for p in points]
except:
raise config.error("Unable to parse bed tilt points")
if len(self.points) < 3:
raise config.error("Need at least 3 points for bed_tilt_calibrate")
self.speed = config.getfloat('speed', 50., above=0.)
self.horizontal_move_z = config.getfloat('horizontal_move_z', 5.)
self.z_position_endstop = None
if config.has_section('stepper_z'):
zconfig = config.getsection('stepper_z')
self.z_position_endstop = zconfig.getfloat('position_endstop', None)
self.manual_probe = config.getboolean('manual_probe', None)
if self.manual_probe is None:
self.manual_probe = not config.has_section('probe')
self.gcode = self.printer.lookup_object('gcode')
self.gcode.register_command(
'BED_TILT_CALIBRATE', self.cmd_BED_TILT_CALIBRATE,
desc=self.cmd_BED_TILT_CALIBRATE_help)
cmd_BED_TILT_CALIBRATE_help = "Bed tilt calibration script"
def cmd_BED_TILT_CALIBRATE(self, params):
self.gcode.run_script("G28")
probe.ProbePointsHelper(
self.printer, self.points, self.horizontal_move_z,
self.speed, self.manual_probe, self)
def get_position(self):
kin = self.printer.lookup_object('toolhead').get_kinematics()
return kin.get_position()
def finalize(self, z_offset, positions):
logging.info("Calculating bed_tilt with: %s", positions)
params = { 'x_adjust': self.bedtilt.x_adjust,
'y_adjust': self.bedtilt.y_adjust,
'z_adjust': z_offset }
logging.info("Initial bed_tilt parameters: %s", params)
def adjusted_height(pos, params):
x, y, z = pos
return (z - x*params['x_adjust'] - y*params['y_adjust']
- params['z_adjust'])
def errorfunc(params):
total_error = 0.
for pos in positions:
total_error += adjusted_height(pos, params)**2
return total_error
new_params = mathutil.coordinate_descent(
params.keys(), params, errorfunc)
logging.info("Calculated bed_tilt parameters: %s", new_params)
for pos in positions:
logging.info("orig: %s new: %s", adjusted_height(pos, params),
adjusted_height(pos, new_params))
z_diff = new_params['z_adjust'] - z_offset
if self.z_position_endstop is not None:
# Cartesian style robot
z_extra = ""
probe = self.printer.lookup_object('probe', None)
if probe is not None:
last_home_position = probe.last_home_position()
if last_home_position is not None:
# Using z_virtual_endstop
home_x, home_y = last_home_position[:2]
z_diff -= home_x * new_params['x_adjust']
z_diff -= home_y * new_params['y_adjust']
z_extra = " (when Z homing at %.3f,%.3f)" % (home_x, home_y)
z_adjust = "stepper_z position_endstop: %.6f%s\n" % (
self.z_position_endstop - z_diff, z_extra)
else:
# Delta (or other) style robot
z_adjust = "Add %.6f to endstop position\n" % (-z_diff,)
msg = "%sx_adjust: %.6f y_adjust: %.6f" % (
z_adjust, new_params['x_adjust'], new_params['y_adjust'])
logging.info("bed_tilt_calibrate: %s", msg)
self.gcode.respond_info(
"%s\nTo use these parameters, update the printer config file with\n"
"the above and then issue a RESTART command" % (msg,))
def load_config(config):
return BedTilt(config)

View File

@@ -0,0 +1,73 @@
# Delta calibration support
#
# Copyright (C) 2017-2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import math, logging
import probe, delta, mathutil
class DeltaCalibrate:
def __init__(self, config):
self.printer = config.get_printer()
if config.getsection('printer').get('kinematics') != 'delta':
raise config.error("Delta calibrate is only for delta printers")
self.radius = config.getfloat('radius', above=0.)
self.speed = config.getfloat('speed', 50., above=0.)
self.horizontal_move_z = config.getfloat('horizontal_move_z', 5.)
self.manual_probe = config.getboolean('manual_probe', None)
if self.manual_probe is None:
self.manual_probe = not config.has_section('probe')
self.gcode = self.printer.lookup_object('gcode')
self.gcode.register_command(
'DELTA_CALIBRATE', self.cmd_DELTA_CALIBRATE,
desc=self.cmd_DELTA_CALIBRATE_help)
cmd_DELTA_CALIBRATE_help = "Delta calibration script"
def cmd_DELTA_CALIBRATE(self, params):
# Setup probe points
points = [(0., 0.)]
scatter = [.95, .90, .85, .70, .75, .80]
for i in range(6):
r = math.radians(90. + 60. * i)
dist = self.radius * scatter[i]
points.append((math.cos(r) * dist, math.sin(r) * dist))
# Probe them
self.gcode.run_script("G28")
probe.ProbePointsHelper(self.printer, points, self.horizontal_move_z,
self.speed, self.manual_probe, self)
def get_position(self):
kin = self.printer.lookup_object('toolhead').get_kinematics()
return kin.get_stable_position()
def finalize(self, z_offset, positions):
kin = self.printer.lookup_object('toolhead').get_kinematics()
logging.info("Calculating delta_calibrate with: %s", positions)
params = kin.get_calibrate_params()
logging.info("Initial delta_calibrate parameters: %s", params)
adj_params = ('endstop_a', 'endstop_b', 'endstop_c', 'radius',
'angle_a', 'angle_b')
def delta_errorfunc(params):
total_error = 0.
for spos in positions:
x, y, z = delta.get_position_from_stable(spos, params)
total_error += (z - z_offset)**2
return total_error
new_params = mathutil.coordinate_descent(
adj_params, params, delta_errorfunc)
logging.info("Calculated delta_calibrate parameters: %s", new_params)
for spos in positions:
logging.info("orig: %s new: %s",
delta.get_position_from_stable(spos, params),
delta.get_position_from_stable(spos, new_params))
self.gcode.respond_info(
"stepper_a: position_endstop: %.6f angle: %.6f\n"
"stepper_b: position_endstop: %.6f angle: %.6f\n"
"stepper_c: position_endstop: %.6f angle: %.6f\n"
"radius: %.6f\n"
"To use these parameters, update the printer config file with\n"
"the above and then issue a RESTART command" % (
new_params['endstop_a'], new_params['angle_a'],
new_params['endstop_b'], new_params['angle_b'],
new_params['endstop_c'], new_params['angle_c'],
new_params['radius']))
def load_config(config):
return DeltaCalibrate(config)

602
klippy/extras/display.py Normal file
View File

@@ -0,0 +1,602 @@
# Basic LCD display support
#
# Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net>
# Copyright (C) 2018 Aleph Objects, Inc <marcio@alephobjects.com>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging
BACKGROUND_PRIORITY_CLOCK = 0x7fffffff00000000
######################################################################
# HD44780 (20x4 text) lcd chip
######################################################################
HD44780_DELAY = .000037
class HD44780:
char_right_arrow = '\x7e'
char_thermometer = '\x00'
char_heater_bed = '\x01'
char_speed_factor = '\x02'
char_clock = '\x03'
char_degrees = '\x04'
def __init__(self, config):
self.printer = config.get_printer()
# pin config
ppins = self.printer.lookup_object('pins')
pins = [ppins.lookup_pin('digital_out', config.get(name + '_pin'))
for name in ['rs', 'e', 'd4', 'd5', 'd6', 'd7']]
mcu = None
for pin_params in pins:
if mcu is not None and pin_params['chip'] != mcu:
raise ppins.error("hd44780 all pins must be on same mcu")
mcu = pin_params['chip']
if pin_params['invert']:
raise ppins.error("hd44780 can not invert pin")
self.pins = [pin_params['pin'] for pin_params in pins]
self.mcu = mcu
self.oid = self.mcu.create_oid()
self.mcu.add_config_object(self)
self.send_data_cmd = self.send_cmds_cmd = None
# framebuffers
self.text_framebuffer = (bytearray(' '*80), bytearray('~'*80), 0x80)
self.glyph_framebuffer = (bytearray(64), bytearray('~'*64), 0x40)
self.framebuffers = [self.text_framebuffer, self.glyph_framebuffer]
def build_config(self):
self.mcu.add_config_cmd(
"config_hd44780 oid=%d rs_pin=%s e_pin=%s"
" d4_pin=%s d5_pin=%s d6_pin=%s d7_pin=%s delay_ticks=%d" % (
self.oid, self.pins[0], self.pins[1],
self.pins[2], self.pins[3], self.pins[4], self.pins[5],
self.mcu.seconds_to_clock(HD44780_DELAY)))
cmd_queue = self.mcu.alloc_command_queue()
self.send_cmds_cmd = self.mcu.lookup_command(
"hd44780_send_cmds oid=%c cmds=%*s", cq=cmd_queue)
self.send_data_cmd = self.mcu.lookup_command(
"hd44780_send_data oid=%c data=%*s", cq=cmd_queue)
def send(self, cmds, is_data=False):
cmd_type = self.send_cmds_cmd
if is_data:
cmd_type = self.send_data_cmd
cmd_type.send([self.oid, cmds], reqclock=BACKGROUND_PRIORITY_CLOCK)
#logging.debug("hd44780 %d %s", is_data, repr(cmds))
def flush(self):
# Find all differences in the framebuffers and send them to the chip
for new_data, old_data, fb_id in self.framebuffers:
if new_data == old_data:
continue
# Find the position of all changed bytes in this framebuffer
diffs = [[i, 1] for i, (nd, od) in enumerate(zip(new_data, old_data))
if nd != od]
# Batch together changes that are close to each other
for i in range(len(diffs)-2, -1, -1):
pos, count = diffs[i]
nextpos, nextcount = diffs[i+1]
if pos + 4 >= nextpos and nextcount < 16:
diffs[i][1] = nextcount + (nextpos - pos)
del diffs[i+1]
# Transmit changes
for pos, count in diffs:
chip_pos = pos
if fb_id == 0x80 and pos >= 40:
chip_pos += 0x40 - 40
self.send([fb_id + chip_pos])
self.send(new_data[pos:pos+count], is_data=True)
old_data[:] = new_data
def init(self):
curtime = self.printer.get_reactor().monotonic()
print_time = self.mcu.estimated_print_time(curtime)
# Program 4bit / 2-line mode and then issue 0x02 "Home" command
init = [[0x33], [0x33], [0x33, 0x22, 0x28, 0x02]]
# Reset (set positive direction ; enable display and hide cursor)
init.append([0x06, 0x0c])
for i, cmds in enumerate(init):
minclock = self.mcu.print_time_to_clock(print_time + i * .100)
self.send_cmds_cmd.send([self.oid, cmds], minclock=minclock)
# Add custom fonts
self.glyph_framebuffer[0][:len(HD44780_chars)] = HD44780_chars
for i in range(len(self.glyph_framebuffer[0])):
self.glyph_framebuffer[1][i] = self.glyph_framebuffer[0][i] ^ 1
self.flush()
def write_text(self, x, y, data):
if x + len(data) > 20:
data = data[:20 - min(x, 20)]
pos = [0, 40, 20, 60][y] + x
self.text_framebuffer[0][pos:pos+len(data)] = data
def clear(self):
self.text_framebuffer[0][:] = ' '*80
HD44780_chars = [
# Thermometer
0b00100,
0b01010,
0b01010,
0b01010,
0b01010,
0b10001,
0b10001,
0b01110,
# Heated bed
0b00000,
0b11111,
0b10101,
0b10001,
0b10101,
0b11111,
0b00000,
0b00000,
# Speed factor
0b11100,
0b10000,
0b11000,
0b10111,
0b00101,
0b00110,
0b00101,
0b00000,
# Clock
0b00000,
0b01110,
0b10011,
0b10101,
0b10001,
0b01110,
0b00000,
0b00000,
# Degrees
0b01100,
0b10010,
0b10010,
0b01100,
0b00000,
0b00000,
0b00000,
0b00000,
]
######################################################################
# ST7920 (128x64 graphics) lcd chip
######################################################################
ST7920_DELAY = .000020 # Spec says 72us, but faster is possible in practice
class ST7920:
char_right_arrow = '\x1a'
def __init__(self, config):
printer = config.get_printer()
# pin config
ppins = printer.lookup_object('pins')
pins = [ppins.lookup_pin('digital_out', config.get(name + '_pin'))
for name in ['cs', 'sclk', 'sid']]
mcu = None
for pin_params in pins:
if mcu is not None and pin_params['chip'] != mcu:
raise ppins.error("st7920 all pins must be on same mcu")
mcu = pin_params['chip']
if pin_params['invert']:
raise ppins.error("st7920 can not invert pin")
self.pins = [pin_params['pin'] for pin_params in pins]
self.mcu = mcu
self.oid = self.mcu.create_oid()
self.mcu.add_config_object(self)
self.send_data_cmd = self.send_cmds_cmd = None
self.is_extended = False
# framebuffers
self.text_framebuffer = (bytearray(' '*64), bytearray('~'*64), 0x80)
self.glyph_framebuffer = (bytearray(128), bytearray('~'*128), 0x40)
self.graphics_framebuffers = [(bytearray(32), bytearray('~'*32), i)
for i in range(32)]
self.framebuffers = ([self.text_framebuffer, self.glyph_framebuffer]
+ self.graphics_framebuffers)
def build_config(self):
self.mcu.add_config_cmd(
"config_st7920 oid=%u cs_pin=%s sclk_pin=%s sid_pin=%s"
" delay_ticks=%d" % (
self.oid, self.pins[0], self.pins[1], self.pins[2],
self.mcu.seconds_to_clock(ST7920_DELAY)))
cmd_queue = self.mcu.alloc_command_queue()
self.send_cmds_cmd = self.mcu.lookup_command(
"st7920_send_cmds oid=%c cmds=%*s", cq=cmd_queue)
self.send_data_cmd = self.mcu.lookup_command(
"st7920_send_data oid=%c data=%*s", cq=cmd_queue)
def send(self, cmds, is_data=False, is_extended=False):
cmd_type = self.send_cmds_cmd
if is_data:
cmd_type = self.send_data_cmd
elif self.is_extended != is_extended:
add_cmd = 0x22
if is_extended:
add_cmd = 0x26
cmds = [add_cmd] + cmds
self.is_extended = is_extended
cmd_type.send([self.oid, cmds], reqclock=BACKGROUND_PRIORITY_CLOCK)
#logging.debug("st7920 %d %s", is_data, repr(cmds))
def flush(self):
# Find all differences in the framebuffers and send them to the chip
for new_data, old_data, fb_id in self.framebuffers:
if new_data == old_data:
continue
# Find the position of all changed bytes in this framebuffer
diffs = [[i, 1] for i, (nd, od) in enumerate(zip(new_data, old_data))
if nd != od]
# Batch together changes that are close to each other
for i in range(len(diffs)-2, -1, -1):
pos, count = diffs[i]
nextpos, nextcount = diffs[i+1]
if pos + 5 >= nextpos and nextcount < 16:
diffs[i][1] = nextcount + (nextpos - pos)
del diffs[i+1]
# Transmit changes
for pos, count in diffs:
count += pos & 0x01
count += count & 0x01
pos = pos & ~0x01
chip_pos = pos >> 1
if fb_id < 0x40:
# Graphics framebuffer update
self.send([0x80 + fb_id, 0x80 + chip_pos], is_extended=True)
else:
self.send([fb_id + chip_pos])
self.send(new_data[pos:pos+count], is_data=True)
old_data[:] = new_data
def init(self):
cmds = [0x24, # Enter extended mode
0x40, # Clear vertical scroll address
0x02, # Enable CGRAM access
0x26, # Enable graphics
0x22, # Leave extended mode
0x02, # Home the display
0x06, # Set positive update direction
0x0c] # Enable display and hide cursor
self.send(cmds)
self.flush()
def load_glyph(self, glyph_id, data):
if len(data) > 32:
data = data[:32]
pos = min(glyph_id * 32, 96)
self.glyph_framebuffer[0][pos:pos+len(data)] = data
def write_text(self, x, y, data):
if x + len(data) > 16:
data = data[:16 - min(x, 16)]
pos = [0, 32, 16, 48][y] + x
self.text_framebuffer[0][pos:pos+len(data)] = data
def write_graphics(self, x, y, row, data):
if x + len(data) > 16:
data = data[:16 - min(x, 16)]
gfx_fb = y * 16 + row
if gfx_fb >= 32:
gfx_fb -= 32
x += 16
self.graphics_framebuffers[gfx_fb][0][x:x+len(data)] = data
def clear(self):
self.text_framebuffer[0][:] = ' '*64
zeros = bytearray(32)
for new_data, old_data, fb_id in self.graphics_framebuffers:
new_data[:] = zeros
######################################################################
# Icons
######################################################################
nozzle_icon = [
0b0000000000000000,
0b0000000000000000,
0b0000111111110000,
0b0001111111111000,
0b0001111111111000,
0b0001111111111000,
0b0000111111110000,
0b0000111111110000,
0b0001111111111000,
0b0001111111111000,
0b0001111111111000,
0b0000011111100000,
0b0000001111000000,
0b0000000110000000,
0b0000000000000000,
0b0000000000000000
]
bed_icon = [
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0111111111111110,
0b0111111111111110,
0b0000000000000000,
0b0000000000000000
]
heat1_icon = [
0b0000000000000000,
0b0000000000000000,
0b0010001000100000,
0b0001000100010000,
0b0000100010001000,
0b0000100010001000,
0b0001000100010000,
0b0010001000100000,
0b0010001000100000,
0b0001000100010000,
0b0000100010001000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000
]
heat2_icon = [
0b0000000000000000,
0b0000000000000000,
0b0000100010001000,
0b0000100010001000,
0b0001000100010000,
0b0010001000100000,
0b0010001000100000,
0b0001000100010000,
0b0000100010001000,
0b0000100010001000,
0b0001000100010000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000
]
fan1_icon = [
0b0000000000000000,
0b0111111111111110,
0b0111000000001110,
0b0110001111000110,
0b0100001111000010,
0b0100000110000010,
0b0101100000011010,
0b0101110110111010,
0b0101100000011010,
0b0100000110000010,
0b0100001111000010,
0b0110001111000110,
0b0111000000001110,
0b0111111111111110,
0b0000000000000000,
0b0000000000000000
]
fan2_icon = [
0b0000000000000000,
0b0111111111111110,
0b0111000000001110,
0b0110010000100110,
0b0100111001110010,
0b0101111001111010,
0b0100110000110010,
0b0100000110000010,
0b0100110000110010,
0b0101111001111010,
0b0100111001110010,
0b0110010000100110,
0b0111000000001110,
0b0111111111111110,
0b0000000000000000,
0b0000000000000000
]
feedrate_icon = [
0b0000000000000000,
0b0111111000000000,
0b0100000000000000,
0b0100000000000000,
0b0100000000000000,
0b0111111011111000,
0b0100000010000100,
0b0100000010000100,
0b0100000010000100,
0b0100000011111000,
0b0000000010001000,
0b0000000010000100,
0b0000000010000100,
0b0000000010000010,
0b0000000000000000,
0b0000000000000000
]
######################################################################
# LCD screen updates
######################################################################
LCD_chips = { 'st7920': ST7920, 'hd44780': HD44780 }
class PrinterLCD:
def __init__(self, config):
self.printer = config.get_printer()
self.reactor = self.printer.get_reactor()
self.lcd_chip = config.getchoice('lcd_type', LCD_chips)(config)
self.lcd_type = config.get('lcd_type')
# printer objects
self.gcode = self.toolhead = self.sdcard = None
self.fan = self.extruder0 = self.extruder1 = self.heater_bed = None
# screen updating
self.screen_update_timer = self.reactor.register_timer(
self.screen_update_event)
# Initialization
FAN1_GLYPH, FAN2_GLYPH, BED1_GLYPH, BED2_GLYPH = 0, 1, 2, 3
def printer_state(self, state):
if state == 'ready':
self.lcd_chip.init()
# Load printer objects
self.gcode = self.printer.lookup_object('gcode')
self.toolhead = self.printer.lookup_object('toolhead')
self.sdcard = self.printer.lookup_object('virtual_sdcard', None)
self.fan = self.printer.lookup_object('fan', None)
self.extruder0 = self.printer.lookup_object('extruder0', None)
self.extruder1 = self.printer.lookup_object('extruder1', None)
self.heater_bed = self.printer.lookup_object('heater_bed', None)
# Load glyphs
self.load_glyph(self.BED1_GLYPH, heat1_icon)
self.load_glyph(self.BED2_GLYPH, heat2_icon)
self.load_glyph(self.FAN1_GLYPH, fan1_icon)
self.load_glyph(self.FAN2_GLYPH, fan2_icon)
# Start screen update timer
self.reactor.update_timer(self.screen_update_timer, self.reactor.NOW)
# ST7920 Glyphs
def load_glyph(self, glyph_id, data):
if self.lcd_type != 'st7920':
return
glyph = [0x00] * (len(data) * 2)
for i, bits in enumerate(data):
glyph[i*2] = (bits >> 8) & 0xff
glyph[i*2 + 1] = bits & 0xff
return self.lcd_chip.load_glyph(glyph_id, glyph)
def animate_glyphs(self, eventtime, x, y, glyph_id, do_animate):
frame = do_animate and int(eventtime) & 1
self.lcd_chip.write_text(x, y, (0, (glyph_id + frame)*2))
# Graphics drawing
def draw_icon(self, x, y, data):
for i, bits in enumerate(data):
self.lcd_chip.write_graphics(
x, y, i, [(bits >> 8) & 0xff, bits & 0xff])
def draw_progress_bar(self, x, y, width, value):
value = int(value * 100.)
data = [0x00] * width
char_pcnt = int(100/width)
for i in range(width):
if (i+1)*char_pcnt <= value:
# Draw completely filled bytes
data[i] |= 0xFF
elif (i*char_pcnt) < value:
# Draw partially filled bytes
data[i] |= (-1 << 8-((value % char_pcnt)*8/char_pcnt)) & 0xff
data[0] |= 0x80
data[-1] |= 0x01
self.lcd_chip.write_graphics(x, y, 0, [0xff]*width)
for i in range(1, 15):
self.lcd_chip.write_graphics(x, y, i, data)
self.lcd_chip.write_graphics(x, y, 15, [0xff]*width)
# Screen updating
def screen_update_event(self, eventtime):
self.lcd_chip.clear()
if self.lcd_type == 'hd44780':
self.screen_update_hd44780(eventtime)
else:
self.screen_update_st7920(eventtime)
self.lcd_chip.flush()
return eventtime + .500
def screen_update_hd44780(self, eventtime):
lcd_chip = self.lcd_chip
# Heaters
if self.extruder0 is not None:
info = self.extruder0.get_heater().get_status(eventtime)
lcd_chip.write_text(0, 0, lcd_chip.char_thermometer)
self.draw_heater(1, 0, info)
if self.extruder1 is not None:
info = self.extruder1.get_heater().get_status(eventtime)
lcd_chip.write_text(0, 1, lcd_chip.char_thermometer)
self.draw_heater(1, 1, info)
if self.heater_bed is not None:
info = self.heater_bed.get_status(eventtime)
lcd_chip.write_text(10, 0, lcd_chip.char_heater_bed)
self.draw_heater(11, 0, info)
# Fan speed
if self.fan is not None:
info = self.fan.get_status(eventtime)
lcd_chip.write_text(10, 1, "Fan")
self.draw_percent(14, 1, 4, info['speed'])
# G-Code speed factor
gcode_info = self.gcode.get_status(eventtime)
lcd_chip.write_text(0, 2, lcd_chip.char_speed_factor)
self.draw_percent(1, 2, 4, gcode_info['speed_factor'])
# SD card print progress
if self.sdcard is not None:
info = self.sdcard.get_status(eventtime)
lcd_chip.write_text(7, 2, "SD")
self.draw_percent(9, 2, 4, info['progress'])
# Printing time and status
toolhead_info = self.toolhead.get_status(eventtime)
lcd_chip.write_text(14, 2, lcd_chip.char_clock)
self.draw_time(15, 2, toolhead_info['printing_time'])
self.draw_status(0, 3, gcode_info, toolhead_info)
def screen_update_st7920(self, eventtime):
# Heaters
if self.extruder0 is not None:
info = self.extruder0.get_heater().get_status(eventtime)
self.draw_icon(0, 0, nozzle_icon)
self.draw_heater(2, 0, info)
extruder_count = 1
if self.extruder1 is not None:
info = self.extruder1.get_heater().get_status(eventtime)
self.draw_icon(0, 1, nozzle_icon)
self.draw_heater(2, 1, info)
extruder_count = 2
if self.heater_bed is not None:
info = self.heater_bed.get_status(eventtime)
self.draw_icon(0, extruder_count, bed_icon)
if info['target']:
self.animate_glyphs(eventtime, 0, extruder_count,
self.BED1_GLYPH, True)
self.draw_heater(2, extruder_count, info)
# Fan speed
if self.fan is not None:
info = self.fan.get_status(eventtime)
self.animate_glyphs(eventtime, 10, 0, self.FAN1_GLYPH,
info['speed'] != 0.)
self.draw_percent(12, 0, 4, info['speed'])
# SD card print progress
if self.sdcard is not None:
info = self.sdcard.get_status(eventtime)
if extruder_count == 1:
x, y, width = 0, 2, 10
else:
x, y, width = 10, 1, 6
self.draw_percent(x, y, width, info['progress'])
self.draw_progress_bar(x, y, width, info['progress'])
# G-Code speed factor
gcode_info = self.gcode.get_status(eventtime)
if extruder_count == 1:
self.draw_icon(10, 1, feedrate_icon)
self.draw_percent(12, 1, 4, gcode_info['speed_factor'])
# Printing time and status
toolhead_info = self.toolhead.get_status(eventtime)
self.draw_time(10, 2, toolhead_info['printing_time'])
self.draw_status(0, 3, gcode_info, toolhead_info)
# Screen update helpers
def draw_heater(self, x, y, info):
temperature, target = info['temperature'], info['target']
if target and abs(temperature - target) > 2.:
s = "%3.0f%s%.0f" % (
temperature, self.lcd_chip.char_right_arrow, target)
else:
s = "%3.0f" % (temperature,)
if self.lcd_type == 'hd44780':
s += self.lcd_chip.char_degrees
self.lcd_chip.write_text(x, y, s)
def draw_percent(self, x, y, width, value):
self.lcd_chip.write_text(x, y, ("%d%%" % (value * 100.,)).center(width))
def draw_time(self, x, y, seconds):
seconds = int(seconds)
self.lcd_chip.write_text(x, y, "%02d:%02d" % (
seconds // (60 * 60), (seconds // 60) % 60))
def draw_status(self, x, y, gcode_info, toolhead_info):
status = toolhead_info['status']
if status == 'Printing' or gcode_info['busy']:
pos = self.toolhead.get_position()
status = "X%-4.0fY%-4.0fZ%-5.2f" % (pos[0], pos[1], pos[2])
self.lcd_chip.write_text(x, y, status)
def load_config(config):
return PrinterLCD(config)

39
klippy/extras/fan.py Normal file
View File

@@ -0,0 +1,39 @@
# Printer cooling fan
#
# Copyright (C) 2016-2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import pins
FAN_MIN_TIME = 0.100
class PrinterFan:
def __init__(self, config):
self.last_fan_value = 0.
self.last_fan_time = 0.
self.max_power = config.getfloat('max_power', 1., above=0., maxval=1.)
self.kick_start_time = config.getfloat('kick_start_time', 0.1, minval=0.)
printer = config.get_printer()
self.mcu_fan = pins.setup_pin(printer, 'pwm', config.get('pin'))
self.mcu_fan.setup_max_duration(0.)
cycle_time = config.getfloat('cycle_time', 0.010, above=0.)
hardware_pwm = config.getboolean('hardware_pwm', False)
self.mcu_fan.setup_cycle_time(cycle_time, hardware_pwm)
def set_speed(self, print_time, value):
value = max(0., min(self.max_power, value))
if value == self.last_fan_value:
return
print_time = max(self.last_fan_time + FAN_MIN_TIME, print_time)
if (value and value < self.max_power
and not self.last_fan_value and self.kick_start_time):
# Run fan at full speed for specified kick_start_time
self.mcu_fan.set_pwm(print_time, self.max_power)
print_time += self.kick_start_time
self.mcu_fan.set_pwm(print_time, value)
self.last_fan_time = print_time
self.last_fan_value = value
def get_status(self, eventtime):
return {'speed': self.last_fan_value}
def load_config(config):
return PrinterFan(config)

View File

@@ -0,0 +1,37 @@
# Support fans that are enabled when a heater is on
#
# Copyright (C) 2016-2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import fan, extruder
PIN_MIN_TIME = 0.100
class PrinterHeaterFan:
def __init__(self, config):
self.printer = config.get_printer()
self.heater_name = config.get("heater", "extruder0")
self.heater_temp = config.getfloat("heater_temp", 50.0)
self.fan = fan.PrinterFan(config)
self.mcu = self.fan.mcu_fan.get_mcu()
max_power = self.fan.max_power
self.fan_speed = config.getfloat(
"fan_speed", max_power, minval=0., maxval=max_power)
self.fan.mcu_fan.setup_start_value(0., max_power)
def printer_state(self, state):
if state == 'ready':
self.heater = extruder.get_printer_heater(
self.printer, self.heater_name)
reactor = self.printer.get_reactor()
reactor.register_timer(self.callback, reactor.NOW)
def callback(self, eventtime):
current_temp, target_temp = self.heater.get_temp(eventtime)
power = 0.
if target_temp or current_temp > self.heater_temp:
power = self.fan_speed
print_time = self.mcu.estimated_print_time(eventtime) + PIN_MIN_TIME
self.fan.set_speed(print_time, power)
return eventtime + 1.
def load_config_prefix(config):
return PrinterHeaterFan(config)

View File

@@ -0,0 +1,39 @@
# Run user defined actions in place of a normal G28 homing command
#
# Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
class HomingOverride:
def __init__(self, config):
self.printer = config.get_printer()
self.start_pos = [config.getfloat('set_position_' + a, None)
for a in 'xyz']
self.script = config.get('gcode')
self.in_script = False
self.gcode = self.printer.lookup_object('gcode')
self.gcode.register_command("G28", self.cmd_G28)
def cmd_G28(self, params):
if self.in_script:
# Was called recursively - invoke the real G28 command
self.gcode.cmd_G28(params)
return
# Calculate forced position (if configured)
toolhead = self.printer.lookup_object('toolhead')
pos = toolhead.get_position()
homing_axes = []
for axis, loc in enumerate(self.start_pos):
if loc is not None:
pos[axis] = loc
homing_axes.append(axis)
toolhead.set_position(pos, homing_axes=homing_axes)
self.gcode.reset_last_position()
# Perform homing
try:
self.in_script = True
self.gcode.run_script(self.script)
finally:
self.in_script = False
def load_config(config):
return HomingOverride(config)

View File

@@ -0,0 +1,54 @@
# Virtual pin that propagates its changes to multiple output pins
#
# Copyright (C) 2017,2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import pins
class PrinterMultiPin:
def __init__(self, config):
self.printer = config.get_printer()
try:
pins.get_printer_pins(self.printer).register_chip('multi_pin', self)
except pins.error:
pass
self.pin_type = None
self.pin_list = [pin.strip() for pin in config.get('pins').split(',')]
self.mcu_pins = []
def setup_pin(self, pin_params):
pin_name = pin_params['pin']
pin = self.printer.lookup_object('multi_pin ' + pin_name, None)
if pin is not self:
if pin is None:
raise pins.error("multi_pin %s not configured" % (pin_name,))
return pin.setup_pin(pin_params)
if self.pin_type is not None:
raise pins.error("Can't setup multi_pin %s twice" % (pin_name,))
self.pin_type = pin_params['type']
invert = ""
if pin_params['invert']:
invert = "!"
self.mcu_pins = [
pins.setup_pin(self.printer, self.pin_type, invert + pin_desc)
for pin_desc in self.pin_list]
return self
def get_mcu(self):
return self.mcu_pins[0].get_mcu()
def setup_max_duration(self, max_duration):
for mcu_pin in self.mcu_pins:
mcu_pin.setup_max_duration(max_duration)
def setup_start_value(self, start_value, shutdown_value):
for mcu_pin in self.mcu_pins:
mcu_pin.setup_start_value(start_value, shutdown_value)
def setup_cycle_time(self, cycle_time, hardware_pwm=False):
for mcu_pin in self.mcu_pins:
mcu_pin.setup_cycle_time(cycle_time, hardware_pwm)
def set_digital(self, print_time, value):
for mcu_pin in self.mcu_pins:
mcu_pin.set_digital(print_time, value)
def set_pwm(self, print_time, value):
for mcu_pin in self.mcu_pins:
mcu_pin.set_pwm(print_time, value)
def load_config_prefix(config):
return PrinterMultiPin(config)

View File

@@ -0,0 +1,69 @@
# Code to configure miscellaneous chips
#
# Copyright (C) 2017,2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
PIN_MIN_TIME = 0.100
class PrinterOutputPin:
def __init__(self, config):
self.printer = config.get_printer()
ppins = self.printer.lookup_object('pins')
self.is_pwm = config.getboolean('pwm', False)
if self.is_pwm:
self.mcu_pin = ppins.setup_pin('pwm', config.get('pin'))
cycle_time = config.getfloat('cycle_time', 0.100, above=0.)
hardware_pwm = config.getboolean('hardware_pwm', False)
self.mcu_pin.setup_cycle_time(cycle_time, hardware_pwm)
self.scale = config.getfloat('scale', 1., above=0.)
else:
self.mcu_pin = ppins.setup_pin('digital_out', config.get('pin'))
self.scale = 1.
self.mcu_pin.setup_max_duration(0.)
self.last_value_time = 0.
static_value = config.getfloat('static_value', None,
minval=0., maxval=self.scale)
if static_value is not None:
self.is_static = True
self.last_value = static_value / self.scale
self.mcu_pin.setup_start_value(
self.last_value, self.last_value, True)
else:
self.is_static = False
self.last_value = config.getfloat(
'value', 0., minval=0., maxval=self.scale) / self.scale
shutdown_value = config.getfloat(
'shutdown_value', 0., minval=0., maxval=self.scale) / self.scale
self.mcu_pin.setup_start_value(self.last_value, shutdown_value)
self.gcode = self.printer.lookup_object('gcode')
self.gcode.register_command("SET_PIN", self.cmd_SET_PIN,
desc=self.cmd_SET_PIN_help)
cmd_SET_PIN_help = "Set the value of an output pin"
def cmd_SET_PIN(self, params):
pin_name = self.gcode.get_str('PIN', params)
pin = self.printer.lookup_object('output_pin ' + pin_name, None)
if pin is not self:
if pin is None:
raise self.gcode.error("Pin not configured")
return pin.cmd_SET_PIN(params)
if self.is_static:
raise self.gcode.error("Static pin can not be changed at run-time")
value = self.gcode.get_float('VALUE', params) / self.scale
if value == self.last_value:
return
print_time = self.printer.lookup_object('toolhead').get_last_move_time()
print_time = max(print_time, self.last_value_time + PIN_MIN_TIME)
if self.is_pwm:
if value < 0. or value > 1.:
raise self.gcode.error("Invalid pin value")
self.mcu_pin.set_pwm(print_time, value)
else:
if value not in [0., 1.]:
raise self.gcode.error("Invalid pin value")
self.mcu_pin.set_digital(print_time, value)
self.last_value = value
self.last_value_time = print_time
def load_config_prefix(config):
return PrinterOutputPin(config)

View File

@@ -0,0 +1,127 @@
# Calibration of heater PID settings
#
# Copyright (C) 2016-2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import math, logging
import extruder, heater
class PIDCalibrate:
def __init__(self, config):
self.printer = config.get_printer()
self.gcode = self.printer.lookup_object('gcode')
self.gcode.register_command(
'PID_CALIBRATE', self.cmd_PID_CALIBRATE,
desc=self.cmd_PID_CALIBRATE_help)
cmd_PID_CALIBRATE_help = "Run PID calibration test"
def cmd_PID_CALIBRATE(self, params):
heater_name = self.gcode.get_str('HEATER', params)
target = self.gcode.get_float('TARGET', params)
write_file = self.gcode.get_int('WRITE_FILE', params, 0)
try:
heater = extruder.get_printer_heater(self.printer, heater_name)
except self.printer.config_error as e:
raise self.gcode.error(str(e))
print_time = self.printer.lookup_object('toolhead').get_last_move_time()
calibrate = ControlAutoTune(heater)
old_control = heater.set_control(calibrate)
try:
heater.set_temp(print_time, target)
except heater.error as e:
raise self.gcode.error(str(e))
self.gcode.bg_temp(heater)
heater.set_control(old_control)
if write_file:
calibrate.write_file('/tmp/heattest.txt')
Kp, Ki, Kd = calibrate.calc_final_pid()
logging.info("Autotune: final: Kp=%f Ki=%f Kd=%f", Kp, Ki, Kd)
self.gcode.respond_info(
"PID parameters: pid_Kp=%.3f pid_Ki=%.3f pid_Kd=%.3f\n"
"To use these parameters, update the printer config file with\n"
"the above and then issue a RESTART command" % (Kp, Ki, Kd))
TUNE_PID_DELTA = 5.0
class ControlAutoTune:
def __init__(self, heater):
self.heater = heater
# Heating control
self.heating = False
self.peak = 0.
self.peak_time = 0.
# Peak recording
self.peaks = []
# Sample recording
self.last_pwm = 0.
self.pwm_samples = []
self.temp_samples = []
# Heater control
def set_pwm(self, read_time, value):
if value != self.last_pwm:
self.pwm_samples.append((read_time + heater.PWM_DELAY, value))
self.last_pwm = value
self.heater.set_pwm(read_time, value)
def adc_callback(self, read_time, temp):
self.temp_samples.append((read_time, temp))
if self.heating and temp >= self.heater.target_temp:
self.heating = False
self.check_peaks()
elif (not self.heating
and temp <= self.heater.target_temp - TUNE_PID_DELTA):
self.heating = True
self.check_peaks()
if self.heating:
self.set_pwm(read_time, self.heater.max_power)
if temp < self.peak:
self.peak = temp
self.peak_time = read_time
else:
self.set_pwm(read_time, 0.)
if temp > self.peak:
self.peak = temp
self.peak_time = read_time
def check_busy(self, eventtime):
if self.heating or len(self.peaks) < 12:
return True
return False
# Analysis
def check_peaks(self):
self.peaks.append((self.peak, self.peak_time))
if self.heating:
self.peak = 9999999.
else:
self.peak = -9999999.
if len(self.peaks) < 4:
return
self.calc_pid(len(self.peaks)-1)
def calc_pid(self, pos):
temp_diff = self.peaks[pos][0] - self.peaks[pos-1][0]
time_diff = self.peaks[pos][1] - self.peaks[pos-2][1]
max_power = self.heater.max_power
Ku = 4. * (2. * max_power) / (abs(temp_diff) * math.pi)
Tu = time_diff
Ti = 0.5 * Tu
Td = 0.125 * Tu
Kp = 0.6 * Ku * heater.PID_PARAM_BASE
Ki = Kp / Ti
Kd = Kp * Td
logging.info("Autotune: raw=%f/%f Ku=%f Tu=%f Kp=%f Ki=%f Kd=%f",
temp_diff, max_power, Ku, Tu, Kp, Ki, Kd)
return Kp, Ki, Kd
def calc_final_pid(self):
cycle_times = [(self.peaks[pos][1] - self.peaks[pos-2][1], pos)
for pos in range(4, len(self.peaks))]
midpoint_pos = sorted(cycle_times)[len(cycle_times)/2][1]
return self.calc_pid(midpoint_pos)
# Offline analysis helper
def write_file(self, filename):
pwm = ["pwm: %.3f %.3f" % (time, value)
for time, value in self.pwm_samples]
out = ["%.3f %.3f" % (time, temp) for time, temp in self.temp_samples]
f = open(filename, "wb")
f.write('\n'.join(pwm + out))
f.close()
def load_config(config):
return PIDCalibrate(config)

189
klippy/extras/probe.py Normal file
View File

@@ -0,0 +1,189 @@
# Z-Probe support
#
# Copyright (C) 2017-2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import pins, homing
HINT_TIMEOUT = """
Make sure to home the printer before probing. If the probe
did not move far enough to trigger, then consider reducing
the Z axis minimum position so the probe can travel further
(the Z minimum position can be negative).
"""
class PrinterProbe:
def __init__(self, config):
self.printer = config.get_printer()
self.speed = config.getfloat('speed', 5.0)
self.z_offset = config.getfloat('z_offset')
# Infer Z position to move to during a probe
if config.has_section('stepper_z'):
zconfig = config.getsection('stepper_z')
self.z_position = zconfig.getfloat('position_min', 0.)
else:
pconfig = config.getsection('printer')
self.z_position = pconfig.getfloat('minimum_z_position', 0.)
# Create an "endstop" object to handle the probe pin
ppins = self.printer.lookup_object('pins')
pin_params = ppins.lookup_pin('endstop', config.get('pin'))
mcu = pin_params['chip']
mcu.add_config_object(self)
self.mcu_probe = mcu.setup_pin(pin_params)
if (config.get('activate_gcode', None) is not None or
config.get('deactivate_gcode', None) is not None):
self.mcu_probe = ProbeEndstopWrapper(config, self.mcu_probe)
# Create z_virtual_endstop pin
ppins.register_chip('probe', self)
self.z_virtual_endstop = None
# Register PROBE/QUERY_PROBE commands
self.gcode = self.printer.lookup_object('gcode')
self.gcode.register_command(
'PROBE', self.cmd_PROBE, desc=self.cmd_PROBE_help)
self.gcode.register_command(
'QUERY_PROBE', self.cmd_QUERY_PROBE, desc=self.cmd_QUERY_PROBE_help)
def build_config(self):
toolhead = self.printer.lookup_object('toolhead')
z_steppers = toolhead.get_kinematics().get_steppers("Z")
for s in z_steppers:
for mcu_endstop, name in s.get_endstops():
for mcu_stepper in mcu_endstop.get_steppers():
self.mcu_probe.add_stepper(mcu_stepper)
def setup_pin(self, pin_params):
if (pin_params['pin'] != 'z_virtual_endstop'
or pin_params['type'] != 'endstop'):
raise pins.error("Probe virtual endstop only useful as endstop pin")
if pin_params['invert'] or pin_params['pullup']:
raise pins.error("Can not pullup/invert probe virtual endstop")
self.z_virtual_endstop = ProbeVirtualEndstop(
self.printer, self.mcu_probe)
return self.z_virtual_endstop
def last_home_position(self):
if self.z_virtual_endstop is None:
return None
return self.z_virtual_endstop.position
cmd_PROBE_help = "Probe Z-height at current XY position"
def cmd_PROBE(self, params):
toolhead = self.printer.lookup_object('toolhead')
homing_state = homing.Homing(toolhead)
pos = toolhead.get_position()
pos[2] = self.z_position
try:
homing_state.homing_move(
pos, [(self.mcu_probe, "probe")], self.speed, probe_pos=True)
except homing.EndstopError as e:
reason = str(e)
if "Timeout during endstop homing" in reason:
reason += HINT_TIMEOUT
raise self.gcode.error(reason)
self.gcode.reset_last_position()
cmd_QUERY_PROBE_help = "Return the status of the z-probe"
def cmd_QUERY_PROBE(self, params):
toolhead = self.printer.lookup_object('toolhead')
print_time = toolhead.get_last_move_time()
self.mcu_probe.query_endstop(print_time)
res = self.mcu_probe.query_endstop_wait()
self.gcode.respond_info(
"probe: %s" % (["open", "TRIGGERED"][not not res],))
# Endstop wrapper that enables running g-code scripts on setup
class ProbeEndstopWrapper:
def __init__(self, config, mcu_endstop):
self.mcu_endstop = mcu_endstop
self.gcode = config.get_printer().lookup_object('gcode')
self.activate_gcode = config.get('activate_gcode', "")
self.deactivate_gcode = config.get('deactivate_gcode', "")
# Wrappers
self.get_mcu = self.mcu_endstop.get_mcu
self.add_stepper = self.mcu_endstop.add_stepper
self.get_steppers = self.mcu_endstop.get_steppers
self.home_start = self.mcu_endstop.home_start
self.home_wait = self.mcu_endstop.home_wait
self.query_endstop = self.mcu_endstop.query_endstop
self.query_endstop_wait = self.mcu_endstop.query_endstop_wait
self.TimeoutError = self.mcu_endstop.TimeoutError
def home_prepare(self):
self.gcode.run_script(self.activate_gcode)
self.mcu_endstop.home_prepare()
def home_finalize(self):
self.gcode.run_script(self.deactivate_gcode)
self.mcu_endstop.home_finalize()
# Wrapper that records the last XY position of a virtual endstop probe
class ProbeVirtualEndstop:
def __init__(self, printer, mcu_endstop):
self.printer = printer
self.mcu_endstop = mcu_endstop
self.position = None
# Wrappers
self.get_mcu = self.mcu_endstop.get_mcu
self.add_stepper = self.mcu_endstop.add_stepper
self.get_steppers = self.mcu_endstop.get_steppers
self.home_start = self.mcu_endstop.home_start
self.home_wait = self.mcu_endstop.home_wait
self.query_endstop = self.mcu_endstop.query_endstop
self.query_endstop_wait = self.mcu_endstop.query_endstop_wait
self.home_prepare = self.mcu_endstop.home_prepare
self.TimeoutError = self.mcu_endstop.TimeoutError
def home_finalize(self):
self.position = self.printer.lookup_object('toolhead').get_position()
self.mcu_endstop.home_finalize()
# Helper code that can probe a series of points and report the
# position at each point.
class ProbePointsHelper:
def __init__(self, printer, probe_points, horizontal_move_z, speed,
manual_probe, callback):
self.printer = printer
self.probe_points = probe_points
self.horizontal_move_z = horizontal_move_z
self.speed = speed
self.manual_probe = manual_probe
self.callback = callback
self.toolhead = self.printer.lookup_object('toolhead')
self.results = []
self.busy = True
self.gcode = self.printer.lookup_object('gcode')
self.gcode.register_command(
'NEXT', self.cmd_NEXT, desc=self.cmd_NEXT_help)
# Begin probing
self.move_next()
if not manual_probe:
while self.busy:
self.gcode.run_script("PROBE")
self.cmd_NEXT({})
def move_next(self):
x, y = self.probe_points[len(self.results)]
curpos = self.toolhead.get_position()
curpos[0] = x
curpos[1] = y
curpos[2] = self.horizontal_move_z
self.toolhead.move(curpos, self.speed)
self.gcode.reset_last_position()
cmd_NEXT_help = "Move to the next XY position to probe"
def cmd_NEXT(self, params):
# Record current position
self.toolhead.wait_moves()
self.results.append(self.callback.get_position())
# Move to next position
curpos = self.toolhead.get_position()
curpos[2] = self.horizontal_move_z
self.toolhead.move(curpos, self.speed)
if len(self.results) == len(self.probe_points):
self.toolhead.get_last_move_time()
self.finalize(True)
return
self.move_next()
def finalize(self, success):
self.busy = False
self.gcode.reset_last_position()
self.gcode.register_command('NEXT', None)
if success:
z_offset = 0.
if not self.manual_probe:
probe = self.printer.lookup_object('probe')
z_offset = probe.z_offset
self.callback.finalize(z_offset, self.results)
def load_config(config):
return PrinterProbe(config)

229
klippy/extras/replicape.py Normal file
View File

@@ -0,0 +1,229 @@
# Code to configure miscellaneous chips
#
# Copyright (C) 2017,2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging
import pins, mcu
REPLICAPE_MAX_CURRENT = 3.84
REPLICAPE_SHIFT_REGISTER_BUS = 1
REPLICAPE_SHIFT_REGISTER_DEVICE = 1
REPLICAPE_PCA9685_BUS = 2
REPLICAPE_PCA9685_ADDRESS = 0x70
REPLICAPE_PCA9685_CYCLE_TIME = .001
PIN_MIN_TIME = 0.100
class pca9685_pwm:
def __init__(self, replicape, channel, pin_params):
self._replicape = replicape
self._channel = channel
if pin_params['type'] not in ['digital_out', 'pwm']:
raise pins.error("Pin type not supported on replicape")
self._mcu = replicape.host_mcu
self._mcu.add_config_object(self)
self._bus = REPLICAPE_PCA9685_BUS
self._address = REPLICAPE_PCA9685_ADDRESS
self._cycle_time = REPLICAPE_PCA9685_CYCLE_TIME
self._max_duration = 2.
self._oid = None
self._invert = pin_params['invert']
self._start_value = self._shutdown_value = float(self._invert)
self._is_static = False
self._last_clock = 0
self._pwm_max = 0.
self._set_cmd = None
def get_mcu(self):
return self._mcu
def setup_max_duration(self, max_duration):
self._max_duration = max_duration
def setup_cycle_time(self, cycle_time, hardware_pwm=False):
if hardware_pwm:
raise pins.error("pca9685 does not support hardware_pwm parameter")
if cycle_time != self._cycle_time:
logging.info("Ignoring pca9685 cycle time of %.6f (using %.6f)",
cycle_time, self._cycle_time)
def setup_start_value(self, start_value, shutdown_value, is_static=False):
if is_static and start_value != shutdown_value:
raise pins.error("Static pin can not have shutdown value")
if self._invert:
start_value = 1. - start_value
shutdown_value = 1. - shutdown_value
self._start_value = max(0., min(1., start_value))
self._shutdown_value = max(0., min(1., shutdown_value))
self._is_static = is_static
self._replicape.note_pwm_start_value(
self._channel, self._start_value, self._shutdown_value)
def build_config(self):
self._pwm_max = self._mcu.get_constant_float("PCA9685_MAX")
cycle_ticks = self._mcu.seconds_to_clock(self._cycle_time)
if self._is_static:
self._mcu.add_config_cmd(
"set_pca9685_out bus=%d addr=%d channel=%d"
" cycle_ticks=%d value=%d" % (
self._bus, self._address, self._channel,
cycle_ticks, self._start_value * self._pwm_max))
return
self._oid = self._mcu.create_oid()
self._mcu.add_config_cmd(
"config_pca9685 oid=%d bus=%d addr=%d channel=%d cycle_ticks=%d"
" value=%d default_value=%d max_duration=%d" % (
self._oid, self._bus, self._address, self._channel, cycle_ticks,
self._start_value * self._pwm_max,
self._shutdown_value * self._pwm_max,
self._mcu.seconds_to_clock(self._max_duration)))
cmd_queue = self._mcu.alloc_command_queue()
self._set_cmd = self._mcu.lookup_command(
"schedule_pca9685_out oid=%c clock=%u value=%hu", cq=cmd_queue)
def set_pwm(self, print_time, value):
clock = self._mcu.print_time_to_clock(print_time)
if self._invert:
value = 1. - value
value = int(max(0., min(1., value)) * self._pwm_max + 0.5)
self._replicape.note_pwm_enable(print_time, self._channel, value)
self._set_cmd.send([self._oid, clock, value],
minclock=self._last_clock, reqclock=clock)
self._last_clock = clock
def set_digital(self, print_time, value):
if value:
self.set_pwm(print_time, 1.)
else:
self.set_pwm(print_time, 0.)
class ReplicapeDACEnable:
def __init__(self, replicape, channel, pin_params):
if pin_params['type'] != 'digital_out':
raise pins.error("Replicape virtual enable pin must be digital_out")
if pin_params['invert']:
raise pins.error("Replicape virtual enable pin can not be inverted")
self.mcu = replicape.host_mcu
self.value = replicape.stepper_dacs[channel]
self.pwm = pca9685_pwm(replicape, channel, pin_params)
def get_mcu(self):
return self.mcu
def setup_max_duration(self, max_duration):
self.pwm.setup_max_duration(max_duration)
def set_digital(self, print_time, value):
if value:
self.pwm.set_pwm(print_time, self.value)
else:
self.pwm.set_pwm(print_time, 0.)
ReplicapeStepConfig = {
'disable': None,
'1': (1<<7)|(1<<5), '2': (1<<7)|(1<<5)|(1<<6), 'spread2': (1<<5),
'4': (1<<7)|(1<<5)|(1<<4), '16': (1<<7)|(1<<5)|(1<<6)|(1<<4),
'spread4': (1<<5)|(1<<4), 'spread16': (1<<7), 'stealth4': (1<<7)|(1<<6),
'stealth16': 0
}
class Replicape:
def __init__(self, config):
printer = config.get_printer()
pins.get_printer_pins(printer).register_chip('replicape', self)
revisions = {'B3': 'B3'}
config.getchoice('revision', revisions)
self.host_mcu = mcu.get_printer_mcu(printer, config.get('host_mcu'))
# Setup enable pin
self.mcu_pwm_enable = pins.setup_pin(
printer, 'digital_out', config.get('enable_pin', '!P9_41'))
self.mcu_pwm_enable.setup_max_duration(0.)
self.mcu_pwm_start_value = self.mcu_pwm_shutdown_value = False
# Setup power pins
self.pins = {
"power_e": (pca9685_pwm, 5), "power_h": (pca9685_pwm, 3),
"power_hotbed": (pca9685_pwm, 4),
"power_fan0": (pca9685_pwm, 7), "power_fan1": (pca9685_pwm, 8),
"power_fan2": (pca9685_pwm, 9), "power_fan3": (pca9685_pwm, 10) }
# Setup stepper config
self.send_spi_cmd = None
self.last_stepper_time = 0.
self.stepper_dacs = {}
shift_registers = [1, 0, 0, 1, 1]
for port, name in enumerate('xyzeh'):
prefix = 'stepper_%s_' % (name,)
sc = config.getchoice(
prefix + 'microstep_mode', ReplicapeStepConfig, 'disable')
if sc is None:
continue
sc |= shift_registers[port]
if config.getboolean(prefix + 'chopper_off_time_high', False):
sc |= 1<<3
if config.getboolean(prefix + 'chopper_hysteresis_high', False):
sc |= 1<<2
if config.getboolean(prefix + 'chopper_blank_time_high', True):
sc |= 1<<1
shift_registers[port] = sc
channel = port + 11
cur = config.getfloat(
prefix + 'current', above=0., maxval=REPLICAPE_MAX_CURRENT)
self.stepper_dacs[channel] = cur / REPLICAPE_MAX_CURRENT
self.pins[prefix + 'enable'] = (ReplicapeDACEnable, channel)
self.enabled_channels = {ch: False for cl, ch in self.pins.values()}
if config.getboolean('servo0_enable', False):
shift_registers[1] |= 1
if config.getboolean('servo1_enable', False):
shift_registers[2] |= 1
self.sr_disabled = tuple(reversed(shift_registers))
if [i for i in [0, 1, 2] if 11+i in self.stepper_dacs]:
# Enable xyz steppers
shift_registers[0] &= ~1
if [i for i in [3, 4] if 11+i in self.stepper_dacs]:
# Enable eh steppers
shift_registers[3] &= ~1
if (config.getboolean('standstill_power_down', False)
and self.stepper_dacs):
shift_registers[4] &= ~1
self.sr_enabled = tuple(reversed(shift_registers))
self.host_mcu.add_config_object(self)
self.host_mcu.add_config_cmd("send_spi bus=%d dev=%d msg=%s" % (
REPLICAPE_SHIFT_REGISTER_BUS, REPLICAPE_SHIFT_REGISTER_DEVICE,
"".join(["%02x" % (x,) for x in self.sr_disabled])))
def build_config(self):
cmd_queue = self.host_mcu.alloc_command_queue()
self.send_spi_cmd = self.host_mcu.lookup_command(
"send_spi bus=%u dev=%u msg=%*s", cq=cmd_queue)
def note_pwm_start_value(self, channel, start_value, shutdown_value):
self.mcu_pwm_start_value |= not not start_value
self.mcu_pwm_shutdown_value |= not not shutdown_value
self.mcu_pwm_enable.setup_start_value(
self.mcu_pwm_start_value, self.mcu_pwm_shutdown_value)
self.enabled_channels[channel] = not not start_value
def note_pwm_enable(self, print_time, channel, value):
is_enable = not not value
if self.enabled_channels[channel] == is_enable:
# Nothing to do
return
self.enabled_channels[channel] = is_enable
# Check if need to set the pca9685 enable pin
on_channels = [1 for c, e in self.enabled_channels.items() if e]
if not on_channels:
self.mcu_pwm_enable.set_digital(print_time, 0)
elif is_enable and len(on_channels) == 1:
self.mcu_pwm_enable.set_digital(print_time, 1)
# Check if need to set the stepper enable lines
if channel not in self.stepper_dacs:
return
on_dacs = [1 for c in self.stepper_dacs.keys()
if self.enabled_channels[c]]
if not on_dacs:
sr = self.sr_disabled
elif is_enable and len(on_dacs) == 1:
sr = self.sr_enabled
else:
return
print_time = max(print_time, self.last_stepper_time + PIN_MIN_TIME)
clock = self.host_mcu.print_time_to_clock(print_time)
# XXX - the send_spi message should be scheduled
self.send_spi_cmd.send([REPLICAPE_SHIFT_REGISTER_BUS,
REPLICAPE_SHIFT_REGISTER_DEVICE, sr],
minclock=clock, reqclock=clock)
def setup_pin(self, pin_params):
pin = pin_params['pin']
if pin not in self.pins:
raise pins.error("Unknown replicape pin %s" % (pin,))
pclass, channel = self.pins[pin]
return pclass(self, channel, pin_params)
def load_config(config):
return Replicape(config)

59
klippy/extras/servo.py Normal file
View File

@@ -0,0 +1,59 @@
# Support for servos
#
# Copyright (C) 2017,2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import pins
SERVO_SIGNAL_PERIOD = 0.020
PIN_MIN_TIME = 0.100
class PrinterServo:
def __init__(self, config):
self.printer = config.get_printer()
self.mcu_servo = pins.setup_pin(self.printer, 'pwm', config.get('pin'))
self.mcu_servo.setup_max_duration(0.)
self.mcu_servo.setup_cycle_time(SERVO_SIGNAL_PERIOD)
self.min_width = config.getfloat(
'minimum_pulse_width', .001, above=0., below=SERVO_SIGNAL_PERIOD)
self.max_width = config.getfloat(
'maximum_pulse_width', .002
, above=self.min_width, below=SERVO_SIGNAL_PERIOD)
self.max_angle = config.getfloat('maximum_servo_angle', 180.)
self.angle_to_width = (self.max_width - self.min_width) / self.max_angle
self.width_to_value = 1. / SERVO_SIGNAL_PERIOD
self.last_value = self.last_value_time = 0.
self.gcode = self.printer.lookup_object('gcode')
self.gcode.register_command("SET_SERVO", self.cmd_SET_SERVO,
desc=self.cmd_SET_SERVO_help)
def set_pwm(self, print_time, value):
if value == self.last_value:
return
print_time = max(print_time, self.last_value_time + PIN_MIN_TIME)
self.mcu_servo.set_pwm(print_time, value)
self.last_value = value
self.last_value_time = print_time
def set_angle(self, print_time, angle):
angle = max(0., min(self.max_angle, angle))
width = self.min_width + angle * self.angle_to_width
self.set_pwm(print_time, width * self.width_to_value)
def set_pulse_width(self, print_time, width):
width = max(self.min_width, min(self.max_width, width))
self.set_pwm(print_time, width * self.width_to_value)
cmd_SET_SERVO_help = "Set servo angle"
def cmd_SET_SERVO(self, params):
servo_name = self.gcode.get_str('SERVO', params)
servo = self.printer.lookup_object('servo ' + servo_name, None)
if servo is not self:
if servo is None:
raise self.gcode.error("Servo not configured")
return servo.cmd_SET_SERVO(params)
print_time = self.printer.lookup_object('toolhead').get_last_move_time()
if 'WIDTH' in params:
self.set_pulse_width(print_time,
self.gcode.get_float('WIDTH', params))
else:
self.set_angle(print_time, self.gcode.get_float('ANGLE', params))
def load_config_prefix(config):
return PrinterServo(config)

View File

@@ -0,0 +1,17 @@
# Set the state of a list of digital output pins
#
# Copyright (C) 2017-2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
class PrinterStaticDigitalOut:
def __init__(self, config):
printer = config.get_printer()
ppins = printer.lookup_object('pins')
pin_list = [pin.strip() for pin in config.get('pins').split(',')]
for pin_desc in pin_list:
mcu_pin = ppins.setup_pin('digital_out', pin_desc)
mcu_pin.setup_start_value(1, 1, True)
def load_config_prefix(config):
return PrinterStaticDigitalOut(config)

View File

@@ -0,0 +1,74 @@
# Heater/sensor verification code
#
# Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging
import extruder
HINT_THERMAL = """
See the 'verify_heater' section in config/example-extras.cfg
for the parameters that control this check.
"""
class HeaterCheck:
def __init__(self, config):
self.printer = config.get_printer()
self.heater_name = config.get_name().split()[1]
self.heater = None
self.hysteresis = config.getfloat('hysteresis', 5., minval=0.)
self.max_error = config.getfloat('max_error', 120., minval=0.)
self.heating_gain = config.getfloat('heating_gain', 2., above=0.)
default_gain_time = 20.
if self.heater_name == 'heater_bed':
default_gain_time = 60.
self.check_gain_time = config.getfloat(
'check_gain_time', default_gain_time, minval=1.)
self.met_target = False
self.last_target = self.goal_temp = self.error = 0.
self.fault_systime = self.printer.get_reactor().NEVER
def printer_state(self, state):
if state == 'connect':
self.heater = extruder.get_printer_heater(
self.printer, self.heater_name)
logging.info("Starting heater checks for %s", self.heater_name)
reactor = self.printer.get_reactor()
reactor.register_timer(self.check_event, reactor.NOW)
def check_event(self, eventtime):
temp, target = self.heater.get_temp(eventtime)
if temp >= target - self.hysteresis:
# Temperature near target - reset checks
if not self.met_target and target:
logging.info("Heater %s within range of %.3f",
self.heater_name, target)
self.met_target = True
self.error = 0.
elif self.met_target:
self.error += (target - self.hysteresis) - temp
if target != self.last_target:
# Target changed - reset checks
logging.info("Heater %s approaching new target of %.3f",
self.heater_name, target)
self.met_target = False
self.goal_temp = temp + self.heating_gain
self.fault_systime = eventtime + self.check_gain_time
elif self.error >= self.max_error:
# Failure due to inability to maintain target temperature
return self.heater_fault()
elif temp >= self.goal_temp:
# Temperature approaching target - reset checks
self.goal_temp = temp + self.heating_gain
self.fault_systime = eventtime + self.check_gain_time
elif eventtime >= self.fault_systime:
# Failure due to inability to approach target temperature
return self.heater_fault()
self.last_target = target
return eventtime + 1.
def heater_fault(self):
msg = "Heater %s not heating at expected rate" % (self.heater_name,)
logging.error(msg)
self.printer.invoke_shutdown(msg + HINT_THERMAL)
return self.printer.get_reactor().NEVER
def load_config_prefix(config):
return HeaterCheck(config)

View File

@@ -0,0 +1,162 @@
# Virtual sdcard support (print files directly from a host g-code file)
#
# Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import os, logging
class VirtualSD:
def __init__(self, config):
printer = config.get_printer()
# sdcard state
sd = config.get('path')
self.sdcard_dirname = os.path.normpath(os.path.expanduser(sd))
self.current_file = None
self.file_position = self.file_size = 0
# Work timer
self.reactor = printer.get_reactor()
self.must_pause_work = False
self.work_timer = None
# Register commands
self.gcode = printer.lookup_object('gcode')
for cmd in ['M20', 'M21', 'M23', 'M24', 'M25', 'M26', 'M27']:
self.gcode.register_command(cmd, getattr(self, 'cmd_' + cmd))
for cmd in ['M28', 'M29', 'M30']:
self.gcode.register_command(cmd, self.cmd_error)
def printer_state(self, state):
if state == 'shutdown' and self.work_timer is not None:
self.must_pause_work = True
def get_file_list(self):
dname = self.sdcard_dirname
try:
filenames = os.listdir(self.sdcard_dirname)
return [(fname, os.path.getsize(os.path.join(dname, fname)))
for fname in filenames]
except:
logging.exception("virtual_sdcard get_file_list")
raise self.gcode.error("Unable to get file list")
def get_status(self, eventtime):
progress = 0.
if self.work_timer is not None and self.file_size:
progress = float(self.file_position) / self.file_size
return {'progress': progress}
# G-Code commands
def cmd_error(self, params):
raise self.gcode.error("SD write not supported")
def cmd_M20(self, params):
# List SD card
files = self.get_file_list()
self.gcode.respond("Begin file list")
for fname, fsize in files:
self.gcode.respond("%s %d" % (fname, fsize))
self.gcode.respond("End file list")
def cmd_M21(self, params):
# Initialize SD card
self.gcode.respond("SD card ok")
def cmd_M23(self, params):
# Select SD file
if self.work_timer is not None:
raise self.gcode.error("SD busy")
if self.current_file is not None:
self.current_file.close()
self.current_file = None
self.file_position = self.file_size = 0
try:
orig = params['#original']
filename = orig[orig.find("M23") + 4:].split()[0].strip()
if '*' in filename:
filename = filename[:filename.find('*')].strip()
except:
raise self.gcode.error("Unable to extract filename")
if filename.startswith('/'):
filename = filename[1:]
files = self.get_file_list()
files_by_lower = { fname.lower(): fname for fname, fsize in files }
try:
fname = files_by_lower[filename.lower()]
fname = os.path.join(self.sdcard_dirname, fname)
f = open(fname, 'rb')
f.seek(0, os.SEEK_END)
fsize = f.tell()
f.seek(0)
except:
logging.exception("virtual_sdcard file open")
raise self.gcode.error("Unable to open file")
self.gcode.respond("File opened:%s Size:%d" % (filename, fsize))
self.gcode.respond("File selected")
self.current_file = f
self.file_position = 0
self.file_size = fsize
def cmd_M24(self, params):
# Start/resume SD print
if self.work_timer is not None:
raise self.gcode.error("SD busy")
self.must_pause_work = False
self.work_timer = self.reactor.register_timer(
self.work_handler, self.reactor.NOW)
def cmd_M25(self, params):
# Pause SD print
if self.work_timer is not None:
self.must_pause_work = True
def cmd_M26(self, params):
# Set SD position
if self.work_timer is not None:
raise self.gcode.error("SD busy")
pos = self.gcode.get_int('S', params)
self.file_position = pos
def cmd_M27(self, params):
# Report SD print status
if self.current_file is None or self.work_timer is None:
self.gcode.respond("Not SD printing.")
return
self.gcode.respond("SD printing byte %d/%d" % (
self.file_position, self.file_size))
# Background work timer
def work_handler(self, eventtime):
self.reactor.unregister_timer(self.work_timer)
try:
self.current_file.seek(self.file_position)
except:
logging.exception("virtual_sdcard seek")
self.gcode.respond_error("Unable to seek file")
self.work_timer = None
return self.reactor.NEVER
partial_input = ""
lines = []
while not self.must_pause_work:
if not lines:
# Read more data
try:
data = self.current_file.read(8192)
except:
logging.exception("virtual_sdcard read")
self.gcode.respond_error("Error on virtual sdcard read")
break
if not data:
# End of file
self.current_file.close()
self.current_file = None
self.gcode.respond("Done printing file")
break
lines = data.split('\n')
lines[0] = partial_input + lines[0]
partial_input = lines.pop()
lines.reverse()
continue
# Dispatch command
try:
res = self.gcode.process_batch(lines[-1])
if not res:
self.reactor.pause(self.reactor.monotonic() + 0.100)
continue
except self.gcode.error as e:
break
except:
logging.exception("virtual_sdcard dispatch")
break
self.file_position += len(lines.pop()) + 1
self.work_timer = None
return self.reactor.NEVER
def load_config(config):
return VirtualSD(config)

View File

@@ -1,6 +1,6 @@
# Code for handling printer nozzle extruders
#
# Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
# Copyright (C) 2016-2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import math, logging
@@ -10,20 +10,33 @@ EXTRUDE_DIFF_IGNORE = 1.02
class PrinterExtruder:
def __init__(self, printer, config):
self.config = config
shared_heater = config.get('shared_heater', None)
if shared_heater is None:
self.heater = heater.PrinterHeater(printer, config)
self.stepper = stepper.PrinterStepper(printer, config, 'extruder')
else:
self.heater = get_printer_heater(printer, shared_heater)
self.stepper = stepper.PrinterStepper(printer, config)
self.nozzle_diameter = config.getfloat('nozzle_diameter', above=0.)
filament_diameter = config.getfloat(
'filament_diameter', minval=self.nozzle_diameter)
filament_area = math.pi * (filament_diameter * .5)**2
self.filament_area = math.pi * (filament_diameter * .5)**2
max_cross_section = config.getfloat(
'max_extrude_cross_section', 4. * self.nozzle_diameter**2
, above=0.)
self.max_extrude_ratio = max_cross_section / filament_area
self.max_extrude_ratio = max_cross_section / self.filament_area
toolhead = printer.lookup_object('toolhead')
max_velocity, max_accel = toolhead.get_max_velocity()
self.max_e_velocity = config.getfloat(
'max_extrude_only_velocity', max_velocity * self.max_extrude_ratio
, above=0.)
self.max_e_accel = config.getfloat(
'max_extrude_only_accel', max_accel * self.max_extrude_ratio
, above=0.)
self.stepper.set_max_jerk(9999999.9, 9999999.9)
self.max_e_dist = config.getfloat(
'max_extrude_only_distance', 50., minval=0.)
self.max_e_velocity = self.max_e_accel = None
self.activate_gcode = config.get('activate_gcode', '')
self.deactivate_gcode = config.get('deactivate_gcode', '')
self.pressure_advance = config.getfloat(
'pressure_advance', 0., minval=0.)
self.pressure_advance_lookahead_time = 0.
@@ -32,37 +45,49 @@ class PrinterExtruder:
'pressure_advance_lookahead_time', 0.010, minval=0.)
self.need_motor_enable = True
self.extrude_pos = 0.
def set_max_jerk(self, max_xy_halt_velocity, max_velocity, max_accel):
self.max_e_velocity = self.config.getfloat(
'max_extrude_only_velocity', max_velocity * self.max_extrude_ratio
, above=0.)
self.max_e_accel = self.config.getfloat(
'max_extrude_only_accel', max_accel * self.max_extrude_ratio
, above=0.)
self.stepper.set_max_jerk(9999999.9, 9999999.9)
def motor_off(self, move_time):
self.stepper.motor_enable(move_time, 0)
def get_heater(self):
return self.heater
def set_active(self, print_time, is_active):
return self.extrude_pos
def get_activate_gcode(self, is_active):
if is_active:
return self.activate_gcode
return self.deactivate_gcode
def stats(self, eventtime):
return self.heater.stats(eventtime)
def motor_off(self, print_time):
self.stepper.motor_enable(print_time, 0)
self.need_motor_enable = True
def check_move(self, move):
move.extrude_r = move.axes_d[3] / move.move_d
move.extrude_max_corner_v = 0.
if not self.heater.can_extrude:
raise homing.EndstopMoveError(
move.end_pos, "Extrude below minimum temp")
raise homing.EndstopError(
"Extrude below minimum temp\n"
"See the 'min_extrude_temp' config option for details")
if not move.is_kinematic_move or move.extrude_r < 0.:
# Extrude only move (or retraction move) - limit accel and velocity
if abs(move.axes_d[3]) > self.max_e_dist:
raise homing.EndstopMoveError(
move.end_pos, "Extrude move too long")
raise homing.EndstopError(
"Extrude only move too long (%.3fmm vs %.3fmm)\n"
"See the 'max_extrude_only_distance' config"
" option for details" % (move.axes_d[3], self.max_e_dist))
inv_extrude_r = 1. / abs(move.extrude_r)
move.limit_speed(self.max_e_velocity * inv_extrude_r
, self.max_e_accel * inv_extrude_r)
elif (move.extrude_r > self.max_extrude_ratio
and move.axes_d[3] > self.nozzle_diameter*self.max_extrude_ratio):
logging.debug("Overextrude: %s vs %s" % (
move.extrude_r, self.max_extrude_ratio))
raise homing.EndstopMoveError(
move.end_pos, "Move exceeds maximum extrusion cross section")
elif move.extrude_r > self.max_extrude_ratio:
if move.axes_d[3] <= self.nozzle_diameter * self.max_extrude_ratio:
# Permit extrusion if amount extruded is tiny
move.extrude_r = self.max_extrude_ratio
return
area = move.axes_d[3] * self.filament_area / move.move_d
logging.debug("Overextrude: %s vs %s (area=%.3f dist=%.3f)",
move.extrude_r, self.max_extrude_ratio,
area, move.move_d)
raise homing.EndstopError(
"Move exceeds maximum extrusion (%.3fmm^2 vs %.3fmm^2)\n"
"See the 'max_extrude_cross_section' config option for details"
% (area, self.max_extrude_ratio * self.filament_area))
def calc_junction(self, prev_move, move):
extrude = move.axes_d[3]
prev_extrude = prev_move.axes_d[3]
@@ -114,9 +139,9 @@ class PrinterExtruder:
return i
move.extrude_max_corner_v = max_corner_v
return flush_count
def move(self, move_time, move):
def move(self, print_time, move):
if self.need_motor_enable:
self.stepper.motor_enable(move_time, 1)
self.stepper.motor_enable(print_time, 1)
self.need_motor_enable = False
axis_d = move.axes_d[3]
axis_r = abs(axis_d) / move.move_d
@@ -172,35 +197,34 @@ class PrinterExtruder:
decel_d -= extra_decel_d
# Prepare for steps
mcu_stepper = self.stepper.mcu_stepper
mcu_time = mcu_stepper.print_to_mcu_time(move_time)
step_const = self.stepper.step_const
move_time = print_time
# Acceleration steps
if accel_d:
mcu_stepper.step_const(mcu_time, start_pos, accel_d, start_v, accel)
step_const(move_time, start_pos, accel_d, start_v, accel)
start_pos += accel_d
mcu_time += accel_t
move_time += accel_t
# Cruising steps
if cruise_d:
mcu_stepper.step_const(mcu_time, start_pos, cruise_d, cruise_v, 0.)
step_const(move_time, start_pos, cruise_d, cruise_v, 0.)
start_pos += cruise_d
mcu_time += cruise_t
move_time += cruise_t
# Deceleration steps
if decel_d:
mcu_stepper.step_const(mcu_time, start_pos, decel_d, decel_v, -accel)
step_const(move_time, start_pos, decel_d, decel_v, -accel)
start_pos += decel_d
mcu_time += decel_t
move_time += decel_t
# Retraction steps
if retract_d:
mcu_stepper.step_const(
mcu_time, start_pos, -retract_d, retract_v, accel)
step_const(move_time, start_pos, -retract_d, retract_v, accel)
start_pos -= retract_d
self.extrude_pos = start_pos
# Dummy extruder class used when a printer has no extruder at all
class DummyExtruder:
def set_max_jerk(self, max_xy_halt_velocity, max_velocity, max_accel):
pass
def set_active(self, print_time, is_active):
return 0.
def motor_off(self, move_time):
pass
def check_move(self, move):
@@ -210,3 +234,33 @@ class DummyExtruder:
return move.max_cruise_v2
def lookahead(self, moves, flush_count, lazy):
return flush_count
def add_printer_objects(printer, config):
for i in range(99):
section = 'extruder%d' % (i,)
if not config.has_section(section):
if not i and config.has_section('extruder'):
printer.add_object('extruder0', PrinterExtruder(
printer, config.getsection('extruder')))
continue
break
printer.add_object(section, PrinterExtruder(
printer, config.getsection(section)))
def get_printer_extruders(printer):
out = []
for i in range(99):
extruder = printer.lookup_object('extruder%d' % (i,), None)
if extruder is None:
break
out.append(extruder)
return out
def get_printer_heater(printer, name):
if name == 'heater_bed':
return printer.lookup_object(name)
if name == 'extruder':
name = 'extruder0'
if name.startswith('extruder'):
return printer.lookup_object(name).get_heater()
raise printer.config_error("Unknown heater '%s'" % (name,))

View File

@@ -1,32 +0,0 @@
# Printer fan support
#
# Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
FAN_MIN_TIME = 0.1
PWM_CYCLE_TIME = 0.010
class PrinterFan:
def __init__(self, printer, config):
self.last_fan_value = 0.
self.last_fan_time = 0.
self.kick_start_time = config.getfloat('kick_start_time', 0.1, minval=0.)
pin = config.get('pin')
hard_pwm = config.getint('hard_pwm', 0)
self.mcu_fan = printer.mcu.create_pwm(pin, PWM_CYCLE_TIME, hard_pwm, 0.)
# External commands
def set_speed(self, print_time, value):
value = max(0., min(1., value))
if value == self.last_fan_value:
return
mcu_time = self.mcu_fan.print_to_mcu_time(print_time)
mcu_time = max(self.last_fan_time + FAN_MIN_TIME, mcu_time)
if (value and value < 1.
and not self.last_fan_value and self.kick_start_time):
# Run fan at full speed for specified kick_start_time
self.mcu_fan.set_pwm(mcu_time, 1.)
mcu_time += self.kick_start_time
self.mcu_fan.set_pwm(mcu_time, value)
self.last_fan_time = mcu_time
self.last_fan_value = value

View File

@@ -1,144 +1,230 @@
# Parse gcode commands
#
# Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
# Copyright (C) 2016-2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import os, re, logging, collections
import homing
import homing, extruder
# Parse out incoming GCode and find and translate head movements
class error(Exception):
pass
# Parse and handle G-Code commands
class GCodeParser:
error = error
RETRY_TIME = 0.100
def __init__(self, printer, fd, is_fileinput=False):
def __init__(self, printer, fd):
self.printer = printer
self.fd = fd
self.is_fileinput = is_fileinput
# Input handling
self.reactor = printer.reactor
self.reactor = printer.get_reactor()
self.is_processing_data = False
self.is_fileinput = not not printer.get_start_args().get("debuginput")
self.fd_handle = None
if not is_fileinput:
if not self.is_fileinput:
self.fd_handle = self.reactor.register_fd(self.fd, self.process_data)
self.input_commands = [""]
self.partial_input = ""
self.pending_commands = []
self.bytes_read = 0
self.input_log = collections.deque([], 50)
# Command handling
self.gcode_handlers = self.build_handlers(False)
self.is_printer_ready = False
self.need_ack = False
self.toolhead = self.heater_nozzle = self.heater_bed = self.fan = None
self.speed = 25.0
self.base_gcode_handlers = self.gcode_handlers = {}
self.ready_gcode_handlers = {}
self.gcode_help = {}
for cmd in self.all_handlers:
func = getattr(self, 'cmd_' + cmd)
wnr = getattr(self, 'cmd_' + cmd + '_when_not_ready', False)
desc = getattr(self, 'cmd_' + cmd + '_help', None)
self.register_command(cmd, func, wnr, desc)
for a in getattr(self, 'cmd_' + cmd + '_aliases', []):
self.register_command(a, func, wnr)
# G-Code coordinate manipulation
self.absolutecoord = self.absoluteextrude = True
self.base_position = [0.0, 0.0, 0.0, 0.0]
self.last_position = [0.0, 0.0, 0.0, 0.0]
self.homing_add = [0.0, 0.0, 0.0, 0.0]
self.speed_factor = 1. / 60.
self.extrude_factor = 1.
self.move_transform = self.move_with_transform = None
self.position_with_transform = (lambda: [0., 0., 0., 0.])
# G-Code state
self.need_ack = False
self.toolhead = self.fan = self.extruder = None
self.heaters = []
self.speed = 25.0
self.axis2pos = {'X': 0, 'Y': 1, 'Z': 2, 'E': 3}
def build_handlers(self, is_ready):
handlers = self.all_handlers
if not is_ready:
handlers = [h for h in handlers
if getattr(self, 'cmd_'+h+'_when_not_ready', False)]
gcode_handlers = dict((h, getattr(self, 'cmd_'+h)) for h in handlers)
for h, f in gcode_handlers.items():
aliases = getattr(self, 'cmd_'+h+'_aliases', [])
gcode_handlers.update(dict([(a, f) for a in aliases]))
return gcode_handlers
def register_command(self, cmd, func, when_not_ready=False, desc=None):
if func is None:
if cmd in self.ready_gcode_handlers:
del self.ready_gcode_handlers[cmd]
if cmd in self.base_gcode_handlers:
del self.base_gcode_handlers[cmd]
return
if not (len(cmd) >= 2 and not cmd[0].isupper() and cmd[1].isdigit()):
origfunc = func
func = lambda params: origfunc(self.get_extended_params(params))
self.ready_gcode_handlers[cmd] = func
if when_not_ready:
self.base_gcode_handlers[cmd] = func
if desc is not None:
self.gcode_help[cmd] = desc
def set_move_transform(self, transform):
if self.move_transform is not None:
raise self.printer.config_error(
"G-Code move transform already specified")
self.move_transform = transform
self.move_with_transform = transform.move
self.position_with_transform = transform.get_position
def stats(self, eventtime):
return "gcodein=%d" % (self.bytes_read,)
def set_printer_ready(self, is_ready):
if self.is_printer_ready == is_ready:
return False, "gcodein=%d" % (self.bytes_read,)
def get_status(self, eventtime):
busy = self.is_processing_data
return {'speed_factor': self.speed_factor * 60., 'busy': busy}
def printer_state(self, state):
if state == 'shutdown':
if not self.is_printer_ready:
return
self.is_printer_ready = is_ready
self.gcode_handlers = self.build_handlers(is_ready)
if not is_ready:
# Printer is shutdown (could be running in a background thread)
self.is_printer_ready = False
self.gcode_handlers = self.base_gcode_handlers
self.dump_debug()
if self.is_fileinput:
self.printer.request_exit()
return
if state != 'ready':
return
self.is_printer_ready = True
self.gcode_handlers = self.ready_gcode_handlers
# Lookup printer components
self.toolhead = self.printer.objects.get('toolhead')
self.heater_nozzle = None
extruder = self.printer.objects.get('extruder')
if extruder:
self.heater_nozzle = extruder.heater
self.heater_bed = self.printer.objects.get('heater_bed')
self.fan = self.printer.objects.get('fan')
self.toolhead = self.printer.lookup_object('toolhead')
if self.move_transform is None:
self.move_with_transform = self.toolhead.move
self.position_with_transform = self.toolhead.get_position
extruders = extruder.get_printer_extruders(self.printer)
if extruders:
self.extruder = extruders[0]
self.toolhead.set_extruder(self.extruder)
self.heaters = [ e.get_heater() for e in extruders ]
self.heaters.append(self.printer.lookup_object('heater_bed', None))
self.fan = self.printer.lookup_object('fan', None)
if self.is_fileinput and self.fd_handle is None:
self.fd_handle = self.reactor.register_fd(self.fd, self.process_data)
def motor_heater_off(self):
if self.toolhead is None:
return
self.toolhead.motor_off()
print_time = self.toolhead.get_last_move_time()
if self.heater_nozzle is not None:
self.heater_nozzle.set_temp(print_time, 0.)
if self.heater_bed is not None:
self.heater_bed.set_temp(print_time, 0.)
if self.fan is not None:
self.fan.set_speed(print_time, 0.)
def reset_last_position(self):
self.last_position = self.position_with_transform()
def dump_debug(self):
logging.info("Dumping gcode input %d blocks" % (
out = []
out.append("Dumping gcode input %d blocks" % (
len(self.input_log),))
for eventtime, data in self.input_log:
logging.info("Read %f: %s" % (eventtime, repr(data)))
out.append("Read %f: %s" % (eventtime, repr(data)))
out.append(
"gcode state: absolutecoord=%s absoluteextrude=%s"
" base_position=%s last_position=%s homing_add=%s"
" speed_factor=%s extrude_factor=%s speed=%s" % (
self.absolutecoord, self.absoluteextrude,
self.base_position, self.last_position, self.homing_add,
self.speed_factor, self.extrude_factor, self.speed))
logging.info("\n".join(out))
# Parse input into commands
args_r = re.compile('([a-zA-Z_]+|[a-zA-Z*])')
def process_commands(self, eventtime):
while len(self.input_commands) > 1:
line = self.input_commands.pop(0)
args_r = re.compile('([A-Z_]+|[A-Z*/])')
def process_commands(self, commands, need_ack=True):
for line in commands:
# Ignore comments and leading/trailing spaces
line = origline = line.strip()
cpos = line.find(';')
if cpos >= 0:
line = line[:cpos]
# Break command into parts
parts = self.args_r.split(line)[1:]
params = dict((parts[i].upper(), parts[i+1].strip())
for i in range(0, len(parts), 2))
parts = self.args_r.split(line.upper())[1:]
params = { parts[i]: parts[i+1].strip()
for i in range(0, len(parts), 2) }
params['#original'] = origline
if parts and parts[0].upper() == 'N':
if parts and parts[0] == 'N':
# Skip line number at start of command
del parts[:2]
if not parts:
self.cmd_default(params)
continue
params['#command'] = cmd = parts[0].upper() + parts[1].strip()
# Treat empty line as empty command
parts = ['', '']
params['#command'] = cmd = parts[0] + parts[1].strip()
# Invoke handler for command
self.need_ack = True
self.need_ack = need_ack
handler = self.gcode_handlers.get(cmd, self.cmd_default)
try:
handler(params)
except error, e:
except error as e:
self.respond_error(str(e))
self.reset_last_position()
if not need_ack:
raise
except:
logging.exception("Exception in command handler")
self.toolhead.force_shutdown()
self.respond_error('Internal error on command:"%s"' % (cmd,))
if self.is_fileinput:
self.printer.request_exit('exit_eof')
break
msg = 'Internal error on command:"%s"' % (cmd,)
logging.exception(msg)
self.printer.invoke_shutdown(msg)
self.respond_error(msg)
if not need_ack:
raise
self.ack()
m112_r = re.compile('^(?:[nN][0-9]+)?\s*[mM]112(?:\s|$)')
def process_data(self, eventtime):
# Read input, separate by newline, and add to pending_commands
data = os.read(self.fd, 4096)
self.input_log.append((eventtime, data))
self.bytes_read += len(data)
lines = data.split('\n')
lines[0] = self.input_commands.pop() + lines[0]
self.input_commands.extend(lines)
if self.is_processing_data:
if len(lines) <= 1:
return
if not self.is_fileinput and lines[0].strip().upper() == 'M112':
lines[0] = self.partial_input + lines[0]
self.partial_input = lines.pop()
pending_commands = self.pending_commands
pending_commands.extend(lines)
# Special handling for debug file input EOF
if not data and self.is_fileinput:
if not self.is_processing_data:
self.request_restart('exit')
pending_commands.append("")
# Handle case where multiple commands pending
if self.is_processing_data or len(pending_commands) > 1:
if len(pending_commands) < 20:
# Check for M112 out-of-order
for line in lines:
if self.m112_r.match(line) is not None:
self.cmd_M112({})
if self.is_processing_data:
if len(pending_commands) >= 20:
# Stop reading input
self.reactor.unregister_fd(self.fd_handle)
self.fd_handle = None
return
# Process commands
self.is_processing_data = True
self.process_commands(eventtime)
self.pending_commands = []
self.process_commands(pending_commands)
if self.pending_commands:
self.process_pending()
self.is_processing_data = False
def process_pending(self):
pending_commands = self.pending_commands
while pending_commands:
self.pending_commands = []
self.process_commands(pending_commands)
pending_commands = self.pending_commands
if self.fd_handle is None:
self.fd_handle = self.reactor.register_fd(self.fd, self.process_data)
if not data and self.is_fileinput:
self.motor_heater_off()
self.printer.request_exit('exit_eof')
def process_batch(self, command):
if self.is_processing_data:
return False
self.is_processing_data = True
try:
self.process_commands([command], need_ack=False)
finally:
if self.pending_commands:
self.process_pending()
self.is_processing_data = False
return True
def run_script(self, script):
prev_need_ack = self.need_ack
try:
self.process_commands(script.split('\n'), need_ack=False)
finally:
self.need_ack = prev_need_ack
# Response handling
def ack(self, msg=None):
if not self.need_ack or self.is_fileinput:
@@ -149,51 +235,66 @@ class GCodeParser:
os.write(self.fd, "ok\n")
self.need_ack = False
def respond(self, msg):
logging.debug(msg)
if self.is_fileinput:
return
os.write(self.fd, msg+"\n")
def respond_info(self, msg):
logging.debug(msg)
lines = [l.strip() for l in msg.strip().split('\n')]
self.respond("// " + "\n// ".join(lines))
def respond_error(self, msg):
logging.warning(msg)
lines = msg.strip().split('\n')
if len(lines) > 1:
self.respond_info("\n".join(lines[:-1]))
self.respond('!! %s' % (lines[-1].strip(),))
self.respond_info("\n".join(lines))
self.respond('!! %s' % (lines[0].strip(),))
# Parameter parsing helpers
def get_int(self, name, params, default=None):
class sentinel: pass
def get_str(self, name, params, default=sentinel, parser=str):
if name in params:
try:
return int(params[name])
except ValueError:
return parser(params[name])
except:
raise error("Error on '%s': unable to parse %s" % (
params['#original'], params[name]))
if default is not None:
if default is not self.sentinel:
return default
raise error("Error on '%s': missing %s" % (params['#original'], name))
def get_float(self, name, params, default=None):
if name in params:
def get_int(self, name, params, default=sentinel):
return self.get_str(name, params, default, parser=int)
def get_float(self, name, params, default=sentinel):
return self.get_str(name, params, default, parser=float)
extended_r = re.compile(
r'^\s*(?:N[0-9]+\s*)?'
r'(?P<cmd>[a-zA-Z_][a-zA-Z_]+)(?:\s+|$)'
r'(?P<args>[^#*;]*?)'
r'\s*(?:[#*;].*)?$')
def get_extended_params(self, params):
m = self.extended_r.match(params['#original'])
if m is None:
# Not an "extended" command
return params
eargs = m.group('args')
try:
return float(params[name])
except ValueError:
raise error("Error on '%s': unable to parse %s" % (
params['#original'], params[name]))
if default is not None:
return default
raise error("Error on '%s': missing %s" % (params['#original'], name))
eparams = [earg.split('=', 1) for earg in eargs.split()]
eparams = { k.upper(): v for k, v in eparams }
eparams.update({k: params[k] for k in params if k.startswith('#')})
return eparams
except ValueError as e:
raise error("Malformed command '%s'" % (params['#original'],))
# Temperature wrappers
def get_temp(self):
if not self.is_printer_ready:
return "T:0"
# T:XXX /YYY B:XXX /YYY
def get_temp(self, eventtime):
# Tn:XXX /YYY B:XXX /YYY
out = []
if self.heater_nozzle:
cur, target = self.heater_nozzle.get_temp()
out.append("T:%.1f /%.1f" % (cur, target))
if self.heater_bed:
cur, target = self.heater_bed.get_temp()
out.append("B:%.1f /%.1f" % (cur, target))
for i, heater in enumerate(self.heaters):
if heater is not None:
cur, target = heater.get_temp(eventtime)
name = "B"
if i < len(self.heaters) - 1:
name = "T%d" % (i,)
out.append("%s:%.1f /%.1f" % (name, cur, target))
if not out:
return "T:0"
return " ".join(out)
def bg_temp(self, heater):
if self.is_fileinput:
@@ -201,10 +302,19 @@ class GCodeParser:
eventtime = self.reactor.monotonic()
while self.is_printer_ready and heater.check_busy(eventtime):
print_time = self.toolhead.get_last_move_time()
self.respond(self.get_temp())
self.respond(self.get_temp(eventtime))
eventtime = self.reactor.pause(eventtime + 1.)
def set_temp(self, heater, params, wait=False):
def set_temp(self, params, is_bed=False, wait=False):
temp = self.get_float('S', params, 0.)
heater = None
if is_bed:
heater = self.heaters[-1]
elif 'T' in params:
heater_index = self.get_int('T', params)
if heater_index >= 0 and heater_index < len(self.heaters) - 1:
heater = self.heaters[heater_index]
elif self.extruder is not None:
heater = self.extruder.get_heater()
if heater is None:
if temp > 0.:
self.respond_error("Heater not configured")
@@ -212,19 +322,18 @@ class GCodeParser:
print_time = self.toolhead.get_last_move_time()
try:
heater.set_temp(print_time, temp)
except heater.error, e:
self.respond_error(str(e))
return
if wait:
except heater.error as e:
raise error(str(e))
if wait and temp:
self.bg_temp(heater)
def set_fan_speed(self, speed):
if self.fan is None:
if speed:
if speed and not self.is_fileinput:
self.respond_info("Fan not configured")
return
print_time = self.toolhead.get_last_move_time()
self.fan.set_speed(print_time, speed)
# Individual command handlers
# G-Code special command handlers
def cmd_default(self, params):
if not self.is_printer_ready:
self.respond_error(self.printer.get_state_message())
@@ -233,40 +342,69 @@ class GCodeParser:
if not cmd:
logging.debug(params['#original'])
return
self.respond('echo:Unknown command:"%s"' % (cmd,))
if cmd[0] == 'T' and len(cmd) > 1 and cmd[1].isdigit():
# Tn command has to be handled specially
self.cmd_Tn(params)
return
self.respond_info('Unknown command:"%s"' % (cmd,))
def cmd_Tn(self, params):
# Select Tool
index = self.get_int('T', params)
extruders = extruder.get_printer_extruders(self.printer)
if self.extruder is None or index < 0 or index >= len(extruders):
self.respond_error("Extruder %d not configured" % (index,))
return
e = extruders[index]
if self.extruder is e:
return
self.run_script(self.extruder.get_activate_gcode(False))
try:
self.toolhead.set_extruder(e)
except homing.EndstopError as e:
raise error(str(e))
self.extruder = e
self.reset_last_position()
self.run_script(self.extruder.get_activate_gcode(True))
all_handlers = [
'G1', 'G4', 'G20', 'G28', 'G90', 'G91', 'G92',
'M82', 'M83', 'M18', 'M105', 'M104', 'M109', 'M112', 'M114', 'M115',
'M140', 'M190', 'M106', 'M107', 'M206', 'M400',
'IGNORE', 'QUERY_ENDSTOPS', 'PID_TUNE', 'RESTART', 'FIRMWARE_RESTART',
'STATUS', 'HELP']
'G1', 'G4', 'G28', 'M18', 'M400',
'G20', 'M82', 'M83', 'G90', 'G91', 'G92', 'M114', 'M206', 'M220', 'M221',
'M105', 'M104', 'M109', 'M140', 'M190', 'M106', 'M107',
'M112', 'M115', 'IGNORE', 'QUERY_ENDSTOPS', 'GET_POSITION',
'RESTART', 'FIRMWARE_RESTART', 'ECHO', 'STATUS', 'HELP']
# G-Code movement commands
cmd_G1_aliases = ['G0']
def cmd_G1(self, params):
# Move
try:
for a, p in self.axis2pos.items():
if a in params:
v = float(params[a])
if (not self.absolutecoord
or (p>2 and not self.absoluteextrude)):
for axis in 'XYZ':
if axis in params:
v = float(params[axis])
pos = self.axis2pos[axis]
if not self.absolutecoord:
# value relative to position of last move
self.last_position[p] += v
self.last_position[pos] += v
else:
# value relative to base coordinate position
self.last_position[p] = v + self.base_position[p]
self.last_position[pos] = v + self.base_position[pos]
if 'E' in params:
v = float(params['E']) * self.extrude_factor
if not self.absolutecoord or not self.absoluteextrude:
# value relative to position of last move
self.last_position[3] += v
else:
# value relative to base coordinate position
self.last_position[3] = v + self.base_position[3]
if 'F' in params:
speed = float(params['F']) / 60.
speed = float(params['F']) * self.speed_factor
if speed <= 0.:
raise ValueError()
raise error("Invalid speed in '%s'" % (params['#original'],))
self.speed = speed
except ValueError, e:
self.last_position = self.toolhead.get_position()
except ValueError as e:
raise error("Unable to parse move '%s'" % (params['#original'],))
try:
self.toolhead.move(self.last_position, self.speed)
except homing.EndstopError, e:
self.respond_error(str(e))
self.last_position = self.toolhead.get_position()
self.move_with_transform(self.last_position, self.speed)
except homing.EndstopError as e:
raise error(str(e))
def cmd_G4(self, params):
# Dwell
if 'S' in params:
@@ -274,9 +412,6 @@ class GCodeParser:
else:
delay = self.get_float('P', params, 0.) / 1000.
self.toolhead.dwell(delay)
def cmd_G20(self, params):
# Set units to inches
self.respond_error('Machine does not support G20 (inches) command')
def cmd_G28(self, params):
# Move to origin
axes = []
@@ -285,19 +420,33 @@ class GCodeParser:
axes.append(self.axis2pos[axis])
if not axes:
axes = [0, 1, 2]
homing_state = homing.Homing(self.toolhead, axes)
homing_state = homing.Homing(self.toolhead)
if self.is_fileinput:
homing_state.set_no_verify_retract()
try:
self.toolhead.home(homing_state)
except homing.EndstopError, e:
self.toolhead.motor_off()
self.respond_error(str(e))
return
newpos = self.toolhead.get_position()
homing_state.home_axes(axes)
except homing.EndstopError as e:
raise error(str(e))
for axis in homing_state.get_axes():
self.last_position[axis] = newpos[axis]
self.base_position[axis] = -self.homing_add[axis]
self.reset_last_position()
cmd_M18_aliases = ["M84"]
def cmd_M18(self, params):
# Turn off motors
self.toolhead.motor_off()
def cmd_M400(self, params):
# Wait for current moves to finish
self.toolhead.wait_moves()
# G-Code coordinate manipulation
def cmd_G20(self, params):
# Set units to inches
self.respond_error('Machine does not support G20 (inches) command')
def cmd_M82(self, params):
# Use absolute distances for extrusion
self.absoluteextrude = True
def cmd_M83(self, params):
# Use relative distances for extrusion
self.absoluteextrude = False
def cmd_G90(self, params):
# Use absolute coordinates
self.absolutecoord = True
@@ -309,71 +458,73 @@ class GCodeParser:
offsets = { p: self.get_float(a, params)
for a, p in self.axis2pos.items() if a in params }
for p, offset in offsets.items():
if p == 3:
offset *= self.extrude_factor
self.base_position[p] = self.last_position[p] - offset
if not offsets:
self.base_position = list(self.last_position)
def cmd_M82(self, params):
# Use absolute distances for extrusion
self.absoluteextrude = True
def cmd_M83(self, params):
# Use relative distances for extrusion
self.absoluteextrude = False
cmd_M18_aliases = ["M84"]
def cmd_M18(self, params):
# Turn off motors
self.toolhead.motor_off()
cmd_M105_when_not_ready = True
def cmd_M105(self, params):
# Get Extruder Temperature
self.ack(self.get_temp())
def cmd_M104(self, params):
# Set Extruder Temperature
self.set_temp(self.heater_nozzle, params)
def cmd_M109(self, params):
# Set Extruder Temperature and Wait
self.set_temp(self.heater_nozzle, params, wait=True)
def cmd_M112(self, params):
# Emergency Stop
self.toolhead.force_shutdown()
cmd_M114_when_not_ready = True
def cmd_M114(self, params):
# Get Current Position
if self.toolhead is None:
self.cmd_default(params)
return
kinpos = self.toolhead.get_position()
self.respond("X:%.3f Y:%.3f Z:%.3f E:%.3f Count X:%.3f Y:%.3f Z:%.3f" % (
self.last_position[0], self.last_position[1],
self.last_position[2], self.last_position[3],
kinpos[0], kinpos[1], kinpos[2]))
cmd_M115_when_not_ready = True
def cmd_M115(self, params):
# Get Firmware Version and Capabilities
kw = {"FIRMWARE_NAME": "Klipper"
, "FIRMWARE_VERSION": self.printer.software_version}
self.ack(" ".join(["%s:%s" % (k, v) for k, v in kw.items()]))
p = [lp - bp for lp, bp in zip(self.last_position, self.base_position)]
p[3] /= self.extrude_factor
self.respond("X:%.3f Y:%.3f Z:%.3f E:%.3f" % tuple(p))
def cmd_M206(self, params):
# Set home offset
offsets = { self.axis2pos[a]: self.get_float(a, params)
for a in 'XYZ' if a in params }
for p, offset in offsets.items():
self.base_position[p] += self.homing_add[p] - offset
self.homing_add[p] = offset
def cmd_M220(self, params):
# Set speed factor override percentage
value = self.get_float('S', params, 100.) / (60. * 100.)
if value <= 0.:
raise error("Invalid factor in '%s'" % (params['#original'],))
self.speed_factor = value
def cmd_M221(self, params):
# Set extrude factor override percentage
new_extrude_factor = self.get_float('S', params, 100.) / 100.
if new_extrude_factor <= 0.:
raise error("Invalid factor in '%s'" % (params['#original'],))
last_e_pos = self.last_position[3]
e_value = (last_e_pos - self.base_position[3]) / self.extrude_factor
self.base_position[3] = last_e_pos - e_value * new_extrude_factor
self.extrude_factor = new_extrude_factor
# G-Code temperature and fan commands
cmd_M105_when_not_ready = True
def cmd_M105(self, params):
# Get Extruder Temperature
self.ack(self.get_temp(self.reactor.monotonic()))
def cmd_M104(self, params):
# Set Extruder Temperature
self.set_temp(params)
def cmd_M109(self, params):
# Set Extruder Temperature and Wait
self.set_temp(params, wait=True)
def cmd_M140(self, params):
# Set Bed Temperature
self.set_temp(self.heater_bed, params)
self.set_temp(params, is_bed=True)
def cmd_M190(self, params):
# Set Bed Temperature and Wait
self.set_temp(self.heater_bed, params, wait=True)
self.set_temp(params, is_bed=True, wait=True)
def cmd_M106(self, params):
# Set fan speed
self.set_fan_speed(self.get_float('S', params, 255.) / 255.)
def cmd_M107(self, params):
# Turn fan off
self.set_fan_speed(0.)
def cmd_M206(self, params):
# Set home offset
offsets = { p: self.get_float(a, params)
for a, p in self.axis2pos.items() if a in params }
for p, offset in offsets.items():
self.base_position[p] += self.homing_add[p] - offset
self.homing_add[p] = offset
def cmd_M400(self, params):
# Wait for current moves to finish
self.toolhead.wait_moves()
# G-Code miscellaneous commands
cmd_M112_when_not_ready = True
def cmd_M112(self, params):
# Emergency Stop
self.printer.invoke_shutdown("Shutdown due to M112 command")
cmd_M115_when_not_ready = True
def cmd_M115(self, params):
# Get Firmware Version and Capabilities
software_version = self.printer.get_start_args().get('software_version')
kw = {"FIRMWARE_NAME": "Klipper", "FIRMWARE_VERSION": software_version}
self.ack(" ".join(["%s:%s" % (k, v) for k, v in kw.items()]))
cmd_IGNORE_when_not_ready = True
cmd_IGNORE_aliases = ["G21", "M110", "M21"]
def cmd_IGNORE(self, params):
@@ -383,42 +534,65 @@ class GCodeParser:
cmd_QUERY_ENDSTOPS_aliases = ["M119"]
def cmd_QUERY_ENDSTOPS(self, params):
# Get Endstop Status
if self.is_fileinput:
return
try:
res = self.toolhead.query_endstops()
except self.printer.mcu.error, e:
self.respond_error(str(e))
return
res = homing.query_endstops(self.toolhead)
self.respond(" ".join(["%s:%s" % (name, ["open", "TRIGGERED"][not not t])
for name, t in res]))
cmd_PID_TUNE_help = "Run PID Tuning"
cmd_PID_TUNE_aliases = ["M303"]
def cmd_PID_TUNE(self, params):
# Run PID tuning
heater = self.get_int('E', params, 0)
heater = {0: self.heater_nozzle, -1: self.heater_bed}[heater]
if heater is None:
self.respond_error("Heater not configured")
temp = self.get_float('S', params)
heater.start_auto_tune(temp)
self.bg_temp(heater)
def prep_restart(self):
cmd_GET_POSITION_when_not_ready = True
def cmd_GET_POSITION(self, params):
if self.toolhead is None:
self.cmd_default(params)
return
kin = self.toolhead.get_kinematics()
steppers = kin.get_steppers()
mcu_pos = " ".join(["%s:%d" % (s.name, s.mcu_stepper.get_mcu_position())
for s in steppers])
stepper_pos = " ".join(
["%s:%.6f" % (s.name, s.mcu_stepper.get_commanded_position())
for s in steppers])
kinematic_pos = " ".join(["%s:%.6f" % (a, v)
for a, v in zip("XYZE", kin.get_position())])
toolhead_pos = " ".join(["%s:%.6f" % (a, v) for a, v in zip(
"XYZE", self.toolhead.get_position())])
gcode_pos = " ".join(["%s:%.6f" % (a, v)
for a, v in zip("XYZE", self.last_position)])
origin_pos = " ".join(["%s:%.6f" % (a, v)
for a, v in zip("XYZE", self.base_position)])
homing_pos = " ".join(["%s:%.6f" % (a, v)
for a, v in zip("XYZE", self.homing_add)])
self.respond_info(
"mcu: %s\n"
"stepper: %s\n"
"kinematic: %s\n"
"toolhead: %s\n"
"gcode: %s\n"
"gcode origin: %s\n"
"gcode homing: %s" % (
mcu_pos, stepper_pos, kinematic_pos, toolhead_pos,
gcode_pos, origin_pos, homing_pos))
def request_restart(self, result):
if self.is_printer_ready:
self.respond_info("Preparing to restart...")
self.motor_heater_off()
self.toolhead.motor_off()
print_time = self.toolhead.get_last_move_time()
for heater in self.heaters:
if heater is not None:
heater.set_temp(print_time, 0.)
if self.fan is not None:
self.fan.set_speed(print_time, 0.)
self.toolhead.dwell(0.500)
self.toolhead.wait_moves()
self.printer.request_exit(result)
cmd_RESTART_when_not_ready = True
cmd_RESTART_help = "Reload config file and restart host software"
def cmd_RESTART(self, params):
self.prep_restart()
self.printer.request_exit('restart')
self.request_restart('restart')
cmd_FIRMWARE_RESTART_when_not_ready = True
cmd_FIRMWARE_RESTART_help = "Restart firmware, host, and reload config"
def cmd_FIRMWARE_RESTART(self, params):
self.prep_restart()
self.printer.request_exit('firmware_restart')
self.request_restart('firmware_restart')
cmd_ECHO_when_not_ready = True
def cmd_ECHO(self, params):
self.respond_info(params['#original'])
cmd_STATUS_when_not_ready = True
cmd_STATUS_help = "Report the printer status"
def cmd_STATUS(self, params):
@@ -434,10 +608,6 @@ class GCodeParser:
cmdhelp.append("Printer is not ready - not all commands available.")
cmdhelp.append("Available extended commands:")
for cmd in sorted(self.gcode_handlers):
desc = getattr(self, 'cmd_'+cmd+'_help', None)
if desc is not None:
cmdhelp.append("%-10s: %s" % (cmd, desc))
if cmd in self.gcode_help:
cmdhelp.append("%-10s: %s" % (cmd, self.gcode_help[cmd]))
self.respond_info("\n".join(cmdhelp))
class error(Exception):
pass

View File

@@ -1,31 +1,106 @@
# Printer heater support
#
# Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
# Copyright (C) 2016-2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import math, logging, threading
import pins
######################################################################
# Sensors
######################################################################
KELVIN_TO_CELCIUS = -273.15
# Thermistor calibrated with three temp measurements
class Thermistor:
def __init__(self, config, params):
self.pullup = config.getfloat('pullup_resistor', 4700., above=0.)
# Calculate Steinhart-Hart coefficents from temp measurements.
# Arrange samples as 3 linear equations and solve for c1, c2, and c3.
inv_t1 = 1. / (params['t1'] - KELVIN_TO_CELCIUS)
inv_t2 = 1. / (params['t2'] - KELVIN_TO_CELCIUS)
inv_t3 = 1. / (params['t3'] - KELVIN_TO_CELCIUS)
ln_r1 = math.log(params['r1'])
ln_r2 = math.log(params['r2'])
ln_r3 = math.log(params['r3'])
ln3_r1, ln3_r2, ln3_r3 = ln_r1**3, ln_r2**3, ln_r3**3
inv_t12, inv_t13 = inv_t1 - inv_t2, inv_t1 - inv_t3
ln_r12, ln_r13 = ln_r1 - ln_r2, ln_r1 - ln_r3
ln3_r12, ln3_r13 = ln3_r1 - ln3_r2, ln3_r1 - ln3_r3
self.c3 = ((inv_t12 - inv_t13 * ln_r12 / ln_r13)
/ (ln3_r12 - ln3_r13 * ln_r12 / ln_r13))
self.c2 = (inv_t12 - self.c3 * ln3_r12) / ln_r12
self.c1 = inv_t1 - self.c2 * ln_r1 - self.c3 * ln3_r1
def calc_temp(self, adc):
adc = max(.00001, min(.99999, adc))
r = self.pullup * adc / (1.0 - adc)
ln_r = math.log(r)
inv_t = self.c1 + self.c2 * ln_r + self.c3 * ln_r**3
return 1.0/inv_t + KELVIN_TO_CELCIUS
def calc_adc(self, temp):
inv_t = 1. / (temp - KELVIN_TO_CELCIUS)
if self.c3:
# Solve for ln_r using Cardano's formula
y = (self.c1 - inv_t) / (2. * self.c3)
x = math.sqrt((self.c2 / (3. * self.c3))**3 + y**2)
ln_r = math.pow(x - y, 1./3.) - math.pow(x + y, 1./3.)
else:
ln_r = (inv_t - self.c1) / self.c2
r = math.exp(ln_r)
return r / (self.pullup + r)
# Thermistor calibrated from one temp measurement and its beta
class ThermistorBeta(Thermistor):
def __init__(self, config, params):
self.pullup = config.getfloat('pullup_resistor', 4700., above=0.)
# Calculate Steinhart-Hart coefficents from beta
inv_t1 = 1. / (params['t1'] - KELVIN_TO_CELCIUS)
ln_r1 = math.log(params['r1'])
self.c3 = 0.
self.c2 = 1. / params['beta']
self.c1 = inv_t1 - self.c2 * ln_r1
# Linear style conversion chips calibrated with two temp measurements
class Linear:
def __init__(self, config, params):
adc_voltage = config.getfloat('adc_voltage', 5., above=0.)
slope = (params['t2'] - params['t1']) / (params['v2'] - params['v1'])
self.gain = adc_voltage * slope
self.offset = params['t1'] - params['v1'] * slope
def calc_temp(self, adc):
return adc * self.gain + self.offset
def calc_adc(self, temp):
return (temp - self.offset) / self.gain
# Available sensors
Sensors = {
# Common thermistors and their Steinhart-Hart coefficients
"EPCOS 100K B57560G104F": (
"thermistor",
0.000722136308968056, 0.000216766566488498, 8.92935804531095e-08),
"ATC Semitec 104GT-2": (
"thermistor",
0.000809651054275124, 0.000211636030735685, 7.07420883993973e-08),
# Linear style conversion chips and their gain/offset
"AD595": ("linear", 300.0 / 3.022, 0.),
"EPCOS 100K B57560G104F": {
'class': Thermistor, 't1': 25., 'r1': 100000.,
't2': 150., 'r2': 1641.9, 't3': 250., 'r3': 226.15 },
"ATC Semitec 104GT-2": {
'class': Thermistor, 't1': 20., 'r1': 126800.,
't2': 150., 'r2': 1360., 't3': 300., 'r3': 80.65 },
"NTC 100K beta 3950": {
'class': ThermistorBeta, 't1': 25., 'r1': 100000., 'beta': 3950. },
"AD595": { 'class': Linear, 't1': 25., 'v1': .25, 't2': 300., 'v2': 3.022 },
}
######################################################################
# Heater
######################################################################
SAMPLE_TIME = 0.001
SAMPLE_COUNT = 8
REPORT_TIME = 0.300
PWM_CYCLE_TIME = 0.100
KELVIN_TO_CELCIUS = -273.15
MAX_HEAT_TIME = 5.0
AMBIENT_TEMP = 25.
PID_PARAM_BASE = 255.
PWM_DELAY = REPORT_TIME + SAMPLE_TIME*SAMPLE_COUNT
class error(Exception):
pass
@@ -33,22 +108,15 @@ class error(Exception):
class PrinterHeater:
error = error
def __init__(self, printer, config):
self.name = config.section
self.printer = printer
self.name = config.get_name()
sensor_params = config.getchoice('sensor_type', Sensors)
self.is_linear_sensor = (sensor_params[0] == 'linear')
if self.is_linear_sensor:
adc_voltage = config.getfloat('adc_voltage', 5., above=0.)
self.sensor_coef = sensor_params[1] * adc_voltage, sensor_params[2]
else:
pullup = config.getfloat('pullup_resistor', 4700., above=0.)
self.sensor_coef = sensor_params[1:] + (pullup,)
self.min_temp = config.getfloat('min_temp', minval=0.)
self.sensor = sensor_params['class'](config, sensor_params)
self.min_temp = config.getfloat('min_temp', minval=KELVIN_TO_CELCIUS)
self.max_temp = config.getfloat('max_temp', above=self.min_temp)
self.min_extrude_temp = config.getfloat(
'min_extrude_temp', 170., minval=self.min_temp, maxval=self.max_temp)
self.max_power = config.getfloat('max_power', 1., above=0., maxval=1.)
self.can_extrude = (self.min_extrude_temp <= 0.
or printer.mcu.is_fileoutput())
self.lock = threading.Lock()
self.last_temp = 0.
self.last_temp_time = 0.
@@ -56,22 +124,29 @@ class PrinterHeater:
algos = {'watermark': ControlBangBang, 'pid': ControlPID}
algo = config.getchoice('control', algos)
heater_pin = config.get('heater_pin')
sensor_pin = config.get('sensor_pin')
if algo is ControlBangBang and self.max_power == 1.:
self.mcu_pwm = printer.mcu.create_digital_out(
heater_pin, MAX_HEAT_TIME)
self.mcu_pwm = pins.setup_pin(printer, 'digital_out', heater_pin)
else:
self.mcu_pwm = printer.mcu.create_pwm(
heater_pin, PWM_CYCLE_TIME, 0, MAX_HEAT_TIME)
self.mcu_adc = printer.mcu.create_adc(sensor_pin)
adc_range = [self.calc_adc(self.min_temp), self.calc_adc(self.max_temp)]
self.mcu_adc.set_minmax(SAMPLE_TIME, SAMPLE_COUNT,
self.mcu_pwm = pins.setup_pin(printer, 'pwm', heater_pin)
pwm_cycle_time = config.getfloat(
'pwm_cycle_time', 0.100, above=0., maxval=REPORT_TIME)
self.mcu_pwm.setup_cycle_time(pwm_cycle_time)
self.mcu_pwm.setup_max_duration(MAX_HEAT_TIME)
self.mcu_adc = pins.setup_pin(printer, 'adc', config.get('sensor_pin'))
adc_range = [self.sensor.calc_adc(self.min_temp),
self.sensor.calc_adc(self.max_temp)]
self.mcu_adc.setup_minmax(SAMPLE_TIME, SAMPLE_COUNT,
minval=min(adc_range), maxval=max(adc_range))
self.mcu_adc.set_adc_callback(REPORT_TIME, self.adc_callback)
self.mcu_adc.setup_adc_callback(REPORT_TIME, self.adc_callback)
is_fileoutput = self.mcu_adc.get_mcu().is_fileoutput()
self.can_extrude = self.min_extrude_temp <= 0. or is_fileoutput
self.control = algo(self, config)
# pwm caching
self.next_pwm_time = 0.
self.last_pwm_value = 0
self.last_pwm_value = 0.
# Load additional modules
printer.try_load_module(config, "verify_heater %s" % (self.name,))
printer.try_load_module(config, "pid_calibrate")
def set_pwm(self, read_time, value):
if self.target_temp <= 0.:
value = 0.
@@ -79,44 +154,21 @@ class PrinterHeater:
and abs(value - self.last_pwm_value) < 0.05):
# No significant change in value - can suppress update
return
pwm_time = read_time + REPORT_TIME + SAMPLE_TIME*SAMPLE_COUNT
pwm_time = read_time + PWM_DELAY
self.next_pwm_time = pwm_time + 0.75 * MAX_HEAT_TIME
self.last_pwm_value = value
logging.debug("%s: pwm=%.3f@%.3f (from %.3f@%.3f [%.3f])" % (
logging.debug("%s: pwm=%.3f@%.3f (from %.3f@%.3f [%.3f])",
self.name, value, pwm_time,
self.last_temp, self.last_temp_time, self.target_temp))
self.last_temp, self.last_temp_time, self.target_temp)
self.mcu_pwm.set_pwm(pwm_time, value)
# Temperature calculation
def calc_temp(self, adc):
if self.is_linear_sensor:
gain, offset = self.sensor_coef
return adc * gain + offset
c1, c2, c3, pullup = self.sensor_coef
r = pullup * adc / (1.0 - adc)
ln_r = math.log(r)
temp_inv = c1 + c2*ln_r + c3*math.pow(ln_r, 3)
return 1.0/temp_inv + KELVIN_TO_CELCIUS
def calc_adc(self, temp):
if temp is None:
return None
if self.is_linear_sensor:
gain, offset = self.sensor_coef
return (temp - offset) / gain
c1, c2, c3, pullup = self.sensor_coef
temp -= KELVIN_TO_CELCIUS
temp_inv = 1./temp
y = (c1 - temp_inv) / (2*c3)
x = math.sqrt(math.pow(c2 / (3.*c3), 3.) + math.pow(y, 2.))
r = math.exp(math.pow(x-y, 1./3.) - math.pow(x+y, 1./3.))
return r / (pullup + r)
def adc_callback(self, read_time, read_value):
temp = self.calc_temp(read_value)
temp = self.sensor.calc_temp(read_value)
with self.lock:
self.last_temp = temp
self.last_temp_time = read_time
self.can_extrude = (temp >= self.min_extrude_temp)
self.control.adc_callback(read_time, temp)
#logging.debug("temp: %.3f %f = %f" % (read_time, read_value, temp))
#logging.debug("temp: %.3f %f = %f", read_time, read_value, temp)
# External commands
def set_temp(self, print_time, degrees):
if degrees and (degrees < self.min_temp or degrees > self.max_temp):
@@ -124,15 +176,34 @@ class PrinterHeater:
% (degrees, self.min_temp, self.max_temp))
with self.lock:
self.target_temp = degrees
def get_temp(self):
def get_temp(self, eventtime):
print_time = self.mcu_adc.get_mcu().estimated_print_time(eventtime) - 5.
with self.lock:
if self.last_temp_time < print_time:
return 0., self.target_temp
return self.last_temp, self.target_temp
def check_busy(self, eventtime):
with self.lock:
return self.control.check_busy(eventtime)
def start_auto_tune(self, temp):
def set_control(self, control):
with self.lock:
self.control = ControlAutoTune(self, self.control, temp)
old_control = self.control
self.control = control
self.target_temp = 0.
return old_control
def stats(self, eventtime):
with self.lock:
target_temp = self.target_temp
last_temp = self.last_temp
last_pwm_value = self.last_pwm_value
is_active = target_temp or last_temp > 50.
return is_active, '%s: target=%.0f temp=%.1f pwm=%.3f' % (
self.name, target_temp, last_temp, last_pwm_value)
def get_status(self, eventtime):
with self.lock:
target_temp = self.target_temp
last_temp = self.last_temp
return {'temperature': last_temp, 'target': target_temp}
######################################################################
@@ -161,6 +232,9 @@ class ControlBangBang:
# Proportional Integral Derivative (PID) control algo
######################################################################
PID_SETTLE_DELTA = 1.
PID_SETTLE_SLOPE = .1
class ControlPID:
def __init__(self, heater, config):
self.heater = heater
@@ -189,8 +263,8 @@ class ControlPID:
temp_integ = max(0., min(self.temp_integ_max, temp_integ))
# Calculate output
co = self.Kp*temp_err + self.Ki*temp_integ - self.Kd*temp_deriv
#logging.debug("pid: %f@%.3f -> diff=%f deriv=%f err=%f integ=%f co=%d" % (
# temp, read_time, temp_diff, temp_deriv, temp_err, temp_integ, co))
#logging.debug("pid: %f@%.3f -> diff=%f deriv=%f err=%f integ=%f co=%d",
# temp, read_time, temp_diff, temp_deriv, temp_err, temp_integ, co)
bounded_co = max(0., min(self.heater.max_power, co))
self.heater.set_pwm(read_time, bounded_co)
# Store state for next measurement
@@ -201,110 +275,10 @@ class ControlPID:
self.prev_temp_integ = temp_integ
def check_busy(self, eventtime):
temp_diff = self.heater.target_temp - self.heater.last_temp
return abs(temp_diff) > 1. or abs(self.prev_temp_deriv) > 0.1
return (abs(temp_diff) > PID_SETTLE_DELTA
or abs(self.prev_temp_deriv) > PID_SETTLE_SLOPE)
######################################################################
# Ziegler-Nichols PID autotuning
######################################################################
TUNE_PID_DELTA = 5.0
class ControlAutoTune:
def __init__(self, heater, old_control, target_temp):
self.heater = heater
self.old_control = old_control
self.target_temp = target_temp
self.heating = False
self.peaks = []
self.peak = 0.
self.peak_time = 0.
def adc_callback(self, read_time, temp):
if self.heating and temp >= self.target_temp:
self.heating = False
self.check_peaks()
elif not self.heating and temp <= self.target_temp - TUNE_PID_DELTA:
self.heating = True
self.check_peaks()
if self.heating:
self.heater.set_pwm(read_time, self.heater.max_power)
if temp < self.peak:
self.peak = temp
self.peak_time = read_time
else:
self.heater.set_pwm(read_time, 0.)
if temp > self.peak:
self.peak = temp
self.peak_time = read_time
def check_peaks(self):
self.peaks.append((self.peak, self.peak_time))
if self.heating:
self.peak = 9999999.
else:
self.peak = -9999999.
if len(self.peaks) < 4:
return
temp_diff = self.peaks[-1][0] - self.peaks[-2][0]
time_diff = self.peaks[-1][1] - self.peaks[-3][1]
max_power = self.heater.max_power
Ku = 4. * (2. * max_power) / (abs(temp_diff) * math.pi)
Tu = time_diff
Kp = 0.6 * Ku
Ti = 0.5 * Tu
Td = 0.125 * Tu
Ki = Kp / Ti
Kd = Kp * Td
logging.info("Autotune: raw=%f/%f Ku=%f Tu=%f Kp=%f Ki=%f Kd=%f" % (
temp_diff, max_power, Ku, Tu,
Kp * PID_PARAM_BASE, Ki * PID_PARAM_BASE, Kd * PID_PARAM_BASE))
def check_busy(self, eventtime):
if self.heating or len(self.peaks) < 12:
return True
self.heater.control = self.old_control
return False
######################################################################
# Tuning information test
######################################################################
class ControlBumpTest:
def __init__(self, heater, old_control, target_temp):
self.heater = heater
self.old_control = old_control
self.target_temp = target_temp
self.temp_samples = {}
self.pwm_samples = {}
self.state = 0
def set_pwm(self, read_time, value):
self.pwm_samples[read_time + 2*REPORT_TIME] = value
self.heater.set_pwm(read_time, value)
def adc_callback(self, read_time, temp):
self.temp_samples[read_time] = temp
if not self.state:
self.set_pwm(read_time, 0.)
if len(self.temp_samples) >= 20:
self.state += 1
elif self.state == 1:
if temp < self.target_temp:
self.set_pwm(read_time, self.heater.max_power)
return
self.set_pwm(read_time, 0.)
self.state += 1
elif self.state == 2:
self.set_pwm(read_time, 0.)
if temp <= (self.target_temp + AMBIENT_TEMP) / 2.:
self.dump_stats()
self.state += 1
def dump_stats(self):
out = ["%.3f %.1f %d" % (time, temp, self.pwm_samples.get(time, -1.))
for time, temp in sorted(self.temp_samples.items())]
f = open("/tmp/heattest.txt", "wb")
f.write('\n'.join(out))
f.close()
def check_busy(self, eventtime):
if self.state < 3:
return True
self.heater.control = self.old_control
return False
def add_printer_objects(printer, config):
if config.has_section('heater_bed'):
printer.add_object('heater_bed', PrinterHeater(
printer, config.getsection('heater_bed')))

View File

@@ -1,14 +1,18 @@
# Code for state tracking during homing operations
#
# Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
# Copyright (C) 2016,2017 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging
import logging, math
HOMING_STEP_DELAY = 0.00000025
ENDSTOP_SAMPLE_TIME = .000015
ENDSTOP_SAMPLE_COUNT = 4
class Homing:
def __init__(self, toolhead, changed_axes):
def __init__(self, toolhead):
self.toolhead = toolhead
self.changed_axes = changed_axes
self.changed_axes = []
self.verify_retract = True
def set_no_verify_retract(self):
self.verify_retract = False
@@ -25,33 +29,99 @@ class Homing:
return thcoord
def retract(self, newpos, speed):
self.toolhead.move(self._fill_coord(newpos), speed)
def home(self, forcepos, movepos, steppers, speed, second_home=False):
# Alter kinematics class to think printer is at forcepos
self.toolhead.set_position(self._fill_coord(forcepos))
# Start homing and issue move
print_time = self.toolhead.get_last_move_time()
endstops = []
for s in steppers:
es = s.enable_endstop_checking(print_time, s.step_dist / speed)
endstops.append((s, es, s.mcu_stepper.get_mcu_position()))
self.toolhead.move(self._fill_coord(movepos), speed)
move_end_print_time = self.toolhead.get_last_move_time()
self.toolhead.reset_print_time()
for s, es, last_pos in endstops:
es.home_finalize(es.print_to_mcu_time(move_end_print_time))
# Wait for endstops to trigger
for s, es, last_pos in endstops:
try:
es.home_wait()
except es.error, e:
raise EndstopError("Failed to home stepper %s: %s" % (
s.name, str(e)))
post_home_pos = s.mcu_stepper.get_mcu_position()
if second_home and self.verify_retract and last_pos == post_home_pos:
raise EndstopError("Endstop %s still triggered after retract" % (
s.name,))
def set_homed_position(self, pos):
self.toolhead.set_position(self._fill_coord(pos))
def _get_homing_speed(self, speed, endstops):
# Round the requested homing speed so that it is an even
# number of ticks per step.
speed = min(speed, self.toolhead.get_max_velocity()[0])
mcu_stepper = endstops[0][0].get_steppers()[0]
adjusted_freq = mcu_stepper.get_mcu().get_adjusted_freq()
dist_ticks = adjusted_freq * mcu_stepper.get_step_dist()
ticks_per_step = math.ceil(dist_ticks / speed)
return dist_ticks / ticks_per_step
def homing_move(self, movepos, endstops, speed, probe_pos=False):
# Start endstop checking
for mcu_endstop, name in endstops:
mcu_endstop.home_prepare()
print_time = self.toolhead.get_last_move_time()
for mcu_endstop, name in endstops:
min_step_dist = min([s.get_step_dist()
for s in mcu_endstop.get_steppers()])
mcu_endstop.home_start(
print_time, ENDSTOP_SAMPLE_TIME, ENDSTOP_SAMPLE_COUNT,
min_step_dist / speed)
# Issue move
movepos = self._fill_coord(movepos)
error = None
try:
self.toolhead.move(movepos, speed)
except EndstopError as e:
error = "Error during homing move: %s" % (str(e),)
# Wait for endstops to trigger
move_end_print_time = self.toolhead.get_last_move_time()
self.toolhead.reset_print_time(print_time)
for mcu_endstop, name in endstops:
try:
mcu_endstop.home_wait(move_end_print_time)
except mcu_endstop.TimeoutError as e:
if error is None:
error = "Failed to home %s: %s" % (name, str(e))
if probe_pos:
self.set_homed_position(
list(self.toolhead.get_kinematics().get_position()) + [None])
else:
self.toolhead.set_position(movepos)
for mcu_endstop, name in endstops:
mcu_endstop.home_finalize()
if error is not None:
raise EndstopError(error)
def home(self, forcepos, movepos, endstops, speed, second_home=False):
if second_home and forcepos == movepos:
return
# Alter kinematics class to think printer is at forcepos
homing_axes = [axis for axis in range(3) if forcepos[axis] is not None]
self.toolhead.set_position(
self._fill_coord(forcepos), homing_axes=homing_axes)
# Add a CPU delay when homing a large axis
if not second_home:
est_move_d = sum([abs(forcepos[i]-movepos[i])
for i in range(3) if movepos[i] is not None])
est_steps = sum([est_move_d / s.get_step_dist()
for es, n in endstops for s in es.get_steppers()])
self.toolhead.dwell(est_steps * HOMING_STEP_DELAY, check_stall=False)
speed = self._get_homing_speed(speed, endstops)
# Setup for retract verification
self.toolhead.get_last_move_time()
start_mcu_pos = [(s, name, s.get_mcu_position())
for es, name in endstops for s in es.get_steppers()]
# Issue homing move
self.homing_move(movepos, endstops, speed)
# Verify retract led to some movement on second home
if second_home and self.verify_retract:
for s, name, pos in start_mcu_pos:
if s.get_mcu_position() == pos:
raise EndstopError(
"Endstop %s still triggered after retract" % (name,))
def home_axes(self, axes):
self.changed_axes = axes
try:
self.toolhead.get_kinematics().home(self)
except EndstopError:
self.toolhead.motor_off()
raise
def query_endstops(toolhead):
print_time = toolhead.get_last_move_time()
steppers = toolhead.get_kinematics().get_steppers()
out = []
for s in steppers:
for mcu_endstop, name in s.get_endstops():
mcu_endstop.query_endstop(print_time)
for s in steppers:
for mcu_endstop, name in s.get_endstops():
out.append((name, mcu_endstop.query_endstop_wait()))
return out
class EndstopError(Exception):
pass

View File

@@ -1,19 +1,20 @@
#!/usr/bin/env python
#!/usr/bin/env python2
# Main code for host side printer firmware
#
# Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
# Copyright (C) 2016-2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import sys, optparse, ConfigParser, logging, time, threading
import gcode, toolhead, util, mcu, fan, heater, extruder, reactor, queuelogger
import msgproto
import sys, os, optparse, logging, time, threading
import collections, ConfigParser, importlib
import util, reactor, queuelogger, msgproto
import gcode, pins, mcu, toolhead, extruder, heater
message_ready = "Printer is ready"
message_startup = """
Printer is not ready
The klippy host software is attempting to connect. Please
retry in a few moments.
Printer is not ready
"""
message_restart = """
@@ -49,19 +50,24 @@ class ConfigWrapper:
error = ConfigParser.Error
class sentinel:
pass
def __init__(self, printer, section):
def __init__(self, printer, fileconfig, section):
self.printer = printer
self.fileconfig = fileconfig
self.section = section
def get_wrapper(self, parser, option, default
, minval=None, maxval=None, above=None, below=None):
def get_printer(self):
return self.printer
def get_name(self):
return self.section
def _get_wrapper(self, parser, option, default,
minval=None, maxval=None, above=None, below=None):
if (default is not self.sentinel
and not self.printer.fileconfig.has_option(self.section, option)):
and not self.fileconfig.has_option(self.section, option)):
return default
self.printer.all_config_options[
(self.section.lower(), option.lower())] = 1
try:
v = parser(self.section, option)
except self.error, e:
except self.error as e:
raise
except:
raise self.error("Unable to parse option '%s' in section '%s'" % (
@@ -84,18 +90,16 @@ class ConfigWrapper:
option, self.section, below))
return v
def get(self, option, default=sentinel):
return self.get_wrapper(self.printer.fileconfig.get, option, default)
return self._get_wrapper(self.fileconfig.get, option, default)
def getint(self, option, default=sentinel, minval=None, maxval=None):
return self.get_wrapper(
self.printer.fileconfig.getint, option, default, minval, maxval)
def getfloat(self, option, default=sentinel
, minval=None, maxval=None, above=None, below=None):
return self.get_wrapper(
self.printer.fileconfig.getfloat, option, default
, minval, maxval, above, below)
return self._get_wrapper(
self.fileconfig.getint, option, default, minval, maxval)
def getfloat(self, option, default=sentinel,
minval=None, maxval=None, above=None, below=None):
return self._get_wrapper(self.fileconfig.getfloat, option, default,
minval, maxval, above, below)
def getboolean(self, option, default=sentinel):
return self.get_wrapper(
self.printer.fileconfig.getboolean, option, default)
return self._get_wrapper(self.fileconfig.getboolean, option, default)
def getchoice(self, option, choices, default=sentinel):
c = self.get(option, default)
if c not in choices:
@@ -104,7 +108,12 @@ class ConfigWrapper:
option, self.section))
return choices[c]
def getsection(self, section):
return ConfigWrapper(self.printer, section)
return ConfigWrapper(self.printer, self.fileconfig, section)
def has_section(self, section):
return self.fileconfig.has_section(section)
def get_prefix_sections(self, prefix):
return [self.getsection(s) for s in self.fileconfig.sections()
if s.startswith(prefix)]
class ConfigLogger():
def __init__(self, cfg, bglogger):
@@ -118,149 +127,174 @@ class ConfigLogger():
self.lines.append(data.strip())
class Printer:
def __init__(self, conffile, input_fd, startup_state
, is_fileinput=False, version="?", bglogger=None):
self.conffile = conffile
self.startup_state = startup_state
self.software_version = version
config_error = ConfigParser.Error
def __init__(self, input_fd, bglogger, start_args):
self.bglogger = bglogger
self.start_args = start_args
if bglogger is not None:
bglogger.set_rollover_info("config", None)
self.reactor = reactor.Reactor()
self.objects = {}
self.gcode = gcode.GCodeParser(self, input_fd, is_fileinput)
self.stats_timer = self.reactor.register_timer(self.stats)
gc = gcode.GCodeParser(self, input_fd)
self.objects = collections.OrderedDict({'gcode': gc})
self.stats_timer = self.reactor.register_timer(self._stats)
self.connect_timer = self.reactor.register_timer(
self.connect, self.reactor.NOW)
self._connect, self.reactor.NOW)
self.all_config_options = {}
self.need_dump_debug = False
self.state_message = message_startup
self.debugoutput = self.dictionary = None
self.is_shutdown = False
self.async_shutdown_msg = ""
self.run_result = None
self.fileconfig = None
self.mcu = None
def set_fileoutput(self, debugoutput, dictionary):
self.debugoutput = debugoutput
self.dictionary = dictionary
def stats(self, eventtime, force_output=False):
if self.need_dump_debug:
# Call dump_debug here so it is executed in the main thread
self.gcode.dump_debug()
self.need_dump_debug = False
toolhead = self.objects.get('toolhead')
if toolhead is None or self.mcu is None:
return
is_active, thstats = toolhead.stats(eventtime)
if not is_active and not force_output:
return
out = []
out.append(self.gcode.stats(eventtime))
out.append(thstats)
out.append(self.mcu.stats(eventtime))
logging.info("Stats %.1f: %s" % (eventtime, ' '.join(out)))
return eventtime + 1.
def load_config(self):
self.fileconfig = ConfigParser.RawConfigParser()
res = self.fileconfig.read(self.conffile)
if not res:
raise ConfigParser.Error("Unable to open config file %s" % (
self.conffile,))
self.stats_cb = []
self.state_cb = []
def get_start_args(self):
return self.start_args
def get_reactor(self):
return self.reactor
def get_state_message(self):
return self.state_message
def add_object(self, name, obj):
if obj in self.objects:
raise self.config_error(
"Printer object '%s' already created" % (name,))
self.objects[name] = obj
def lookup_object(self, name, default=ConfigWrapper.sentinel):
if name in self.objects:
return self.objects[name]
if default is ConfigWrapper.sentinel:
raise self.config_error("Unknown config object '%s'" % (name,))
return default
def lookup_module_objects(self, module_name):
prefix = module_name + ' '
objs = [self.objects[n] for n in self.objects if n.startswith(prefix)]
if module_name in self.objects:
return [self.objects[module_name]] + objs
return objs
def set_rollover_info(self, name, info):
if self.bglogger is not None:
ConfigLogger(self.fileconfig, self.bglogger)
self.mcu = mcu.MCU(self, ConfigWrapper(self, 'mcu'))
if self.debugoutput is not None:
self.mcu.connect_file(self.debugoutput, self.dictionary)
if self.fileconfig.has_section('extruder'):
self.objects['extruder'] = extruder.PrinterExtruder(
self, ConfigWrapper(self, 'extruder'))
if self.fileconfig.has_section('fan'):
self.objects['fan'] = fan.PrinterFan(
self, ConfigWrapper(self, 'fan'))
if self.fileconfig.has_section('heater_bed'):
self.objects['heater_bed'] = heater.PrinterHeater(
self, ConfigWrapper(self, 'heater_bed'))
self.objects['toolhead'] = toolhead.ToolHead(
self, ConfigWrapper(self, 'printer'))
self.bglogger.set_rollover_info(name, info)
def _stats(self, eventtime, force_output=False):
stats = [cb(eventtime) for cb in self.stats_cb]
if max([s[0] for s in stats] + [force_output]):
logging.info("Stats %.1f: %s", eventtime,
' '.join([s[1] for s in stats]))
return eventtime + 1.
def try_load_module(self, config, section):
if section in self.objects:
return
module_parts = section.split()
module_name = module_parts[0]
py_name = os.path.join(os.path.dirname(__file__),
'extras', module_name + '.py')
if not os.path.exists(py_name):
return
mod = importlib.import_module('extras.' + module_name)
init_func = 'load_config'
if len(module_parts) > 1:
init_func = 'load_config_prefix'
init_func = getattr(mod, init_func, None)
if init_func is not None:
self.objects[section] = init_func(config.getsection(section))
def _read_config(self):
fileconfig = ConfigParser.RawConfigParser()
config_file = self.start_args['config_file']
res = fileconfig.read(config_file)
if not res:
raise self.config_error("Unable to open config file %s" % (
config_file,))
if self.bglogger is not None:
ConfigLogger(fileconfig, self.bglogger)
# Create printer components
config = ConfigWrapper(self, fileconfig, 'printer')
for m in [pins, mcu]:
m.add_printer_objects(self, config)
for section in fileconfig.sections():
self.try_load_module(config, section)
for m in [toolhead, extruder, heater]:
m.add_printer_objects(self, config)
# Validate that there are no undefined parameters in the config file
valid_sections = dict([(s, 1) for s, o in self.all_config_options])
for section in self.fileconfig.sections():
valid_sections = { s: 1 for s, o in self.all_config_options }
for section in fileconfig.sections():
section = section.lower()
if section not in valid_sections:
raise ConfigParser.Error("Unknown config file section '%s'" % (
if section not in valid_sections and section not in self.objects:
raise self.config_error("Unknown config file section '%s'" % (
section,))
for option in self.fileconfig.options(section):
for option in fileconfig.options(section):
option = option.lower()
if (section, option) not in self.all_config_options:
raise ConfigParser.Error(
raise self.config_error(
"Unknown option '%s' in section '%s'" % (
option, section))
def connect(self, eventtime):
# Determine which printer objects have stats/state callbacks
self.stats_cb = [o.stats for o in self.objects.values()
if hasattr(o, 'stats')]
self.state_cb = [o.printer_state for o in self.objects.values()
if hasattr(o, 'printer_state')]
def _connect(self, eventtime):
self.reactor.unregister_timer(self.connect_timer)
try:
self.load_config()
if self.debugoutput is None:
self.reactor.update_timer(self.stats_timer, self.reactor.NOW)
self.mcu.connect()
self.gcode.set_printer_ready(True)
self._read_config()
for cb in self.state_cb:
if self.state_message is not message_startup:
return self.reactor.NEVER
cb('connect')
self.state_message = message_ready
except ConfigParser.Error, e:
for cb in self.state_cb:
if self.state_message is not message_ready:
return self.reactor.NEVER
cb('ready')
if self.start_args.get('debugoutput') is None:
self.reactor.update_timer(self.stats_timer, self.reactor.NOW)
except (self.config_error, pins.error) as e:
logging.exception("Config error")
self.state_message = "%s%s" % (str(e), message_restart)
self.reactor.update_timer(self.stats_timer, self.reactor.NEVER)
except msgproto.error, e:
except msgproto.error as e:
logging.exception("Protocol error")
self.state_message = "%s%s" % (str(e), message_protocol_error)
self.reactor.update_timer(self.stats_timer, self.reactor.NEVER)
except mcu.error, e:
except mcu.error as e:
logging.exception("MCU error during connect")
self.state_message = "%s%s" % (str(e), message_mcu_connect_error)
self.reactor.update_timer(self.stats_timer, self.reactor.NEVER)
except:
logging.exception("Unhandled exception during connect")
self.state_message = "Internal error during connect.%s" % (
message_restart)
self.reactor.update_timer(self.stats_timer, self.reactor.NEVER)
self.reactor.unregister_timer(self.connect_timer)
message_restart,)
return self.reactor.NEVER
def run(self):
systime = time.time()
monotime = self.reactor.monotonic()
logging.info("Start printer at %s (%.1f %.1f)" % (
time.asctime(time.localtime(systime)), systime, monotime))
logging.info("Start printer at %s (%.1f %.1f)",
time.asctime(time.localtime(systime)), systime, monotime)
while 1:
# Enter main reactor loop
try:
self.reactor.run()
except:
logging.exception("Unhandled exception during run")
return "exit"
# Check restart flags
run_result = self.run_result
try:
if run_result == 'shutdown':
self.invoke_shutdown(self.async_shutdown_msg)
continue
self._stats(self.reactor.monotonic(), force_output=True)
if run_result == 'firmware_restart':
for m in self.lookup_module_objects('mcu'):
m.microcontroller_restart()
for cb in self.state_cb:
cb('disconnect')
except:
logging.exception("Unhandled exception during post run")
return run_result
def invoke_shutdown(self, msg):
if self.is_shutdown:
return
return self.run_result
def get_state_message(self):
return self.state_message
def note_shutdown(self, msg):
if self.state_message == message_ready:
self.need_dump_debug = True
self.state_message = "Firmware shutdown: %s%s" % (
msg, message_shutdown)
self.gcode.set_printer_ready(False)
def note_mcu_error(self, msg):
self.state_message = "%s%s" % (msg, message_restart)
self.gcode.set_printer_ready(False)
self.gcode.motor_heater_off()
def disconnect(self):
try:
if self.mcu is not None:
self.stats(self.reactor.monotonic(), force_output=True)
self.mcu.disconnect()
except:
logging.exception("Unhandled exception during disconnect")
def firmware_restart(self):
try:
if self.mcu is not None:
self.stats(self.reactor.monotonic(), force_output=True)
self.mcu.microcontroller_restart()
self.mcu.disconnect()
except:
logging.exception("Unhandled exception during firmware_restart")
def get_startup_state(self):
return self.startup_state
self.is_shutdown = True
self.state_message = "%s%s" % (msg, message_shutdown)
for cb in self.state_cb:
cb('shutdown')
def invoke_async_shutdown(self, msg):
self.async_shutdown_msg = msg
self.request_exit("shutdown")
def request_exit(self, result="exit"):
self.run_result = result
self.reactor.end()
@@ -270,18 +304,19 @@ class Printer:
# Startup
######################################################################
def read_dictionary(filename):
dfile = open(filename, 'rb')
dictionary = dfile.read()
dfile.close()
return dictionary
def arg_dictionary(option, opt_str, value, parser):
key, fname = "dictionary", value
if '=' in value:
mcu_name, fname = value.split('=', 1)
key = "dictionary_" + mcu_name
if parser.values.dictionary is None:
parser.values.dictionary = {}
parser.values.dictionary[key] = fname
def main():
usage = "%prog [options] <config file>"
opts = optparse.OptionParser(usage)
opts.add_option("-o", "--debugoutput", dest="outputfile",
help="write output to file instead of to serial port")
opts.add_option("-i", "--debuginput", dest="inputfile",
opts.add_option("-i", "--debuginput", dest="debuginput",
help="read commands from file instead of from tty port")
opts.add_option("-I", "--input-tty", dest="inputtty", default='/tmp/printer',
help="input tty name (default is /tmp/printer)")
@@ -289,63 +324,54 @@ def main():
help="write log to file instead of stderr")
opts.add_option("-v", action="store_true", dest="verbose",
help="enable debug messages")
opts.add_option("-d", dest="read_dictionary",
opts.add_option("-o", "--debugoutput", dest="debugoutput",
help="write output to file instead of to serial port")
opts.add_option("-d", "--dictionary", dest="dictionary", type="string",
action="callback", callback=arg_dictionary,
help="file to read for mcu protocol dictionary")
options, args = opts.parse_args()
if len(args) != 1:
opts.error("Incorrect number of arguments")
conffile = args[0]
start_args = {'config_file': args[0], 'start_reason': 'startup'}
input_fd = debuginput = debugoutput = bglogger = None
input_fd = bglogger = None
debuglevel = logging.INFO
if options.verbose:
debuglevel = logging.DEBUG
if options.inputfile:
debuginput = open(options.inputfile, 'rb')
if options.debuginput:
start_args['debuginput'] = options.debuginput
debuginput = open(options.debuginput, 'rb')
input_fd = debuginput.fileno()
else:
input_fd = util.create_pty(options.inputtty)
if options.outputfile:
debugoutput = open(options.outputfile, 'wb')
if options.debugoutput:
start_args['debugoutput'] = options.debugoutput
start_args.update(options.dictionary)
if options.logfile:
bglogger = queuelogger.setup_bg_logging(options.logfile, debuglevel)
else:
logging.basicConfig(level=debuglevel)
logging.info("Starting Klippy...")
software_version = util.get_git_version()
start_args['software_version'] = util.get_git_version()
if bglogger is not None:
lines = ["Args: %s" % (sys.argv,),
"Git version: %s" % (repr(software_version),),
"Git version: %s" % (repr(start_args['software_version']),),
"CPU: %s" % (util.get_cpu_info(),),
"Python: %s" % (repr(sys.version),)]
lines = "\n".join(lines)
logging.info(lines)
bglogger.set_rollover_info('versions', lines)
# Start firmware
res = 'startup'
# Start Printer() class
while 1:
is_fileinput = debuginput is not None
printer = Printer(
conffile, input_fd, res, is_fileinput, software_version, bglogger)
if debugoutput:
proto_dict = read_dictionary(options.read_dictionary)
printer.set_fileoutput(debugoutput, proto_dict)
printer = Printer(input_fd, bglogger, start_args)
res = printer.run()
if res == 'restart':
printer.disconnect()
time.sleep(1.)
logging.info("Restarting printer")
continue
elif res == 'firmware_restart':
printer.firmware_restart()
time.sleep(1.)
logging.info("Restarting printer")
continue
elif res == 'exit_eof':
printer.disconnect()
if res == 'exit':
break
time.sleep(1.)
logging.info("Restarting printer")
start_args['start_reason'] = res
if bglogger is not None:
bglogger.stop()

40
klippy/mathutil.py Normal file
View File

@@ -0,0 +1,40 @@
# Simple math helper functions
#
# Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging
# Helper code that implements coordinate descent
def coordinate_descent(adj_params, params, error_func):
# Define potential changes
params = dict(params)
dp = {param_name: 1. for param_name in adj_params}
# Calculate the error
best_err = error_func(params)
threshold = 0.00001
rounds = 0
while sum(dp.values()) > threshold and rounds < 10000:
rounds += 1
for param_name in adj_params:
orig = params[param_name]
params[param_name] = orig + dp[param_name]
err = error_func(params)
if err < best_err:
# There was some improvement
best_err = err
dp[param_name] *= 1.1
continue
params[param_name] = orig - dp[param_name]
err = error_func(params)
if err < best_err:
# There was some improvement
best_err = err
dp[param_name] *= 1.1
continue
params[param_name] = orig
dp[param_name] *= 0.9
logging.info("Coordinate descent best_err: %s rounds: %d", best_err, rounds)
return params

File diff suppressed because it is too large Load Diff

View File

@@ -108,7 +108,7 @@ class MessageFormat:
self.param_types = [MessageTypes[fmt] for name, fmt in argparts]
self.param_names = [(name, MessageTypes[fmt]) for name, fmt in argparts]
self.name_to_type = dict(self.param_names)
def encode(self, *params):
def encode(self, params):
out = []
out.append(self.msgid)
for i, t in enumerate(self.param_types):
@@ -183,11 +183,12 @@ class MessageParser:
error = error
def __init__(self):
self.unknown = UnknownFormat()
self.command_ids = []
self.messages_by_id = {}
self.messages_by_name = {}
self.static_strings = []
self.static_strings = {}
self.config = {}
self.version = ""
self.version = self.build_versions = ""
self.raw_identify_data = ""
self._init_messages(DefaultMessages, DefaultMessages.keys())
def check_packet(self, s):
@@ -207,7 +208,7 @@ class MessageParser:
msgcrc = s[msglen-MESSAGE_TRAILER_CRC:msglen-MESSAGE_TRAILER_CRC+2]
crc = crc16_ccitt(s[:msglen-MESSAGE_TRAILER_SIZE])
if crc != msgcrc:
#logging.debug("got crc %s vs %s" % (repr(crc), repr(msgcrc)))
#logging.debug("got crc %s vs %s", repr(crc), repr(msgcrc))
return -1
return msglen
def dump(self, s):
@@ -240,7 +241,7 @@ class MessageParser:
params['#name'] = mid.name
static_string_id = params.get('static_string_id')
if static_string_id is not None:
params['#msg'] = self.static_strings[static_string_id]
params['#msg'] = self.static_strings.get(static_string_id, "?")
return params
def encode(self, seq, cmd):
msglen = MESSAGE_MIN + len(cmd)
@@ -252,7 +253,7 @@ class MessageParser:
def _parse_buffer(self, value):
tval = int(value, 16)
out = []
for i in range(len(value)/2):
for i in range(len(value) // 2):
out.append(tval & 0xff)
tval >>= 8
out.reverse()
@@ -303,23 +304,36 @@ class MessageParser:
self.messages_by_id[msgid] = msg
self.messages_by_name[msg.name] = msg
def process_identify(self, data, decompress=True):
try:
if decompress:
data = zlib.decompress(data)
self.raw_identify_data = data
data = json.loads(data)
messages = data.get('messages')
commands = data.get('commands')
self.command_ids = commands
responses = data.get('responses')
self._init_messages(messages, commands+responses)
self.static_strings = data.get('static_strings', [])
static_strings = data.get('static_strings', {})
self.static_strings = { int(k): v for k, v in static_strings.items() }
self.config.update(data.get('config', {}))
self.version = data.get('version', '')
def get_constant(self, name):
try:
return self.config[name]
except KeyError:
self.build_versions = data.get('build_versions', '')
except error as e:
raise
except Exception as e:
logging.exception("process_identify error")
raise error("Error during identify: %s" % (str(e),))
class sentinel: pass
def get_constant(self, name, default=sentinel):
if name not in self.config:
if default is not self.sentinel:
return default
raise error("Firmware constant '%s' not found" % (name,))
def get_constant_float(self, name):
return self.config[name]
def get_constant_float(self, name, default=sentinel):
if name not in self.config and default is not self.sentinel:
return default
try:
return float(self.config[name])
except ValueError:

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python2
# Script to parse a serial port data dump
#
# Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>

View File

@@ -1,11 +1,15 @@
# Pin name to pin number definitions
#
# Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
# Copyright (C) 2016-2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import re
######################################################################
# Hardware pin names
######################################################################
def port_pins(port_count, bit_count=8):
pins = {}
for port in range(port_count):
@@ -16,11 +20,24 @@ def port_pins(port_count, bit_count=8):
pins['P%c%d' % (portchr, portbit)] = port * bit_count + portbit
return pins
def named_pins(fmt, port_count, bit_count=32):
return { fmt % (port, portbit) : port * bit_count + portbit
for port in range(port_count)
for portbit in range(bit_count) }
def beaglebone_pins():
gpios = named_pins("gpio%d_%d", 4)
gpios.update({"AIN%d" % i: i+4*32 for i in range(8)})
return gpios
MCU_PINS = {
"atmega168": port_pins(4), "atmega644p": port_pins(4),
"at90usb1286": port_pins(5),
"atmega168": port_pins(5), "atmega328": port_pins(5),
"atmega644p": port_pins(4), "atmega1284p": port_pins(4),
"at90usb1286": port_pins(6), "at90usb646": port_pins(6),
"atmega1280": port_pins(12), "atmega2560": port_pins(12),
"sam3x8e": port_pins(4, 32)
"sam3x8e": port_pins(4, 32),
"pru": beaglebone_pins(),
"linux": {"analog%d" % i: i for i in range(8)}, # XXX
}
@@ -78,34 +95,156 @@ Arduino_Due_analog = [
Arduino_from_mcu = {
"atmega168": (Arduino_standard, Arduino_analog_standard),
"atmega328": (Arduino_standard, Arduino_analog_standard),
"atmega644p": (Sanguino, Sanguino_analog),
"atmega1280": (Arduino_mega, Arduino_analog_mega),
"atmega2560": (Arduino_mega, Arduino_analog_mega),
"sam3x8e": (Arduino_Due, Arduino_Due_analog),
}
######################################################################
# External commands
######################################################################
# Obtains the pin mappings
def get_pin_map(mcu, mapping_name=None):
pins = MCU_PINS.get(mcu, {})
if mapping_name == 'arduino':
dpins, apins = Arduino_from_mcu.get(mcu, [])
def update_map_arduino(pins, mcu):
dpins, apins = Arduino_from_mcu.get(mcu, ([], []))
for i in range(len(dpins)):
pins['ar' + str(i)] = pins[dpins[i]]
for i in range(len(apins)):
pins['analog%d' % (i,)] = pins[apins[i]]
return pins
# Translate pin names and tick times in a firmware command
######################################################################
# Beaglebone mappings
######################################################################
beagleboneblack_mappings = {
'P8_3': 'gpio1_6', 'P8_4': 'gpio1_7', 'P8_5': 'gpio1_2',
'P8_6': 'gpio1_3', 'P8_7': 'gpio2_2', 'P8_8': 'gpio2_3',
'P8_9': 'gpio2_5', 'P8_10': 'gpio2_4', 'P8_11': 'gpio1_13',
'P8_12': 'gpio1_12', 'P8_13': 'gpio0_23', 'P8_14': 'gpio0_26',
'P8_15': 'gpio1_15', 'P8_16': 'gpio1_14', 'P8_17': 'gpio0_27',
'P8_18': 'gpio2_1', 'P8_19': 'gpio0_22', 'P8_20': 'gpio1_31',
'P8_21': 'gpio1_30', 'P8_22': 'gpio1_5', 'P8_23': 'gpio1_4',
'P8_24': 'gpio1_1', 'P8_25': 'gpio1_0', 'P8_26': 'gpio1_29',
'P8_27': 'gpio2_22', 'P8_28': 'gpio2_24', 'P8_29': 'gpio2_23',
'P8_30': 'gpio2_25', 'P8_31': 'gpio0_10', 'P8_32': 'gpio0_11',
'P8_33': 'gpio0_9', 'P8_34': 'gpio2_17', 'P8_35': 'gpio0_8',
'P8_36': 'gpio2_16', 'P8_37': 'gpio2_14', 'P8_38': 'gpio2_15',
'P8_39': 'gpio2_12', 'P8_40': 'gpio2_13', 'P8_41': 'gpio2_10',
'P8_42': 'gpio2_11', 'P8_43': 'gpio2_8', 'P8_44': 'gpio2_9',
'P8_45': 'gpio2_6', 'P8_46': 'gpio2_7', 'P9_11': 'gpio0_30',
'P9_12': 'gpio1_28', 'P9_13': 'gpio0_31', 'P9_14': 'gpio1_18',
'P9_15': 'gpio1_16', 'P9_16': 'gpio1_19', 'P9_17': 'gpio0_5',
'P9_18': 'gpio0_4', 'P9_19': 'gpio0_13', 'P9_20': 'gpio0_12',
'P9_21': 'gpio0_3', 'P9_22': 'gpio0_2', 'P9_23': 'gpio1_17',
'P9_24': 'gpio0_15', 'P9_25': 'gpio3_21', 'P9_26': 'gpio0_14',
'P9_27': 'gpio3_19', 'P9_28': 'gpio3_17', 'P9_29': 'gpio3_15',
'P9_30': 'gpio3_16', 'P9_31': 'gpio3_14', 'P9_41': 'gpio0_20',
'P9_42': 'gpio3_20', 'P9_43': 'gpio0_7', 'P9_44': 'gpio3_18',
'P9_33': 'AIN4', 'P9_35': 'AIN6', 'P9_36': 'AIN5', 'P9_37': 'AIN2',
'P9_38': 'AIN3', 'P9_39': 'AIN0', 'P9_40': 'AIN1',
}
def update_map_beaglebone(pins, mcu):
for pin, gpio in beagleboneblack_mappings.items():
pins[pin] = pins[gpio]
######################################################################
# Command translation
######################################################################
re_pin = re.compile(r'(?P<prefix>[ _]pin=)(?P<name>[^ ]*)')
re_ticks = re.compile(r'TICKS\((?P<ticks>[^)]*)\)')
def update_command(cmd, mcu_freq, pmap):
class PinResolver:
def __init__(self, mcu_type, validate_aliases=True):
self.mcu_type = mcu_type
self.validate_aliases = validate_aliases
self.pins = dict(MCU_PINS.get(mcu_type, {}))
self.active_pins = {}
def update_aliases(self, mapping_name):
self.pins = dict(MCU_PINS.get(self.mcu_type, {}))
if mapping_name == 'arduino':
update_map_arduino(self.pins, self.mcu_type)
elif mapping_name == 'beaglebone':
update_map_beaglebone(self.pins, self.mcu_type)
def update_command(self, cmd):
def pin_fixup(m):
return m.group('prefix') + str(pmap[m.group('name')])
def ticks_fixup(m):
return str(int(mcu_freq * float(m.group('ticks'))))
return re_ticks.sub(ticks_fixup, re_pin.sub(pin_fixup, cmd))
name = m.group('name')
if name not in self.pins:
raise error("Unable to translate pin name: %s" % (cmd,))
pin_id = self.pins[name]
if (name != self.active_pins.setdefault(pin_id, name)
and self.validate_aliases):
raise error("pin %s is an alias for %s" % (
name, self.active_pins[pin_id]))
return m.group('prefix') + str(pin_id)
return re_pin.sub(pin_fixup, cmd)
######################################################################
# Pin to chip mapping
######################################################################
class error(Exception):
pass
class PrinterPins:
error = error
def __init__(self):
self.chips = {}
self.active_pins = {}
def lookup_pin(self, pin_type, pin_desc, share_type=None):
can_invert = pin_type in ['stepper', 'endstop', 'digital_out', 'pwm']
can_pullup = pin_type == 'endstop'
desc = pin_desc
pullup = invert = 0
if can_pullup and desc.startswith('^'):
pullup = 1
desc = desc[1:].strip()
if can_invert and desc.startswith('!'):
invert = 1
desc = desc[1:].strip()
if ':' not in desc:
chip_name, pin = 'mcu', desc
else:
chip_name, pin = [s.strip() for s in desc.split(':', 1)]
if chip_name not in self.chips:
raise error("Unknown pin chip name '%s'" % (chip_name,))
if [c for c in '^!: ' if c in pin]:
format = ""
if can_pullup:
format += "[^] "
if can_invert:
format += "[!] "
raise error("Invalid pin description '%s'\n"
"Format is: %s[chip_name:] pin_name" % (
pin_desc, format))
share_name = "%s:%s" % (chip_name, pin)
if share_name in self.active_pins:
pin_params = self.active_pins[share_name]
if share_type is None or share_type != pin_params['share_type']:
raise error("pin %s used multiple times in config" % (pin,))
if invert != pin_params['invert'] or pullup != pin_params['pullup']:
raise error("Shared pin %s must have same polarity" % (pin,))
return pin_params
pin_params = {'chip': self.chips[chip_name], 'chip_name': chip_name,
'type': pin_type, 'share_type': share_type,
'pin': pin, 'invert': invert, 'pullup': pullup}
self.active_pins[share_name] = pin_params
return pin_params
def setup_pin(self, pin_type, pin_desc):
pin_params = self.lookup_pin(pin_type, pin_desc)
return pin_params['chip'].setup_pin(pin_params)
def register_chip(self, chip_name, chip):
chip_name = chip_name.strip()
if chip_name in self.chips:
raise error("Duplicate chip name '%s'" % (chip_name,))
self.chips[chip_name] = chip
def add_printer_objects(printer, config):
printer.add_object('pins', PrinterPins())
def get_printer_pins(printer):
return printer.lookup_object('pins')
def setup_pin(printer, pin_type, pin_desc):
return get_printer_pins(printer).setup_pin(pin_type, pin_desc)

View File

@@ -69,7 +69,7 @@ report_errno(char *where, int rc)
}
// Return a hex character for a given number
#define GETHEX(x) ((x) < 10 ? '0' + (x) : 'e' + (x) - 10)
#define GETHEX(x) ((x) < 10 ? '0' + (x) : 'a' + (x) - 10)
// Translate a binary string into an ASCII string with escape sequences
char *

View File

@@ -1,6 +1,6 @@
# Serial port management for firmware communication
#
# Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
# Copyright (C) 2016,2017 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging, threading
@@ -25,22 +25,15 @@ class SerialReader:
self.serialqueue = None
self.default_cmd_queue = self.alloc_command_queue()
self.stats_buf = self.ffi_main.new('char[4096]')
# MCU time/clock tracking
self.last_ack_time = self.last_ack_rtt_time = 0.
self.last_ack_clock = self.last_ack_rtt_clock = 0
self.est_clock = 0.
# Threading
self.lock = threading.Lock()
self.background_thread = None
# Message handlers
self.status_timer = self.reactor.register_timer(self._status_event)
self.status_cmd = None
handlers = {
'#unknown': self.handle_unknown,
'#output': self.handle_output, 'status': self.handle_status,
'#unknown': self.handle_unknown, '#output': self.handle_output,
'shutdown': self.handle_output, 'is_shutdown': self.handle_output
}
self.handlers = dict(((k, None), v) for k, v in handlers.items())
self.handlers = { (k, None): v for k, v in handlers.items() }
def _bg_thread(self):
response = self.ffi_main.new('struct pull_queue_message *')
while 1:
@@ -51,8 +44,8 @@ class SerialReader:
params = self.msgparser.parse(response.msg[0:count])
params['#sent_time'] = response.sent_time
params['#receive_time'] = response.receive_time
with self.lock:
hdl = (params['#name'], params.get('oid'))
with self.lock:
hdl = self.handlers.get(hdl, self.handle_default)
try:
hdl(params)
@@ -64,11 +57,16 @@ class SerialReader:
while 1:
starttime = self.reactor.monotonic()
try:
self.ser = serial.Serial(self.serialport, self.baud, timeout=0)
except (OSError, serial.SerialException), e:
logging.warn("Unable to open port: %s" % (e,))
if self.baud:
self.ser = serial.Serial(
self.serialport, self.baud, timeout=0)
else:
self.ser = open(self.serialport, 'rb+')
except (OSError, IOError, serial.SerialException) as e:
logging.warn("Unable to open port: %s", e)
self.reactor.pause(starttime + 5.)
continue
if self.baud:
stk500v2_leave(self.ser, self.reactor)
self.serialqueue = self.ffi_lib.serialqueue_alloc(
self.ser.fileno(), 0)
@@ -86,44 +84,24 @@ class SerialReader:
msgparser.process_identify(identify_data)
self.msgparser = msgparser
self.register_callback(self.handle_unknown, '#unknown')
logging.info("Loaded %d commands (%s)" % (
len(msgparser.messages_by_id), msgparser.version))
logging.info("MCU config: %s" % (" ".join(
["%s=%s" % (k, v) for k, v in msgparser.config.items()])))
logging.info("Loaded %d commands (%s / %s)",
len(msgparser.messages_by_id),
msgparser.version, msgparser.build_versions)
logging.info("MCU config: %s", " ".join(
["%s=%s" % (k, v) for k, v in msgparser.config.items()]))
# Setup baud adjust
mcu_baud = float(msgparser.config.get('SERIAL_BAUD', 0.))
if mcu_baud:
mcu_baud = msgparser.get_constant_float('SERIAL_BAUD', None)
if mcu_baud is not None:
baud_adjust = self.BITS_PER_BYTE / mcu_baud
self.ffi_lib.serialqueue_set_baud_adjust(
self.serialqueue, baud_adjust)
# Enable periodic get_status timer
get_status = msgparser.lookup_command('get_status')
self.status_cmd = get_status.encode()
self.reactor.update_timer(self.status_timer, self.reactor.NOW)
# Load initial last_ack_clock/last_ack_time
uptime_msg = msgparser.create_command('get_uptime')
params = self.send_with_response(uptime_msg, 'uptime')
self.last_ack_clock = (params['high'] << 32) | params['clock']
self.last_ack_time = params['#receive_time']
# Make sure est_clock is calculated
starttime = eventtime = self.reactor.monotonic()
while not self.est_clock:
if eventtime > starttime + 5.:
raise error("timeout on est_clock calculation")
eventtime = self.reactor.pause(eventtime + 0.010)
def connect_file(self, debugoutput, dictionary, pace=False):
self.ser = debugoutput
self.msgparser.process_identify(dictionary, decompress=False)
est_clock = 1000000000000.
if pace:
est_clock = float(self.msgparser.config['CLOCK_FREQ'])
self.serialqueue = self.ffi_lib.serialqueue_alloc(self.ser.fileno(), 1)
self.est_clock = est_clock
self.last_ack_time = self.reactor.monotonic()
self.last_ack_clock = 0
def set_clock_est(self, freq, last_time, last_clock):
self.ffi_lib.serialqueue_set_clock_est(
self.serialqueue, self.est_clock, self.last_ack_time
, self.last_ack_clock)
self.serialqueue, freq, last_time, last_clock)
def disconnect(self):
if self.serialqueue is not None:
self.ffi_lib.serialqueue_exit(self.serialqueue)
@@ -137,15 +115,9 @@ class SerialReader:
def stats(self, eventtime):
if self.serialqueue is None:
return ""
sqstats = self.ffi_lib.serialqueue_get_stats(
self.ffi_lib.serialqueue_get_stats(
self.serialqueue, self.stats_buf, len(self.stats_buf))
sqstats = self.ffi_main.string(self.stats_buf)
tstats = " est_clock=%.3f last_ack_time=%.3f last_ack_clock=%d" % (
self.est_clock, self.last_ack_time, self.last_ack_clock)
return sqstats + tstats
def _status_event(self, eventtime):
self.send(self.status_cmd)
return eventtime + 1.0
return self.ffi_main.string(self.stats_buf)
# Serial response callbacks
def register_callback(self, callback, name, oid=None):
with self.lock:
@@ -153,90 +125,70 @@ class SerialReader:
def unregister_callback(self, name, oid=None):
with self.lock:
del self.handlers[name, oid]
# Clock tracking
def get_clock(self, eventtime):
with self.lock:
return int(self.last_ack_clock
+ (eventtime - self.last_ack_time) * self.est_clock)
def translate_clock(self, raw_clock):
with self.lock:
last_ack_clock = self.last_ack_clock
clock_diff = (last_ack_clock - raw_clock) & 0xffffffff
if clock_diff & 0x80000000:
return last_ack_clock + 0x100000000 - clock_diff
return last_ack_clock - clock_diff
def get_last_clock(self):
with self.lock:
return self.last_ack_clock, self.last_ack_time
# Command sending
def send(self, cmd, minclock=0, reqclock=0, cq=None):
def raw_send(self, cmd, minclock, reqclock, cmd_queue):
self.ffi_lib.serialqueue_send(
self.serialqueue, cmd_queue, cmd, len(cmd), minclock, reqclock)
def send(self, msg, minclock=0, reqclock=0):
cmd = self.msgparser.create_command(msg)
self.raw_send(cmd, minclock, reqclock, self.default_cmd_queue)
def lookup_command(self, msgformat, cq=None):
if cq is None:
cq = self.default_cmd_queue
self.ffi_lib.serialqueue_send(
self.serialqueue, cq, cmd, len(cmd), minclock, reqclock)
def encode_and_send(self, data, minclock, reqclock, cq):
self.ffi_lib.serialqueue_encode_and_send(
self.serialqueue, cq, data, len(data), minclock, reqclock)
def send_with_response(self, cmd, name, oid=None):
src = SerialRetryCommand(self, cmd, name, oid)
return src.get_response()
cmd = self.msgparser.lookup_command(msgformat)
return SerialCommand(self, cq, cmd)
def alloc_command_queue(self):
return self.ffi_main.gc(self.ffi_lib.serialqueue_alloc_commandqueue(),
self.ffi_lib.serialqueue_free_commandqueue)
# Dumping debug lists
def dump_debug(self):
out = []
out.append("Dumping serial stats: %s" % (
self.stats(self.reactor.monotonic()),))
sdata = self.ffi_main.new('struct pull_queue_message[1024]')
rdata = self.ffi_main.new('struct pull_queue_message[1024]')
scount = self.ffi_lib.serialqueue_extract_old(
self.serialqueue, 1, sdata, len(sdata))
rcount = self.ffi_lib.serialqueue_extract_old(
self.serialqueue, 0, rdata, len(rdata))
logging.info("Dumping send queue %d messages" % (scount,))
out.append("Dumping send queue %d messages" % (scount,))
for i in range(scount):
msg = sdata[i]
cmds = self.msgparser.dump(msg.msg[0:msg.len])
logging.info("Sent %d %f %f %d: %s" % (
out.append("Sent %d %f %f %d: %s" % (
i, msg.receive_time, msg.sent_time, msg.len, ', '.join(cmds)))
logging.info("Dumping receive queue %d messages" % (rcount,))
out.append("Dumping receive queue %d messages" % (rcount,))
for i in range(rcount):
msg = rdata[i]
cmds = self.msgparser.dump(msg.msg[0:msg.len])
logging.info("Receive: %d %f %f %d: %s" % (
out.append("Receive: %d %f %f %d: %s" % (
i, msg.receive_time, msg.sent_time, msg.len, ', '.join(cmds)))
return '\n'.join(out)
# Default message handlers
def handle_status(self, params):
with self.lock:
# Update last_ack_time / last_ack_clock
ack_clock = (self.last_ack_clock & ~0xffffffff) | params['clock']
if ack_clock < self.last_ack_clock:
ack_clock += 0x100000000
sent_time = params['#sent_time']
self.last_ack_time = receive_time = params['#receive_time']
self.last_ack_clock = ack_clock
# Update est_clock (if applicable)
if receive_time > self.last_ack_rtt_time + 1. and sent_time:
if self.last_ack_rtt_time:
timedelta = receive_time - self.last_ack_rtt_time
clockdelta = ack_clock - self.last_ack_rtt_clock
estclock = clockdelta / timedelta
if estclock > self.est_clock and self.est_clock:
self.est_clock = (self.est_clock * 63. + estclock) / 64.
else:
self.est_clock = estclock
self.last_ack_rtt_time = sent_time
self.last_ack_rtt_clock = ack_clock
self.ffi_lib.serialqueue_set_clock_est(
self.serialqueue, self.est_clock, receive_time, ack_clock)
def handle_unknown(self, params):
logging.warn("Unknown message type %d: %s" % (
params['#msgid'], repr(params['#msg'])))
logging.warn("Unknown message type %d: %s",
params['#msgid'], repr(params['#msg']))
def handle_output(self, params):
logging.info("%s: %s" % (params['#name'], params['#msg']))
logging.info("%s: %s", params['#name'], params['#msg'])
def handle_default(self, params):
logging.warn("got %s" % (params,))
logging.warn("got %s", params)
def __del__(self):
self.disconnect()
# Wrapper around command sending
class SerialCommand:
def __init__(self, serial, cmd_queue, cmd):
self.serial = serial
self.cmd_queue = cmd_queue
self.cmd = cmd
def send(self, data=(), minclock=0, reqclock=0):
cmd = self.cmd.encode(data)
self.serial.raw_send(cmd, minclock, reqclock, self.cmd_queue)
def send_with_response(self, data=(), response=None, response_oid=None):
cmd = self.cmd.encode(data)
src = SerialRetryCommand(self.serial, cmd, response, response_oid)
return src.get_response()
# Class to retry sending of a query command until a given response is received
class SerialRetryCommand:
TIMEOUT_TIME = 5.0
@@ -257,7 +209,7 @@ class SerialRetryCommand:
def send_event(self, eventtime):
if self.response is not None:
return self.serial.reactor.NEVER
self.serial.send(self.cmd)
self.serial.raw_send(self.cmd, 0, 0, self.serial.default_cmd_queue)
return eventtime + self.RETRY_TIME
def handle_callback(self, params):
last_sent_time = params['#sent_time']
@@ -279,7 +231,7 @@ class SerialBootStrap:
def __init__(self, serial):
self.serial = serial
self.identify_data = ""
self.identify_cmd = self.serial.msgparser.lookup_command(
self.identify_cmd = self.serial.lookup_command(
"identify offset=%u count=%c")
self.is_done = False
self.serial.register_callback(self.handle_identify, 'identify_response')
@@ -303,17 +255,15 @@ class SerialBootStrap:
self.is_done = True
return
self.identify_data += msgdata
imsg = self.identify_cmd.encode(len(self.identify_data), 40)
self.serial.send(imsg)
self.identify_cmd.send([len(self.identify_data), 40])
def send_event(self, eventtime):
if self.is_done:
return self.serial.reactor.NEVER
imsg = self.identify_cmd.encode(len(self.identify_data), 40)
self.serial.send(imsg)
self.identify_cmd.send([len(self.identify_data), 40])
return eventtime + self.RETRY_TIME
def handle_unknown(self, params):
logging.debug("Unknown message %d (len %d) while identifying" % (
params['#msgid'], len(params['#msg'])))
logging.debug("Unknown message %d (len %d) while identifying",
params['#msgid'], len(params['#msg']))
# Attempt to place an AVR stk500v2 style programmer into normal mode
def stk500v2_leave(ser, reactor):
@@ -330,16 +280,16 @@ def stk500v2_leave(ser, reactor):
ser.write('\x1b\x01\x00\x01\x0e\x11\x04')
reactor.pause(reactor.monotonic() + 0.050)
res = ser.read(4096)
logging.debug("Got %s from stk500v2" % (repr(res),))
logging.debug("Got %s from stk500v2", repr(res))
ser.baudrate = origbaud
# Attempt an arduino style reset on a serial port
def arduino_reset(serialport, reactor):
# First try opening the port at 1200 baud
ser = serial.Serial(serialport, 1200, timeout=0)
# First try opening the port at a different baud
ser = serial.Serial(serialport, 2400, timeout=0)
ser.read(1)
reactor.pause(reactor.monotonic() + 0.100)
# Then try toggling DTR
# Then toggle DTR
ser.dtr = True
reactor.pause(reactor.monotonic() + 0.100)
ser.dtr = False

View File

@@ -12,6 +12,7 @@
// clock times, prioritizes commands, and handles retransmissions. A
// background thread is launched to do this work and minimize latency.
#include <fcntl.h> // fcntl
#include <math.h> // ceil
#include <poll.h> // poll
#include <pthread.h> // pthread_mutex_lock
@@ -102,14 +103,12 @@ pollreactor_add_timer(struct pollreactor *pr, int pos, void *callback)
pr->timers[pos].waketime = PR_NEVER;
}
#if 0
// Return the last schedule wake-up time for a timer
static double
pollreactor_get_timer(struct pollreactor *pr, int pos)
{
return pr->timers[pos].waketime;
}
#endif
// Set the wake-up time for a given timer
static void
@@ -148,7 +147,6 @@ pollreactor_check_timers(struct pollreactor *pr, double eventtime)
static void
pollreactor_run(struct pollreactor *pr)
{
pr->must_exit = 0;
double eventtime = get_monotonic();
while (! pr->must_exit) {
int timeout = pollreactor_check_timers(pr, eventtime);
@@ -180,6 +178,22 @@ pollreactor_is_exit(struct pollreactor *pr)
return pr->must_exit;
}
static int
set_non_blocking(int fd)
{
int flags = fcntl(fd, F_GETFL);
if (flags < 0) {
report_errno("fcntl getfl", flags);
return -1;
}
int ret = fcntl(fd, F_SETFL, flags | O_NONBLOCK);
if (ret < 0) {
report_errno("fcntl setfl", flags);
return -1;
}
return 0;
}
/****************************************************************
* Serial protocol helpers
@@ -344,17 +358,17 @@ struct serialqueue {
int receive_waiting;
// Baud / clock tracking
double baud_adjust, idle_time;
double est_clock, last_ack_time;
uint64_t last_ack_clock;
double est_freq, last_clock_time;
uint64_t last_clock;
double last_receive_sent_time;
// Retransmit support
uint64_t send_seq, receive_seq;
uint64_t retransmit_seq, rtt_sample_seq;
uint64_t ignore_nak_seq, retransmit_seq, rtt_sample_seq;
struct list_head sent_queue;
double srtt, rttvar, rto;
// Pending transmission message queues
struct list_head pending_queues;
int ready_bytes, stalled_bytes;
int ready_bytes, stalled_bytes, need_ack_bytes;
uint64_t need_kick_clock;
// Received messages
struct list_head receive_queue;
@@ -374,8 +388,8 @@ struct serialqueue {
#define MIN_RTO 0.025
#define MAX_RTO 5.000
#define MAX_SERIAL_BUFFER 0.050
#define MIN_REQTIME_DELTA 0.250
#define MIN_BACKGROUND_DELTA 0.005
#define IDLE_QUERY_TIME 1.0
#define DEBUG_QUEUE_SENT 100
@@ -427,23 +441,31 @@ static void
update_receive_seq(struct serialqueue *sq, double eventtime, uint64_t rseq)
{
// Remove from sent queue
int ack_count = rseq - sq->receive_seq;
uint64_t sent_seq = sq->receive_seq;
while (!list_empty(&sq->sent_queue) && ack_count--) {
for (;;) {
struct queue_message *sent = list_first_entry(
&sq->sent_queue, struct queue_message, node);
if (rseq == ++sent_seq)
sq->last_receive_sent_time = sent->receive_time;
if (list_empty(&sq->sent_queue)) {
// Got an ack for a message not sent; must be connection init
sq->send_seq = rseq;
sq->last_receive_sent_time = 0.;
break;
}
sq->need_ack_bytes -= sent->len;
list_del(&sent->node);
debug_queue_add(&sq->old_sent, sent);
sent_seq++;
if (rseq == sent_seq) {
// Found sent message corresponding with the received sequence
sq->last_receive_sent_time = sent->receive_time;
break;
}
}
sq->receive_seq = rseq;
if (rseq > sq->send_seq)
sq->send_seq = rseq;
pollreactor_update_timer(&sq->pr, SQPT_COMMAND, PR_NOW);
// Update retransmit info
if (sq->rtt_sample_seq && rseq >= sq->rtt_sample_seq
if (sq->rtt_sample_seq && rseq > sq->rtt_sample_seq
&& sq->last_receive_sent_time) {
// RFC6298 rtt calculations
double delta = eventtime - sq->last_receive_sent_time;
@@ -487,7 +509,7 @@ handle_message(struct serialqueue *sq, double eventtime, int len)
if (rseq != sq->receive_seq)
// New sequence number
update_receive_seq(sq, eventtime, rseq);
else if (len == MESSAGE_MIN && rseq > sq->retransmit_seq
else if (len == MESSAGE_MIN && rseq > sq->ignore_nak_seq
&& !list_empty(&sq->sent_queue))
// Duplicate sequence number in an empty message is a nak
pollreactor_update_timer(&sq->pr, SQPT_RETRANSMIT, PR_NOW);
@@ -495,8 +517,10 @@ handle_message(struct serialqueue *sq, double eventtime, int len)
if (len > MESSAGE_MIN) {
// Add message to receive queue
struct queue_message *qm = message_fill(sq->input_buf, len);
qm->sent_time = sq->last_receive_sent_time;
qm->sent_time = (rseq > sq->retransmit_seq
? sq->last_receive_sent_time : 0.);
qm->receive_time = get_monotonic(); // must be time post read()
qm->receive_time -= sq->baud_adjust * len;
list_add_tail(&qm->node, &sq->receive_queue);
check_wake_receive(sq);
}
@@ -561,12 +585,14 @@ retransmit_event(struct serialqueue *sq, double eventtime)
// Retransmit all pending messages
uint8_t buf[MESSAGE_MAX * MESSAGE_SEQ_MASK + 1];
int buflen = 0;
int buflen = 0, first_buflen = 0;
buf[buflen++] = MESSAGE_SYNC;
struct queue_message *qm;
list_for_each_entry(qm, &sq->sent_queue, node) {
memcpy(&buf[buflen], qm->msg, qm->len);
buflen += qm->len;
if (!first_buflen)
first_buflen = qm->len + 1;
}
ret = write(sq->serial_fd, buf, buflen);
if (ret < 0)
@@ -574,13 +600,23 @@ retransmit_event(struct serialqueue *sq, double eventtime)
sq->bytes_retransmit += buflen;
// Update rto
if (pollreactor_get_timer(&sq->pr, SQPT_RETRANSMIT) == PR_NOW) {
// Retransmit due to nak
sq->ignore_nak_seq = sq->receive_seq;
if (sq->receive_seq < sq->retransmit_seq)
// Second nak for this retransmit - don't allow third
sq->ignore_nak_seq = sq->retransmit_seq;
} else {
// Retransmit due to timeout
sq->rto *= 2.0;
if (sq->rto > MAX_RTO)
sq->rto = MAX_RTO;
sq->ignore_nak_seq = sq->send_seq;
}
sq->retransmit_seq = sq->send_seq;
sq->rtt_sample_seq = 0;
sq->idle_time = eventtime + buflen * sq->baud_adjust;
double waketime = sq->idle_time + sq->rto;
double waketime = eventtime + first_buflen * sq->baud_adjust + sq->rto;
pthread_mutex_unlock(&sq->lock);
return waketime;
@@ -643,9 +679,10 @@ build_and_send_command(struct serialqueue *sq, double eventtime)
if (list_empty(&sq->sent_queue))
pollreactor_update_timer(&sq->pr, SQPT_RETRANSMIT
, sq->idle_time + sq->rto);
sq->send_seq++;
if (!sq->rtt_sample_seq)
sq->rtt_sample_seq = sq->send_seq;
sq->send_seq++;
sq->need_ack_bytes += out->len;
list_add_tail(&out->node, &sq->sent_queue);
}
@@ -653,10 +690,8 @@ build_and_send_command(struct serialqueue *sq, double eventtime)
static double
check_send_command(struct serialqueue *sq, double eventtime)
{
if (eventtime < sq->idle_time - MAX_SERIAL_BUFFER)
// Serial port already busy
return sq->idle_time - MAX_SERIAL_BUFFER;
if (sq->send_seq - sq->receive_seq >= MESSAGE_SEQ_MASK
if ((sq->send_seq - sq->receive_seq >= MESSAGE_SEQ_MASK
|| (sq->need_ack_bytes - 2*MESSAGE_MAX) * sq->baud_adjust > sq->srtt)
&& sq->receive_seq != (uint64_t)-1)
// Need an ack before more messages can be sent
return PR_NEVER;
@@ -664,8 +699,9 @@ check_send_command(struct serialqueue *sq, double eventtime)
// Check for stalled messages now ready
double idletime = eventtime > sq->idle_time ? eventtime : sq->idle_time;
idletime += MESSAGE_MIN * sq->baud_adjust;
double timedelta = idletime - sq->last_ack_time;
uint64_t ack_clock = (uint64_t)(timedelta * sq->est_clock) + sq->last_ack_clock;
double timedelta = idletime - sq->last_clock_time;
uint64_t ack_clock = ((uint64_t)(timedelta * sq->est_freq)
+ sq->last_clock);
uint64_t min_stalled_clock = MAX_CLOCK, min_ready_clock = MAX_CLOCK;
struct command_queue *cq;
list_for_each_entry(cq, &sq->pending_queues, node) {
@@ -687,28 +723,33 @@ check_send_command(struct serialqueue *sq, double eventtime)
if (!list_empty(&cq->ready_queue)) {
struct queue_message *qm = list_first_entry(
&cq->ready_queue, struct queue_message, node);
if (qm->req_clock < min_ready_clock)
min_ready_clock = qm->req_clock;
uint64_t req_clock = qm->req_clock;
if (req_clock == BACKGROUND_PRIORITY_CLOCK)
req_clock = (uint64_t)(
(sq->idle_time - sq->last_clock_time + MIN_BACKGROUND_DELTA)
* sq->est_freq) + sq->last_clock;
if (req_clock < min_ready_clock)
min_ready_clock = req_clock;
}
}
// Check for messages to send
if (sq->ready_bytes >= MESSAGE_PAYLOAD_MAX)
return PR_NOW;
if (! sq->est_clock) {
if (! sq->est_freq) {
if (sq->ready_bytes)
return PR_NOW;
sq->need_kick_clock = MAX_CLOCK;
return PR_NEVER;
}
uint64_t reqclock_delta = MIN_REQTIME_DELTA * sq->est_clock;
uint64_t reqclock_delta = MIN_REQTIME_DELTA * sq->est_freq;
if (min_ready_clock <= ack_clock + reqclock_delta)
return PR_NOW;
uint64_t wantclock = min_ready_clock - reqclock_delta;
if (min_stalled_clock < wantclock)
wantclock = min_stalled_clock;
sq->need_kick_clock = wantclock;
return idletime + (wantclock - ack_clock) / sq->est_clock;
return idletime + (wantclock - ack_clock) / sq->est_freq;
}
// Callback timer to send data to the serial port
@@ -759,6 +800,9 @@ serialqueue_alloc(int serial_fd, int write_only)
pollreactor_add_fd(&sq->pr, SQPF_PIPE, sq->pipe_fds[0], kick_event);
pollreactor_add_timer(&sq->pr, SQPT_RETRANSMIT, retransmit_event);
pollreactor_add_timer(&sq->pr, SQPT_COMMAND, command_event);
set_non_blocking(serial_fd);
set_non_blocking(sq->pipe_fds[0]);
set_non_blocking(sq->pipe_fds[1]);
// Retransmit setup
sq->send_seq = 1;
@@ -869,7 +913,8 @@ serialqueue_send_batch(struct serialqueue *sq, struct command_queue *cq
int len = 0;
struct queue_message *qm;
list_for_each_entry(qm, msgs, node) {
if (qm->min_clock + (1LL<<31) < qm->req_clock)
if (qm->min_clock + (1LL<<31) < qm->req_clock
&& qm->req_clock != BACKGROUND_PRIORITY_CLOCK)
qm->min_clock = qm->req_clock - (1LL<<31);
len += qm->len;
}
@@ -974,13 +1019,13 @@ serialqueue_set_baud_adjust(struct serialqueue *sq, double baud_adjust)
// Set the estimated clock rate of the mcu on the other end of the
// serial port
void
serialqueue_set_clock_est(struct serialqueue *sq, double est_clock
, double last_ack_time, uint64_t last_ack_clock)
serialqueue_set_clock_est(struct serialqueue *sq, double est_freq
, double last_clock_time, uint64_t last_clock)
{
pthread_mutex_lock(&sq->lock);
sq->est_clock = est_clock;
sq->last_ack_time = last_ack_time;
sq->last_ack_clock = last_ack_clock;
sq->est_freq = est_freq;
sq->last_clock_time = last_clock_time;
sq->last_clock = last_clock;
pthread_mutex_unlock(&sq->lock);
}

View File

@@ -3,7 +3,8 @@
#include "list.h" // struct list_head
#define MAX_CLOCK 0x7fffffffffffffff
#define MAX_CLOCK 0x7fffffffffffffffLL
#define BACKGROUND_PRIORITY_CLOCK 0x7fffffff00000000LL
#define MESSAGE_MIN 5
#define MESSAGE_MAX 64
@@ -59,8 +60,8 @@ void serialqueue_encode_and_send(struct serialqueue *sq, struct command_queue *c
, uint64_t min_clock, uint64_t req_clock);
void serialqueue_pull(struct serialqueue *sq, struct pull_queue_message *pqm);
void serialqueue_set_baud_adjust(struct serialqueue *sq, double baud_adjust);
void serialqueue_set_clock_est(struct serialqueue *sq, double est_clock
, double last_ack_time, uint64_t last_ack_clock);
void serialqueue_set_clock_est(struct serialqueue *sq, double est_freq
, double last_clock_time, uint64_t last_clock);
void serialqueue_get_stats(struct serialqueue *sq, char *buf, int len);
int serialqueue_extract_old(struct serialqueue *sq, int sentq
, struct pull_queue_message *q, int max);

View File

@@ -28,9 +28,10 @@
struct stepcompress {
// Buffer management
uint64_t *queue, *queue_end, *queue_pos, *queue_next;
uint32_t *queue, *queue_end, *queue_pos, *queue_next;
// Internal tracking
uint32_t max_error;
double mcu_time_offset, mcu_freq;
// Message generation
uint64_t last_step_clock, homing_clock;
struct list_head msg_queue;
@@ -39,42 +40,6 @@ struct stepcompress {
};
/****************************************************************
* Queue management
****************************************************************/
// Shuffle the internal queue to avoid having to allocate more ram
static void
clean_queue(struct stepcompress *sc)
{
int in_use = sc->queue_next - sc->queue_pos;
memmove(sc->queue, sc->queue_pos, in_use * sizeof(*sc->queue));
sc->queue_pos = sc->queue;
sc->queue_next = sc->queue + in_use;
}
// Expand the internal queue of step times
static void
expand_queue(struct stepcompress *sc, int count)
{
int alloc = sc->queue_end - sc->queue;
if (count + sc->queue_next - sc->queue_pos <= alloc) {
clean_queue(sc);
return;
}
int pos = sc->queue_pos - sc->queue;
int next = sc->queue_next - sc->queue;
if (!alloc)
alloc = QUEUE_START_SIZE;
while (next + count > alloc)
alloc *= 2;
sc->queue = realloc(sc->queue, alloc * sizeof(*sc->queue));
sc->queue_end = sc->queue + alloc;
sc->queue_pos = sc->queue + pos;
sc->queue_next = sc->queue + next;
}
/****************************************************************
* Step compression
****************************************************************/
@@ -100,10 +65,10 @@ struct points {
// Given a requested step time, return the minimum and maximum
// acceptable times
static inline struct points
minmax_point(struct stepcompress *sc, uint64_t *pos)
minmax_point(struct stepcompress *sc, uint32_t *pos)
{
uint32_t prevpoint = pos > sc->queue_pos ? *(pos-1) - sc->last_step_clock : 0;
uint32_t point = *pos - sc->last_step_clock;
uint32_t lsc = sc->last_step_clock, point = *pos - lsc;
uint32_t prevpoint = pos > sc->queue_pos ? *(pos-1) - lsc : 0;
uint32_t max_error = (point - prevpoint) / 2;
if (max_error > sc->max_error)
max_error = sc->max_error;
@@ -126,6 +91,9 @@ struct step_move {
static struct step_move
compress_bisect_add(struct stepcompress *sc)
{
uint32_t *qlast = sc->queue_next;
if (qlast > sc->queue_pos + 65535)
qlast = sc->queue_pos + 65535;
struct points point = minmax_point(sc, sc->queue_pos);
int32_t outer_mininterval = point.minp, outer_maxinterval = point.maxp;
int32_t add = 0, minadd = -0x8000, maxadd = 0x7fff;
@@ -140,10 +108,7 @@ compress_bisect_add(struct stepcompress *sc)
int32_t nextcount = 1;
for (;;) {
nextcount++;
if (nextcount > bestcount
&& (&sc->queue_pos[nextcount-1] >= sc->queue_next
|| sc->queue_pos[nextcount-1] >= sc->last_step_clock+(3<<28)
|| nextcount > 65535)) {
if (&sc->queue_pos[nextcount-1] >= qlast) {
int32_t count = nextcount - 1;
return (struct step_move){ interval, count, add };
}
@@ -230,18 +195,7 @@ check_line(struct stepcompress *sc, struct step_move move)
{
if (!CHECK_LINES)
return 0;
if (move.count == 1) {
if (move.interval != (uint32_t)(*sc->queue_pos - sc->last_step_clock)
|| *sc->queue_pos < sc->last_step_clock) {
errorf("stepcompress o=%d i=%d c=%d a=%d:"
" Count 1 point out of range (%lld)"
, sc->oid, move.interval, move.count, move.add
, (long long)(*sc->queue_pos - sc->last_step_clock));
return ERROR_RET;
}
return 0;
}
if (!move.count || (!move.interval && !move.add)
if (!move.count || (!move.interval && !move.add && move.count > 1)
|| move.interval >= 0x80000000) {
errorf("stepcompress o=%d i=%d c=%d a=%d: Invalid sequence"
, sc->oid, move.interval, move.count, move.add);
@@ -310,7 +264,7 @@ stepcompress_flush(struct stepcompress *sc, uint64_t move_clock)
{
if (sc->queue_pos >= sc->queue_next)
return 0;
while (move_clock > sc->last_step_clock) {
while (sc->last_step_clock < move_clock) {
struct step_move move = compress_bisect_add(sc);
int ret = check_line(sc, move);
if (ret)
@@ -321,14 +275,9 @@ stepcompress_flush(struct stepcompress *sc, uint64_t move_clock)
};
struct queue_message *qm = message_alloc_and_encode(msg, 5);
qm->min_clock = qm->req_clock = sc->last_step_clock;
if (move.count == 1 && sc->last_step_clock + (1<<27) < *sc->queue_pos) {
// Be careful with 32bit overflow
sc->last_step_clock = qm->req_clock = *sc->queue_pos;
} else {
int32_t addfactor = move.count*(move.count-1)/2;
uint32_t ticks = move.add*addfactor + move.interval*move.count;
sc->last_step_clock += ticks;
}
if (sc->homing_clock)
// When homing, all steps should be sent prior to homing_clock
qm->min_clock = qm->req_clock = sc->homing_clock;
@@ -343,6 +292,23 @@ stepcompress_flush(struct stepcompress *sc, uint64_t move_clock)
return 0;
}
// Generate a queue_step for a step far in the future from the last step
static int
stepcompress_flush_far(struct stepcompress *sc, uint64_t abs_step_clock)
{
uint32_t msg[5] = {
sc->queue_step_msgid, sc->oid, abs_step_clock - sc->last_step_clock, 1, 0
};
struct queue_message *qm = message_alloc_and_encode(msg, 5);
qm->min_clock = sc->last_step_clock;
sc->last_step_clock = qm->req_clock = abs_step_clock;
if (sc->homing_clock)
// When homing, all steps should be sent prior to homing_clock
qm->min_clock = qm->req_clock = sc->homing_clock;
list_add_tail(&qm->node, &sc->msg_queue);
return 0;
}
// Send the set_next_step_dir command
static int
set_next_step_dir(struct stepcompress *sc, int sdir)
@@ -362,35 +328,6 @@ set_next_step_dir(struct stepcompress *sc, int sdir)
return 0;
}
// Check if the internal queue needs to be expanded, and expand if so
static int
_check_push(struct stepcompress *sc)
{
if (sc->queue_next - sc->queue_pos > 65535 + 2000) {
// No point in keeping more than 64K steps in memory
int ret = stepcompress_flush(sc, *(sc->queue_next - 65535));
if (ret)
return ret;
}
expand_queue(sc, 1);
return 0;
}
static inline int
check_push(struct stepcompress *sc, uint64_t **pqnext, uint64_t **pqend
, uint64_t c)
{
if (unlikely(*pqnext >= *pqend)) {
sc->queue_next = *pqnext;
int ret = _check_push(sc);
if (ret)
return ret;
*pqnext = sc->queue_next;
*pqend = sc->queue_end;
}
*(*pqnext)++ = c;
return 0;
}
// Reset the internal state of the stepcompress object
int
stepcompress_reset(struct stepcompress *sc, uint64_t last_step_clock)
@@ -428,11 +365,129 @@ stepcompress_queue_msg(struct stepcompress *sc, uint32_t *data, int len)
return 0;
}
// Set the conversion rate of 'print_time' to mcu clock
static void
stepcompress_set_time(struct stepcompress *sc
, double time_offset, double mcu_freq)
{
sc->mcu_time_offset = time_offset;
sc->mcu_freq = mcu_freq;
}
/****************************************************************
* Queue management
****************************************************************/
struct queue_append {
struct stepcompress *sc;
uint32_t *qnext, *qend, last_step_clock_32;
double clock_offset;
};
// Maximium clock delta between messages in the queue
#define CLOCK_DIFF_MAX (3<<28)
// Create a cursor for inserting clock times into the queue
static inline struct queue_append
queue_append_start(struct stepcompress *sc, double print_time, double adjust)
{
double print_clock = (print_time - sc->mcu_time_offset) * sc->mcu_freq;
return (struct queue_append) {
.sc = sc, .qnext = sc->queue_next, .qend = sc->queue_end,
.last_step_clock_32 = sc->last_step_clock,
.clock_offset = (print_clock - (double)sc->last_step_clock) + adjust };
}
// Finalize a cursor created with queue_append_start()
static inline void
queue_append_finish(struct queue_append qa)
{
qa.sc->queue_next = qa.qnext;
}
// Slow path for queue_append()
static int
queue_append_slow(struct stepcompress *sc, double rel_sc)
{
uint64_t abs_step_clock = (uint64_t)rel_sc + sc->last_step_clock;
if (abs_step_clock >= sc->last_step_clock + CLOCK_DIFF_MAX) {
// Avoid integer overflow on steps far in the future
int ret = stepcompress_flush(sc, abs_step_clock - CLOCK_DIFF_MAX + 1);
if (ret)
return ret;
if (abs_step_clock >= sc->last_step_clock + CLOCK_DIFF_MAX)
return stepcompress_flush_far(sc, abs_step_clock);
}
if (sc->queue_next - sc->queue_pos > 65535 + 2000) {
// No point in keeping more than 64K steps in memory
uint32_t flush = *(sc->queue_next-65535) - (uint32_t)sc->last_step_clock;
int ret = stepcompress_flush(sc, sc->last_step_clock + flush);
if (ret)
return ret;
}
if (sc->queue_next >= sc->queue_end) {
// Make room in the queue
int in_use = sc->queue_next - sc->queue_pos;
if (sc->queue_pos > sc->queue) {
// Shuffle the internal queue to avoid having to allocate more ram
memmove(sc->queue, sc->queue_pos, in_use * sizeof(*sc->queue));
} else {
// Expand the internal queue of step times
int alloc = sc->queue_end - sc->queue;
if (!alloc)
alloc = QUEUE_START_SIZE;
while (in_use >= alloc)
alloc *= 2;
sc->queue = realloc(sc->queue, alloc * sizeof(*sc->queue));
sc->queue_end = sc->queue + alloc;
}
sc->queue_pos = sc->queue;
sc->queue_next = sc->queue + in_use;
}
*sc->queue_next++ = abs_step_clock;
return 0;
}
// Add a clock time to the queue (flushing the queue if needed)
static inline int
queue_append(struct queue_append *qa, double step_clock)
{
double rel_sc = step_clock + qa->clock_offset;
if (likely(!(qa->qnext >= qa->qend || rel_sc >= (double)CLOCK_DIFF_MAX))) {
*qa->qnext++ = qa->last_step_clock_32 + (uint32_t)rel_sc;
return 0;
}
// Call queue_append_slow() to handle queue expansion and integer overflow
struct stepcompress *sc = qa->sc;
uint64_t old_last_step_clock = sc->last_step_clock;
sc->queue_next = qa->qnext;
int ret = queue_append_slow(sc, rel_sc);
if (ret)
return ret;
qa->qnext = sc->queue_next;
qa->qend = sc->queue_end;
qa->last_step_clock_32 = sc->last_step_clock;
qa->clock_offset -= sc->last_step_clock - old_last_step_clock;
return 0;
}
/****************************************************************
* Motion to step conversions
****************************************************************/
// Common suffixes: _sd is step distance (a unit length the same
// distance the stepper moves on each step), _sv is step velocity (in
// units of step distance per time), _sd2 is step distance squared, _r
// is ratio (scalar usually between 0.0 and 1.0). Times are in
// seconds and acceleration is in units of step distance per second
// squared.
// Wrapper around sqrt() to handle small negative numbers
static double
_safe_sqrt(double v)
@@ -448,38 +503,29 @@ static inline double safe_sqrt(double v) {
}
// Schedule a step event at the specified step_clock time
int
stepcompress_push(struct stepcompress *sc, double step_clock, int32_t sdir)
int32_t
stepcompress_push(struct stepcompress *sc, double print_time, int32_t sdir)
{
int ret = set_next_step_dir(sc, !!sdir);
if (ret)
return ret;
step_clock += 0.5;
uint64_t *qnext = sc->queue_next, *qend = sc->queue_end;
ret = check_push(sc, &qnext, &qend, step_clock);
struct queue_append qa = queue_append_start(sc, print_time, 0.5);
ret = queue_append(&qa, 0.);
if (ret)
return ret;
sc->queue_next = qnext;
return 0;
queue_append_finish(qa);
return sdir ? 1 : -1;
}
// Common suffixes: _sd is step distance (a unit length the same
// distance the stepper moves on each step), _sv is step velocity (in
// units of step distance per clock tick), _sd2 is step distance
// squared, _r is ratio (scalar usually between 0.0 and 1.0). Times
// are represented as clock ticks (a unit of time determined by a
// micro-controller tick) and acceleration is in units of step
// distance per clock ticks squared.
// Schedule 'steps' number of steps at constant acceleration. If
// acceleration is zero (ie, constant velocity) it uses the formula:
// step_clock = clock_offset + step_num/start_sv
// step_time = print_time + step_num/start_sv
// Otherwise it uses the formula:
// step_clock = (clock_offset + sqrt(2*step_num/accel + (start_sv/accel)**2)
// step_time = (print_time + sqrt(2*step_num/accel + (start_sv/accel)**2)
// - start_sv/accel)
int32_t
stepcompress_push_const(
struct stepcompress *sc, double clock_offset
struct stepcompress *sc, double print_time
, double step_offset, double steps, double start_sv, double accel)
{
// Calculate number of steps to take
@@ -493,7 +539,7 @@ stepcompress_push_const(
if (count <= 0 || count > 10000000) {
if (count && steps) {
errorf("push_const invalid count %d %f %f %f %f %f"
, sc->oid, clock_offset, step_offset, steps
, sc->oid, print_time, step_offset, steps
, start_sv, accel);
return ERROR_RET;
}
@@ -505,35 +551,35 @@ stepcompress_push_const(
int res = sdir ? count : -count;
// Calculate each step time
clock_offset += 0.5;
double pos = step_offset + .5;
uint64_t *qnext = sc->queue_next, *qend = sc->queue_end;
if (!accel) {
// Move at constant velocity (zero acceleration)
double inv_cruise_sv = 1. / start_sv;
struct queue_append qa = queue_append_start(sc, print_time, .5);
double inv_cruise_sv = sc->mcu_freq / start_sv;
double pos = (step_offset + .5) * inv_cruise_sv;
while (count--) {
uint64_t c = clock_offset + pos*inv_cruise_sv;
int ret = check_push(sc, &qnext, &qend, c);
ret = queue_append(&qa, pos);
if (ret)
return ret;
pos += 1.0;
pos += inv_cruise_sv;
}
queue_append_finish(qa);
} else {
// Move with constant acceleration
double inv_accel = 1. / accel;
clock_offset -= start_sv * inv_accel;
pos += .5 * start_sv*start_sv * inv_accel;
double accel_multiplier = 2. * inv_accel;
double accel_time = start_sv * inv_accel * sc->mcu_freq;
struct queue_append qa = queue_append_start(
sc, print_time, 0.5 - accel_time);
double accel_multiplier = 2. * inv_accel * sc->mcu_freq * sc->mcu_freq;
double pos = (step_offset + .5)*accel_multiplier + accel_time*accel_time;
while (count--) {
double v = safe_sqrt(pos * accel_multiplier);
uint64_t c = clock_offset + (accel_multiplier >= 0. ? v : -v);
int ret = check_push(sc, &qnext, &qend, c);
double v = safe_sqrt(pos);
int ret = queue_append(&qa, accel_multiplier >= 0. ? v : -v);
if (ret)
return ret;
pos += 1.0;
pos += accel_multiplier;
}
queue_append_finish(qa);
}
sc->queue_next = qnext;
return res;
}
@@ -541,7 +587,7 @@ stepcompress_push_const(
static int32_t
_stepcompress_push_delta(
struct stepcompress *sc, int sdir
, double clock_offset, double move_sd, double start_sv, double accel
, double print_time, double move_sd, double start_sv, double accel
, double height, double startxy_sd, double arm_sd, double movez_r)
{
// Calculate number of steps to take
@@ -553,7 +599,7 @@ _stepcompress_push_delta(
if (count <= 0 || count > 10000000) {
if (count) {
errorf("push_delta invalid count %d %d %f %f %f %f %f %f %f %f"
, sc->oid, count, clock_offset, move_sd, start_sv, accel
, sc->oid, count, print_time, move_sd, start_sv, accel
, height, startxy_sd, arm_sd, movez_r);
return ERROR_RET;
}
@@ -565,32 +611,30 @@ _stepcompress_push_delta(
int res = sdir ? count : -count;
// Calculate each step time
clock_offset += 0.5;
height += (sdir ? .5 : -.5);
uint64_t *qnext = sc->queue_next, *qend = sc->queue_end;
if (!accel) {
// Move at constant velocity (zero acceleration)
double inv_cruise_sv = 1. / start_sv;
struct queue_append qa = queue_append_start(sc, print_time, .5);
double inv_cruise_sv = sc->mcu_freq / start_sv;
if (!movez_r) {
// Optimized case for common XY only moves (no Z movement)
while (count--) {
double v = safe_sqrt(arm_sd2 - height*height);
double pos = startxy_sd + (sdir ? -v : v);
uint64_t c = clock_offset + pos * inv_cruise_sv;
int ret = check_push(sc, &qnext, &qend, c);
int ret = queue_append(&qa, pos * inv_cruise_sv);
if (ret)
return ret;
height += (sdir ? 1. : -1.);
}
} else if (!movexy_r) {
// Optimized case for Z only moves
double pos = (sdir ? height-end_height : end_height-height);
double pos = ((sdir ? height-end_height : end_height-height)
* inv_cruise_sv);
while (count--) {
uint64_t c = clock_offset + pos * inv_cruise_sv;
int ret = check_push(sc, &qnext, &qend, c);
int ret = queue_append(&qa, pos);
if (ret)
return ret;
pos += 1.;
pos += inv_cruise_sv;
}
} else {
// General case (handles XY+Z moves)
@@ -599,39 +643,39 @@ _stepcompress_push_delta(
double relheight = movexy_r*height - zoffset;
double v = safe_sqrt(arm_sd2 - relheight*relheight);
double pos = start_pos + movez_r*height + (sdir ? -v : v);
uint64_t c = clock_offset + pos * inv_cruise_sv;
int ret = check_push(sc, &qnext, &qend, c);
int ret = queue_append(&qa, pos * inv_cruise_sv);
if (ret)
return ret;
height += (sdir ? 1. : -1.);
}
}
queue_append_finish(qa);
} else {
// Move with constant acceleration
double start_pos = movexy_r*startxy_sd, zoffset = movez_r*startxy_sd;
double inv_accel = 1. / accel;
clock_offset -= start_sv * inv_accel;
start_pos += 0.5 * start_sv*start_sv * inv_accel;
double accel_multiplier = 2. * inv_accel;
struct queue_append qa = queue_append_start(
sc, print_time, 0.5 - start_sv * inv_accel * sc->mcu_freq);
double accel_multiplier = 2. * inv_accel * sc->mcu_freq * sc->mcu_freq;
while (count--) {
double relheight = movexy_r*height - zoffset;
double v = safe_sqrt(arm_sd2 - relheight*relheight);
double pos = start_pos + movez_r*height + (sdir ? -v : v);
v = safe_sqrt(pos * accel_multiplier);
uint64_t c = clock_offset + (accel_multiplier >= 0. ? v : -v);
int ret = check_push(sc, &qnext, &qend, c);
int ret = queue_append(&qa, accel_multiplier >= 0. ? v : -v);
if (ret)
return ret;
height += (sdir ? 1. : -1.);
}
queue_append_finish(qa);
}
sc->queue_next = qnext;
return res;
}
int32_t
stepcompress_push_delta(
struct stepcompress *sc, double clock_offset, double move_sd
struct stepcompress *sc, double print_time, double move_sd
, double start_sv, double accel
, double height, double startxy_sd, double arm_sd, double movez_r)
{
@@ -639,22 +683,22 @@ stepcompress_push_delta(
if (reversexy_sd <= 0.)
// All steps are in down direction
return _stepcompress_push_delta(
sc, 0, clock_offset, move_sd, start_sv, accel
sc, 0, print_time, move_sd, start_sv, accel
, height, startxy_sd, arm_sd, movez_r);
double movexy_r = movez_r ? sqrt(1. - movez_r*movez_r) : 1.;
if (reversexy_sd >= move_sd * movexy_r)
// All steps are in up direction
return _stepcompress_push_delta(
sc, 1, clock_offset, move_sd, start_sv, accel
sc, 1, print_time, move_sd, start_sv, accel
, height, startxy_sd, arm_sd, movez_r);
// Steps in both up and down direction
int res1 = _stepcompress_push_delta(
sc, 1, clock_offset, reversexy_sd / movexy_r, start_sv, accel
sc, 1, print_time, reversexy_sd / movexy_r, start_sv, accel
, height, startxy_sd, arm_sd, movez_r);
if (res1 == ERROR_RET)
return res1;
int res2 = _stepcompress_push_delta(
sc, 0, clock_offset, move_sd, start_sv, accel
sc, 0, print_time, move_sd, start_sv, accel
, height + res1, startxy_sd, arm_sd, movez_r);
if (res2 == ERROR_RET)
return res2;
@@ -718,6 +762,17 @@ steppersync_free(struct steppersync *ss)
free(ss);
}
// Set the conversion rate of 'print_time' to mcu clock
void
steppersync_set_time(struct steppersync *ss, double time_offset, double mcu_freq)
{
int i;
for (i=0; i<ss->sc_num; i++) {
struct stepcompress *sc = ss->sc_list[i];
stepcompress_set_time(sc, time_offset, mcu_freq);
}
}
// Implement a binary heap algorithm to track when the next available
// 'struct move' in the mcu will be available
static void

View File

@@ -1,65 +1,57 @@
# Printer stepper support
#
# Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
# Copyright (C) 2016-2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import math, logging
import homing
import homing, pins
class PrinterStepper:
def __init__(self, printer, config, name):
self.name = name
self.step_dist = config.getfloat('step_distance', above=0.)
self.inv_step_dist = 1. / self.step_dist
self.min_stop_interval = 0.
self.homing_speed = config.getfloat('homing_speed', 5.0, above=0.)
self.homing_positive_dir = config.getboolean(
'homing_positive_dir', False)
self.homing_retract_dist = config.getfloat(
'homing_retract_dist', 5., above=0.)
self.homing_stepper_phases = config.getint(
'homing_stepper_phases', None, minval=0)
endstop_accuracy = config.getfloat(
'homing_endstop_accuracy', None, above=0.)
self.homing_endstop_accuracy = self.homing_endstop_phase = None
if self.homing_stepper_phases:
self.homing_endstop_phase = config.getint(
'homing_endstop_phase', None, minval=0
, maxval=self.homing_stepper_phases-1)
if endstop_accuracy is None:
self.homing_endstop_accuracy = self.homing_stepper_phases//2 - 1
elif self.homing_endstop_phase is not None:
self.homing_endstop_accuracy = int(math.ceil(
endstop_accuracy * self.inv_step_dist / 2.))
# Tracking of shared stepper enable pins
class StepperEnablePin:
def __init__(self, mcu_enable, enable_count=0):
self.mcu_enable = mcu_enable
self.enable_count = enable_count
def set_enable(self, print_time, enable):
if enable:
if not self.enable_count:
self.mcu_enable.set_digital(print_time, 1)
self.enable_count += 1
else:
self.homing_endstop_accuracy = int(math.ceil(
endstop_accuracy * self.inv_step_dist))
if self.homing_endstop_accuracy >= self.homing_stepper_phases/2:
logging.info("Endstop for %s is not accurate enough for stepper"
" phase adjustment" % (name,))
self.homing_stepper_phases = None
if printer.mcu.is_fileoutput():
self.homing_endstop_accuracy = self.homing_stepper_phases
self.position_min = self.position_endstop = self.position_max = None
endstop_pin = config.get('endstop_pin', None)
step_pin = config.get('step_pin')
dir_pin = config.get('dir_pin')
mcu = printer.mcu
self.mcu_stepper = mcu.create_stepper(step_pin, dir_pin)
self.mcu_stepper.set_step_distance(self.step_dist)
enable_pin = config.get('enable_pin', None)
if enable_pin is not None:
self.mcu_enable = mcu.create_digital_out(enable_pin, 0)
if endstop_pin is not None:
self.mcu_endstop = mcu.create_endstop(endstop_pin)
self.mcu_endstop.add_stepper(self.mcu_stepper)
self.position_min = config.getfloat('position_min', 0.)
self.position_max = config.getfloat(
'position_max', 0., above=self.position_min)
self.position_endstop = config.getfloat('position_endstop')
self.enable_count -= 1
if not self.enable_count:
self.mcu_enable.set_digital(print_time, 0)
def lookup_enable_pin(printer, pin):
if pin is None:
return StepperEnablePin(None, 9999)
pin_params = pins.get_printer_pins(printer).lookup_pin(
'digital_out', pin, 'stepper_enable')
enable = pin_params.get('class')
if enable is None:
mcu_enable = pin_params['chip'].setup_pin(pin_params)
mcu_enable.setup_max_duration(0.)
pin_params['class'] = enable = StepperEnablePin(mcu_enable)
return enable
# Code storing the definitions for a stepper motor
class PrinterStepper:
def __init__(self, printer, config):
self.name = config.get_name()
if self.name.startswith('stepper_'):
self.name = self.name[8:]
self.need_motor_enable = True
# Stepper definition
self.mcu_stepper = pins.setup_pin(
printer, 'stepper', config.get('step_pin'))
dir_pin_params = pins.get_printer_pins(printer).lookup_pin(
'digital_out', config.get('dir_pin'))
self.mcu_stepper.setup_dir_pin(dir_pin_params)
self.step_dist = config.getfloat('step_distance', above=0.)
self.mcu_stepper.setup_step_distance(self.step_dist)
self.step = self.mcu_stepper.step
self.step_const = self.mcu_stepper.step_const
self.step_delta = self.mcu_stepper.step_delta
self.enable = lookup_enable_pin(printer, config.get('enable_pin', None))
def _dist_to_time(self, dist, start_velocity, accel):
# Calculate the time it takes to travel a distance with constant accel
time_offset = start_velocity / accel
@@ -71,33 +63,96 @@ class PrinterStepper:
second_last_step_time = self._dist_to_time(
2. * self.step_dist, max_halt_velocity, max_accel)
min_stop_interval = second_last_step_time - last_step_time
self.mcu_stepper.set_min_stop_interval(min_stop_interval)
def motor_enable(self, move_time, enable=0):
if enable and self.need_motor_enable:
mcu_time = self.mcu_stepper.print_to_mcu_time(move_time)
self.mcu_stepper.reset_step_clock(mcu_time)
if (self.mcu_enable is not None
and self.mcu_enable.get_last_setting() != enable):
mcu_time = self.mcu_enable.print_to_mcu_time(move_time)
self.mcu_enable.set_digital(mcu_time, enable)
self.mcu_stepper.setup_min_stop_interval(min_stop_interval)
def set_position(self, pos):
self.mcu_stepper.set_position(pos)
def motor_enable(self, print_time, enable=0):
if self.need_motor_enable != (not enable):
self.enable.set_enable(print_time, enable)
self.need_motor_enable = not enable
def enable_endstop_checking(self, move_time, step_time):
mcu_time = self.mcu_endstop.print_to_mcu_time(move_time)
self.mcu_endstop.home_start(mcu_time, step_time)
return self.mcu_endstop
def query_endstop(self, print_time):
mcu_time = self.mcu_endstop.print_to_mcu_time(print_time)
self.mcu_endstop.query_endstop(mcu_time)
return self.mcu_endstop
# Support for stepper controlled linear axis with an endstop
class PrinterHomingStepper(PrinterStepper):
def __init__(self, printer, config, default_position=None):
PrinterStepper.__init__(self, printer, config)
# Endstop and its position
self.mcu_endstop = pins.setup_pin(
printer, 'endstop', config.get('endstop_pin'))
self.mcu_endstop.add_stepper(self.mcu_stepper)
if default_position is None:
self.position_endstop = config.getfloat('position_endstop')
else:
self.position_endstop = config.getfloat(
'position_endstop', default_position)
# Axis range
self.position_min = config.getfloat('position_min', 0.)
self.position_max = config.getfloat(
'position_max', 0., above=self.position_min)
# Homing mechanics
self.homing_speed = config.getfloat('homing_speed', 5.0, above=0.)
self.homing_retract_dist = config.getfloat(
'homing_retract_dist', 5., minval=0.)
self.homing_positive_dir = config.getboolean('homing_positive_dir', None)
if self.homing_positive_dir is None:
axis_len = self.position_max - self.position_min
if self.position_endstop <= self.position_min + axis_len / 4.:
self.homing_positive_dir = False
elif self.position_endstop >= self.position_max - axis_len / 4.:
self.homing_positive_dir = True
else:
raise config.error(
"Unable to infer homing_positive_dir in section '%s'" % (
config.get_name(),))
# Endstop stepper phase position tracking
self.homing_stepper_phases = config.getint(
'homing_stepper_phases', None, minval=0)
endstop_accuracy = config.getfloat(
'homing_endstop_accuracy', None, above=0.)
self.homing_endstop_accuracy = self.homing_endstop_phase = None
if self.homing_stepper_phases:
self.homing_endstop_phase = config.getint(
'homing_endstop_phase', None, minval=0
, maxval=self.homing_stepper_phases-1)
if (self.homing_endstop_phase is not None
and config.getboolean('homing_endstop_align_zero', False)):
# Adjust the endstop position so 0.0 is always at a full step
micro_steps = self.homing_stepper_phases // 4
phase_offset = (
((self.homing_endstop_phase + micro_steps // 2) % micro_steps)
- micro_steps // 2) * self.step_dist
full_step = micro_steps * self.step_dist
es_pos = (int(self.position_endstop / full_step + .5) * full_step
+ phase_offset)
if es_pos != self.position_endstop:
logging.info("Changing %s endstop position to %.3f"
" (from %.3f)", self.name, es_pos,
self.position_endstop)
self.position_endstop = es_pos
if endstop_accuracy is None:
self.homing_endstop_accuracy = self.homing_stepper_phases//2 - 1
elif self.homing_endstop_phase is not None:
self.homing_endstop_accuracy = int(math.ceil(
endstop_accuracy * .5 / self.step_dist))
else:
self.homing_endstop_accuracy = int(math.ceil(
endstop_accuracy / self.step_dist))
if self.homing_endstop_accuracy >= self.homing_stepper_phases // 2:
logging.info("Endstop for %s is not accurate enough for stepper"
" phase adjustment", name)
self.homing_stepper_phases = None
if self.mcu_endstop.get_mcu().is_fileoutput():
self.homing_endstop_accuracy = self.homing_stepper_phases
def get_endstops(self):
return [(self.mcu_endstop, self.name)]
def get_homed_offset(self):
if not self.homing_stepper_phases or self.need_motor_enable:
return 0
return 0.
pos = self.mcu_stepper.get_mcu_position()
pos %= self.homing_stepper_phases
if self.homing_endstop_phase is None:
logging.info("Setting %s endstop phase to %d" % (self.name, pos))
logging.info("Setting %s endstop phase to %d", self.name, pos)
self.homing_endstop_phase = pos
return 0
return 0.
delta = (pos - self.homing_endstop_phase) % self.homing_stepper_phases
if delta >= self.homing_stepper_phases - self.homing_endstop_accuracy:
delta -= self.homing_stepper_phases
@@ -106,3 +161,48 @@ class PrinterStepper:
"Endstop %s incorrect phase (got %d vs %d)" % (
self.name, pos, self.homing_endstop_phase))
return delta * self.step_dist
# Wrapper for dual stepper motor support
class PrinterMultiStepper(PrinterHomingStepper):
def __init__(self, printer, config):
PrinterHomingStepper.__init__(self, printer, config)
self.endstops = PrinterHomingStepper.get_endstops(self)
self.extras = []
self.all_step_const = [self.step_const]
for i in range(1, 99):
if not config.has_section(config.get_name() + str(i)):
break
extraconfig = config.getsection(config.get_name() + str(i))
extra = PrinterStepper(printer, extraconfig)
self.extras.append(extra)
self.all_step_const.append(extra.step_const)
extraendstop = extraconfig.get('endstop_pin', None)
if extraendstop is not None:
mcu_endstop = pins.setup_pin(printer, 'endstop', extraendstop)
mcu_endstop.add_stepper(extra.mcu_stepper)
self.endstops.append((mcu_endstop, extra.name))
else:
self.mcu_endstop.add_stepper(extra.mcu_stepper)
self.step_const = self.step_multi_const
def step_multi_const(self, print_time, start_pos, dist, start_v, accel):
for step_const in self.all_step_const:
step_const(print_time, start_pos, dist, start_v, accel)
def set_max_jerk(self, max_halt_velocity, max_accel):
PrinterHomingStepper.set_max_jerk(self, max_halt_velocity, max_accel)
for extra in self.extras:
extra.set_max_jerk(max_halt_velocity, max_accel)
def set_position(self, pos):
PrinterHomingStepper.set_position(self, pos)
for extra in self.extras:
extra.set_position(pos)
def motor_enable(self, print_time, enable=0):
PrinterHomingStepper.motor_enable(self, print_time, enable)
for extra in self.extras:
extra.motor_enable(print_time, enable)
def get_endstops(self):
return self.endstops
def LookupMultiHomingStepper(printer, config):
if not config.has_section(config.get_name() + '1'):
return PrinterHomingStepper(printer, config)
return PrinterMultiStepper(printer, config)

View File

@@ -1,10 +1,10 @@
# Code for coordinating events on the printer toolhead
#
# Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
# Copyright (C) 2016-2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import math, logging
import cartesian, corexy, delta, extruder
import mcu, homing, cartesian, corexy, delta, extruder
# Common suffixes: _d is distance (in mm), _v is velocity (in
# mm/second), _v2 is velocity squared (mm^2/s^2), _t is time (in
@@ -42,18 +42,18 @@ class Move:
self.delta_v2 = 2.0 * self.move_d * self.accel
self.smooth_delta_v2 = min(self.smooth_delta_v2, self.delta_v2)
def calc_junction(self, prev_move):
axes_d = self.axes_d
prev_axes_d = prev_move.axes_d
if (axes_d[2] or prev_axes_d[2] or self.accel != prev_move.accel
or not self.is_kinematic_move or not prev_move.is_kinematic_move):
if not self.is_kinematic_move or not prev_move.is_kinematic_move:
return
# Allow extruder to calculate its maximum junction
extruder_v2 = self.toolhead.extruder.calc_junction(prev_move, self)
# Find max velocity using approximated centripetal velocity as
# described at:
# https://onehossshay.wordpress.com/2011/09/24/improving_grbl_cornering_algorithm/
axes_d = self.axes_d
prev_axes_d = prev_move.axes_d
junction_cos_theta = -((axes_d[0] * prev_axes_d[0]
+ axes_d[1] * prev_axes_d[1])
+ axes_d[1] * prev_axes_d[1]
+ axes_d[2] * prev_axes_d[2])
/ (self.move_d * prev_move.move_d))
if junction_cos_theta > 0.999999:
return
@@ -61,8 +61,9 @@ class Move:
sin_theta_d2 = math.sqrt(0.5*(1.0-junction_cos_theta))
R = self.toolhead.junction_deviation * sin_theta_d2 / (1. - sin_theta_d2)
self.max_start_v2 = min(
R * self.accel, self.max_cruise_v2, prev_move.max_cruise_v2
, extruder_v2, prev_move.max_start_v2 + prev_move.delta_v2)
R * self.accel, R * prev_move.accel, extruder_v2
, self.max_cruise_v2, prev_move.max_cruise_v2
, prev_move.max_start_v2 + prev_move.delta_v2)
self.max_smoothed_v2 = min(
self.max_start_v2
, prev_move.max_smoothed_v2 + prev_move.smooth_delta_v2)
@@ -96,8 +97,8 @@ LOOKAHEAD_FLUSH_TIME = 0.250
# Class to track a list of pending move requests and to facilitate
# "look-ahead" across moves to reduce acceleration between moves.
class MoveQueue:
def __init__(self, extruder_lookahead):
self.extruder_lookahead = extruder_lookahead
def __init__(self):
self.extruder_lookahead = None
self.queue = []
self.leftover = 0
self.junction_flush = LOOKAHEAD_FLUSH_TIME
@@ -107,6 +108,8 @@ class MoveQueue:
self.junction_flush = LOOKAHEAD_FLUSH_TIME
def set_flush_time(self, flush_time):
self.junction_flush = flush_time
def set_extruder(self, extruder):
self.extruder_lookahead = extruder.lookahead
def flush(self, lazy=False):
self.junction_flush = LOOKAHEAD_FLUSH_TIME
update_flush_count = lazy
@@ -180,22 +183,17 @@ STALL_TIME = 0.100
class ToolHead:
def __init__(self, printer, config):
self.printer = printer
self.reactor = printer.reactor
self.extruder = printer.objects.get('extruder')
if self.extruder is None:
self.extruder = extruder.DummyExtruder()
kintypes = {'cartesian': cartesian.CartKinematics,
'corexy': corexy.CoreXYKinematics,
'delta': delta.DeltaKinematics}
self.kin = config.getchoice('kinematics', kintypes)(printer, config)
self.max_speed = config.getfloat('max_velocity', above=0.)
self.reactor = printer.get_reactor()
self.all_mcus = printer.lookup_module_objects('mcu')
self.mcu = self.all_mcus[0]
self.max_velocity = config.getfloat('max_velocity', above=0.)
self.max_accel = config.getfloat('max_accel', above=0.)
self.max_accel_to_decel = config.getfloat(
'max_accel_to_decel', self.max_accel * 0.5
, above=0., maxval=self.max_accel)
self.junction_deviation = config.getfloat(
'junction_deviation', 0.02, above=0.)
self.move_queue = MoveQueue(self.extruder.lookahead)
'junction_deviation', 0.02, minval=0.)
self.move_queue = MoveQueue()
self.commanded_pos = [0., 0., 0., 0.]
# Print time tracking
self.buffer_time_low = config.getfloat(
@@ -207,130 +205,121 @@ class ToolHead:
self.move_flush_time = config.getfloat(
'move_flush_time', 0.050, above=0.)
self.print_time = 0.
self.last_print_end_time = self.reactor.monotonic()
self.last_print_start_time = 0.
self.need_check_stall = -1.
self.print_stall = 0
self.synch_print_time = True
self.forced_synch = False
self.sync_print_time = True
self.idle_flush_print_time = 0.
self.flush_timer = self.reactor.register_timer(self._flush_handler)
self.move_queue.set_flush_time(self.buffer_time_high)
# Motor off tracking
self.motor_off_time = config.getfloat(
'motor_off_time', 600.000, minval=0.)
self.need_motor_off = False
self.motor_off_time = config.getfloat('motor_off_time', 600., above=0.)
self.motor_off_timer = self.reactor.register_timer(
self._motor_off_handler)
# Determine the maximum velocity a cartesian axis could have
# before cornering. The 8. was determined experimentally.
xy_halt = math.sqrt(8. * self.junction_deviation * self.max_accel)
self.kin.set_max_jerk(xy_halt, self.max_speed, self.max_accel)
self.extruder.set_max_jerk(xy_halt, self.max_speed, self.max_accel)
self._motor_off_handler, self.reactor.NOW)
# Create kinematics class
self.extruder = extruder.DummyExtruder()
self.move_queue.set_extruder(self.extruder)
kintypes = {'cartesian': cartesian.CartKinematics,
'corexy': corexy.CoreXYKinematics,
'delta': delta.DeltaKinematics}
self.kin = config.getchoice('kinematics', kintypes)(
self, printer, config)
# Print time tracking
def update_move_time(self, movetime):
self.print_time += movetime
flush_to_time = self.print_time - self.move_flush_time
self.printer.mcu.flush_moves(flush_to_time)
for m in self.all_mcus:
m.flush_moves(flush_to_time)
def get_next_move_time(self):
if self.synch_print_time:
curtime = self.reactor.monotonic()
if self.print_time:
buffer_time = self.printer.mcu.get_print_buffer_time(
curtime, self.print_time)
self.print_time += max(self.buffer_time_start - buffer_time, 0.)
if self.forced_synch:
self.print_stall += 1
self.forced_synch = False
else:
self.printer.mcu.set_print_start_time(curtime)
self.print_time = self.buffer_time_start
self._reset_motor_off()
self.reactor.update_timer(self.flush_timer, self.reactor.NOW)
self.synch_print_time = False
if not self.sync_print_time:
return self.print_time
def _flush_lookahead(self, must_synch=False):
synch_print_time = self.synch_print_time
self.sync_print_time = False
self.need_motor_off = True
est_print_time = self.mcu.estimated_print_time(self.reactor.monotonic())
if est_print_time + self.buffer_time_start > self.print_time:
self.print_time = est_print_time + self.buffer_time_start
self.last_print_start_time = self.print_time
self.reactor.update_timer(self.flush_timer, self.reactor.NOW)
return self.print_time
def _flush_lookahead(self, must_sync=False):
sync_print_time = self.sync_print_time
self.move_queue.flush()
if synch_print_time or must_synch:
self.synch_print_time = True
self.idle_flush_print_time = 0.
if sync_print_time or must_sync:
self.sync_print_time = True
self.move_queue.set_flush_time(self.buffer_time_high)
self.printer.mcu.flush_moves(self.print_time)
self.need_check_stall = -1.
self.reactor.update_timer(self.flush_timer, self.reactor.NEVER)
for m in self.all_mcus:
m.flush_moves(self.print_time)
def get_last_move_time(self):
self._flush_lookahead()
return self.get_next_move_time()
def reset_print_time(self):
self._flush_lookahead(must_synch=True)
self.print_time = 0.
self.last_print_end_time = self.reactor.monotonic()
self.need_check_stall = -1.
self.forced_synch = False
self._reset_motor_off()
def reset_print_time(self, min_print_time=0.):
self._flush_lookahead(must_sync=True)
self.print_time = max(min_print_time, self.mcu.estimated_print_time(
self.reactor.monotonic()))
def _check_stall(self):
eventtime = self.reactor.monotonic()
if not self.print_time:
if self.sync_print_time:
# Building initial queue - make sure to flush on idle input
if self.idle_flush_print_time:
est_print_time = self.mcu.estimated_print_time(eventtime)
if est_print_time < self.idle_flush_print_time:
self.print_stall += 1
self.idle_flush_print_time = 0.
self.reactor.update_timer(self.flush_timer, eventtime + 0.100)
return
# Check if there are lots of queued moves and stall if so
while 1:
buffer_time = self.printer.mcu.get_print_buffer_time(
eventtime, self.print_time)
est_print_time = self.mcu.estimated_print_time(eventtime)
buffer_time = self.print_time - est_print_time
stall_time = buffer_time - self.buffer_time_high
if stall_time <= 0.:
break
eventtime = self.reactor.pause(eventtime + stall_time)
if not self.print_time:
if self.mcu.is_fileoutput():
self.need_check_stall = self.reactor.NEVER
return
self.need_check_stall = self.print_time - stall_time + 0.100
eventtime = self.reactor.pause(eventtime + min(1., stall_time))
self.need_check_stall = est_print_time + self.buffer_time_high + 0.100
def _flush_handler(self, eventtime):
try:
if not self.print_time:
# Input idled before filling lookahead queue - flush it
self._flush_lookahead()
if not self.print_time:
return self.reactor.NEVER
print_time = self.print_time
buffer_time = self.printer.mcu.get_print_buffer_time(
eventtime, print_time)
buffer_time = print_time - self.mcu.estimated_print_time(eventtime)
if buffer_time > self.buffer_time_low:
# Running normally - reschedule check
return eventtime + buffer_time - self.buffer_time_low
# Under ran low buffer mark - flush lookahead queue
self._flush_lookahead(must_synch=True)
self._flush_lookahead(must_sync=True)
if print_time != self.print_time:
# Flushed something - retry
self.forced_synch = True
return self.reactor.NOW
if buffer_time > 0.:
# Wait for buffer to fully empty
return eventtime + buffer_time
self.reset_print_time()
self.idle_flush_print_time = self.print_time
except:
logging.exception("Exception in flush_handler")
self.force_shutdown()
self.printer.invoke_shutdown("Exception in flush_handler")
return self.reactor.NEVER
# Motor off timer
def _reset_motor_off(self):
if not self.print_time:
waketime = self.reactor.monotonic() + self.motor_off_time
else:
waketime = self.reactor.NEVER
self.reactor.update_timer(self.motor_off_timer, waketime)
def _motor_off_handler(self, eventtime):
if not self.need_motor_off or not self.sync_print_time:
return eventtime + self.motor_off_time
elapsed_time = self.mcu.estimated_print_time(eventtime) - self.print_time
if elapsed_time < self.motor_off_time:
return eventtime + self.motor_off_time - elapsed_time
try:
self.motor_off()
self.reset_print_time()
except:
logging.exception("Exception in motor_off_handler")
self.force_shutdown()
return self.reactor.NEVER
self.printer.invoke_shutdown("Exception in motor_off_handler")
return eventtime + self.motor_off_time
# Movement commands
def get_position(self):
return list(self.commanded_pos)
def set_position(self, newpos):
def set_position(self, newpos, homing_axes=()):
self._flush_lookahead()
self.commanded_pos[:] = newpos
self.kin.set_position(newpos)
self.kin.set_position(newpos, homing_axes)
def move(self, newpos, speed):
speed = min(speed, self.max_speed)
speed = min(speed, self.max_velocity)
move = Move(self, self.commanded_pos, newpos, speed)
if not move.move_d:
return
@@ -342,11 +331,10 @@ class ToolHead:
self.move_queue.add_move(move)
if self.print_time > self.need_check_stall:
self._check_stall()
def home(self, homing_state):
self.kin.home(homing_state)
def dwell(self, delay):
def dwell(self, delay, check_stall=True):
self.get_last_move_time()
self.update_move_time(delay)
if check_stall:
self._check_stall()
def motor_off(self):
self.dwell(STALL_TIME)
@@ -354,31 +342,58 @@ class ToolHead:
self.kin.motor_off(last_move_time)
self.extruder.motor_off(last_move_time)
self.dwell(STALL_TIME)
logging.debug('; Max time of %f' % (last_move_time,))
self.need_motor_off = False
logging.debug('; Max time of %f', last_move_time)
def wait_moves(self):
self._flush_lookahead()
if self.mcu.is_fileoutput():
return
eventtime = self.reactor.monotonic()
while self.print_time:
while (not self.sync_print_time
or self.print_time >= self.mcu.estimated_print_time(eventtime)):
eventtime = self.reactor.pause(eventtime + 0.100)
def query_endstops(self):
def set_extruder(self, extruder):
last_move_time = self.get_last_move_time()
return self.kin.query_endstops(last_move_time)
self.extruder.set_active(last_move_time, False)
extrude_pos = extruder.set_active(last_move_time, True)
self.extruder = extruder
self.move_queue.set_extruder(extruder)
self.commanded_pos[3] = extrude_pos
# Misc commands
def stats(self, eventtime):
buffer_time = 0.
print_time = self.print_time
if print_time:
is_active = True
buffer_time = max(0., self.printer.mcu.get_print_buffer_time(
eventtime, print_time))
else:
is_active = eventtime < self.last_print_end_time + 60.
for m in self.all_mcus:
m.check_active(self.print_time, eventtime)
buffer_time = self.print_time - self.mcu.estimated_print_time(eventtime)
is_active = buffer_time > -60. or not self.sync_print_time
return is_active, "print_time=%.3f buffer_time=%.3f print_stall=%d" % (
print_time, buffer_time, self.print_stall)
def force_shutdown(self):
self.print_time, max(buffer_time, 0.), self.print_stall)
def get_status(self, eventtime):
buffer_time = self.print_time - self.mcu.estimated_print_time(eventtime)
if buffer_time > -1. or not self.sync_print_time:
status = "Printing"
elif self.need_motor_off:
status = "Ready"
else:
status = "Idle"
printing_time = self.print_time - self.last_print_start_time
return {'status': status, 'printing_time': printing_time}
def printer_state(self, state):
if state == 'shutdown':
try:
self.printer.mcu.force_shutdown()
self.move_queue.reset()
self.reset_print_time()
except:
logging.exception("Exception in force_shutdown")
logging.exception("Exception in toolhead shutdown")
def get_kinematics(self):
return self.kin
def get_max_velocity(self):
return self.max_velocity, self.max_accel
def get_max_axis_halt(self):
# Determine the maximum velocity a cartesian axis could halt
# at due to the junction_deviation setting. The 8.0 was
# determined experimentally.
return min(self.max_velocity,
math.sqrt(8. * self.junction_deviation * self.max_accel))
def add_printer_objects(printer, config):
printer.add_object('toolhead', ToolHead(printer, config))

View File

@@ -30,8 +30,7 @@ def create_pty(ptyname):
except os.error:
pass
os.symlink(os.ttyname(sfd), ptyname)
fcntl.fcntl(mfd, fcntl.F_SETFL
, fcntl.fcntl(mfd, fcntl.F_GETFL) | os.O_NONBLOCK)
set_nonblock(mfd)
old = termios.tcgetattr(mfd)
old[3] = old[3] & ~termios.ECHO
termios.tcsetattr(mfd, termios.TCSADRAIN, old)
@@ -43,8 +42,8 @@ def get_cpu_info():
data = f.read()
f.close()
except OSError:
logging.debug("Exception on read /proc/cpuinfo: %s" % (
traceback.format_exc(),))
logging.debug("Exception on read /proc/cpuinfo: %s",
traceback.format_exc())
return "?"
lines = [l.split(':', 1) for l in data.split('\n')]
lines = [(l[0].strip(), l[1].strip()) for l in lines if len(l) == 2]
@@ -54,16 +53,16 @@ def get_cpu_info():
def get_git_version():
# Obtain version info from "git" program
gitdir = os.path.join(sys.path[0], '..', '.git')
gitdir = os.path.join(sys.path[0], '..')
if not os.path.exists(gitdir):
logging.debug("No '.git' file/directory found")
return "?"
prog = "git --git-dir=%s describe --tags --long --dirty" % (gitdir,)
prog = "git -C %s describe --always --tags --long --dirty" % (gitdir,)
try:
process = subprocess.Popen(shlex.split(prog), stdout=subprocess.PIPE)
output = process.communicate()[0]
retcode = process.poll()
except OSError:
logging.debug("Exception on run: %s" % (traceback.format_exc(),))
logging.debug("Exception on run: %s", traceback.format_exc())
return "?"
return output.strip()

View File

@@ -3,14 +3,22 @@ This directory contains external library code.
The pjrc_usb_serial directory contains code from:
http://www.pjrc.com/teensy/usb_serial.html
version 1.7 (extracted on 20160605). It has been modified to compile
on recent versions of gcc. See usb_serial.patch for the modifications.
on recent versions of gcc, to support asynchronous notification of
incoming data, and to not use SOF interrupts. See usb_serial.patch for
the modifications.
The cmsis-sam3x8e directory contains code from the Arduino project:
https://www.arduino.cc/
version 1.5.1 (extracted on 20160608). It has been modified to
compile with gcc's LTO feature. See cmsis-sam3x8e.patch for the
modifications.
version 1.5.1 (extracted on 20160608). It has been modified to compile
with gcc's LTO feature. See cmsis-sam3x8e.patch for the modifications.
The hub-ctrl directory contains code from:
https://github.com/codazoda/hub-ctrl.c/
revision 42095e522859059e8a5f4ec05c1e3def01a870a9.
The pru_rpmsg directory contains code from:
https://github.com/dinuxbg/pru-gcc-examples
revision 425a42d82006cf0aa24be27b483d2f6a41607489. The code is taken
from the repo's hc-sr04-range-sensor directory. It has been modified
so that the IEP definitions compile correctly. See pru_rpmsg.patch for
the modifications.

View File

@@ -325,7 +325,7 @@ void usb_init(void)
UDCON = 0; // enable attach resistor
usb_configuration = 0;
cdc_line_rtsdtr = 0;
UDIEN = (1<<EORSTE)|(1<<SOFE);
UDIEN = (1<<EORSTE);
sei();
}
@@ -359,6 +359,7 @@ int16_t usb_serial_getchar(void)
UEINTX = 0x6B;
goto retry;
}
UEIENX = (1<<RXOUTE);
SREG = intr_state;
return -1;
}
@@ -775,7 +776,14 @@ static inline void usb_ack_out(void)
//
ISR(USB_COM_vect)
{
uint8_t intbits;
uint8_t intbits = UEINT;
if (intbits & (1<<CDC_RX_ENDPOINT)) {
UENUM = CDC_RX_ENDPOINT;
UEIENX = 0;
extern void sched_wake_tasks(void);
sched_wake_tasks();
return;
}
const uint8_t *list;
const uint8_t *cfg;
uint8_t i, n, len, en;

View File

@@ -1,5 +1,5 @@
--- usb_serial.c 2011-04-19 05:54:12.000000000 -0400
+++ usb_serial.c 2016-06-04 23:48:52.590001697 -0400
--- ../../../lib/pjrc/usb_serial/usb_serial.c 2011-04-19 05:54:12.000000000 -0400
+++ usb_serial.c 2017-08-07 11:32:47.106357362 -0400
@@ -30,6 +30,7 @@
// Version 1.6: fix zero length packet bug
// Version 1.7: fix usb_serial_set_control
@@ -62,7 +62,24 @@
uint16_t wValue;
uint16_t wIndex;
const uint8_t *addr;
@@ -646,7 +647,9 @@
@@ -324,7 +325,7 @@
UDCON = 0; // enable attach resistor
usb_configuration = 0;
cdc_line_rtsdtr = 0;
- UDIEN = (1<<EORSTE)|(1<<SOFE);
+ UDIEN = (1<<EORSTE);
sei();
}
@@ -358,6 +359,7 @@
UEINTX = 0x6B;
goto retry;
}
+ UEIENX = (1<<RXOUTE);
SREG = intr_state;
return -1;
}
@@ -646,7 +648,9 @@
// communication
uint32_t usb_serial_get_baud(void)
{
@@ -73,3 +90,19 @@
}
uint8_t usb_serial_get_stopbits(void)
{
@@ -772,7 +776,14 @@
//
ISR(USB_COM_vect)
{
- uint8_t intbits;
+ uint8_t intbits = UEINT;
+ if (intbits & (1<<CDC_RX_ENDPOINT)) {
+ UENUM = CDC_RX_ENDPOINT;
+ UEIENX = 0;
+ extern void sched_wake_tasks(void);
+ sched_wake_tasks();
+ return;
+ }
const uint8_t *list;
const uint8_t *cfg;
uint8_t i, n, len, en;

View File

@@ -0,0 +1,25 @@
Programmable Real-time Unit (PRU) Software Support Package
------------------------------------------------------------
============================================================
INCLUDE
============================================================
DESCRIPTION
This directory provides header files for PRU firmware.
For more details about these header files, visit:
http://processors.wiki.ti.com/index.php/PRU-ICSS_Header_Files
ADDITIONAL RESOURCES
For more information about the PRU, visit:
PRU-ICSS Wiki - http://processors.wiki.ti.com/index.php/PRU-ICSS
PRU Training Slides - http://www.ti.com/sitarabootcamp
PRU Evaluation Hardware - http://www.ti.com/tool/PRUCAPE
Support - http://e2e.ti.com

View File

@@ -0,0 +1,249 @@
/*
* Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _PRU_CFG_H_
#define _PRU_CFG_H_
/* PRU_CFG register set */
typedef struct {
/* PRU_CFG_REVID register bit field */
union {
volatile uint32_t REVID;
volatile struct {
unsigned REVID : 32;
} REVID_bit;
}; // 0x0
/* PRU_CFG_SYSCFG register bit field */
union {
volatile uint32_t SYSCFG;
volatile struct {
unsigned IDLE_MODE : 2;
unsigned STANDBY_MODE : 2;
unsigned STANDBY_INIT : 1;
unsigned SUB_MWAIT : 1;
unsigned rsvd6 : 26;
} SYSCFG_bit;
}; // 0x4
/* PRU_CFG_GPCFG0 register bit field */
union {
volatile uint32_t GPCFG0;
volatile struct {
unsigned PRU0_GPI_MODE : 2; // 1:0
unsigned PRU0_GPI_CLK_MODE : 1; // 2
unsigned PRU0_GPI_DIV0 : 5; // 7:3
unsigned PRU0_GPI_DIV1 : 5; // 12:8
unsigned PRU0_GPI_SB : 1; // 13
unsigned PRU0_GPO_MODE : 1; // 14
unsigned PRU0_GPO_DIV0 : 5; // 19:15
unsigned PRU0_GPO_DIV1 : 5; // 24:20
unsigned PRU0_GPO_SH_SEL : 1; // 25
unsigned rsvd26 : 6; // 31:26
} GPCFG0_bit;
}; // 0x8
/* PRU_CFG_GPCFG1 register bit field */
union {
volatile uint32_t GPCFG1;
volatile struct {
unsigned PRU1_GPI_MODE : 2; // 1:0
unsigned PRU1_GPI_CLK_MODE : 1; // 2
unsigned PRU1_GPI_DIV0 : 5; // 7:3
unsigned PRU1_GPI_DIV1 : 5; // 12:8
unsigned PRU1_GPI_SB : 1; // 13
unsigned PRU1_GPO_MODE : 1; // 14
unsigned PRU1_GPO_DIV0 : 5; // 19:15
unsigned PRU1_GPO_DIV1 : 5; // 24:20
unsigned PRU1_GPO_SH_SEL : 1; // 25
unsigned rsvd26 : 6; // 31:26
} GPCFG1_bit;
}; // 0xC
/* PRU_CFG_CGR register bit field */
union {
volatile uint32_t CGR;
volatile struct {
unsigned PRU0_CLK_STOP_REQ : 1; // 0
unsigned PRU0_CLK_STOP_ACK : 1; // 1
unsigned PRU0_CLK_EN : 1; // 2
unsigned PRU1_CLK_STOP_REQ : 1; // 3
unsigned PRU1_CLK_STOP_ACK : 1; // 4
unsigned PRU1_CLK_EN : 1; // 5
unsigned INTC_CLK_STOP_REQ : 1; // 6
unsigned INTC_CLK_STOP_ACK : 1; // 7
unsigned INTC_CLK_EN : 1; // 8
unsigned UART_CLK_STOP_REQ : 1; // 9
unsigned UART_CLK_STOP_ACK : 1; // 10
unsigned UART_CLK_EN : 1; // 11
unsigned ECAP_CLK_STOP_REQ : 1; // 12
unsigned ECAP_CLK_STOP_ACK : 1; // 13
unsigned ECAP_CLK_EN : 1; // 14
unsigned IEP_CLK_STOP_REQ : 1; // 15
unsigned IEP_CLK_STOP_ACK : 1; // 16
unsigned IEP_CLK_EN : 1; // 17
unsigned rsvd18 : 14; // 31:18
} CGR_bit;
}; // 0x10
/* PRU_CFG_ISRP register bit field */
union {
volatile uint32_t ISRP;
volatile struct {
unsigned PRU0_IMEM_PE_RAW : 4; // 3:0
unsigned PRU0_DMEM_PE_RAW : 4; // 7:4
unsigned PRU1_IMEM_PE_RAW : 4; // 11:8
unsigned PRU1_DMEM_PE_RAW : 4; // 15:12
unsigned RAM_PE_RAW : 4; // 19:16
unsigned rsvd20 : 12; // 31:20
} ISRP_bit;
}; // 0x14
/* PRU_CFG_ISP register bit field */
union {
volatile uint32_t ISP;
volatile struct {
unsigned PRU0_IMEM_PE : 4; // 3:0
unsigned PRU0_DMEM_PE : 4; // 7:4
unsigned PRU1_IMEM_PE : 4; // 11:8
unsigned PRU1_DMEM_PE : 4; // 15:12
unsigned RAM_PE : 4; // 19:16
unsigned rsvd20 : 12; // 31:20
} ISP_bit;
}; // 0x18
/* PRU_CFG_IESP register bit field */
union {
volatile uint32_t IESP;
volatile struct {
unsigned PRU0_IMEM_PE_SET : 4; // 3:0
unsigned PRU0_DMEM_PE_SET : 4; // 7:4
unsigned PRU1_IMEM_PE_SET : 4; // 11:8
unsigned PRU1_DMEM_PE_SET : 4; // 15:12
unsigned RAM_PE_SET : 4; // 19:16
unsigned rsvd20 : 12; // 31:20
} IESP_bit;
}; // 0x1C
/* PRU_CFG_IECP register bit field */
union {
volatile uint32_t IECP;
volatile struct {
unsigned PRU0_IMEM_PE_CLR : 4; // 3:0
unsigned PRU0_DMEM_PE_CLR : 4; // 7:4
unsigned PRU1_IMEM_PE_CLR : 4; // 11:8
unsigned PRU1_DMEM_PE_CLR : 4; // 15:12
unsigned rsvd16 : 16; // 31:16
} IECP_bit;
}; // 0x20
uint32_t rsvd24; // 0x24
/* PRU_CFG_PMAO register bit field */
union {
volatile uint32_t PMAO;
volatile struct {
unsigned PMAO_PRU0 : 1; // 0
unsigned PMAO_PRU1 : 1; // 1
unsigned rsvd2 : 30; // 31:2
} PMAO_bit;
}; // 0x28
uint32_t rsvd2c[1]; // 0x2C
/* PRU_CFG_IEPCLK register bit field */
union {
volatile uint32_t IEPCLK;
volatile struct {
unsigned OCP_EN : 1; // 0
unsigned rsvd1 : 31; // 31:1
} IEPCLK_bit;
}; // 0x30
/* PRU_CFG_SPP register bit field */
union {
volatile uint32_t SPP;
volatile struct {
unsigned PRU1_PAD_HP_EN : 1; // 0
unsigned XFR_SHIFT_EN : 1; // 1
unsigned rsvd2 : 30; // 31:2
} SPP_bit;
}; // 0x34
uint32_t rsvd38[2]; // 0x38 - 0x3C
union {
volatile uint32_t PIN_MX;
volatile struct {
unsigned PIN_MUX_SEL : 8; // 7:0
unsigned rsvd2 : 24; // 31:8
} PIN_MX_bit;
}; //0x40
} pruCfg;
#ifdef __GNUC__
static volatile pruCfg *__CT_CFG = (void *)0x00026000;
#define CT_CFG (*__CT_CFG)
#else
volatile __far pruCfg CT_CFG __attribute__((cregister("PRU_CFG", near), peripheral));
#endif
#endif /* _PRU_CFG_H_ */

View File

@@ -0,0 +1,155 @@
/*
* Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _PRU_CTRL_H_
#define _PRU_CTRL_H_
/* PRU_CTRL register set */
typedef struct {
/* PRU_CTRL_CTRL register bit field */
union {
volatile uint32_t CTRL;
volatile struct {
unsigned SOFT_RST_N : 1;
unsigned EN : 1;
unsigned SLEEPING : 1;
unsigned CTR_EN : 1;
unsigned rsvd4 : 4;
unsigned SINGLE_STEP : 1;
unsigned rsvd9 : 6;
unsigned RUNSTATE : 1;
unsigned PCTR_RST_VAL : 16;
} CTRL_bit;
}; // 0x0
/* PRU_CTRL_STS register bit field */
union {
volatile uint32_t STS;
volatile struct {
unsigned PCTR : 16;
unsigned rsvd16 : 16;
} STS_bit;
}; // 0x4
/* PRU_CTRL_WAKEUP_EN register bit field */
union {
volatile uint32_t WAKEUP_EN;
volatile struct {
unsigned BITWISE_ENS : 32;
} WAKEUP_EN_bit;
}; // 0x8
/* PRU_CTRL_CYCLE register bit field */
union {
volatile uint32_t CYCLE;
volatile struct {
unsigned CYCLECOUNT : 32;
} CYCLE_bit;
}; // 0xC
/* PRU_CTRL_STALL register bit field */
union {
volatile uint32_t STALL;
volatile struct {
unsigned STALLCOUNT : 32;
} STALL_bit;
}; // 0x10
uint32_t rsvd14[3]; // 0x14 - 0x1C
/* PRU_CTRL_CTBIR0 register bit field */
union {
volatile uint32_t CTBIR0;
volatile struct {
unsigned C24_BLK_IDX : 8;
unsigned rsvd8 : 8;
unsigned C25_BLK_IDX : 8;
unsigned rsvd24 : 8;
} CTBIR0_bit;
}; // 0x20
/* PRU_CTRL_CTBIR1 register bit field */
union {
volatile uint32_t CTBIR1;
volatile struct {
unsigned C26_BLK_IDX : 8;
unsigned rsvd8 : 8;
unsigned C27_BLK_IDX : 8;
unsigned rsvd24 : 8;
} CTBIR1_bit;
}; // 0x24
/* PRU_CTRL_CTPPR0 register bit field */
union {
volatile uint32_t CTPPR0;
volatile struct {
unsigned C28_BLK_POINTER : 16;
unsigned C29_BLK_POINTER : 16;
} CTPPR0_bit;
}; // 0x28
/* PRU_CTRL_CTPPR1 register bit field */
union {
volatile uint32_t CTPPR1;
volatile struct {
unsigned C30_BLK_POINTER : 16;
unsigned C31_BLK_POINTER : 16;
} CTPPR1_bit;
}; // 0x2C
} pruCtrl;
/* Definition of control register structures. */
#define PRU0_CTRL (*((volatile pruCtrl*)0x22000))
#define PRU1_CTRL (*((volatile pruCtrl*)0x24000))
#endif /* _PRU_CTRL_H_ */

View File

@@ -0,0 +1,128 @@
/*
* Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _PRU_ECAP_H_
#define _PRU_ECAP_H_
/* PRU_ECAP register set */
typedef struct {
/* PRU_ECAP_TSCTR register bit field */
union {
volatile uint32_t TSCTR;
volatile struct {
unsigned TSCTR : 32; //31:0
} TSCTR_bit;
}; // 0x0
/* PRU_ECAP_CTRPHS register bit field */
union {
volatile uint32_t CTRPHS;
volatile struct {
unsigned CTRPHS : 32; //31:0
} CTRPHS_bit;
}; // 0x4
/* PRU_ECAP_CAP1 register bit field */
union {
volatile uint32_t CAP1;
volatile struct {
unsigned CAP1 : 32; //31:0
} CAP1_bit;
}; // 0x8
/* PRU_ECAP_CAP2 register bit field */
union {
volatile uint32_t CAP2;
volatile struct {
unsigned CAP2 : 32; //31:0
} CAP2_bit;
}; // 0xC
/* PRU_ECAP_CAP3 register bit field */
union {
volatile uint32_t CAP3;
volatile struct {
unsigned CAP3 : 32; //31:0
} CAP3_bit;
}; // 0x10
/* PRU_ECAP_CAP4 register bit field */
union {
volatile uint32_t CAP4;
volatile struct {
unsigned CAP4 : 32; //31:0
} CAP4_bit;
}; // 0x14
uint32_t rsvd118[4]; // 0x118 - 0x124
/* PRU_ECAP_ECCTL1 register bit field */
volatile uint16_t ECCTL1; // 0x28
/* PRU_ECAP_ECCTL2 register bit field */
volatile uint16_t ECCTL2; // 0x2A
/* PRU_ECAP_ECEINT register bit field */
volatile uint16_t ECEINT; // 0x2C
/* PRU_ECAP_ECFLG register bit field */
volatile uint16_t ECFLG; // 0x2E
/* PRU_ECAP_ECCLR register bit field */
volatile uint16_t ECCLR; // 0x30
/* PRU_ECAP_ECFRC register bit field */
volatile uint16_t ECFRC; // 0x32
uint32_t rsvd34[10]; // 0x34 - 0x58
/* PRU_ECAP_REVID register bit field */
union {
volatile uint32_t REVID;
volatile struct {
unsigned REV : 32; //31:0
} REVID_bit;
}; // 0x5C
} pruEcap;
volatile __far pruEcap CT_ECAP __attribute__((cregister("PRU_ECAP", near), peripheral));
#endif /* _PRU_ECAP_H_ */

View File

@@ -0,0 +1,261 @@
/*
* Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _PRU_IEP_H_
#define _PRU_IEP_H_
/* PRU IEP register set */
typedef struct {
/* PRU_IEP_TMR_GLB_CFG register bit field */
union {
volatile uint32_t TMR_GLB_CFG;
volatile struct {
unsigned CNT_EN : 1; // 0
unsigned rsvd1 : 3; // 3:1
unsigned DEFAULT_INC : 4; // 7:4
unsigned CMP_INC : 12; // 19:8
unsigned rsvd12 : 12; // 31:20
} TMR_GLB_CFG_bit;
}; // 0x0
/* PRU_IEP_TMR_GLB_STS register bit field */
union {
volatile uint32_t TMR_GLB_STS;
volatile struct {
unsigned CNT_OVF : 1; // 0
unsigned rsvd1 : 31; // 31:1
} TMR_GLB_STS_bit;
}; // 0x4
/* PRU_IEP_TMR_COMPEN register bit field */
union {
volatile uint32_t TMR_COMPEN;
volatile struct {
unsigned COMPEN_CNT : 24; // 23:0
unsigned rsvd24 : 8; // 31:24
} TMR_COMPEN_bit;
}; // 0x8
/* PRU_IEP_TMR_CNT register bit field */
union {
volatile uint32_t TMR_CNT;
volatile struct {
unsigned COUNT : 32; // 31:0
} TMR_CNT_bit;
}; // 0xC
uint32_t rsvd10[12]; // 0x10 - 0x3C
/* PRU_IEP_TMR_CMP_CFG register bit field */
union {
volatile uint32_t TMR_CMP_CFG;
volatile struct {
unsigned CMP0_RST_CNT_EN : 1; // 0
unsigned CMP_EN : 8; // 8:1
unsigned rsvd9 : 23; // 31:9
} TMR_CMP_CFG_bit;
}; // 0x40
/* PRU_IEP_TMR_CMP_STS register bit field */
union {
volatile uint32_t TMR_CMP_STS;
volatile struct {
unsigned CMP_HIT : 8; // 7:0
unsigned rsvd8 : 24; // 31:8
} TMR_CMP_STS_bit;
}; // 0x44
/* PRU_IEP_TMR_CMP0 register bit field */
union {
volatile uint32_t TMR_CMP0;
volatile struct {
unsigned CMP0 : 32; // 31:0
} TMR_CMP0_bit;
}; // 0x48
/* PRU_IEP_TMR_CMP1 register bit field */
union {
volatile uint32_t TMR_CMP1;
volatile struct {
unsigned CMP1 : 32; // 31:0
} TMR_CMP1_bit;
}; // 0x4C
/* PRU_IEP_TMR_CMP2 register bit field */
union {
volatile uint32_t TMR_CMP2;
volatile struct {
unsigned CMP2 : 32; // 31:0
} TMR_CMP2_bit;
}; // 0x50
/* PRU_IEP_TMR_CMP3 register bit field */
union {
volatile uint32_t TMR_CMP3;
volatile struct {
unsigned CMP3 : 32; // 31:0
} TMR_CMP3_bit;
}; // 0x54
/* PRU_IEP_TMR_CMP4 register bit field */
union {
volatile uint32_t TMR_CMP4;
volatile struct {
unsigned CMP4 : 32; // 31:0
} TMR_CMP4_bit;
}; // 0x58
/* PRU_IEP_TMR_CMP5 register bit field */
union {
volatile uint32_t TMR_CMP5;
volatile struct {
unsigned CMP5 : 32; // 31:0
} TMR_CMP5_bit;
}; // 0x5C
/* PRU_IEP_TMR_CMP6 register bit field */
union {
volatile uint32_t TMR_CMP6;
volatile struct {
unsigned CMP6 : 32; // 31:0
} TMR_CMP6_bit;
}; // 0x60
/* PRU_IEP_TMR_CMP7 register bit field */
union {
volatile uint32_t TMR_CMP7;
volatile struct {
unsigned CMP7 : 32; // 31:0
} TMR_CMP7_bit;
}; // 0x64
uint32_t rsvd68[166]; // 0x68 - 0x2FF
/* PRU_IEP_DIGIO_CTRL register bit field */
union {
volatile uint32_t DIGIO_CTRL;
volatile struct {
unsigned RESERVED0 : 4; // 3:0
unsigned IN_MODE : 1; // 4
unsigned RESERVED5 : 27; // 31:5
} DIGIO_CTRL_bit;
}; // 0x300
uint32_t rsvd304[1]; // 0x304
/* PRU_IEP_DIGIO_DATA_IN register bit field */
union {
volatile uint32_t DIGIO_DATA_IN;
volatile struct {
unsigned DATA_IN : 32; // 31:0
} DIGIO_DATA_IN_bit;
}; // 0x308
/* PRU_IEP_DIGIO_DATA_IN_RAW register bit field */
union {
volatile uint32_t DIGIO_DATA_IN_RAW;
volatile struct {
unsigned DATA_IN_RAW : 32; // 31:0
} DIGIO_DATA_IN_RAW_bit;
}; // 0x30C
/* PRU_IEP_DIGIO_DATA_OUT register bit field */
union {
volatile uint32_t DIGIO_DATA_OUT;
volatile struct {
unsigned DATA_OUT : 32; // 31:0
} DIGIO_DATA_OUT_bit;
}; // 0x310
/* PRU_IEP_DIGIO_DATA_OUT_EN register bit field */
union {
volatile uint32_t DIGIO_DATA_OUT_EN;
volatile struct {
unsigned DATA_OUT_EN : 32; // 31:0
} DIGIO_DATA_OUT_EN_bit;
}; // 0x314
/* PRU_IEP_DIGIO_EXP register bit field */
union {
volatile uint32_t DIGIO_EXP;
volatile struct {
unsigned SW_DATA_OUT_UPDATE : 1; // 0
unsigned OUTVALID_OVR_EN : 1; // 1
unsigned RESERVED2 : 30; // 31:2
} DIGIO_EXP_bit;
}; // 0x318
} pruIep;
#ifdef __GNUC__
static volatile pruIep *__CT_IEP = (void *)0x0002e000;
#define CT_IEP (*__CT_IEP)
#else
volatile __far pruIep CT_IEP __attribute__((cregister("PRU_IEP", far), peripheral));
#endif
#endif /* _PRU_IEP_H_ */

View File

@@ -0,0 +1,912 @@
/*
* Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _PRU_INTC_H_
#define _PRU_INTC_H_
/* PRU INTC register set */
typedef struct {
/* PRU_INTC_REVID register bit field */
union {
volatile uint32_t REVID;
volatile struct {
unsigned REV_MINOR : 6; // 5:0
unsigned REV_CUSTOM : 2; // 7:6
unsigned REV_MAJOR : 3; // 10:8
unsigned REV_RTL : 5; // 15:11
unsigned REV_MODULE : 12; // 27:16
unsigned rsvd28 : 2; // 29:28
unsigned REV_SCHEME : 2; // 31:30
} REVID_bit;
}; // 0x0
/* PRU_INTC_CR register bit field */
union {
volatile uint32_t CR;
volatile struct {
unsigned rsvd0 : 2; // 1:0
unsigned NEST_MODE : 2; // 3:2
unsigned rsvd4 : 28; // 31:4
} CR_bit;
}; // 0x4
uint32_t rsvd8[2]; // 0x8 - 0xC
/* PRU_INTC_GER register bit field */
union {
volatile uint32_t GER;
volatile struct {
unsigned EN_HINT_ANY : 1; // 0
unsigned rsvd1 : 31; // 31:1
} GER_bit;
}; // 0x10
uint32_t rsvd14[2]; // 0x14 - 0x18
/* PRU_INTC_GNLR register bit field */
union {
volatile uint32_t GNLR;
volatile struct {
unsigned GLB_NEST_LEVEL : 9; // 8:0
unsigned rsvd9 : 22; // 30:9
unsigned AUTO_OVERRIDE : 1; // 31
} GNLR_bit;
}; // 0x1C
/* PRU_INTC_SISR register bit field */
union {
volatile uint32_t SISR;
volatile struct {
unsigned STS_SET_IDX : 10; // 9:0
unsigned rsvd10 : 22; // 31:10
} SISR_bit;
}; // 0x20
/* PRU_INTC_SICR register bit field */
union {
volatile uint32_t SICR;
volatile struct {
unsigned STS_CLR_IDX : 10; // 9:0
unsigned rsvd10 : 22; // 31:10
} SICR_bit;
}; // 0x24
/* PRU_INTC_EISR register bit field */
union {
volatile uint32_t EISR;
volatile struct {
unsigned EN_SET_IDX : 10; // 9:0
unsigned rsvd10 : 22; // 31:10
} EISR_bit;
}; // 0x28
/* PRU_INTC_EICR register bit field */
union {
volatile uint32_t EICR;
volatile struct {
unsigned EN_CLR_IDX : 10; // 9:0
unsigned rsvd10 : 22; // 31:10
} EICR_bit;
}; // 0x2C
uint32_t rsvd30; // 0x30
/* PRU_INTC_HIEISR register bit field */
union {
volatile uint32_t HIEISR;
volatile struct {
unsigned HINT_EN_SET_IDX : 4; // 3:0
unsigned rsvd4 : 28; // 31:4
} HIEISR_bit;
}; // 0x34
/* PRU_INTC_HIDISR register bit field */
union {
volatile uint32_t HIDISR;
volatile struct {
unsigned HINT_EN_CLR_IDX : 4; // 3:0
unsigned rsvd4 : 28; // 31:4
} HIDISR_bit;
}; // 0x38
uint32_t rsvd3C[17]; // 0x3C - 0x7C
/* PRU_INTC_GPIR register bit field */
union {
volatile uint32_t GPIR;
volatile struct {
unsigned GLB_PRI_INTR : 10; // 9:0
unsigned rsvd10 : 21; // 30:10
unsigned GLB_NONE : 1; // 31
} GPIR_bit;
}; // 0x80
uint32_t rsvd84[95]; // 0x84 - 0x1FC
/* PRU_INTC_SRSR0 register bit field */
union {
volatile uint32_t SRSR0;
volatile struct {
unsigned RAW_STS_31_0 : 32; // 31:0
} SRSR0_bit;
}; // 0x200
/* PRU_INTC_SRSR1 register bit field */
union {
volatile uint32_t SRSR1;
volatile struct {
unsigned RAW_STS_63_32 : 32; // 31:0
} SRSR1_bit;
}; // 0x204
uint32_t rsvd208[30]; // 0x208 - 0x27C
/* PRU_INTC_SECR0 register bit field */
union {
volatile uint32_t SECR0;
volatile struct {
unsigned ENA_STS_31_0 : 32; // 31:0
} SECR0_bit;
}; // 0x280
/* PRU_INTC_SECR1 register bit field */
union {
volatile uint32_t SECR1;
volatile struct {
unsigned ENA_STS_63_32 : 32; // 31:0
} SECR1_bit;
}; // 0x284
uint32_t rsvd288[30]; // 0x288 - 0x2FC
/* PRU_INTC_ESR0 register bit field */
union {
volatile uint32_t ESR0;
volatile struct {
unsigned EN_SET_31_0 : 32; // 31:0
} ESR0_bit;
}; // 0x300
/* PRU_INTC_ESR1 register bit field */
union {
volatile uint32_t ESR1;
volatile struct {
unsigned EN_SET_63_32 : 32; // 31:0
} ESR1_bit;
}; // 0x304
uint32_t rsvd308[30]; // 0x308 - 0x37C
/* PRU_INTC_ECR0 register bit field */
union {
volatile uint32_t ECR0;
volatile struct {
unsigned EN_CLR_31_0 : 32; // 31:0
} ECR0_bit;
}; // 0x380
/* PRU_INTC_ECR1 register bit field */
union {
volatile uint32_t ECR1;
volatile struct {
unsigned EN_CLR_63_32 : 32; // 31:0
} ECR1_bit;
}; // 0x384
uint32_t rsvd388[30]; // 0x388 - 0x3FC
/* PRU_INTC_CMR0 register bit field */
union {
volatile uint32_t CMR0;
volatile struct {
unsigned CH_MAP_0 : 4; // 3:0
unsigned rsvd4 : 4; // 7:4
unsigned CH_MAP_1 : 4; // 11:8
unsigned rsvd12 : 4; // 15:12
unsigned CH_MAP_2 : 4; // 19:16
unsigned rsvd20 : 4; // 23:20
unsigned CH_MAP_3 : 4; // 27:24
unsigned rsvd28 : 4; // 31:28
} CMR0_bit;
}; // 0x400
/* PRU_INTC_CMR1 register bit field */
union {
volatile uint32_t CMR1;
volatile struct {
unsigned CH_MAP_4 : 4; // 3:0
unsigned rsvd4 : 4; // 7:4
unsigned CH_MAP_5 : 4; // 11:8
unsigned rsvd12 : 4; // 15:12
unsigned CH_MAP_6 : 4; // 19:16
unsigned rsvd20 : 4; // 23:20
unsigned CH_MAP_7 : 4; // 27:24
unsigned rsvd28 : 4; // 31:28
} CMR1_bit;
}; // 0x404
/* PRU_INTC_CMR2 register bit field */
union {
volatile uint32_t CMR2;
volatile struct {
unsigned CH_MAP_8 : 4; // 3:0
unsigned rsvd4 : 4; // 7:4
unsigned CH_MAP_9 : 4; // 11:8
unsigned rsvd12 : 4; // 15:12
unsigned CH_MAP_10 : 4; // 19:16
unsigned rsvd20 : 4; // 23:20
unsigned CH_MAP_11 : 4; // 27:24
unsigned rsvd28 : 4; // 31:28
} CMR2_bit;
}; // 0x408
/* PRU_INTC_CMR3 register bit field */
union {
volatile uint32_t CMR3;
volatile struct {
unsigned CH_MAP_12 : 4; // 3:0
unsigned rsvd4 : 4; // 7:4
unsigned CH_MAP_13 : 4; // 11:8
unsigned rsvd12 : 4; // 15:12
unsigned CH_MAP_14 : 4; // 19:16
unsigned rsvd20 : 4; // 23:20
unsigned CH_MAP_15 : 4; // 27:24
unsigned rsvd28 : 4; // 31:28
} CMR3_bit;
}; // 0x40C
/* PRU_INTC_CMR4 register bit field */
union {
volatile uint32_t CMR4;
volatile struct {
unsigned CH_MAP_16 : 4; // 3:0
unsigned rsvd4 : 4; // 7:4
unsigned CH_MAP_17 : 4; // 11:8
unsigned rsvd12 : 4; // 15:12
unsigned CH_MAP_18 : 4; // 19:16
unsigned rsvd20 : 4; // 23:20
unsigned CH_MAP_19 : 4; // 27:24
unsigned rsvd28 : 4; // 31:28
} CMR4_bit;
}; // 0x410
/* PRU_INTC_CMR5 register bit field */
union {
volatile uint32_t CMR5;
volatile struct {
unsigned CH_MAP_20 : 4; // 3:0
unsigned rsvd4 : 4; // 7:4
unsigned CH_MAP_21 : 4; // 11:8
unsigned rsvd12 : 4; // 15:12
unsigned CH_MAP_22 : 4; // 19:16
unsigned rsvd20 : 4; // 23:20
unsigned CH_MAP_23 : 4; // 27:24
unsigned rsvd28 : 4; // 31:28
} CMR5_bit;
}; // 0x414
/* PRU_INTC_CMR6 register bit field */
union {
volatile uint32_t CMR6;
volatile struct {
unsigned CH_MAP_24 : 4; // 3:0
unsigned rsvd4 : 4; // 7:4
unsigned CH_MAP_25 : 4; // 11:8
unsigned rsvd12 : 4; // 15:12
unsigned CH_MAP_26 : 4; // 19:16
unsigned rsvd20 : 4; // 23:20
unsigned CH_MAP_27 : 4; // 27:24
unsigned rsvd28 : 4; // 31:28
} CMR6_bit;
}; // 0x418
/* PRU_INTC_CMR7 register bit field */
union {
volatile uint32_t CMR7;
volatile struct {
unsigned CH_MAP_28 : 4; // 3:0
unsigned rsvd4 : 4; // 7:4
unsigned CH_MAP_29 : 4; // 11:8
unsigned rsvd12 : 4; // 15:12
unsigned CH_MAP_30 : 4; // 19:16
unsigned rsvd20 : 4; // 23:20
unsigned CH_MAP_31 : 4; // 27:24
unsigned rsvd28 : 4; // 31:28
} CMR7_bit;
}; // 0x41C
/* PRU_INTC_CMR8 register bit field */
union {
volatile uint32_t CMR8;
volatile struct {
unsigned CH_MAP_32 : 4; // 3:0
unsigned rsvd4 : 4; // 7:4
unsigned CH_MAP_33 : 4; // 11:8
unsigned rsvd12 : 4; // 15:12
unsigned CH_MAP_34 : 4; // 19:16
unsigned rsvd20 : 4; // 23:20
unsigned CH_MAP_35 : 4; // 27:24
unsigned rsvd28 : 4; // 31:28
} CMR8_bit;
}; // 0x420
/* PRU_INTC_CMR9 register bit field */
union {
volatile uint32_t CMR9;
volatile struct {
unsigned CH_MAP_36 : 4; // 3:0
unsigned rsvd4 : 4; // 7:4
unsigned CH_MAP_37 : 4; // 11:8
unsigned rsvd12 : 4; // 15:12
unsigned CH_MAP_38 : 4; // 19:16
unsigned rsvd20 : 4; // 23:20
unsigned CH_MAP_39 : 4; // 27:24
unsigned rsvd28 : 4; // 31:28
} CMR9_bit;
}; // 0x424
/* PRU_INTC_CMR10 register bit field */
union {
volatile uint32_t CMR10;
volatile struct {
unsigned CH_MAP_40 : 4; // 3:0
unsigned rsvd4 : 4; // 7:4
unsigned CH_MAP_41 : 4; // 11:8
unsigned rsvd12 : 4; // 15:12
unsigned CH_MAP_42 : 4; // 19:16
unsigned rsvd20 : 4; // 23:20
unsigned CH_MAP_43 : 4; // 27:24
unsigned rsvd28 : 4; // 31:28
} CMR10_bit;
}; // 0x428
/* PRU_INTC_CMR11 register bit field */
union {
volatile uint32_t CMR11;
volatile struct {
unsigned CH_MAP_44 : 4; // 3:0
unsigned rsvd4 : 4; // 7:4
unsigned CH_MAP_45 : 4; // 11:8
unsigned rsvd12 : 4; // 15:12
unsigned CH_MAP_46 : 4; // 19:16
unsigned rsvd20 : 4; // 23:20
unsigned CH_MAP_47 : 4; // 27:24
unsigned rsvd28 : 4; // 31:28
} CMR11_bit;
}; // 0x42C
/* PRU_INTC_CMR12 register bit field */
union {
volatile uint32_t CMR12;
volatile struct {
unsigned CH_MAP_48 : 4; // 3:0
unsigned rsvd4 : 4; // 7:4
unsigned CH_MAP_49 : 4; // 11:8
unsigned rsvd12 : 4; // 15:12
unsigned CH_MAP_50 : 4; // 19:16
unsigned rsvd20 : 4; // 23:20
unsigned CH_MAP_51 : 4; // 27:24
unsigned rsvd28 : 4; // 31:28
} CMR12_bit;
}; // 0x430
/* PRU_INTC_CMR13 register bit field */
union {
volatile uint32_t CMR13;
volatile struct {
unsigned CH_MAP_52 : 4; // 3:0
unsigned rsvd4 : 4; // 7:4
unsigned CH_MAP_53 : 4; // 11:8
unsigned rsvd12 : 4; // 15:12
unsigned CH_MAP_54 : 4; // 19:16
unsigned rsvd20 : 4; // 23:20
unsigned CH_MAP_55 : 4; // 27:24
unsigned rsvd28 : 4; // 31:28
} CMR13_bit;
}; // 0x434
/* PRU_INTC_CMR14 register bit field */
union {
volatile uint32_t CMR14;
volatile struct {
unsigned CH_MAP_56 : 4; // 3:0
unsigned rsvd4 : 4; // 7:4
unsigned CH_MAP_57 : 4; // 11:8
unsigned rsvd12 : 4; // 15:12
unsigned CH_MAP_58 : 4; // 19:16
unsigned rsvd20 : 4; // 23:20
unsigned CH_MAP_59 : 4; // 27:24
unsigned rsvd28 : 4; // 31:28
} CMR14_bit;
}; // 0x438
/* PRU_INTC_CMR15 register bit field */
union {
volatile uint32_t CMR15;
volatile struct {
unsigned CH_MAP_60 : 4; // 3:0
unsigned rsvd4 : 4; // 7:4
unsigned CH_MAP_61 : 4; // 11:8
unsigned rsvd12 : 4; // 15:12
unsigned CH_MAP_62 : 4; // 19:16
unsigned rsvd20 : 4; // 23:20
unsigned CH_MAP_63 : 4; // 27:24
unsigned rsvd28 : 4; // 31:28
} CMR15_bit;
}; // 0x43C
uint32_t rsvd440[240]; // 0x440 - 0x7FC
/* PRU_INTC_HMR0 register bit field */
union {
volatile uint32_t HMR0;
volatile struct {
unsigned HINT_MAP_0 : 4; // 3:0
unsigned rsvd4 : 4; // 7:4
unsigned HINT_MAP_1 : 4; // 11:8
unsigned rsvd12 : 4; // 15:12
unsigned HINT_MAP_2 : 4; // 19:16
unsigned rsvd20 : 4; // 23:20
unsigned HINT_MAP_3 : 4; // 27:24
unsigned rsvd28 : 4; // 31:28
} HMR0_bit;
}; // 0x800
/* PRU_INTC_HMR1 register bit field */
union {
volatile uint32_t HMR1;
volatile struct {
unsigned HINT_MAP_4 : 4; // 3:0
unsigned rsvd4 : 4; // 7:4
unsigned HINT_MAP_5 : 4; // 11:8
unsigned rsvd12 : 4; // 15:12
unsigned HINT_MAP_6 : 4; // 19:16
unsigned rsvd20 : 4; // 23:20
unsigned HINT_MAP_7 : 4; // 27:24
unsigned rsvd28 : 4; // 31:28
} HMR1_bit;
}; // 0x804
/* PRU_INTC_HMR2 register bit field */
union {
volatile uint32_t HMR2;
volatile struct {
unsigned HINT_MAP_8 : 4; // 3:0
unsigned rsvd4 : 4; // 7:4
unsigned HINT_MAP_9 : 4; // 11:8
unsigned rsvd12 : 20; // 31:12
} HMR2_bit;
}; // 0x808
uint32_t rsvd80C[61]; // 0x80C - 0x8FC
/* PRU_INTC_HIPIR0 register bit field */
union {
volatile uint32_t HIPIR0;
volatile struct {
unsigned PRI_HINT_0 : 10; // 9:0
unsigned rsvd10 : 21; // 30:10
unsigned NONE_HINT_0 : 1; // 31
} HIPIR0_bit;
}; // 0x900
/* PRU_INTC_HIPIR1 register bit field */
union {
volatile uint32_t HIPIR1;
volatile struct {
unsigned PRI_HINT_1 : 10; // 9:0
unsigned rsvd10 : 21; // 30:10
unsigned NONE_HINT_1 : 1; // 31
} HIPIR1_bit;
}; // 0x904
/* PRU_INTC_HIPIR2 register bit field */
union {
volatile uint32_t HIPIR2;
volatile struct {
unsigned PRI_HINT_2 : 10; // 9:0
unsigned rsvd10 : 21; // 30:10
unsigned NONE_HINT_2 : 1; // 31
} HIPIR2_bit;
}; // 0x908
/* PRU_INTC_HIPIR3 register bit field */
union {
volatile uint32_t HIPIR3;
volatile struct {
unsigned PRI_HINT_3 : 10; // 9:0
unsigned rsvd10 : 21; // 30:10
unsigned NONE_HINT_3 : 1; // 31
} HIPIR3_bit;
}; // 0x90C
/* PRU_INTC_HIPIR4 register bit field */
union {
volatile uint32_t HIPIR4;
volatile struct {
unsigned PRI_HINT_4 : 10; // 9:0
unsigned rsvd10 : 21; // 30:10
unsigned NONE_HINT_4 : 1; // 31
} HIPIR4_bit;
}; // 0x910
/* PRU_INTC_HIPIR5 register bit field */
union {
volatile uint32_t HIPIR5;
volatile struct {
unsigned PRI_HINT_5 : 10; // 9:0
unsigned rsvd10 : 21; // 30:10
unsigned NONE_HINT_5 : 1; // 31
} HIPIR5_bit;
}; // 0x914
/* PRU_INTC_HIPIR6 register bit field */
union {
volatile uint32_t HIPIR6;
volatile struct {
unsigned PRI_HINT_6 : 10; // 9:0
unsigned rsvd10 : 21; // 30:10
unsigned NONE_HINT_6 : 1; // 31
} HIPIR6_bit;
}; // 0x918
/* PRU_INTC_HIPIR7 register bit field */
union {
volatile uint32_t HIPIR7;
volatile struct {
unsigned PRI_HINT_7 : 10; // 9:0
unsigned rsvd10 : 21; // 30:10
unsigned NONE_HINT_7 : 1; // 31
} HIPIR7_bit;
}; // 0x91C
/* PRU_INTC_HIPIR8 register bit field */
union {
volatile uint32_t HIPIR8;
volatile struct {
unsigned PRI_HINT_8 : 10; // 9:0
unsigned rsvd10 : 21; // 30:10
unsigned NONE_HINT_8 : 1; // 31
} HIPIR8_bit;
}; // 0x920
/* PRU_INTC_HIPIR9 register bit field */
union {
volatile uint32_t HIPIR9;
volatile struct {
unsigned PRI_HINT_9 : 10; // 9:0
unsigned rsvd10 : 21; // 30:10
unsigned NONE_HINT_9 : 1; // 31
} HIPIR9_bit;
}; // 0x924
uint32_t rsvd928[246]; // 0x928 - 0xCFC
/* PRU_INTC_SIPR0 register bit field */
union {
volatile uint32_t SIPR0;
volatile struct {
unsigned POLARITY_31_0 : 32; // 31:0
} SIPR0_bit;
}; // 0xD00
/* PRU_INTC_SIPR1 register bit field */
union {
volatile uint32_t SIPR1;
volatile struct {
unsigned POLARITY_63_32 : 32; // 31:0
} SIPR1_bit;
}; // 0xD04
uint32_t rsvdD08[30]; // 0xD08 - 0xD7C
/* PRU_INTC_SITR0 register bit field */
union {
volatile uint32_t SITR0;
volatile struct {
unsigned TYPE_31_0 : 32; // 31:0
} SITR0_bit;
}; // 0xD80
/* PRU_INTC_SITR1 register bit field */
union {
volatile uint32_t SITR1;
volatile struct {
unsigned TYPE_63_32 : 32; // 31:0
} SITR1_bit;
}; // 0xD84
uint32_t rsvdD84[222]; // 0xD88 - 0x10FC
/* PRU_INTC_HINLR0 register bit field */
union {
volatile uint32_t HINLR0;
volatile struct {
unsigned NEST_HINT_0 : 9; // 8:0
unsigned rsvd9 : 22; // 30:9
unsigned AUTO_OVERRIDE : 1; // 31
} HINLR0_bit;
}; // 0x1100
/* PRU_INTC_HINLR1 register bit field */
union {
volatile uint32_t HINLR1;
volatile struct {
unsigned NEST_HINT_1 : 9; // 8:0
unsigned rsvd9 : 22; // 30:9
unsigned AUTO_OVERRIDE : 1; // 31
} HINLR1_bit;
}; // 0x1104
/* PRU_INTC_HINLR2 register bit field */
union {
volatile uint32_t HINLR2;
volatile struct {
unsigned NEST_HINT_2 : 9; // 8:0
unsigned rsvd9 : 22; // 30:9
unsigned AUTO_OVERRIDE : 1; // 31
} HINLR2_bit;
}; // 0x1108
/* PRU_INTC_HINLR3 register bit field */
union {
volatile uint32_t HINLR3;
volatile struct {
unsigned NEST_HINT_3 : 9; // 8:0
unsigned rsvd9 : 22; // 30:9
unsigned AUTO_OVERRIDE : 1; // 31
} HINLR3_bit;
}; // 0x110C
/* PRU_INTC_HINLR4 register bit field */
union {
volatile uint32_t HINLR4;
volatile struct {
unsigned NEST_HINT_4 : 9; // 8:0
unsigned rsvd9 : 22; // 30:9
unsigned AUTO_OVERRIDE : 1; // 31
} HINLR4_bit;
}; // 0x1110
/* PRU_INTC_HINLR5 register bit field */
union {
volatile uint32_t HINLR5;
volatile struct {
unsigned NEST_HINT_5 : 9; // 8:0
unsigned rsvd9 : 22; // 30:9
unsigned AUTO_OVERRIDE : 1; // 31
} HINLR5_bit;
}; // 0x1114
/* PRU_INTC_HINLR6 register bit field */
union {
volatile uint32_t HINLR6;
volatile struct {
unsigned NEST_HINT_6 : 9; // 8:0
unsigned rsvd9 : 22; // 30:9
unsigned AUTO_OVERRIDE : 1; // 31
} HINLR6_bit;
}; // 0x1118
/* PRU_INTC_HINLR7 register bit field */
union {
volatile uint32_t HINLR7;
volatile struct {
unsigned NEST_HINT_7 : 9; // 8:0
unsigned rsvd9 : 22; // 30:9
unsigned AUTO_OVERRIDE : 1; // 31
} HINLR7_bit;
}; // 0x111C
/* PRU_INTC_HINLR8 register bit field */
union {
volatile uint32_t HINLR8;
volatile struct {
unsigned NEST_HINT_8 : 9; // 8:0
unsigned rsvd9 : 22; // 30:9
unsigned AUTO_OVERRIDE : 1; // 31
} HINLR8_bit;
}; // 0x1120
/* PRU_INTC_HINLR9 register bit field */
union {
volatile uint32_t HINLR9;
volatile struct {
unsigned NEST_HINT_9 : 9; // 8:0
unsigned rsvd9 : 22; // 30:9
unsigned AUTO_OVERRIDE : 1; // 31
} HINLR9_bit;
}; // 0x1124
uint32_t rsvd1128[246]; // 0x1128 - 0x14FC
/* PRU_INTC_HIER register bit field */
union {
volatile uint32_t HIER;
volatile struct {
unsigned EN_HINT : 10; // 9:0
unsigned rsvd9 : 22; // 31:10
} HIER_bit;
}; // 0x1500
} pruIntc;
#ifdef __GNUC__
static volatile pruIntc *__CT_INTC = (void *)0x00020000;
#define CT_INTC (*__CT_INTC)
#else
volatile __far pruIntc CT_INTC __attribute__((cregister("PRU_INTC", far), peripheral));
#endif
#endif /* _PRU_INTC_H_ */

View File

@@ -0,0 +1,285 @@
/*
* Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _PRU_UART_H_
#define _PRU_UART_H_
/* UART Register set */
typedef struct {
/*
* RBR and THR register pair
* This is a unique register pair in that RBR and THR
* share the same address. RBR is read-only while THR is
* write-only.
*
* Additionally, RBR and THR share an address with DLL. To
* read/write RBR/THR write 0 to the DLAB bit in the LCR
* register. To modify DLL write a 1.
*
* DLL also has a dedicated
* address which does not require toggling the DLAB bit.
*/
union {
/* PRU_UART_RBR register bit field */
union {
volatile uint32_t RBR;
volatile struct {
unsigned DATA : 8; // 7:0
unsigned rsvd8 : 24; // 31:8
} RBR_bit;
};
/* PRU_UART_THR register bit field */
union {
volatile uint32_t THR;
volatile struct {
unsigned DATA : 8; // 7:0
unsigned rsvd8 : 24; // 31:8
} THR_bit;
};
}; // 0x0
/* PRU_UART_IER register bit field */
/*
* IER shares an address with DLH. To modify IER write 0
* to the DLAB bit in the LCR register. To modify DLH write a 1.
*
* DLH also has a dedicated address which does not require
* toggling the DLAB bit.
*/
union {
volatile uint32_t IER;
volatile struct {
unsigned ERBI : 1; // 0
unsigned ETBEI : 1; // 1
unsigned ELSI : 1; // 2
unsigned EDSSI : 1; // 3
unsigned rsvd4 : 28; // 31:4
} IER_bit;
}; // 0x4
/*
* IIR and FCR register pair
* This is a unique register pair in that IIR and FCR
* share the same address. IIR is read-only while FCR is
* write-only.
*/
union {
/* PRU_UART_IIR register bit field */
union {
volatile uint32_t IIR;
volatile struct {
unsigned IPEND : 1; // 0
unsigned INTID : 3; // 3:1
unsigned rsvd4 : 2; // 5:4
unsigned FIFOEN : 2; // 7:6
unsigned rsvd8 : 24; // 31:8
} IIR_bit;
};
/* PRU_UART_FCR register bit field */
union {
volatile uint32_t FCR;
volatile struct {
unsigned FIFOEN : 1; // 0
unsigned RXCLR : 1; // 1
unsigned TXCLR : 1; // 2
unsigned DMAMODE1 : 1; // 3
unsigned rsvd4 : 2; // 5:4
unsigned RXFIFTL : 2; // 7:6
unsigned rsvd8 : 24; // 31:8
} FCR_bit;
};
}; // 0x8
/* PRU_UART_LCR register bit field */
union {
volatile uint32_t LCR;
volatile struct {
unsigned WLS : 2; // 1:0
unsigned STB : 1; // 2
unsigned PEN : 1; // 3
unsigned EPS : 1; // 4
unsigned SP : 1; // 5
unsigned BC : 1; // 6
unsigned DLAB : 1; // 7
unsigned rsvd8 : 24; // 31:8
} LCR_bit;
}; // 0xC
/* PRU_UART_MCR register bit field */
union {
volatile uint32_t MCR;
volatile struct {
unsigned rsvd0 : 1; // 0
unsigned RTS : 1; // 1
unsigned OUT1 : 1; // 2
unsigned OUT2 : 1; // 3
unsigned LOOP : 1; // 4
unsigned AFE : 1; // 5
unsigned rsvd8 : 26; // 31:6
} MCR_bit;
}; // 0x10
/* PRU_UART_LSR register bit field */
union {
volatile uint32_t LSR;
volatile struct {
unsigned DR : 1; // 0
unsigned OE : 1; // 1
unsigned PE : 1; // 2
unsigned FE : 1; // 3
unsigned BI : 1; // 4
unsigned THRE : 1; // 5
unsigned TEMT : 1; // 6
unsigned RXFIFOE : 1; // 7
unsigned rsvd8 : 24; // 31:8
} LSR_bit;
}; // 0x14
/* PRU_UART_MSR register bit field */
union {
volatile uint32_t MSR;
volatile struct {
unsigned DCTS : 1; // 0
unsigned DDSR : 1; // 1
unsigned TERI : 1; // 2
unsigned DCD : 1; // 3
unsigned CTS : 1; // 4
unsigned DSR : 1; // 5
unsigned RI : 1; // 6
unsigned CD : 1; // 7
unsigned rsvd8 : 24; // 31:8
} MSR_bit;
}; // 0x18
/* PRU_UART_SCR register bit field */
union {
volatile uint32_t SCR;
volatile struct {
unsigned SCR : 8; // 7:0
unsigned rsvd8 : 24; // 31:8
} SCR_bit;
}; // 0x1C
/* PRU_UART_DLL register bit field */
union {
volatile uint32_t DLL;
volatile struct {
unsigned DLL : 8; // 7:0
unsigned rsvd8 : 24; // 31:8
} DLL_bit;
}; // 0x20
/* PRU_UART_DLH register bit field */
union {
volatile uint32_t DLH;
volatile struct {
unsigned DLH : 8; // 7:0
unsigned rsvd8 : 24; // 31:8
} DLH_bit;
}; // 0x24
/* PRU_UART_REVID1 register bit field */
union {
volatile uint32_t REVID1;
volatile struct {
unsigned REVID1 : 32; // 31:0
} REVID1_bit;
}; // 0x28
/* PRU_UART_REVID2 register bit field */
union {
volatile uint32_t REVID2;
volatile struct {
unsigned REVID2 : 8; // 7:0
unsigned rsvd8 : 24; // 31:8
} REVID2_bit;
}; // 0x2C
/* PRU_UART_PWREMU_MGMT register bit field */
union {
volatile uint32_t PWREMU_MGMT;
volatile struct {
unsigned FREE : 1; // 0
unsigned rsvd1 : 12; // 12:1
unsigned URRST : 1; // 13
unsigned UTRST : 1; // 14
unsigned rsvd15 : 17; // 31:15
} PWREMU_MGMT_bit;
}; // 0x30
/* PRU_UART_MDR register bit field */
union {
volatile uint32_t MDR;
volatile struct {
unsigned OSM_SEL : 1; // 0
unsigned rsvd1 : 31; // 31:1
} MDR_bit;
}; // 0x34
} pruUart;
volatile __far pruUart CT_UART __attribute__((cregister("PRU_UART", near), peripheral));
#endif /* _PRU_UART_H_ */

Some files were not shown because too many files have changed in this diff Show More