��Equations of Motion�&�Physics Engines
Chapters 2-3, and Appendix P.4
Design Study A
Introduction to Feedback Control, Beard, McLain, Peterson, Killpack
2
Design Study B
Introduction to Feedback Control, Beard, McLain, Peterson, Killpack
3
Design Study C
Introduction to Feedback Control, Beard, McLain, Peterson, Killpack
4
Design Study D
Introduction to Feedback Control, Beard, McLain, Peterson, Killpack
5
Design Study E
Introduction to Feedback Control, Beard, McLain, Peterson, Killpack
6
Design Study F
Introduction to Feedback Control, Beard, McLain, Peterson, Killpack
7
Appendix P.4�Numerical Solutions to Differential Equations
8
Numerically Solving an ODE
Introduction to Feedback Control, Beard, McLain, Peterson, Killpack
9
Numerically Solving an ODE
Introduction to Feedback Control, Beard, McLain, Peterson, Killpack
10
Euler Method / Runge-Kutta 1 (RK1)
Introduction to Feedback Control, Beard, McLain, Peterson, Killpack
11
Euler Method / Runge-Kutta 1 (RK1)
Introduction to Feedback Control, Beard, McLain, Peterson, Killpack
12
import numpy as np
class systemDynamics:
# Model the system yddot + a1*ydot + a2*sin(y) = b*u
def __init__(self, Ts=0.01):
self.Ts = Ts # sample rate
# Specify the initial condition
y0 = 0.0 # y at time zero
ydot0 = 0.0 # ydot at time zero
self.state = np.array([[y0], [ydot0]]) # state at time zero
self.a1 = 2.0
self.a2 = 2.0
self.b = 4.0
def update(self, u):
# This is the external method that takes the input u and
# returns the output y.
self.rk1_step(u) # propagate the state by one time sample
y = self.h() # return the corresponding output
return y
def rk1_step(self, u):
# Integrate ODE using Runge-Kutta RK1 algorithm
F1 = self.f(self.state, u)
self.state = self.state + self.Ts * F1
Runge-Kutta 2 (RK2)
Introduction to Feedback Control, Beard, McLain, Peterson, Killpack
13
Runge-Kutta 2 (RK2)
Introduction to Feedback Control, Beard, McLain, Peterson, Killpack
14
import numpy as np�
class systemDynamics:
# Model the system yddot + a1*ydot + a2*sin(y) = b*u
def __init__(self, Ts=0.01):
self.Ts = Ts # sample rate
# Specify the initial condition
y0 = 0.0 # y at time zero
ydot0 = 0.0 # ydot at time zero
self.state = np.array([[y0],[ydot0]]) # state at time zero
self.a1 = 2.0
self.a2 = 2.0
self.b = 4.0�
def update(self, u):
# This is the external method that takes the input u and
# returns the output y.
self.rk2_step(u) # propagate the state by one time sample
y = self.h() # return the corresponding output
return y�
def rk2_step(self, u):
# Integrate ODE using Runge-Kutta RK2 algorithm
F1 = self.f(self.state, u)
F2 = self.f(self.state + self.Ts / 2 * F1, u)
self.state += self.Ts / 2 * (F1 + F2)
Runge-Kutta 4 (RK4)
Introduction to Feedback Control, Beard, McLain, Peterson, Killpack
15
Runge-Kutta 4 (RK4)
Introduction to Feedback Control, Beard, McLain, Peterson, Killpack
16
import numpy as np�
class systemDynamics:
# Model the system yddot + a1*ydot + a2*sin(y) = b*u
def __init__(self, Ts=0.01):
self.Ts = Ts # sample rate
# Specify the initial condition
y0 = 0.0 # y at time zero
ydot0 = 0.0 # ydot at time zero
self.state = np.array([[y0],[ydot0]]) # state at time zero
self.a1 = 2.0
self.a2 = 2.0
self.b = 4.0�
def update(self, u):
# This is the external method that takes the input u and
# returns the output y.
self.rk4_step(u) # propagate the state by one time sample
y = self.h() # return the corresponding output
return y�
def rk4_step(self, u):
# Integrate ODE using Runge-Kutta RK4 algorithm
F1 = self.f(self.state, u)
F2 = self.f(self.state + self.Ts / 2 * F1, u)
F3 = self.f(self.state + self.Ts / 2 * F2, u)
F4 = self.f(self.state + self.Ts * F3, u)
self.state += self.Ts / 6 * (F1 + 2 * F2 + 2 * F3 + F4)
Perturbing a constant
Introduction to Feedback Control, Beard, McLain, Peterson, Killpack
17
Perturbing a constant, cont.
Introduction to Feedback Control, Beard, McLain, Peterson, Killpack
18
Perturbing a constant, cont.
Introduction to Feedback Control, Beard, McLain, Peterson, Killpack
19
Design Study A
Introduction to Feedback Control, Beard, McLain, Peterson, Killpack
20
Design Study A
Discuss python implementation
https://github.com/randybeard/controlbook_public/blob/master/_A_arm/python/armDynamics.py
Introduction to Feedback Control, Beard, McLain, Peterson, Killpack
21
Design Study B
Introduction to Feedback Control, Beard, McLain, Peterson, Killpack
22
Design Study B
Discuss python implementation
https://github.com/randybeard/controlbook_public/blob/master/_B_pendulum/python/pendulumDynamics.py
Introduction to Feedback Control, Beard, McLain, Peterson, Killpack
23
Design Study C
Introduction to Feedback Control, Beard, McLain, Peterson, Killpack
24
Design Study C
Discuss python implementation
Introduction to Feedback Control, Beard, McLain, Peterson, Killpack
25