#include "pid.h"
Go to the source code of this file.
Data Structures | |
union | spindle_state_t |
union | spindle_cap_t |
Bitmap flags for spindle capabilities. More... | |
struct | spindle_data_t |
Used when HAL driver supports spindle synchronization. More... | |
struct | pwm_piece_t |
union | spindle_settings_flags_t |
struct | spindle_settings_t |
struct | spindle1_settings_t |
union | spindle_pwm_flags_t |
struct | spindle_pwm |
Precalculated values that may be set/used by HAL driver to speed up RPM to PWM conversions if variable spindle is supported. */. More... | |
union | spindle_context_ptr_t |
struct | spindle_ptrs |
Handlers and data for spindle support. More... | |
struct | spindle_css_data_t |
Data used for Constant Surface Speed (CSS) mode calculations. More... | |
struct | spindle_param |
Structure used for holding the current state of an enabled spindle. More... | |
struct | spindle_data_ptrs_t |
struct | spindle_info_t |
Structure holding data passed to the callback function called by spindle_enumerate_spindles(). More... | |
Macros | |
#define | SPINDLE_NONE 0 |
#define | SPINDLE_HUANYANG1 1 |
#define | SPINDLE_HUANYANG2 2 |
#define | SPINDLE_GS20 3 |
#define | SPINDLE_YL620A 4 |
#define | SPINDLE_MODVFD 5 |
#define | SPINDLE_H100 6 |
#define | SPINDLE_ONOFF0 7 |
#define | SPINDLE_ONOFF0_DIR 8 |
#define | SPINDLE_ONOFF1 9 |
#define | SPINDLE_ONOFF1_DIR 10 |
#define | SPINDLE_PWM0 11 |
#define | SPINDLE_PWM0_NODIR 12 |
#define | SPINDLE_PWM1 13 |
#define | SPINDLE_PWM1_NODIR 14 |
#define | SPINDLE_PWM2 15 |
#define | SPINDLE_PWM2_NODIR 16 |
#define | SPINDLE_PWM0_CLONE 17 |
#define | SPINDLE_SOLENOID 18 |
#define | SPINDLE_STEPPER 19 |
#define | SPINDLE_NOWFOREVER 20 |
#define | SPINDLE_MY_SPINDLE 30 |
#define | SPINDLE_ALL_VFD ((1<<SPINDLE_HUANYANG1)|(1<<SPINDLE_HUANYANG2)|(1<<SPINDLE_GS20)|(1<<SPINDLE_YL620A)|(1<<SPINDLE_MODVFD)|(1<<SPINDLE_H100)|(1<<SPINDLE_NOWFOREVER)) |
#define | SPINDLE_ALL (SPINDLE_ALL_VFD|(1<<SPINDLE_PWM0)) |
#define | spindle_validate_at_speed(d, r) { d.rpm = r; d.state_programmed.at_speed = !d.at_speed_enabled || (d.rpm >= d.rpm_low_limit && d.rpm <= d.rpm_high_limit); } |
Typedefs | |
typedef int8_t | spindle_id_t |
typedef int8_t | spindle_num_t |
typedef bool(* | spindle_config_ptr) (struct spindle_ptrs *spindle) |
Pointer to function for configuring a spindle. More... | |
typedef void(* | spindle_set_state_ptr) (struct spindle_ptrs *spindle, spindle_state_t state, float rpm) |
Pointer to function for setting the spindle state. More... | |
typedef spindle_state_t(* | spindle_get_state_ptr) (struct spindle_ptrs *spindle) |
Pointer to function for getting the spindle state. More... | |
typedef uint_fast16_t(* | spindle_get_pwm_ptr) (struct spindle_ptrs *spindle, float rpm) |
Pointer to function for converting a RPM value to a PWM value. More... | |
typedef void(* | spindle_update_pwm_ptr) (struct spindle_ptrs *spindle, uint_fast16_t pwm) |
Pointer to function for updating spindle speed on the fly. More... | |
typedef void(* | spindle_update_rpm_ptr) (struct spindle_ptrs *spindle, float rpm) |
Pointer to function for updating spindle RPM. More... | |
typedef spindle_data_t *(* | spindle_get_data_ptr) (spindle_data_request_t request) |
Pointer to function for getting spindle data. More... | |
typedef void(* | spindle_reset_data_ptr) (void) |
Pointer to function for resetting spindle data. More... | |
typedef void(* | spindle_pulse_on_ptr) (uint_fast16_t pulse_length) |
Pointer to function for outputting a spindle on pulse. Used for Pulses Per Inch (PPI) laser mode. More... | |
typedef struct spindle_pwm | spindle_pwm_t |
Precalculated values that may be set/used by HAL driver to speed up RPM to PWM conversions if variable spindle is supported. */. More... | |
typedef struct spindle_ptrs | spindle_ptrs_t |
typedef struct spindle_param | spindle_param_t |
Structure used for holding the current state of an enabled spindle. More... | |
typedef void(* | spindle_enumerate_callback_ptr) (spindle_info_t *spindle, void *data) |
Pointer to callback function called by spindle_enumerate_spindles(). More... | |
Enumerations | |
enum | spindle_data_request_t { SpindleData_Counters , SpindleData_RPM , SpindleData_AngularPosition , SpindleData_AtSpeed } |
enum | spindle_type_t { SpindleType_PWM , SpindleType_Basic , SpindleType_VFD , SpindleType_Solenoid , SpindleType_Stepper , SpindleType_Null } |
enum | spindle_hal_t { SpindleHAL_Raw , SpindleHAL_Configured , SpindleHAL_Active } |
Functions | |
void | spindle_set_override (spindle_ptrs_t *spindle, override_t speed_override) |
Set spindle speed override. More... | |
bool | spindle_sync (spindle_ptrs_t *spindle, spindle_state_t state, float rpm) |
G-code parser entry-point for setting spindle state. Forces a planner buffer sync and bails if an abort or check-mode is active. If the spindle supports at speed functionality it will wait for it to reach the speed and raise an alarm if the speed is not reached within the timeout period. More... | |
bool | spindle_set_state (spindle_ptrs_t *spindle, spindle_state_t state, float rpm) |
Immediately sets spindle running state with direction and spindle rpm, if enabled. Called by g-code parser spindle_sync(), parking retract and restore, g-code program end, sleep, and spindle stop override. More... | |
float | spindle_set_rpm (spindle_ptrs_t *spindle, float rpm, override_t speed_override) |
Calculate and set programmed RPM according to override and max/min limits. More... | |
bool | spindle_restore (spindle_ptrs_t *spindle, spindle_state_t state, float rpm) |
Restore spindle running state with direction, enable, spindle RPM and appropriate delay. More... | |
void | spindle_all_off (void) |
Turn off all enabled spindles. More... | |
bool | spindle_precompute_pwm_values (spindle_ptrs_t *spindle, spindle_pwm_t *pwm_data, spindle_settings_t *settings, uint32_t clock_hz) |
Precompute PWM values for faster conversion. More... | |
spindle_id_t | spindle_register (const spindle_ptrs_t *spindle, const char *name) |
Register a spindle with the core. More... | |
spindle_id_t | spindle_add_null (void) |
Register a null spindle that has no connection to the outside world. This is done automatically on startup if no spindle can be succesfully enabled. More... | |
uint8_t | spindle_get_count (void) |
Get number of registered spindles. More... | |
bool | spindle_select (spindle_id_t spindle_id) |
Enables a spindle and sets it as default spindle (spindle number 0). More... | |
spindle_cap_t | spindle_get_caps (bool active) |
Get the merged spindle capabilities of all registered spindles. More... | |
void | spindle_update_caps (spindle_ptrs_t *spindle, spindle_pwm_t *pwm_caps) |
Update the capabilities of a registered PWM spindle. May be used by the driver on spindle initialization or when spindle settings has been changed. More... | |
void | spindle_bind_encoder (const spindle_data_ptrs_t *encoder_data) |
bool | spindle_set_at_speed_range (spindle_ptrs_t *spindle, spindle_data_t *spindle_data, float rpm) |
spindle_ptrs_t * | spindle_get_hal (spindle_id_t spindle_id, spindle_hal_t hal) |
Get the handlers (function pointers) etc. associated with the spindle. More... | |
const char * | spindle_get_name (spindle_id_t spindle_id) |
Get the registered name of a spindle. More... | |
spindle_id_t | spindle_get_default (void) |
Get the spindle id of the default spindle (spindle number 0). More... | |
spindle_num_t | spindle_enable (spindle_id_t spindle_id) |
Enable a spindle and make it available for use by gcode. More... | |
bool | spindle_enumerate_spindles (spindle_enumerate_callback_ptr callback, void *data) |
Enumerate registered spindles by calling a callback function for each of them. More... | |
bool | spindle_is_enabled (spindle_num_t spindle_num) |
Check if a spindle is enabled and available or not. More... | |
bool | spindle_is_on (void) |
Check if any of the enabled spindles is running. More... | |
spindle_ptrs_t * | spindle_get (spindle_num_t spindle_num) |
Get the handlers (function pointers) etc. associated with an enabled spindle. More... | |
#define SPINDLE_ALL (SPINDLE_ALL_VFD|(1<<SPINDLE_PWM0)) |
#define SPINDLE_ALL_VFD ((1<<SPINDLE_HUANYANG1)|(1<<SPINDLE_HUANYANG2)|(1<<SPINDLE_GS20)|(1<<SPINDLE_YL620A)|(1<<SPINDLE_MODVFD)|(1<<SPINDLE_H100)|(1<<SPINDLE_NOWFOREVER)) |
#define SPINDLE_GS20 3 |
#define SPINDLE_H100 6 |
#define SPINDLE_HUANYANG1 1 |
#define SPINDLE_HUANYANG2 2 |
#define SPINDLE_MODVFD 5 |
#define SPINDLE_MY_SPINDLE 30 |
#define SPINDLE_NONE 0 |
#define SPINDLE_NOWFOREVER 20 |
#define SPINDLE_ONOFF0 7 |
#define SPINDLE_ONOFF0_DIR 8 |
#define SPINDLE_ONOFF1 9 |
#define SPINDLE_ONOFF1_DIR 10 |
#define SPINDLE_PWM0 11 |
#define SPINDLE_PWM0_CLONE 17 |
#define SPINDLE_PWM0_NODIR 12 |
#define SPINDLE_PWM1 13 |
#define SPINDLE_PWM1_NODIR 14 |
#define SPINDLE_PWM2 15 |
#define SPINDLE_PWM2_NODIR 16 |
#define SPINDLE_SOLENOID 18 |
#define SPINDLE_STEPPER 19 |
#define spindle_validate_at_speed | ( | d, | |
r | |||
) | { d.rpm = r; d.state_programmed.at_speed = !d.at_speed_enabled || (d.rpm >= d.rpm_low_limit && d.rpm <= d.rpm_high_limit); } |
#define SPINDLE_YL620A 4 |
typedef bool(* spindle_config_ptr) (struct spindle_ptrs *spindle) |
Pointer to function for configuring a spindle.
spindle | a pointer to a spindle_struct. |
typedef void(* spindle_enumerate_callback_ptr) (spindle_info_t *spindle, void *data) |
Pointer to callback function called by spindle_enumerate_spindles().
spindle | prointer to a spindle_info_t struct. |
typedef spindle_data_t*(* spindle_get_data_ptr) (spindle_data_request_t request) |
Pointer to function for getting spindle data.
request | request type as a spindle_data_request_t enum. |
NOTE: this function requires input from a spindle encoder.
typedef uint_fast16_t(* spindle_get_pwm_ptr) (struct spindle_ptrs *spindle, float rpm) |
Pointer to function for converting a RPM value to a PWM value.
Typically this is a wrapper for the spindle_compute_pwm_value() function provided by the core.
rpm | spindle RPM. |
typedef spindle_state_t(* spindle_get_state_ptr) (struct spindle_ptrs *spindle) |
Pointer to function for getting the spindle state.
typedef int8_t spindle_id_t |
typedef int8_t spindle_num_t |
typedef struct spindle_param spindle_param_t |
Structure used for holding the current state of an enabled spindle.
typedef struct spindle_ptrs spindle_ptrs_t |
typedef void(* spindle_pulse_on_ptr) (uint_fast16_t pulse_length) |
Pointer to function for outputting a spindle on pulse. Used for Pulses Per Inch (PPI) laser mode.
pulse_length | spindle on length in microseconds. |
typedef struct spindle_pwm spindle_pwm_t |
Precalculated values that may be set/used by HAL driver to speed up RPM to PWM conversions if variable spindle is supported. */.
typedef void(* spindle_reset_data_ptr) (void) |
Pointer to function for resetting spindle data.
typedef void(* spindle_set_state_ptr) (struct spindle_ptrs *spindle, spindle_state_t state, float rpm) |
Pointer to function for setting the spindle state.
state | a spindle_state_t union variable. |
rpm | spindle RPM. |
typedef void(* spindle_update_pwm_ptr) (struct spindle_ptrs *spindle, uint_fast16_t pwm) |
Pointer to function for updating spindle speed on the fly.
pwm | new spindle PWM value. |
NOTE: this function will be called from an interrupt context.
typedef void(* spindle_update_rpm_ptr) (struct spindle_ptrs *spindle, float rpm) |
Pointer to function for updating spindle RPM.
rpm | spindle RPM. |
enum spindle_hal_t |
enum spindle_type_t |
spindle_id_t spindle_add_null | ( | void | ) |
Register a null spindle that has no connection to the outside world. This is done automatically on startup if no spindle can be succesfully enabled.
void spindle_all_off | ( | void | ) |
Turn off all enabled spindles.
void spindle_bind_encoder | ( | const spindle_data_ptrs_t * | encoder_data | ) |
spindle_num_t spindle_enable | ( | spindle_id_t | spindle_id | ) |
Enable a spindle and make it available for use by gcode.
spindle_id | spindle id as a spindle_id_t. |
NOTE: up to N_SYS_SPINDLE spindles can be enabled at a time.
bool spindle_enumerate_spindles | ( | spindle_enumerate_callback_ptr | callback, |
void * | data | ||
) |
Enumerate registered spindles by calling a callback function for each of them.
callback | pointer to a spindle_enumerate_callback_ptr type function. |
data | pointer to optional data to pass to the callback function. |
spindle_ptrs_t* spindle_get | ( | spindle_num_t | spindle_num | ) |
Get the handlers (function pointers) etc. associated with an enabled spindle.
spindle_num | spindle number as a spindle_num_t. |
NOTE: do not modify the returned structure!
spindle_cap_t spindle_get_caps | ( | bool | active | ) |
Get the merged spindle capabilities of all registered spindles.
active | true to return active capabilities, false to return default capabilities. |
uint8_t spindle_get_count | ( | void | ) |
Get number of registered spindles.
spindle_id_t spindle_get_default | ( | void | ) |
Get the spindle id of the default spindle (spindle number 0).
spindle_ptrs_t* spindle_get_hal | ( | spindle_id_t | spindle_id, |
spindle_hal_t | hal | ||
) |
Get the handlers (function pointers) etc. associated with the spindle.
spindle_id | spindle id as a spindle_id_t. |
hal | a spindle_hal_t enum value: SpindleHAL_Raw - get the read only version as supplied at registration SpindleHAL_Configured - get the version with run-time modifications applied by the spindle driver. SpindleHAL_Active - get the enabled version available from gcode. Can be overriden by event handlers prior to activation. |
NOTE: do not modify the returned structure!
const char* spindle_get_name | ( | spindle_id_t | spindle_id | ) |
Get the registered name of a spindle.
spindle_id | spindle id as a spindle_id_t. |
bool spindle_is_enabled | ( | spindle_num_t | spindle_num | ) |
Check if a spindle is enabled and available or not.
spindle_num | spindle number as a spindle_num_t. |
bool spindle_is_on | ( | void | ) |
Check if any of the enabled spindles is running.
bool spindle_precompute_pwm_values | ( | spindle_ptrs_t * | spindle, |
spindle_pwm_t * | pwm_data, | ||
spindle_settings_t * | settings, | ||
uint32_t | clock_hz | ||
) |
Precompute PWM values for faster conversion.
spindle | pointer to a spindle_ptrs_t structure. |
pwm_data | pointer to a spindle_pwm_t structure, to hold the precomputed values. |
clock_hz | timer clock frequency used for PWM generation. |
spindle_id_t spindle_register | ( | const spindle_ptrs_t * | spindle, |
const char * | name | ||
) |
Register a spindle with the core.
spindle | pointer to a spindle_ptrs_t structure. |
name | pointer to a null terminated string. |
NOTE: The first spindle registered will become the default active spindle. NOTE: up to N_SPINDLE spindles can be registered at a time.
bool spindle_restore | ( | spindle_ptrs_t * | spindle, |
spindle_state_t | state, | ||
float | rpm | ||
) |
Restore spindle running state with direction, enable, spindle RPM and appropriate delay.
spindle | pointer to a spindle_ptrs_t structure. |
state | a spindle_state_t structure. |
rpm | the spindle RPM to set. |
bool spindle_select | ( | spindle_id_t | spindle_id | ) |
Enables a spindle and sets it as default spindle (spindle number 0).
spindle_id | spindle id as a spindle_id_t. |
bool spindle_set_at_speed_range | ( | spindle_ptrs_t * | spindle, |
spindle_data_t * | spindle_data, | ||
float | rpm | ||
) |
void spindle_set_override | ( | spindle_ptrs_t * | spindle, |
override_t | speed_override | ||
) |
Set spindle speed override.
spindle | pointer to a spindle_ptrs_t structure. |
speed_override | override as a percentage of the programmed RPM. |
NOTE: Unlike motion overrides, spindle overrides do not require a planner reinitialization.
float spindle_set_rpm | ( | spindle_ptrs_t * | spindle, |
float | rpm, | ||
override_t | override_pct | ||
) |
Calculate and set programmed RPM according to override and max/min limits.
spindle | pointer to a spindle_ptrs_t structure. |
rpm | the programmed RPM. |
override_pct | override value in percent. |
bool spindle_set_state | ( | spindle_ptrs_t * | spindle, |
spindle_state_t | state, | ||
float | rpm | ||
) |
Immediately sets spindle running state with direction and spindle rpm, if enabled. Called by g-code parser spindle_sync(), parking retract and restore, g-code program end, sleep, and spindle stop override.
spindle | pointer to a spindle_ptrs_t structure. |
state | a spindle_state_t structure. |
rpm | the spindle RPM to set. |
bool spindle_sync | ( | spindle_ptrs_t * | spindle, |
spindle_state_t | state, | ||
float | rpm | ||
) |
G-code parser entry-point for setting spindle state. Forces a planner buffer sync and bails if an abort or check-mode is active. If the spindle supports at speed functionality it will wait for it to reach the speed and raise an alarm if the speed is not reached within the timeout period.
spindle | pointer to a spindle_ptrs_t structure. |
state | a spindle_state_t structure. |
rpm | the spindle RPM to set. |
void spindle_update_caps | ( | spindle_ptrs_t * | spindle, |
spindle_pwm_t * | pwm_caps | ||
) |
Update the capabilities of a registered PWM spindle. May be used by the driver on spindle initialization or when spindle settings has been changed.
spindle | pointer to a spindle_ptrs_t structure. |
pwm_caps | pointer to a spindle_pwm_t structure. |