src package

Submodules

src.DrivingDynamicsReference module

class src.DrivingDynamicsReference.DrivingDynamicsReference(b_visualize: bool = False)[source]

Bases: object

Class to calculate the reference velocity profile under full-speed operation.

Parameters

b_visualize – turn on plotting

Authors

Thomas Herrmann <thomas.herrmann@tum.de>

Created on

01.10.2020

create_ref(track_data: dict) int[source]

Calculates the reference velocity profile.

Parameters

track_data – dictionary containing track length and discretization steps

Return int

return 0 if everything is OK

Authors

Thomas Herrmann <thomas.herrmann@tum.de>

Created on

01.10.2020

src.GetESresults module

class src.GetESresults.ESres[source]

Bases: object

Class to extract and store the optimization results from acados.

Authors

Thomas Herrmann <thomas.herrmann@tum.de>

Created on

01.10.2020

convert_results(es_model: types.SimpleNamespace, es_constraints: types.SimpleNamespace, es_solver: acados_template.acados_ocp_solver.AcadosOcpSolver, kappa_disc: numpy.array)[source]

Converts the results from the AcadosOcpSolver to interpretable values.

Parameters
  • es_model – optimization model (CasADi language)

  • es_constraints – optimization constraints (CasADi language)

  • es_solver – acados solver object

  • kappa_disc – discrete track curvature values [rad/m]

Authors

Thomas Herrmann <thomas.herrmann@tum.de>

Created on

01.10.2020

plot_results(es_model: types.SimpleNamespace, s_glo_offset: float = 0.0, b_save_tikz: bool = False)[source]

Plots extracted results and saves them as separate .tex-files (optional).

Parameters
  • es_model – optimization model (CasADi language)

  • s_glo_offset – converts the local solver s-coordinate into the global s-coordinate of the race track

including an offset from previous solver instances :param b_save_tikz: saves the plots as separate .tex-files

Authors

Thomas Herrmann <thomas.herrmann@tum.de>

Created on

01.11.2020

show_statistics(solver: acados_template.acados_ocp_solver.AcadosOcpSolver)[source]

Shows internal solver statistics, e.g., convergence rates and residuals.

Parameters

solver – acados solver object

Authors

Thomas Herrmann <thomas.herrmann@tum.de> Maximilian Bayerlein

Created on

01.11.2020

src.OnlineES module

class src.OnlineES.OnlineES(b_visualize: bool = False)[source]

Bases: object

Class containing all the functionality to initialize and recalculate the energy strategy.

Parameters

b_visualize – activate interactive plots after every optimization of the energy strategy.

Authors

Thomas Herrmann <thomas.herrmann@tum.de>

Created on

01.12.2020

bind_meas_to_constraints(x_meas: numpy.array) numpy.array[source]

Binds the measurement values to the linear OCP state constraints.

Parameters

x_meas – measured states vector

Return x_meas

returns modified measurement values

Authors

Thomas Herrmann <thomas.herrmann@tum.de>

Created on

01.12.2020

initialize_es(x0: numpy.array, track_data: dict, laps: int) int[source]

Initializes the energy strategy. This is the first attempt to create an energy for a given race lap, which takes a reference velocity profile as an initial guess. You can create this reference velocity profile using the class DrivingDynamicsReference.

Parameters
  • x0 – initial values of the ODEs

  • track_data – dictionary containing all the necessary track information

  • laps – number of race laps

Return stat

return the solver status, which must be ‘0’ for success

Authors

Thomas Herrmann <thomas.herrmann@tum.de>

Created on

01.12.2020

recalc_es(dpx: int, dpx_dist: int, x0: numpy.array)[source]

Recalculates the energy strategy. Based on current measurement data (x0), a reoptimization will take place for the remaining race distance.

Parameters
  • x0 – initial values of the ODEs (measurement)

  • dpx – index in the global s-coordinate where the vehicle currently is and the measurements were taken

  • dpx_dist – local index in the global s-coordinate where the vehicle currently is and the measurements

were taken

Authors

Thomas Herrmann <thomas.herrmann@tum.de>

Created on

01.12.2020

reset_state_constraints()[source]

# lower bounds self.es_solver. set(0, ‘lbx’,

np.array((self.es_model.v_min, self.es_model.soc_min, self.es_model.temp_batt_min,

self.es_model.temp_mach_min, self.es_model.temp_inv_min, self.es_model.temp_cool_mach_inv_min, self.es_model.temp_cool_batt_min)))

# upper bounds self.es_solver. set(0, ‘ubx’,

np.array((self.es_model.v_max, self.es_model.soc_max, self.es_model.temp_batt_max,

self.es_model.temp_mach_max, self.es_model.temp_inv_max, self.es_model.temp_cool_mach_inv_max, self.es_model.temp_cool_batt_max)))

set_state_constraints(x: numpy.array)[source]

Set solver values to match the set constraints on the initial DAE value

Parameters

