1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
/****************************************************************************************************
RepRapFirmware - Heat
This is all the code to deal with heat and temperature.
-----------------------------------------------------------------------------------------------------
Version 0.1
18 November 2012
Adrian Bowyer
RepRap Professional Ltd
http://reprappro.com
Licence: GPL
****************************************************************************************************/
#ifndef HEAT_H
#define HEAT_H
/**
* The master class that controls all the heaters in the RepRap machine
*/
#include "RepRapFirmware.h"
#include "RepRap.h"
#include "Heater.h"
#include "TemperatureError.h"
#include "MessageType.h"
#include "GCodes/GCodeResult.h"
#include <RTOSIface/RTOSIface.h>
class TemperatureSensor;
class HeaterProtection;
class GCodeBuffer;
class CanMessageSensorTemperatures;
class CanMessageHeatersStatus;
class Heat INHERIT_OBJECT_MODEL
{
public:
Heat();
// Methods that don't relate to a particular heater
void HeaterTask();
void Init(); // Set everything up
void Exit(); // Shut everything down
void ResetHeaterModels(); // Reset all active heater models to defaults
bool ColdExtrude() const; // Is cold extrusion allowed?
void AllowColdExtrude(bool b); // Allow or deny cold extrusion
float GetExtrusionMinTemp() const; // Get minimum extrusion temperature
float GetRetractionMinTemp() const; // Get minimum retraction temperature
void SetExtrusionMinTemp(float t); // Set minimum extrusion temperature
void SetRetractionMinTemp(float t); // Set minimum retraction temperature
int GetBedHeater(size_t index) const // Get a hot bed heater number
pre(index < NumBedHeaters);
void SetBedHeater(size_t index, int heater) // Set a hot bed heater number
pre(index < NumBedHeaters; -1 <= heater; heater < MaxHeaters);
bool IsBedHeater(int heater) const; // Check if this heater is a bed heater
int GetChamberHeater(size_t index) const // Get a chamber heater number
pre(index < NumChamberHeaters);
void SetChamberHeater(size_t index, int heater) // Set a chamber heater number
pre(index < NumChamberHeaters; -1 <= heater; heater < MaxHeaters);
bool IsChamberHeater(int heater) const; // Check if this heater is a chamber heater
bool AllHeatersAtSetTemperatures(bool includingBed, float tolerance) const; // Is everything at temperature within tolerance?
void SwitchOffAll(bool includingChamberAndBed); // Turn all heaters off
GCodeResult ResetFault(int heater, const StringRef& reply); // Reset a heater fault for a specific heater or all heaters
GCodeResult SetOrReportHeaterModel(GCodeBuffer& gb, const StringRef& reply);
GCodeResult TuneHeater(GCodeBuffer& gb, const StringRef& reply);
GCodeResult ConfigureSensor(GCodeBuffer& gb, const StringRef& reply); // Create a sensor or change the parameters for an existing sensor
GCodeResult SetPidParameters(unsigned int heater, GCodeBuffer& gb, const StringRef& reply); // Set the P/I/D parameters for a heater
GCodeResult SetHeaterProtection(GCodeBuffer &gb, const StringRef &reply); // Configure heater protection (M143)
void UpdateHeaterProtection(int heaterNumber); // Updates the PIDs and HeaterProtection items when a heater is remapped
void SuspendHeaters(bool sus); // Suspend the heaters to conserve power
void SensorsTask();
static void EnsureSensorsTask();
ReadLockedPointer<TemperatureSensor> FindSensor(int sn) const; // Get a pointer to the temperature sensor entry
ReadLockedPointer<TemperatureSensor> FindSensorAtOrAbove(unsigned int sn) const; // Get a pointer to the first temperature sensor with the specified or higher number
float GetSensorTemperature(int sensorNum, TemperatureError& err) const; // Result is in degrees Celsius
float GetHighestTemperatureLimit() const; // Get the highest temperature limit of any heater
size_t GetHighestUsedHeaterNumber() const;
void Diagnostics(MessageType mtype); // Output useful information
// Methods that relate to a particular heater
const char *GetHeaterSensorName(size_t heater) const; // Get the name of the sensor associated with heater, or nullptr if it hasn't been named
float GetAveragePWM(size_t heater) const // Return the running average PWM to the heater as a fraction in [0, 1].
pre(heater < MaxHeaters);
bool IsBedOrChamberHeater(int heater) const; // Queried by the Platform class
float GetHeaterTemperature(size_t heater) const; // Result is in degrees Celsius
const Tool* GetLastStandbyTool(int heater) const
pre(heater >= 0; heater < MaxHeaters)
{
return lastStandbyTools[heater];
}
bool IsHeaterEnabled(size_t heater) const; // Is this heater enabled?
pre(heater < MaxHeaters);
float GetActiveTemperature(int heater) const;
float GetStandbyTemperature(int heater) const;
float GetHighestTemperatureLimit(int heater) const;
float GetLowestTemperatureLimit(int heater) const;
float GetHeaterTemperature(int heater) const; // Get the current temperature of a heater
float GetTargetTemperature(int heater) const; // Get the target temperature
HeaterStatus GetStatus(int heater) const; // Get the off/standby/active status
bool HeaterAtSetTemperature(int heater, bool waitWhenCooling, float tolerance) const;
GCodeResult ConfigureHeater(size_t heater, GCodeBuffer& gb, const StringRef& reply);
GCodeResult ConfigureHeaterMonitoring(size_t heater, GCodeBuffer& gb, const StringRef& reply);
void SetActiveTemperature(int heater, float t);
void SetStandbyTemperature(int heater, float t);
GCodeResult Activate(int heater, const StringRef& reply); // Turn on a heater
void Standby(int heater, const Tool* tool); // Set a heater to standby
void SwitchOff(int heater); // Turn off a specific heater
#if HAS_MASS_STORAGE
bool WriteModelParameters(FileStore *f) const; // Write heater model parameters to file returning true if no error
bool WriteBedAndChamberTempSettings(FileStore *f) const; // Save some resume information
#endif
#if SUPPORT_CAN_EXPANSION
void ProcessRemoteSensorsReport(CanAddress src, const CanMessageSensorTemperatures& msg);
void ProcessRemoteHeatersReport(CanAddress src, const CanMessageHeatersStatus& msg);
#endif
protected:
DECLARE_OBJECT_MODEL
private:
Heat(const Heat&) = delete; // Private copy constructor to prevent copying
ReadLockedPointer<Heater> FindHeater(int heater) const;
void DeleteSensor(unsigned int sn);
void InsertSensor(TemperatureSensor *newSensor);
static ReadWriteLock heatersLock;
static ReadWriteLock sensorsLock;
uint8_t volatile sensorCount;
TemperatureSensor * volatile sensorsRoot; // The sensor list
HeaterProtection *heaterProtections[MaxHeaters + MaxExtraHeaterProtections]; // Heater protection instances to guarantee legal heater temperature ranges
Heater* heaters[MaxHeaters]; // A local or remote heater
const Tool* lastStandbyTools[MaxHeaters]; // The last tool that caused the corresponding heater to be set to standby
float extrusionMinTemp; // Minimum temperature to allow regular extrusion
float retractionMinTemp; // Minimum temperature to allow regular retraction
bool coldExtrude; // Is cold extrusion allowed?
int8_t bedHeaters[MaxBedHeaters]; // Indices of the hot bed heaters to use or -1 if none is available
int8_t chamberHeaters[MaxChamberHeaters]; // Indices of the chamber heaters to use or -1 if none is available
int8_t heaterBeingTuned; // which PID is currently being tuned
int8_t lastHeaterTuned; // which PID we last finished tuning
};
//***********************************************************************************************************
inline bool Heat::ColdExtrude() const
{
return coldExtrude;
}
inline void Heat::AllowColdExtrude(bool b)
{
coldExtrude = b;
}
inline float Heat::GetExtrusionMinTemp() const
{
return extrusionMinTemp;
}
inline float Heat::GetRetractionMinTemp() const
{
return retractionMinTemp;
}
inline void Heat::SetExtrusionMinTemp(float t)
{
extrusionMinTemp = t;
}
inline void Heat::SetRetractionMinTemp(float t)
{
retractionMinTemp = t;
}
inline int Heat::GetBedHeater(size_t index) const
{
return bedHeaters[index];
}
inline int Heat::GetChamberHeater(size_t index) const
{
return chamberHeaters[index];
}
#endif
|