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

HeightController.h « HeightControl « Movement « src - github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c9d243fb99074badb6f55dcdb51da6c68f113d4e (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
/*
 * HeightController.h
 *
 *  Created on: 18 Apr 2019
 *      Author: David
 */

#ifndef SRC_MOVEMENT_HEIGHTCONTROL_HEIGHTCONTROLLER_H_
#define SRC_MOVEMENT_HEIGHTCONTROL_HEIGHTCONTROLLER_H_

#include <RepRapFirmware.h>

#if SUPPORT_ASYNC_MOVES

#include <RTOSIface/RTOSIface.h>

class HeightController
{
public:
	HeightController() noexcept;

	GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeException);
	GCodeResult StartHeightFollowing(GCodeBuffer& gb, const StringRef& reply) noexcept;		// Start/stop height following
	void Stop() noexcept;							// stop height following mode

	[[noreturn]] void RunTask() noexcept;

private:
	void CalcDerivedValues() noexcept;

	static constexpr unsigned int HeightControllerTaskStackWords = 100;
	static constexpr uint32_t DefaultSampleInterval = 200;

	Task<HeightControllerTaskStackWords> *heightControllerTask;
	int sensorNumber;								// which sensor, normally a virtual heater, or -1 if not configured
	uint32_t sampleInterval;						// in milliseconds
	uint32_t lastWakeTime;
	float setPoint;									// the sensor output we are aiming for
	float lastReading;								// the last reading we took from the sensor
	float pidP;
	float configuredPidI, configuredPidD;			// the PID parameters
	float actualPidI, actualPidD;
	float iAccumulator;								// the integral PID component
	float zMin, zMax;								// the control limits
	float currentZ;
	float startSpeed;
	float maxSpeed;
	float acceleration;
	float maxZAdjustmentPerSample;					// how much Z adjustment is possible in one sample period

	enum class PidState : uint8_t
	{
		stopped,
		starting,
		running
	};

	volatile PidState state;						// volatile because it is accessed by more than one task
	bool lastReadingOk;
};

#endif

#endif /* SRC_MOVEMENT_HEIGHTCONTROL_HEIGHTCONTROLLER_H_ */