/* Autogenerated by /home/engrtech/linuxcnc-dev/bin/halcompile on Mon Feb 12 11:35:43 2018 -- do not edit */ #include "rtapi.h" #ifdef RTAPI #include "rtapi_app.h" #endif #include "rtapi_string.h" #include "rtapi_errno.h" #include "hal.h" #include "rtapi_math64.h" static int comp_id; #ifdef MODULE_INFO MODULE_INFO(linuxcnc, "component:syrctrl:syringe control"); MODULE_INFO(linuxcnc, "pin:i-homevel:float:0:in:homing velocity:None:None"); MODULE_INFO(linuxcnc, "pin:i-extrvel:float:0:in:extrusion velocity:None:None"); MODULE_INFO(linuxcnc, "pin:i-spinvel:float:0:in:electrospin velocity:None:None"); MODULE_INFO(linuxcnc, "pin:i-target-pos:float:0:in:jog position cmd:None:None"); MODULE_INFO(linuxcnc, "pin:i-limit-pos:float:0:in:limit3 jog position cmd:None:None"); MODULE_INFO(linuxcnc, "pin:i-m68:float:0:in:M67/68 E0 value:None:None"); MODULE_INFO(linuxcnc, "pin:i-running:bit:0:in:running G-code or MDI:None:None"); MODULE_INFO(linuxcnc, "pin:i-homesw:bit:0:in:home and limit switches:None:None"); MODULE_INFO(linuxcnc, "pin:i-home:bit:0:in:start homing sequence:None:None"); MODULE_INFO(linuxcnc, "pin:i-hv_arm:bit:0:in:arm HV:None:None"); MODULE_INFO(linuxcnc, "pin:o-vel-cmd:float:0:out:velocity command for stepgen:None:None"); MODULE_INFO(linuxcnc, "pin:o-homing:bit:0:out:is doing home sequence:None:None"); MODULE_INFO(linuxcnc, "pin:o-homed:bit:0:out:is done homing:None:None"); MODULE_INFO(linuxcnc, "pin:o-en:bit:0:out:enable stepgen:None:None"); MODULE_INFO(linuxcnc, "pin:o-hvon:bit:0:out:HV is on:None:None"); MODULE_INFO(linuxcnc, "pin:o-ctrltype:bit:0:out:stepgen type: 0=pos, 1=vel:None:None"); MODULE_INFO(linuxcnc, "funct:_:1:"); MODULE_INFO(linuxcnc, "license:GPL"); MODULE_INFO(linuxcnc, "author:Ralph Stirling"); MODULE_LICENSE("GPL"); #endif // MODULE_INFO struct __comp_state { struct __comp_state *_next; hal_float_t *i_homevel; hal_float_t *i_extrvel; hal_float_t *i_spinvel; hal_float_t *i_target_pos; hal_float_t *i_limit_pos; hal_float_t *i_m68; hal_bit_t *i_running; hal_bit_t *i_homesw; hal_bit_t *i_home; hal_bit_t *i_hv_arm; hal_float_t *o_vel_cmd; hal_bit_t *o_homing; hal_bit_t *o_homed; hal_bit_t *o_en; hal_bit_t *o_hvon; hal_bit_t *o_ctrltype; }; struct __comp_state *__comp_first_inst=0, *__comp_last_inst=0; static void _(struct __comp_state *__comp_inst, long period); static int __comp_get_data_size(void); #undef TRUE #define TRUE (1) #undef FALSE #define FALSE (0) #undef true #define true (1) #undef false #define false (0) static int export(char *prefix, long extra_arg) { char buf[HAL_NAME_LEN + 1]; int r = 0; int sz = sizeof(struct __comp_state) + __comp_get_data_size(); struct __comp_state *inst = hal_malloc(sz); memset(inst, 0, sz); r = hal_pin_float_newf(HAL_IN, &(inst->i_homevel), comp_id, "%s.i-homevel", prefix); if(r != 0) return r; r = hal_pin_float_newf(HAL_IN, &(inst->i_extrvel), comp_id, "%s.i-extrvel", prefix); if(r != 0) return r; r = hal_pin_float_newf(HAL_IN, &(inst->i_spinvel), comp_id, "%s.i-spinvel", prefix); if(r != 0) return r; r = hal_pin_float_newf(HAL_IN, &(inst->i_target_pos), comp_id, "%s.i-target-pos", prefix); if(r != 0) return r; r = hal_pin_float_newf(HAL_IN, &(inst->i_limit_pos), comp_id, "%s.i-limit-pos", prefix); if(r != 0) return r; r = hal_pin_float_newf(HAL_IN, &(inst->i_m68), comp_id, "%s.i-m68", prefix); if(r != 0) return r; r = hal_pin_bit_newf(HAL_IN, &(inst->i_running), comp_id, "%s.i-running", prefix); if(r != 0) return r; r = hal_pin_bit_newf(HAL_IN, &(inst->i_homesw), comp_id, "%s.i-homesw", prefix); if(r != 0) return r; r = hal_pin_bit_newf(HAL_IN, &(inst->i_home), comp_id, "%s.i-home", prefix); if(r != 0) return r; r = hal_pin_bit_newf(HAL_IN, &(inst->i_hv_arm), comp_id, "%s.i-hv-arm", prefix); if(r != 0) return r; r = hal_pin_float_newf(HAL_OUT, &(inst->o_vel_cmd), comp_id, "%s.o-vel-cmd", prefix); if(r != 0) return r; r = hal_pin_bit_newf(HAL_OUT, &(inst->o_homing), comp_id, "%s.o-homing", prefix); if(r != 0) return r; r = hal_pin_bit_newf(HAL_OUT, &(inst->o_homed), comp_id, "%s.o-homed", prefix); if(r != 0) return r; r = hal_pin_bit_newf(HAL_OUT, &(inst->o_en), comp_id, "%s.o-en", prefix); if(r != 0) return r; r = hal_pin_bit_newf(HAL_OUT, &(inst->o_hvon), comp_id, "%s.o-hvon", prefix); if(r != 0) return r; r = hal_pin_bit_newf(HAL_OUT, &(inst->o_ctrltype), comp_id, "%s.o-ctrltype", prefix); if(r != 0) return r; rtapi_snprintf(buf, sizeof(buf), "%s", prefix); r = hal_export_funct(buf, (void(*)(void *inst, long))_, inst, 1, 0, comp_id); if(r != 0) return r; if(__comp_last_inst) __comp_last_inst->_next = inst; __comp_last_inst = inst; if(!__comp_first_inst) __comp_first_inst = inst; return 0; } int rtapi_app_main(void) { int r = 0; comp_id = hal_init("syrctrl"); if(comp_id < 0) return comp_id; r = export("syrctrl", 0); if(r) { hal_exit(comp_id); } else { hal_ready(comp_id); } return r; } void rtapi_app_exit(void) { hal_exit(comp_id); } #undef FUNCTION #define FUNCTION(name) static void name(struct __comp_state *__comp_inst, long period) #undef EXTRA_SETUP #define EXTRA_SETUP() static int extra_setup(struct __comp_state *__comp_inst, char *prefix, long extra_arg) #undef EXTRA_CLEANUP #define EXTRA_CLEANUP() static void extra_cleanup(void) #undef fperiod #define fperiod (period * 1e-9) #undef i_homevel #define i_homevel (0+*__comp_inst->i_homevel) #undef i_extrvel #define i_extrvel (0+*__comp_inst->i_extrvel) #undef i_spinvel #define i_spinvel (0+*__comp_inst->i_spinvel) #undef i_target_pos #define i_target_pos (0+*__comp_inst->i_target_pos) #undef i_limit_pos #define i_limit_pos (0+*__comp_inst->i_limit_pos) #undef i_m68 #define i_m68 (0+*__comp_inst->i_m68) #undef i_running #define i_running (0+*__comp_inst->i_running) #undef i_homesw #define i_homesw (0+*__comp_inst->i_homesw) #undef i_home #define i_home (0+*__comp_inst->i_home) #undef i_hv_arm #define i_hv_arm (0+*__comp_inst->i_hv_arm) #undef o_vel_cmd #define o_vel_cmd (*__comp_inst->o_vel_cmd) #undef o_homing #define o_homing (*__comp_inst->o_homing) #undef o_homed #define o_homed (*__comp_inst->o_homed) #undef o_en #define o_en (*__comp_inst->o_en) #undef o_hvon #define o_hvon (*__comp_inst->o_hvon) #undef o_ctrltype #define o_ctrltype (*__comp_inst->o_ctrltype) #line 61 "syrctrl.comp" #include variable int mode = 0; variable int reached-home = 0; variable float last-pos = 0; static int differ(float v1, float v2); static int differ(float v1, float v2) { if (abs(v1) > abs(v2)+0.01) return (1); if (abs(v1) < abs(v2)-0.01) return (1); return (0); } FUNCTION(_) { switch (mode) { default: mode = 0; case 0: // idle if (!i-running && i-home && !i-homesw) mode = 1; if (!i-running && differ(i-target-pos, last-pos)) mode = 4; if (i-running && i-m68==1) mode = 5; if (i-running && i-m68==2) mode = 6; o-en = 0; o-ctrltype = 0; break; case 1: // homing if (i-homesw) mode = 2; o-en = 1; o-ctrltype = 1; break; case 2: // backoff if (!i-homesw) mode = 3; o-en = 1; o-ctrltype = 1; break; case 3: // homed mode = 0; o-en = 0; o-ctrltype = 0; break; case 4: // jogging if (!differ(i-target-pos,last-pos) && !differ(i-target-pos,i-limit-pos)) mode = 0; o-en = 1; o-ctrltype = 0; break; case 5: // extruding if ((i_running && i-m68==0) || (!i_running)) mode = 0; o-en = 1; o-ctrltype = 1; break; case 6: // spinning if ((i_running && i-m68==0) || (!i_running)) mode = 0; o-en = 1; o-ctrltype = 1; break; } } static int __comp_get_data_size(void) { return 0; }