Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Heat.h « Heating « src - github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0862665a21536f2579d3fb1a80541f612f09bb56 (plain)
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() noexcept;

	// Methods that don't relate to a particular heater
	void HeaterTask() noexcept;
	void Init() noexcept;												// Set everything up
	void Exit() noexcept;												// Shut everything down
	void ResetHeaterModels() noexcept;									// Reset all active heater models to defaults

	bool ColdExtrude() const noexcept;									// Is cold extrusion allowed?
	void AllowColdExtrude(bool b) noexcept;								// Allow or deny cold extrusion
	float GetExtrusionMinTemp() const noexcept;							// Get minimum extrusion temperature
	float GetRetractionMinTemp() const noexcept;							// Get minimum retraction temperature
	void SetExtrusionMinTemp(float t) noexcept;							// Set minimum extrusion temperature
	void SetRetractionMinTemp(float t) noexcept;							// Set minimum retraction temperature

	int GetBedHeater(size_t index) const noexcept						// Get a hot bed heater number
	pre(index < NumBedHeaters);
	void SetBedHeater(size_t index, int heater)	 noexcept				// Set a hot bed heater number
	pre(index < NumBedHeaters; -1 <= heater; heater < MaxHeaters);
	bool IsBedHeater(int heater) const noexcept;							// Check if this heater is a bed heater

	int GetChamberHeater(size_t index) const noexcept					// Get a chamber heater number
	pre(index < NumChamberHeaters);
	void SetChamberHeater(size_t index, int heater)	 noexcept			// Set a chamber heater number
	pre(index < NumChamberHeaters; -1 <= heater; heater < MaxHeaters);
	bool IsChamberHeater(int heater) const noexcept;						// Check if this heater is a chamber heater

	bool AllHeatersAtSetTemperatures(bool includingBed, float tolerance) const noexcept;	// Is everything at temperature within tolerance?

	void SwitchOffAll(bool includingChamberAndBed) noexcept;				// Turn all heaters off
	GCodeResult ResetFault(int heater, const StringRef& reply) noexcept;	// Reset a heater fault for a specific heater or all heaters
	GCodeResult SetOrReportHeaterModel(GCodeBuffer& gb, const StringRef& reply) noexcept;
	GCodeResult TuneHeater(GCodeBuffer& gb, const StringRef& reply) noexcept;
	GCodeResult ConfigureSensor(GCodeBuffer& gb, const StringRef& reply) noexcept;	// Create a sensor or change the parameters for an existing sensor
	GCodeResult SetPidParameters(unsigned int heater, GCodeBuffer& gb, const StringRef& reply) noexcept; // Set the P/I/D parameters for a heater

	GCodeResult SetHeaterProtection(GCodeBuffer &gb, const StringRef &reply) noexcept;	// Configure heater protection (M143)
	void UpdateHeaterProtection(int heaterNumber) noexcept;				// Updates the PIDs and HeaterProtection items when a heater is remapped

	void SuspendHeaters(bool sus) noexcept;								// Suspend the heaters to conserve power

	void SensorsTask() noexcept;
	static void EnsureSensorsTask() noexcept;

	ReadLockedPointer<TemperatureSensor> FindSensor(int sn) const noexcept;	// Get a pointer to the temperature sensor entry
	ReadLockedPointer<TemperatureSensor> FindSensorAtOrAbove(unsigned int sn) const noexcept;	// Get a pointer to the first temperature sensor with the specified or higher number

	float GetSensorTemperature(int sensorNum, TemperatureError& err) const noexcept; // Result is in degrees Celsius

	float GetHighestTemperatureLimit() const noexcept;					// Get the highest temperature limit of any heater
	size_t GetHighestUsedHeaterNumber() const noexcept;

	void Diagnostics(MessageType mtype) noexcept;						// Output useful information

	// Methods that relate to a particular heater
	const char *GetHeaterSensorName(size_t heater) const noexcept;		// Get the name of the sensor associated with heater, or nullptr if it hasn't been named
	float GetAveragePWM(size_t heater) const noexcept					// Return the running average PWM to the heater as a fraction in [0, 1].
	pre(heater < MaxHeaters);

	bool IsBedOrChamberHeater(int heater) const noexcept;				// Queried by the Platform class

	float GetHeaterTemperature(size_t heater) const noexcept;			 // Result is in degrees Celsius

	const Tool* GetLastStandbyTool(int heater) const noexcept
	pre(heater >= 0; heater < MaxHeaters)
	{
		return lastStandbyTools[heater];
	}

	bool IsHeaterEnabled(size_t heater)	const noexcept;					// Is this heater enabled?
	pre(heater < MaxHeaters);

	float GetActiveTemperature(int heater) const noexcept;
	float GetStandbyTemperature(int heater) const noexcept;
	float GetHighestTemperatureLimit(int heater) const noexcept;
	float GetLowestTemperatureLimit(int heater) const noexcept;
	float GetHeaterTemperature(int heater) const noexcept;				// Get the current temperature of a heater
	float GetTargetTemperature(int heater) const noexcept;				// Get the target temperature
	HeaterStatus GetStatus(int heater) const noexcept;					// Get the off/standby/active status
	bool HeaterAtSetTemperature(int heater, bool waitWhenCooling, float tolerance) const noexcept;

	GCodeResult ConfigureHeater(size_t heater, GCodeBuffer& gb, const StringRef& reply) noexcept;
	GCodeResult ConfigureHeaterMonitoring(size_t heater, GCodeBuffer& gb, const StringRef& reply) noexcept;

	void SetActiveTemperature(int heater, float t) noexcept;
	void SetStandbyTemperature(int heater, float t) noexcept;
	GCodeResult Activate(int heater, const StringRef& reply) noexcept;	// Turn on a heater
	void Standby(int heater, const Tool* tool) noexcept;					// Set a heater to standby
	void SwitchOff(int heater) noexcept;									// Turn off a specific heater

#if HAS_MASS_STORAGE
	bool WriteModelParameters(FileStore *f) const noexcept;				// Write heater model parameters to file returning true if no error
	bool WriteBedAndChamberTempSettings(FileStore *f) const noexcept;	// Save some resume information
#endif

#if SUPPORT_CAN_EXPANSION
	void ProcessRemoteSensorsReport(CanAddress src, const CanMessageSensorTemperatures& msg) noexcept;
	void ProcessRemoteHeatersReport(CanAddress src, const CanMessageHeatersStatus& msg) noexcept;
#endif

protected:
	DECLARE_OBJECT_MODEL

private:
	Heat(const Heat&) = delete;									// Private copy constructor to prevent copying

	ReadLockedPointer<Heater> FindHeater(int heater) const noexcept;
	void DeleteSensor(unsigned int sn) noexcept;
	void InsertSensor(TemperatureSensor *newSensor) noexcept;

	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 noexcept
{
	return coldExtrude;
}

inline void Heat::AllowColdExtrude(bool b) noexcept
{
	coldExtrude = b;
}

inline float Heat::GetExtrusionMinTemp() const noexcept
{
	return extrusionMinTemp;
}

inline float Heat::GetRetractionMinTemp() const noexcept
{
	return retractionMinTemp;
}

inline void Heat::SetExtrusionMinTemp(float t) noexcept
{
	extrusionMinTemp = t;
}

inline void Heat::SetRetractionMinTemp(float t) noexcept
{
	retractionMinTemp = t;
}

inline int Heat::GetBedHeater(size_t index) const noexcept
{
	return bedHeaters[index];
}

inline int Heat::GetChamberHeater(size_t index) const noexcept
{
	return chamberHeaters[index];
}

#endif