diff options
-rw-r--r-- | src/GCodes/GCodeMachineState.h | 2 | ||||
-rw-r--r-- | src/GCodes/GCodes.h | 14 | ||||
-rw-r--r-- | src/GCodes/GCodes2.cpp | 12 | ||||
-rw-r--r-- | src/GCodes/GCodes4.cpp | 12 | ||||
-rw-r--r-- | src/Movement/Kinematics/FiveBarScaraKinematics.cpp | 17 | ||||
-rw-r--r-- | src/RepRap.cpp | 5 | ||||
-rw-r--r-- | src/RepRap.h | 2 | ||||
-rw-r--r-- | src/Version.h | 2 |
8 files changed, 39 insertions, 27 deletions
diff --git a/src/GCodes/GCodeMachineState.h b/src/GCodes/GCodeMachineState.h index 12d52564..6bde095a 100644 --- a/src/GCodes/GCodeMachineState.h +++ b/src/GCodes/GCodeMachineState.h @@ -176,7 +176,6 @@ public: uint32_t lineNumber; Compatibility compatibility; - int16_t newToolNumber; uint16_t drivesRelative : 1, axesRelative : 1, @@ -198,7 +197,6 @@ public: uint8_t blockNesting; GCodeState state; - uint8_t toolChangeParam; bool DoingFile() const noexcept; void CloseFile() noexcept; diff --git a/src/GCodes/GCodes.h b/src/GCodes/GCodes.h index 959ee938..d6fbd208 100644 --- a/src/GCodes/GCodes.h +++ b/src/GCodes/GCodes.h @@ -87,8 +87,6 @@ class StraightProbeSettings; class GCodes { public: - friend class LinuxInterface; - GCodes(Platform& p) noexcept; void Spin() noexcept; // Called in a tight loop to make this class work void Init() noexcept; // Set it up @@ -193,6 +191,12 @@ public: void AssignGrid(float xRange[2], float yRange[2], float radius, float spacing[2]) noexcept; // Assign the heightmap using the given parameters void ActivateHeightmap(bool activate) noexcept; // (De-)Activate the height map + int GetNewToolNumber() const noexcept { return newToolNumber; } + + // These next two are public because they are used by class LinuxInterface + void UnlockAll(const GCodeBuffer& gb) noexcept; // Release all locks + GCodeBuffer *GetGCodeBuffer(GCodeChannel channel) const noexcept { return gcodeSources[channel.ToBaseType()]; } + #if HAS_MASS_STORAGE GCodeResult StartSDTiming(GCodeBuffer& gb, const StringRef& reply) noexcept; // Start timing SD card file writing #endif @@ -278,9 +282,7 @@ private: void GrabMovement(const GCodeBuffer& gb) noexcept; // Grab the movement lock even if it is already owned void UnlockResource(const GCodeBuffer& gb, Resource r) noexcept; // Unlock the resource if we own it void UnlockMovement(const GCodeBuffer& gb) noexcept; // Unlock the movement resource if we own it - void UnlockAll(const GCodeBuffer& gb) noexcept; // Release all locks - GCodeBuffer *GetGCodeBuffer(GCodeChannel channel) const noexcept { return gcodeSources[channel.ToBaseType()]; } void StartNextGCode(GCodeBuffer& gb, const StringRef& reply) noexcept; // Fetch a new or old GCode and process it void RunStateMachine(GCodeBuffer& gb, const StringRef& reply) noexcept; // Execute a step of the state machine void DoStraightManualProbe(GCodeBuffer& gb, const StraightProbeSettings& sps); @@ -527,6 +529,10 @@ private: FilePosition fileOffsetToPrint; // The offset to print from #endif + // Tool change. These variables can be global because movement is locked while doing a tool change, so only one can take place at a time. + int16_t newToolNumber; + uint8_t toolChangeParam; + char axisLetters[MaxAxes + 1]; // The names of the axes, with a null terminator bool limitAxes; // Don't think outside the box bool noMovesBeforeHoming; // Don't allow movement prior to homing the associates axes diff --git a/src/GCodes/GCodes2.cpp b/src/GCodes/GCodes2.cpp index 328eb1b2..1dc7aad1 100644 --- a/src/GCodes/GCodes2.cpp +++ b/src/GCodes/GCodes2.cpp @@ -1370,8 +1370,8 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeEx return false; } - gb.MachineState().newToolNumber = applicableTool->Number(); - gb.MachineState().toolChangeParam = (simulationMode != 0) ? 0 : DefaultToolChangeParam; + newToolNumber = applicableTool->Number(); + toolChangeParam = (simulationMode != 0) ? 0 : DefaultToolChangeParam; gb.SetState(GCodeState::m109ToolChange0); result = GCodeResult::ok; } @@ -4318,10 +4318,10 @@ bool GCodes::HandleTcode(GCodeBuffer& gb, const StringRef& reply) // If old and new are the same we no longer follow the sequence. User can deselect and then reselect the tool if he wants the macros run. if (oldTool == nullptr || oldTool->Number() != toolNum) { - gb.MachineState().newToolNumber = toolNum; - gb.MachineState().toolChangeParam = (simulationMode != 0) ? 0 - : gb.Seen('P') ? gb.GetUIValue() - : DefaultToolChangeParam; + newToolNumber = toolNum; + toolChangeParam = (simulationMode != 0) ? 0 + : gb.Seen('P') ? gb.GetUIValue() + : DefaultToolChangeParam; gb.SetState(GCodeState::toolChange0); return true; // proceeding with state machine, so don't unlock or send a reply } diff --git a/src/GCodes/GCodes4.cpp b/src/GCodes/GCodes4.cpp index 7370cf25..d08a9152 100644 --- a/src/GCodes/GCodes4.cpp +++ b/src/GCodes/GCodes4.cpp @@ -234,7 +234,7 @@ void GCodes::RunStateMachine(GCodeBuffer& gb, const StringRef& reply) noexcept currentUserPosition[Z_AXIS] += currentZHop; currentZHop = 0.0; - if ((gb.MachineState().toolChangeParam & TFreeBit) != 0) + if ((toolChangeParam & TFreeBit) != 0) { const Tool * const oldTool = reprap.GetCurrentTool(); if (oldTool != nullptr && AllAxesAreHomed()) @@ -257,10 +257,10 @@ void GCodes::RunStateMachine(GCodeBuffer& gb, const StringRef& reply) noexcept UpdateCurrentUserPosition(); // the tool offset may have changed, so get the current position } gb.AdvanceState(); - if (reprap.GetTool(gb.MachineState().newToolNumber).IsNotNull() && AllAxesAreHomed() && (gb.MachineState().toolChangeParam & TPreBit) != 0) + if (reprap.GetTool(newToolNumber).IsNotNull() && AllAxesAreHomed() && (toolChangeParam & TPreBit) != 0) { String<StringLength20> scratchString; - scratchString.printf("tpre%d.g", gb.MachineState().newToolNumber); + scratchString.printf("tpre%d.g", newToolNumber); DoFileMacro(gb, scratchString.c_str(), false, 0); } } @@ -270,16 +270,16 @@ void GCodes::RunStateMachine(GCodeBuffer& gb, const StringRef& reply) noexcept case GCodeState::m109ToolChange2: // select the new tool if it exists and run tpost if (LockMovementAndWaitForStandstill(gb)) // wait for tpre.g to finish executing { - reprap.SelectTool(gb.MachineState().newToolNumber, simulationMode != 0); + reprap.SelectTool(newToolNumber, simulationMode != 0); UpdateCurrentUserPosition(); // get the actual position of the new tool gb.AdvanceState(); if (AllAxesAreHomed()) { - if (reprap.GetCurrentTool() != nullptr && (gb.MachineState().toolChangeParam & TPostBit) != 0) + if (reprap.GetCurrentTool() != nullptr && (toolChangeParam & TPostBit) != 0) { String<StringLength20> scratchString; - scratchString.printf("tpost%d.g", gb.MachineState().newToolNumber); + scratchString.printf("tpost%d.g", newToolNumber); DoFileMacro(gb, scratchString.c_str(), false, 0); } } diff --git a/src/Movement/Kinematics/FiveBarScaraKinematics.cpp b/src/Movement/Kinematics/FiveBarScaraKinematics.cpp index 2461ca53..9c2eefe2 100644 --- a/src/Movement/Kinematics/FiveBarScaraKinematics.cpp +++ b/src/Movement/Kinematics/FiveBarScaraKinematics.cpp @@ -32,6 +32,7 @@ constexpr ObjectModelTableEntry FiveBarScaraKinematics::objectModelTable[] = // Within each group, these entries must be in alphabetical order // 0. kinematics members { "name", OBJECT_MODEL_FUNC(self->GetName(true)), ObjectModelEntryFlags::none }, + //TODO lots more to be added here }; constexpr uint8_t FiveBarScaraKinematics::objectModelTableDescriptor[] = { 1, 1 }; @@ -54,7 +55,7 @@ const char *FiveBarScaraKinematics::GetName(bool forStatusReport) const noexcept //////////////////////// private functions ///////////////////////// -// no results returnes. All results are stored in the cached variables. +// no results returned. All results are stored in the cached variables. // The constraints are not checked void FiveBarScaraKinematics::getInverse(const float coords[]) const noexcept { @@ -541,6 +542,7 @@ bool FiveBarScaraKinematics::Configure(unsigned int mCode, GCodeBuffer& gb, cons { if (mCode == 669) { + //TODO this should print the existing values if no parameters are given, instead of insisting that all parameters are present // must be defined: X, Y, P, D gb.MustSee('X'); gb.MustSee('Y'); @@ -579,7 +581,7 @@ bool FiveBarScaraKinematics::Configure(unsigned int mCode, GCodeBuffer& gb, cons workmode = 1; // default } - // proximal arm lenghts + // proximal arm lengths float proximalLengths[2]; gb.TryGetFloatArray('P', 2, proximalLengths, reply, seen); proximalL = proximalLengths[0]; @@ -588,6 +590,8 @@ bool FiveBarScaraKinematics::Configure(unsigned int mCode, GCodeBuffer& gb, cons // distal arm lengths and optional lengths of cantilevered arm bool dseen = false; float distalLengths[4]; + //TODO TryGetFloatArray will report an error if the wrong number of values is provided. But we want to allow either 2 or 4. + //TODO So this code should call Seen() followed by GetFloatArray() instead, then check the number of returned values. if (!gb.TryGetFloatArray('D', 4, distalLengths, reply, dseen) && dseen) { distalL = distalLengths[0]; @@ -619,6 +623,7 @@ bool FiveBarScaraKinematics::Configure(unsigned int mCode, GCodeBuffer& gb, cons } else { + //TODO instead of doing this, set these values up up during initialisation or when changing workmode, and leave them alone here if (workmode == 1) { homingAngleL = 20.0; // default @@ -681,10 +686,11 @@ bool FiveBarScaraKinematics::Configure(unsigned int mCode, GCodeBuffer& gb, cons } // optional rectangle definition of a print area. Must match the workmode reachable area + //TODO is this needed? Why not use the M208 limits instead? if (gb.Seen('Z')) { float coordinates[4]; - gb.TryGetFloatArray('Z', 4, coordinates, reply, seen); + gb.TryGetFloatArray('Z', 4, coordinates, reply, seenNonGeometry); for (int i=0; i < 4; i++) { printArea[i] = coordinates[i]; @@ -699,12 +705,13 @@ bool FiveBarScaraKinematics::Configure(unsigned int mCode, GCodeBuffer& gb, cons gb.TryGetFValue('S', segmentsPerSecond, seenNonGeometry); // value defined in Kinematics.h gb.TryGetFValue('T', minSegmentLength, seenNonGeometry); // value defined in Kinematics.h - if (seen || seenNonGeometry) + if (seen) { Recalc(); } - else if (!gb.Seen('K')) + else if (!seenNonGeometry && !gb.Seen('K')) { + //TODO print all the parameters here reply.printf("Kinematics is FiveBarScara, documented in https://duet3d.dozuki.com/Guide/Five+Bar+Parallel+SCARA/24?lang=en"); } diff --git a/src/RepRap.cpp b/src/RepRap.cpp index 57709199..1fc72a63 100644 --- a/src/RepRap.cpp +++ b/src/RepRap.cpp @@ -250,13 +250,14 @@ constexpr ObjectModelTableEntry RepRap::objectModelTable[] = { "beep", OBJECT_MODEL_FUNC(self, 4), ObjectModelEntryFlags::live }, { "currentTool", OBJECT_MODEL_FUNC((int32_t)self->GetCurrentToolNumber()), ObjectModelEntryFlags::live }, { "displayMessage", OBJECT_MODEL_FUNC(&self->message), ObjectModelEntryFlags::live }, - { "laserPwm", OBJECT_MODEL_FUNC(self->platform->GetLaserPwm(), 2), ObjectModelEntryFlags::live }, + { "laserPwm", OBJECT_MODEL_FUNC_IF(self->gCodes->GetMachineType() == MachineType::laser, self->platform->GetLaserPwm(), 2), ObjectModelEntryFlags::live }, #if HAS_MASS_STORAGE { "logFile", OBJECT_MODEL_FUNC(self->platform->GetLogFileName()), ObjectModelEntryFlags::none }, #else { "logFile", OBJECT_MODEL_FUNC(nullptr), ObjectModelEntryFlags::none }, #endif { "machineMode", OBJECT_MODEL_FUNC(self->gCodes->GetMachineModeString()), ObjectModelEntryFlags::none }, + { "nextTool", OBJECT_MODEL_FUNC((int32_t)self->gCodes->GetNewToolNumber()), ObjectModelEntryFlags::live }, { "powerFailScript", OBJECT_MODEL_FUNC(self->gCodes->GetPowerFailScript()), ObjectModelEntryFlags::none }, { "previousTool", OBJECT_MODEL_FUNC((int32_t)self->previousToolNumber), ObjectModelEntryFlags::live }, { "status", OBJECT_MODEL_FUNC(self->GetStatusString()), ObjectModelEntryFlags::live }, @@ -292,7 +293,7 @@ constexpr ObjectModelTableEntry RepRap::objectModelTable[] = { "volumes", OBJECT_MODEL_FUNC((int32_t)self->volumesSeq), ObjectModelEntryFlags::live }, }; -constexpr uint8_t RepRap::objectModelTableDescriptor[] = { 7, 16, 7, 22, 11, 2, 6, 14 }; +constexpr uint8_t RepRap::objectModelTableDescriptor[] = { 7, 16, 7, 22, 12, 2, 6, 14 }; DEFINE_GET_OBJECT_MODEL_TABLE(RepRap) diff --git a/src/RepRap.h b/src/RepRap.h index 9c7a7fe6..eec84bd5 100644 --- a/src/RepRap.h +++ b/src/RepRap.h @@ -279,7 +279,7 @@ private: MessageBox mbox; // message box data - int8_t previousToolNumber; + int16_t previousToolNumber; // the tool number we were using before the last tool change, or -1 if we weren't using a tool // Deferred diagnostics MessageType diagnosticsDestination; diff --git a/src/Version.h b/src/Version.h index d18cab4f..1262bc88 100644 --- a/src/Version.h +++ b/src/Version.h @@ -19,7 +19,7 @@ #endif #ifndef DATE -# define DATE "2020-03-11b1" +# define DATE "2020-03-12b1" #endif #define AUTHORS "reprappro, dc42, chrishamm, t3p3, dnewman, printm3d" |