openpilot/selfdrive/controls/lib/lateral_mpc/libmpc_py.py

33 lines
791 B
Python
Raw Normal View History

2020-01-17 13:48:30 -07:00
import os
from cffi import FFI
from common.ffi_wrapper import suffix
2020-01-17 13:48:30 -07:00
mpc_dir = os.path.dirname(os.path.abspath(__file__))
libmpc_fn = os.path.join(mpc_dir, "libmpc"+suffix())
2020-01-17 13:48:30 -07:00
ffi = FFI()
ffi.cdef("""
typedef struct {
double x, y, psi, delta, t;
} state_t;
int N = 16;
2020-01-17 13:48:30 -07:00
typedef struct {
double x[N+1];
double y[N+1];
double psi[N+1];
double delta[N+1];
double rate[N];
2020-01-17 13:48:30 -07:00
double cost;
} log_t;
void init(double pathCost, double headingCost, double steerRateCost);
void init_weights(double pathCost, double headingCost, double steerRateCost);
2020-01-17 13:48:30 -07:00
int run_mpc(state_t * x0, log_t * solution,
double v_poly[4], double curvature_factor, double rotation_radius,
double target_y[N+1], double target_psi[N+1]);
2020-01-17 13:48:30 -07:00
""")
libmpc = ffi.dlopen(libmpc_fn)