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

First pass at laser control including dynamic power control #431

Open
wants to merge 3 commits into
base: edge
Choose a base branch
from

Conversation

mhlong10
Copy link
Contributor

@mhlong10 mhlong10 commented Nov 23, 2019

This is a simple set of changes which are be beginnings of my attempt at laser control. This uses a tool (tool 32 for now) to specify laser mode and M3 for immediate control and M4 for dynamic laser power based on velocity.

I'm not sure if this is the best approach but it works really well and is simple.

I've change my settings to run the PWM at 2khz and scale the power from 0 to 100% using S0 to S100. None of this is required to make this work, however the segments are run at about 1.5ms so updates to the PWM are at this rate. It doesn't make sense to have PWM at frequencies below 1/1.5ms. In fact 2khz is only slightly above nyquist... and segment times can run quicker. Here are my PWM and spindle settings:

{p1:n}
{"r":{"p1":{"frq":2000,"csl":0,"csh":100,"cpl":0,"cph":1,"wsl":0,"wsh":100,"wpl":0,"wph":1,"pof":0}},"f":[1,0,8]}
{"sr":{"stat":4}}

{sp:n}
{"r":{"sp":{"mo":2,"ph":1,"de":0,"sn":0,"sm":1000,"ep":1,"dp":0,"oe":0,"o":0,"c":0,"s":0}},"f":[1,0,8]}
{"sr":{"stat":4}}

Note - I'm new to working with this project so not sure of best process to simply show people changes. I created a PR thinking it was going to be against my fork. I don't know git that well and have never used forks before.

@giseburt
Copy link
Member

This is fascinating. A pull request is the ideal way to bring this up. Thank you.

I’ll look this over as soon as I can.

@mhlong10
Copy link
Contributor Author

My comment in #422 shows a couple of pictures and a video of this running (if you stay to the very end there is a close up of the resulting laser marking - very clean).

g2core/spindle.cpp Outdated Show resolved Hide resolved
g2core/spindle.cpp Outdated Show resolved Hide resolved
@justinclift
Copy link
Member

Note - I'm new to working with this project so not sure of best process to simply show people changes. I created a PR thinking it was going to be against my fork. I don't know git that well and have never used forks before.

You've set up the PR correctly (eg from a branch of your fork, to a target branch - edge - here), so no stress. 😄

It sometimes takes people a few goes to get the hang of the forking/branching model GitHub uses, but it looks like you got it right first time around. 😁

@@ -180,6 +180,11 @@ static void _exec_spindle_control(float *value, bool *flag)
spindle.direction = control;
spindle.state = control;
spinup_delay = true;
if (cm_is_laser_tool() && spindle.direction == SPINDLE_CCW) {
// Since dynamic laser mode relies on spindle override to scale
// the power, ensure it is initialize when transitioning into this state.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initialize -> initialized

// if (fabs(spindle_override - spindle.override_factor) >= 0.01) {
// Only update if the change is worth while (at least 1%)
spindle.override_factor = spindle_override;
pwm_set_duty(PWM_1, _get_spindle_pwm(spindle, pwm));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: This is where I would adjust the i2c code if we were controlling a digital pot for plasma power settings.

@tomashx
Copy link

tomashx commented Apr 6, 2022

@mhlong10 this change, is it working for your CNC laser? Do you have a router also on your CNC?

@mhlong10
Copy link
Contributor Author

mhlong10 commented Apr 6, 2022

@tomashx I use the same CNC machine with a router and laser. This code has been working fine for a couple years now.

@kbrown73
Copy link

Hello @mhlong10. I've only just found this yesterday and have also read #422. Sounds like you've cracked the Da Vinci gcode for g2core laser engravers :) I'm curious if you're still using this or has there been other more "official" advancements recently?

I've recently converted my old Chinese CNC 3040Z-DQ to use Arduino Due + gShield and g2core. I've bolted a 5W diode laser head to the spindle holder as well and have hard wired the the setup electronically so that CW direction signal enables the spindle and CCW enables the laser head. Does this sound similar to your setup?

Also what is the best way of getting your changes? Your fork looks untouched for a number of years now.

Many thanks!

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

Successfully merging this pull request may close these issues.

6 participants