@@ -68,6 +68,7 @@ typedef enum {
6868typedef struct {
6969 int32_t id ;
7070 bool thc_disabled ;
71+ float feed_factor ;
7172 union {
7273 float params [6 ];
7374 struct {
@@ -105,11 +106,11 @@ typedef struct {
105106 float arc_voltage_offset ;
106107 float arc_height_per_volt ;
107108 float arc_ok_low_voltage ;
108- float arc_high_low_voltage ;
109+ float arc_ok_high_voltage ;
109110 uint8_t arc_retries ;
110111 thc_options_t option ;
111- uint8_t unused1 ;
112- uint8_t unused2 ;
112+ uint8_t feed_factor ;
113+ uint8_t unused2 ; // thc cutoff feedrate %?
113114 plasma_mode_t mode ;
114115 pid_values_t pid ;
115116 uint8_t port_arc_voltage ;
@@ -788,10 +789,13 @@ static void state_idle (void)
788789 }
789790 }
790791
791- if (plasma .option .sync_pos && state_get () == STATE_IDLE ) {
792+ if (st2_motor_running (z_motor ))
793+ st2_motor_stop (z_motor );
792794
793- if (mode != Plasma_ModeUpDown )
794- step_count = (uint32_t )st2_get_position (z_motor );
795+ else if (plasma .option .sync_pos && state_get () == STATE_IDLE ) {
796+
797+ // if(mode != Plasma_ModeUpDown)
798+ step_count = (uint32_t )st2_get_position (z_motor );
795799
796800 if (step_count && state_get () == STATE_IDLE ) {
797801 sys .position [Z_AXIS ] += step_count ;
@@ -808,18 +812,23 @@ static void state_thc_delay (void)
808812
809813 if (!(thc .enabled = !(job .thc_disabled || mode == Plasma_ModeArcOK )))
810814 stateHandler = state_arc_monitor ;
811- else if (mode == Plasma_ModeUpDown ) {
812- step_count = 0 ;
813- stateHandler = state_thc_adjust ;
814- } else {
815- pidf_reset (& pid );
815+
816+ else {
817+
818+ job .feed_factor = (float )plasma .feed_factor / 100.0f ;
816819 st2_set_position (z_motor , 0LL );
817- if (!isnanf (job .cut_voltage ))
818- set_target_voltage (job .cut_voltage );
819- else
820- set_target_voltage (parc_voltage .get_value (& parc_voltage ) * plasma .arc_voltage_scale - plasma .arc_voltage_offset );
821- stateHandler = state_vad_lock ;
822- stateHandler ();
820+
821+ if (mode == Plasma_ModeUpDown )
822+ stateHandler = state_thc_adjust ;
823+ else {
824+ pidf_reset (& pid );
825+ if (!isnanf (job .cut_voltage ))
826+ set_target_voltage (job .cut_voltage );
827+ else
828+ set_target_voltage (parc_voltage .get_value (& parc_voltage ) * plasma .arc_voltage_scale - plasma .arc_voltage_offset );
829+ stateHandler = state_vad_lock ;
830+ stateHandler ();
831+ }
823832 }
824833 }
825834}
@@ -833,17 +842,18 @@ static void state_arc_monitor (void)
833842static void state_thc_adjust (void )
834843{
835844 if ((thc .arc_ok = arc_ok .get_value (& arc_ok ) == 1.0f )) {
845+
836846 if (updown_enabled ) {
847+
837848 thc .up = thc .report_up = cutter_up .get_value (& cutter_up ) == 1.0f ;
838849 thc .down = thc .report_down = cutter_down .get_value (& cutter_down ) == 1.0f ;
839- if (thc .up != thc .down ) {
840- if (thc .up ) {
841- step_count ++ ;
842- hal .stepper .output_step ((axes_signals_t ){Z_AXIS_BIT }, (axes_signals_t ){0 });
843- } else {
844- step_count -- ;
845- hal .stepper .output_step ((axes_signals_t ){Z_AXIS_BIT }, (axes_signals_t ){Z_AXIS_BIT });
846- }
850+
851+ if (st2_motor_running (z_motor )) {
852+ if (thc .up == thc .down )
853+ st2_motor_stop (z_motor );
854+ } else if (thc .up != thc .down ) {
855+ float feedrate = st_get_realtime_rate ();
856+ st2_motor_move (z_motor , thc .up ? 1.0f : -1.0f , min (feedrate , settings .axis [Z_AXIS ].max_rate ) * job .feed_factor , Stepper2_InfiniteSteps );
847857 }
848858 }
849859 } else
@@ -891,7 +901,9 @@ static void state_thc_pid (void)
891901 strcat(buf, ftoa(err, 1));
892902 report_message(buf, Message_Info);
893903*/
894- st2_motor_move (z_motor , - err * plasma .arc_height_per_volt , settings .axis [Z_AXIS ].max_rate , Stepper2_mm );
904+ float feedrate = st_get_realtime_rate ();
905+
906+ st2_motor_move (z_motor , err * plasma .arc_height_per_volt , min (feedrate , settings .axis [Z_AXIS ].max_rate ) * job .feed_factor , Stepper2_mm );
895907 }
896908 }
897909 }
@@ -1146,6 +1158,7 @@ static bool is_setting_available (const setting_detail_t *setting, uint_fast16_t
11461158 break ;
11471159
11481160 case Setting_THC_VADThreshold :
1161+ case Setting_THC_FeedFactor :
11491162 ok = init_ok ;
11501163 break ;
11511164
@@ -1231,13 +1244,14 @@ PROGMEM static const setting_detail_t plasma_settings[] = {
12311244 { Setting_Arc_VoltageScale , Group_Plasma , "Plasma Arc voltage scale" , NULL , Format_Decimal , "###0.000" , NULL , NULL , Setting_NonCore , & plasma .arc_voltage_scale , NULL , is_setting_available },
12321245 { Setting_Arc_VoltageOffset , Group_Plasma , "Plasma Arc voltage offset" , NULL , Format_Decimal , "###0.000" , NULL , NULL , Setting_NonCore , & plasma .arc_voltage_offset , NULL , is_setting_available },
12331246 { Setting_Arc_HeightPerVolt , Group_Plasma , "Plasma Arc height per volt" , "mm" , Format_Decimal , "###0.000" , NULL , NULL , Setting_NonCore , & plasma .arc_height_per_volt , NULL , is_setting_available },
1234- { Setting_Arc_OkHighVoltage , Group_Plasma , "Plasma Arc ok high volts" , "V" , Format_Decimal , "###0.000" , NULL , NULL , Setting_NonCore , & plasma .arc_high_low_voltage , NULL , is_setting_available },
1247+ { Setting_Arc_OkHighVoltage , Group_Plasma , "Plasma Arc ok high volts" , "V" , Format_Decimal , "###0.000" , NULL , NULL , Setting_NonCore , & plasma .arc_ok_high_voltage , NULL , is_setting_available },
12351248 { Setting_Arc_OkLowVoltage , Group_Plasma , "Plasma Arc ok low volts" , "V" , Format_Decimal , "###0.000" , NULL , NULL , Setting_NonCore , & plasma .arc_ok_low_voltage , NULL , is_setting_available },
12361249 { Setting_Arc_VoltagePort , Group_AuxPorts , "Arc voltage port" , NULL , Format_Decimal , "-#0" , "-1" , max_aport , Setting_NonCoreFn , set_port , get_port , is_setting_available , { .reboot_required = On } },
12371250 { Setting_Arc_OkPort , Group_AuxPorts , "Arc ok port" , NULL , Format_Decimal , "-#0" , "-1" , max_dport , Setting_NonCoreFn , set_port , get_port , NULL , { .reboot_required = On } },
12381251 { Setting_THC_CutterDownPort , Group_AuxPorts , "Cutter down port" , NULL , Format_Decimal , "-#0" , "-1" , max_dport , Setting_NonCoreFn , set_port , get_port , is_setting_available , { .reboot_required = On } },
12391252 { Setting_THC_CutterUpPort , Group_AuxPorts , "Cutter up port" , NULL , Format_Decimal , "-#0" , "-1" , max_dport , Setting_NonCoreFn , set_port , get_port , is_setting_available , { .reboot_required = On } },
12401253 { Setting_THC_Options , Group_Plasma , "Plasma options" , NULL , Format_Bitfield , "Virtual ports,Sync Z position" , NULL , NULL , Setting_NonCore , & plasma .option .flags , NULL , NULL , { .reboot_required = On } },
1254+ { Setting_THC_FeedFactor , Group_Plasma , "Plasma Z feed factor" , "percent" , Format_Int8 , "##0" , "1" , "100" , Setting_NonCore , & plasma .feed_factor , NULL , is_setting_available },
12411255};
12421256
12431257PROGMEM static const setting_descr_t plasma_settings_descr [] = {
@@ -1265,7 +1279,9 @@ PROGMEM static const setting_descr_t plasma_settings_descr[] = {
12651279 { Setting_Arc_OkPort , "Aux port number to use for arc ok signal. Set to -1 to disable." },
12661280 { Setting_THC_CutterDownPort , "Aux port number to use for cutter down signal. Set to -1 to disable." },
12671281 { Setting_THC_CutterUpPort , "Aux port number to use for cutter up signal. Set to -1 to disable." },
1268- { Setting_THC_Options , "" }
1282+ { Setting_THC_Options , "" },
1283+ { Setting_THC_FeedFactor , "Z-axis feedrate to use for height corrections as a percentage of the actual XY feedrate." },
1284+
12691285};
12701286
12711287static void plasma_settings_save (void )
@@ -1291,8 +1307,9 @@ static void plasma_settings_restore (void)
12911307 plasma .arc_voltage_scale = 1.0f ;
12921308 plasma .arc_voltage_offset = 0.0f ;
12931309 plasma .arc_height_per_volt = 0.1f ;
1294- plasma .arc_high_low_voltage = 150.0 ;
1310+ plasma .arc_ok_high_voltage = 150.0 ;
12951311 plasma .arc_ok_low_voltage = 100.0f ;
1312+ plasma .feed_factor = 5 ;
12961313 plasma .pid .p_gain = 1.0f ;
12971314 plasma .pid .i_gain = 0.0f ;
12981315 plasma .pid .d_gain = 0.0f ;
@@ -1360,6 +1377,9 @@ static void plasma_settings_load (void)
13601377
13611378 updown_enabled = mode == Plasma_ModeUpDown ;
13621379
1380+ if (plasma .feed_factor == 0 || plasma .feed_factor > 100 )
1381+ plasma .feed_factor = 5 ;
1382+
13631383 settings_changed = hal .settings_changed ;
13641384 hal .settings_changed = plasma_setup ;
13651385
@@ -1404,7 +1424,7 @@ static void onReportOptions (bool newopt)
14041424 * s1 ++ = ')' ;
14051425 * s1 = '\0' ;
14061426
1407- report_plugin (buf , "0.23 " );
1427+ report_plugin (buf , "0.24 " );
14081428
14091429 } else if (mode != Plasma_ModeOff )
14101430 hal .stream .write (",THC" );
0 commit comments