Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import sys
import pysurvive
ctx = pysurvive.init(sys.argv)
if ctx is None: # implies -help or similiar
exit(-1)
def imu_func(ctx, mode, accelgyro, timecode, id):
print(accelgyro)
keepRunning = True
pysurvive.install_imu_fn(ctx, imu_func)
while keepRunning and pysurvive.poll(ctx) == 0:
pass
pysurvive.close(ctx)
ctx = pysurvive.init(sys.argv)
if ctx is None: # implies -help or similiar
exit(-1)
def imu_func(ctx, mode, accelgyro, timecode, id):
print(accelgyro)
keepRunning = True
pysurvive.install_imu_fn(ctx, imu_func)
while keepRunning and pysurvive.poll(ctx) == 0:
pass
pysurvive.close(ctx)
import sys
import pysurvive
ctx = pysurvive.init(sys.argv)
if ctx is None: # implies -help or similiar
exit(-1)
def imu_func(ctx, mode, accelgyro, timecode, id):
print(accelgyro)
keepRunning = True
pysurvive.install_imu_fn(ctx, imu_func)
while keepRunning and pysurvive.poll(ctx) == 0:
pass
pysurvive.close(ctx)
import sys
import pysurvive
ctx = pysurvive.init(sys.argv)
if ctx is None: # implies -help or similiar
exit(-1)
def imu_func(ctx, mode, accelgyro, timecode, id):
print(accelgyro)
keepRunning = True
pysurvive.install_imu_fn(ctx, imu_func)
while keepRunning and pysurvive.poll(ctx) == 0:
pass
pysurvive.close(ctx)
def plot_imu(self, fig = None, plot_num = 1, plot_rows = 2, plot_cols = 2, figsize=None, **kwargs):
if fig is None:
fig = plt.figure(figsize=figsize)
ax = fig.add_subplot(plot_rows, plot_cols, plot_num, title=self.name + ' Gyros')
moveThreshGyro = pysurvive.configf(self.so.contents.ctx, "move-threshold-gyro", pysurvive.SC_GET, 0)
moveThreshAcc = pysurvive.configf(self.so.contents.ctx, "move-threshold-acc", pysurvive.SC_GET, 0)
axes_name = ['X', 'Y', 'Z']
gyros = np.array(self.gyros)
ax.plot([self.imu_times[0],self.imu_times[-1]], [moveThreshGyro] * 2, linewidth=1)
ax.plot(self.imu_times, np.linalg.norm(gyros, axis=1), linewidth=1, label='Norm')
for i in range(3):
ax.plot(self.imu_times, gyros[:, i], linewidth=1, label=axes_name[i])
ax.legend()
ax = fig.add_subplot(plot_rows, plot_cols, plot_num + 1, title=self.name + ' Accels')
ax.plot([self.imu_times[0],self.imu_times[-1]], [moveThreshAcc] * 2, linewidth=1)
ax.plot(self.imu_times[1:], np.linalg.norm(np.diff(self.accels, axis=0), axis=1), linewidth=1)
return 2
def plot_light_diff(self, fig = None, plot_num = 1, plot_rows = 1, plot_cols = 1, figsize=None, norm_diff = True, **kwargs):
if len(self.angles) == 0:
return 0
if fig is None:
fig = plt.figure()
ax = fig.add_subplot(plot_rows, plot_cols, plot_num, title=self.name + ' light diff')
moveThreshAng = pysurvive.configf(self.so.contents.ctx, "move-threshold-ang", pysurvive.SC_GET, 0)
ax.plot([self.imu_times[0],self.imu_times[-1]], [moveThreshAng] * 2, linewidth=1)
for k,v in self.angles.items():
if len(v) <= 1:
continue
vv = np.array(v)
norm = np.diff(vv[:, 0]) if norm_diff else 1.
data = np.stack([vv[1:, 0], np.array(np.diff(vv[:, 1]) / norm)])
diff_data = insert_blanks(data)
times = diff_data[:, 0]
data = diff_data[:, 1]
ax.plot(times, data, label=k, linewidth=1)
return 1
def plot_imu(self, fig = None, plot_num = 1, plot_rows = 2, plot_cols = 2, figsize=None, **kwargs):
if fig is None:
fig = plt.figure(figsize=figsize)
ax = fig.add_subplot(plot_rows, plot_cols, plot_num, title=self.name + ' Gyros')
moveThreshGyro = pysurvive.configf(self.so.contents.ctx, "move-threshold-gyro", pysurvive.SC_GET, 0)
moveThreshAcc = pysurvive.configf(self.so.contents.ctx, "move-threshold-acc", pysurvive.SC_GET, 0)
axes_name = ['X', 'Y', 'Z']
gyros = np.array(self.gyros)
ax.plot([self.imu_times[0],self.imu_times[-1]], [moveThreshGyro] * 2, linewidth=1)
ax.plot(self.imu_times, np.linalg.norm(gyros, axis=1), linewidth=1, label='Norm')
for i in range(3):
ax.plot(self.imu_times, gyros[:, i], linewidth=1, label=axes_name[i])
ax.legend()
ax = fig.add_subplot(plot_rows, plot_cols, plot_num + 1, title=self.name + ' Accels')
ax.plot([self.imu_times[0],self.imu_times[-1]], [moveThreshAcc] * 2, linewidth=1)
ax.plot(self.imu_times[1:], np.linalg.norm(np.diff(self.accels, axis=0), axis=1), linewidth=1)
return 2
def install(ctx):
recorder = Recorder()
def cb_fn(class_fn, so, *args):
dat = recorder.get(so)
time = pysurvive.survive_run_time(so.contents.ctx)
return class_fn(dat, time, *args)
pysurvive.install_angle_fn(ctx, partial(cb_fn, RecordedData.record_angle))
pysurvive.install_light_fn(ctx, partial(cb_fn, RecordedData.record_light))
pysurvive.install_imu_fn(ctx, partial(cb_fn, RecordedData.record_imu))
pysurvive.install_pose_fn(ctx, partial(cb_fn, RecordedData.record_pose))
pysurvive.install_sweep_fn(ctx, partial(cb_fn, RecordedData.record_sweep))
pysurvive.install_sync_fn(ctx, partial(cb_fn, RecordedData.record_sync))
pysurvive.install_sweep_angle_fn(ctx, partial(cb_fn, RecordedData.record_sweep_angle))
return recorder
import pysurvive
import sys
actx = pysurvive.SimpleContext(sys.argv)
for obj in actx.Objects():
print(obj.Name())
while actx.Running():
updated = actx.NextUpdated()
if updated:
print(updated.Name(), updated.Pose())
def record_imu(self, time, mode, accelgyro, timecode, id):
self.imu_times.append(time)
self.gyros.append(accelgyro[3:6])
self.accels.append(accelgyro[0:3])
self.time_since_move.append(pysurvive.SurviveSensorActivations_stationary_time(self.so.contents.activations) /
48000000.)