-
-
Notifications
You must be signed in to change notification settings - Fork 768
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reads the max spindle speed from the controller and automatically upd…
…ates the designer job (#2543)
- Loading branch information
Showing
24 changed files
with
464 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
ugs-core/src/com/willwinder/universalgcodesender/firmware/fluidnc/SpeedMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
Copyright 2024 Will Winder | ||
This file is part of Universal Gcode Sender (UGS). | ||
UGS is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
UGS is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with UGS. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.willwinder.universalgcodesender.firmware.fluidnc; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* A class for parsing FluidNC speed maps | ||
* | ||
* @author Joacim Breiler | ||
*/ | ||
public class SpeedMap { | ||
private final Map<Integer, Double> speeds = new HashMap<>(); | ||
|
||
public SpeedMap(String speedMaps) { | ||
String[] speeds = speedMaps.split(" "); | ||
for (String speedMap : speeds) { | ||
String[] split = speedMap.split("="); | ||
if (split.length != 2) { | ||
continue; | ||
} | ||
|
||
this.speeds.put(Integer.parseInt(split[0].trim()), Double.parseDouble(split[1].trim().replace("%", ""))); | ||
} | ||
} | ||
|
||
public int getMax() { | ||
return speeds.keySet().stream() | ||
.max((s1, s2) -> speeds.get(s1).compareTo(speeds.get(s2))) | ||
.orElse(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
ugs-core/test/com/willwinder/universalgcodesender/firmware/fluidnc/SpeedMapTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.willwinder.universalgcodesender.firmware.fluidnc; | ||
|
||
import static org.junit.Assert.*; | ||
import org.junit.Test; | ||
|
||
public class SpeedMapTest { | ||
|
||
@Test | ||
public void getMaxShouldReturnTheHundredPercentMaxSpindleSpeed() { | ||
SpeedMap speedMap = new SpeedMap("0=0.00% 0=0.00% 5000=100.00%"); | ||
assertEquals(5000, speedMap.getMax()); | ||
} | ||
|
||
@Test | ||
public void getMaxShouldReturnTheMaxSpindleSpeedRegardlessOfOrder() { | ||
SpeedMap speedMap = new SpeedMap("5000=100.00% 0=0.00% "); | ||
assertEquals(5000, speedMap.getMax()); | ||
} | ||
|
||
@Test | ||
public void getMaxShouldReturnValueOfTheHighestPercent() { | ||
SpeedMap speedMap = new SpeedMap("5000=99.00% 0=0.00% 4000=100%"); | ||
assertEquals(4000, speedMap.getMax()); | ||
} | ||
|
||
@Test | ||
public void speedMapShouldHandleExtraSpacing() { | ||
SpeedMap speedMap = new SpeedMap("0=0.00% 5000=50.00% 10000=100.00%"); | ||
assertEquals(10000, speedMap.getMax()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.