def main():

    # start the server
    server = Server(server_address, server_port)
    server.start()

    # create client wrappers, that wrap the underlying communication to the sockets
    gh = ClientWrapper("GH")

    # wait for the clients to be connected
    gh.wait_for_connected()

    # now enter fabrication loop
    while True:  # and ur and gh connected
        # let gh control if we should continue
        continue_fabrication = gh.wait_for_int()
        print("continue_fabrication: %i" % continue_fabrication)
        if not continue_fabrication:
            break

        float_list = gh.wait_for_float_list()

        # do some calculation
        x, y = float_list
        sum = x + y
        print("%f + %f = %f" % (x, y, sum))

        gh.send_float_list([sum])

    gh.quit()
    server.close()
    time.sleep(2)
    print("Done.")
Example #2
0
def main():

    # start the server
    server = Server(server_address, server_port)
    server.start()
    server.client_ips.update({"UR": ur_ip})

    # create client wrappers, that wrap the underlying communication to the sockets
    gh = ClientWrapper("GH")
    ur = ClientWrapper("UR")

    # wait for the clients to be connected
    gh.wait_for_connected()
    ur.wait_for_connected()

    # now enter fabrication loop
    while True:  # and ur and gh connected
        # let gh control if we should continue
        continue_fabrication = gh.wait_for_int()
        print("continue_fabrication: %i" % continue_fabrication)
        if not continue_fabrication:
            break

        safe_pt_toggle = gh.wait_for_int()
        len_command = gh.wait_for_int()
        commands_flattened = gh.wait_for_float_list()
        # the commands are formatted according to the sent length
        commands = format_commands(commands_flattened, len_command)
        print("We received %i commands." % len(commands))

        if safe_pt_toggle:
            print("Moving to safe point")
            for i, cmd in enumerate(commands):
                if i == 0:
                    # Move to first point, toggle extruder and wait
                    x, y, z, ax, ay, az, speed, radius = cmd
                    ur.send_command_movel([x, y, z, ax, ay, az],
                                          v=speed,
                                          r=radius)
                    print("Toggling extruder")
                    ur.send_command_digital_out(0, True)

                    print("Waiting for 30 seconds")
                    ur.send_command_wait(30)

                    # And move axis
                    # p = s.SiemensPortal(1)
                    # p.set_x(650)
                    # p.set_z(850)

                else:
                    x, y, z, ax, ay, az, speed, radius = cmd
                    ur.send_command_movel([x, y, z, ax, ay, az],
                                          v=speed,
                                          r=radius)

        else:
            print("Skipping safe points")

            for i, cmd in enumerate(commands[1:-1]):
                x, y, z, ax, ay, az, speed, radius = cmd
                ur.send_command_movel([x, y, z, ax, ay, az], v=speed, r=radius)

        # for i, cmd in enumerate(commands):
        #     ur.wait_for_command_executed(i)
        #     print("Executed command", i+1, "of", len(commands), "[", (i+1)*100/(len(commands)), "%]")
        #     current_pose_cartesian = ur.get_current_pose_cartesian()
        #     print(current_pose_cartesian)

        ur.wait_for_ready()
        ur.send_command_digital_out(0, False)
        gh.send_float_list(commands[0])
        print("============================================================")
        """
        ur.wait_for_ready()
        # wait for sensor value
        digital_in = ur.wait_for_digital_in(number)
        current_pose_joint = ur.wait_for_current_pose_joint()
        current_pose_cartesian = ur.get_current_pose_cartesian()
        # send further to gh
        gh.send_float_list(digital_in)
        gh.send_float_list(current_pose_joint)
        gh.send_float_list(current_pose_cartesian)
        """
    ur.quit()
    gh.quit()
    server.close()

    print("Please press a key to terminate the program.")
    junk = sys.stdin.readline()
    print("Done.")
