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

Grid.h « BedProbing « Movement « src - github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6ce5b742afbea30aefaaa69fa170e5966ed6cf2b (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
/*
 * Grid.h
 *
 *  Created on: 18 Nov 2016
 *      Author: David
 */

#ifndef SRC_MOVEMENT_GRID_H_
#define SRC_MOVEMENT_GRID_H_

#include "RepRapFirmware.h"
#include "ObjectModel/ObjectModel.h"

class DataTransfer;
class Deviation;

// This class defines the bed probing grid
class GridDefinition INHERIT_OBJECT_MODEL
{
public:
	friend class DataTransfer;
	friend class HeightMap;

	GridDefinition() noexcept;

	char GetAxisLetter(size_t axis) const noexcept pre(axis < 2) { return letters[axis]; }
	uint8_t GetAxisNumber(size_t axis) const noexcept pre(axis < 2) { return axisNumbers[axis]; }
	float GetMin(size_t axis) const noexcept pre(axis < 2) { return mins[axis]; }
	float GetMax(size_t axis) const noexcept pre(axis < 2) { return maxs[axis]; }
	float GetSpacing(size_t axis) const noexcept pre(axis < 2) { return spacings[axis]; }

	uint32_t NumAxisPoints(size_t axis) const noexcept pre(axis < 2) { return nums[axis]; }
	uint32_t NumPoints() const noexcept { return nums[0] * nums[1]; }
	float GetCoordinate(size_t axis, size_t coordinateIndex) pre(axis < 2) const noexcept { return mins[axis] + (coordinateIndex * spacings[axis]); }
	bool IsInRadius(float x, float y) const noexcept;
	bool IsValid() const noexcept { return isValid; }

	bool Set(const char axisLetters[2], const float axis0Range[2], const float axis1Range[2], float pRadius, const float pSpacings[2]) noexcept;
	void PrintParameters(const StringRef& r) const noexcept;
	void WriteHeadingAndParameters(const StringRef& r) const noexcept;
	static int CheckHeading(const StringRef& s) noexcept;
	bool ReadParameters(const StringRef& s, int version) noexcept;

	void PrintError(float originalXrange, float originalYrange, const StringRef& r) const noexcept
	pre(!IsValid());

protected:
	DECLARE_OBJECT_MODEL

private:
	void CheckValidity() noexcept;

	static constexpr float MinSpacing = 0.1;						// The minimum point spacing allowed
	static constexpr float MinRange = 1.0;							// The minimum X and Y range allowed
	static const char * const HeightMapLabelLines[];				// The line we write to the height map file listing the parameter names

	// Primary parameters
	char letters[2];												// Axis letters for this grid
	float mins[2], maxs[2];											// The edges of the grid for G29 probing
	float radius;													// The grid radius to probe
	float spacings[2];												// The spacings of the grid probe points

	// Derived parameters
	uint8_t axisNumbers[2];											// Axis numbers for this grid
	uint32_t nums[2];												// Number of probe points in each direction
	float recipAxisSpacings[2];										// Reciprocals of the axis spacings
	bool isValid;
};

// Class to represent the height map
class HeightMap
{
public:
	HeightMap() noexcept;

	const GridDefinition& GetGrid() const noexcept { return def; }
	void SetGrid(const GridDefinition& gd) noexcept;

	float GetInterpolatedHeightError(float axis0, float axis1) const noexcept;			// Compute the interpolated height error at the specified point
	void ClearGridHeights() noexcept;													// Clear all grid height corrections
	void SetGridHeight(size_t axis0Index, size_t axis1Index, float height) noexcept;	// Set the height of a grid point
	void SetGridHeight(size_t index, float height) noexcept;							// Set the height of a grid point

#if HAS_MASS_STORAGE
	bool SaveToFile(FileStore *f, const char *fname, float zOffset) noexcept	// Save the grid to file returning true if an error occurred
	pre(IsValid());
	bool LoadFromFile(FileStore *f, const char *fname, const StringRef& r) noexcept;	// Load the grid from file returning true if an error occurred
#endif

#if HAS_MASS_STORAGE || HAS_LINUX_INTERFACE
	const char *GetFileName() const noexcept { return fileName.c_str(); }
#endif

#if HAS_LINUX_INTERFACE
	void SetFileName(const char *name) noexcept;								// Update the filename
	void SaveToArray(float *array, float zOffset) const noexcept				// Save the grid Z coordinates to an array
	pre(IsValid());
#endif

	unsigned int GetMinimumSegments(float deltaAxis0, float deltaAxis1) const noexcept;	// Return the minimum number of segments for a move by this X or Y amount

	bool UseHeightMap(bool b) noexcept;
	bool UsingHeightMap() const noexcept { return useMap; }

	unsigned int GetStatistics(Deviation& deviation, float& minError, float& maxError) const noexcept;
																	// Return number of points probed, mean and RMS deviation, min and max error
	void ExtrapolateMissing() noexcept;								// Extrapolate missing points to ensure consistency

private:
	static const char * const HeightMapComment;						// The start of the comment we write at the start of the height map file

	GridDefinition def;
	float gridHeights[MaxGridProbePoints];							// The Z coordinates of the points on the bed that were probed
	LargeBitmap<MaxGridProbePoints> gridHeightSet;					// Bitmap of which heights are set
#if HAS_MASS_STORAGE || HAS_LINUX_INTERFACE
	String<MaxFilenameLength> fileName;								// The name of the file that this height map was loaded from or saved to
#endif
	bool useMap;													// True to do bed compensation

	uint32_t GetMapIndex(uint32_t axis0Index, uint32_t axis1Index) const noexcept { return (axis1Index * def.NumAxisPoints(0)) + axis0Index; }

	float InterpolateAxis0Axis1(uint32_t axis0Index, uint32_t axis1Index, float axis0Frac, float axis1Frac) const noexcept;
};

#endif /* SRC_MOVEMENT_GRID_H_ */