Home Applications

Discussion

Left ArrowBack to discussions page
SebastienSebastien Posts: 219 Handy
edited April 2018 in Applications
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 Founding Pro, Tactile Sensor Beta Testers Posts: 1,267 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: 219 Handy
    @matthewd92
    How would you do that in script code?

  • matthewd92matthewd92 Founding Pro, Tactile Sensor Beta Testers Posts: 1,267 Handy
    @Sebastien not sure I understand the question, script would look very similar to what I wrote above. 
  • SebastienSebastien Posts: 219 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 Founding Pro, Tactile Sensor Beta Testers Posts: 1,267 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: 219 Handy
    @matthewd92
    This is a good tip that I never thought of doing. Going from a .urp to script!
    Thanks for the tip!
  • matthewd92matthewd92 Founding Pro, Tactile Sensor Beta Testers Posts: 1,267 Handy
    edited February 2017
    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: 4 Apprentice
    edited March 2017
    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.
  • RamonSanchezRamonSanchez Posts: 14 Apprentice
    edited April 2018
    Sorry for the bump over here, but we've got the same trouble and we have programmed it with Polyscope in this way:



    We do not yet have a sensor so we cannot check if the programming is good enough... with False, the whole program works smoothly but we are not sure what will happen when the value is True.
  • DMO_UniversalDMO_Universal Posts: 4 Apprentice
    Sorry for the bump over here, but we've got the same trouble and we have programmed it with Polyscope in this way:


    We do not yet have a sensor so we cannot check if the programming is good enough... with False, the whole program works smoothly but we are not sure what will happen when the value is True.
    Ramon,

    1)
    This is kind of a nonintuitive thing, but when you're using an If/Else and the If is checked continuously, you can enter the 'If DO[0]=True' portion of the program, start running the commands within it, and then jump into the Else portion if DO[0] ever goes false while headed to point_6.

    Normally this isn't something that happens.  If you have an If/Else that is NOT checked continuously, you have two hunks of code (one under If, one under Else) and only one of those hunks will ever run.

    If you wanted to ensure that you jump completely out of the If/Else statement, you could replace the Else with an Elseif.  Maybe it would look like this:

    Started_If is just an arbitrary variable functioning as a flag that lets us know if we entered the first part of the If statement.  If we do, it ensures we never enter the Else portion.

    2)
    Also please note the stopj(5) Script command.  if you're checking things continuously there's a chance you could interrupt robot motion and lead to a protective stop.  Putting in a stopj(a) command ensures that the robot will decelerate before moving on.  That 'a' is the acceleration argument.  Rule of thumb is 0.1=slow deceleration 5+=pretty rapid deceleration.

    3)
    Lastly, if your robot encounters that Halt it will never reach the 3F Basic Open after it in the Else statement.
  • RamonSanchezRamonSanchez Posts: 14 Apprentice
    Hello, and thank you for your reply.

    There is one thing I don't understand though. 99% of the times, DO[0] will be false in the beginning. Our process consists of the tooling of some polypropylene tubes. These tubes have three longitudinal lines separated 120º on which we cannot tool or otherwise they would break. Therefore, we need to place them onto a support and position them according to a sensor that detects those lines over which we cannot tool.
    My question is then: if started_if:=True when we enter the continuously checked if, and then DO[0]:=True, we would jump to the elseif with DO[0]:=True and started_if:=True as well, right? Or am I missing something?

    PS: Thank you for the Halt, I have no idea why I entered that into the program.
  • ssandbergssandberg Partner, Wrist Camera URCap 1.3.0 Posts: 11 Apprentice
    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.
    I should look at that more often, I always found the continuosly scanning IF statements to be quite bizzare ;)

    I wonder if they thought that would make more sense to a non-programmer over a WHILE command?
  • matthewd92matthewd92 Founding Pro, Tactile Sensor Beta Testers Posts: 1,267 Handy
    That’s the only thing I’ve ever come up with, I wish we had a while loop as well as switch cases that could work on strings 
Sign In or Register to comment.
Left ArrowBack to discussions page