531,720 active members*
3,376 visitors online*
Register for free
Login
Results 1 to 11 of 11
  1. #1

    Reading input in scripts

    Hello
    I would like to evaluate the state of a specific input pin in a script wit a.
    Is this possible?


    Background:
    I have a wireless probe that sets a output pin if the wireless probe is not turned on. I would like to check the state prior to executing any measurements (yea I managed to forget turn on the Probe an break a Stylus......)

    basically adding something like this to the beginning of each measurement script should do the trick:
    O<ProbeCheck> if[<INPUT PIN 1> EQ 1]
    (msg,Probe is not turned on)
    M2
    O<ProbeCheck> endif

    However I don't know what I need to enter for
    <INPUT PIN 1>

    All I found in the Documentation was M59
    However this seems to Wait for a input and not evaluate its state. I might be able to use it as a workaround by inverting the error pin and thus preventing the code from running further if the Input pin is low (assuming M59 does not wait for a change of the input) But a if statement with a message box would be the better solution because I could put all the existing code into the else part which should make it quiet foolproofed.

    Best Regards,
    Klaus

  2. #2

    Re: Reading input in scripts

    short update:

    Looks like the syntax could be:
    O<ProbeCheck> if [[#<_hw_input_num|1>]]
    Seems to work in simulation but need to test it on the machine tomorrow.

  3. #3

    Re: Reading input in scripts

    #<_hw_input_num|1>
    Is working as expected.

    I found noch documentation on how to access the pins directly (Checked the Website, Blog and pdf manuals in the installation folder).
    Is there some source I'm currently missing or is this just a undocumented feature (I basically got it from looking at the delivered scripts and some good guessing)?

    Best Regards,
    Klaus

  4. #4
    Moderator
    Join Date
    Mar 2017
    Posts
    710

    Re: Reading input in scripts

    Quote Originally Posted by ScorpionTDL View Post
    ... how to access the pins directly
    To directly access input pin 1 use #<_hw_input_num|1>

  5. #5
    Quote Originally Posted by PlanetCNC View Post
    To directly access input pin 1 use #<_hw_input_num|1>
    Thanks for the confirmation.
    Is it possible to use some kind of a variable that can be set in the header of the script? I would like to implement some additional checks and would like to be able to easily change the pin in just one place of the script.

  6. #6
    Moderator
    Join Date
    Mar 2017
    Posts
    710

    Re: Reading input in scripts

    I believe all this things are possible but to give you better answer I'll need better (detailed) question.

  7. #7

    Re: Reading input in scripts

    OK, lets work with an actual script that I try to modify as an example. In fact while writing this post I figured some of the stuff out, but a comment if I'm doing it correctly would be welcome.

    I have a Wireless Probe from https://vers.by/
    The Receiver has a error Pin that is connected to input 1 of my controller. This error pin is triggert on several occasions.
    1. If the Probe is turned of and not ready
    2. the Delay of the Measurement was too high due to problems with the wireless connection.

    To ensure a robust measurement the error pin needs to be check on multiple occasions.
    1. before each G38 it needs to be checked if the probe is ready, G38 should only be executed if the probe is ready.
    2. after each G38 it needs to be checked to validate if the Measurement was accurate, if not a error message should be displayed to warn the user

    I tried to implement this in the Measure/Axis script (attached at the end of this post). In general this is working OK, but I'm not 100% happy with it due to the following reasons:
    a. [#<_hw_input_num|1> is repeated multiple times throughput the script. I would like to define the input pin once at the beginning of the script to avoid any issues should I change the port sometime in the future, or someone else uses the code and want to use a different port. While writing this I figured that I can just put a #<_Probe_error_pin>=1 at the beginning of the script and use this as the pin info. So this questions is answered.
    b. I'm currently setting the variable #<_measure_failed> in the sub routine O<probe>, can I return the value of #<_measure_failed> together with #<_measure> to access its value outside of the sub? I assume that every variable starting with a _ is threated as global (at last the _ was required for the _Probe_error_pin to work within the sub and not only outside of it), Is the modified value of #<_measure_failed> available outside of the Sub? If yes, why is the measure value set to the return value with #<_measure> = #<_return> after calling the sub.

    I assume its quiet obvious that I'm new to this kind of gcode programming (I typically Programm in Python, C#, Javascript etc...) and it seems I'm missing a lot of information about the syntax and code words. Sorry if this are somewhat obvious or stupid questions. Is there some documentation about the programming capabilities of Planet CNC beside the GCODE pdf file?
    Or is Planet CNC using some kind of a open standard syntax that I can look up somewhere else?



    Code:
    (name,Measure Axis)
    #<_Probe_error_pin>=1
    O<Probe_check> if [[#<_hw_input_num|#<_Probe_error_pin>>]]
     (msg,Probe not turned on or in sleep!!!)
     M2
    O<Probe_check> else
    
    O<PlanetCNC> if[[#<_probe_pin_1> EQ 0] AND [#<_probe_pin_2> EQ 0]]
      (msg,Sensor is not configured)
      M2
    O<PlanetCNC> endif
    
    (dlgname,Measure Axis)
    (dlg,Select start postition, typ=label, x=20, w=455, color=0xffa500)
    (dlg,data::MeasureAxis, typ=image, x=0)
    (dlg,|X+|X-|Y+|Y-, typ=checkbox, x=50, w=425, def=1, param=strt)
    (dlgshow)
    
    M73 ;store state, auto restore
    G17 G90 G91.1 G90.2 G08 G15 G94
    M50P0 ;disable speed override
    M55P0 ;disable trans
    M56P0 ;disable warp
    M57P0 ;disable swap
    M10P1 ;motor enable
    M11P1 ;limits/probe enable
    
    o<st> if [#<strt> EQ 1]
      #<axis> = 0
      #<dir> = +1
    o<st> elseif [#<strt> EQ 2]
      #<axis> = 0
      #<dir> = -1
    o<st> elseif [#<strt> EQ 3]
      #<axis> = 1
      #<dir> = +1
    o<st> elseif [#<strt> EQ 4]
      #<axis> = 1
      #<dir> = -1
    o<st> else
      (msg,Error)
      M2
    o<st> endif
    
    #<pos> = #<_machine_axis|#<axis>>
    O<probe> call [#<axis>] [#<dir>]
    #<_measure> = #<_return>
    G53 G00 H#<axis> E#<pos>
    
    G53 G00 Z#<_probe_safeheigh>
    
    G53 G00 H#<axis> E#<_measure>
    
    o<st> if [#<strt> EQ 1]
      (print,Measure result: X=#<_measure>)
    o<st> elseif [#<strt> EQ 2]
      (print,Measure result: X=#<_measure>)
    o<st> elseif [#<strt> EQ 3]
      (print,Measure result: Y=#<_measure>)
    o<st> elseif [#<strt> EQ 4]
      (print,Measure result: Y=#<_measure>)
    o<st> else
      (msg,Error)
      M2
    o<st> endif
    
    
    M2
    O<Probe_check> endif	
    
    O<probe> sub
    M73
    #<axis> = #1
    #<dir> = #2
    #<_measure_failed> = 0
    O<Probe_check_1> if [[#<_hw_input_num|#<_Probe_error_pin>>]]
        (msg,Probe not turned on or in sleep, Measurement Failed!!!)
        #<_measure_failed> = 1
        M2
    O<Probe_check_1> else
        M11P0 G38.2 H#<axis> E[#<dir> * 100000] F#<_probe_speed>
        G91 G01 H#<axis> E[-#<dir> * #<_probe_swdist>]
        o<low> if [#<_probe_speed_low> GT 0]
            O<Probe_check_2> if [[#<_hw_input_num|#<_Probe_error_pin>>]]
                (msg,Probe not turned on or in sleep, Measurement Failed!!!)
                #<_measure_failed> = 1
                M2
            O<Probe_check_2> else
                G90 G38.2 H#<axis> E[#<dir> * 100000] F#<_probe_speed_low>
                O<Probe_check_3> if [[#<_hw_input_num|#<_Probe_error_pin>>]]
                    (msg,Probe delay too big. Measurement inaccurate!!!)
                    #<_measure_failed> = 1
                    M2
                O<Probe_check_3> endif          
                G91 G01 H#<axis> E[-#<dir> * #<_probe_swdist>] F#<_probe_speed>
            O<Probe_check_2> endif
        o<low> endif
        M11P1 G90
    #<_measure> = [#<_probe_axis|#<axis>> + #<dir> * #<_probe_size_axis|#<axis>>]
    O<Probe_check_1> endif
    O<probe> endsub [#<_measure>]

  8. #8
    Moderator
    Join Date
    Mar 2017
    Posts
    710

    Re: Reading input in scripts

    Variables that begin with _ are global.
    #<_measure> = #<_return> is redundant.

    You solved both a and b reasons correctly.

    PlanetCNC syntax is based on LinuxCNC. However it is greatly evolved and there is really no good documentation.
    GCODE pdf should one day cover all this stuff. But there are not many people that actually bother to check documentation so it isn't on highest priority. You are and exception.

  9. #9

    Re: Reading input in scripts

    Thanks for confirming my assumptions.

    I will have a look if I can find some documentation for Linux cnc. Most likely this is like any other programming language and once I get the general idea I can normally figure most of the stuff out. Unfortunately the normal Google approach does not work for most of the cnc stuff ;-)
    So I might rely on asking questions here from time to time.

    I totally get that handling documentation is not a thankfully task.

  10. #10
    Moderator
    Join Date
    Mar 2017
    Posts
    710

    Re: Reading input in scripts

    LinuxCNC documentation will not help you. TNG evolved this to much higher lever.
    Feel free to ask.

  11. #11

    Re: Reading input in scripts

    OK, seems I will just go forward and ask questions when they arise ;-)

    Completely different topic but somewhat related:
    As I'm currently enhancing the original Measurements scripts to handle the vers.by requirements I was thinking of making them publicly available. Is this OK? Do I have to include any licensing information? As they are mainly the code from TNG with should be under TNG license I'm not sure how you handle this.

Similar Threads

  1. debugging scripts
    By kjl-pdx in forum Mach Wizards, Macros, & Addons
    Replies: 0
    Last Post: 01-23-2014, 05:36 AM
  2. reading input in NC program
    By aliaghaei in forum Fanuc
    Replies: 1
    Last Post: 09-19-2012, 01:58 PM
  3. Need help with scripts
    By joewaterjet in forum BobCad-Cam
    Replies: 1
    Last Post: 03-13-2012, 05:24 AM
  4. Scripts
    By tjones in forum Tutorials
    Replies: 0
    Last Post: 01-25-2006, 07:06 PM
  5. vb scripts
    By HuFlungDung in forum Mastercam
    Replies: 2
    Last Post: 07-08-2003, 05:53 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •