forked from reprappro/RepRapFirmware
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTool.cpp
More file actions
170 lines (147 loc) · 4.23 KB
/
Copy pathTool.cpp
File metadata and controls
170 lines (147 loc) · 4.23 KB
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
/****************************************************************************************************
RepRapFirmware - Tool
This class implements a tool in the RepRap machine, usually (though not necessarily) an extruder.
Tools may have zero or more drives associated with them and zero or more heaters. There are a fixed number
of tools in a given RepRap, with fixed heaters and drives. All this is specified on reboot, and cannot
be altered dynamically. This restriction may be lifted in the future. Tool descriptions are stored in
GCode macros that are loaded on reboot.
-----------------------------------------------------------------------------------------------------
Version 0.1
Created on: Apr 11, 2014
Adrian Bowyer
RepRap Professional Ltd
http://reprappro.com
Licence: GPL
****************************************************************************************************/
#include "RepRapFirmware.h"
Tool::Tool(int toolNumber, long d[], int dCount, long h[], int hCount)
{
myNumber = toolNumber;
next = NULL;
active = false;
driveCount = dCount;
heaterCount = hCount;
if(driveCount > 0)
{
if(driveCount > DRIVES - AXES)
{
reprap.GetPlatform()->Message(HOST_MESSAGE, "Tool creation: attempt to use more drives than there are in the RepRap...");
driveCount = 0;
heaterCount = 0;
return;
}
drives = new int[driveCount];
for(int8_t drive = 0; drive < driveCount; drive++)
drives[drive] = d[drive];
}
if(heaterCount > 0)
{
if(heaterCount > HEATERS)
{
reprap.GetPlatform()->Message(HOST_MESSAGE, "Tool creation: attempt to use more heaters than there are in the RepRap...");
driveCount = 0;
heaterCount = 0;
return;
}
heaters = new int[heaterCount];
activeTemperatures = new float[heaterCount];
standbyTemperatures = new float[heaterCount];
for(int8_t heater = 0; heater < heaterCount; heater++)
{
heaters[heater] = h[heater];
activeTemperatures[heater] = ABS_ZERO;
standbyTemperatures[heater] = ABS_ZERO;
}
}
}
float Tool::MaxFeedrate()
{
if(driveCount <= 0)
{
reprap.GetPlatform()->Message(HOST_MESSAGE, "Attempt to get maximum feedrate for a tool with no drives.\n");
return 1.0;
}
float result = 0.0;
float mf;
for(int8_t d = 0; d < driveCount; d++)
{
mf = reprap.GetPlatform()->MaxFeedrate(drives[d] + AXES);
if(mf > result)
result = mf;
}
return result;
}
float Tool::InstantDv()
{
if(driveCount <= 0)
{
reprap.GetPlatform()->Message(HOST_MESSAGE, "Attempt to get InstantDv for a tool with no drives.\n");
return 1.0;
}
float result = FLT_MAX;
float idv;
for(int8_t d = 0; d < driveCount; d++)
{
idv = reprap.GetPlatform()->InstantDv(drives[d] + AXES);
if(idv < result)
result = idv;
}
return result;
}
// Add a tool to the end of the linked list.
// (We must already be in it.)
void Tool::AddTool(Tool* t)
{
Tool* last = this;
Tool* n = next;
while(n != NULL)
{
last = n;
n = n->Next();
}
t->next = NULL; // Defensive...
last->next = t;
}
void Tool::Activate(Tool* currentlyActive)
{
if(active)
return;
if(currentlyActive != NULL && currentlyActive != this)
currentlyActive->Standby();
for(int8_t heater = 0; heater < heaterCount; heater++)
{
reprap.GetHeat()->SetActiveTemperature(heaters[heater], activeTemperatures[heater]);
reprap.GetHeat()->SetStandbyTemperature(heaters[heater], standbyTemperatures[heater]);
reprap.GetHeat()->Activate(heaters[heater]);
}
active = true;
}
void Tool::Standby()
{
if(!active)
return;
for(int8_t heater = 0; heater < heaterCount; heater++)
{
reprap.GetHeat()->SetStandbyTemperature(heaters[heater], standbyTemperatures[heater]);
reprap.GetHeat()->Standby(heaters[heater]);
}
active = false;
}
void Tool::SetVariables(float* standby, float* active)
{
for(int8_t heater = 0; heater < heaterCount; heater++)
{
activeTemperatures[heater] = active[heater];
standbyTemperatures[heater] = standby[heater];
reprap.GetHeat()->SetActiveTemperature(heaters[heater], activeTemperatures[heater]);
reprap.GetHeat()->SetStandbyTemperature(heaters[heater], standbyTemperatures[heater]);
}
}
void Tool::GetVariables(float* standby, float* active)
{
for(int8_t heater = 0; heater < heaterCount; heater++)
{
active[heater] = activeTemperatures[heater];
standby[heater] = standbyTemperatures[heater];
}
}