vlachoudis / bCNC

GRBL CNC command sender, autoleveler and g-code editor
GNU General Public License v2.0
1.57k stars 533 forks source link

Heightmap plugin exception raised #1511

Open creat1c opened 3 years ago

creat1c commented 3 years ago

I am trying to work with a heightmap image but seemingly the plugin aborts with the message shown below. I've attached the image and screenshots of the settings as well.

Traceback (most recent call last): File "c:\python37\lib\site-packages\bCNC\Utils.py", line 465, in __call__ return self.func(*args) File "c:\python37\lib\site-packages\bCNC\lib\tkExtra.py", line 866, in handleKey active = unicode(self.get(ACTIVE)) NameError: name 'unicode' is not defined Traceback (most recent call last): File "c:\python37\lib\site-packages\bCNC\Utils.py", line 465, in __call__ return self.func(*args) File "c:\python37\lib\site-packages\bCNC\lib\tkExtra.py", line 866, in handleK ey active = unicode(self.get(ACTIVE)) NameError: name 'unicode' is not defined Traceback (most recent call last): File "c:\python37\lib\site-packages\bCNC\Utils.py", line 465, in __call__ return self.func(*args) File "c:\python37\lib\site-packages\bCNC\lib\tkExtra.py", line 866, in handleK ey active = unicode(self.get(ACTIVE)) NameError: name 'unicode' is not defined Traceback (most recent call last): File "c:\python37\lib\site-packages\bCNC\Utils.py", line 465, in __call__ return self.func(*args) File "c:\python37\lib\site-packages\bCNC\lib\tkExtra.py", line 866, in handleK ey active = unicode(self.get(ACTIVE)) NameError: name 'unicode' is not defined Traceback (most recent call last): File "c:\python37\lib\site-packages\bCNC\Utils.py", line 465, in __call__ return self.func(*args) File "c:\python37\lib\site-packages\bCNC\lib\tkExtra.py", line 866, in handleK ey active = unicode(self.get(ACTIVE)) NameError: name 'unicode' is not defined Traceback (most recent call last): File "c:\python37\lib\site-packages\bCNC\Utils.py", line 465, in __call__ return self.func(*args) File "c:\python37\lib\site-packages\bCNC\ToolsPage.py", line 1746, in execute self.tools.getActive().execute(self.app) File "c:\python37\lib\site-packages\bCNC\plugins\heightmap.py", line 326, in e xecute MAT.pad_w_zeros(TOOL) File "c:\python37\lib\site-packages\bCNC\lib\imageToGcode.py", line 823, in pa d_w_zeros temp[to:to+w, to:to+h] = self.matrix TypeError: slice indices must be integers or None or have an __index__ method

schild_height_frei

heightmap_setttings endmill_settings

GitHubCaps commented 3 years ago

@creat1c Are you using the most recent version of bCNC?

I just ran this without a problem using Python 3.8.2

image

output using your endmill settings:

(Block-name: Header)
(Block-expand: 0)
(Block-enable: 1)
M3 S12000
G4 P3
G0 Z10
(Block-name: test)
(Block-expand: 1)
(Block-enable: 1)
(Size: 100 x 45 x 1)
(Endmill shape: Ball End , Diameter: 2.400)

G0 Z3.0000
F1200.0000
F500.0000
G0 X27.6872 Y44.9127
F1200.0000
G1 Z-0.1289
 X28.0479 Z-0.4084
 X72.1489
 X72.5097 Z-0.1289
F500.0000
G0 Z3.0000
 X72.7803 Y44.0109
F1200.0000
G1 Z-0.1027
 X72.2391 Z-0.5120
 X66.7378 Z-0.5154
 X27.9577 Z-0.5120
 X27.4166 Z-0.1027
F500.0000
G0 Z3.0000
 X27.1460 Y43.1090
F1200.0000
G1 Z-0.1027
 X27.5068 Z-0.2896
 X72.6901
 X73.0508 Z-0.1138
F500.0000
G0 Z3.0000
 X73.7723 Y42.2071
F1200.0000
G1 Z-0.1138
 X73.3214 Z-0.2825
 X26.8755
 X26.4246 Z-0.1138
F500.0000
G0 Z3.0000
 X25.3423 Y41.3053
F1200.0000
G1 Z-0.1027
 X25.8834 Z-0.2825
 X74.3134 Z-0.2789
 X74.8545 Z-0.1138
F500.0000
G0 Z3.0000
 X85.9474 Y40.4034
F1200.0000
G1 Z-0.1289
 X85.6769 Z-0.2825
 X14.5200
 X14.2494 Z-0.1289
F500.0000
G0 Z3.0000
 Y39.5015
F1200.0000
G1 Z-0.1289
 X14.5200 Z-0.2507
 X85.6769
 X85.9474 Z-0.1289
F500.0000
G0 Z3.0000
 X99.2950 Y38.5997
F1200.0000
G1 Z-0.1027
 X86.4886 Z-0.1795
 X85.9474 Z-0.3348
 X85.4063 Z-0.2198
 X14.7905
 X14.2494 Z-0.3348
 X13.7083 Z-0.1795
 X0.9019 Z-0.1027
F500.0000
G0 Z3.0000
 X0.6313 Y37.6978
F1200.0000
G1 Z-0.1289
 X1.1724 Z-0.6241
 X12.9868 Z-0.6275
 X14.7905 Z-0.2198
 X85.4063
 X87.1199 Z-0.6241
 X95.8679 Z-0.6284
 X98.9342 Z-0.6250
 X99.5655 Z-0.1214
F500.0000
G0 Z3.0000
 X100.1067 Y36.7960
F1200.0000
G1 Z-0.1795
 X99.2048 Z-0.5724
 X86.9395 Z-0.5686
 X85.4063 Z-0.2198
 X14.7905
 X13.2574 Z-0.5680
 X1.0822 Z-0.5724
 X0.5411 Z-0.1289
F500.0000
G0 Z3.0000
 Y35.8941
F1200.0000
G1 Z-0.1289
 X1.0822 Z-0.5724
 X13.1672 Z-0.5715
 X14.7905 Z-0.2198
 X85.4063
 X87.0297 Z-0.5715
 X99.0244
 X100.1067 Z-0.1795
F500.0000
G0 Z3.0000
 X99.5655 Y34.9922
F1200.0000
G1 Z-0.1214
 X99.0244 Z-0.5814
 X98.7539 Z-0.6284
 X87.1199 Z-0.6241
 X85.4063 Z-0.2198
 X14.7905
 X13.0770 Z-0.6241
 X1.6234 Z-0.6275
 X1.1724 Z-0.6241
 X0.6313 Z-0.1289
F500.0000
G0 Z3.0000
 X0.8117 Y34.0904
F1200.0000
G1 Z-0.1027
 X1.4430 Z-0.7140
 X1.8037 Z-0.7240
 X12.9868 Z-0.7205
 X14.7905 Z-0.2198
 X85.4063
 X87.3002 Z-0.7240
 X98.6637 Z-0.7205
 X99.2950 Z-0.1327
F500.0000
G0 Z3.0000
 X99.3852 Y33.1885
F1200.0000
G1 Z-0.1027
 X98.7539 Z-0.7067
 X98.4833 Z-0.7076
 X87.2100
 X85.4063 Z-0.2198
 X14.7905
 X12.9868 Z-0.7067
 X1.4430 Z-0.7033
 X0.8117 Z-0.1027
F500.0000
G0 Z3.0000
 X0.6313 Y32.2867
F1200.0000
G1 Z-0.1289
 X1.1724 Z-0.6198
 X13.0770 Z-0.6232
 X14.7905 Z-0.2198
 X85.4063
 X87.0297 Z-0.6191
 X98.6637 Z-0.6232
 X99.0244 Z-0.5814
 X99.5655 Z-0.1214
F500.0000
G0 Z3.0000
 X100.1067 Y31.3848
F1200.0000
G1 Z-0.1795
 X99.2950 Z-0.5680
 X86.9395
 X85.4063 Z-0.2198
 X14.7905
 X13.2574 Z-0.5680
 X1.0822
 X0.5411 Z-0.1289
F500.0000
G0 Z3.0000
 Y30.4829
F1200.0000
G1 Z-0.1289
 X1.0822 Z-0.5724
 X3.5173 Z-0.5758
 X13.1672 Z-0.5733
 X14.7905 Z-0.2198
 X85.4063
 X87.0297 Z-0.5724
 X99.2950
 X99.6557 Z-0.2845
 X100.1067 Z-0.1795
F500.0000
G0 Z3.0000
 X99.5655 Y29.5811
F1200.0000
G1 Z-0.1214
 X98.9342 Z-0.6241
 X97.9422 Z-0.6284
 X87.3002 Z-0.6275
 X85.4063 Z-0.2198
 X14.7905
 X12.9868 Z-0.6284
 X1.3528
 X0.6313 Z-0.1214
F500.0000
G0 Z3.0000
 X0.9019 Y28.6792
F1200.0000
G1 Z-0.1327
 X1.5332 Z-0.7240
 X5.1406 Z-0.7248
 X11.0027 Z-0.7205
 X11.6340 Z-0.5095
 X13.5279 Z-0.4358
 X14.7003 Z-0.2198
 X85.4965
 X86.6689 Z-0.4358
 X88.5628 Z-0.5095
 X89.1941 Z-0.7240
 X98.6637
 X99.2950 Z-0.1327
F500.0000
G0 Z3.0000
 X99.3852 Y27.7773
F1200.0000
G1 Z-0.1027
 X98.7539 Z-0.7067
 X98.3931 Z-0.7076
 X90.5469 Z-0.7067
 X89.7353 Z-0.4846
 X86.8493 Z-0.2198
 X13.3476
 X10.4616 Z-0.4846
 X9.5597 Z-0.7033
 X1.4430 Z-0.7067
 X0.8117 Z-0.1027
F500.0000
G0 Z3.0000
 X0.6313 Y26.8755
F1200.0000
G1 Z-0.1289
 X1.3528 Z-0.6232
 X8.2971 Z-0.6198
 X11.8144 Z-0.2198
 X88.3825
 X91.8997 Z-0.6232
 X97.5815
 X98.9342 Z-0.6198
 X99.5655 Z-0.1214
F500.0000
G0 Z3.0000
 X100.1067 Y25.9736
F1200.0000
G1 Z-0.2411
 X99.3852 Z-0.5680
 X93.3427
 X89.9156 Z-0.2198
 X10.1910
 X6.8541 Z-0.5680
 X1.0822
 X0.5411 Z-0.1289
F500.0000
G0 Z3.0000
 Y25.0718
F1200.0000
G1 Z-0.1289
 X1.0822 Z-0.5724
 X4.2388 Z-0.5758
 X7.3051 Z-0.4358
 X8.6579 Z-0.2198
 X91.5390
 X94.8759 Z-0.5724
 X99.2950
 X99.6557 Z-0.2845
 X100.1067 Z-0.1795
F500.0000
G0 Z3.0000
 X99.5655 Y24.1699
F1200.0000
G1 Z-0.1214
 X98.8441 Z-0.6284
 X96.5894
 X93.0721 Z-0.2198
 X7.1247
 X3.6074 Z-0.6241
 X1.6234 Z-0.6284
 X1.1724 Z-0.5814
 X0.6313 Z-0.1214
F500.0000
G0 Z3.0000
 X0.9019 Y23.2680
F1200.0000
G1 Z-0.1327
 X1.6234 Z-0.7248
 X2.4350
 X3.0663 Z-0.4671
 X5.5915 Z-0.2198
 X94.6053
 X97.1305 Z-0.4671
 X97.7618 Z-0.7205
 X98.6637 Z-0.7240
 X99.2950 Z-0.1327
F500.0000
G0 Z3.0000
 X99.3852 Y22.3662
F1200.0000
G1 Z-0.1027
 X98.6637 Z-0.7067
 X97.6716 Z-0.7033
 X97.0403 Z-0.4567
 X95.7777 Z-0.4397
 X94.5151 Z-0.2198
 X5.6817
 X4.4191 Z-0.4397
 X3.1565 Z-0.4567
 X2.5252 Z-0.7033
 X1.5332 Z-0.7067
 X0.8117 Z-0.1027
F500.0000
G0 Z3.0000
 X0.6313 Y21.4643
F1200.0000
G1 Z-0.1289
 X1.1724 Z-0.6198
 X3.7878
 X7.3051 Z-0.2198
 X92.8918
 X96.4090 Z-0.6198
 X99.0244
 X99.5655 Z-0.1289
F500.0000
G0 Z3.0000
 X100.1067 Y20.5624
F1200.0000
G1 Z-0.2411
 X99.3852 Z-0.5671
 X94.6053 Z-0.5610
 X91.3586 Z-0.2198
 X8.8382
 X5.5014 Z-0.5637
 X1.1724 Z-0.5671
 X0.5411 Z-0.1289
F500.0000
G0 Z3.0000
 Y19.6606
F1200.0000
G1 Z-0.1289
 X1.2626 Z-0.5767
 X7.0345 Z-0.5733
 X10.3714 Z-0.2198
 X89.8254
 X93.1623 Z-0.5733
 X99.1146 Z-0.5767
 X100.1067 Z-0.1795
F500.0000
G0 Z3.0000
 X99.5655 Y18.7587
F1200.0000
G1 Z-0.1027
 X98.9342 Z-0.6327
 X91.8095
 X88.2021 Z-0.2198
 X11.9948
 X8.3873 Z-0.6318
 X1.2626
 X0.6313 Z-0.1214
F500.0000
G0 Z3.0000
 X0.9019 Y17.8569
F1200.0000
G1 Z-0.1327
 X1.5332 Z-0.7378
 X4.7799 Z-0.7412
 X9.6499 Z-0.7378
 X10.6420 Z-0.4846
 X13.5279 Z-0.2198
 X86.6689
 X89.5549 Z-0.4846
 X90.5469 Z-0.7378
 X98.6637 Z-0.7412
 X99.2950 Z-0.1327
F500.0000
G0 Z3.0000
 X99.3852 Y16.9550
F1200.0000
G1 Z-0.1027
 X98.7539 Z-0.6974
 X96.7698 Z-0.6990
 X89.1039 Z-0.6974
 X85.4063 Z-0.2198
 X14.7905
 X11.0929 Z-0.6974
 X1.4430
 X0.8117 Z-0.1027
F500.0000
G0 Z3.0000
 X0.6313 Y16.0531
F1200.0000
G1 Z-0.1289
 X1.1724 Z-0.6155
 X3.5173 Z-0.6198
 X13.0770 Z-0.6189
 X14.7905 Z-0.2198
 X85.4063
 X87.0297 Z-0.6155
 X98.5735 Z-0.6189
 X99.0244 Z-0.6155
 X99.5655 Z-0.1289
F500.0000
G0 Z3.0000
 X100.1067 Y15.1513
F1200.0000
G1 Z-0.2411
 X99.3852 Z-0.5637
 X98.5735 Z-0.5671
 X86.9395
 X85.4063 Z-0.2198
 X14.7905
 X13.2574 Z-0.5637
 X1.1724 Z-0.5671
 X0.5411 Z-0.1289
F500.0000
G0 Z3.0000
 Y14.2494
F1200.0000
G1 Z-0.1289
 X1.0822 Z-0.5733
 X7.3051 Z-0.5767
 X13.2574 Z-0.5686
 X14.7905 Z-0.2198
 X85.4063
 X87.0297 Z-0.5758
 X99.2048 Z-0.5733
 X99.6557 Z-0.2285
 X100.1067 Z-0.1289
F500.0000
G0 Z3.0000
 X99.5655 Y13.3476
F1200.0000
G1 Z-0.1027
 X98.9342 Z-0.6284
 X87.1199
 X85.4063 Z-0.2198
 X14.7905
 X13.0770 Z-0.6284
 X1.4430
 X1.1724 Z-0.5814
 X0.6313 Z-0.1214
F500.0000
G0 Z3.0000
 X0.9019 Y12.4457
F1200.0000
G1 Z-0.1327
 X1.6234 Z-0.7283
 X12.9868 Z-0.7248
 X14.7905 Z-0.2198
 X85.4063
 X87.2100 Z-0.7248
 X98.6637
 X99.2950 Z-0.1327
F500.0000
G0 Z3.0000
 X99.3852 Y11.5438
F1200.0000
G1 Z-0.1027
 X98.7539 Z-0.7033
 X98.4833 Z-0.7076
 X87.2100 Z-0.7067
 X85.4063 Z-0.2198
 X14.7905
 X12.9868 Z-0.7076
 X1.9841 Z-0.7067
 X1.4430 Z-0.7033
 X0.8117 Z-0.1214
F500.0000
G0 Z3.0000
 X0.6313 Y10.6420
F1200.0000
G1 Z-0.1289
 X1.1724 Z-0.6189
 X1.4430 Z-0.6198
 X13.1672 Z-0.6191
 X14.7905 Z-0.2198
 X85.4063
 X87.0297 Z-0.6191
 X99.0244 Z-0.6198
 X99.5655 Z-0.1289
F500.0000
G0 Z3.0000
 X100.1067 Y9.7401
F1200.0000
G1 Z-0.2411
 X99.3852 Z-0.5671
 X87.0297
 X85.4063 Z-0.2198
 X14.7905
 X13.2574 Z-0.5671
 X1.8939 Z-0.5680
 X1.0822 Z-0.5637
 X0.5411 Z-0.1289
F500.0000
G0 Z3.0000
 Y8.8382
F1200.0000
G1 Z-0.1289
 X0.9920 Z-0.5248
 X1.3528 Z-0.5767
 X13.0770 Z-0.5758
 X14.7905 Z-0.2198
 X85.4063
 X87.1199 Z-0.5758
 X99.2048 Z-0.5767
 X99.6557 Z-0.2285
 X100.1067 Z-0.1289
F500.0000
G0 Z3.0000
 X99.5655 Y7.9364
F1200.0000
G1 Z-0.1027
 X98.9342 Z-0.6327
 X87.1199 Z-0.6318
 X85.4063 Z-0.2198
 X14.7905
 X13.0770 Z-0.6318
 X1.4430
 X1.1724 Z-0.5814
 X0.6313 Z-0.1214
F500.0000
G0 Z3.0000
 X1.0822 Y7.0345
F1200.0000
G1 Z-0.1027
 X13.7083 Z-0.1289
 X14.3396 Z-0.3078
 X85.8572
 X86.4886 Z-0.1289
 X99.1146 Z-0.1027
F500.0000
G0 Z3.0000
 X85.9474 Y6.1327
F1200.0000
G1 Z-0.1289
 X85.6769 Z-0.2507
 X14.5200
 X14.2494 Z-0.1289
F500.0000
G0 Z3.0000
 Y5.2308
F1200.0000
G1 Z-0.1289
 X14.4298 Z-0.2411
 X23.7190 Z-0.2753
 X76.6583
 X85.7671 Z-0.2411
 X85.9474 Z-0.1289
F500.0000
G0 Z3.0000
 X74.7643 Y4.3289
F1200.0000
G1 Z-0.1027
 X74.2232 Z-0.2825
 X26.0638 Z-0.2789
 X25.5227 Z-0.1138
F500.0000
G0 Z3.0000
 X26.5147 Y3.4271
F1200.0000
G1 Z-0.1138
 X26.9657 Z-0.2825
 X73.2312 Z-0.2789
 X73.6821 Z-0.1138
F500.0000
G0 Z3.0000
 X72.9606 Y2.5252
F1200.0000
G1 Z-0.1214
 X72.5999 Z-0.3114
 X27.5970
 X27.2362 Z-0.1214
F500.0000
G0 Z3.0000
 X27.5068 Y1.6234
F1200.0000
G1 Z-0.1327
 X28.1381 Z-0.5172
 X72.0588
 X72.6901 Z-0.1327
F500.0000
G0 Z3.0000
 X72.5097 Y0.7215
F1200.0000
G1 Z-0.1289
 X71.9686 Z-0.6115
 X71.3373 Z-0.6128
 X28.2283 Z-0.6120
 X27.6872 Z-0.1289
