Skip to content

Commit

Permalink
#114 extrusion visualization take 2 (#244)
Browse files Browse the repository at this point in the history
* Work at step resolution
* enable colour by extrusion width
* raise FPS cap, keep lines as default extrusion
* Add averageing for non-highres Evis mode and lines
* Add a "flat-quad" extrusion vis mode.
* Add nonlinearity/VFA test print.
* camera tweak
* fix a thread violation in the mouse script handler
  • Loading branch information
vintagepc authored Oct 6, 2020
1 parent fa042b5 commit 2336da9
Show file tree
Hide file tree
Showing 34 changed files with 3,190 additions and 208 deletions.
9 changes: 6 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ endif()

add_subdirectory(3rdParty/tinyobjloader)
add_subdirectory(3rdParty/gsl)

add_subdirectory(scripts/tests)

if (ENABLE_IWYU)
Expand Down Expand Up @@ -122,6 +121,7 @@ set(H_FILES
parts/wiring/MM_Control_01.h
parts/wiring/Test_Wiring.h
utility/Color.h
utility/Config.h
utility/GLPrint.h
utility/FatImage.h
utility/MK3SGL.h
Expand Down Expand Up @@ -431,9 +431,12 @@ if(SANITY_TESTS)
add_test(Fancy_Gfx env ${TEST_EXPORT_PREFIX} ${TEST_XVFB_PREFIX} ./MK404 -g fancy -f MK3S.afx --script ../scripts/tests/test_fancy_gfx.txt)
add_test(Lite_MMU_Gfx env ${TEST_EXPORT_PREFIX} ${TEST_XVFB_PREFIX} ./MK404 Prusa_MK3SMMU2 -g lite -f MK3S.afx --script ../scripts/tests/test_litemmu_gfx.txt)
add_test(Fancy_MMU_Gfx env ${TEST_EXPORT_PREFIX} ${TEST_XVFB_PREFIX} ./MK404 Prusa_MK3SMMU2 -g fancy -f MK3S.afx --script ../scripts/tests/test_fancymmu_gfx.txt)
add_test(KeyPress env ${TEST_EXPORT_PREFIX} ${TEST_XVFB_PREFIX} ./MK404 Prusa_MK3S -g lite --script ../scripts/tests/test_lite_gfx_mouse.txt)
add_test(Mouse env ${TEST_EXPORT_PREFIX} ${TEST_XVFB_PREFIX} ./MK404 Prusa_MK3S -g lite --script ../scripts/tests/test_lite_gfx_keys.txt)
add_test(Mouse env ${TEST_EXPORT_PREFIX} ${TEST_XVFB_PREFIX} ./MK404 Prusa_MK3S -g lite --script ../scripts/tests/test_lite_gfx_mouse.txt)
add_test(Keys env ${TEST_EXPORT_PREFIX} ${TEST_XVFB_PREFIX} ./MK404 Prusa_MK3S -g lite --script ../scripts/tests/test_lite_gfx_keys.txt)
add_test(Print env ${TEST_EXPORT_PREFIX} ${TEST_XVFB_PREFIX} ./MK404 Prusa_MK3S -g lite --sdimage Test.img --script ../scripts/tests/test_GLPrint.txt)
add_test(Print_HRQ env ${TEST_EXPORT_PREFIX} ${TEST_XVFB_PREFIX} ./MK404 Prusa_MK3S -g lite --sdimage Test.img --script ../scripts/tests/test_GLPrint_HRQ.txt --extrusion Quad_HR --colour-extrusion)
add_test(Print_TAvg env ${TEST_EXPORT_PREFIX} ${TEST_XVFB_PREFIX} ./MK404 Prusa_MK3S -g lite --sdimage Test.img --script ../scripts/tests/test_GLPrint_AvgT.txt --extrusion Tube_Avg)

endif()

# This is a bit meaningless if your system doesn't generate the same renderings as the BR.
Expand Down
107 changes: 60 additions & 47 deletions MK404.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
along with MK404. If not, see <http://www.gnu.org/licenses/>.
*/

#include "Config.h"
#include "FatImage.h" // for FatImage
#include "KeyController.h"
#include "Macros.h"
#include "PrintVisualType.h"
#include "Printer.h" // for Printer, Printer::VisualType
#include "PrinterFactory.h" // for PrinterFactory
#include "ScriptHost.h" // for ScriptHost
Expand Down Expand Up @@ -64,6 +66,10 @@ bool m_bStopping = false;

bool m_bTestMode = false;

// GL context stuff for FPS counting...

int m_iTic =0, m_iLast = 0, m_iFrCount = 0;


// pragma: LCOV_EXCL_START
// Exit cleanly on ^C
Expand Down Expand Up @@ -101,6 +107,19 @@ extern "C" {
}
// pragma: LCOV_EXCL_STOP

static std::string GetBaseTitle()
{
static std::string strTitle;
if (strTitle.empty())
{
strTitle += "Prusa i3 MK404 (PRINTER NOT FOUND) ";
strTitle += version::GIT_TAG_NAME;
strTitle.push_back('+');
strTitle+= std::to_string(version::GIT_COMMITS_SINCE_TAG);
}
return strTitle;
}

std::atomic_bool bIsQuitting {false};

void displayCB() /* function called whenever redisplay needed */
Expand All @@ -117,6 +136,17 @@ void displayCB() /* function called whenever redisplay needed */
int iH = glutGet(GLUT_WINDOW_HEIGHT);
printer->Draw();

m_iFrCount++;
m_iTic=glutGet(GLUT_ELAPSED_TIME);
auto iDiff = m_iTic - m_iLast;
if (iDiff > 1000) {
int iFPS = m_iFrCount*1000.f/(iDiff);
m_iLast = m_iTic;
m_iFrCount = 0;
std::string strFPS = GetBaseTitle() + " (" +std::to_string(iFPS) + " FPS)";
glutSetWindowTitle(strFPS.c_str());
}

if (pBoard->IsStopped() || pBoard->IsPaused())
{
std::string strState = pBoard->IsStopped() ? "Stopped" : "Paused";
Expand Down Expand Up @@ -171,7 +201,7 @@ void timerCB(int i)
{
glutReshapeWindow(iWinW, iWinH);
}
glutTimerFunc(25, timerCB, i);
glutTimerFunc(20, timerCB, i);
glutPostRedisplay();
}

Expand Down Expand Up @@ -239,54 +269,40 @@ int main(int argc, char *argv[])
signal(SIGINT, OnSigINT);

TCLAP::CmdLine cmd("MK404 is an 8-bit AVR based 3D printer simulator for firmware debugging and tinkering.\n Copyright 2020 VintagePC <https://github.com/vintagepc/> with contributions from leptun, wavexx and 3d-gussner.",' ',version::VERSION_STRING); // NOLINT
SwitchArg argWait("w","wait","Wait after the printer (and any PTYs) are set up but before starting execution.");
cmd.add(argWait);
MultiSwitchArg argSpam("v","verbose","Increases verbosity of the output, where supported.");
cmd.add(argSpam);
ValueArg<int> argVCDRate("","tracerate", "Sets the logging frequency of the VCD trace (default 100uS)",false, 100,"integer");
cmd.add(argVCDRate);
MultiArg<string> argVCD("t","trace","Enables VCD traces for the specified categories or IRQs. use '-t ?' to get a printout of available traces",false,"string");
cmd.add(argVCD);
SwitchArg argTest("","test","Run it test mode (no graphics, don't auto-exit.");
cmd.add(argTest);
ValueArg<string> argSD("","sdimage","Use the given SD card .img file instead of the default", false ,"", "filename.img");
cmd.add(argSD);
SwitchArg argSerial("s","serial","Connect a printer's serial port to a PTY instead of printing its output to the console.");
cmd.add(argSerial);
SwitchArg argScriptHelp("","scripthelp", "Prints the available scripting commands for the current printer/context",false);
cmd.add(argScriptHelp);
ValueArg<string> argScript("","script","Execute the given script. Use --scripthelp for syntax.", false ,"", "filename.txt");
cmd.add(argScript);
SwitchArg argNoHacks("n","no-hacks","Disable any special hackery that might have been implemented for a board to run its manufacturer firmware, e.g. if you want to run stock marlin and have issues. Effects depend on the board and firmware.");
cmd.add(argNoHacks);
SwitchArg argMute("m","mute","Tell a printer to mute any audio it may produce.");
cmd.add(argMute);
SwitchArg argLoad("l","loadfw","Directs the printer to load the default firmware file. (-f implies -l) If neither -l or -f are provided, the printer executes solely from its persisted flash.");
cmd.add(argLoad);
SwitchArg argWait("w","wait","Wait after the printer (and any PTYs) are set up but before starting execution.", cmd);
MultiSwitchArg argSpam("v","verbose","Increases verbosity of the output, where supported.",cmd);
ValueArg<int> argVCDRate("","tracerate", "Sets the logging frequency of the VCD trace (default 100uS)",false, 100,"integer",cmd);
MultiArg<string> argVCD("t","trace","Enables VCD traces for the specified categories or IRQs. use '-t ?' to get a printout of available traces",false,"string",cmd);
SwitchArg argTest("","test","Run it test mode (no graphics, don't auto-exit.", cmd);
ValueArg<string> argSD("","sdimage","Use the given SD card .img file instead of the default", false ,"", "filename.img", cmd);
SwitchArg argSerial("s","serial","Connect a printer's serial port to a PTY instead of printing its output to the console.", cmd);
SwitchArg argScriptHelp("","scripthelp", "Prints the available scripting commands for the current printer/context",cmd, false);
ValueArg<string> argScript("","script","Execute the given script. Use --scripthelp for syntax.", false ,"", "filename.txt", cmd);
SwitchArg argNoHacks("n","no-hacks","Disable any special hackery that might have been implemented for a board to run its manufacturer firmware, e.g. if you want to run stock marlin and have issues. Effects depend on the board and firmware.",cmd);
SwitchArg argMute("m","mute","Tell a printer to mute any audio it may produce.", cmd);
SwitchArg argLoad("l","loadfw","Directs the printer to load the default firmware file. (-f implies -l) If neither -l or -f are provided, the printer executes solely from its persisted flash.", cmd);
SwitchArg argKeyHelp("k","keys","Prints the list of available keyboard controls",cmd,false);
std::vector<string> vstrSizes = FatImage::GetSizes();
ValuesConstraint<string> vcSizes(vstrSizes);
ValueArg<string> argImgSize("","image-size","Specify a size for a new SD image. You must specify an image with --sdimage",false,"256M",&vcSizes);
cmd.add(argImgSize);
SwitchArg argGDB("","gdb","Enable SimAVR's GDB support");
cmd.add(argGDB);
ValueArg<string> argImgSize("","image-size","Specify a size for a new SD image. You must specify an image with --sdimage",false,"256M",&vcSizes,cmd);
SwitchArg argGDB("","gdb","Enable SimAVR's GDB support",cmd);
std::vector<string> vstrGfx = {"none","lite","fancy", "bear"};
ValuesConstraint<string> vcGfxAllowed(vstrGfx);
ValueArg<string> argGfx("g","graphics","Whether to enable fancy (advanced) or lite (minimal advanced) visuals. If not specified, only the basic 2D visuals are shown.",false,"lite",&vcGfxAllowed);
cmd.add(argGfx);
ValueArg<string> argFW("f","firmware","hex/afx/elf Firmware file to load (default MK3S.afx)",false,"MK3S.afx","filename");
cmd.add(argFW);
MultiSwitchArg argDebug("d","debug","Increases debugging output, where supported.");
cmd.add(argDebug);
SwitchArg argBootloader("b","bootloader","Run bootloader on first start instead of going straight to the firmware.");
cmd.add(argBootloader);
SwitchArg argMD("","markdown","Used to auto-generate the items in refs/ as markdown");
cmd.add(argMD);
ValueArg<string> argGfx("g","graphics","Whether to enable fancy (advanced) or lite (minimal advanced) visuals. If not specified, only the basic 2D visuals are shown.",false,"lite",&vcGfxAllowed, cmd);
ValueArg<string> argFW("f","firmware","hex/afx/elf Firmware file to load (default MK3S.afx)",false,"MK3S.afx","filename", cmd);
std::vector<string> vstrExts = PrintVisualType::GetOpts();
ValuesConstraint<string> vcPrintOpts(vstrExts);
ValueArg<string> argExtrusion("","extrusion","Set Print visual type. HR options create a LOT of triangles, do not use for large prints!",false, "Line", &vcPrintOpts, cmd);
MultiSwitchArg argDebug("d","debug","Increases debugging output, where supported.", cmd);
SwitchArg argColourE("", "colour-extrusion", "Colours extrusion by width (for advanced step/extrusion debugging.", cmd, false);
SwitchArg argBootloader("b","bootloader","Run bootloader on first start instead of going straight to the firmware.",cmd);
SwitchArg argMD("","markdown","Used to auto-generate the items in refs/ as markdown",cmd);
SwitchArg arg3D("", "3d-extrusion", "Visualize with 3D extrusions (can be GPU intensive for large prints)", cmd);

std::vector<string> vstrPrinters = PrinterFactory::GetModels();
ValuesConstraint<string> vcAllowed(vstrPrinters);

TCLAP::UnlabeledValueArg<string> argModel("printer","Model name of the printer to run",false,"Prusa_MK3S",&vcAllowed);
cmd.add(argModel);
TCLAP::UnlabeledValueArg<string> argModel("printer","Model name of the printer to run",false,"Prusa_MK3S",&vcAllowed, cmd);

if (version::IS_DEV_VERSION)
{
Expand Down Expand Up @@ -317,7 +333,8 @@ int main(int argc, char *argv[])

m_bTestMode = (argModel.getValue()=="Test_Printer") | argTest.isSet();

//bNoGraphics |= (m_bTestMode && bRunGLTests);
Config::Get().SetExtrusionMode(PrintVisualType::GetNameToType().at(argExtrusion.getValue()));
Config::Get().SetColourE(argColourE.isSet());

TelemetryHost::GetHost().SetCategories(argVCD.getValue());

Expand Down Expand Up @@ -355,11 +372,7 @@ int main(int argc, char *argv[])
glutInitDisplayMode(US(GLUT_RGB) | US(GLUT_DOUBLE));
#endif
glutInitWindowSize(iWinW, iWinH); /* width=400pixels height=500pixels */
std::string strTitle = "Prusa i3 MK404 (PRINTER NOT FOUND) ";
strTitle += version::GIT_TAG_NAME;
strTitle.push_back('+');
strTitle+= std::to_string(version::GIT_COMMITS_SINCE_TAG);
window = glutCreateWindow(strTitle.c_str()); /* create window */
window = glutCreateWindow(GetBaseTitle().c_str()); /* create window */

glewInit();
std::cout << "GL_VERSION : " << glGetString(GL_VERSION) << '\n';
Expand Down
2 changes: 1 addition & 1 deletion SDCard/Test.gcode
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ G1 X121.344 Y107.578 E0.05317 ; infill
G1 X121.344 Y108.172 E0.02072 ; infill
G1 X122.011 Y108.839 E0.03291 ; infill
M204 S1250 ; adjust acceleration
G1 E-0.40000 F4800.00000 ; retract
G1 E-0.80000 F4800.00000 ; retract
G1 Z0.500 F12000.000 ; lift Z
G4 S0
M73 P75 R0
Expand Down
Loading

0 comments on commit 2336da9

Please sign in to comment.