Restrict speed setting to fixed-point output with 3 decimal places. Includes test.

Fixes #4769
This commit is contained in:
Joseph Lenox 2019-03-30 13:02:54 -05:00 committed by Joseph Lenox
parent 05a2f9028a
commit 205cb02efa
2 changed files with 29 additions and 1 deletions

View File

@ -98,3 +98,30 @@ SCENARIO("lift() is not ignored after unlift() at normal values of Z") {
}
}
}
SCENARIO("set_speed emits values with fixed-point output.") {
GIVEN("GCodeWriter instance") {
GCodeWriter writer;
WHEN("set_speed is called to set speed to 1.09321e+06") {
THEN("Output string is G1 F1093210.000") {
REQUIRE_THAT(writer.set_speed(1.09321e+06), Catch::Equals("G1 F1093210.000\n"));
}
}
WHEN("set_speed is called to set speed to 1") {
THEN("Output string is G1 F1.000") {
REQUIRE_THAT(writer.set_speed(1.0), Catch::Equals("G1 F1.000\n"));
}
}
WHEN("set_speed is called to set speed to 203.200022") {
THEN("Output string is G1 F203.200") {
REQUIRE_THAT(writer.set_speed(203.200022), Catch::Equals("G1 F203.200\n"));
}
}
WHEN("set_speed is called to set speed to 203.200522") {
THEN("Output string is G1 F203.200") {
REQUIRE_THAT(writer.set_speed(203.200522), Catch::Equals("G1 F203.201\n"));
}
}
}
}

View File

@ -309,7 +309,8 @@ GCodeWriter::set_speed(double F, const std::string &comment,
const std::string &cooling_marker) const
{
std::ostringstream gcode;
gcode << "G1 F" << F;
gcode.precision(3);
gcode << "G1 F" << std::fixed << F;
COMMENT(comment);
gcode << cooling_marker;
gcode << "\n";