Skip to content

Commit

Permalink
- fixed: macro not being callet at start
Browse files Browse the repository at this point in the history
- fixed: missing low power laser dot during calibration
  • Loading branch information
daniel-fabteam committed Mar 3, 2017
1 parent e8b8dbc commit f24966c
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 151 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# FABtotum official laser plugin
Laser Engraving utilities plugin.
Extends Create and Projectmanager with support for laser engraving.
74 changes: 11 additions & 63 deletions controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ public function make($fileID = '')
//~ $data['z_height_values'] = array('0.1' => '0.1', '0.01' => '0.01');

// select_file
$data['get_files_url'] = plugin_url('getFiles');
$data['get_reacent_url'] = plugin_url('getRecentFiles');
$data['get_files_url'] = 'std/getFiles/laser';
$data['get_reacent_url'] = 'std/getRecentFiles/laser';

// task_wizard
$data['start_task_url'] = plugin_url('startTask');
Expand Down Expand Up @@ -190,63 +190,6 @@ public function make($fileID = '')
$this->view();
}

/**
* @param $data (list)
* return array data for dataTable pluguin
*/
private function dataTableFormat($data)
{
//load text helper
$this->load->helper('text_helper');
$aaData = array();
foreach($data as $file){
$td0 = '<label class="radio"><input type="radio" name="create-file" value="'.$file['id_file'].'"><i></i></label>';
$td1 = '<i></i><span class="hidden-xs">'.$file['client_name'].'</span><span class="hidden-md hidden-sm hidden-lg">'.ellipsize($file['orig_name'], 35).'</span>';
$td2 = '<i class="fa fa-folder-open"></i> <span class="hidden-xs">'.$file['name'].'</span><span class="hidden-md hidden-sm hidden-lg">'.ellipsize($file['name'], 35).'</span>';
$td3 = $file['id_file'];
$td4 = $file['id_object'];
$aaData[] = array($td0, $td1, $td2, $td3, $td4);
}
return $aaData;
}

/**
* @param type (additive, subtractive)
* @return json object for dataTables plugin
* get all files
*/
public function getFiles()
{
//load libraries, models, helpers
$this->load->model('Files', 'files');
$files = $this->files->getForCreate( 'laser' );
$aaData = $this->dataTableFormat($files);
$this->output->set_content_type('application/json')->set_output(json_encode(array('aaData' => $aaData)));
}

/**
* @param type (additive, subtractive)
* @return json object for dataTables plugin
* get all files
*/
public function getImageFiles()
{
//load libraries, models, helpers
$this->load->model('Files', 'files');
$files = $this->files->getByExtension( array('.jpg', '.jpeg', '.png', '.dxf') );
$aaData = $this->dataTableFormat($files);
$this->output->set_content_type('application/json')->set_output(json_encode(array('aaData' => $aaData)));
}

public function getRecentFiles($task_type = '')
{
//load libraries, models, helpers
$this->load->model('Tasks', 'tasks');
$files = $this->tasks->getLastCreations($task_type);
$aaData = $this->dataTableFormat($files);
$this->output->set_content_type('application/json')->set_output(json_encode(array('aaData' => $aaData)));
}

public function startTask()
{
//load helpers
Expand All @@ -258,8 +201,15 @@ public function startTask()

$fileToCreate = $this->files->get($data['idFile'], 1);

//reset task monitor file
resetTaskMonitor();
resetTrace('Please wait...');
$startSubtractive = doMacro('start_engraving');
if($startSubtractive['response'] =! 'ok'){
$this->output->set_content_type('application/json')->set_output(json_encode(array('start' => false, 'message' => $startSubtractive['message'])));
return;
}

resetTrace( _("Please wait...") );

//get object record
$object = $this->files->getObject($fileToCreate['id']);
Expand All @@ -276,12 +226,10 @@ public function startTask()
'start_date' => date('Y-m-d H:i:s')
);
$taskId = $this->tasks->add($taskData);
//$taskId = 0;
//$userID = $this->session->user['id'];

$response = array(
'start' => false,
'message' => 'Task Not Implemented yet.',
'message' => _("Task Not Implemented yet."),
'trace' => '',
'error' => ''
);
Expand Down
54 changes: 20 additions & 34 deletions scripts/py/engrave.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,49 +21,39 @@
# Import standard python module
import argparse
import time
import gettext

# Import external modules

# Import internal modules
from fabtotum.utils.translation import _, setLanguage
from fabtotum.fabui.config import ConfigService
from fabtotum.fabui.gpusher import GCodePusher
import fabtotum.fabui.macros.general as general_macros
import fabtotum.fabui.macros.printing as print_macros

# Set up message catalog access
tr = gettext.translation('mill', 'locale', fallback=True)
_ = tr.ugettext

################################################################################

class Application(GCodePusher):
"""
Milling application.
"""

def __init__(self, log_trace, monitor_file, standalone = False, autolevel = False, finalize = True):
super(Application, self).__init__(log_trace, monitor_file, use_stdout=standalone )
def __init__(self, standalone = False):
super(Application, self).__init__(use_stdout=standalone)
self.standalone = standalone
self.autolevel = autolevel
self.finalize = finalize

def progress_callback(self, percentage):
print "Progress", percentage

def task_finalize(self):
if self.standalone or self.finalize:
if self.is_aborted():
self.set_task_status(GCodePusher.TASK_ABORTING)
else:
self.set_task_status(GCodePusher.TASK_COMPLETING)

#~ self.exec_macro("end_subtractive")

if self.is_aborted():
self.set_task_status(GCodePusher.TASK_ABORTED)
else:
self.set_task_status(GCodePusher.TASK_COMPLETED)
def task_finalize(self):
if self.is_aborted():
self.set_task_status(GCodePusher.TASK_ABORTING)
else:
self.set_task_status(GCodePusher.TASK_COMPLETING)

