How to make M1** execute Gcode

More
31 Jul 2022 21:23 #248757 by andypugh
The existing remap.py is fairly close to what you had. as a bash script. So it should be a decent starting point.

You might want to choose a different M-code and make things consistent. Currently M201 is calling a function called M172.
The following user(s) said Thank You: my1987toyota

Please Log in or Create an account to join the conversation.

More
31 Jul 2022 22:00 - 31 Jul 2022 22:02 #248760 by my1987toyota
I did notice that when I looked at it's code . I wasn't exactly sure of it's purpose but I wasn't going to question. The end game for the
M-code will be it will use a P number to represent what feeder position to travel to and use a table file via either a .tbl  or similar.
That way any component offset can be entered into the table file and when The M-code and P number are entered the pickup
head will go to the exact position required . But that will be down the road. For now just having an M-code that I can enter
those offsets into will suffice.
Last edit: 31 Jul 2022 22:02 by my1987toyota.

Please Log in or Create an account to join the conversation.

More
31 Jul 2022 23:07 #248761 by my1987toyota
I have another question for you andy . Why are only "if" statemants used and not "if" and "elif".?

Please Log in or Create an account to join the conversation.

More
01 Aug 2022 02:11 - 01 Aug 2022 02:12 #248765 by andypugh

for some inexplicable reason the forum will include the date in some file names.

It's not entirely inexplicable, all these files live in an attachments folder on the server, and mine is almost certainly not the first remap.py posted here. 
But the file names in that folder need to be unique.
Last edit: 01 Aug 2022 02:12 by andypugh.
The following user(s) said Thank You: my1987toyota

Please Log in or Create an account to join the conversation.

More
01 Aug 2022 02:14 #248766 by andypugh

I have another question for you andy . Why are only "if" statemants used and not "if" and "elif".?


Do you want the real answer? I jump between C, VBA and Python so often I forget which uses elif, else if and elseif.
The following user(s) said Thank You: my1987toyota

Please Log in or Create an account to join the conversation.

More
01 Aug 2022 15:10 #248792 by my1987toyota
Gotcha I didn't know if their was some specific rule of why you used only if statements. it was only when I looked up how to do Case Statements
in python that I discovered that python doesn't do Case statements like C or C++ and probably others do. I am trying to learn C on my own
But honestly I'm struggling with it right now.

Please Log in or Create an account to join the conversation.

More
02 Aug 2022 12:50 #248835 by my1987toyota
Hi Andypugh . I have a Python question for you. From what I have read if you exclusively use "if" statements multiple one's can be true and
executed at the same time. if someone uses "if" and "elif" statements once one is true the rest are ignored. Am I understanding that correctly?
I am still very much learning this stuff so I don't know the rules yet.

Please Log in or Create an account to join the conversation.

More
02 Aug 2022 14:28 #248843 by Todd Zuercher
An if and the elif statemts that follow it form a tree or line, that once one of the statements in that line are true, the ones that follow (in that line) are ignored. But that doesn't apply to other separate if lines in the program. They should still be processed individually. Elif (or else if) is kind of the opposite of then.
The following user(s) said Thank You: my1987toyota

Please Log in or Create an account to join the conversation.

More
03 Aug 2022 12:36 - 03 Aug 2022 12:37 #248927 by rodw
Replied by rodw on topic How to make M1** execute Gcode
I have not played with it at all but Python 3.10 which is shipped with Debian Bookworm where Linuxcnc can be installed using:
sudo apt install linuxcnc-uspace
Now includes a case statement:

http_code = "418"
match http_code:
    case "200":
        print("OK")
        do_something_good()
    case "404":
        print("Not Found")
        do_something_bad()
    case "418":
        print("I'm a teapot")
        make_coffee()
    case _:
        print("Code not found")
Ref: towardsdatascience.com/switch-case-state...-python-d0caf7b2bfd3

Its enought to make me want to adopt Bookworm as my new best friend.
Last edit: 03 Aug 2022 12:37 by rodw.
The following user(s) said Thank You: my1987toyota

Please Log in or Create an account to join the conversation.

More
04 Aug 2022 05:50 - 07 Aug 2022 06:08 #249004 by tjtr33
Hi,
I dont knopw if this will help
but I use M1xx to move
Theres a comp i use
and it changes modes from auto to Pause
and the motion destination is set by a seperate Mcode
My effort is for EDM
Yours is PickAnPlace
But the use of MoveWhilePaused is similar
Mine uses a single axis but can be modified
Yours would like have motion with some waypoints
that is, move UPtoClearHeight then XYtoPartWanted then DownToGrabPart then XYtoOverDest then DownToPartDestHeight
All this could be done using machine coordinates

This idea does NOT use Gcode, just destination positions
This code does NOT use PID Accell/Decell
This idea ends at same position where it began
That allows the mode reversal back to Auto without any jerk.
I attach the comp code and the hal wiring as png's
hth tomp

edit 07aug2022
in python script use
import sys, subprocess

then build your command string
  like  cmdstr = "halcmd setp testEtab.0.mypin"
and add the value to be set
  like cmdstr = cmdstr + str(myval)
then have the system exec the cmdstr
  like
    subprocess.call(cmdstr, shell=True)

loop that recipe thru all the pins to be set

hth tomp

watch in action


  subprocess.call(strg5, shell=True)
...
 
Attachments:
Last edit: 07 Aug 2022 06:08 by tjtr33. Reason: example code & video link added
The following user(s) said Thank You: my1987toyota

Please Log in or Create an account to join the conversation.

Time to create page: 0.275 seconds
Powered by Kunena Forum