You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					42 lines
				
				988 B
			
		
		
			
		
	
	
					42 lines
				
				988 B
			| 
											6 years ago
										 | import os
 | ||
|  | 
 | ||
|  | from cffi import FFI
 | ||
| 
											6 years ago
										 | from common.ffi_wrapper import suffix
 | ||
| 
											6 years ago
										 | 
 | ||
|  | mpc_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)))
 | ||
|  | 
 | ||
|  | def _get_libmpc(mpc_id):
 | ||
| 
											6 years ago
										 |     libmpc_fn = os.path.join(mpc_dir, "libmpc%d%s" % (mpc_id, suffix()))
 | ||
| 
											6 years ago
										 | 
 | ||
|  |     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))
 | ||
|  | 
 | ||
| 
											4 years ago
										 | mpcs = [_get_libmpc(0), _get_libmpc(1)]
 | ||
| 
											6 years ago
										 | 
 | ||
|  | def get_libmpc(mpc_id):
 | ||
| 
											4 years ago
										 |     return mpcs[mpc_id]
 |