smoothie port to mbed online compiler (smoothieware.org)

Dependencies:   mbed

For documentation, license, ..., please check http://smoothieware.org/

This version has been tested with a 3 axis machine

Committer:
scachat
Date:
Tue Jul 31 21:11:18 2012 +0000
Revision:
0:31e91bb0ef3c
smoothie port to mbed online compiler

Who changed what in which revision?

UserRevisionLine numberNew contents of line
scachat 0:31e91bb0ef3c 1 /*
scachat 0:31e91bb0ef3c 2 This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
scachat 0:31e91bb0ef3c 3 Smoothie is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
scachat 0:31e91bb0ef3c 4 Smoothie is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
scachat 0:31e91bb0ef3c 5 You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
scachat 0:31e91bb0ef3c 6 */
scachat 0:31e91bb0ef3c 7
scachat 0:31e91bb0ef3c 8 #include "libs/Module.h"
scachat 0:31e91bb0ef3c 9 #include "libs/Kernel.h"
scachat 0:31e91bb0ef3c 10 #include "modules/communication/utils/Gcode.h"
scachat 0:31e91bb0ef3c 11 #include "modules/robot/Stepper.h"
scachat 0:31e91bb0ef3c 12 #include "Spindle.h"
scachat 0:31e91bb0ef3c 13 #include "libs/nuts_bolts.h"
scachat 0:31e91bb0ef3c 14
scachat 0:31e91bb0ef3c 15 Spindle::Spindle(){
scachat 0:31e91bb0ef3c 16
scachat 0:31e91bb0ef3c 17 }
scachat 0:31e91bb0ef3c 18
scachat 0:31e91bb0ef3c 19 void Spindle::on_module_loaded() {
scachat 0:31e91bb0ef3c 20 if( !this->kernel->config->value( spindle_module_enable_checksum )->by_default(false)->as_bool() ){ return; }
scachat 0:31e91bb0ef3c 21
scachat 0:31e91bb0ef3c 22 // Settings
scachat 0:31e91bb0ef3c 23 this->on_config_reload(this);
scachat 0:31e91bb0ef3c 24
scachat 0:31e91bb0ef3c 25 this->register_for_event(ON_GCODE_EXECUTE);
scachat 0:31e91bb0ef3c 26 this->register_for_event(ON_PLAY);
scachat 0:31e91bb0ef3c 27 this->register_for_event(ON_PAUSE);
scachat 0:31e91bb0ef3c 28 this->register_for_event(ON_BLOCK_BEGIN);
scachat 0:31e91bb0ef3c 29 this->register_for_event(ON_BLOCK_END);
scachat 0:31e91bb0ef3c 30 }
scachat 0:31e91bb0ef3c 31
scachat 0:31e91bb0ef3c 32
scachat 0:31e91bb0ef3c 33 // Get config
scachat 0:31e91bb0ef3c 34 void Spindle::on_config_reload(void* argument){
scachat 0:31e91bb0ef3c 35 this->spindle_pin= this->kernel->config->value(spindle_pin_checksum)->by_default("0.4" )->as_pin()->as_output();
scachat 0:31e91bb0ef3c 36 }
scachat 0:31e91bb0ef3c 37
scachat 0:31e91bb0ef3c 38 // Turn spindle off spindle at the end of a move
scachat 0:31e91bb0ef3c 39 void Spindle::on_block_end(void* argument){
scachat 0:31e91bb0ef3c 40 //this->spindle_pin->set(0);
scachat 0:31e91bb0ef3c 41 }
scachat 0:31e91bb0ef3c 42
scachat 0:31e91bb0ef3c 43 // Set spindle power at the beginning of a block
scachat 0:31e91bb0ef3c 44 void Spindle::on_block_begin(void* argument){
scachat 0:31e91bb0ef3c 45 //this->set_spindle();
scachat 0:31e91bb0ef3c 46 }
scachat 0:31e91bb0ef3c 47
scachat 0:31e91bb0ef3c 48 // When the play/pause button is set to pause, or a module calls the ON_PAUSE event
scachat 0:31e91bb0ef3c 49 void Spindle::on_pause(void* argument){
scachat 0:31e91bb0ef3c 50 this->spindle_pin->set(0);
scachat 0:31e91bb0ef3c 51 }
scachat 0:31e91bb0ef3c 52
scachat 0:31e91bb0ef3c 53 // When the play/pause button is set to play, or a module calls the ON_PLAY event
scachat 0:31e91bb0ef3c 54 void Spindle::on_play(void* argument){
scachat 0:31e91bb0ef3c 55 this->set_spindle();
scachat 0:31e91bb0ef3c 56 }
scachat 0:31e91bb0ef3c 57
scachat 0:31e91bb0ef3c 58 // Turn spindle on/off depending on received GCodes
scachat 0:31e91bb0ef3c 59 void Spindle::on_gcode_execute(void* argument){
scachat 0:31e91bb0ef3c 60 Gcode* gcode = static_cast<Gcode*>(argument);
scachat 0:31e91bb0ef3c 61 this->spindle_on = false;
scachat 0:31e91bb0ef3c 62 if( gcode->has_letter('G' )){
scachat 0:31e91bb0ef3c 63 int code = gcode->get_value('G');
scachat 0:31e91bb0ef3c 64 if( code == 0 ){ // G0
scachat 0:31e91bb0ef3c 65 this->kernel->serial->printf("off\r\n");
scachat 0:31e91bb0ef3c 66 this->spindle_pin->set(0);
scachat 0:31e91bb0ef3c 67 this->spindle_on = false;
scachat 0:31e91bb0ef3c 68 }else if( code >= 1 && code <= 3 ){ // G1, G2, G3
scachat 0:31e91bb0ef3c 69 this->kernel->serial->printf("on\r\n");
scachat 0:31e91bb0ef3c 70 this->spindle_pin->set(1);
scachat 0:31e91bb0ef3c 71 this->spindle_on = true;
scachat 0:31e91bb0ef3c 72 }
scachat 0:31e91bb0ef3c 73 }
scachat 0:31e91bb0ef3c 74 }
scachat 0:31e91bb0ef3c 75
scachat 0:31e91bb0ef3c 76
scachat 0:31e91bb0ef3c 77 void Spindle::set_spindle(){
scachat 0:31e91bb0ef3c 78 if( this->spindle_on && this->kernel->stepper->current_block ){
scachat 0:31e91bb0ef3c 79 this->spindle_pin->set(1);
scachat 0:31e91bb0ef3c 80 }
scachat 0:31e91bb0ef3c 81 }