Help with simple M1XX file
- stevep55376
- Offline
- New Member
Less
More
- Posts: 4
- Thank you received: 0
08 Jan 2014 04:58 #42458
by stevep55376
Help with simple M1XX file was created by stevep55376
I am looking for help writing a simple custom M1xx file. I am struggling with the Hal programming language, in my advancing age and my old IF THEN ELSE programming logic I don't seem to be getting this Hal format.
I want to connect a punch to my machine, I would like to use a custom M1xx program to do the following:
Step 1 turn on pin 14 to activate the punch solenoid
Step 2 keep active for .2 seconds
Step 3 turn off pin 14 to deactivate the punch solenoid
(May need a time delay here)?
Step 4 Verify that the "punch up" limit switch is met
Step 5 If the switch is not met after 5 seconds activate the feed hold and print an error message to the screen,
If the switch is met then exit the M program and return to the main Gcode program until the next Punch M1xx code is called.
This is what I have so far;
M101
#!/bin/bash
halcmd setp parport.0.pin-14-out true
sleep 0.2
halcmd setp parport.0.pin-14-out false
sleep 0.2
HELP HELP HELP
.
.
.
exit 0
Thanks for any help you can give me, SteveP
I want to connect a punch to my machine, I would like to use a custom M1xx program to do the following:
Step 1 turn on pin 14 to activate the punch solenoid
Step 2 keep active for .2 seconds
Step 3 turn off pin 14 to deactivate the punch solenoid
(May need a time delay here)?
Step 4 Verify that the "punch up" limit switch is met
Step 5 If the switch is not met after 5 seconds activate the feed hold and print an error message to the screen,
If the switch is met then exit the M program and return to the main Gcode program until the next Punch M1xx code is called.
This is what I have so far;
M101
#!/bin/bash
halcmd setp parport.0.pin-14-out true
sleep 0.2
halcmd setp parport.0.pin-14-out false
sleep 0.2
HELP HELP HELP
.
.
.
exit 0
Thanks for any help you can give me, SteveP
Please Log in or Create an account to join the conversation.
08 Jan 2014 19:43 - 08 Jan 2014 19:48 #42492
by Rick G
Replied by Rick G on topic Help with simple M1XX file
Have you considered call a sub program to do that?
For example, below is just from memory, not code just a rough example...
linuxcnc.org/docs/html/gcode/m-code.html#sec:M100-to-M199
O<punch> sub
M101; Step 1 turn on pin 14 to activate the punch solenoid
G4P.2 ; Step 2 keep active for .2 seconds
M102 ;Step 3 turn off pin 14 to deactivate the punch solenoid
G4P.2 ;pause
M66 P0 L3 Q5 (wait up to 5 seconds for digital input 0 to turn on) Step 4 Verify that the "punch up" limit switch is met)
O105 IF [ #5399 ne 1] ;Step 5 If the switch is not met after 5 seconds activate the feed hold and print an error message to the screen,
(debug, Punch failure)
O106 return
O105 ENDIF
O<punch> endsub
Take a look here...
linuxcnc.org/docs/devel/html/gcode/m-cod...ec:M66-Input-Control
Rick G
For example, below is just from memory, not code just a rough example...
linuxcnc.org/docs/html/gcode/m-code.html#sec:M100-to-M199
O<punch> sub
M101; Step 1 turn on pin 14 to activate the punch solenoid
G4P.2 ; Step 2 keep active for .2 seconds
M102 ;Step 3 turn off pin 14 to deactivate the punch solenoid
G4P.2 ;pause
M66 P0 L3 Q5 (wait up to 5 seconds for digital input 0 to turn on) Step 4 Verify that the "punch up" limit switch is met)
O105 IF [ #5399 ne 1] ;Step 5 If the switch is not met after 5 seconds activate the feed hold and print an error message to the screen,
(debug, Punch failure)
O106 return
O105 ENDIF
O<punch> endsub
Take a look here...
linuxcnc.org/docs/devel/html/gcode/m-cod...ec:M66-Input-Control
Rick G
Last edit: 08 Jan 2014 19:48 by Rick G.
Please Log in or Create an account to join the conversation.
08 Jan 2014 22:17 #42500
by andypugh
I suspect that part of the problem is that you think you are programming in HAL, but actually you are programming in "bash"
I have no idea how to do that either, but perhaps Google does?
linux.die.net/Bash-Beginners-Guide/chap_07.html
something like
ought to exit if the parport pin is set. But that doesn't handle the timeout. For that you would need to wrap the if-then-fi in a loop in a counter.
I have no idea if this will work as-written as I don't have a bash shell here and I have almost zero shell scripting experience.
I have also rather glossed-over sending a message to the user.
Replied by andypugh on topic Help with simple M1XX file
I am looking for help writing a simple custom M1xx file. I am struggling with the Hal programming language, in my advancing age and my old IF THEN ELSE programming logic I don't seem to be getting this Hal format.
I suspect that part of the problem is that you think you are programming in HAL, but actually you are programming in "bash"
Step 4 Verify that the "punch up" limit switch is met
Step 5 If the switch is not met after 5 seconds activate the feed hold and print an error message to the screen,
If the switch is met then exit the M program and return to the main Gcode program until the next Punch M1xx code is called.
I have no idea how to do that either, but perhaps Google does?
linux.die.net/Bash-Beginners-Guide/chap_07.html
something like
...
halcmd getp parport.0.pin-01-in
if [ $? eq 1 ] ;
then exit 0
fi
ought to exit if the parport pin is set. But that doesn't handle the timeout. For that you would need to wrap the if-then-fi in a loop in a counter.
COUNTER = 0
while [ $COUNTER lt 25 ] ; do
halcmd getp parport.0.pin-01-in
if [ $? eq 1 ] ; then
exit 0
fi
sleep 0.2
(( COUNTER ++ ))
done
halcmd setp motion.feedhold 1
I have no idea if this will work as-written as I don't have a bash shell here and I have almost zero shell scripting experience.
I have also rather glossed-over sending a message to the user.
Please Log in or Create an account to join the conversation.
- stevep55376
- Offline
- New Member
Less
More
- Posts: 4
- Thank you received: 0
08 Jan 2014 23:59 #42504
by stevep55376
Replied by stevep55376 on topic Help with simple M1XX file
Thanks Rick for your suggestion, it looks like I have the Sub program working.
This is a nice option to have with sub's in a Gcode program. I am also able to save it as a file and call it just like an M1xx file.
Thanks allot.
This is a nice option to have with sub's in a Gcode program. I am also able to save it as a file and call it just like an M1xx file.
Thanks allot.
Please Log in or Create an account to join the conversation.
- stevep55376
- Offline
- New Member
Less
More
- Posts: 4
- Thank you received: 0
09 Jan 2014 00:04 #42505
by stevep55376
Replied by stevep55376 on topic Help with simple M1XX file
Andy thanks for the reply, I did get my punch working using a Sub program but will still investigate the Bash language. I am sure there is a lot of power in this programming language, i just need to understand the basics.
Thanks again,
Thanks again,
Please Log in or Create an account to join the conversation.
09 Jan 2014 18:10 #42543
by Rick G
Replied by Rick G on topic Help with simple M1XX file
Your welcome,
Glad you have it working the way you wanted.
Rick G
Glad you have it working the way you wanted.
Rick G
Please Log in or Create an account to join the conversation.
Time to create page: 0.073 seconds