Skip to content

Commit

Permalink
Merge pull request #464 from Paciente8159/laser-ppi-tool-rework
Browse files Browse the repository at this point in the history
Laser ppi tool rework
  • Loading branch information
Paciente8159 authored Aug 4, 2023
2 parents 447b825 + 617c15e commit 530f108
Show file tree
Hide file tree
Showing 13 changed files with 315 additions and 191 deletions.
2 changes: 1 addition & 1 deletion makefiles/virtual/uCNC.dev
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ IncludeVersionInfo=0
SupportXPThemes=0
CompilerSet=1
CompilerSettings=000000e0a0000000001000000
UnitCount=81
UnitCount=80

[VersionInfo]
Major=1
Expand Down
15 changes: 14 additions & 1 deletion uCNC/cnc_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,13 @@ extern "C"
// #define DEFAULT_LASER_PPI 254
// #define DEFAULT_LASER_PPI_USWIDTH 1500

/**
*
* Enables Plasma THC capabilities
*
* **/
// #define ENABLE_PLASMA_THC

/**
* Feed overrides increments and percentage ranges
* */
Expand Down Expand Up @@ -312,7 +319,13 @@ extern "C"
// #define ENABLE_IO_MODULES
// #define ENABLE_PARSER_MODULES
// #define ENABLE_MOTION_CONTROL_MODULES
// #define ENABLE_SETTINGS_MODULES

/**
* Settings extensions are enabled by default
* Uncomment to disable this extension.
* Some option might override this (like ENABLE_TOOL_PID_CONTROLLER)
* */
// #define DISABLE_SETTINGS_MODULES

/**
* Report specific options
Expand Down
7 changes: 0 additions & 7 deletions uCNC/cnc_hal_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,6 @@ extern "C"
// #define INVERT_LASER_PPI_LOGIC
#endif

/**
*
* Enables Plasma THC capabilities
*
* **/
// #define ENABLE_PLASMA_THC

/**
*
* Tool pallete
Expand Down
14 changes: 14 additions & 0 deletions uCNC/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ These files contain initialization code for all modules that extend µCNC functi
_**Jump to section**_
* [Adding custom modules to µCNC](#adding-custom-modules-to-µcnc)
* [µCNC existing events/delegates](#µcnc-existing-eventsdelegates)
* [µCNC existing hooks](#µcnc-existing-hooks)
* [modules.h and events](#modulesh-and-events)
* [Creating a new custom event listener](#creating-a-new-custom-event-listener)
* [Creating a new custom event](#creating-a-new-custom-event)
Expand All @@ -25,6 +26,7 @@ __NOTE__: _Version 1.4.6 implemented changes to module initialization. Also addi
µCNC has implemented a module system that allows the user to perform custom actions that get executed in an event/delegate fashion style similar to what is done with C#. Multiple callbacks functions can be attached to the same event.
These modules can be quite useful and perform several things like adding custom custom gcodes to perform actions, or modifying IO states if a given condition is verified.
µCNC already has a few useful modules like PID controller, Encoder module, TMC drivers support and custom G/M code support.
Version 1.8 also introduces the concept of simple hooks. These hooks are simple function pointers that execute the assigned callback at that time. They are usually used inside interrupt service routines and provide a way to extend ISR's with small extra code blocks to perform certain tasks. Unlike events, simple hooks can only run a single callback. The active callback is the last one to attach to any give hook.

## µCNC existing events/delegates

Expand Down Expand Up @@ -183,6 +185,18 @@ typedef struct
} motion_data_t;
```

## µCNC existing hooks

These are the list of available hooks inside

__NOTE__: Not all simple hooks may be listed here. To find all available simple hooks declarations, do a search on all files (on VSCode in Windows it's Ctrl+Shift+F) of the project of `DECL_HOOK`. You can also search for the `HOOK_INVOKE` to see what argument is being passed to the simple hook handler.

| Event name | Argument | Enable option | Description |
| --- | --- | --- | --- |
| itp_rt_pre_stepbits | int*, int* | ENABLE_RT_SYNC_MOTIONS | Fires when the next computed step bits and dirs have been computed to be output. Args are a pointer the stepbit var and a pointer to a dirbit var |
| itp_rt_stepbits | int, int | ENABLE_RT_SYNC_MOTIONS | Fires when the setpbits have been output to the IO. Args are the stepbit mask value and the step ISR flags value |
| encoder_index | void | ENCODER_COUNT | Fires when the index of the specialized rpm encoder is triggered. Has no args |

## modules.h and events

`src/module.h` exposes a few handy macros that make event listeners, or custom events creations easy.
Expand Down
15 changes: 13 additions & 2 deletions uCNC/src/cnc_hal_config_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,9 @@ extern "C"
/*laser ppi*/
#if (TOOL_COUNT < 1)
#undef ENABLE_LASER_PPI
#undef ENABLE_PLASMA_THC
#endif

#ifdef ENABLE_LASER_PPI
#ifndef MCU_HAS_ONESHOT_TIMER
#error "The current MCU does not support ONESHOT_TIMER or the ONESHOT_TIMER is not configured"
Expand Down Expand Up @@ -2121,8 +2123,18 @@ typedef uint16_t step_t;
#endif
#endif

#ifdef ENABLE_PLASMA_THC
#ifndef DISABLE_SETTINGS_MODULES
#define ENABLE_SETTINGS_MODULES
#endif

#ifdef ENABLE_LASER_PPI
// forces modes
#ifndef ENABLE_RT_SYNC_MOTIONS
#define ENABLE_RT_SYNC_MOTIONS
#endif
#endif

#ifdef ENABLE_PLASMA_THC
// forces modes
#ifndef ENABLE_TOOL_PID_CONTROLLER
#define ENABLE_TOOL_PID_CONTROLLER
Expand All @@ -2136,7 +2148,6 @@ typedef uint16_t step_t;
#ifndef ENABLE_RT_SYNC_MOTIONS
#define ENABLE_RT_SYNC_MOTIONS
#endif

#endif

#ifdef ENABLE_TOOL_PID_CONTROLLER
Expand Down
92 changes: 27 additions & 65 deletions uCNC/src/core/interpolator.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ static volatile uint8_t itp_step_lock;
#endif

#ifdef ENABLE_RT_SYNC_MOTIONS
volatile int32_t itp_sync_step_counter;
// deprecated with new hooks
// volatile int32_t itp_sync_step_counter;

void itp_update_feed(float feed)
{
Expand Down Expand Up @@ -96,6 +97,9 @@ bool itp_sync_ready(void)

return false;
}

CREATE_HOOK(itp_rt_pre_stepbits);
CREATE_HOOK(itp_rt_stepbits);
#endif

static void itp_sgm_buffer_read(void);
Expand Down Expand Up @@ -854,24 +858,6 @@ uint32_t itp_get_rt_line_number(void)
}
#endif

#ifdef ENABLE_LASER_PPI
// turn laser off callback
MCU_CALLBACK void laser_ppi_turnoff_cb(void)
{
#ifndef INVERT_LASER_PPI_LOGIC
io_clear_output(LASER_PPI);
#else
io_set_output(LASER_PPI);
#endif
}
#endif

#ifdef ENABLE_RT_SYNC_MOTIONS
void __attribute__((weak)) itp_rt_stepbits(uint8_t *stepbits, uint8_t *dirs)
{
}
#endif

// always fires after pulse
MCU_CALLBACK void mcu_step_reset_cb(void)
{
Expand All @@ -883,9 +869,6 @@ MCU_CALLBACK void mcu_step_cb(void)
{
static uint8_t stepbits = 0;
static bool itp_busy = false;
#ifdef ENABLE_LASER_PPI
static uint16_t new_laser_ppi = 0;
#endif

#ifdef RT_STEP_PREVENT_CONDITION
if (RT_STEP_PREVENT_CONDITION)
Expand All @@ -899,6 +882,17 @@ MCU_CALLBACK void mcu_step_cb(void)
return;
}

uint8_t new_stepbits = stepbits;
io_toggle_steps(new_stepbits);

// sets step bits
#ifdef ENABLE_RT_SYNC_MOTIONS
if (new_stepbits && itp_rt_sgm)
{
HOOK_INVOKE(itp_rt_stepbits, new_stepbits, itp_rt_sgm->flags);
}
#endif

if (itp_rt_sgm != NULL)
{
if (itp_rt_sgm->flags & ITP_UPDATE)
Expand All @@ -911,18 +905,7 @@ MCU_CALLBACK void mcu_step_cb(void)
#if TOOL_COUNT > 0
if (itp_rt_sgm->flags & ITP_UPDATE_TOOL)
{
#ifdef ENABLE_LASER_PPI
if (g_settings.laser_mode & (LASER_PPI_MODE | LASER_PPI_VARPOWER_MODE))
{
new_laser_ppi = itp_rt_sgm->spindle;
}
else
{
#endif
tool_set_speed(itp_rt_sgm->spindle);
#ifdef ENABLE_LASER_PPI
}
#endif
tool_set_speed(itp_rt_sgm->spindle);
}
#endif
itp_rt_sgm->flags &= ~(ITP_UPDATE);
Expand All @@ -937,30 +920,6 @@ MCU_CALLBACK void mcu_step_cb(void)
}
}

uint8_t new_stepbits = stepbits;

// sets step bits
#ifdef ENABLE_LASER_PPI
if (g_settings.laser_mode & (LASER_PPI_MODE | LASER_PPI_VARPOWER_MODE))
{
if (new_stepbits & LASER_PPI_MASK)
{
if (new_laser_ppi)
{
mcu_config_timeout(&laser_ppi_turnoff_cb, new_laser_ppi);
new_laser_ppi = 0;
}
mcu_start_timeout();
#ifndef INVERT_LASER_PPI_LOGIC
io_set_output(LASER_PPI);
#else
io_clear_output(LASER_PPI);
#endif
}
}
#endif
io_toggle_steps(new_stepbits);

// if buffer empty loads one
if (itp_rt_sgm == NULL)
{
Expand Down Expand Up @@ -1039,12 +998,15 @@ MCU_CALLBACK void mcu_step_cb(void)
}
}

#ifdef ENABLE_RT_SYNC_MOTIONS
if (new_stepbits && (itp_rt_sgm->flags & ITP_SYNC))
{
itp_sync_step_counter++;
}
#endif
/*
Must put this on G33 module
#ifdef ENABLE_RT_SYNC_MOTIONS
if (new_stepbits && (itp_rt_sgm->flags & ITP_SYNC))
{
itp_sync_step_counter++;
}
#endif
*/

new_stepbits = 0;
itp_busy = true;
Expand Down Expand Up @@ -1218,7 +1180,7 @@ MCU_CALLBACK void mcu_step_cb(void)
static uint8_t last_dirs = 0;
if (new_stepbits)
{
itp_rt_stepbits(&new_stepbits, &dirs);
HOOK_INVOKE(itp_rt_pre_stepbits, &new_stepbits, &dirs);
if (dirs != last_dirs)
{
last_dirs = dirs;
Expand Down
7 changes: 4 additions & 3 deletions uCNC/src/core/interpolator.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ extern "C"
float itp_get_rt_feed(void);
bool itp_is_empty(void);
uint8_t itp_sync(void);

void itp_sync_spindle(void);
void itp_start(bool is_synched);
#if (defined(ENABLE_DUAL_DRIVE_AXIS) || defined(KINEMATICS_MOTION_BY_SEGMENTS))
Expand All @@ -102,10 +102,11 @@ extern "C"
uint32_t itp_get_rt_line_number(void);
#endif
#ifdef ENABLE_RT_SYNC_MOTIONS
extern volatile int32_t itp_sync_step_counter;
// extern volatile int32_t itp_sync_step_counter;
void itp_update_feed(float feed);
bool itp_sync_ready(void);
void itp_rt_stepbits(uint8_t *stepbits, uint8_t* dirs);
DECL_HOOK(itp_rt_pre_stepbits, uint8_t *, uint8_t *);
DECL_HOOK(itp_rt_stepbits, uint8_t, uint8_t);
#endif

#ifdef __cplusplus
Expand Down
Loading

0 comments on commit 530f108

Please sign in to comment.