Files
sunnypilot/selfdrive/controls/lib/lead_mpc_lib/libmpc_py.py
HaraldSchafer 96d4bfbff3 Refactor long (#21433)
* refactor

* needs casting

* tests pass

* fix that test

* refactor in controls

* lets not go crazy

* change of names

* use constants

* better naming

* renamed

* soft constraints

* compile slack variables

* rm git conflict

* add slack variables

* unused

* new edition

* fcw

* fix tests

* dividing causes problems

* was way too slow

* take a step back

* byeeee

* for another time

* bad idxs

* little more cpu for cruise mpc

* update refs

* these limits seem fine

* rename

* test model timings fails sometimes

* add default

* save some cpu

* Revert "little more cpu for cruise mpc"

This reverts commit f0a8163ec90e8dc1eabb3c4a4268ad330d23374d.

* Revert "test model timings fails sometimes"

This reverts commit d259d845710ed2cbeb28b383e2600476527d4838.

* update refs

* less cpu

* Revert "Revert "test model timings fails sometimes""

This reverts commit e0263050d9929bfc7ee70c9788234541a4a8461c.

* Revert "less cpu"

This reverts commit 679007472bc2013e7fafb7b17de7a43d6f82359a.

* cleanup

* not too much until we clean up mpc

* more cost on jerk

* change ref

* add todo

* new ref

* indentation
old-commit-hash: be5ddd25cd
2021-07-07 19:42:26 -07:00

42 lines
988 B
Python

import os
from cffi import FFI
from common.ffi_wrapper import suffix
mpc_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)))
def _get_libmpc(mpc_id):
libmpc_fn = os.path.join(mpc_dir, "libmpc%d%s" % (mpc_id, suffix()))
ffi = FFI()
ffi.cdef("""
typedef struct {
double x_ego, v_ego, a_ego, x_l, v_l, a_l;
} state_t;
typedef struct {
double x_ego[21];
double v_ego[21];
double a_ego[21];
double j_ego[20];
double x_l[21];
double v_l[21];
double a_l[21];
double t[21];
double cost;
} log_t;
void init(double ttcCost, double distanceCost, double accelerationCost, double jerkCost);
void init_with_simulation(double v_ego, double x_l, double v_l, double a_l, double l);
int run_mpc(state_t * x0, log_t * solution,
double l, double a_l_0);
""")
return (ffi, ffi.dlopen(libmpc_fn))
mpcs = [_get_libmpc(0), _get_libmpc(1)]
def get_libmpc(mpc_id):
return mpcs[mpc_id]