From 05c556d7a14f67781ab19306c7ebf106376a17df Mon Sep 17 00:00:00 2001 From: reprappro Date: Tue, 7 Aug 2012 22:25:14 +0100 Subject: [PATCH] Started work on the slave controller code. --- Marlin/Marlin.h | 16 +++- Marlin/Marlin.pde | 22 ++++- Marlin/MarlinSerial.cpp | 9 ++ Marlin/MarlinSerial.h | 6 ++ Marlin/pins.h | 3 + Marlin/slave_comms.cpp | 16 ++++ Marlin/slave_comms.h | 66 +++++++++++++ Marlin/stepper.cpp | 4 +- Marlin/stepper.h | 2 +- Marlin/temperature.cpp | 14 +-- Marlin/temperature.h | 2 +- README | 143 ++++++++++++++------------- Slave/Slave/Slave.pde | 154 ++++++++++++++++++++++++++++++ Slave/Slave/Slave_Configuration.h | 76 +++++++++++++++ 14 files changed, 453 insertions(+), 80 deletions(-) create mode 100644 Marlin/slave_comms.cpp create mode 100644 Marlin/slave_comms.h create mode 100644 Slave/Slave/Slave.pde create mode 100644 Slave/Slave/Slave_Configuration.h diff --git a/Marlin/Marlin.h b/Marlin/Marlin.h index 70f9062428b7..3afc6bd80a21 100644 --- a/Marlin/Marlin.h +++ b/Marlin/Marlin.h @@ -4,7 +4,11 @@ #ifndef MARLIN_H #define MARLIN_H +#include "Configuration.h" + +#ifndef REPRAPPRO_MULTIMATERIALS #define HardwareSerial_h // trick to disable the standard HWserial +#endif #define FORCE_INLINE __attribute__((always_inline)) inline @@ -22,7 +26,7 @@ #include "fastio.h" -#include "Configuration.h" + #include "pins.h" #if ARDUINO >= 100 @@ -46,12 +50,20 @@ #include "WString.h" -#if MOTHERBOARD == 8 // Teensylu +#ifdef REPRAPPRO_MULTIMATERIALS #define MYSERIAL Serial + #define MYSERIAL1 Serial1 +#else + +#if MOTHERBOARD == 8 // Teensylu + #define MYSERIAL Serial + #define MYSERIAL1 Serial1 #else #define MYSERIAL MSerial #endif +#endif + //this is a unfinsihed attemp to removes a lot of warning messages, see: // http://www.avrfreaks.net/index.php?name=PNphpBB2&file=printview&t=57011 //typedef char prog_char PROGMEM; diff --git a/Marlin/Marlin.pde b/Marlin/Marlin.pde index 2505680c8226..566ac4aa36f9 100644 --- a/Marlin/Marlin.pde +++ b/Marlin/Marlin.pde @@ -49,9 +49,7 @@ #include "EEPROMwrite.h" #include "language.h" #include "pins_arduino.h" - -// REMOVE THIS**** -float txyz[EXTRUDERS]; +#include "slave_comms.h" #define VERSION_STRING "1.0.1 RRP" @@ -136,6 +134,8 @@ float txyz[EXTRUDERS]; // M512 - FPU Disable // M999 - Restart after being stopped by error +// M555 - Temporary: master/slave comms test + // TN - Select extruder N //Stepper Movement Variables @@ -356,6 +356,11 @@ void setup() probe_init(); //Initializes probe if PROBE_PIN is defined FPUTransform_init(); //Initializes FPU when UMFPUSUPPORT defined setup_photpin(); + +#ifdef REPRAPPRO_MULTIMATERIALS + setup_slave(); +#endif + } @@ -1358,7 +1363,14 @@ void process_commands() FPUDisable(); } break; - +#ifdef REPRAPPRO_MULTIMATERIALS + case 555: // Slave comms test + talkToSlave("AMFP"); + SERIAL_ECHO_START; + SERIAL_ECHOPGM("Slave response:"); + SERIAL_ECHO(listenToSlave()); + break; +#endif } } @@ -1394,7 +1406,7 @@ void process_commands() y_off_d = extruder_y_off[tmp_extruder] - extruder_y_off[active_extruder]; z_off_d = extruder_z_off[tmp_extruder] - extruder_z_off[active_extruder]; - if(z_off_d >= 0) + if(z_off_d > 0) { destination[Z_AXIS] += z_off_d; feedrate = fast_home_feedrate[Z_AXIS]; diff --git a/Marlin/MarlinSerial.cpp b/Marlin/MarlinSerial.cpp index e369800b893b..5041a53799c1 100644 --- a/Marlin/MarlinSerial.cpp +++ b/Marlin/MarlinSerial.cpp @@ -20,7 +20,12 @@ Modified 28 September 2010 by Mark Sproul */ + + #include "Marlin.h" + +#ifndef REPRAPPRO_MULTIMATERIALS + #include "MarlinSerial.h" #if MOTHERBOARD != 8 // !teensylu @@ -324,6 +329,10 @@ void MarlinSerial::printFloat(double number, uint8_t digits) MarlinSerial MSerial; +MarlinSerial MSerial1; + #endif // whole file #endif //teensylu +#endif REPRAPPRO_MULTIMATERIALS + diff --git a/Marlin/MarlinSerial.h b/Marlin/MarlinSerial.h index 8525cba288d3..7a86b09fb156 100644 --- a/Marlin/MarlinSerial.h +++ b/Marlin/MarlinSerial.h @@ -19,10 +19,13 @@ Modified 28 September 2010 by Mark Sproul */ + + #ifndef MarlinSerial_h #define MarlinSerial_h #include "Marlin.h" +#ifndef REPRAPPRO_MULTIMATERIALS #define DEC 10 #define HEX 16 @@ -145,6 +148,9 @@ class MarlinSerial //: public Stream }; extern MarlinSerial MSerial; +extern MarlinSerial MSerial1; #endif // ! teensylu #endif + +#endif // REPRAPPRO_MULTIMATERIALS diff --git a/Marlin/pins.h b/Marlin/pins.h index 00212e2e6c31..fbdc1cc36373 100644 --- a/Marlin/pins.h +++ b/Marlin/pins.h @@ -73,6 +73,7 @@ #define SDPOWER -1 #define SDSS 31 + #endif /**************************************************************************************** @@ -131,6 +132,8 @@ #define SDPOWER -1 #define SDSS 31 +#define STEP_TOGGLE 16 + #endif diff --git a/Marlin/slave_comms.cpp b/Marlin/slave_comms.cpp new file mode 100644 index 000000000000..ad59f650428c --- /dev/null +++ b/Marlin/slave_comms.cpp @@ -0,0 +1,16 @@ + +#include "Marlin.h" + +#ifdef REPRAPPRO_MULTIMATERIALS + +float txyz[EXTRUDERS]; +char slaveBuffer[64]; +long timeout; + +void setup_slave() +{ + MYSERIAL1.begin(250000); + SET_OUTPUT(STEP_TOGGLE); +} + +#endif diff --git a/Marlin/slave_comms.h b/Marlin/slave_comms.h new file mode 100644 index 000000000000..5faffabd0a26 --- /dev/null +++ b/Marlin/slave_comms.h @@ -0,0 +1,66 @@ +#ifndef _SLAVE_COMMSH +#define _SLAVE_COMMSH +/* + Functions to drive, and to return values from, a slave processor + + Adrian Bowyer 29 July 2012 +*/ + +#ifdef REPRAPPRO_MULTIMATERIALS + +extern float txyz[]; +extern char slaveBuffer[]; +extern long timeout; +#define TIMEOUT 2 + +float slaveDegHotend(uint8_t extruder); +void slaveSetTargetHotend(const float &celsius, uint8_t extruder); +float slaveDegTargetHotend(uint8_t extruder); +bool slaveIsHeatingHotend(uint8_t extruder); +bool slaveIsCoolingHotend(uint8_t extruder); +void slaveRemoteStep(int8_t extruder, int8_t v); +void slaveRemoteDir(int8_t extruder, bool forward); +void talkToSlave(char s[]); +char* listenToSlave(); +void setup_slave(); + + +FORCE_INLINE float slaveDegHotend(uint8_t extruder) { return txyz[extruder]; } +FORCE_INLINE void slaveSetTargetHotend(const float &celsius, uint8_t extruder) {txyz[extruder] = celsius; } +FORCE_INLINE float slaveDegTargetHotend(uint8_t extruder) { return txyz[extruder]; } +FORCE_INLINE bool slaveIsHeatingHotend(uint8_t extruder) { return false; } +FORCE_INLINE bool slaveIsCoolingHotend(uint8_t extruder) { return false; } + + +FORCE_INLINE void slaveRemoteStep(int8_t extruder, int8_t v) +{ + +} + +FORCE_INLINE void slaveRemoteDir(int8_t extruder, bool forward) +{ + +} + +FORCE_INLINE void talkToSlave(char s[]) { MYSERIAL1.println(s); } +FORCE_INLINE char* listenToSlave() +{ + int c = 0; + timeout = millis(); + int8_t i = 0; + while(c != '\n') + { + while(!MYSERIAL1.available() && (millis() - timeout < TIMEOUT)); + c = MYSERIAL1.read(); + timeout = millis(); + slaveBuffer[i] = (char)c; + i++; + } + slaveBuffer[i] = 0; + return slaveBuffer; +} + +#endif + +#endif + diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index 152ec0cb6e60..e7c834c0a241 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -432,10 +432,12 @@ ISR(TIMER1_COMPA_vect) - for(int8_t i=0; i < step_loops; i++) { // Take multiple steps per interrupt (For high speed moves) + for(int8_t i=0; i < step_loops; i++) { // Take multiple steps per interrupt (For high speed moves) + #ifndef REPRAPPRO_MULTIMATERIALS #if MOTHERBOARD != 8 // !teensylu MSerial.checkRx(); // Check for serial chars. #endif + #endif #ifdef ADVANCE counter_e += current_block->steps_e; diff --git a/Marlin/stepper.h b/Marlin/stepper.h index 2f2bdb38d014..f5d5a91f97cb 100644 --- a/Marlin/stepper.h +++ b/Marlin/stepper.h @@ -22,7 +22,7 @@ #define stepper_h #include "planner.h" -#include "slave.h" +#include "slave_comms.h" #ifdef REPRAPPRO_MULTIMATERIALS diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index b49931c185de..99ae6cefc589 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -309,15 +309,16 @@ float analog2tempi(int raw, const float& beta, const float& rs, const float& r_i #ifdef REPRAPPRO_MULTIMATERIALS -// TODO Put some code in here... + float analog2temp_remote(uint8_t e) { - return 20; + return slaveDegHotend(e); } int temp2analog_remote(int celsius, uint8_t e) { + // What do we do about this, then? return temp2analogi(celsius, E_BETA, E_RS, E_R_INF); } #endif @@ -330,10 +331,6 @@ int temp2analog(int celsius, uint8_t e) #endif return temp2analogi(celsius, E_BETA, E_RS, E_R_INF); } -int temp2analogBed(int celsius) -{ - return temp2analogi(celsius, BED_BETA, BED_RS, BED_R_INF); -} float analog2temp(int raw, uint8_t e) { #ifdef REPRAPPRO_MULTIMATERIALS @@ -341,6 +338,11 @@ float analog2temp(int raw, uint8_t e) #endif return analog2tempi(raw, E_BETA, E_RS, E_R_INF); } + +int temp2analogBed(int celsius) +{ + return temp2analogi(celsius, BED_BETA, BED_RS, BED_R_INF); +} float analog2tempBed(int raw) { return analog2tempi(raw, BED_BETA, BED_RS, BED_R_INF); diff --git a/Marlin/temperature.h b/Marlin/temperature.h index 6bb58f67dbe5..1352add07b85 100644 --- a/Marlin/temperature.h +++ b/Marlin/temperature.h @@ -23,7 +23,7 @@ #include "Marlin.h" #include "planner.h" -#include "slave.h" +#include "slave_comms.h" // If we are using a slave board we have multiple extruders, but we only have to worry // about the temperature of the first one of them. diff --git a/README b/README index 46040eb11861..8c4d55fac0d3 100644 --- a/README +++ b/README @@ -1,3 +1,18 @@ +This is the RepRapPRo version of Marlin. + +http://reprappro.com + +Modifications mainly be Jean-Marc and Adrian + +The core Marlin code in the Marlin directory is stable and is our standard +release firmware for all RepRapPro RepRap machines. + +Code in the Slave directory is under development. This drives a slave +controller (with the core Marling code on the master controller) to drive +multiple extruders. + + + <<<<<<< HEAD A new beta version is avaiable. Look under the Marlin_v1 branch. We also made a tag that you can download. @@ -87,68 +102,68 @@ The best workaround is to move these files to sanguino directory. ======= -This RepRap firmware is a mashup between Sprinter, grbl and many original parts. - (https://github.com/kliment/Sprinter) - (https://github.com/simen/grbl/tree) - -Derived from Sprinter and Grbl by Erik van der Zalm. -Sprinters lead developers are Kliment and caru. -Grbls lead developer is Simen Svale Skogsrud. -It has been adapted to the Ultimaker Printer by: -Bernhard Kubicek, Matthijs Keuper, Bradley Feldman, and others... - - -Features: - - Interrupt based movement with real linear acceleration - - High steprate - - Look ahead (Keep the speed high when possible. High cornering speed) - - Interrupt based temperature protection - - preliminary support for Matthew Roberts advance algorithm - For more info see: http://reprap.org/pipermail/reprap-dev/2011-May/003323.html - - Full endstop support - - Simple LCD support (16x2) - - SD Card support - - Provisions for Bernhard Kubicek's new hardware control console and 20x4 lcd - -This firmware is optimized for Ultimaker's gen6 electronics (including the Ultimaker 1.5.x daughterboard and Arduino Mega 2560). - -The default baudrate is 115200. - - -======================================================================================== - -Configuring and compilation - - -Install the latest arduino software IDE/toolset (currently 0022) - http://www.arduino.cc/en/Main/Software - -Install Ultimaker's RepG 25 build - http://software.ultimaker.com -(or alternatively install Kliment's printrun/pronterface https://github.com/kliment/Printrun_) - -Copy the Ultimaker Marlin firmware - https:/github.com/bkubicek/Marlin - (Use the download button) - -Start the arduino IDE. -Select Tools -> Board -> Arduino Mega 2560 -Select the correct serial port in Tools ->Serial Port -Open Marlin.pde - -Click the Verify/Compile button - -Click the Upload button -If all goes well the firmware is uploading - -Start Ultimaker's Custom RepG 25 -Make sure Show Experimental Profiles is enabled in Preferences -Select Sprinter as the Driver - -Press the Connect button. - -KNOWN ISSUES: RepG will display: Unknown: marlin x.y.z - -That's ok. Enjoy Silky Smooth Printing. - +This RepRap firmware is a mashup between Sprinter, grbl and many original parts. + (https://github.com/kliment/Sprinter) + (https://github.com/simen/grbl/tree) + +Derived from Sprinter and Grbl by Erik van der Zalm. +Sprinters lead developers are Kliment and caru. +Grbls lead developer is Simen Svale Skogsrud. +It has been adapted to the Ultimaker Printer by: +Bernhard Kubicek, Matthijs Keuper, Bradley Feldman, and others... + + +Features: + - Interrupt based movement with real linear acceleration + - High steprate + - Look ahead (Keep the speed high when possible. High cornering speed) + - Interrupt based temperature protection + - preliminary support for Matthew Roberts advance algorithm + For more info see: http://reprap.org/pipermail/reprap-dev/2011-May/003323.html + - Full endstop support + - Simple LCD support (16x2) + - SD Card support + - Provisions for Bernhard Kubicek's new hardware control console and 20x4 lcd + +This firmware is optimized for Ultimaker's gen6 electronics (including the Ultimaker 1.5.x daughterboard and Arduino Mega 2560). + +The default baudrate is 115200. + + +======================================================================================== + +Configuring and compilation + + +Install the latest arduino software IDE/toolset (currently 0022) + http://www.arduino.cc/en/Main/Software + +Install Ultimaker's RepG 25 build + http://software.ultimaker.com +(or alternatively install Kliment's printrun/pronterface https://github.com/kliment/Printrun_) + +Copy the Ultimaker Marlin firmware + https:/github.com/bkubicek/Marlin + (Use the download button) + +Start the arduino IDE. +Select Tools -> Board -> Arduino Mega 2560 +Select the correct serial port in Tools ->Serial Port +Open Marlin.pde + +Click the Verify/Compile button + +Click the Upload button +If all goes well the firmware is uploading + +Start Ultimaker's Custom RepG 25 +Make sure Show Experimental Profiles is enabled in Preferences +Select Sprinter as the Driver + +Press the Connect button. + +KNOWN ISSUES: RepG will display: Unknown: marlin x.y.z + +That's ok. Enjoy Silky Smooth Printing. + >>>>>>> Mendel diff --git a/Slave/Slave/Slave.pde b/Slave/Slave/Slave.pde new file mode 100644 index 000000000000..83981ce60480 --- /dev/null +++ b/Slave/Slave/Slave.pde @@ -0,0 +1,154 @@ +/* + Slave processor code for RepRapPro mult-extruder machines + + Adrian Bowyer 7 August 2012 + RepRapPro Ltd + http://reprappro.com + + Licence: GPL +*/ + +#include "Slave_Configuration.h" + +unsigned long time; +char buf[BUFLEN]; +char scratch[2*BUFLEN]; +int bp; + +// Pin arrays + +int8_t steps[DRIVES] = STEPS; +int8_t dirs[DRIVES] = DIRS; +int8_t enables[DRIVES] = ENABLES; +int8_t therms[HOT_ENDS] = THERMS; +int8_t heaters[HOT_ENDS] = HEATERS; + +void setup() +{ + int8_t i; + MYSERIAL1.begin(BAUD); + bp = 0; + + for(i = 0; i < DRIVES; i++) + { + pinMode(steps[i], OUTPUT); + pinMode(dirs[i], OUTPUT); + pinMode(enables[i], OUTPUT); + } + for(i = 0; i < HOT_ENDS; i++) + { + pinMode(therms[i], INPUT); + pinMode(heaters[i], OUTPUT); + setTemperature(i, 0); + } + time = millis() + TEMP_INTERVAL; +} + +inline char* strplus(char* a, char* b) +{ + strcpy(scratch, a); + return strcat(scratch, b); +} + +inline void error(char* s) +{ +} + + + +// Use algebra to work out temperatures, not tables +// NB - this assumes all extruders use the same thermistor type. +inline int temp2analogi(const int& celsius) +{ + float r = TH_R_INF*exp(TH_BETA/(celsius - ABS_ZERO)); + return AD_RANGE - (int)(0.5 + AD_RANGE*r/(r + TH_RS)); +} + +inline float analog2tempi(const int& raw) +{ + float rawf = (float)(AD_RANGE - raw); + return ABS_ZERO + TH_BETA/log( (rawf*TH_RS/(AD_RANGE - rawf))/TH_R_INF ); +} + + + +inline void setTemperature(int8_t e, int t) +{ +} + +inline float getTemperature(int8_t e) +{ + return analog2tempi(analogRead(therms[e])); +} + +void heatControl() +{ +} + +void stop() +{ + int8_t i; + for(i = 0; i < DRIVES; i++) + digitalWrite(enables[i], DISABLE); + for(i = 0; i < HOT_ENDS; i++) + setTemperature(i, 0); +} + +void command() +{ + switch(buf[0]) + { + case GET_T: // Get temperature + + case SET_T: // Set temperature + + case SET_PID: // Set PID parameters + + case Q_DDA: // Queue DDA parameters + + case SET_DDA: // Set DDA parameters from head of queue + + case STOP: // Shut everything down; carry on listening for commands + stop(); + break; + + default: + error(strplus("dud command: ", buf)); + break; + } +} + +inline void incomming() +{ + if(MYSERIAL1.available()) + { + buf[bp] = (char)MYSERIAL1.read(); + if(buf[bp] == '\n') + { + buf[bp] = 0; + command(); + bp = 0; + } else + bp++; + if(bp >= BUFLEN) + { + bp = BUFLEN-1; + error(strplus("command overflow: ", buf)); + } + } +} + +inline void tempCheck() +{ + if( (long)(millis() - time) < 0) + return; + time += TEMP_INTERVAL; + heatControl(); +} + + +void loop() +{ + incomming(); + tempCheck(); +} diff --git a/Slave/Slave/Slave_Configuration.h b/Slave/Slave/Slave_Configuration.h new file mode 100644 index 000000000000..09d107de65a9 --- /dev/null +++ b/Slave/Slave/Slave_Configuration.h @@ -0,0 +1,76 @@ +/* + Slave processor code for RepRapPro mult-extruder machines + + Adrian Bowyer 7 August 2012 + RepRapPro Ltd + http://reprappro.com + + Licence: GPL +*/ + +// Commands +#define GET_T 't' // Get temperature +#define SET_T 'T' // Set temperature +#define SET_PID 'P' // Set PID parameters +#define Q_DDA 'Q' // Queue DDA parameters +#define SET_DDA 'D' // Set DDA parameters from head of queue +#define STOP 'S' // Shut down everything + +// Various... + +#define MYSERIAL1 Serial1 // comms here +#define BAUD 250000 // comms speed +#define TEMP_INTERVAL 500 // check temperature this many milliseconds +#define BUFLEN 64 // input string +#define RING_B 32 // DDA parameter ring buffer +#define HOT_ENDS 2 // number of heaters controlled +#define DRIVES 4 // number of steppers controlled + + +// === Pin definitions === +// Sanguinololu V 1.2 or higher + +#define ENABLE 0 +#define DISABLE 1 + +#define STEPS { 15, 22, 3, 1 } +#define DIRS { 21, 23, 2, 0 } +#define ENABLES { 14, 14, 26, 14 } + + +#define THERMS { 7, 6 } // Analogue +#define HEATERS { 13, 14 } + +//=========================================================================== +//=============================Thermal Settings ============================ +//=========================================================================== + +// Set this if you want to define the constants in the thermistor circuit +// and work out temperatures algebraically - added by AB. + +// See http://en.wikipedia.org/wiki/Thermistor#B_or_.CE.B2_parameter_equation + +// BETA is the B value +// RS is the value of the series resistor in ohms +// R_INF is R0.exp(-BETA/T0), where R0 is the thermistor resistance at T0 (T0 is in kelvin) +// Normally T0 is 298.15K (25 C). If you write that expression in brackets in the #define the compiler +// should compute it for you (i.e. it won't need to be calculated at run time). + +// If the A->D converter has a range of 0..1023 and the measured voltage is V (between 0 and 1023) +// then the thermistor resistance, R = V.RS/(1023 - V) +// and the temperature, T = BETA/ln(R/R_INF) +// To get degrees celsius (instead of kelvin) add -273.15 to T + +// This DOES assume that all extruders use the same thermistor type. + +#define ABS_ZERO -273.15 +#define AD_RANGE 16383 + +// RS 198-961 +#define TH_BETA 3960.0 +#define TH_RS 4700 +#define TH_R_INF ( 100000.0*exp(-TH_BETA/298.15) ) + + + +