Upgrade to Pro — share decks privately, control downloads, hide ads and more …

kerbal_space_program.rb

listrophy
October 27, 2017

 kerbal_space_program.rb

So there's this game, Kerbal Space Program. You basically create your own space program from scratch. Well, you can control it via TCP, and—using Ruby—we're gonna launch, orbit, and crash our brave Kerbins. You might even learn a thing or two about orbital mechanics and control theory along the way.

listrophy

October 27, 2017
Tweet

More Decks by listrophy

Other Decks in Programming

Transcript

  1. Whenever Brad is drinking, you wanna make sure you're sitting

    next to him, because instead of being obnoxious, he teaches you orbital mechanics. Ashe Dryden
  2. Whenever Brad is drinking, you wanna make sure you're sitting

    next to him, because instead of being obnoxious, he teaches you orbital mechanics. Ashe Dryden GET YOUR ALTERCONF TICKETS!
  3. PREFACE PREREQUISITES ▸ Buy KSP ($40 on Steam) ▸ Install

    ckan ▸ Install kRPC on ckan ▸ EMA 550: Astrodynamics $24
  4. PREFACE PREREQUISITES ▸ Buy KSP ($40 on Steam) ▸ Install

    ckan ▸ Install kRPC on ckan ▸ EMA 550: Astrodynamics ▸ ME 446: Automatic Controls $24
  5. PREFACE PREREQUISITES ▸ Buy KSP ($40 on Steam) ▸ Install

    ckan ▸ Install kRPC on ckan ▸ EMA 550: Astrodynamics ▸ ME 446: Automatic Controls ▸ Install ruby correctly #%&! $24
  6. PREFACE PREREQUISITES ▸ Buy KSP ($40 on Steam) ▸ Install

    ckan ▸ Install kRPC on ckan ▸ EMA 550: Astrodynamics ▸ ME 446: Automatic Controls ▸ Install ruby correctly #%&! ▸ gem install krpc $24
  7. PREFACE PREREQUISITES ▸ Buy KSP ($40 on Steam) ▸ Install

    ckan ▸ Install kRPC on ckan ▸ EMA 550: Astrodynamics ▸ ME 446: Automatic Controls ▸ Install ruby correctly #%&! ▸ gem install krpc ▸ Write some ruby $24
  8. MAKE A ROCKET HOVER PROBLEM STATEMENT: MAKE ALTITUDE CONSTANT (AND

    SUFFICIENTLY >0) 1 CONTROL: THROTTLE (ALSO, VARIABLE MASS)
  9. PROJECT 1: MERCURY SOME MATHS F = m⋅a ∑ T

    − m⋅ g = m⋅a T − m⋅ g = m⋅ d dt v T − m⋅ g = m⋅ d2 dt2 x T(t) − m(t)⋅ g = m(t)⋅ d2 dt2 x(t)
  10. PROJECT 1: MERCURY SOME MATHS F = m⋅a ∑ T

    − m⋅ g = m⋅a T − m⋅ g = m⋅ d dt v T − m⋅ g = m⋅ d2 dt2 x T(t) − m(t)⋅ g = m(t)⋅ d2 dt2 x(t) Nonlinear 2nd Order
 Differential Equation
  11. PROJECT 1: MERCURY SOME MATHS F = m⋅a ∑ T

    − m⋅ g = m⋅a T − m⋅ g = m⋅ d dt v T − m⋅ g = m⋅ d2 dt2 x T(t) − m(t)⋅ g = m(t)⋅ d2 dt2 x(t) Nonlinear 2nd Order
 Differential Equation ಠ_ಠ
  12. PROJECT 1: MERCURY PID CONTROLLER prev_time = Time.now dt =

    0.1 prev_error = 0 accumulated_error = 0 while true do sleep dt curr_time = Time.now error = DESIRED_ALTITUDE - current_altitude() accumulated_error += error * dt derivative = (error - prev_error) / dt set_throttle( P * error + I * accumulated_error + D * derivative ) prev_error, prev_time = error, curr_time end
  13. ORBIT? 1 foot Austin Houston d = 237km h =

    4.41km t = 30s v = 7.9km/s
  14. ENERGIES Get up there m g h = E g

    h = E/m (9.81/1000) 200 1.96 MJ
  15. ENERGIES Get up there m g h = E g

    h = E/m (9.81/1000) 200 1.96 MJ Go real fast E = ½ m v2 E/m = ½ v2 ½ (7.8)2 30.4 MJ
  16. PROJECT 2: GEMINI OK, BUT HOW? ▸ Checklist! ▸ 2

    state machines: staging & control ▸ On each tick, use case-when for each state machine ▸ On each state-transition, maybe do a single thing ▸ "Pitch over while managing stages"
  17. PROJECT 3: APOLLO STATES 1. determining insertion burn delta v

    2. determining insertion burn location 3. waiting for insertion burn far 4. waiting for insertion burn mid 5. waiting for insertion burn near 6. insertion burning 7. finalizing insertion burn 8. transmunar orbit 9. outer munar orbit 10.mid munar orbit 11.final approach