def simple_run():
    # db_name = '../db/car_db_sample'
    db_path = osp.abspath(
        osp.join(osp.dirname(my_dir + '/../'), 'co2mpas_driver', 'db',
                 'EuroSegmentCar'))

    # A sample car id from the database
    car_id = 39393

    # The gear shifting style as described in the TRR paper.
    gs_style = 0.8
    '''import vehicle object, curves and gear shifting strategy'''
    db = rno.load_db_to_dictionary(db_path)

    # The vehicle specs as returned from the database
    selected_car = rno.get_vehicle_from_db(db, car_id)
    '''
        The final acceleration curvers (Curves), the engine acceleration 
        potential curves (cs_acc_per_gear), before the calculation of the 
        resistances and the limitation due to max possible acceleration 
        (friction).
    '''
    Curves, cs_acc_per_gear, StartStop, gs = mf.gear_4degree_curves_with_linear_gs(
        selected_car, gs_style)

    for gear, curve in enumerate(Curves):
        start = StartStop[0][gear]
        stop = StartStop[1][gear]
        x = np.arange(start, stop, 0.2)
        y = curve(x)
        plt.plot(x, y)
    plt.show()

    return 0
def simple_run():
    # file path without extension of the file
    db_path = osp.abspath(
        osp.join(osp.dirname(my_dir + '/../'), 'co2mpas_driver', 'db',
                 'EuroSegmentCar'))
    car_id = 40516
    gs_style = 0.8
    # degree = 4

    db = rno.load_db_to_dictionary(db_path)
    my_car = rno.get_vehicle_from_db(db, car_id)
    """Full load curves of speed and torque"""
    full_load_speeds, full_load_torques = vf.get_load_speed_n_torque(my_car)
    """Speed and acceleration ranges and points for each gear"""
    speed_per_gear, acc_per_gear = vf.get_speeds_n_accelerations_per_gear(
        my_car, full_load_speeds, full_load_torques)
    """Extract speed acceleration Splines"""
    coefs_per_gear = vf.get_tan_coefs(speed_per_gear, acc_per_gear, 4)
    poly_spline = vf.get_spline_out_of_coefs(coefs_per_gear,
                                             speed_per_gear[0][0])
    """Start/stop speed for each gear"""
    start, stop = vf.get_start_stop(my_car, speed_per_gear, acc_per_gear,
                                    poly_spline)

    sp_bins = np.arange(0, stop[-1] + 1, 0.01)
    """define discrete poly spline"""
    discrete_poly_spline = ddp(poly_spline, sp_bins)
    """Get resistances"""
    car_res_curve, car_res_curve_force, Alimit = vf.get_resistances(
        my_car, sp_bins)
    """define discrete_car_res_curve"""
    discrete_car_res_curve = ddc(car_res_curve, sp_bins)
    """define discrete_car_res_curve_force"""
    discrete_car_res_curve_force = ddcf(car_res_curve_force, sp_bins)
    """Calculate Curves"""
    curves = vf.calculate_curves_to_use(poly_spline, start, stop, Alimit,
                                        car_res_curve, sp_bins)
    """Get gs"""
    gs = fg.gear_linear(speed_per_gear, gs_style)

    from co2mpas_driver.model import define_discrete_acceleration_curves as func
    discrete_acceleration_curves = func(curves, start, stop)
    for d in discrete_acceleration_curves:
        plt.plot(d['x'], d['y'])

    plt.show()

    return 0
def simple_run():
    # file path without extension of the file
    db_path = osp.abspath(
        osp.join(osp.dirname(my_dir + '/../'), 'co2mpas_driver', 'db',
                 'EuroSegmentCar'))

    car_id = 47844

    db = rno.load_db_to_dictionary(db_path)
    selected_car = rno.get_vehicle_from_db(db, car_id, electric=True)

    curves, start_stop = mf.get_ev_curve_main(selected_car)

    from co2mpas_driver.model import define_discrete_acceleration_curves as func
    discrete_acceleration_curves = func(curves, *start_stop)
    for d in discrete_acceleration_curves:
        plt.plot(d['x'], d['y'], 'x')
        plt.grid()
    plt.show()
    return 0
def simple_run():
    db_path = osp.abspath(osp.join(osp.dirname(my_dir + '/../'),
                                   'co2mpas_driver', 'db',
                                   'EuroSegmentCar'))
    car_id = 27748
    gs_style = 1

    db = rno.load_db_to_dictionary(db_path)

    selected_car = rno.get_vehicle_from_db(db, car_id)

    full_load_speeds, full_load_torques = vf.get_load_speed_n_torque(selected_car)
    speed_per_gear, acc_per_gear = vf.get_speeds_n_accelerations_per_gear(
        selected_car, full_load_speeds, full_load_torques)

    coefs_per_gear = vf.get_tan_coefs(speed_per_gear, acc_per_gear, 2)

    degree, speeds_new, acceleration_new = \
        pt.calculate_speed_acceleration_from_coefs(coefs_per_gear,
                                                   speed_per_gear, acc_per_gear)

    for x_new, a_new in zip(speeds_new, acceleration_new):
        plt.plot(x_new, a_new, 'rx')

    poly_spline = vf.get_cubic_splines_of_speed_acceleration_relationship(
        selected_car, speed_per_gear, acc_per_gear)

    Start, Stop = vf.get_start_stop(selected_car, speed_per_gear, acc_per_gear,
                                    poly_spline)

    tans = fg.find_list_of_tans_from_coefs(coefs_per_gear, Start, Stop)

    gs = fg.gear_points_from_tan(tans, gs_style, Start, Stop)

    for gear in gs:
        plt.plot([gear, gear], [0, 5], 'k')

    plt.show()
def simple_run():
    # Vehicles database path
    db_path = osp.abspath(
        osp.join(osp.dirname(my_dir + '/../'), 'co2mpas_driver', 'db',
                 'EuroSegmentCar'))
    car_id = 39393
    gs_style = 0.8  # gear shifting can take value from 0(timid driver)
    degree = 2

    db = rno.load_db_to_dictionary(db_path)
    selected_car = rno.get_vehicle_from_db(db, car_id)

    curves, cs_acc_per_gear, start_stop, gs = mf.gear_curves_n_gs_from_poly(
        selected_car, gs_style, degree)

    from co2mpas_driver.model import define_discrete_acceleration_curves as func
    discrete_acceleration_curves = func(curves, *start_stop)
    for d in discrete_acceleration_curves:
        plt.plot(d['x'], d['y'])

    plt.show()

    return 0
Exemplo n.º 6
0
def simple_run():
    db_path = osp.abspath(
        osp.join(osp.dirname(my_dir + '/../'), 'co2mpas_driver', 'db',
                 'EuroSegmentCar'))
    car_id = 35135

    db = rno.load_db_to_dictionary(db_path)

    my_car = rno.get_vehicle_from_db(db, car_id, lco=True)

    # Sample speed profile.
    sp = [
        0.075647222, 0.138130556, 0.165027778, 0.093338889, 0.050647222,
        0.073841667, 0.067722222, 0.041172222, 0.094272222, 0.240147222,
        0.421988889, 0.601022222, 0.805477778, 1.067511111, 1.360083333,
        1.650283333, 1.913175, 2.176333333, 2.444797222, 2.700288889,
        2.946313889, 3.189297222, 3.448358333, 3.704702778, 3.940416667,
        4.130133333, 4.260580556, 4.3409, 4.388002778, 4.426941667,
        4.455319444, 4.476166667, 4.515033333, 4.539722222, 4.54225,
        4.563194444, 4.616366667, 4.794819444, 4.925277778, 5.010258333,
        5.270727778, 5.526880556, 5.698258333, 5.863777778, 6.025444444,
        6.178002778, 6.320294444, 6.455533333, 6.586655556, 6.7208,
        6.850394444, 6.973597222, 7.076808333, 7.125569444, 7.125688889,
        7.095327778, 7.045141667, 6.987052778, 6.942780556, 6.943469444,
        6.972669444, 6.987636111, 6.995147222, 7.01125, 7.034722222,
        7.064722222, 7.095263889, 7.144930556, 7.228544444, 7.351388889,
        7.516902778, 7.705436111, 7.912636111, 8.142141667, 8.384738889,
        8.638480556, 8.896288889, 9.157808333, 9.427988889, 9.695, 9.931672222,
        10.09765, 10.17970556, 10.211575, 10.22029444, 10.21634444,
        10.22308056, 10.25685278, 10.32316667, 10.43054444, 10.55200833,
        10.67687222, 10.81433889, 10.94932778, 11.08748889, 11.23079444,
        11.37732778, 11.52675278, 11.67602222, 11.83357778, 11.99132222,
        12.127225, 12.217525, 12.27826111, 12.33689444, 12.41279167,
        12.52231944, 12.648375, 12.78034722, 12.91521111, 13.04194444,
        13.16066111, 13.28333333, 13.40571944, 13.53175556, 13.64644444,
        13.75571111, 13.8666, 13.93222222, 13.95751111, 13.96354444,
        13.95462222, 13.92623333, 13.89566111, 13.88161111, 13.90078611,
        13.92424167, 13.95039722, 13.98454444, 14.02729722, 14.07866111, 14.15,
        14.24663333, 14.3537, 14.45984444, 14.58112778, 14.7043, 14.83035556,
        14.96040278, 15.09104722, 15.22573889, 15.36123611, 15.49455833,
        15.63419444, 15.77003889, 15.90303333, 16.04134167, 16.17628056,
        16.30461111, 16.4286, 16.54910556, 16.66977778, 16.77255278,
        16.85622222, 16.94144444, 17.02344444, 17.09977778, 17.17553056,
        17.24705278, 17.31889444, 17.39001389, 17.44721389
    ]

    # Gear shifting points as can be derived from
    gs = [
        5.715589018826222, 10.974960637586783, 16.396951475513028,
        22.832902038337586
    ]
    sim_step = 0.1
    """
      Function "light_co2mpas_series" computes the CO2 emissions in grams for a series
      of speed profile. If the gear-shifting is not given as input it uses the an 
      internal function to compute the current gear.
      """
    fp = lco.light_co2mpas_series(my_car, sp, gs, sim_step)

    plt.plot(fp)
    # plt.plot(fp2)
    plt.show()
