Discussion

Left ArrowBack to discussions page
SebastienSebastien Posts: 194 Handy
Hi pros, 
we are working on a program where we would have two waypoints that are variable waypoints. We would move the robot to the first one. Then the robot would move to the second point but we would like to make the robot stop during that motion to the second point based on a Digital input signal.
How would you program that? Do you think using a thread that is checked continuously makes sense?

Comments

  • matthewd92matthewd92 Posts: 385Founding Pro, Tactile Sensor Beta Testers Handy
    Use an If statement with the "Check continuously" box marked which turns it into a while statement basically.

    Something like this

    
    movej(variable_waypoint_2)
    while  not digital_in_1:
      movej(variable_waypoint_2)
    end
    stopj()
     
    This would move to waypoint_1 and then monitor the input during the move to waypoint_2, if at any point the digital input turned on the move would be terminated.  We use this a lot with our programs for instance placing one part onto another, only move until a certain force threshold is reached and then stop.  Allows us to accommodate variation in parts or pick position for instance without causing the robot to fault.
  • SebastienSebastien Posts: 194 Handy
    @matthewd92
    How would you do that in script code?

  • matthewd92matthewd92 Posts: 385Founding Pro, Tactile Sensor Beta Testers Handy
    @Sebastien not sure I understand the question, script would look very similar to what I wrote above. 
  • SebastienSebastien Posts: 194 Handy
    @matthewd92
    Turns out I was not able to program this in a script. I tried the way you suggest  but I did not know how to have the condition monitored at all time in my script file. I tried using a thread but my stopl commande was in the thread and because the move line had control of the robot, it did not allow the stopl to operate without an error appearing on the pendant.
  • matthewd92matthewd92 Posts: 385Founding Pro, Tactile Sensor Beta Testers Handy
    @Sebastien in script you would have used a while loop...like this which is just the script that was generated from a simple program moving from waypoint 1 to waypoint 2 while monitoring digital output 0

    while (True):
        $ 1 "Robot Program"
        $ 2 "MoveJ"
        $ 3 "Waypoint_1"
        movej([-1.6007002035724085, -1.7271001974688929, -2.2029998938189905, -0.8079999128924769, 1.5951000452041626, -0.03099996248354131], a=1.3962634015954636, v=1.0471975511965976)
        $ 4 "If digital_out[0]≟ False "
        global thread_flag_4=0
        thread Thread_if_4():
          $ 5 "Waypoint_2"
          movej([-1.5918919155982847, -2.077602322080553, -1.690556245487243, -0.9697263956928577, 1.5953255450589165, -0.02219193606001557], a=1.3962634015954636, v=1.0471975511965976)
          thread_flag_4 = 1
        end
        if (get_standard_digital_out(0) ==   False  ):
          global thread_handler_4=run Thread_if_4()
          while (thread_flag_4 == 0):
            if not(get_standard_digital_out(0) ==   False  ):
              kill thread_handler_4
              thread_flag_4 = 2
            else:
              sync()
            end
          end
        else:
          thread_flag_4 = 2
        end
        $ 6 "stopj(15)"
        stopj(15)
        $ 7 "sync()"
        sync()
      end
    I have never tried implementing this in script but it makes sense, basically if you get into the if statement you would kick off a thread that would execute the move.  Then a while loop would be monitoring the status of the thread handler, as long as the thread was still executing then the if statement would interrupt the thread if the conditional was voided.

    Takes a moment to kind of figure out whats going on but makes sense.  Also, notice that the stopj is not inside of a thread, it just follows the of statement just like it would in a polyscope program.


  • SebastienSebastien Posts: 194 Handy
    @matthewd92
    This is a good tip that I never thought of doing. Going from a .urp to script!
    Thanks for the tip!
  • matthewd92matthewd92 Posts: 385Founding Pro, Tactile Sensor Beta Testers Handy
    edited February 26
    You're welcome.  Thats what it always compiles to anyways....find it useful sometimes to understand whats really going on to look at the script file.
  • DMO_UniversalDMO_Universal Posts: 3 Apprentice
    edited March 6
    I'm glad you found a solution, but I'm not sure why you had to turn to Script Code to do it.

    When you add an If statement or Loop within Polyscope, you have the ability to click 'Check Statement Continuously'.  This means that once you enter the If statement or Loop, it will execute the commands within only as long as the initial condition remains true.

    So if I had my structural elements as follows (pseudocode):
    Program Start
    Wait DO[0]=True
       If DO[0]=True (checked continuously)
       movej(pose1)
       movej(pose2)
       ...
       movej(pose98)
       movej(pose99)
       end
    stopj(5)
    halt
    The program would Wait until Digital Input 0 was True, then begin going through the list of waypoints.  If Digital Input 0 ever dropped Low before reaching pose99, the program would halt.
Sign In or Register to comment.
Left ArrowBack to discussions page