forked from Klipper3d/klipper
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
- Loading branch information
Showing
9 changed files
with
149 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
# Support for servos | ||
# | ||
# Copyright (C) 2017-2020 Kevin O'Connor <[email protected]> | ||
# Copyright (C) 2017-2024 Kevin O'Connor <[email protected]> | ||
# | ||
# This file may be distributed under the terms of the GNU GPLv3 license. | ||
from . import output_pin | ||
|
||
SERVO_SIGNAL_PERIOD = 0.020 | ||
PIN_MIN_TIME = 0.100 | ||
|
||
class PrinterServo: | ||
def __init__(self, config): | ||
|
@@ -18,7 +18,7 @@ def __init__(self, config): | |
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.last_value = 0. | ||
initial_pwm = 0. | ||
iangle = config.getfloat('initial_angle', None, minval=0., maxval=360.) | ||
if iangle is not None: | ||
|
@@ -33,6 +33,9 @@ def __init__(self, config): | |
self.mcu_servo.setup_max_duration(0.) | ||
self.mcu_servo.setup_cycle_time(SERVO_SIGNAL_PERIOD) | ||
self.mcu_servo.setup_start_value(initial_pwm, 0.) | ||
# Create gcode request queue | ||
self.gcrq = output_pin.GCodeRequestQueue( | ||
config, self.mcu_servo.get_mcu(), self._set_pwm) | ||
# Register commands | ||
servo_name = config.get_name().split()[1] | ||
gcode = self.printer.lookup_object('gcode') | ||
|
@@ -42,12 +45,10 @@ def __init__(self, config): | |
def get_status(self, eventtime): | ||
return {'value': self.last_value} | ||
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 | ||
if value != self.last_value: | ||
self.last_value = value | ||
self.mcu_servo.set_pwm(print_time, value) | ||
return (True, 0.) | ||
def _get_pwm_from_angle(self, angle): | ||
angle = max(0., min(self.max_angle, angle)) | ||
width = self.min_width + angle * self.angle_to_width | ||
|
@@ -64,9 +65,7 @@ def cmd_SET_SERVO(self, gcmd): | |
else: | ||
angle = gcmd.get_float('ANGLE') | ||
value = self._get_pwm_from_angle(angle) | ||
toolhead = self.printer.lookup_object('toolhead') | ||
toolhead.register_lookahead_callback((lambda pt: | ||
self._set_pwm(pt, value))) | ||
self.gcrq.queue_gcode_request(value) | ||
|
||
def load_config_prefix(config): | ||
return PrinterServo(config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Test config for load_cell | ||
[mcu] | ||
serial: /dev/ttyACM0 | ||
|
||
[printer] | ||
kinematics: none | ||
max_velocity: 300 | ||
max_accel: 3000 | ||
|
||
[load_cell my_ads1220] | ||
sensor_type: ads1220 | ||
cs_pin: PA0 | ||
data_ready_pin: PA1 | ||
|
||
[load_cell my_hx711] | ||
sensor_type: hx711 | ||
sclk_pin: PA2 | ||
dout_pin: PA3 | ||
|
||
[load_cell my_hx717] | ||
sensor_type: hx717 | ||
sclk_pin: PA4 | ||
dout_pin: PA5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Tests for loadcell sensors | ||
DICTIONARY atmega2560.dict | ||
CONFIG load_cell.cfg | ||
|
||
G4 P1000 |