def simple_run():
    ''':parameters of the simulation'''
    # Vehicle databased based on the Euro Car Segment classification
    db_path = osp.abspath(
        osp.join(osp.dirname(my_dir + '/../'), 'co2mpas_driver', 'db',
                 'EuroSegmentCar'))
    # A sample car id from the database
    car_id = 39393
    # The gear shifting style as described in the TRR paper.
    gs_style = 0.9

    # The desired speed
    vdes = 40

    # Current speed
    v_start = 0

    # The simulation step in seconds
    sim_step = 0.1

    # The driving style as described in the TRR paper.
    driver_style = 1

    # Duration of the simulation in seconds.
    duration = 100

    # sample time series
    times = np.arange(0, duration + sim_step, sim_step)
    '''import vehicle object, curves and gear shifting strategy'''
    db = rno.load_db_to_dictionary(db_path)

    # The vehicle specs as returned from the database
    selected_car = rno.get_vehicle_from_db(db, car_id)
    '''
    The final acceleration curvers (Curves), the engine acceleration potential 
    curves (cs_acc_per_gear), before the calculation of the resistances and the 
    limitation due to max possible acceleration (friction) .
    '''
    Curves, cs_acc_per_gear, StartStop, gs = mf.gear_4degree_curves_with_linear_gs(
        selected_car, gs_style)
    '''
        The difference betweeen "gear_4degree_curves_with_linear_gs" and 
        "gear_curves_n_gs_from_poly" is the
        computation of the engine acceleration potential curves
    '''
    # Curves, cs_acc_per_gear, StartStop, gs = mf.gear_curves_n_gs_from_
    # poly(selected_car, gs_style,4)
    '''Lists to gather simulation data'''
    Speeds = [v_start]
    Acceleration = [0]
    '''Initialize speed and gear'''
    speed = v_start
    '''
    Returns the gear that must be used and the clutch condition
    '''
    gear, gear_count = fg.gear_for_speed_profiles(gs, speed, 0, 0)
    gear_count = 0
    '''Core loop'''
    for t in times:
        speed, gear, gear_count = sp.simulation_step_function(
            selected_car.transmission, speed, gear, gear_count, gs, Curves,
            vdes, driver_style, sim_step)
        '''Gather data'''
        Speeds.append(speed)
        Acceleration.append((Speeds[-1] - Speeds[-2]) / sim_step)
    '''Plot'''
    plt.figure('Time-Speed')
    plt.plot(times, Speeds[1:])
    plt.grid()
    plt.figure('Speed-Acceleration')
    plt.plot(Speeds[1:], Acceleration[1:])
    plt.grid()
    plt.figure('Acceleration-Time')
    plt.plot(times, Acceleration[1:])
    plt.grid()

    plt.figure('Speed-Acceleration')
    for i, gear_curve in enumerate(Curves):
        sp_bins = np.arange(StartStop[0][i], StartStop[1][i] + 0.1, 0.1)
        accelerations = gear_curve(sp_bins)
        plt.plot(sp_bins, accelerations, 'k')
    plt.grid()
    plt.show()
    return 0
Exemplo n.º 8
0
def simple_run():
    """
    This example illustrates the specifications of vehicles in the database.

    :return:
    """
    # Vehicle database based on the Euro Car Segment classification
    db_path = osp.abspath(
        osp.join(osp.dirname(my_dir + "/../"), "db", "EuroSegmentCar_cleaned"))

    # load vehicle database
    db = rno.load_db_to_dictionary(db_path)
    df = pd.DataFrame.from_dict(db, orient="index")
    df = df.reset_index(drop=True)
    df["vehicle-class"] = pd.Categorical(df["vehicle-class"])
    df["vehicle-class"] = df["vehicle-class"].cat.codes

    # fig = px.parallel_coordinates(df_veh, color="Drive-Total max power",
    #                             dimensions=['vehicle-class', 'Drive-Total max power', 'Exterior sizes-Length', 'Performance-Acceleration 0-100 km/h',
    #                                         'Performance-Top speed', 'Weights-Empty mass', 'Class-Euro standard car segments'],
    #                             color_continuous_scale=px.colors.diverging.Tealrose,
    #                             color_continuous_midpoint=2)

    fig = go.Figure(data=go.Parcoords(
        line=dict(
            color=df["Drive-Total max power"].astype(float),
            colorscale=[[0, "purple"], [0.5, "lightseagreen"], [1, "gold"]],
        ),
        dimensions=[
            dict(
                label="Max power (kW)",
                values=df["Drive-Total max power"].astype(float),
            ),
            dict(
                label="Max torque (Nm)",
                values=df["Drive-Total max torque"].astype(float),
            ),
            dict(
                label="Max speed (m/s)",
                values=df["Performance-Top speed"].astype(float),
            ),
            dict(label="Veh mass (kg)",
                 values=df["Weights-Empty mass"].astype(float)),
            dict(
                label="Veh length (m)",
                values=df["Exterior sizes-Length"].astype(float),
            ),
            dict(
                label="0-100km/h time (s)",
                values=df["Performance-Acceleration 0-100 km/h"].astype(float),
            ),
            dict(
                tickvals=list(range(9)),
                ticktext=["A", "B", "C", "D", "E", "F", "J", "M", "S"],
                label="Veh class",
                values=df["vehicle-class"],
            ),
        ],
    ))

    fig.update_layout(plot_bgcolor="white", paper_bgcolor="white")
    fig.show()
