Refresh axes


In [ ]:
# %% Update and plot
hl, = plt.plot([], [])

def update_line(hl, new_data):
    hl.set_xdata(np.append(hl.get_xdata(), new_data))
    hl.set_ydata(np.append(hl.get_ydata(), new_data))
    plt.draw()

# %% relim and autoscale to fit the data
fig, ax = plt.subplots(figsize=(8,8))

[line] = ax.plot([1.6, 2.7])
plt.waitforbuttonpress();

line.set_xdata([0, 1, 2])
line.set_ydata([1.6, 2.7, 4.1])

ax.relim()
ax.autoscale_view()
fig.canvas.draw()

Integrator


In [ ]:
t = ca.SX.sym('t')
x = ca.SX.sym('x')
u = ca.SX.sym('u')
dae = ca.SXFunction('Dynamics', ca.daeIn(x=x, p=u, t=t), ca.daeOut(ode=u))
integrator = ca.Integrator('Integrator', 'cvodes', dae)
integrator({'x0': x, 'p': u})['xf']

In [ ]:


In [ ]:
t = ca.SX.sym('t')
# Create f
[x_b,y_b,vx_b,vy_b,x_c,y_c,phi] = state[...]
[v,w,psi] = control[...]    
# Define right-hand side
rhs = cat.struct_SX(state)
rhs['x_b'] = vx_b
rhs['y_b'] = vy_b
rhs['vx_b'] = 0
rhs['vy_b'] = 0
rhs['x_c'] = v * ca.cos(phi)
rhs['y_c'] = v * ca.sin(phi)
rhs['phi'] = w
# Continuous dynamics
dae = ca.SXFunction('Continuous dynamics', ca.daeIn(x=state, p=control, t=t), ca.daeOut(ode=rhs))

# Integrator
opts = {
    'tf' : dt
}
integrator = ca.Integrator('Integrator', 'cvodes', dae, opts)

# Get integration result
state_next = integrator({'x0': state, 'p': control})['xf']

F = ca.SXFunction('Discrete dynamics', [state,control], [state_next])

In [ ]:


In [4]:
(5.46-4.37)


Out[4]:
1.0899999999999999

In [5]:
5.46/15 * 3


Out[5]:
1.092

In [ ]: