blob: 1664b3d36c1a2d18639f51ed0bde30b072765905 (
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
|
/*
* PulsedFilamentSensor.h
*
* Created on: 9 Jan 2018
* Author: David
*/
#ifndef SRC_FILAMENTSENSORS_PULSEDFILAMENTMONITOR_H_
#define SRC_FILAMENTSENSORS_PULSEDFILAMENTMONITOR_H_
#include "FilamentMonitor.h"
class PulsedFilamentMonitor : public FilamentMonitor
{
public:
PulsedFilamentMonitor(unsigned int extruder, unsigned int type);
bool Configure(GCodeBuffer& gb, const StringRef& reply, bool& seen) override;
FilamentSensorStatus Check(bool isPrinting, bool fromIsr, uint32_t isrMillis, float filamentConsumed) override;
FilamentSensorStatus Clear() override;
void Diagnostics(MessageType mtype, unsigned int extruder) override;
bool Interrupt() override;
private:
static constexpr float DefaultMmPerPulse = 1.0;
static constexpr float DefaultMinMovementAllowed = 0.6;
static constexpr float DefaultMaxMovementAllowed = 1.6;
static constexpr float DefaultMinimumExtrusionCheckLength = 5.0;
void Init();
void Reset();
void Poll();
FilamentSensorStatus CheckFilament(float amountCommanded, float amountMeasured, bool overdue);
// Configuration parameters
float mmPerPulse;
float minMovementAllowed, maxMovementAllowed;
float minimumExtrusionCheckLength;
bool comparisonEnabled;
// Other data
uint32_t sensorValue; // how many pulses received
uint32_t lastIsrTime; // the time we recorded an interrupt
uint32_t lastSyncTime; // the last time we synced a measurement
uint32_t lastMeasurementTime; // the last time we received a value
float extrusionCommandedAtInterrupt; // the amount of extrusion commanded (mm) when we received the interrupt since the last sync
float extrusionCommandedSinceLastSync; // the amount of extrusion commanded (mm) since the last sync
float movementMeasuredSinceLastSync; // the amount of movement in complete rotations of the wheel since the last sync
bool wasPrintingAtInterrupt;
bool haveInterruptData;
float extrusionCommandedThisSegment; // the amount of extrusion commanded (mm) since we last did a comparison
float movementMeasuredThisSegment; // the accumulated movement in complete rotations since the previous comparison
// Values measured for calibration
float minMovementRatio, maxMovementRatio;
float totalExtrusionCommanded;
float totalMovementMeasured;
uint8_t samplesReceived;
bool comparisonStarted;
bool calibrationStarted;
};
#endif /* SRC_FILAMENTSENSORS_PULSEDFILAMENTMONITOR_H_ */
|