---
# System prepended metadata

title: MPC
tags: [cs 593 robotics]

---

---
title: MPC
tags: cs 593 robotics
---

# MPC
- dynamical model 
- horizon period
- cost function

# MPC algorithms
- exact approach


## moving back and forth from global frame to body(local or inertial) frame



## cost function
function of current state, action, and next state
J($s_0, \hat{s}_{i - 1}, \hat{s}_1$)
- we define cost function 
- MPC tries to minimize it
- only executes first action
- prefer quadrtic cost function because it's easy to minimize


## practical approach

cross entropy based model
```
for env_steps l = 1 to N do
    sample G initial plans from N(mean=0, variance=I)
    s_0 = getEnvState()
    for CEM iteration t = 1 to t = T do
        #predict all future states
        {s^{t}_{1, H}}^G_{g = 1} = f(a^{t}_{1, H}}^G_{g = 1}, s_0)
        {J^{(t)}}^G_{g=1} = getReturns from cost function
        sort actions based on returns(cost functions)
        update mean and sigma to fit top k action sequence
        replace bottom G - k action sequences with sample from new distribution
    execute the first action from the highest model return action sequence

```

