
M563 command extended to allow the tool number origin to be adjusted. If there is no P parameter in the command then the S parameter specifies an offset to be added to tool numbers in T, G10, M104 and M109 commands. This is so that multi-media gcode files generated by slic3r can be printed without having to edit all the tool numbers in the gcode file first. This extension is intended to be temporary, until slicer provides a mechanism for specifying the tool numbers. A separate offset is maintained for each data source (USB, web or SD card) and the offset for data from the SD card is reset to zero when a new file is started. To use this facility to print slic3r multi-media gcode files, add M563 S1 to your start gcode. M104 and M109 commands now accept an optional T parameter to specify the tool number, as generated by slic3r in multi-media gcode files. Movement code from RepRapPro's dev branch incorporated, including 5-point manual or automatic bed compensation mechanism. Heater status (off/standby/on) is included in the status poll response for the web interface. This will be used in a future version of the web interface. Incorporated code from RepRapPro dev branch to allow many more M-commands to return values as well as set them. Incorporated code from RepRapPro dev branch to implement the M119 and M135 commands. There is currently a bug in the M135 (set heat sample interval) command, which means that if you change the interval from its default value of 0.5 seconds then you need to adjust the I parameter by the same ratio and the D parameter by the inverse ratio. Extrusion totals are reset to zero when starting a new print from SD card.
222 lines
5.4 KiB
C++
222 lines
5.4 KiB
C++
/****************************************************************************************************
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
void Tool::Print(char* reply) const
|
|
{
|
|
snprintf(reply, STRING_LENGTH, "Tool %d - drives: ", myNumber);
|
|
char comma = ',';
|
|
for(int8_t drive = 0; drive < driveCount; drive++)
|
|
{
|
|
if(drive >= driveCount - 1)
|
|
{
|
|
comma = ';';
|
|
}
|
|
sncatf(reply, STRING_LENGTH, "%d%c", drives[drive], comma);
|
|
}
|
|
|
|
sncatf(reply, STRING_LENGTH, "heaters (active/standby temps): ");
|
|
comma = ',';
|
|
for(int8_t heater = 0; heater < heaterCount; heater++)
|
|
{
|
|
if(heater >= heaterCount - 1)
|
|
{
|
|
comma = ';';
|
|
}
|
|
sncatf(reply, STRING_LENGTH, "%d (%.1f/%.1f)%c", heaters[heater],
|
|
activeTemperatures[heater], standbyTemperatures[heater], comma);
|
|
}
|
|
|
|
sncatf(reply, STRING_LENGTH, " status: %s", active ? "selected" : "standby");
|
|
}
|
|
float Tool::MaxFeedrate() const
|
|
{
|
|
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;
|
|
for(int8_t d = 0; d < driveCount; d++)
|
|
{
|
|
float mf = reprap.GetPlatform()->MaxFeedrate(drives[d] + AXES);
|
|
if(mf > result)
|
|
{
|
|
result = mf;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
float Tool::InstantDv() const
|
|
{
|
|
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;
|
|
for(int8_t d = 0; d < driveCount; d++)
|
|
{
|
|
float 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) const
|
|
{
|
|
for(int8_t heater = 0; heater < heaterCount; heater++)
|
|
{
|
|
active[heater] = activeTemperatures[heater];
|
|
standby[heater] = standbyTemperatures[heater];
|
|
}
|
|
}
|
|
|
|
// Update the number of active drives and extruders in use to reflect what this tool uses
|
|
void Tool::UpdateExtruderAndHeaterCount(uint16_t &numExtruders, uint16_t &numHeaters) const
|
|
{
|
|
for(int8_t drive = 0; drive < driveCount; drive++)
|
|
{
|
|
if (drives[drive] >= numExtruders)
|
|
{
|
|
numExtruders = drives[drive] + 1;
|
|
}
|
|
}
|
|
|
|
for(int8_t heater = 0; heater < heaterCount; heater++)
|
|
{
|
|
if (heaters[heater] >= numHeaters)
|
|
{
|
|
numHeaters = heaters[heater] + 1;
|
|
}
|
|
}
|
|
}
|
|
|