Example #1
0
    def readJointLogFile(self):
        jfilename = self.filename[:-5] + ".h5"

        if not os.path.isfile(jfilename):
            print(f"HDF5 file {jfilename} not found")
            return

        from qnd.h5f import openh5

        f = openh5(jfilename, "r")

        jlog = defaultdict(list)
        for rec in f.gotoit():
            for v in f:
                jlog[v].append(f[v])

        for v in jlog:
            jlog[v] = np.asarray(jlog[v])

        return jlog
        '''
Example #2
0
# Misc. qnd example, runs for pdb, h5, and nc3:
# though some things don't work for specific file types

from pylab import *
from qnd.h5f import openh5
from qnd.ncf import opennc
from qnd.pdbf import openpdb
from qnd.frontend import QList

########## Write a new file ##########
iftype = 'pdb'

if iftype == 'h5':
    fname = 'example_misc.h5'
    f = openh5(fname, 'w')
elif iftype == 'nc':
    fname = 'example_misc.nc3'
    f = opennc(fname, 'w')
elif iftype == 'pdb':
    fname = 'example_misc.pdb'
    f = openpdb(fname, 'w')

# non-record vars
x = linspace(0, 10, 201)  # numpy array
y = sin(x)

f.x = x  # like an object attribute
f['y'] = y  # like a dict

# record vars
f.recording(1)
logId1 = p.startStateLogging(p.STATE_LOGGING_GENERIC_ROBOT,
                             log_file,
                             [kuka],
                             logFlags = p.STATE_LOG_JOINT_TORQUES,
                             )

if make_joint_log:
    import numpy as np
    from qnd.h5f import openh5

    # turn on torque sensing recorded in getJointStates():
    for jointIndex in range(p.getNumJoints(kuka)):
        p.enableJointForceTorqueSensor(kuka, jointIndex)

    # initialize qnd logfile:
    jlog = openh5(jointlog_file, "w")
    jlog.recording(1)

while p.isConnected():
    keys = p.getKeyboardEvents()

    appliedtorques = [0]*p.getNumJoints(kuka)
    for k in my_keys:
        if k.ord in keys and keys[k.ord] & p.KEY_IS_DOWN: #WAS_TRIGGERED:
            print(f"{k.key} was pressed")
            torque = k.torque
            appliedtorques[k.joint] = torque
        else:
            torque = 0.
        time.sleep(0.01)
        p.setJointMotorControl2(kuka, k.joint, p.VELOCITY_CONTROL, targetVelocity = 0, force = 0.1)
Example #4
0
'''
example_write_h5.py demos how to write single values and multiple records 
into an hdf5 file
'''
import numpy as np
from qnd.h5f import openh5

fname = "foo.h5"

with openh5(fname, "w") as f:

    # write a single value:
    f.x = 3

    # turn on recording and write two records:
    f.recording(1)
    f.tm = 0
    f.y = 0.1
    f.z = np.arange(3)

    f.tm = 1
    f.y = 0.2
    f.z = np.arange(3) + 1

# reopen file to append data:
with openh5(fname, "a") as f:

    # append a single new variable to the file
    f.a = 10

    # write one new record: