Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Z-Change Timelapse only on real z changes #1148

Merged
merged 4 commits into from
Mar 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/octoprint/server/api/timelapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def getTimelapseData():
config["type"] = "zchange"
config["postRoll"] = timelapse.post_roll
config["fps"] = timelapse.fps
config.update({
"retractionZHop": timelapse.retraction_zhop
})
elif timelapse is not None and isinstance(timelapse, octoprint.timelapse.TimedTimelapse):
config["type"] = "timed"
config["postRoll"] = timelapse.post_roll
Expand Down Expand Up @@ -113,6 +116,21 @@ def setTimelapseConfig():
else:
return make_response("Invalid value for interval: %d" % interval)

if "retractionZHop" in request.values:
config["options"] = {
"retractionZHop": 0
}

try:
retractionZHop = float(request.values["retractionZHop"])
except ValueError:
return make_response("Invalid value for retraction Z-Hop: %r" % request.values["retractionZHop"])
else:
if retractionZHop > 0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't allow retractionZHop to be 0, but that is the default lower down. The effect is that if you switch to "Timed" and hit "Save Config" and then switch back to "On Z Change" it won't let you "Save Config" any more unless you set the retraction Z-hop to something non-zero. Is there a problem letting it be zero? If so, should we fix that problem or set the default to a small non-zero number (0.01mm)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO there's no problem letting it be 0 and that should simply have been a >= instead of a >. Fixed accordingly on maintenance.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I follow correctly, in the meantime for those of us on master, if simply switch to "On Z-Change", set a retraction z-hop to something other than zero, save settings, change it back to zero, and save again it should work fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except that last step will hit the error again. If you just set the z-hop to something smaller than the lowest layer height you'll ever print, you'll be fine. 0.001 perhaps.

config["options"]["retractionZHop"] = retractionZHop
else:
return make_response("Invalid value for retraction Z-Hop: %d" % retractionZHop)

if admin_permission.can() and "save" in request.values and request.values["save"] in valid_boolean_trues:
octoprint.timelapse.configureTimelapse(config, True)
else:
Expand Down
2 changes: 1 addition & 1 deletion src/octoprint/static/css/octoprint.css

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions src/octoprint/static/js/app/viewmodels/timelapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ $(function() {
self.defaultFps = 25;
self.defaultPostRoll = 0;
self.defaultInterval = 10;
self.defaultRetractionZHop = 0;

self.timelapseType = ko.observable(undefined);
self.timelapseTimedInterval = ko.observable(self.defaultInterval);
self.timelapsePostRoll = ko.observable(self.defaultPostRoll);
self.timelapseFps = ko.observable(self.defaultFps);
self.timelapseRetractionZHop = ko.observable(self.defaultRetractionZHop);

self.persist = ko.observable(false);
self.isDirty = ko.observable(false);
Expand Down Expand Up @@ -50,6 +52,9 @@ $(function() {
self.timelapseFps.subscribe(function(newValue) {
self.isDirty(true);
});
self.timelapseRetractionZHop.subscribe(function(newValue) {
self.isDirty(true);
});

// initialize list helper
self.listHelper = new ItemListHelper(
Expand Down Expand Up @@ -106,6 +111,14 @@ $(function() {
self.timelapseTimedInterval(self.defaultInterval);
}

if (config.type == "zchange") {
if (config.retractionZHop != undefined && config.retractionZHop > 0) {
self.timelapseRetractionZHop(config.retractionZHop);
}
} else {
self.timelapseRetractionZHop(self.defaultRetractionZHop);
}

if (config.postRoll != undefined && config.postRoll >= 0) {
self.timelapsePostRoll(config.postRoll);
} else {
Expand Down Expand Up @@ -161,6 +174,10 @@ $(function() {
payload["interval"] = self.timelapseTimedInterval();
}

if (self.timelapseType() == "zchange") {
payload["retractionZHop"] = self.timelapseRetractionZHop();
}

$.ajax({
url: API_BASEURL + "timelapse",
type: "POST",
Expand Down
2 changes: 1 addition & 1 deletion src/octoprint/static/less/octoprint.less
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ table {
}

#temp_newTemp, #temp_newBedTemp, #speed_innerWall, #speed_outerWall, #speed_fill, #speed_support,
#webcam_timelapse_interval, #webcam_timelapse_postRoll, #webcam_timelapse_fps {
#webcam_timelapse_interval, #webcam_timelapse_postRoll, #webcam_timelapse_fps, #webcam_timelapse_retractionZHop {
text-align: right;
}

Expand Down
9 changes: 9 additions & 0 deletions src/octoprint/templates/tabs/timelapse.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@
</div>
</div>

<div id="webcam_timelapse_retractionsettings" data-bind="visible: timelapseType() == 'zchange'">
<label for="webcam_timelapse_retractionZHop">{{ _('Retraction Z-Hop (in mm)') }}</label>
<span class="help-block"><span class="label label-info">{{ _('Note') }}</span> {{ _('Enter the retraction z-hop used in the firmware or the gcode file to trigger snapshots for the timelapse only if a real layer change happens. For this to work properly your retraction z-hop has to be different from your layerheight!') }}</span>
<div class="input-append">
<input type="text" class="input-mini" id="webcam_timelapse_retractionZHop" data-bind="value: timelapseRetractionZHop, valueUpdate: 'afterkeydown', enable: isOperational() && !isPrinting() && loginState.isUser()">
<span class="add-on">{{ _('mm') }}</span>
</div>
</div>

<div data-bind="visible: loginState.isAdmin">
<label class="checkbox">
<input type="checkbox" data-bind="checked: persist"> {{ _('Save as default') }}
Expand Down
25 changes: 21 additions & 4 deletions src/octoprint/timelapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ def configureTimelapse(config=None, persist=False):
if type is None or "off" == type:
current = None
elif "zchange" == type:
current = ZTimelapse(post_roll=postRoll, fps=fps)
retractionZHop = 0
if "options" in config and "retractionZHop" in config["options"] and config["options"]["retractionZHop"] > 0:
retractionZHop = config["options"]["retractionZHop"]
current = ZTimelapse(post_roll=postRoll, retraction_zhop=retractionZHop, fps=fps)
elif "timed" == type:
interval = 10
if "options" in config and "interval" in config["options"] and config["options"]["interval"] > 0:
Expand Down Expand Up @@ -404,18 +407,26 @@ def clean_capture_dir(self):


class ZTimelapse(Timelapse):
def __init__(self, post_roll=0, fps=25):
def __init__(self, post_roll=0, retraction_zhop=0, fps=25):
Timelapse.__init__(self, post_roll=post_roll, fps=fps)
self._retraction_zhop = retraction_zhop
self._logger.debug("ZTimelapse initialized")

@property
def retraction_zhop(self):
return self._retraction_zhop

def event_subscriptions(self):
return [
(Events.Z_CHANGE, self._on_z_change)
]

def config_data(self):
return {
"type": "zchange"
"type": "zchange",
"options": {
"retractionZHop": self._retraction_zhop
}
}

def process_post_roll(self):
Expand All @@ -432,7 +443,13 @@ def process_post_roll(self):
Timelapse.process_post_roll(self)

def _on_z_change(self, event, payload):
self.captureImage()
if self._retraction_zhop == 0:
self.captureImage()
else:
diff = round(payload["new"] - payload["old"], 3)
zhop = round(self._retraction_zhop, 3)
if diff > 0 and diff != zhop:
self.captureImage()


class TimedTimelapse(Timelapse):
Expand Down