commit 1ac3c08f36000fea787e025833789d5479ad0413 Author: Carl Philipp Klemm Date: Wed Jul 23 17:56:50 2025 +0200 inital commit diff --git a/build/collisionavoid b/build/collisionavoid new file mode 100755 index 0000000..3976fa5 Binary files /dev/null and b/build/collisionavoid differ diff --git a/build/collisionavoid.c b/build/collisionavoid.c new file mode 100644 index 0000000..f1e0f8e --- /dev/null +++ b/build/collisionavoid.c @@ -0,0 +1,153 @@ +/* Autogenerated by /usr/bin/halcompile on Wed Nov 27 15:02:36 2024 -- 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:collisionavoid:Avoid Collisions"); +MODULE_INFO(linuxcnc, "pin:xaxis:float:0:in::None:None"); +MODULE_INFO(linuxcnc, "pin:yaxis:float:0:in::None:None"); +MODULE_INFO(linuxcnc, "pin:zaxis:float:0:in::None:None"); +MODULE_INFO(linuxcnc, "pin:chuck:bit:0:in::None:None"); +MODULE_INFO(linuxcnc, "pin:table:bit:0:in::None:None"); +MODULE_INFO(linuxcnc, "pin:stop:bit:0:out::None:None"); +MODULE_INFO(linuxcnc, "license:GPL"); +MODULE_LICENSE("GPL"); +#endif // MODULE_INFO + + +struct __comp_state { + struct __comp_state *_next; + hal_float_t *xaxis; + hal_float_t *yaxis; + hal_float_t *zaxis; + hal_bit_t *chuck; + hal_bit_t *table; + hal_bit_t *stop; +}; +#include +struct __comp_state *__comp_first_inst=0, *__comp_last_inst=0; + +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) { + 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->xaxis), comp_id, + "%s.xaxis", prefix); + if(r != 0) return r; + r = hal_pin_float_newf(HAL_IN, &(inst->yaxis), comp_id, + "%s.yaxis", prefix); + if(r != 0) return r; + r = hal_pin_float_newf(HAL_IN, &(inst->zaxis), comp_id, + "%s.zaxis", prefix); + if(r != 0) return r; + r = hal_pin_bit_newf(HAL_IN, &(inst->chuck), comp_id, + "%s.chuck", prefix); + if(r != 0) return r; + r = hal_pin_bit_newf(HAL_IN, &(inst->table), comp_id, + "%s.table", prefix); + if(r != 0) return r; + r = hal_pin_bit_newf(HAL_OUT, &(inst->stop), comp_id, + "%s.stop", prefix); + 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("collisionavoid"); + if(comp_id < 0) return comp_id; + r = export("collisionavoid", 0); + if(r) { + hal_exit(comp_id); + } else { + hal_ready(comp_id); + } + return r; +} + +void rtapi_app_exit(void) { + hal_exit(comp_id); +} +static void user_mainloop(void); +int argc=0; char **argv=0; +int main(int argc_, char **argv_) { + argc = argc_; argv = argv_; + + if(rtapi_app_main() < 0) return 1; + user_mainloop(); + rtapi_app_exit(); + return 0; +} + +#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 xaxis +#define xaxis (0+*__comp_inst->xaxis) +#undef yaxis +#define yaxis (0+*__comp_inst->yaxis) +#undef zaxis +#define zaxis (0+*__comp_inst->zaxis) +#undef chuck +#define chuck (0+*__comp_inst->chuck) +#undef table +#define table (0+*__comp_inst->table) +#undef stop +#define stop (*__comp_inst->stop) +#undef FOR_ALL_INSTS +#define __comp_inst __comp_first_inst +#define FOR_ALL_INSTS() + + +#line 19 "collisionavoid.comp" + +#include /* Standard input/output definitions */ + + +void user_mainloop(void) +{ + FOR_ALL_INSTS() //needed for resaons + { + while(1) + { + usleep(500); + if(chuck == 1 && xaxis > 107 && yaxis < 32 && zaxis < -25 ) stop = 1; + else if(table == 1 && xaxis > 107 && yaxis < 32 && zaxis < -25 ) stop = 1; + else stop = 0; + + } + } + exit(0); +} + + + + + +static int __comp_get_data_size(void) { return 0; } diff --git a/collisionavoid.comp b/collisionavoid.comp new file mode 100644 index 0000000..168652f --- /dev/null +++ b/collisionavoid.comp @@ -0,0 +1,41 @@ +//CNCExtension Hal Component + +component collisionavoid "Avoid Collisions"; + +pin in float xaxis; +pin in float yaxis; +pin in float zaxis; + +pin in bit chuck; +pin in bit table; + +pin out bit stop; + +option singleton yes; // makes no sense to have more than one of these components running +option userspace yes; + +license "GPL"; +;; + +#include /* Standard input/output definitions */ + + +void user_mainloop(void) +{ + FOR_ALL_INSTS() //needed for resaons + { + while(1) + { + usleep(500); + if(chuck == 1 && xaxis > 107 && yaxis < 32 && zaxis < -25 ) stop = 1; + else if(table == 1 && xaxis > 107 && yaxis < 32 && zaxis < -25 ) stop = 1; + else stop = 0; + + } + } + exit(0); +} + + + +