Example #3
0
def main():

    # start the server
    server = Server(server_address, server_port)
    server.start()
    server.client_ips.update({"UR": ur_ip})

    # create client wrappers, that wrap the underlying communication to the sockets
    gh = ClientWrapper("GH")
    ur = ClientWrapper("UR")

    # wait for the clients to be connected
    gh.wait_for_connected()
    ur.wait_for_connected()

    # now enter fabrication loop
    while True: # and ur and gh connected
        # let gh control if we should continue
        continue_fabrication = gh.wait_for_int()
        print("continue_fabrication: %i" % continue_fabrication)
        if not continue_fabrication:
            break
        # receive further information from gh
        # e.g. send number of commands:
        # number = gh.wait_for_int()
        # commands = []
        # for i in range(number):
        #       cmd = gh.wait_for_float_list()
        #       commands.append(cmd)


        picking_pose_cmd = gh.wait_for_float_list()
        savety_pose_cmd = gh.wait_for_float_list()

        len_command = gh.wait_for_int()
        commands_flattened = gh.wait_for_float_list()
        # the commands are formatted according to the sent length
        commands = format_commands(commands_flattened, len_command)
        print("We received %i commands." % len(commands))

        # 1. move to savety pose
        x, y, z, ax, ay, az, acc, vel = savety_pose_cmd
        ur.send_command_movel([x, y, z, ax, ay, az], a=acc, v=vel)
        # 2. open gripper
        ur.send_command_digital_out(2, True) # open tool
        # 3. move to picking pose
        x, y, z, ax, ay, az, acc, vel = picking_pose_cmd
        ur.send_command_movel([x, y, z, ax, ay, az], a=acc, v=vel)
        # 4. Close gripper
        ur.send_command_digital_out(2, False) # close tool
        # 5. move to savety pose
        x, y, z, ax, ay, az, acc, vel = savety_pose_cmd
        ur.send_command_movel([x, y, z, ax, ay, az], a=acc, v=vel)


        ur.wait_for_message(self, msg_id)
        # placing path
        for i in range(0, len(commands), 3):

            savety_cmd1 = commands[i]
            placing_cmd = commands[i+1]
            savety_cmd2 = commands[i+2]

            # 5. move to savety pose 1
            x, y, z, ax, ay, az, speed, radius = savety_cmd1
            ur.send_command_movel([x, y, z, ax, ay, az], v=speed, r=radius)
            # 6. move to placing pose
            x, y, z, ax, ay, az, speed, radius = placing_cmd
            ur.send_command_movel([x, y, z, ax, ay, az], v=speed, r=radius)
            # 7. wait
            ur.send_command_wait(2.)
            # 8. open gripper
            ur.send_command_digital_out(2, True) # open tool
            # 7. wait
            ur.send_command_wait(1.)
            # 9. move to savety pose 2
            x, y, z, ax, ay, az, speed, radius = savety_cmd2
            ur.send_command_movel([x, y, z, ax, ay, az], v=speed, r=radius)

            # 1. move to savety pose
            x, y, z, ax, ay, az, acc, vel = savety_pose_cmd
            ur.send_command_movel([x, y, z, ax, ay, az], a=acc, v=vel)
            # 2. open gripper
            ur.send_command_digital_out(2, True) # open tool
            # 3. move to picking pose
            x, y, z, ax, ay, az, acc, vel = picking_pose_cmd
            ur.send_command_movel([x, y, z, ax, ay, az], a=acc, v=vel)
            # 4. Close gripper
            ur.send_command_digital_out(2, False) # close tool
            # 5. move to savety pose
            x, y, z, ax, ay, az, acc, vel = savety_pose_cmd
            ur.send_command_movel([x, y, z, ax, ay, az], a=acc, v=vel)


        ur.wait_for_ready()
        gh.send_float_list(commands[0])
        print("============================================================")
        break
        """
        ur.wait_for_ready()
        # wait for sensor value
        digital_in = ur.wait_for_digital_in(number)
        current_pose_joint = ur.wait_for_current_pose_joint()
        current_pose_cartesian = ur.get_current_pose_cartesian()
        # send further to gh
        gh.send_float_list(digital_in)
        gh.send_float_list(current_pose_joint)
        gh.send_float_list(current_pose_cartesian)
        """
    ur.quit()
    gh.quit()
    server.close()

    print("Please press a key to terminate the program.")
    junk = sys.stdin.readline()
    print("Done.")