Home Troubleshooting

Discussion

Left ArrowBack to discussions page
tom24tom24 Unconfirmed Posts: 37 Apprentice
the  Hass send signal to the robot two times with one signal M100. the first signal stay as input to the robot for 1 second and the second will stay for 3 second . so if i need only the second signal how i can use the timer. i tested may times but  it is not work. i appreciated for the help 
for instance i use like this before start 
time=0
timer=false
main program
if DIO =true and time=1 sec
    timer=false 
else DIO=true and timer =3 sec

Comments

  • LoïcLoïc Posts: 29 Handy
    The easier way I'm seeing to do it is to use some loop and delay. Maybe something like this:

    timer=false
    Loop timer=false
      wait(0.01)
      Count=0
      Loop DIO=true
        if Count>=10
          timer=true
        endif
        wait(0.1)
        Count=Count+1
      EndLoop
    EndLoop


  • tom24tom24 Unconfirmed Posts: 37 Apprentice
    I tested with this program but not work 
  • matthewd92matthewd92 Founding Pro, Tactile Sensor Beta Testers Posts: 1,161 Handy
    edited October 14
    I would use a background thread to monitor for that input

    thread monitorInput():
      local timer1 = False
      local timer2 = False
      while (true):
        local time = 0
        while (DI0):
         time = time + 0.002
         sync()
        end
        if (time = > 1 and time < 1.5):
          timer1 = True
        elif(time = &gt; 3):<br>      timer2 = True
        end
        sync()
      end
    end
    This way in your main code you can simply wait for the timer1 or timer2 to go to True, also does it stay high for exactly 1 second or 3 seconds or is there any variability?  You may need to monitor the state of time and see if sometimes it's slightly less than 1 or 3 for example.

    Also, once you get the timer1 or timer2 True condition you will need to reset them as the thread will not reset or else the main program will not have time to use them.  YOu cold also add a wait statement at the end so that the code simply waits for the input to go high again and then resets the flags and goes back to the top of the loop, something like this.

    thread monitorInput():
      local timer1 = False
      local timer2 = False
      while (true):
        local time = 0
        while (DI0):
         time = time + 0.002
         sync()
        end
        if (time = &gt; 1 and time &lt; 1.5):
          timer1 = True
        elif(time = &gt; 3):<br>      timer2 = True
        end
        while (not DI0):
         sync()
        end
        timer1 = False
        timer2 = False
      end
    end

  • tom24tom24 Unconfirmed Posts: 37 Apprentice
    I tested but it  shows me an error on the following lines script 
        if (time=&gt; 1 and time &lt; 1.5)
        elif(time =&gt; 3):<br>     timer2=true 

  • matthewd92matthewd92 Founding Pro, Tactile Sensor Beta Testers Posts: 1,161 Handy
    It’s the formatting on the forum

    should read

    if (time >= 1 and time <1.5 ):

    if (time >= 3):
      timer2 =True
       
  • tom24tom24 Unconfirmed Posts: 37 Apprentice
    still the same issue i have with the same line 
  • matthewd92matthewd92 Founding Pro, Tactile Sensor Beta Testers Posts: 1,161 Handy
    Can you post up your actual code. Hard to tell what the issue is. 
  • tom24tom24 Unconfirmed Posts: 37 Apprentice
    <i><b></b></i><b></b><br>i tried but i have the issue to attach the screenshot 
      it shows me Lexer exception on line 6446: if(time>=1 & timer-1<1.5)
  • matthewd92matthewd92 Founding Pro, Tactile Sensor Beta Testers Posts: 1,161 Handy
    tom24 said:
    <i><b></b></i><b></b><br>i tried but i have the issue to attach the screenshot 
      it shows me Lexer exception on line 6446: if(time>=1 & timer-1<1.5)
    You have a typo in that line

    if(time>=1 and time<1.5):

    cannot use & and your second conditional is timer-1 which if that is how you typed it is a Boolean, you want time there
  • tom24tom24 Unconfirmed Posts: 37 Apprentice
    the script is working with out error but not trace as background to the main program i have. 
  • tom24tom24 Unconfirmed Posts: 37 Apprentice
    The issue i have is with Machine A. 

     One machine will very briefly will send voltage to the end of cycle causing the robot to head to that CNC per the program.

     looks at that input and waits for the input to be HI (ON) for more than 2 seconds. This would alleviate that millisecond signal we are seeing, being interpreted as end of cycle. this is while running the machine A. so, can you check the following program if it fix the  problem

    Doosan_MB running=false

    Main Program 

    Loop

    if Doosan_Ma=True and start=true .............(Machine A)

     Doosan_MA_Running=True

     statrt=false

          Do acction 

    Doosan_MA_Running=False


    if Doosan_MB=True    .................................(Machine B)

    Doosan_MA_Running=True

          Do acction 

    Doosan_MA_Running=False

     Else

         waite=0.01


    Thread

    MA_End_Cycle=True and Doosan-MA Running=false

     Doosan_MA_Running=True

    Elseiif timer_1=True

     Doosan_MA_Running=True

    MB_End_Cycle=True and Doosan-MB_ Running=false

     Doosan_MB_Running=True

    Thread


    if timer_1>=2

       timer_stop

    start =true

    sync()


    Event DIO=true 

    timer_1 start

    sync()


    Thread 

    thread monitorInput():

      local timer_1 = False

      while (true):

        local time = 0

        while (DI0):

         time = time + 0.002

         sync()

        end

        if (time >=1 and time &< 2):

          timer_1 = True

        end

        while (not DI0):

         sync()

        end

        timer_1 = False

      end



Sign In or Register to comment.
Left ArrowBack to discussions page