In [1]:
#%matplotlib notebook
#DEFAULT_FIGSIZE = (8, 6)
%matplotlib inline 
DEFAULT_FIGSIZE = (12, 8)

import numpy as np
import scipy.signal
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style('darkgrid')

from phobos.constants import sa
import plot_sim as ps

import matplotlib as mpl
mpl.rcParams['figure.figsize'] = DEFAULT_FIGSIZE

In [2]:
log = ps.ProcessedRecord('logs/multisine.pb.cobs.gz')

In [3]:
# calculate upper and lower masses
accel = scipy.signal.savgol_filter(log.measured_steer_angle, 101, 3, 2, 0.001)
torque1 = log.kistler_sensor_torque
torque2 = -torque1 + log.kollmorgen_applied_torque


m1 = np.linalg.lstsq(accel.reshape((-1, 1)), torque1.reshape((-1, 1)))[0][0][0]
print('least-squares fit for upper inertia {} kg-m^2'.format(m1))

m2 = np.linalg.lstsq(accel.reshape((-1, 1)), torque2.reshape((-1, 1)))[0][0][0]
print('least-squares fit for lower inertia {} kg-m^2'.format(m2))


least-squares fit for upper inertia 0.03185004118699606 kg-m^2
least-squares fit for lower inertia 0.010860690708980467 kg-m^2

In [4]:
color = sns.color_palette('Paired', 12)[1::2]

plt.close('all')
fig, ax = plt.subplots(3, 1, sharex=True)
ax[0].plot(log.t, accel,
           color=color[0],
           label='accel')
ax[0].legend()

ax[1].plot(log.t, accel * m1,
           color=color[1], linestyle='--',
           label='m1*a')
ax[1].plot(log.t, torque1,
           color=color[2],
           label='sensor torque')
ax[1].legend()


ax[2].plot(log.t, accel * m2,
           color=color[1], linestyle='--',
           label='m2*a')
ax[2].plot(log.t, torque2,
           color=color[2],
           label='-(sensor torque) + acuator torque')
ax[2].legend()

plt.show()



In [5]:
log = ps.ProcessedRecord('logs/2018-02-09T16h46m40sZ.pb.cobs.gz')

In [7]:
m1 = sa.UPPER_ASSEMBLY_INERTIA
m2 = sa.LOWER_ASSEMBLY_INERTIA

# reduce amount of data plotted
index = slice(20*1000, 100*1000)
t = log.t[index]

sensor_torque = log.kistler_sensor_torque[index]
motor_torque = log.kollmorgen_applied_torque[index]

accel = scipy.signal.savgol_filter(
    log.measured_steer_angle[index], 101, 3, 2, 0.001)
inertia_torque_accel = m1*accel
steer_torque_accel = -sensor_torque + inertia_torque_accel

inertia_torque_motor = m1/m2*(-sensor_torque + motor_torque)
steer_torque_motor = -sensor_torque + inertia_torque_motor

color = sns.color_palette('Paired', 12)

fig, ax = plt.subplots()
ax.plot(t, sensor_torque,
        color=color[0], label='sensor torque')
ax.plot(t, -sensor_torque,
        color=color[1], label='-(sensor torque)')
ax.plot(t, motor_torque,
        color=color[2], label='motor torque')
ax.plot(t, inertia_torque_accel,
        color=color[4], label='inertia torque (accel)')
ax.plot(t, inertia_torque_motor,
        color=color[8], label='inertia torque (motor)')
ax.plot(t, steer_torque_accel,
        color=color[5], label='steer torque (accel)')
ax.plot(t, steer_torque_motor,
        color=color[9], label='steer torque (motor)')
ax.legend()
plt.show()