F500.0000
G0 Z3.0000
 X27.8675 Y0.0000
F1200.0000
G1 Z-0.1289
 X28.3185 Z-0.5248
 X29.4909 Z-0.5422
 X71.6980 Z-0.5388
 X72.2391 Z-0.1289
G0 Z3.0000

(Block-name: Footer)
(Block-expand: 0)
(Block-enable: 1)
G0 Z10
M5
GitHubCaps commented 3 years ago

Test with conical bit: Screenshot_2021-01-09_13-18-01

creat1c commented 3 years ago

I didn't use 3.8.2 initially, but now verified the behaviour is similar (see below). Also the version of bCNC is 0.9.14 which is what was installed by py -m pip install bCNC

From the error is seems like there might be an issue with the end mill settings? I tried using the exact settings in the screenshot but to no avail.

Am I correct in the assumption that it uses whatever tool was selected from the endmill menu? My Workflow was: Click "End mill" -> Setup endmill values Open menu CAM, submenu Generators, Heightmap Select file Click the "heightmap" execute button Works for 1-2 sec, then the error is shown.

Also, i tried this on my windows machine as well as the rPI connected to my mill, with comparable results.

Traceback (most recent call last): File "E:\Python\3.8.2\lib\site-packages\bCNC\Utils.py", line 526, in __call__ return self.func(*args) File "E:\Python\3.8.2\lib\site-packages\bCNC\ToolsPage.py", line 1747, in exec ute self.tools.getActive().execute(self.app) File "E:\Python\3.8.2\lib\site-packages\bCNC\plugins\heightmap.py", line 326, in execute MAT.pad_w_zeros(TOOL) File "E:\Python\3.8.2\lib\site-packages\bCNC\lib\imageToGcode.py", line 823, i n pad_w_zeros temp[to:to+w, to:to+h] = self.matrix TypeError: slice indices must be integers or None or have an __index__ method

creat1c commented 3 years ago

I was able to get the plugin to work by changing imagetogcode.py, line 823 to read

self.t_offset = int((ts-1)/2)

GitHubCaps commented 3 years ago

Honestly, this is very puzzling. I haven't seen any issues with the heightmap plugin or its dependency imageToGcode before and like I said, it works for me without modifying. I do know that there are some improvements to be made for both, but nothing that has stopped it from running before. In my opinion, there seems to be varying results by users, but why? I tested in py2 and py3 and it simply worked.

creat1c commented 3 years ago

The issue seemed to be that this line was previously (without the cast to an int) was evaluated to a float. This seemingly caused the downstream issue with the indexing. All I did was to add the cast to an int and now it works.

As to why this happened, i am unsure. Within my debugger, ts had the value 3 so (3-1)/2=2 which should be an integer? Not a huge python pro, so I am at a loss here, too.

If you have any ideas how I can test further, ill gladly to it, to ensure this does not happen for anyone else.

GitHubCaps commented 3 years ago

@creat1c My apologies! Just realized that I used my own image2gode instead of imageToGcode.

I have a fixed version that doesn't cast to integer, but instead uses self.t_offset = (ts-1)//2 I will put it here for you to try. Hopefully soon, I will commit/push it here.

This one fixes all deprecation issues for py2 and py3! imageToGcode.py.zip

creat1c commented 3 years ago

Ah! Thanks for checking. One more question I had - is the step size normally dependant on the milling bit? It used a very fine grid (0.1 mm) instead of the milling bit i selected (1mm) and I was wondering if my fix has some side effect?

GitHubCaps commented 3 years ago

The Stepover % is percentage of bit diameter to move the bit over. For example, 40.0 moves the bit by 40% of bit diameter on next pass. I have a better heightmap plugin that allows for using both finish and roughing bits and does not really on the endmill database. It also has finer grain control. Give me a little while and I will put it and the actual lib I use here for you to test out, it is way better (imho) than what is provided in bCNC (it just has a basic implementation)

GitHubCaps commented 3 years ago

@creat1c BTW, could you reopen this until it's committed? This still effects py3 ATM

creat1c commented 3 years ago

Sure.

If you need someone to betatest the new script, I can do that.