servo: Remove servo ENABLE parameter

Allow one to disable servos via `SET_SERVO WIDTH=0` instead of using
an explicit ENABLE parameter.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2020-07-16 14:45:48 -04:00
parent 122fd88c6a
commit 428a8d4881
4 changed files with 13 additions and 21 deletions

View File

@ -1254,9 +1254,6 @@
# the mcu resets. Must be between minimum_pulse_width and maximum_pulse_width. # the mcu resets. Must be between minimum_pulse_width and maximum_pulse_width.
# This parameter is optional. If both initial_angle and initial_pulse_width # This parameter is optional. If both initial_angle and initial_pulse_width
# are set initial_angle will be used # are set initial_angle will be used
#enable: True
# Enable or disable servo. It can be enabled or disabled later using
# SET_SERVO SERVO=my_servo ENABLE=<0|1> g-command. The default is True (=enabled)
# Neopixel (aka WS2812) LED support (one may define any number of # Neopixel (aka WS2812) LED support (one may define any number of
# sections with a "neopixel" prefix). One may set the LED color via # sections with a "neopixel" prefix). One may set the LED color via

View File

@ -6,6 +6,10 @@ All dates in this document are approximate.
# Changes # Changes
20200725: The servo `enable` config parameter and the SET_SERVO
`ENABLE` parameter have been removed. Update any macros to use
`SET_SERVO SERVO=my_servo WIDTH=0` to disable a servo.
20200608: The LCD display support has changed the name of some 20200608: The LCD display support has changed the name of some
internal "glyphs". If a custom display layout was implemented it may internal "glyphs". If a custom display layout was implemented it may
be necessary to update to the latest glyph names (see be necessary to update to the latest glyph names (see

View File

@ -258,8 +258,9 @@ sections are enabled:
The following commands are available when a "servo" config section is The following commands are available when a "servo" config section is
enabled: enabled:
- `SET_SERVO SERVO=config_name [WIDTH=<seconds>] [ENABLE=<0|1>]` - `SET_SERVO SERVO=config_name [ANGLE=<degrees> | WIDTH=<seconds>]`:
- `SET_SERVO SERVO=config_name [ANGLE=<degrees>] [ENABLE=<0|1>]` Set the servo position to the given angle (in degrees) or pulse
width (in seconds). Use `WIDTH=0` to disable the servo output.
## Manual stepper Commands ## Manual stepper Commands

View File

@ -23,8 +23,6 @@ class PrinterServo:
self.angle_to_width = (self.max_width - self.min_width) / self.max_angle self.angle_to_width = (self.max_width - self.min_width) / self.max_angle
self.width_to_value = 1. / SERVO_SIGNAL_PERIOD self.width_to_value = 1. / SERVO_SIGNAL_PERIOD
self.last_value = self.last_value_time = 0. self.last_value = self.last_value_time = 0.
self.enable = config.getboolean('enable', True)
self.last_enable = not self.enable
servo_name = config.get_name().split()[1] servo_name = config.get_name().split()[1]
gcode = self.printer.lookup_object('gcode') gcode = self.printer.lookup_object('gcode')
gcode.register_mux_command("SET_SERVO", "SERVO", servo_name, gcode.register_mux_command("SET_SERVO", "SERVO", servo_name,
@ -53,37 +51,29 @@ class PrinterServo:
def get_status(self, eventtime): def get_status(self, eventtime):
return {'value': self.last_value} return {'value': self.last_value}
def _set_pwm(self, print_time, value): def _set_pwm(self, print_time, value):
if value == self.last_value and self.enable == self.last_enable: if value == self.last_value:
return return
print_time = max(print_time, self.last_value_time + PIN_MIN_TIME) print_time = max(print_time, self.last_value_time + PIN_MIN_TIME)
if self.enable:
self.mcu_servo.set_pwm(print_time, value) self.mcu_servo.set_pwm(print_time, value)
else:
self.mcu_servo.set_pwm(print_time, 0)
self.last_value = value self.last_value = value
self.last_enable = self.enable
self.last_value_time = print_time self.last_value_time = print_time
def _get_pwm_from_angle(self, angle): def _get_pwm_from_angle(self, angle):
angle = max(0., min(self.max_angle, angle)) angle = max(0., min(self.max_angle, angle))
width = self.min_width + angle * self.angle_to_width width = self.min_width + angle * self.angle_to_width
return width * self.width_to_value return width * self.width_to_value
def _get_pwm_from_pulse_width(self, width): def _get_pwm_from_pulse_width(self, width):
if width:
width = max(self.min_width, min(self.max_width, width)) width = max(self.min_width, min(self.max_width, width))
return width * self.width_to_value return width * self.width_to_value
cmd_SET_SERVO_help = "Set servo angle" cmd_SET_SERVO_help = "Set servo angle"
def cmd_SET_SERVO(self, gcmd): def cmd_SET_SERVO(self, gcmd):
print_time = self.printer.lookup_object('toolhead').get_last_move_time() print_time = self.printer.lookup_object('toolhead').get_last_move_time()
enable = gcmd.get_int('ENABLE', None)
width = gcmd.get_float('WIDTH', None) width = gcmd.get_float('WIDTH', None)
angle = gcmd.get_float('ANGLE', None)
if enable is not None:
self.enable = enable != 0
if width is not None: if width is not None:
self._set_pwm(print_time, self._get_pwm_from_pulse_width(width)) self._set_pwm(print_time, self._get_pwm_from_pulse_width(width))
elif angle is not None:
self._set_pwm(print_time, self._get_pwm_from_angle(angle))
else: else:
self._set_pwm(print_time, self.last_value) angle = gcmd.get_float('ANGLE')
self._set_pwm(print_time, self._get_pwm_from_angle(angle))
def load_config_prefix(config): def load_config_prefix(config):
return PrinterServo(config) return PrinterServo(config)