Skip to content

Commit

Permalink
Started work on the slave controller code.
Browse files Browse the repository at this point in the history
  • Loading branch information
reprappro committed Aug 7, 2012
1 parent eb78750 commit 05c556d
Show file tree
Hide file tree
Showing 14 changed files with 453 additions and 80 deletions.
16 changes: 14 additions & 2 deletions Marlin/Marlin.h
Expand Up @@ -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

Expand All @@ -22,7 +26,7 @@


#include "fastio.h"
#include "Configuration.h"

#include "pins.h"

#if ARDUINO >= 100
Expand All @@ -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;
Expand Down
22 changes: 17 additions & 5 deletions Marlin/Marlin.pde
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

}


Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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];
Expand Down
9 changes: 9 additions & 0 deletions Marlin/MarlinSerial.cpp
Expand Up @@ -20,7 +20,12 @@
Modified 28 September 2010 by Mark Sproul
*/



#include "Marlin.h"

#ifndef REPRAPPRO_MULTIMATERIALS

#include "MarlinSerial.h"

#if MOTHERBOARD != 8 // !teensylu
Expand Down Expand Up @@ -324,6 +329,10 @@ void MarlinSerial::printFloat(double number, uint8_t digits)

MarlinSerial MSerial;

MarlinSerial MSerial1;

#endif // whole file
#endif //teensylu

#endif REPRAPPRO_MULTIMATERIALS

6 changes: 6 additions & 0 deletions Marlin/MarlinSerial.h
Expand Up @@ -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
Expand Down Expand Up @@ -145,6 +148,9 @@ class MarlinSerial //: public Stream
};

extern MarlinSerial MSerial;
extern MarlinSerial MSerial1;
#endif // ! teensylu

#endif

#endif // REPRAPPRO_MULTIMATERIALS
3 changes: 3 additions & 0 deletions Marlin/pins.h
Expand Up @@ -73,6 +73,7 @@
#define SDPOWER -1
#define SDSS 31


#endif

/****************************************************************************************
Expand Down Expand Up @@ -131,6 +132,8 @@
#define SDPOWER -1
#define SDSS 31

#define STEP_TOGGLE 16

#endif


Expand Down
16 changes: 16 additions & 0 deletions 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
66 changes: 66 additions & 0 deletions 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

4 changes: 3 additions & 1 deletion Marlin/stepper.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Marlin/stepper.h
Expand Up @@ -22,7 +22,7 @@
#define stepper_h

#include "planner.h"
#include "slave.h"
#include "slave_comms.h"

#ifdef REPRAPPRO_MULTIMATERIALS

Expand Down
14 changes: 8 additions & 6 deletions Marlin/temperature.cpp
Expand Up @@ -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
Expand All @@ -330,17 +331,18 @@ 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
if(e > 0) return analog2temp_remote(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);
Expand Down
2 changes: 1 addition & 1 deletion Marlin/temperature.h
Expand Up @@ -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.
Expand Down

0 comments on commit 05c556d

Please sign in to comment.