palette2: Add ping variation + ping status reports (#4114)
Signed-off-by: Clifford Roche <clifford.roche@gmail.com>
This commit is contained in:
parent
316b49c6bf
commit
e7b0e7b43b
|
@ -313,6 +313,12 @@ The following are common printer attributes:
|
||||||
- `printer.system_stats.sysload`, `printer.system_stats.cputime`,
|
- `printer.system_stats.sysload`, `printer.system_stats.cputime`,
|
||||||
`printer.system_stats.memavail`: Information on the host operating
|
`printer.system_stats.memavail`: Information on the host operating
|
||||||
system and process load.
|
system and process load.
|
||||||
|
- `printer.palette2.ping`: Amount of the last reported Palette 2 ping
|
||||||
|
in percent.
|
||||||
|
- `printer.palette2.remaining_load_length`: When starting a Palette 2
|
||||||
|
print, this will be the amount of filament to load into the extruder.
|
||||||
|
- `printer.palette2.is_splicing`: True when the Palette 2 is splicing
|
||||||
|
filament.
|
||||||
|
|
||||||
The above list is subject to change - if using an attribute be sure to
|
The above list is subject to change - if using an attribute be sure to
|
||||||
review the [Config Changes document](Config_Changes.md) when upgrading
|
review the [Config Changes document](Config_Changes.md) when upgrading
|
||||||
|
|
|
@ -3903,12 +3903,14 @@ for your print to begin.
|
||||||
[palette2]
|
[palette2]
|
||||||
serial:
|
serial:
|
||||||
# The serial port to connect to the Palette 2.
|
# The serial port to connect to the Palette 2.
|
||||||
#baud: 250000
|
#baud: 115200
|
||||||
# The baud rate to use. The default is 250000.
|
# The baud rate to use. The default is 115200.
|
||||||
#feedrate_splice: 0.8
|
#feedrate_splice: 0.8
|
||||||
# The feedrate to use when splicing, default is 0.8
|
# The feedrate to use when splicing, default is 0.8
|
||||||
#feedrate_normal: 1.0
|
#feedrate_normal: 1.0
|
||||||
# The feedrate to use after splicing, default is 1.0
|
# The feedrate to use after splicing, default is 1.0
|
||||||
#auto_load_speed: 2
|
#auto_load_speed: 2
|
||||||
# Extrude feedrate when autoloading, default is 2 (mm/s)
|
# Extrude feedrate when autoloading, default is 2 (mm/s)
|
||||||
|
#auto_cancel_variation: 0.1
|
||||||
|
# Auto cancel print when ping varation is above this threshold
|
||||||
```
|
```
|
||||||
|
|
|
@ -32,7 +32,7 @@ COMMAND_SMART_LOAD_STOP = "O102 D1"
|
||||||
|
|
||||||
HEARTBEAT_SEND = 5.
|
HEARTBEAT_SEND = 5.
|
||||||
HEARTBEAT_TIMEOUT = (HEARTBEAT_SEND * 2.) + 1.
|
HEARTBEAT_TIMEOUT = (HEARTBEAT_SEND * 2.) + 1.
|
||||||
SETUP_TIMEOUT = 300
|
SETUP_TIMEOUT = 10
|
||||||
|
|
||||||
SERIAL_TIMER = 0.1
|
SERIAL_TIMER = 0.1
|
||||||
AUTOLOAD_TIMER = 5.
|
AUTOLOAD_TIMER = 5.
|
||||||
|
@ -78,12 +78,14 @@ class Palette2:
|
||||||
self.serial_port = config.get("serial")
|
self.serial_port = config.get("serial")
|
||||||
if not self.serial_port:
|
if not self.serial_port:
|
||||||
raise config.error("Invalid serial port specific for Palette 2")
|
raise config.error("Invalid serial port specific for Palette 2")
|
||||||
self.baud = config.getint("baud", default=250000)
|
self.baud = config.getint("baud", default=115200)
|
||||||
self.feedrate_splice = config.getfloat(
|
self.feedrate_splice = config.getfloat(
|
||||||
"feedrate_splice", 0.8, minval=0., maxval=1.)
|
"feedrate_splice", default=0.8, minval=0., maxval=1.)
|
||||||
self.feedrate_normal = config.getfloat(
|
self.feedrate_normal = config.getfloat(
|
||||||
"feedrate_normal", 1.0, minval=0., maxval=1.)
|
"feedrate_normal", default=1.0, minval=0., maxval=1.)
|
||||||
self.auto_load_speed = config.getint("auto_load_speed", 2)
|
self.auto_load_speed = config.getint("auto_load_speed", 2)
|
||||||
|
self.auto_cancel_variation = config.getfloat(
|
||||||
|
"auto_cancel_variation", default=None, minval=0.01, maxval=0.2)
|
||||||
|
|
||||||
# Omega code matchers
|
# Omega code matchers
|
||||||
self.omega_header = [None] * 9
|
self.omega_header = [None] * 9
|
||||||
|
@ -168,11 +170,12 @@ class Palette2:
|
||||||
# Tell the device we're alive
|
# Tell the device we're alive
|
||||||
self.write_queue.put("\n")
|
self.write_queue.put("\n")
|
||||||
self.write_queue.put(COMMAND_FIRMWARE)
|
self.write_queue.put(COMMAND_FIRMWARE)
|
||||||
|
self._wait_for_heartbeat()
|
||||||
|
|
||||||
cmd_Disconnect_Help = ("Disconnect from the Palette 2")
|
cmd_Disconnect_Help = ("Disconnect from the Palette 2")
|
||||||
|
|
||||||
def cmd_Disconnect(self, gmcd=None):
|
def cmd_Disconnect(self, gmcd=None):
|
||||||
logging.info("Disconnecting from Palette 2")
|
self.gcode.respond_info("Disconnecting from Palette 2")
|
||||||
if self.serial:
|
if self.serial:
|
||||||
self.serial.close()
|
self.serial.close()
|
||||||
self.serial = None
|
self.serial = None
|
||||||
|
@ -215,6 +218,19 @@ class Palette2:
|
||||||
if self._check_P2(gcmd):
|
if self._check_P2(gcmd):
|
||||||
self.write_queue.put(gcmd.get_commandline())
|
self.write_queue.put(gcmd.get_commandline())
|
||||||
|
|
||||||
|
def _wait_for_heartbeat(self):
|
||||||
|
startTs = self.reactor.monotonic()
|
||||||
|
currTs = startTs
|
||||||
|
while self.heartbeat is None and self.heartbeat < (
|
||||||
|
currTs - SETUP_TIMEOUT) and startTs > (
|
||||||
|
currTs - SETUP_TIMEOUT):
|
||||||
|
currTs = self.reactor.pause(currTs + 1.)
|
||||||
|
|
||||||
|
if self.heartbeat < (currTs - SETUP_TIMEOUT):
|
||||||
|
self.signal_disconnect = True
|
||||||
|
raise self.printer.command_error(
|
||||||
|
"No response from Palette 2")
|
||||||
|
|
||||||
cmd_O1_help = (
|
cmd_O1_help = (
|
||||||
"Initialize the print, and check connection with the Palette 2")
|
"Initialize the print, and check connection with the Palette 2")
|
||||||
|
|
||||||
|
@ -224,18 +240,8 @@ class Palette2:
|
||||||
raise self.printer.command_error(
|
raise self.printer.command_error(
|
||||||
"Cannot initialize print, palette 2 is not connected")
|
"Cannot initialize print, palette 2 is not connected")
|
||||||
|
|
||||||
startTs = self.reactor.monotonic()
|
self.reactor.update_timer(self.heartbeat_timer, self.reactor.NOW)
|
||||||
while self.heartbeat is None and self.heartbeat < (
|
self._wait_for_heartbeat()
|
||||||
self.reactor.monotonic() -
|
|
||||||
HEARTBEAT_TIMEOUT) and startTs > (
|
|
||||||
self.reactor.monotonic() -
|
|
||||||
HEARTBEAT_TIMEOUT):
|
|
||||||
self.reactor.pause(1)
|
|
||||||
|
|
||||||
if self.heartbeat < (self.reactor.monotonic() - HEARTBEAT_TIMEOUT):
|
|
||||||
raise self.printer.command_error(
|
|
||||||
"No response from Palette 2 when initializing")
|
|
||||||
|
|
||||||
self.write_queue.put(gcmd.get_commandline())
|
self.write_queue.put(gcmd.get_commandline())
|
||||||
self.gcode.respond_info(
|
self.gcode.respond_info(
|
||||||
"Palette 2 waiting on user to complete setup")
|
"Palette 2 waiting on user to complete setup")
|
||||||
|
@ -363,6 +369,15 @@ class Palette2:
|
||||||
if not self.is_printing:
|
if not self.is_printing:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def check_ping_variation(last_ping):
|
||||||
|
if self.auto_cancel_variation is not None:
|
||||||
|
ping_max = 100. + (self.auto_cancel_variation * 100.)
|
||||||
|
ping_min = 100. - (self.auto_cancel_variation * 100.)
|
||||||
|
if last_ping < ping_min or last_ping > ping_max:
|
||||||
|
logging.info("Ping variation is too high, "
|
||||||
|
"cancelling print")
|
||||||
|
self.gcode.run_script("CANCEL_PRINT")
|
||||||
|
|
||||||
if len(params) > 2:
|
if len(params) > 2:
|
||||||
percent = float(params[1][1:])
|
percent = float(params[1][1:])
|
||||||
if params[0] == "D1":
|
if params[0] == "D1":
|
||||||
|
@ -370,6 +385,7 @@ class Palette2:
|
||||||
d = {"number": number, "percent": percent}
|
d = {"number": number, "percent": percent}
|
||||||
logging.info("Ping %d, %d percent" % (number, percent))
|
logging.info("Ping %d, %d percent" % (number, percent))
|
||||||
self.omega_pings.append(d)
|
self.omega_pings.append(d)
|
||||||
|
check_ping_variation(percent)
|
||||||
elif params[0] == "D2":
|
elif params[0] == "D2":
|
||||||
number = len(self.omega_pongs) + 1
|
number = len(self.omega_pongs) + 1
|
||||||
d = {"number": number, "percent": percent}
|
d = {"number": number, "percent": percent}
|
||||||
|
@ -563,10 +579,12 @@ class Palette2:
|
||||||
|
|
||||||
def _run_Heartbeat(self, eventtime):
|
def _run_Heartbeat(self, eventtime):
|
||||||
self.write_queue.put(COMMAND_HEARTBEAT)
|
self.write_queue.put(COMMAND_HEARTBEAT)
|
||||||
|
eventtime = self.reactor.pause(eventtime + 5)
|
||||||
if self.heartbeat and self.heartbeat < (
|
if self.heartbeat and self.heartbeat < (
|
||||||
eventtime - HEARTBEAT_TIMEOUT):
|
eventtime - HEARTBEAT_TIMEOUT):
|
||||||
logging.error(
|
logging.error(
|
||||||
"P2 has not responded to heartbeat, Palette will disconnect")
|
"P2 has not responded to heartbeat")
|
||||||
|
if not self.is_printing or self.is_setup_complete:
|
||||||
self.cmd_Disconnect()
|
self.cmd_Disconnect()
|
||||||
return self.reactor.NEVER
|
return self.reactor.NEVER
|
||||||
return eventtime + HEARTBEAT_SEND
|
return eventtime + HEARTBEAT_SEND
|
||||||
|
@ -618,6 +636,13 @@ class Palette2:
|
||||||
return self.reactor.NOW
|
return self.reactor.NOW
|
||||||
return eventtime + AUTOLOAD_TIMER
|
return eventtime + AUTOLOAD_TIMER
|
||||||
|
|
||||||
|
def get_status(self, eventtime=None):
|
||||||
|
status = {
|
||||||
|
"ping": self.omega_pings[-1],
|
||||||
|
"remaining_load_length": self.remaining_load_length,
|
||||||
|
"is_splicing": self.is_splicing
|
||||||
|
}
|
||||||
|
return status
|
||||||
|
|
||||||
def load_config(config):
|
def load_config(config):
|
||||||
return Palette2(config)
|
return Palette2(config)
|
||||||
|
|
Loading…
Reference in New Issue