// A gearbox for the drivetrain.
//
// Copyright (C) 2001-2019 Sam Varner
//
// This file is part of Vamos Automotive Simulator.
//
// Vamos is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Vamos is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Vamos. If not, see <http://www.gnu.org/licenses/>.
#ifndef _TRANSMISSION_H_
#define _TRANSMISSION_H_
#include <map>
#include <vector>
namespace Vamos_Body
{
/// A gearbox for the drivetrain.
class Transmission
{
public:
/// Let the program calulate equally-spaced
Transmission(int forward_gears, double first_ratio, double last_ratio);
Transmission(const std::vector<std::pair<int, double>>& gears);
/// Shift to a particular gear.
void shift(int gear);
/// @return The ratio for a gear.
double get_gear_ratio(int gear) const;
/// @return the torque on the driveshaft due to friction at the clutch.
double get_torque(double drag) const;
/// @return the current gear.
int get_gear() const;
/// @return the number of consecutive forward gears.
int num_forward_gears() const;
/// @return the number of consecutive reverse gears.
int num_reverse_gears() const;
/// Tell the transmission what the rotational speed of the driveshaft is.
void set_driveshaft_speed(double speed);
/// @return the rotational speed at the clutch side of the transmission.
double get_clutch_speed() const;
/// A map of gears to gear ratios. Neutral has a key of 0. Reverse gears have
/// negative keys.
std::map<int, double> m_gear_ratios;
/// The current gear.
int m_gear = 0;
/// The number of consecutive forward gears.
int m_forward_gears;
/// The number of consecutive reverse gears.
int m_reverse_gears;
/// The rotational speed at the clutch side of the transmission.
double m_clutch_speed = 0.0;
};
} // namespace Vamos_Body
#endif // not _TRANSMISSION_H_