Exemplo n.º 9
0
def simple_run():
    """
    This example performs a simulation with MFC model from a starting speed to a desired speed.

    :return:
    """
    # Vehicle databased based on the Euro Car Segment classification
    db_path = osp.abspath(
        osp.join(osp.dirname(my_dir + "/../"), "co2mpas_driver", "db",
                 "EuroSegmentCar"))

    # A sample car id from the database
    car_id = 47844

    # The gear shifting style as described in the TRR paper.
    gs_style = 0.9

    # The desired speed
    vdes = 124 / 3.6

    # Current speed
    v_start = 0

    # The simulation step in seconds
    sim_step = 0.1

    # The driving style as described in the TRR paper.
    driver_style = 0.2

    # Duration of the simulation in seconds.
    duration = 100

    # sample time series
    times = np.arange(10, duration + sim_step, sim_step)

    # load vehicle database
    db = rno.load_db_to_dictionary(db_path)

    # The vehicle specs as returned from the database
    selected_car = rno.get_vehicle_from_db(db, car_id, electric=True)
    """
    The final acceleration curvers (Curves), the engine acceleration potential
    curves (cs_acc_per_gear), before the calculation of the resistances and the
    limitation due to max possible acceleration (friction) .
    """
    Curves, Curves_dec, StartStop, gs = mf.get_ev_curve_main(selected_car)

    # Curves, cs_acc_per_gear, StartStop, gs = mf.gear_curves_n_gs_from_
    # poly(selected_car, gs_style,4)
    """Lists to gather simulation data"""
    Speeds = [v_start]
    Acceleration = [0]
    """Initialize speed and gear"""
    speed = v_start
    """
    Returns the gear that must be used and the clutch condition
    """
    gear, gear_count = fg.gear_for_speed_profiles(gs, speed, 0, 0)
    gear_count = 0
    """Core loop"""
    for t in times:
        speed, acceleration, gear, gear_count = sp.simulation_step_function(
            selected_car,
            speed,
            gear,
            gear_count,
            gs,
            Curves,
            vdes,
            driver_style,
            sim_step,
        )
        """Gather data"""
        Speeds.append(speed)
        Acceleration.append(acceleration)
    """Plot"""
    fig2 = plt.figure()
    plt.plot(times, Speeds[1:])
    fig2.suptitle("Speed over time", x=0.54, y=1, fontsize=12)
    plt.xlabel("Time (sec)", fontsize=12)
    plt.ylabel("Speed (m/s)", fontsize=12)
    plt.grid()

    fig3 = plt.figure("Acceleration over Speed")
    plt.plot(Speeds[1:], Acceleration[1:])
    fig3.suptitle("Acceleration over Speed", x=0.54, y=1, fontsize=12)
    plt.xlabel("Speed (m/s)", fontsize=12)
    plt.ylabel("Acceleration (m/s2)", fontsize=12)
    plt.grid()

    fig4 = plt.figure("Acceleration-Time")
    plt.plot(times, Acceleration[1:])
    fig4.suptitle("Acceleration over Time", x=0.54, y=1, fontsize=12)
    plt.xlabel("Time (sec)", fontsize=12)
    plt.ylabel("Acceleration (m/s2)", fontsize=12)
    plt.grid()

    fig5 = plt.figure("Acceleration over Speed")
    for i, gear_curve in enumerate(Curves):
        sp_bins = np.arange(StartStop[0][i], StartStop[1][i] + 0.1, 0.1)
        accelerations = gear_curve(sp_bins)
        plt.plot(sp_bins, accelerations, "k")
    fig5.suptitle("Acceleration over Speed", x=0.54, y=1, fontsize=12)
    plt.xlabel("Speed (m/s)", fontsize=12)
    plt.ylabel("Acceleration (m/s2)", fontsize=12)
    plt.grid()
    plt.show()