From eba2b73dec241e60e426e774f73cd973ee2365ed Mon Sep 17 00:00:00 2001 From: johan Date: Sat, 21 Mar 2026 22:42:04 +0000 Subject: [PATCH] Upload files to "/" --- README.md | 93 +++++++++++++++++++++ hal_extruder_temp_ctrl.py | 120 +++++++++++++++++++++++++++ my-draw.hal | 101 +++++++++++++++++++++++ my-draw.ini | 167 ++++++++++++++++++++++++++++++++++++++ sync-file.py | 130 +++++++++++++++++++++++++++++ 5 files changed, 611 insertions(+) create mode 100644 README.md create mode 100644 hal_extruder_temp_ctrl.py create mode 100644 my-draw.hal create mode 100644 my-draw.ini create mode 100644 sync-file.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..799b6a1 --- /dev/null +++ b/README.md @@ -0,0 +1,93 @@ +# linuxcnc-configs + + + +## Getting started + +To make it easy for you to get started with GitLab, here's a list of recommended next steps. + +Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! + +## Add your files + +- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files +- [ ] [Add files using the command line](https://docs.gitlab.com/topics/git/add_files/#add-files-to-a-git-repository) or push an existing Git repository with the following command: + +``` +cd existing_repo +git remote add origin http://gitlab.example.com:8929/johan/linuxcnc-configs.git +git branch -M main +git push -uf origin main +``` + +## Integrate with your tools + +- [ ] [Set up project integrations](http://gitlab.example.com:8929/johan/linuxcnc-configs/-/settings/integrations) + +## Collaborate with your team + +- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) +- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) +- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) +- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) +- [ ] [Set auto-merge](https://docs.gitlab.com/user/project/merge_requests/auto_merge/) + +## Test and Deploy + +Use the built-in continuous integration in GitLab. + +- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/) +- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) +- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) +- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) +- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) + +*** + +# Editing this README + +When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template. + +## Suggestions for a good README + +Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. + +## Name +Choose a self-explaining name for your project. + +## Description +Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. + +## Badges +On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. + +## Visuals +Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. + +## Installation +Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. + +## Usage +Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. + +## Support +Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. + +## Roadmap +If you have ideas for releases in the future, it is a good idea to list them in the README. + +## Contributing +State if you are open to contributions and what your requirements are for accepting them. + +For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. + +You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. + +## Authors and acknowledgment +Show your appreciation to those who have contributed to the project. + +## License +For open source projects, say how it is licensed. + +## Project status +If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. diff --git a/hal_extruder_temp_ctrl.py b/hal_extruder_temp_ctrl.py new file mode 100644 index 0000000..ef59a43 --- /dev/null +++ b/hal_extruder_temp_ctrl.py @@ -0,0 +1,120 @@ +#!/usr/bin/python3 +import getopt +import hal +import sys +import comms +import time + +class HalAdapter: + def __init__(self, name): + self.hal = hal.component(name) # instanciate the HAL-component + self.hal.newpin("ref-temp", hal.HAL_U32, hal.HAL_IN) + self.hal.newpin("enable", hal.HAL_BIT, hal.HAL_IN) + self.hal.newpin("curr-temp", hal.HAL_U32, hal.HAL_OUT) + self.hal.newpin("ref-temp-out", hal.HAL_U32, hal.HAL_OUT) + + self.hal.ready() + + def setReady(self): + self.hal.ready() + + def readHAL_refTemp(self): + """read values from LinuxCNC HAL""" + return self.hal['ref-temp'] + + def readHAL_enable(self): + """read values from LinuxCNC HAL""" + return self.hal['enable'] + + def writeHAL_currTemp(self, val): + """ write internal wrapper pin values to LinuxCNC HAL """ + self.hal['curr-temp'] = val + + def writeHAL_refTemp(self, val): + """ write internal wrapper pin values to LinuxCNC HAL """ + self.hal['ref-temp-out'] = val + +class TempControllerFacade: + def __init__(self, port): + self.tempController = comms.instrument(port, self.msgHandler) #serial adaptor + self.currTemp = 100 + self.refTemp = 100 + self.enable = False + + def __repr__(self): + return 'curr temp: ' + str(self.currTemp) + ', ref temp: ' + str(self.refTemp) + ' , enabled; ' + str(self.enable) + '\n' + + def msgHandler(self, m): + if (m.name == 'mv'): + self.currTemp = int(m.data) + + def setEnable(self, en): + self.enable = en + print('extruder temp controller enable: ' + str(self.enable)) + + if en == True: + self.tempController.writeMessage(comms.Message('en' , '1')) + else: + self.tempController.writeMessage(comms.Message('en' , '0')) + + + def setRefTemp(self, refT): + if self.enable == True: + if self.refTemp != refT: + self.tempController.writeMessage(comms.Message('sp' , str(refT))) + self.refTemp = refT + + +def main(): + name = 'my-extruder' + port = '/dev/ttyUSB0' # default serial port to use + + try: + opts, args = getopt.getopt(sys.argv[1:], "hp:c:", ["port="]) + except getopt.GetoptError as err: + # print help information and exit: + print(err) # will print something like "option -a not recognized" + sys.exit(2) + + for o, a in opts: + if o == "-h": + sys.exit() + if o == "-c": + name = a + elif o in ("-p", "--port"): + port = a + else: + print(o) + assert False, "unhandled option" + + h = HalAdapter(name) + tc = TempControllerFacade(port) + #tc.setEnable(True) + + print(tc) + + try: + while 1: + tc.tempController.readMessages() + + if h.readHAL_enable() == 1: + if tc.enable == False: + tc.setEnable(True) + else: + if tc.enable == True: + tc.setEnable(False) + + if tc.enable == True: + refTemp = h.readHAL_refTemp() + tc.setRefTemp(refTemp) + + h.writeHAL_currTemp(tc.currTemp) + h.writeHAL_refTemp(tc.refTemp) + # + time.sleep(1) + + except KeyboardInterrupt: + raise SystemExit + +if __name__ == '__main__': + main() diff --git a/my-draw.hal b/my-draw.hal new file mode 100644 index 0000000..055c8ca --- /dev/null +++ b/my-draw.hal @@ -0,0 +1,101 @@ +# Generated by stepconf 1.1 at Fri May 1 19:07:04 2020 +# If you make changes to this file, they will be +# overwritten when you run stepconf again +loadrt [KINS]KINEMATICS +#autoconverted trivkins +loadrt [EMCMOT]EMCMOT base_period_nsec=[EMCMOT]BASE_PERIOD servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[KINS]JOINTS +loadrt hal_parport cfg="0 out" +setp parport.0.reset-time 5000 +loadrt stepgen step_type=0,0,0 +#loadrt pwmgen output_type=0 + +addf parport.0.read base-thread +addf stepgen.make-pulses base-thread +#addf pwmgen.make-pulses base-thread +addf parport.0.write base-thread +addf parport.0.reset base-thread + +addf stepgen.capture-position servo-thread +addf motion-command-handler servo-thread +addf motion-controller servo-thread +addf stepgen.update-freq servo-thread + +net spindle-at-speed => spindle.0.at-speed + +net xdir => parport.0.pin-02-out +net xstep => parport.0.pin-03-out +setp parport.0.pin-03-out-reset 1 +net ydir => parport.0.pin-04-out +net ystep => parport.0.pin-05-out +setp parport.0.pin-05-out-reset 1 +setp parport.0.pin-06-out-invert 1 +net zdir => parport.0.pin-06-out +net zstep => parport.0.pin-07-out +setp parport.0.pin-07-out-reset 1 +setp parport.0.pin-08-out-invert 1 + +net min-home-x <= parport.0.pin-11-in +net max-home-y <= parport.0.pin-10-in +net max-home-z <= parport.0.pin-12-in + +setp stepgen.0.position-scale [JOINT_0]SCALE +setp stepgen.0.steplen 1 +setp stepgen.0.stepspace 0 +setp stepgen.0.dirhold 35000 +setp stepgen.0.dirsetup 35000 +setp stepgen.0.maxaccel [JOINT_0]STEPGEN_MAXACCEL +net xpos-cmd joint.0.motor-pos-cmd => stepgen.0.position-cmd +net xpos-fb stepgen.0.position-fb => joint.0.motor-pos-fb +net xstep <= stepgen.0.step +net xdir <= stepgen.0.dir +net xenable joint.0.amp-enable-out => stepgen.0.enable +net min-home-x => joint.0.home-sw-in +net min-home-x => joint.0.neg-lim-sw-in + +setp stepgen.1.position-scale [JOINT_1]SCALE +setp stepgen.1.steplen 1 +setp stepgen.1.stepspace 0 +setp stepgen.1.dirhold 35000 +setp stepgen.1.dirsetup 35000 +setp stepgen.1.maxaccel [JOINT_1]STEPGEN_MAXACCEL +net ypos-cmd joint.1.motor-pos-cmd => stepgen.1.position-cmd +net ypos-fb stepgen.1.position-fb => joint.1.motor-pos-fb +net ystep <= stepgen.1.step +net ydir <= stepgen.1.dir +net yenable joint.1.amp-enable-out => stepgen.1.enable +net max-home-y => joint.1.home-sw-in +net max-home-y => joint.1.pos-lim-sw-in + +setp stepgen.2.position-scale [JOINT_2]SCALE +setp stepgen.2.steplen 1 +setp stepgen.2.stepspace 0 +setp stepgen.2.dirhold 35000 +setp stepgen.2.dirsetup 35000 +setp stepgen.2.maxaccel [JOINT_2]STEPGEN_MAXACCEL +net zpos-cmd joint.2.motor-pos-cmd => stepgen.2.position-cmd +net zpos-fb stepgen.2.position-fb => joint.2.motor-pos-fb +net zstep <= stepgen.2.step +net zdir <= stepgen.2.dir +net zenable joint.2.amp-enable-out => stepgen.2.enable +net max-home-z => joint.2.home-sw-in +net max-home-z => joint.2.pos-lim-sw-in + +net estop-out <= iocontrol.0.user-enable-out +net estop-out => iocontrol.0.emc-enable-in + +sets spindle-at-speed true + +loadusr -W hal_manualtoolchange +net tool-change iocontrol.0.tool-change => hal_manualtoolchange.change +net tool-changed iocontrol.0.tool-changed <= hal_manualtoolchange.changed +net tool-number iocontrol.0.tool-prep-number => hal_manualtoolchange.number +net tool-prepare-loopback iocontrol.0.tool-prepare => iocontrol.0.tool-prepared + +### enable steppers +net and-in1 halui.machine.is-on => parport.0.pin-17-out + +#disable hot bed +setp parport.0.pin-14-out 0 + +#disable extruderfan +setp parport.0.pin-16-out 0 \ No newline at end of file diff --git a/my-draw.ini b/my-draw.ini new file mode 100644 index 0000000..0838387 --- /dev/null +++ b/my-draw.ini @@ -0,0 +1,167 @@ +# This config file was created 2021-02-04 16:39:45.407451 by the update_ini script +# The original config files may be found in the /home/johan/linuxcnc/configs/test/test.old directory + +# Generated by stepconf 1.1 at Fri May 1 19:07:04 2020 +# If you make changes to this file, they will be +# overwritten when you run stepconf again + +[EMC] +# The version string for this INI file. +VERSION = 1.1 + +MACHINE = my-draw +DEBUG = 0 + +[DISPLAY] +DISPLAY = axis +EDITOR = gedit +POSITION_OFFSET = RELATIVE +POSITION_FEEDBACK = ACTUAL +ARCDIVISION = 64 +GRIDS = 10mm 20mm 50mm 100mm 1in 2in 5in 10in +MAX_FEED_OVERRIDE = 1.2 +MIN_SPINDLE_OVERRIDE = 0.5 +MAX_SPINDLE_OVERRIDE = 1.2 +DEFAULT_LINEAR_VELOCITY = 2.50 +MIN_LINEAR_VELOCITY = 0 +MAX_LINEAR_VELOCITY = 25.00 +DEFAULT_ANGULAR_VELOCITY = 36.00 +MIN_ANGULAR_VELOCITY = 0 +MAX_ANGULAR_VELOCITY = 360.00 +INTRO_GRAPHIC = linuxcnc.gif +INTRO_TIME = 5 +PROGRAM_PREFIX = /home/johan/linuxcnc/nc_files +INCREMENTS = 5mm 1mm .5mm .1mm .05mm .01mm .005mm +GEOMETRY = XYZ + +[FILTER] +PROGRAM_EXTENSION = .png,.gif,.jpg Greyscale Depth Image +PROGRAM_EXTENSION = .py Python Script +PROGRAM_EXTENSION = .gcode 3D Printer + +png = image-to-gcode +gif = image-to-gcode +jpg = image-to-gcode +py = python + + +[RS274NGC] +PARAMETER_FILE = linuxcnc.var +SUBROUTINE_PATH=/home/johan/linuxcnc/configs/my-3d/custom-m-codes +USER_M_PATH=/home/johan/linuxcnc/configs/my-3d/custom-m-codes + + +[EMCMOT] +EMCMOT = motmod +COMM_TIMEOUT = 1.0 +BASE_PERIOD = 100000 +SERVO_PERIOD = 1000000 + +[TASK] +TASK = milltask +CYCLE_TIME = 0.010 + +[HAL] +HALUI = halui +HALFILE = my-draw.hal + +[HALUI] + +[TRAJ] +COORDINATES = XYZ +JOINTS = 3 +HOME = 0 0 0 +LINEAR_UNITS = mm +ANGULAR_UNITS = degree +DEFAULT_LINEAR_VELOCITY = 25.0 +MAX_LINEAR_VELOCITY = 25.0 +MAX_LINEAR_ACCELERATION = 50.0 +DEFAULT_LINEAR_ACCELERATION = 50.0 + +[EMCIO] +EMCIO = io +CYCLE_TIME = 0.100 +TOOL_TABLE = tool.tbl + + +[KINS] +KINEMATICS = trivkins coordinates=XYZ +JOINTS = 3 + +# X axis +#prescale = 2, steps/rev = 200, 2 mm/rev +#scale = 200*2/2 steps/mm +[AXIS_X] +MIN_LIMIT = -90.0 +MAX_LIMIT = 90.0 +MAX_VELOCITY = 25.0 +MAX_ACCELERATION = 50.0 + +[JOINT_0] +TYPE = LINEAR +HOME = 0.0 +MAX_VELOCITY = 25.0 +MAX_ACCELERATION = 50.0 +STEPGEN_MAXACCEL = 62.5 +SCALE = 200.0 +FERROR = 1 +MIN_FERROR = .25 +MIN_LIMIT = -90.0 +MAX_LIMIT = 90.0 +HOME_OFFSET = -91.400000 +HOME_SEARCH_VEL = -10.0 +HOME_LATCH_VEL = -1.50 +HOME_IGNORE_LIMITS = YES +HOME_SEQUENCE = 0 + +# Y axis +#prescale = 2, steps/rev = 200, 2 mm/rev +#scale = 200*2/2 steps/mm +[AXIS_Y] +MIN_LIMIT = -90.0 +MAX_LIMIT = 90.0 +MAX_VELOCITY = 25.0 +MAX_ACCELERATION = 50.0 + +[JOINT_1] +TYPE = LINEAR +HOME = 0.0 +MAX_VELOCITY = 25.0 +MAX_ACCELERATION = 50.0 +STEPGEN_MAXACCEL = 62.5 +SCALE = 200.0 +FERROR = 1 +MIN_FERROR = .25 +MIN_LIMIT = -90.0 +MAX_LIMIT = 90.0 +HOME_OFFSET = 66.00000 +HOME_SEARCH_VEL = 10.0 +HOME_LATCH_VEL = 2.5 +HOME_IGNORE_LIMITS = YES +HOME_SEQUENCE = 0 + +# Z axis +#prescale = 8, steps/rev = 200, 1 mm/rev +#scale = 200*8/1 = 1600 steps/mm +[AXIS_Z] +MIN_LIMIT = -10.0 +MAX_LIMIT = 51.7 +MAX_VELOCITY = 6.0 +MAX_ACCELERATION = 50.0 + +[JOINT_2] +TYPE = LINEAR +HOME = 48.0 +MAX_VELOCITY = 6.0 +MAX_ACCELERATION = 50.0 +STEPGEN_MAXACCEL = 62.5 +SCALE = 1600.0 +FERROR = 1 +MIN_FERROR = .25 +MIN_LIMIT = -10.0 +MAX_LIMIT = 51.7 +HOME_OFFSET = 51.7 +HOME_SEARCH_VEL = 7.500000 +HOME_LATCH_VEL = 0.312500 +HOME_IGNORE_LIMITS = YES +HOME_SEQUENCE = 0 diff --git a/sync-file.py b/sync-file.py new file mode 100644 index 0000000..69f3474 --- /dev/null +++ b/sync-file.py @@ -0,0 +1,130 @@ +#!/usr/bin/python3 + +import os +import subprocess +import getopt +import sys +import filecmp +import shutil + +CRED = '\033[91m' +CEND = '\033[0m' +CCYAN = '\033[96m' +CBLUE = '\033[94m' +CGREEN = '\033[92m' + +def _usage(): + """ print command line options """ + print("usage sync-file.py -h/--help -c/--compare-path= -p/--print file\n"\ + "file # input fil , left side of diff\n"\ + "-c / -compare-path= # to directory to file-sync\n"\ + "-p / --print # print only, dont do any actual sync\n"\ + "-h / --help # Help ") + +def _get_last_mod_date(file): + try: + return int(round(os.path.getmtime(file))) + except FileNotFoundError as err: + print(err) + return None + +def _diff_files(src_file, dst_file): + diff_cmd = shutil.which('meld') + + if diff_cmd != None: + try: + subprocess.run([diff_cmd, src_file, dst_file]) + except: + print("can't start diff tool") + else: + print("can't find diff tool") + +def _conditional_copy_file(src_file, dst_file): + if _ask(): + os.system('cp ' + src_file + ' ' + dst_file) + +def _ask(): + try: + answer = lower(input('\tproceed with copy? [Y/n]: ')) + except EOFError: + return False + + ret_val = False + if answer == '' or answer == 'y' or answer == 'yes': + ret_val = True + + return ret_val + +def main(): + try: + opts, args = getopt.getopt(sys.argv[1:], "dphc:", ["diff", "compare-path=", "print", "help"]) + except getopt.GetoptError as err: + # print help information and exit: + print(err) # will print something like "option -a not recognized" + sys.exit(2) + + file_diff = False + dry_run = False + compare_path = "." + + ### parse input command line + for o, a in opts: + if o in ("-h", "--help"): + _usage() + sys.exit() + elif o in ("-p", "--print"): + dry_run = True + elif o in ("-c", "--compare-path"): + compare_path = a + elif o in ("-d", "--diff"): + file_diff = True + else: + print(o, a) + assert False, "unhandled option" + + for left_file in args: + #left_file contain the full path + file name. pick out filename only and apply the compare_path + right_file = compare_path + '/' + left_file #os.path.basename(left_file) + #print(left_file) + #print(right_file) + left_file_exists = os.path.isfile(left_file) + right_file_exists = os.path.isfile(right_file) + + if not left_file_exists: + print(CRED + '\tno such file... ' + left_file + CEND) + if not right_file_exists: + print(CRED + '\tno such file... ' + right_file + CEND) + + if not dry_run: + _conditional_copy_file(left_file, right_file) + + if left_file_exists and right_file_exists: + #if left and right are different, decide which file is to be copied + if not filecmp.cmp(left_file, right_file): + left_file_mod_time = _get_last_mod_date(left_file) + right_file_mod_time = _get_last_mod_date(right_file) + + if left_file_mod_time < right_file_mod_time: # left file newer + src_file = right_file + dst_file = left_file + color = CBLUE + else: # right file newer + src_file = left_file + dst_file = right_file + color = CCYAN + + print(color + '\t' + src_file + ' is newer than ' + dst_file + '...' + CEND) + + if not dry_run: + _conditional_copy_file(src_file, dst_file) + + if file_diff: + _diff_files(left_file, right_file) + + + else: + print(CGREEN + '\t' + os.path.basename(left_file) + ' same same...' + CEND) + + +if __name__ == '__main__': + main()