if self.is_aborted():
self.exec_macro("end_engraving_aborted")
self.set_task_status(GCodePusher.TASK_ABORTED)
else:
self.exec_macro("end_engraving")
self.set_task_status(GCodePusher.TASK_COMPLETED)

self.stop()

Expand All @@ -81,6 +71,7 @@ def file_done_callback(self):
def state_change_callback(self, state):
if state == 'paused':
self.trace( _("Engraving PAUSED") )
self.trace( _("Please wait until the buffered moves in totumduino are finished") )
if state == 'resumed':
self.trace( _("Engraving RESUMED") )
if state == 'aborted':
Expand All @@ -96,12 +87,11 @@ def run(self, task_id, gcode_file):
:type task_id: int
"""

self.prepare_task(task_id, task_type='fab_laser', task_controller='plugin', gcode_file=gcode_file)
self.prepare_task(task_id, task_type='laser', gcode_file=gcode_file)
self.set_task_status(GCodePusher.TASK_RUNNING)

#if self.standalone:
#~ self.exec_macro("check_pre_print")
#self.exec_macro("start_subtractive")
if self.standalone:
self.exec_macro("start_engraving")

self.send_file(gcode_file)

Expand All @@ -125,12 +115,8 @@ def main():
standalone = True
else:
standalone = False

autolevel = False
monitor_file = config.get('general', 'task_monitor') # TASK MONITOR FILE (write stats & task info, es: temperatures, speed, etc
log_trace = config.get('general', 'trace') # TASK TRACE FILE

app = Application(log_trace, monitor_file, standalone, autolevel)
app = Application(standalone)

app.run(task_id, gcode_file)
app.loop()
Expand Down
82 changes: 29 additions & 53 deletions views/make/js.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,11 @@
var idFile <?php echo $file_id != '' ? ' = '.$file_id : ''; ?>; //file to create
var idTask <?php echo $runningTask ? ' = '.$runningTask['id'] : ''; ?>;


$(document).ready(function() {
$('#understandSafety').on('click', understandSafety);

$('[data-toggle="tooltip"]').tooltip();
});

/**
* freeze ui
*/
function freezeUI()
{
disableButton('.btn-prev');
disableButton('.btn-next');
disableButton('.top-directions');
disableButton('.top-axisz');
}
/**
*
*/
function unFreezeUI()
{
enableButton('.top-directions');
enableButton('.top-axisz');
}

function checkWizard()
{
Expand All @@ -52,32 +33,34 @@ function checkWizard()
disableButton('.btn-next');
$('.btn-next').find('span').html('Next');

//cmd = 'M60 S0\n';
//fabApp.jogMdi(cmd);
cmd = 'M62';
fabApp.jogMdi(cmd);

break;
case 2: // Safety
enableButton('.btn-prev');
disableButton('.btn-next');
$('.btn-next').find('span').html('Next');

//cmd = 'M60 S0\n';
//fabApp.jogMdi(cmd);
cmd = 'M62';
fabApp.jogMdi(cmd);

break;
case 3: // Calibration
enableButton('.btn-prev');
disableButton('.btn-next');
$('.btn-next').find('span').html('Engrave');

//cmd = 'M60 S10\nM300\n';
//fabApp.jogMdi(cmd);
cmd = 'M60 S10\nM300\n';
fabApp.jogMdi(cmd);

break;
case 4: // Execution
<?php if($runningTask): ?>;
// do nothing
<?php else: ?>
cmd = 'M62';
fabApp.jogMdi(cmd);
startTask();
<?php endif; ?>
return false;
Expand All @@ -88,18 +71,23 @@ function checkWizard()
}
}

function setLaserPWM(action, value)
function jogSetAsZero()
{
console.log(action, value);
message="Laser PWM set to: " + value;
showActionAlert(message);
console.log('set as zero');
enableButton('.btn-next');
return false;
}

function understandSafety()
{
enableButton('.btn-next');
return false;
}

function startTask()
{
console.log('Starting task');
is_task_on = true;
openWait('Initializing');
openWait('<i class="fa fa-spinner fa-spin "></i>' + "<?php echo _('Preparing {0}');?>".format("<?php echo _(ucfirst($type)); ?>"), "<?php echo _('Please wait');?>");

var data = {
idFile:idFile
Expand All @@ -110,40 +98,28 @@ function startTask()
data: data,
url: '<?php echo site_url($start_task_url); ?>',
dataType: 'json'
}).done(function(response) {
}).done(function(response) {
if(response.start == false){
$('.wizard').wizard('selectedItem', { step: 2 });
showErrorAlert('Error', response.message);
fabApp.showErrorAlert(response.message);
}else{

//setInterval(timer, 1000);
//setInterval(jsonMonitor, 1000);
idTask = response.id_task;

<?php if($type == "print"): ?>
fabApp.resetTemperaturesPlot(50);
setTimeout(initGraph, 1000);
//~ setTemperaturesSlidersValue(response.temperatures.extruder, response.temperatures.bed);
<?php endif; ?>
idTask = response.id_task;

initRunningTaskPage();
updateZOverride(0);

ga('send', 'event', 'laser', 'start', 'laser started');
}
closeWait();
})
}

function understandSafety()
{
enableButton('.btn-next');
return false;
}

function jogSetAsZero()
function setLaserPWM(action, value)
{
console.log('set as zero');
enableButton('.btn-next');
return false;
console.log(action, value);
message="Laser PWM set to: " + value;
showActionAlert(message);
}

</script>

0 comments on commit f24966c

Please sign in to comment.