Launch-8 PID reconstruction

Data


In [1]:
%matplotlib inline
import numpy as np
import utils
from scipy.signal import firwin, lfilter
from scipy.integrate import simps
from matplotlib import rcParams
rcParams.update({'font.size': 14})

columns = np.loadtxt('../data/Launch-8/roll/raw/output_trim.csv', delimiter=',', unpack=True, usecols=(0,1,2,3))

roll_sample_rate = 1000

roll_time  = columns[0]
roll_accel = columns[1]
roll_rate  = columns[2]
fin_angle  = columns[3]

roll_time = roll_time - 4540.7
roll_rate = roll_rate - roll_rate[0:10].mean()
roll_rate = roll_rate / 42.9

roll_accel -= roll_accel[0:10].mean()
roll_accel *= -0.0068

fin_angle -= fin_angle[0:10].mean()
fin_angle /= (fin_angle.max()/15.0)

velocity = [0]
altitude = [0]
roll_angle = [0]
for i in range(1, len(roll_accel)):
    altitude.append(simps(velocity, roll_time[:i]))
    velocity.append(simps(roll_accel[:i], roll_time[:i]))
    roll_angle.append(simps(roll_rate[:i], roll_time[:i]))

Null Roll Rate

If we try to set roll rate to 0 and run our PID controller, what do we get with L-8 data?


In [3]:
import simulation.lv2 as model
import simulation.simulate as sim
import simulation.PIDcontroller as PIDcontroller

pid = PIDcontroller.PIDController(p=10.0, i=0.01, d=0.1)
pid.setTarget(0.0)

fin = []
for i, t in enumerate(roll_time):
    r = roll_rate[i]
    x = altitude[i]
    v = velocity[i]
    
    correction = pid.step(r)
    a = model.estimate_alpha(correction, x, v, t)
    a = model.servo(a, t)
    fin.append(a)

In [4]:
fig = utils.Plot(r"Fin Angle", "Time [$s$]", r"$\alpha$ [${}^0$]")
fig.plot(roll_time, fin_angle, color=utils.blue)
fig.plot(roll_time, fin)
fig.ylim([-16, 16])
fig.show()


Null Roll Angle

Now, instead, we try to make the rocket have 0 roll angle. This is still different than the original design.


In [5]:
pid0 = PIDcontroller.PIDController(p=1.0, i=0.001, d=0.0)
pid0.setTarget(0.0)

pid1 = PIDcontroller.PIDController(p=10.0, i=0.0, d=0.0)
pid1.setTarget(0.0)

fin = []
for i, t in enumerate(roll_time):
    f = roll_angle[i]
    r = roll_rate[i]
    x = altitude[i]
    v = velocity[i]
    
    correction0 = pid0.step(f)
    pid1.setTarget(correction0)
    correction1 = pid1.step(r)
    a = model.estimate_alpha(correction1, x, v, t)
    a = model.servo(a, t)
    fin.append(a)

fig = utils.Plot(r"Fin Angle, 0 Roll Angle", "Time [$s$]", r"$\alpha$ [${}^0$]")
fig.plot(roll_time, fin)
fig.plot(roll_time, fin_angle, color=utils.blue)
fig.ylim([-16, 16])
fig.show()


Roll Schedule

Now we re-create to roll schedule (script) that set snap rolls for the rocket.


In [6]:
pid0 = PIDcontroller.PIDController(p=1.0, i=0.001, d=0.01)
pid0.setTarget(0.0)

pid1 = PIDcontroller.PIDController(p=10.0, i=0.0, d=0.0)
pid1.setTarget(0.0)

fin = []
for i, t in enumerate(roll_time):
    f = roll_angle[i]
    r = roll_rate[i]
    x = altitude[i]
    v = velocity[i]
    
    # schedule snap rolls
    if t > 4:
        pid0.setTarget(90.0)
    if t > 8:
        pid0.setTarget(-90.0)
    if t > 12:
        pid0.setTarget(-180.0)
    if t > 16:
        pid0.setTarget(-270.0)
    if t > 20:
        pid0.setTarget(-360.0)
    if t > 24:
        pid0.setTarget(-450.0)
    if t > 28:
        pid0.setTarget(-540.0)
        
        
    correction0 = pid0.step(f)
    pid1.setTarget(correction0)
    correction1 = pid1.step(r)
    a = model.estimate_alpha(correction1, x, v, t)
    a = model.servo(a, t)
    fin.append(a)

fig = utils.Plot(r"Fin Angle, Script Roll Angle", "Time [$s$]", r"$\alpha$ [${}^0$]")
fig.plot(roll_time, fin)
fig.plot(roll_time, fin_angle, color=utils.blue)
fig.ylim([-16, 16])
fig.show()