Temperature code all working with simple bang-bang control. PID next...
This commit is contained in:
parent
2d335eadf3
commit
ce7522f682
6 changed files with 96 additions and 18 deletions
2
GCodes.h
2
GCodes.h
|
@ -72,6 +72,7 @@ class GCodes
|
||||||
boolean SetUpMove(GCodeBuffer* gb);
|
boolean SetUpMove(GCodeBuffer* gb);
|
||||||
boolean DoDwell(GCodeBuffer *gb);
|
boolean DoDwell(GCodeBuffer *gb);
|
||||||
boolean DoHome();
|
boolean DoHome();
|
||||||
|
boolean SetOffsets(GCodeBuffer *gb);
|
||||||
boolean NoHome();
|
boolean NoHome();
|
||||||
boolean Push();
|
boolean Push();
|
||||||
boolean Pop();
|
boolean Pop();
|
||||||
|
@ -99,6 +100,7 @@ class GCodes
|
||||||
float distanceScale;
|
float distanceScale;
|
||||||
int fileBeingPrinted;
|
int fileBeingPrinted;
|
||||||
int fileToPrint;
|
int fileToPrint;
|
||||||
|
int8_t selectedHead;
|
||||||
boolean homeX;
|
boolean homeX;
|
||||||
boolean homeY;
|
boolean homeY;
|
||||||
boolean homeZ;
|
boolean homeZ;
|
||||||
|
|
28
GCodes.ino
28
GCodes.ino
|
@ -61,6 +61,7 @@ void GCodes::Init()
|
||||||
homeZQueued = false;
|
homeZQueued = false;
|
||||||
dwellWaiting = false;
|
dwellWaiting = false;
|
||||||
stackPointer = 0;
|
stackPointer = 0;
|
||||||
|
selectedHead = -1;
|
||||||
dwellTime = platform->Time();
|
dwellTime = platform->Time();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,6 +376,20 @@ boolean GCodes::DoDwell(GCodeBuffer *gb)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean GCodes::SetOffsets(GCodeBuffer *gb)
|
||||||
|
{
|
||||||
|
int8_t head;
|
||||||
|
if(gb->Seen('P'))
|
||||||
|
{
|
||||||
|
head = gb->GetIValue();
|
||||||
|
if(gb->Seen('R'))
|
||||||
|
platform->SetStandbyTemperature(head+1, gb->GetFValue());
|
||||||
|
if(gb->Seen('S'))
|
||||||
|
platform->SetActiveTemperature(head+1, gb->GetFValue());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// If the GCode to act on is completed, this returns true,
|
// If the GCode to act on is completed, this returns true,
|
||||||
// otherwise false. It is called repeatedly for a given
|
// otherwise false. It is called repeatedly for a given
|
||||||
// GCode until it returns true for that code.
|
// GCode until it returns true for that code.
|
||||||
|
@ -382,6 +397,7 @@ boolean GCodes::DoDwell(GCodeBuffer *gb)
|
||||||
boolean GCodes::ActOnGcode(GCodeBuffer *gb)
|
boolean GCodes::ActOnGcode(GCodeBuffer *gb)
|
||||||
{
|
{
|
||||||
int code;
|
int code;
|
||||||
|
float value;
|
||||||
boolean result = true;
|
boolean result = true;
|
||||||
|
|
||||||
if(gb->Seen('G'))
|
if(gb->Seen('G'))
|
||||||
|
@ -399,7 +415,7 @@ boolean GCodes::ActOnGcode(GCodeBuffer *gb)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 10: // Set offsets
|
case 10: // Set offsets
|
||||||
platform->Message(HOST_MESSAGE, "Set offsets received\n");
|
result = SetOffsets(gb);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 20: // Inches (which century are we living in, here?)
|
case 20: // Inches (which century are we living in, here?)
|
||||||
|
@ -518,7 +534,8 @@ boolean GCodes::ActOnGcode(GCodeBuffer *gb)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 140: // Set bed temperature
|
case 140: // Set bed temperature
|
||||||
platform->Message(HOST_MESSAGE, "Set bed temp received\n");
|
if(gb->Seen('S'))
|
||||||
|
reprap.GetHeat()->SetTemperature(0, gb->GetFValue());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 141: // Chamber temperature
|
case 141: // Chamber temperature
|
||||||
|
@ -539,9 +556,14 @@ boolean GCodes::ActOnGcode(GCodeBuffer *gb)
|
||||||
boolean ok = false;
|
boolean ok = false;
|
||||||
for(int8_t i = AXES; i < DRIVES; i++)
|
for(int8_t i = AXES; i < DRIVES; i++)
|
||||||
{
|
{
|
||||||
|
if(selectedHead == i - AXES)
|
||||||
|
{
|
||||||
|
reprap.GetHeat()->SetTemperature(selectedHead+1, platform->StandbyTemperature(selectedHead+1));
|
||||||
|
}
|
||||||
if(code == i - AXES)
|
if(code == i - AXES)
|
||||||
{
|
{
|
||||||
platform->Message(HOST_MESSAGE, "Tool selection received\n");
|
reprap.GetHeat()->SetTemperature(code+1, platform->ActiveTemperature(code+1));
|
||||||
|
selectedHead = code;
|
||||||
ok = true;
|
ok = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
10
Heat.h
10
Heat.h
|
@ -28,7 +28,7 @@ class PID
|
||||||
PID(Platform* p, int8_t h);
|
PID(Platform* p, int8_t h);
|
||||||
void Init();
|
void Init();
|
||||||
void Spin();
|
void Spin();
|
||||||
void SetTemperature(float t);
|
void SetTemperature(const float& t);
|
||||||
float GetTemperature();
|
float GetTemperature();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -48,6 +48,7 @@ class Heat
|
||||||
void Spin();
|
void Spin();
|
||||||
void Init();
|
void Init();
|
||||||
void Exit();
|
void Exit();
|
||||||
|
void SetTemperature(int8_t heater, const float& t);
|
||||||
float GetTemperature(int8_t heater);
|
float GetTemperature(int8_t heater);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -62,7 +63,7 @@ class Heat
|
||||||
|
|
||||||
//***********************************************************************************************************
|
//***********************************************************************************************************
|
||||||
|
|
||||||
inline void PID::SetTemperature(float t)
|
inline void PID::SetTemperature(const float& t)
|
||||||
{
|
{
|
||||||
setTemperature = t;
|
setTemperature = t;
|
||||||
}
|
}
|
||||||
|
@ -72,6 +73,11 @@ inline float PID::GetTemperature()
|
||||||
return temperature;
|
return temperature;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void Heat::SetTemperature(int8_t heater, const float& t)
|
||||||
|
{
|
||||||
|
pids[heater]->SetTemperature(t);
|
||||||
|
}
|
||||||
|
|
||||||
inline float Heat::GetTemperature(int8_t heater)
|
inline float Heat::GetTemperature(int8_t heater)
|
||||||
{
|
{
|
||||||
return pids[heater]->GetTemperature();
|
return pids[heater]->GetTemperature();
|
||||||
|
|
14
Heat.ino
14
Heat.ino
|
@ -68,10 +68,20 @@ PID::PID(Platform* p, int8_t h)
|
||||||
|
|
||||||
void PID::Init()
|
void PID::Init()
|
||||||
{
|
{
|
||||||
temperature = 5*(heater + 1);
|
temperature = platform->GetTemperature(heater);
|
||||||
|
setTemperature = 0.0;
|
||||||
|
platform->SetHeater(heater, -1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PID::Spin()
|
void PID::Spin()
|
||||||
{
|
{
|
||||||
temperature += 1;
|
temperature = platform->GetTemperature(heater);
|
||||||
|
if(!platform->UsePID(heater))
|
||||||
|
{
|
||||||
|
if(temperature < setTemperature)
|
||||||
|
platform->SetHeater(heater, 1.0);
|
||||||
|
else
|
||||||
|
platform->SetHeater(heater, 0.0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
51
Platform.h
51
Platform.h
|
@ -76,10 +76,10 @@ Licence: GPL
|
||||||
#define LOW_STOP_PINS {3, 14, 17, -1}
|
#define LOW_STOP_PINS {3, 14, 17, -1}
|
||||||
#define HIGH_STOP_PINS {-1, -1, -1, -1}
|
#define HIGH_STOP_PINS {-1, -1, -1, -1}
|
||||||
#define ENDSTOP_HIT 1 // when a stop == this it is hit
|
#define ENDSTOP_HIT 1 // when a stop == this it is hit
|
||||||
#define MAX_FEEDRATES {300, 300, 3, 45} // mm/sec
|
#define MAX_FEEDRATES {300.0, 300.0, 3.0, 45.0} // mm/sec
|
||||||
#define ACCELERATIONS {800, 800, 30, 250} // mm/sec^2??
|
#define ACCELERATIONS {800.0, 800.0, 30.0, 250.0} // mm/sec^2??
|
||||||
//#define ACCELERATIONS {80, 80, 3, 25}
|
//#define ACCELERATIONS {80, 80, 3, 25}
|
||||||
#define DRIVE_STEPS_PER_UNIT {91.4286, 91.4286, 4000, 929}
|
#define DRIVE_STEPS_PER_UNIT {91.4286, 91.4286, 4000.0, 929.0}
|
||||||
#define INSTANT_DVS {15.0, 15.0, 0.4, 15.0} // (mm/sec)
|
#define INSTANT_DVS {15.0, 15.0, 0.4, 15.0} // (mm/sec)
|
||||||
#define GCODE_LETTERS { 'X', 'Y', 'Z', 'E', 'F' } // The drives and feedrate in a GCode
|
#define GCODE_LETTERS { 'X', 'Y', 'Z', 'E', 'F' } // The drives and feedrate in a GCode
|
||||||
|
|
||||||
|
@ -87,8 +87,9 @@ Licence: GPL
|
||||||
|
|
||||||
#define START_FEED_RATE 200.0
|
#define START_FEED_RATE 200.0
|
||||||
|
|
||||||
#define AXIS_LENGTHS {210, 210, 120} // mm
|
#define AXIS_LENGTHS {210, 200, 120} // mm
|
||||||
#define HOME_FEEDRATES {50*60, 50*60, 1*60} // mm/min
|
#define HOME_FEEDRATES {50.0*60.0, 50.0*60.0, 1.0*60.0} // mm/min
|
||||||
|
#define HEAD_OFFSETS {0.0, 0.0, 0.0}
|
||||||
|
|
||||||
#define X_AXIS 0 // The index of the X axis
|
#define X_AXIS 0 // The index of the X axis
|
||||||
#define Y_AXIS 1 // The index of the Y axis
|
#define Y_AXIS 1 // The index of the Y axis
|
||||||
|
@ -102,12 +103,14 @@ Licence: GPL
|
||||||
#define THERMISTOR_BETAS {3480.0, 3960.0} // Bed thermistor: RS 484-0149; EPCOS B57550G103J; Extruder thermistor: RS 198-961
|
#define THERMISTOR_BETAS {3480.0, 3960.0} // Bed thermistor: RS 484-0149; EPCOS B57550G103J; Extruder thermistor: RS 198-961
|
||||||
#define THERMISTOR_SERIES_RS {4700, 4700} // Ohms in series with the thermistors
|
#define THERMISTOR_SERIES_RS {4700, 4700} // Ohms in series with the thermistors
|
||||||
#define THERMISTOR_25_RS {10000.0, 100000.0} // Thermistor ohms at 25 C = 298.15 K
|
#define THERMISTOR_25_RS {10000.0, 100000.0} // Thermistor ohms at 25 C = 298.15 K
|
||||||
#define USE_PID {false, true} // PID or bang-bang for this heater?
|
#define USE_PID {false, false} // PID or bang-bang for this heater?
|
||||||
#define PID_KIS {-1, 100} // PID constants...
|
#define PID_KIS {-1, 100} // PID constants...
|
||||||
#define PID_KDS {-1, 100}
|
#define PID_KDS {-1, 100}
|
||||||
#define PID_KPS {-1, 100}
|
#define PID_KPS {-1, 100}
|
||||||
#define PID_I_LIMITS {-1, 100} // ... to here
|
#define PID_I_LIMITS {-1, 100} // ... to here
|
||||||
#define TEMP_INTERVAL 0.5 // secs - check and control temperatures this often
|
#define TEMP_INTERVAL 0.5 // secs - check and control temperatures this often
|
||||||
|
#define STANDBY_TEMPERATURES {0.0, 0.0} // We specify one for the bed, though it's not needed
|
||||||
|
#define ACTIVE_TEMPERATURES {0.0, 0.0}
|
||||||
|
|
||||||
#define AD_RANGE 1023.0//16383 // The A->D converter that measures temperatures gives an int this big as its max value
|
#define AD_RANGE 1023.0//16383 // The A->D converter that measures temperatures gives an int this big as its max value
|
||||||
|
|
||||||
|
@ -253,11 +256,15 @@ class Platform
|
||||||
|
|
||||||
float GetTemperature(int8_t heater); // Result is in degrees celsius
|
float GetTemperature(int8_t heater); // Result is in degrees celsius
|
||||||
void SetHeater(int8_t heater, const float& power); // power is a fraction in [0,1]
|
void SetHeater(int8_t heater, const float& power); // power is a fraction in [0,1]
|
||||||
|
void SetStandbyTemperature(int8_t heater, const float& t);
|
||||||
|
void SetActiveTemperature(int8_t heater, const float& t);
|
||||||
|
float StandbyTemperature(int8_t heater);
|
||||||
|
float ActiveTemperature(int8_t heater);
|
||||||
float pidKp(int8_t heater);
|
float pidKp(int8_t heater);
|
||||||
float pidKi(int8_t heater);
|
float pidKi(int8_t heater);
|
||||||
float pidKd(int8_t heater);
|
float pidKd(int8_t heater);
|
||||||
float pidKw(int8_t heater);
|
float pidKw(int8_t heater);
|
||||||
boolean pidBangBang(int8_t heater);
|
boolean UsePID(int8_t heater);
|
||||||
float HeatSampleTime();
|
float HeatSampleTime();
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------------
|
||||||
|
@ -297,6 +304,7 @@ class Platform
|
||||||
|
|
||||||
float axisLengths[AXES];
|
float axisLengths[AXES];
|
||||||
float homeFeedrates[AXES];
|
float homeFeedrates[AXES];
|
||||||
|
float headOffsets[AXES]; // FIXME - needs a 2D array
|
||||||
|
|
||||||
// HEATERS - Bed is assumed to be the first
|
// HEATERS - Bed is assumed to be the first
|
||||||
|
|
||||||
|
@ -305,12 +313,14 @@ class Platform
|
||||||
float thermistorBetas[HEATERS];
|
float thermistorBetas[HEATERS];
|
||||||
float thermistorSeriesRs[HEATERS];
|
float thermistorSeriesRs[HEATERS];
|
||||||
float thermistorInfRs[HEATERS];
|
float thermistorInfRs[HEATERS];
|
||||||
boolean usePid[HEATERS];
|
boolean usePID[HEATERS];
|
||||||
float pidKis[HEATERS];
|
float pidKis[HEATERS];
|
||||||
float pidKds[HEATERS];
|
float pidKds[HEATERS];
|
||||||
float pidKps[HEATERS];
|
float pidKps[HEATERS];
|
||||||
float pidILimits[HEATERS];
|
float pidILimits[HEATERS];
|
||||||
float heatSampleTime;
|
float heatSampleTime;
|
||||||
|
float standbyTemperatures[HEATERS];
|
||||||
|
float activeTemperatures[HEATERS];
|
||||||
|
|
||||||
// Files
|
// Files
|
||||||
|
|
||||||
|
@ -444,6 +454,31 @@ inline float Platform::HeatSampleTime()
|
||||||
return heatSampleTime;
|
return heatSampleTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline boolean Platform::UsePID(int8_t heater)
|
||||||
|
{
|
||||||
|
return usePID[heater];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void Platform::SetStandbyTemperature(int8_t heater, const float& t)
|
||||||
|
{
|
||||||
|
standbyTemperatures[heater] = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void Platform::SetActiveTemperature(int8_t heater, const float& t)
|
||||||
|
{
|
||||||
|
activeTemperatures[heater] = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline float Platform::StandbyTemperature(int8_t heater)
|
||||||
|
{
|
||||||
|
return standbyTemperatures[heater];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline float Platform::ActiveTemperature(int8_t heater)
|
||||||
|
{
|
||||||
|
return activeTemperatures[heater];
|
||||||
|
}
|
||||||
|
|
||||||
//*********************************************************************************************************
|
//*********************************************************************************************************
|
||||||
|
|
||||||
// Interrupts
|
// Interrupts
|
||||||
|
|
|
@ -90,6 +90,7 @@ void Platform::Init()
|
||||||
|
|
||||||
axisLengths = AXIS_LENGTHS;
|
axisLengths = AXIS_LENGTHS;
|
||||||
homeFeedrates = HOME_FEEDRATES;
|
homeFeedrates = HOME_FEEDRATES;
|
||||||
|
headOffsets = HEAD_OFFSETS;
|
||||||
|
|
||||||
// HEATERS - Bed is assumed to be the first
|
// HEATERS - Bed is assumed to be the first
|
||||||
|
|
||||||
|
@ -98,7 +99,7 @@ void Platform::Init()
|
||||||
thermistorBetas = THERMISTOR_BETAS;
|
thermistorBetas = THERMISTOR_BETAS;
|
||||||
thermistorSeriesRs = THERMISTOR_SERIES_RS;
|
thermistorSeriesRs = THERMISTOR_SERIES_RS;
|
||||||
thermistorInfRs = THERMISTOR_25_RS;
|
thermistorInfRs = THERMISTOR_25_RS;
|
||||||
usePid = USE_PID;
|
usePID = USE_PID;
|
||||||
pidKis = PID_KIS;
|
pidKis = PID_KIS;
|
||||||
pidKds = PID_KDS;
|
pidKds = PID_KDS;
|
||||||
pidKps = PID_KPS;
|
pidKps = PID_KPS;
|
||||||
|
@ -108,6 +109,8 @@ void Platform::Init()
|
||||||
sysDir = SYS_DIR;
|
sysDir = SYS_DIR;
|
||||||
tempDir = TEMP_DIR;
|
tempDir = TEMP_DIR;
|
||||||
heatSampleTime = HEAT_SAMPLE_TIME;
|
heatSampleTime = HEAT_SAMPLE_TIME;
|
||||||
|
standbyTemperatures = STANDBY_TEMPERATURES;
|
||||||
|
activeTemperatures = ACTIVE_TEMPERATURES;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0; i < DRIVES; i++)
|
for(i = 0; i < DRIVES; i++)
|
||||||
|
@ -238,7 +241,7 @@ float Platform::GetTemperature(int8_t heater)
|
||||||
|
|
||||||
void Platform::SetHeater(int8_t heater, const float& power)
|
void Platform::SetHeater(int8_t heater, const float& power)
|
||||||
{
|
{
|
||||||
if(power <= 0)
|
if(power <= 0.0)
|
||||||
{
|
{
|
||||||
digitalWrite(heatOnPins[heater], 0);
|
digitalWrite(heatOnPins[heater], 0);
|
||||||
return;
|
return;
|
||||||
|
|
Reference in a new issue