Skip to content

Commit

Permalink
Merge pull request #17 from rbp28668/cutter_blocksize
Browse files Browse the repository at this point in the history
Cutter now aware of geometry comments in gcode
  • Loading branch information
Bruce Porteous authored Oct 17, 2020
2 parents 74cc9a5 + e3a5644 commit bad2d3c
Show file tree
Hide file tree
Showing 22 changed files with 130 additions and 37 deletions.
8 changes: 4 additions & 4 deletions Aerofoil.rc
Original file line number Diff line number Diff line change
Expand Up @@ -1214,8 +1214,8 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 6,1,0,0
PRODUCTVERSION 6,1,0,0
FILEVERSION 7,0,0,0
PRODUCTVERSION 7,0,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -1232,12 +1232,12 @@ BEGIN
BEGIN
VALUE "Comments", "Aerofoil Plotting Program"
VALUE "FileDescription", "Aerofoil MFC Application"
VALUE "FileVersion", "6.1.0.0"
VALUE "FileVersion", "7.0.0.0"
VALUE "InternalName", "Aerofoil"
VALUE "LegalCopyright", "Copyright (C) Bruce Porteous 2002-2020"
VALUE "OriginalFilename", "Aerofoil.EXE"
VALUE "ProductName", "Aerofoil Application"
VALUE "ProductVersion", "6.1.0.0"
VALUE "ProductVersion", "7.0.0.0"
END
END
BLOCK "VarFileInfo"
Expand Down
4 changes: 2 additions & 2 deletions AerofoilDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ void CAerofoilDoc::OnFilePlotSize()
dlg.m_width = size_x;
dlg.m_height = size_y;
dlg.m_sizeSelect = 1; // default to A4
if(dlg.DoModal())
if(dlg.DoModal() == IDOK)
{
switch(dlg.m_sizeSelect)
{
Expand Down Expand Up @@ -575,7 +575,7 @@ void CAerofoilDoc::OnWingFlags()
assert(currentWing);

CWingFlagsDlg dlg(currentWing->getPlotFlags());
if(dlg.DoModal())
if(dlg.DoModal() == IDOK)
RedrawNow();
}

Expand Down
2 changes: 1 addition & 1 deletion AerofoilView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ void CAerofoilView::OnInitialUpdate()
void CAerofoilView::OnViewZoom()
{
CZoomDlg dlg;
if(dlg.DoModal()) {
if(dlg.DoModal() == IDOK) {
if(dlg.fit) {
// Get current size of window
CRect rClient;
Expand Down
11 changes: 8 additions & 3 deletions Cutter/CNCFoamCutter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ CNCFoamCutter::CNCFoamCutter(CutterHardware* ph)
yMicroStep(4),
stepFrequency(2500),
feedRate(2.0), // arbitrary 2mm per sec
feedRateError(false)
feedRateError(false),
useGeometry(true)
{
assert(this);
assert(ph);
Expand Down Expand Up @@ -156,7 +157,9 @@ void CNCFoamCutter::fastMove(const Position<double> & deltas)
{
currentPosition.add(deltas); // new current position;
Position<double> axes(currentPosition);
geometry.blockToAxes(axes, 0, 0); // Note - no Z information available at this stage.
if (useGeometry) {
geometry.blockToAxes(axes, 0, 0); // Note - no Z information available at this stage.
}

// axes now contains the coordinates of where we want the motors to actually end up.
// in practice, they'll get close as there's not infinite resolution.
Expand Down Expand Up @@ -190,7 +193,9 @@ void CNCFoamCutter::cutMove(const Position<double> & deltas)
{
currentPosition.add(deltas); // new current position;
Position<double> axes(currentPosition);
geometry.blockToAxes(axes, 0, 0); // No Z information
if (useGeometry) {
geometry.blockToAxes(axes, 0, 0); // No Z information
}

// axes now contains the coordinates of where we want the motors to actually end up.
// in practice, they'll get close as there's not infinite resolution.
Expand Down
24 changes: 13 additions & 11 deletions Cutter/CNCFoamCutter.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class CNCFoamCutter : public Cutter {
double stepFrequency; // of steppers in Hz

CutterGeometry geometry;
bool useGeometry;

Position<double> currentPosition; // on side of block
Position<long long> axesPosition; // of hardware axes in microsteps
Expand All @@ -49,27 +50,28 @@ class CNCFoamCutter : public Cutter {
virtual ~CNCFoamCutter();

// Config
inline double getWidth() { return geometry.getWidth(); }
inline double getWidth() const { return geometry.getWidth(); }
void setWidth(double width);
inline double getXLead() { return xLead; }
inline double getXLead() const { return xLead; }
void setXLead(double lead);
inline double getYLead() { return yLead; }
inline double getYLead() const { return yLead; }
void setYLead(double lead);
inline int getXStepsPerRev(){ return xStepsPerRev; }
inline int getXStepsPerRev() const { return xStepsPerRev; }
void setXStepsPerRev(int steps);
inline int getYStepsPerRev() { return yStepsPerRev; }
inline int getYStepsPerRev() const { return yStepsPerRev; }
void setYStepsPerRev(int steps);
inline int getXMicroStepping() { return xMicroStep; }
inline int getXMicroStepping() const { return xMicroStep; }
void setXMicroStepping(int steps);
inline int getYMicroStepping() { return yMicroStep; }
inline int getYMicroStepping() const { return yMicroStep; }
void setYMicroStepping(int steps);
inline double getBlockLeft() { return geometry.getBlockLeft(); }
inline double getBlockLeft() const { return geometry.getBlockLeft(); }
void setBlockLeft(double side);
inline double getBlockRight() { return geometry.getBlockRight(); }
inline double getBlockRight() const { return geometry.getBlockRight(); }
void setBlockRight(double side);
inline double getStepFrequency() { return stepFrequency; }
inline double getStepFrequency() const { return stepFrequency; }
void setStepFrequency(double hz);

inline bool getUseGeometry() const { return useGeometry; }
inline void setUseGeometry(bool set) { useGeometry = set; }
virtual double getFeedRate();
virtual void setFeedRate(double feedRate);
// Set if we can't achieve desired feed rate.
Expand Down
1 change: 0 additions & 1 deletion Cutter/ConfigDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ void CConfigDialog::OnBnClickedBtnUpdateCutter()
pCutter->setBlockRight(config->blockRight);
pCutter->setWidth(config->cutterWidth);
pCutter->setFeedRate(config->defaultFeedRate);

pMainDialog->configUpdated(config);
}
}
Expand Down
1 change: 1 addition & 0 deletions Cutter/ConfigDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ class CConfigDialog : public CDialogEx
afx_msg void OnBnClickedBtnUpdate();
virtual BOOL OnInitDialog();
afx_msg void OnSelchangeLstButtons();
CButton useCutterGeometry;
};
19 changes: 10 additions & 9 deletions Cutter/Cutter.rc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,1
PRODUCTVERSION 1,0,0,1
FILEVERSION 7,0,0,0
PRODUCTVERSION 7,0,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -39,20 +39,20 @@ VS_VERSION_INFO VERSIONINFO
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904B0"
BLOCK "080904b0"
BEGIN
VALUE "FileDescription", "Cutter MFC Application"
VALUE "FileVersion", "1, 0, 0, 1"
VALUE "FileVersion", "7.0.0.0"
VALUE "InternalName", "Cutter"
VALUE "LegalCopyright", "Copyright (C) 2002"
VALUE "OriginalFilename", "Cutter.EXE"
VALUE "ProductName", "Cutter Application"
VALUE "ProductVersion", "1, 0, 0, 1"
VALUE "ProductVersion", "7.0.0.0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
VALUE "Translation", 0x809, 1200
END
END

Expand Down Expand Up @@ -163,8 +163,8 @@ FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
EDITTEXT IDC_EDT_COMMAND,42,7,184,14,ES_AUTOHSCROLL
PUSHBUTTON "Send",IDC_BTN_SEND,230,7,50,14
LTEXT "None",IDC_LBL_GCODE_ERR,282,150,237,8
LTEXT "Errors:",IDC_STATIC,251,150,23,8
LTEXT "None",IDC_LBL_GCODE_ERR,237,149,198,8
LTEXT "Errors:",IDC_STATIC,205,149,23,8
CONTROL "Can Pause?",IDC_CAN_PAUSE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,441,173,53,10
CONTROL "Paused",IDC_PAUSED,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,441,190,39,10
CONTROL "Complete",IDC_CHK_COMPLETE,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,441,207,46,10
Expand Down Expand Up @@ -202,7 +202,7 @@ BEGIN
PUSHBUTTON "Start",IDC_BTN_START,68,360,50,14
PUSHBUTTON "Restart",IDC_BTN_RESTART,197,360,50,14,WS_DISABLED
PUSHBUTTON "Clear",IDC_BTN_CLEAR,351,360,50,14
EDITTEXT IDC_EDT_CURRENT_LINE,7,146,201,14,ES_AUTOHSCROLL | WS_DISABLED
EDITTEXT IDC_EDT_CURRENT_LINE,7,146,176,14,ES_AUTOHSCROLL | WS_DISABLED
PUSHBUTTON "Home",IDC_BTN_HOME,7,32,50,35
PUSHBUTTON "Wire ON",IDC_BTN_WIRE_ON,64,32,50,14
PUSHBUTTON "Wire OFF",IDC_BTN_WIRE_OFF,64,52,50,14
Expand Down Expand Up @@ -243,6 +243,7 @@ BEGIN
PUSHBUTTON "Unused",IDC_BTN_PROG_14,352,111,62,14
PUSHBUTTON "Unused",IDC_BTN_PROG_15,421,111,62,14
PUSHBUTTON "Unused",IDC_BTN_PROG_16,490,111,62,14
CONTROL "Use Geometry",IDC_CHK_USE_GEOMETRY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,441,149,61,10
END

IDD_CONFIG DIALOGEX 0, 0, 557, 381
Expand Down
57 changes: 57 additions & 0 deletions Cutter/GCodeDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ along with this program.If not, see <http://www.gnu.org/licenses/>.
#include "afxdialogex.h"
#include "resource.h"
#include "CutterConfig.h"
#include "CutterDlg.h"
#include "../Kernel/Cutter.h"
#include "../Kernel/GCodeInterpreter.h"
#include "../Kernel/GCodeProgram.h"
Expand Down Expand Up @@ -297,6 +298,7 @@ void CGCodeDialog::DoDataExchange(CDataExchange* pDX)
DDX_Control(pDX, IDC_BTN_PROG_14, buttonProg14);
DDX_Control(pDX, IDC_BTN_PROG_15, buttonProg15);
DDX_Control(pDX, IDC_BTN_PROG_16, buttonProg16);
DDX_Control(pDX, IDC_CHK_USE_GEOMETRY, chkUseGeometry);
}


Expand Down Expand Up @@ -340,6 +342,7 @@ BEGIN_MESSAGE_MAP(CGCodeDialog, CDialogEx)
ON_BN_CLICKED(IDC_BTN_PROG_14, &CGCodeDialog::OnBnClickedBtnProg14)
ON_BN_CLICKED(IDC_BTN_PROG_15, &CGCodeDialog::OnBnClickedBtnProg15)
ON_BN_CLICKED(IDC_BTN_PROG_16, &CGCodeDialog::OnBnClickedBtnProg16)
ON_BN_CLICKED(IDC_CHK_USE_GEOMETRY, &CGCodeDialog::OnBnClickedChkUseGeometry)
END_MESSAGE_MAP()


Expand Down Expand Up @@ -475,6 +478,49 @@ void CGCodeDialog::OnBnClickedBtnLoad()
pProgram->load(ifs);
ifs.close();

bool useGeometry = true;

GCodeProgram::AuxInfoT info;
if (pProgram->getAuxInformation(info)) {

CNCFoamCutter* pCutter = pMainDialog->getCutter();

auto it = info.find("PRE_CORRECT_GEOMETRY");
if (it != info.end() && it->second == "TRUE") {
double width = 0;
double left = 0;
double right = 0;
it = info.find("CUTTER_WIDTH"); if (it != info.end()) width = stod(it->second);
it = info.find("BLOCK_LEFT"); if (it != info.end()) left = stod(it->second);
it = info.find("BLOCK_RIGHT"); if (it != info.end()) right = stod(it->second);

std::ostringstream msg;
msg << "Cut is pre-corrected for block geometry." << std::endl
<< "Cutter width: " << width << std::endl
<< "Block left: " << left << std::endl
<< "Block right: " << right << std::endl
<< "Disable local correction?";
if (AfxMessageBox(msg.str().c_str(), MB_ICONQUESTION | MB_YESNO) == IDYES) {
useGeometry = false;
}

}
else {
it = info.find("EFFECTIVE_SPAN");
if (it != info.end()) {
std::ostringstream msg;
double depth = stod(it->second);
msg << "Core has effective span of " << depth << "\n. Use this value for block width?";
if (AfxMessageBox(msg.str().c_str(), MB_ICONQUESTION | MB_YESNO) == IDYES) {
pCutter->setBlockRight(pCutter->getBlockLeft() + depth);

}
}
}
// Want to turn on by default if loading new unprecompensated plot.
pCutter->setUseGeometry(useGeometry);
chkUseGeometry.SetCheck(useGeometry ? BST_CHECKED : BST_UNCHECKED);
}
programUpdated();
}

Expand Down Expand Up @@ -517,6 +563,9 @@ BOOL CGCodeDialog::OnInitDialog()
HBITMAP hBitmap = (HBITMAP)stopBitmap.GetSafeHandle();
stopButton.SetBitmap(hBitmap);
configUpdated(pConfig);

CNCFoamCutter* pCutter = pMainDialog->getCutter();
chkUseGeometry.SetCheck( pCutter->getUseGeometry() ? BST_CHECKED : BST_UNCHECKED);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
Expand Down Expand Up @@ -791,3 +840,11 @@ void CGCodeDialog::OnBnClickedBtnProg16()
{
runProgramButton(15);
}


void CGCodeDialog::OnBnClickedChkUseGeometry()
{
bool useGeometry = chkUseGeometry.GetCheck() == BST_CHECKED;
CNCFoamCutter* pCutter = pMainDialog->getCutter();
pCutter->setUseGeometry(useGeometry);
}
3 changes: 3 additions & 0 deletions Cutter/GCodeDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ class CGCodeDialog : public CDialogEx, ParserContext
CButton buttonProg15;
CButton buttonProg16;

CButton chkUseGeometry;

void programUpdated();
virtual BOOL OnInitDialog();

Expand Down Expand Up @@ -164,4 +166,5 @@ class CGCodeDialog : public CDialogEx, ParserContext
afx_msg void OnBnClickedBtnProg15();
afx_msg void OnBnClickedBtnProg16();

afx_msg void OnBnClickedChkUseGeometry();
};
4 changes: 3 additions & 1 deletion Cutter/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,16 @@
#define IDC_BTN_PROG_14 1111
#define IDC_BTN_PROG_15 1112
#define IDC_BTN_PROG_16 1113
#define IDC_CHECK1 1114
#define IDC_CHK_USE_GEOMETRY 1114

// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 138
#define _APS_NEXT_COMMAND_VALUE 32771
#define _APS_NEXT_CONTROL_VALUE 1101
#define _APS_NEXT_CONTROL_VALUE 1115
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
2 changes: 1 addition & 1 deletion CutterView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void CutterView::OnUpdateViewDrawmoves(CCmdUI *pCmdUI)
void CutterView::OnViewZoom()
{
CZoomDlg dlg;
if (dlg.DoModal())
if (dlg.DoModal() == IDOK)
{
if(dlg.fit) {
// Get current size of window
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added Docs/aerofoil-7.0.odt
Binary file not shown.
Binary file added Docs/aerofoil-7.0.pdf
Binary file not shown.
Binary file added Docs/cutter-7.0.odt
Binary file not shown.
19 changes: 19 additions & 0 deletions Kernel/GCodeProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ along with this program.If not, see <http://www.gnu.org/licenses/>.
*/

#include<assert.h>
#include<regex>
#include "GCodeInterpreter.h"
#include "GCodeProgram.h"
#include "ObjectSerializer.h"
Expand Down Expand Up @@ -197,6 +198,24 @@ void GCodeProgram::reset()
currentLine = lines.end();
}

bool GCodeProgram::getAuxInformation(GCodeProgram::AuxInfoT& info) const
{
std::regex re("^\\(--(\\w+)=([^)]+)\\)$");
std::smatch match;
bool found = false;
for (auto it = lines.begin(); it != lines.end(); ++it) {
if (std::regex_match
(*it, match, re) && match.size() > 2) {
std::string key = match.str(1);
std::string value = match.str(2);
info.emplace(key, value);
found = true;
}

}
return found;
}

void GCodeProgram::clearErrors()
{
errors.clear();
Expand Down
4 changes: 4 additions & 0 deletions Kernel/GCodeProgram.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ along with this program.If not, see <http://www.gnu.org/licenses/>.
#pragma once
#include <vector>
#include <list>
#include <map>
#include <iostream>
#include "ParserContext.h"

Expand Down Expand Up @@ -74,6 +75,9 @@ class GCodeProgram :
bool step(); // one program line, true if there's still stuff to do
void reset(); // ready for start or run

typedef std::map<std::string, std::string> AuxInfoT;
bool getAuxInformation(AuxInfoT& info) const;

// Error reporting
void clearErrors();
bool hasError();
Expand Down
Binary file modified Splsh16.bmp
Binary file not shown.
Loading

0 comments on commit bad2d3c

Please sign in to comment.