Ejemplo n.º 1
0
# 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()

with open(args.output, 'w') as csvfile:
    writer = csv_writer.CSVWriter(csvfile, output_names, output_types)
    writer.writeheader()

    i = 1
    keep_running = True
    while keep_running:

        if i % args.frequency == 0:
            if args.samples > 0:
                sys.stdout.write("\r")
                sys.stdout.write("{:.2%} done.".format(
                    float(i) / float(args.samples)))
                sys.stdout.flush()
            else:
                sys.stdout.write("\r")
                sys.stdout.write("{:3d} samples.".format(i))
Ejemplo n.º 2
0
def record_ur_data(host, port, csvfilename):
    #parameters
    parser = argparse.ArgumentParser()
    parser.add_argument('--host', default=host, help='name of host to connect to (localhost)')
    parser.add_argument('--port', type=int, default=30004, help='port number (30004)')
    parser.add_argument('--samples', type=int, default=0, help='number of samples to record')
    parser.add_argument('--frequency', type=int, default=125, help='the sampling frequency in Herz')
    parser.add_argument('--config', default='record_configuration.xml', help='data configuration file to use (record_configuration.xml)')
    parser.add_argument('--output', default='robot_data.csv', help='data output file to write to (robot_data.csv)')
    parser.add_argument("--verbose", help="increase output verbosity", action="store_true")
    parser.add_argument("--binary", help="save the data in binary format", action="store_true") 
    args = parser.parse_args()
    args.output = csvfilename
    args.host = host
    args.port = port

    if args.verbose:
        logging.basicConfig(level=logging.INFO)

    conf = rtde_config.ConfigFile(args.config)
    output_names, output_types = conf.get_recipe('out')

    con = rtde.RTDE(args.host, args.port)
    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()

    writeModes = 'wb' if args.binary else 'w'
    with open(args.output, writeModes) as csvfile:
        writer = None

        if args.binary:
            writer = csv_binary_writer.CSVBinaryWriter(csvfile, output_names, output_types)
        else:
            writer = csv_writer.CSVWriter(csvfile, output_names, output_types)

        writer.writeheader()
        
        i = 1
        global keep_running
         
        while keep_running:
            timestamp = (time.time() - timestart)*1000
            if i%args.frequency == 0:
                if args.samples > 0:
                    sys.stdout.write("\r")
                    sys.stdout.write("{:.2%} done.".format(float(i)/float(args.samples))) 
                    sys.stdout.flush()
                else:
                    sys.stdout.write("\r")
                    sys.stdout.write("{:3d} samples.".format(i)) 
                    sys.stdout.flush()
            if args.samples > 0 and i >= args.samples:
                keep_running = False
            try:
                state = con.receive(args.binary)
                if state is not None:
                    writer.writerow(state, timestamp)
                else:
                    sys.exit()
            except KeyboardInterrupt:
                keep_running = False
            i += 1

    sys.stdout.write("\rComplete!            \n")

    con.send_pause()
    con.disconnect()