Exemple #1
0
 def writerow(self, data_object):
     data = []
     for i in range(len(self.__names)):
         size = serialize.get_item_size(self.__types[i])
         value = data_object.__dict__[self.__names[i]]
         if size > 1:
             data.extend(value)
         else:
             data.append(value)
     self.__writer.writerow(data)
Exemple #2
0
def run():
    global isfree
    global gripperdone
    global starttime
    global runtext

    is_running.config(text=str(keep_running))
    if keep_running:
    # try sending command
        try:
            state = rtde_connection.receive(save_in_binary)
            
            if state is not None: #check the state from RTDE to check if the robot is busy
                val=''
                for i in range(len(output_names)):
                    size=serialize.get_item_size(output_types[i])
                    val=val+str(state.__dict__[output_names[i]])
                if((val)!='0'): # if the robot isnt busy set it free and open for sending commands
                    isfree=True
                machine_status.config(text=val) #update the status in the ui

                botheval=((val)=='0') and (isfree==True) # double lock to avoid sending multiple commands because of asynchrononous update (RTDE has higher refresh rate than execution speed)
                if ((botheval) or (gripperdone)):
                    try: # if possible run the command, catch if it failed
                        gripperdone, lefttasks = send_this_command(read_and_append_list_return_command(JSON_FILE_LOC),ROBOT_HOST_IP,SECONDARY_PORT,gripper)
                    except: # if failed print in command line
                        print("skipped")
                    print(str(lefttasks))
                    tasks_left.config(text=str(lefttasks)) # show how many tasks are left
                    sock.sendto(str(lefttasks).encode(), (UDP_IP,UDP_PORT))# send how many tasks are left through UDP to grasshopper to make a loop possible
                    # if (gripperdone):
                    #     print("gripperdone")
                    isfree=False
                    starttime=time.time()

                endtime=time.time()
                if abs(endtime-starttime)>1: # check every second, not sure why
                    isfree=True

        except rtde.RTDEException: # catch error
            rtde_connection.disconnect()
            print("ERRO")

            # sys.exit()
    else:
        machine_status.config(text="#")
        tasks_left.config(text="#")
    root.update()
    root.after(10,run)
Exemple #3
0
 def __init__(self, csvfile, names, types, delimiter=' '):
     if len(names) != len(types):
         raise ValueError('List sizes are not identical.')
     self.__names = names
     self.__types = types
     self.__header_names = []
     self.__columns = 0
     for i in range(len(self.__names)):
         size = serialize.get_item_size(self.__types[i])
         self.__columns += size
         if size > 1:
             for j in range(size):
                 name = self.__names[i] + '_' + str(j)
                 self.__header_names.append(name)
         else:
             name = self.__names[i]
             self.__header_names.append(name)
     self.__writer = csv.writer(csvfile, delimiter=delimiter)
Exemple #4
0
 def __init__(self, file, names, types, delimiter=" "):
     if len(names) != len(types):
         raise ValueError("List sizes are not identical.")
     self.__file = file
     self.__names = names
     self.__types = types
     self.__delimiter = delimiter
     self.__header_names = []
     self.__columns = 0
     for i in range(len(self.__names)):
         size = serialize.get_item_size(self.__types[i])
         self.__columns += size
         if size > 1:
             for j in range(size):
                 name = self.__names[i] + "_" + str(j)
                 self.__header_names.append(name)
         else:
             name = self.__names[i]
             self.__header_names.append(name)
Exemple #5
0
def run():
    global isfree
    if keep_running:
        # try sending
        try:
            state = rtde_connection.receive(save_in_binary)
            if state is not None:
                val = ''
                for i in range(len(output_names)):
                    size = serialize.get_item_size(output_types[i])
                    val = val + str(state.__dict__[output_names[i]])
                if ((val) != '0'):
                    isfree = True

                botheval = ((val) == '0') and (isfree == True)
                if ((botheval) or (gripperdone)):
                    try:
                        gripperdone, lefttasks = send_this_command(
                            read_and_append_list_return_command('coords.json'),
                            ROBOT_HOST_IP, SECONDARY_PORT, gripper)
                    except:
                        print("skipped")
                    print(str(lefttasks))
                    sock.sendto(str(lefttasks).encode(), (UDP_IP, UDP_PORT))
                    # if (gripperdone):
                    #     print("gripperdone")
                    isfree = False
                    starttime = time.time()

                endtime = time.time()
                if abs(endtime - starttime) > 1:
                    isfree = True

        except rtde.RTDEException:
            rtde_connection.disconnect()
            sys.exit()
Exemple #6
0
    def update_robot_data(self):

        keep_running = True
        while keep_running:

            try:
                state = self.robot_con.receive()
                if state is not None:
                    data = []
                    for i in range(len(self.output_names)):
                        size = serialize.get_item_size(self.output_types[i])
                        value = state.__dict__[self.output_names[i]]
                        data.append(value)
                    self.data.data = data
                else:
                    self.robot_connected = False
                    return

            except KeyboardInterrupt:
                keep_running = False
                sys.exit(1)

        self.robot_con.send_pause()
        self.robot_con.disconnect()
Exemple #7
0
    logging.error('Unable to start synchronization')
    sys.exit()

int = 1
isidle = True

keep_running = True

while keep_running:
    # if int%10000000==0:
    try:
        state = rtde_connection.receive(save_in_binary)
        if state is not None:
            val = ''
            for i in range(len(output_names)):
                size = serialize.get_item_size(output_types[i])
                val = val + str(state.__dict__[output_names[i]])
            if ((val) != '0'):
                isidle = True
            if (((val) == '0') and (isidle == True)):
                #send first command to robot and remove frst
                # send_command_from_list(dummylist,ROBOT_HOST_IP,SECONDARY_PORT)
                send_this_command(
                    read_and_append_list_return_command('coords.json'))
                isidle = False

            sock.sendto(val.encode("ascii"), (UDP_IP, UDP_PORT))
            # sys.stdout.write("\r")
            # sys.stdout.write(isidle)
            # sys.stdout.flush()
Exemple #8
0
def run():
    # parameters
    parser = argparse.ArgumentParser()
    parser.add_argument('--host',
                        default='10.20.0.25',
                        help='name of host to connect to (localhost)')
    parser.add_argument('--port',
                        type=int,
                        default=30004,
                        help='port number (30004)')
    parser.add_argument('--frequency',
                        type=int,
                        default=10,
                        help='the sampling frequency in Herz')
    parser.add_argument(
        '--config',
        default='record_configuration.xml',
        help='data configuration file to use (record_configuration.xml)')

    args = parser.parse_args()
    print args.host
    conf = rtde_config.ConfigFile(args.config)
    output_names, output_types = conf.get_recipe('out')
    con = rtde.RTDE(args.host, 30004)
    con.connect()

    # get controller version
    con.get_controller_version()

    # setup recipes
    if not con.send_output_setup(
            output_names, output_types, frequency=args.frequency):
        logging.error('Unable to configure output')
        sys.exit()

    # start data synchronization
    if not con.send_start():
        logging.error('Unable to start synchronization')
        sys.exit()

    # get the data
    keep_running = True
    while keep_running:
        try:
            state = con.receive()
            if state is not None:
                data = []
                for i in range(len(output_names)):

                    size = serialize.get_item_size(output_types[i])
                    value = state.__dict__[output_names[i]]

                    if size > 1:
                        data.extend(value)
                    else:
                        data.append(value)

                # first 3 need to be multiplied by 1000
                for i in range(0, 3):
                    data[i] *= 1000
                print(", ".join(str(v) for v in data))

            else:
                # lost connection retrying
                print "Lost connection retrying..."
                run()
        except KeyboardInterrupt:
            keep_running = False
            con.send_pause()
            con.disconnect()
            sys.exit()

        sleep(1 / args.frequency)
    con.send_pause()
    con.disconnect()