Exemplo n.º 1
0
def MakeFakeLogFile(wind_speed, file_name, num_samples):
    """Makes a fake log file for a worker to consume.

  Args:
    wind_speed: List of wind speed values.
    file_name: Name of the log file.
    num_samples: Number of data points for the log file.
  """
    log_file = test_util.CreateSampleHDF5File(file_name, num_samples)
    telem_time = numpy.linspace(0.0, FLAGS.sim_time, num_samples)

    with test_util.H5DatasetWriter(
            log_file['parameters']['sim_params']) as sim_params:
        sim_params['phys_sim']['wind_speed'] = wind_speed
        sim_params['joystick_sim']['updates'][0, 0]['value'] = 0.5

    simulator = log_file['messages']['kAioNodeSimulator']
    controller_a = log_file['messages']['kAioNodeControllerA']
    with test_util.H5DatasetWriter(simulator['kMessageTypeSimTelemetry']) as s:
        s['message']['time'] = telem_time
        power = 1000.0 * numpy.linalg.norm(wind_speed)**3
        s['message']['rotors']['aero_power'][:][:] = power / 8.0

    with test_util.H5DatasetWriter(
            controller_a['kMessageTypeControlDebug']) as c:
        c['message'][
            'flight_mode'][:] = control_types.kFlightModeCrosswindNormal
        c['message']['time'] = telem_time

    log_file.close()
Exemplo n.º 2
0
def MakeFakeLogFile(file_name, num_samples):
    """Makes a fake log file for a worker to consume.

  Args:
    file_name: Name of the log file.
    num_samples: Number of data points for the log file.
  """
    log_file = test_util.CreateSampleHDF5File(file_name, num_samples)

    telem_time = numpy.linspace(0.0, 150.0, num_samples)

    simulator = log_file['messages']['kAioNodeSimulator']
    with test_util.H5DatasetWriter(
            simulator['kMessageTypeSimTelemetry']) as sim:
        sim['message']['time'] = telem_time
        sim['message']['wing']['tether_force_b']['tension'][:] = 2000.0
        for i, x in enumerate(('x', 'y', 'z')):
            sim['message']['wing']['Xg'][x] = float(i)

    controller = log_file['messages']['kAioNodeControllerA']
    with test_util.H5DatasetWriter(
            controller['kMessageTypeControlDebug']) as c:
        c['message']['time'] = telem_time

    log_file.close()
Exemplo n.º 3
0
    def PcapToHdf5(self, args):
        input_filename = self._ParsePositionalArg(args, 0)
        if not os.path.isfile(input_filename):
            raise ValueError('First positional arg to pcap_to_hdf5 (%s) is '
                             'not a file.' % input_filename)

        self._output_file = self._ParseArg(args, '--output_file')
        num_samples = 10  # Arbitrary
        telem_time = np.linspace(0.0, self._config['sim']['sim_time'],
                                 num_samples)

        with contextlib.closing(
                test_util.CreateSampleHDF5File(self._output_file,
                                               num_samples)) as log_file:
            sim_node = log_file['messages']['kAioNodeSimulator']
            with test_util.H5DatasetWriter(
                    sim_node['kMessageTypeSimTelemetry']) as s:
                s['message']['time'] = telem_time

            control_node = log_file['messages']['kAioNodeControllerA']
            with test_util.H5DatasetWriter(
                    control_node['kMessageTypeControlDebug']) as c:
                c['message']['time'] = telem_time

        return 0
Exemplo n.º 4
0
def MakeFakeLogFile(ts, sim_time, wind_speed, faults_sim, file_name):
    """Makes a fake log file for a worker to consume.

  Args:
    ts: Time step.
    sim_time: Simulation duration.
    wind_speed: Wind speed.
    faults_sim: Simulated fault parameters.
    file_name: Name of the log file.
  """
    test_ts = 5 * ts  # To keep the test fast we sub-sample.
    num_samples = int(sim_time / test_ts)
    ground_z = 15.0
    sim_time = numpy.array(range(num_samples)) * test_ts
    control_time = sim_time

    log_file = test_util.CreateSampleHDF5File(file_name, num_samples)

    with test_util.H5DatasetWriter(
            log_file['parameters']['system_params']) as system_params:
        system_params['ground_frame']['ground_z'] = ground_z

    with test_util.H5DatasetWriter(
            log_file['parameters']['sim_params']) as sim_params:
        # Wind speed.
        sim_params['phys_sim']['wind_speed'] = wind_speed

        # Copy over faults.
        sim_params['faults_sim']['num_fault_events'] = (
            faults_sim['num_fault_events'])
        for i in range(faults_sim['num_fault_events']):
            sim_params['faults_sim']['fault_events'][0, i]['parameters'][:] = (
                faults_sim['fault_events'][i]['parameters'])
            for key in ('t_start', 't_end'):
                sim_params['faults_sim']['fault_events'][0, i][key] = (
                    faults_sim['fault_events'][i][key])

    simulator = log_file['messages']['kAioNodeSimulator']
    with test_util.H5DatasetWriter(
            simulator['kMessageTypeSimTelemetry']) as sim:
        sim['message']['time'] = sim_time

        num_faults = faults_sim['num_fault_events']
        faults = faults_sim['fault_events'][0:num_faults]
        max_amplitude = numpy.linalg.norm(faults[-1]['parameters'][0:3])
        sim['message']['wing']['Xg']['z'][:] = wind_speed
        for fault in faults:
            amplitude = numpy.linalg.norm(fault['parameters'][0:3])
            msk = numpy.logical_and(sim_time >= fault['t_start'],
                                    sim_time <= fault['t_end'])
            sim['message']['wing']['Xg']['z'][msk] = (
                wind_speed * (1.0 - amplitude / max_amplitude))

    controller = log_file['messages']['kAioNodeControllerA']
    with test_util.H5DatasetWriter(
            controller['kMessageTypeControlDebug']) as ct:
        ct['message']['time'] = control_time
        ct['message']['hover']['wing_pos_g_cmd']['z'][:] = wind_speed

    log_file.close()
Exemplo n.º 5
0
def MakeFakeLogFile(ts, sim_time, wind_speed, file_name):
  """Makes a fake log file for a worker to consume.

  Args:
    ts: Time step.
    sim_time: Simulation duration.
    wind_speed: Wind speed.
    file_name: Name of the log file.
  """
  test_ts = 20 * ts  # To keep the test fast we sub-sample.
  num_samples = 10
  ground_z = 15.0
  sim_time = numpy.array(range(num_samples)) * test_ts
  control_time = sim_time

  log_file = test_util.CreateSampleHDF5File(file_name, num_samples)

  with test_util.H5DatasetWriter(
      log_file['parameters']['system_params']) as system_params:
    system_params['ground_frame']['ground_z'] = ground_z

  with test_util.H5DatasetWriter(
      log_file['parameters']['sim_params']) as sim_params:
    # Wind speed.
    sim_params['phys_sim']['wind_speed'] = wind_speed

  simulator = log_file['messages']['kAioNodeSimulator']
  with test_util.H5DatasetWriter(simulator['kMessageTypeSimTelemetry']) as sim:
    sim['message']['time'] = sim_time

    sim['message']['wing']['Xg']['z'][:] = wind_speed

  controller = log_file['messages']['kAioNodeControllerA']
  with test_util.H5DatasetWriter(
      controller['kMessageTypeControlDebug']) as ct:
    ct['message']['time'] = control_time
    ct['message']['flight_mode'][:] = control_types.kFlightModeCrosswindNormal
    ct['message']['flight_mode'][0] = control_types.kFlightModeHoverFullLength
    ct['message']['flight_mode'][1] = control_types.kFlightModeHoverAccel
    ct['message']['flight_mode'][2] = control_types.kFlightModeTransIn
    ct['message']['crosswind']['loop_angle'][-1] = numpy.pi * 3.0 / 2.0

  log_file.close()