[grbl Issue#1611] Modify grbl for CNC model

未分类 bolang 6个月前 (10-14) 42次浏览

Issue #1611 | 状态: 已关闭 | 作者: SanZamoyski | 创建时间: 2020-03-02


Hi and hello,

I know it is NOT an issue, but I need your help as I’m trying to resolve this for two days…
My goal is to change spindle behavior to:
* when it is on – PWM 50%,
* when off – LOW
* when on AND Z-Work Position < 0, PWM 100%. I was trying alot of variables and in many places of the code, but with no luck. I've ended with report.c file on line ~522 (under float wco[]) - it is place where WPos/MPos are calculated, before it is printed. I have this (dirty) code here: ``
if(currentposition[ZAXIS] – gcstate.coordsystem[ZAXIS]+gcstate.coordoffset[ZAXIS] <= 0){ pinMode(13, 1); digitalWrite(13, 1); }else{ pinMode(13, 1); digitalWrite(13, 0); }
`
I've tried
`
sysposition[ZAXIS] - (gcstate.coordsystem[ZAXIS] + gcstate.coordoffset[ZAXIS] + gcstate.toollength_offset )< 0 gcstate.position[ZAXIS] - gcstate.coordoffset[Z_AXIS]
gcstate.coordsystem[idx]+gcstate.coordoffset[idx]

and everything what came to my mind analysing the code, bot none worked.
The effect is that LED (connected to 13’th pin) is on when Machine Position is under zero, not Working Position.

Please, please, please help me. I just need to know is there any variable I can use here, and if not – how to calculate it.

I’m quite sure that sysposition is Machine Position, so [ZAXIS] should give me what UGS shows under Machine Position. WCO is difference between MPos and WPos, so adding/substracting should give me right value. But it is not somehow…

Best regards…


评论 (7)

#1 – whitetd 于 2020-03-02

create a post process for what ever your using to create your gcode to do
it, rather then in grbl

<https://www.avast.com/sig-email?utmmedium=email&utmsource=link&utmcampaign=sig-email&utmcontent=webmail&utm_term=icon>
Virus-free.
http://www.avast.com
<https://www.avast.com/sig-email?utmmedium=email&utmsource=link&utmcampaign=sig-email&utmcontent=webmail&utm_term=link>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Mon, Mar 2, 2020 at 7:44 AM SanZamoyski wrote:

> Hi and hello,
>
> I know it is NOT an issue, but I need your help as I’m trying to resolve
> this for two days…
> My goal is to change spindle behavior to:
>
> – when it is on – PWM 50%,
> – when off – LOW
> – when on AND Z-Work Position < 0, PWM 100%. >
> I was trying alot of variables and in many places of the code, but with no
> luck. I’ve ended with report.c file on line ~522 (under float wco[]) – it
> is place where WPos/MPos are calculated, before it is printed.
>
> I have this (dirty) code here:
>
> if(currentposition[ZAXIS] – gcstate.coordsystem[ZAXIS]+gcstate.coordoffset[ZAXIS] <= 0){ > pinMode(13, 1);
> digitalWrite(13, 1);
> }else{
> pinMode(13, 1);
> digitalWrite(13, 0);
> }
>
> I’ve tried
>
> sysposition[ZAXIS] – (gcstate.coordsystem[ZAXIS] + gcstate.coordoffset[ZAXIS] + gcstate.toollength_offset )< 0 > gcstate.position[ZAXIS] – gcstate.coordoffset[Z_AXIS]
> gcstate.coordsystem[idx]+gcstate.coordoffset[idx]
>
> and everything what came to my mind analysing the code, bot none worked.
> The effect is that LED (connected to 13’th pin) is on when Machine
> Position is under zero, not Working Position.
>
> Please, please, please help me. I just need to know is there any variable
> I can use here, and if not – how to calculate it.
>
> I’m quite sure that sysposition is Machine Position, so [ZAXIS] should
> give me what UGS shows under Machine Position. WCO is difference between
> MPos and WPos, so adding/substracting should give me right value. But it is
> not somehow…
>
> Best regards…
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/grbl/grbl/issues/1611?emailsource=notifications&emailtoken=AATT5E33XQNTMMA2R5E63ZLRFPH4BA5CNFSM4K7W5LB2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IRXP2ZA>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AATT5EYQHW344HFPJWRCTTTRFPH4BANCNFSM4K7W5LBQ>
> .
>


#2 – SanZamoyski 于 2020-03-02

Unfortunately it is not an option. I forget to mention that I’m trying to modify grbl for the CNC model for students. X and Y axes are made with regular steppers. Z and spindle are replaced with laser – that’s why I need to use different PWM for over-zero and under-zero. Students will have to program moves by hand (lessons are focused on G-Code, not machine/program). That’s why postprocessing option is not an option.

I’ve already modified GRBL to use h-bridge with microstepping for tho steppers (the third stepper is possible sacrificing some pins but without microstepping) so I would never suspect that this goal was that hard for me to achieve but it is…

I know that report.c is not the right place to add this functionality. At the beginning I was trying to add this at the end of the stepper movement function but there was already mentioned problem so I moved it here to be sure that this is related to wrongly chosen variables. And it is.


#3 – langwadt 于 2020-03-02

could you just add a few lines to the top of the stepper interrupt that sets the pwm to 50/100% depending on whether the last direction was up or down?


#4 – SanZamoyski 于 2020-03-02

It would be almost a good solution, but unfortunately, it would set falsely PWM at 100% if “spindle” is over the material. Please keep in mind that it will be used by people who do not know almost anything about G-code, so this kind of scenario is quite possible.
Is this really very complex problem and we need to look for a workaround?

Also, there is WPos output from grbl (setting verbose in UGS and changing some settings). This would be a workaround for me. But it shouldn’t be that hard to achieve „normally”…


#5 – langwadt 于 2020-03-02

I guess something along these lines,

float zpos;
zpos = sys.position[ZAXIS]/settings.stepspermm[ZAXIS];
zpos -= gcstate.coordsystem[ZAXIS]+gcstate.coordoffset[ZAXIS];
zpos -= gcstate.toollength_offset;


#6 – SanZamoyski 于 2020-03-02

I believe I tried something like this by:
if(sysposition[ZAXIS] - (gcstate.coordsystem[ZAXIS] + gcstate.coordoffset[ZAXIS] + gcstate.toollength_offset ) < 0){ ... }
based on:
``
float wco[N_AXIS];
if (bitisfalse(settings.statusreportmask,BITFLAGRTSTATUSPOSITION_TYPE) ||
(sys.reportwcocounter == 0) ) {
for (idx=0; idx< N_AXIS; idx++) { // Apply work coordinate offsets and tool length offset to current position. wco[idx] = gcstate.coordsystem[idx]+gcstate.coordoffset[idx];
if (idx == TOOLLENGTHOFFSETAXIS) { wco[idx] += gcstate.toollengthoffset; }
if (bitisfalse(settings.statusreportmask,BITFLAGRTSTATUSPOSITION_TYPE)) {
print_position[idx] -= wco[idx];
}
}
}
`
Where printposition is memcopied and coverted by systemconvertarraystepstompos() sysposition. Which is, diggin deeper,
steps[idx]/settings.stepsper_mm[idx].
print_position is then used here:
`
static void reportutilaxisvalues(float *axisvalue) {
uint8_t idx;
for (idx=0; idxCoordValue(axisvalue[idx]);
if (idx < (NAXIS-1)) { serialwrite(','); }
}
}
``
But I missed calculating to mm. And You are correct. Thank You for pointing that out. Also I thought that I don't need recalculating to mm/inch or anything. I'll check Your solution tommorow. Thank You.


#7 - SanZamoyski 于 2020-03-03

Thanks to @langwadt I found the solution to my problem. In the file report.c I put before //Report machine position this code:

``
float zpos;
zpos = sysposition[ZAXIS]/settings.stepspermm[ZAXIS] - wco[ZAXIS];
//zpos -= gcstate.coordsystem[ZAXIS]+gcstate.coordoffset[ZAXIS];
//zpos -= gcstate.toollength_offset;

if(spindlegetstate() != SPINDLESTATEDISABLE){
if(zpos <= 0){ SPINDLEOCRREGISTER = 255;
}else{
SPINDLEOCRREGISTER = 32;
}
}

`
Also commented
//SPINDLEOCRREGISTER = pwmvalue; // Set PWM output level`. in spindlecontrol.c.

It seems to work very well now without any workaround ;)
Probably there are a better places to put this code but I am not sure if it is needed.


原始Issue: https://github.com/grbl/grbl/issues/1611

喜欢 (0)