x – states vector on first discretization point

Authors

Thomas Herrmann <thomas.herrmann@tum.de>

Created on

01.12.2020

solve_es(N: int, kappa_disc_recalc: numpy.array, b_save_tikz: bool, dpx: int = 0)[source]

Solves the OCP to provide energy strategy results.

Parameters
  • N – Length of discrete optimization horizon

  • kappa_disc_recalc – curvature of the track, where the ES shall be solved on [rad/m]

  • b_save_tikz – bool to save results as separate .tex-files

  • dpx – discrete position index in the global s-coordinate frame where the vehicle currently is

Authors

Thomas Herrmann <thomas.herrmann@tum.de>

Created on

01.12.2020

src.def_es_model module

src.def_es_model.es_model(b_dd_ref: bool = False, b_battery_simple: bool = False, b_machine_simple: bool = False, b_inverter_simple: bool = False) tuple[source]

Creates the optimization model using CasADi modeling language and prepares it for the use in acados.

Parameters
  • b_dd_ref – switch to enable the calculation of the reference velocity profile

  • b_battery_simple – switch to enable a simple loss model of the battery

  • b_machine_simple – switch to enable a simple loss model of the machine

  • b_inverter_simple – switch to enable a simple loss model of the inverter

Returns

model: optimization model

constraint: optimization constraints

Authors

Thomas Herrmann <thomas.herrmann@tum.de> Maximilian Bayerlein

Created on

01.06.2020

src.def_es_solver module

src.def_es_solver.es_solver(model: types.SimpleNamespace, constraint: types.SimpleNamespace, time_steps: numpy.ndarray, hessian_method: str, x0: numpy.array, nlp_steplen: float = 1.0, b_dd_ref: bool = False) acados_template.acados_ocp_solver.AcadosOcpSolver[source]

Creates the optimization solver using acados modeling language.

Parameters
  • model – optimization model defined using CasADi modeling language

  • constraint – optimization constraints defined using CasADi modeling language

  • time_steps – discrete time_steps to approximate the DAE system

  • hessian_method – can be ‘GAUSS_NEWTON’ (less accurate) or ‘HESSIAN’ (higher computation time)

  • x0 – initial conditions of ODEs

  • nlp_steplen – initial NLP solver steplength (default: 100 %)

  • b_dd_ref – switch to create reference velocity profile

Returns

acados_solver: acados OCP solver object

Authors

Thomas Herrmann <thomas.herrmann@tum.de> Maximilian Bayerlein

Created on

01.06.2020

src.getIPOPTData module

src.getIPOPTData.getIPOPTData(N: int, Tf: float, offset: float, TRACK: dict)[source]

Extracts mintime IPOPT optimization results, which can be generated using the repository global_racetrajectory_optimization.

Parameters
  • N – number of discretization steps of the track

  • Tf – final optimization horizon

  • offset – offset not to be considered in the IPOPT data

  • TRACK – track parameters (length, number of discretization steps per lap)

Authors

Maximilian Bayerlein

Created on

01.08.2020

src.get_track module

src.get_track.get_track(laps: int, TRACK: dict, b_plot: bool = False) tuple[source]

author: Maximilian Bayerlein

The get track function imports the curvature profile from the optimal race trajectory of a given track. The profile was calculated previously with the main_globaltraj function using IPOPT. Further, the curvature profile is sampled with a non-regular mesh.

Parameters
  • laps (np.int) – number of laps on the track.

  • TRACK (dict) – dictionary containing data regarding the track {“Name”: ‘Name’, “discr”: int, “v0”: int, “Length”: int}

  • b_plot (bool) – switch for plotting the track data

Return s_steps

sampled discretization horizon, containing the distance to the next discretization point (closed full track). (N)

Rtype s_steps

np.ndarray

Return kappa_disc

sampled track curvature profile (closed full track).

Rtype kappa_disc

np.ndarray

Return s_new

sampled discretization points, containing the absolute position of the points (closed full track). (N + 1)

Rtype s_new

np.ndarray

src.get_track.nonreg_sampling(kappa: numpy.ndarray, eps_kappa: float = 0.001, step_non_reg: int = 0) tuple[source]

authors: Thomas Herrmann

Maximilian Bayerlein

The non-regular sampling function runs through the curvature profile and determines straight and corner sections. During straight sections it reduces the amount of points by skipping them depending on the step_non_reg parameter.

Parameters
  • kappa (np.ndarray) – curvature profile (closed full track).

  • eps_kappa (float) – identify straights using this threshold in curvature in rad/m, i.e. straight if kappa < eps_kappa

  • step_non_reg (int) – determines how many points are skipped in straight sections, e.g. step_non_reg = 3 means every fourth point is used while three points are skipped

Return sample_idxs

indices of points that are kept (closed full track).

Rtype sample_idxs

np.ndarray

Return kappa_new

sampled track curvatures profile (closed full track).

Rtype track_sampled

np.ndarray

Module contents