Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: different travel color to distinguish air-cutting and actual-cutting in CNC #183

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

xuzhen1994
Copy link

different travel color to distinguish air-cutting and actual-cutting in CNC.

…-cutting in CNC

different travel color to distinguish air-cutting and actual-cutting in CNC.
@remcoder
Copy link
Member

remcoder commented Jul 16, 2024

Hello @xuzhen1994 ! Thanks for your PR! 😄

It's great to have better support for CNC!

However, defining travel at z <= 0 as cutting is not true in general. Sometimes the z = 0 is defined at the bottom of the stock, sometimes at the top. And for true 3d milling cutting/not-cutting is totally different story.

Have you looked at the nonTravelMoves option? Could be useful, depending on your gcode.

Otherwise, maybe you can create a function parameter so that you can pass the logic that works for your case:

const preview = GCodePreview.init({
      canvas: document.querySelector('canvas'),
      travelColor: (start, end) => start.z > 0 ||  end.z > 0 ? 'green' : 'red'
});

Here start and end would be the states (x,y,z etc) at the start and end of the line segment.

@remcoder
Copy link
Member

Also, could you share a gcode snippet for your case please?

add isActualCutting option to support user custom actual-cutting logic.
add cutting distance calculation includes total-cutting, actual-cutting and air-cutting for a gcode file.
@xuzhen1994
Copy link
Author

xuzhen1994 commented Jul 19, 2024

@remcoder Thanks for your suggestion!
I have added the isActualCutting option to support users in customizing the logic for actual-cutting. In addition to color distinction, I have also added statistics for the actual-cutting distance and air-cutting distance.
I would like to calculate the cutting duration as well, but currently the gcode parser cannot parse the F parameter and the S parameter. I will work on improving this when I have time in the future.
Also, this is my first time using the TypeScript language, so please let me know if there are any issues. Thanks again!

@xuzhen1994
Copy link
Author

my gcode

T1
G43 H1
M03 S18000
G00 X176.604 Y554.890
G00 Z10.000 
F4000
G01 Z-12.100
F12000
G02 X183.675 Y561.961 I3.536 J3.536
G02 X176.604 Y554.890 I-3.536 J-3.536
F4000
G00 Z20.000 
G00 X-4.000 Y785.175
G00 Z10.000 
G01 Z-12.100
F12000
G02 X-0.000 Y789.175 I4.000 J0.000
G01 X380.139 Y789.175
G02 X384.139 Y785.175 I0.000 J-4.000
G01 X384.139 Y331.675
G02 X380.139 Y327.675 I-4.000 J0.000
F4000
G00 Z20.000 
G00 X457.500 Y323.675
G00 Z10.000 
G01 Z-12.100
F12000
G02 X461.500 Y327.675 I4.000 J0.000
G01 X915.000 Y327.675
G02 X919.000 Y323.675 I-0.000 J-4.000
F4000
G00 Z20.000 
G00 X457.500 Y256.000
G00 Z10.000 
G01 Z-12.100
F12000
G03 X453.500 Y260.000 I-4.000 J0.000
F4000
G00 Z20.000 
G00 X457.500 Y176.000
G00 Z10.000 
G01 Z-12.100
F12000
G03 X461.500 Y172.000 I4.000 J0.000
F4000
G00 Z20.000 
G00 X457.500 Y168.000
G00 Z10.000 
G01 Z-12.100
F12000
G03 X453.500 Y172.000 I-4.000 J0.000
F4000
G00 Z20.000 
G00 X457.500 Y88.000
G00 Z10.000 
G01 Z-12.100
F12000
G03 X461.500 Y84.000 I4.000 J0.000
F4000
G00 Z20.000 
G00 X457.500 Y80.000
G00 Z10.000 
G01 Z-12.100
F12000
G03 X453.500 Y84.000 I-4.000 J0.000
F4000
G00 Z20.000 
G00 X457.500 Y0.000
G00 Z10.000 
G01 Z-12.100
F12000
G02 X453.500 Y-4.000 I-4.000 J0.000
F4000
G00 Z20.000 
G00 X461.500 Y-4.000
G00 Z10.000 
G01 Z-12.100
F12000
G02 X457.500 Y-0.000 I-0.000 J4.000
G01 X457.500 Y80.000
G02 X461.500 Y84.000 I4.000 J0.000
G01 X915.000 Y84.000
G03 X919.000 Y88.000 I0.000 J4.000
F4000
G00 Z20.000 
G00 X915.000 Y84.000
G00 Z10.000 
G01 Z-12.100
F12000
G02 X919.000 Y80.000 I-0.000 J-4.000
F4000
G00 Z20.000 
G00 X915.000 Y172.000
G00 Z10.000 
G01 Z-12.100
F12000
G03 X919.000 Y176.000 I-0.000 J4.000
F4000
G00 Z20.000 
G00 X919.000 Y256.000
G00 Z10.000 
G01 Z-12.100
F12000
G03 X915.000 Y260.000 I-4.000 J0.000
F4000
G00 Z20.000 
G00 X919.000 Y264.000
G00 Z10.000 
G01 Z-12.100
F12000
G02 X915.000 Y260.000 I-4.000 J0.000
G01 X461.500 Y260.000
G03 X457.500 Y256.000 I-0.000 J-4.000
G01 X457.500 Y176.000
G02 X453.500 Y172.000 I-4.000 J0.000
G01 X0.000 Y172.000
G03 X-4.000 Y168.000 I-0.000 J-4.000
F4000
G00 Z20.000 
G00 X0.000 Y172.000
G00 Z10.000 
G01 Z-12.100
F12000
G02 X-4.000 Y176.000 I-0.000 J4.000
F4000
G00 Z20.000 
G00 X-0.000 Y260.000
G00 Z10.000 
G01 Z-12.100
F12000
G02 X-4.000 Y264.000 I0.000 J4.000
F4000
G00 Z20.000 
G00 X-4.000 Y323.675
G00 Z10.000 
G01 Z-12.100
F12000
G02 X-0.000 Y327.675 I4.000 J0.000
F4000
G00 Z20.000 
G00 X-4.000 Y331.675
G00 Z10.000 
G01 Z-12.100
F12000
G03 X0.000 Y327.675 I4.000 J0.000
G01 X453.500 Y327.675
G02 X457.500 Y323.675 I0.000 J-4.000
G01 X457.500 Y264.000
G02 X453.500 Y260.000 I-4.000 J0.000
G01 X-0.000 Y260.000
G03 X-4.000 Y256.000 I0.000 J-4.000
F4000
G00 Z20.000 
G00 X-4.000 Y88.000
G00 Z10.000 
G01 Z-12.100
F12000
G03 X-0.000 Y84.000 I4.000 J0.000
F4000
G00 Z20.000 
G00 X-4.000 Y80.000
G00 Z10.000 
G01 Z-12.100
F12000
G02 X-0.000 Y84.000 I4.000 J0.000
G01 X453.500 Y84.000
G03 X457.500 Y88.000 I0.000 J4.000
G01 X457.500 Y168.000
G02 X461.500 Y172.000 I4.000 J0.000
G01 X915.000 Y172.000
G02 X919.000 Y168.000 I0.000 J-4.000
F4000
G00 Z20.000 
G00 X461.500 Y260.000
G00 Z10.000 
G01 Z-12.100
F12000
G02 X457.500 Y264.000 I0.000 J4.000
F4000
G00 Z20.000 
M05
M17
M30

@remcoder
Copy link
Member

Hi again! Thanks for the improvements.
The library is for 3d printing too where 'cutting' doesn't exist. That's why I suggested passing in an option for the color, making it generic.
But my suggestion will not work if you want to track the total cutting distance.

I think that for both the (non)-cutting color and distance I'm looking for a solution that isn't specific to cnc. At least the default will need to work where cutting doesn't work or is defined differently.

Let us know if you can work it out. Also feel free to join the discord to discuss this 🙂

add travel duration calculate
@remcoder
Copy link
Member

hi @xuzhen1994!

Nice proposal but we need to keep the library working for other (non-cnc) usecases too.

For the color changing (z <= 0) I want to remind you of my proposal to define a function that will decide on the travel color using arbitrary logic. That would be a simple generic solution that I can merge.

Furthermore, keeping the stats for cutting don't belong in the webglpreview class. (in fact the class already does too much so we're discussing on discord how to split it up)

The best way would be to move the cutting stats to the parser:

  • create a variant (subclass?) of the parser that tracks the cutting.
  • add the stats to the layer object

Let's do the color change in 1 PR and the stats in another PR. That keeps it simple and moving.

@remcoder
Copy link
Member

@xuzhen1994 I have to apologize. My proposal isn't as easy as I thought.. The reason is that the library groups lines into layers because that's useful for 3d printing. Lines within a layer a rendered in a single go and all consecutive travel lines will share a single color.

To enable different travel colors, the lines will need to be ungrouped (or not grouped to begin with).

I would like to help out with getting this solved. I cannot push to your fork however. Would you be ok with allowing me to do so?

@xuzhen1994
Copy link
Author

Thanks for the advice. Apologies, due to work and effort, I can't promise to finish your proposal by a certain time. I have invited you as collaborator, and let me know if you need anything else.

@remcoder
Copy link
Member

@xuzhen1994 I added some commits and you can see the different travel colors working. Still very hacky and not mergable. I'll clean it up later to get it mergable but then I have to leave out the statistics part (for reasons mentioned above).

@remcoder
Copy link
Member

btw, I already have push access to your branch so I don't need to be added to the repo. I'll decline that invite because it is not needed, thanks anyway.

@remcoder
Copy link
Member

I just realized that there could be a 'cnc mode'. We're probably introducing modes for different views and a cnc mode could fit into that scheme. Let's wait far those modes to land first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants