Eclipse SUMO - Simulation of Urban MObility
VehicleEngineHandler.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 /****************************************************************************/
19 #include <config.h>
20 
22 #include "VehicleEngineHandler.h"
23 
24 
25 // ===========================================================================
26 // static variables
27 // ===========================================================================
41 
43 };
44 
45 
73 
75 };
76 
77 
78 // ===========================================================================
79 // method definitions
80 // ===========================================================================
82  : GenericSAXHandler(engineTags, ENGINE_TAG_NOTHING, engineAttrs, ENGINE_ATTR_NOTHING, "vehicles"),
83  skip(false), currentGear(1) {
84  vehicleToLoad = toLoad;
85 }
86 
87 
89 
90 
91 void
93  switch (element) {
94  case ENGINE_TAG_VEHICLE:
96  if (!skip) {
98  }
99  break;
100  case ENGINE_TAG_GEAR:
101  if (!skip) {
102  int number = attrs.getInt(ENGINE_ATTR_GEAR_N);
103  if (number != currentGear) {
104  //fatal
105  std::stringstream ss;
106  ss << "Invalid gear number " << number << ". Please check that gears are inserted in order";
107  throw ProcessError(ss.str());
108  }
109  gearRatios.push_back(attrs.getFloat(ENGINE_ATTR_GEAR_RATIO));
110  currentGear++;
111  }
112  break;
114  if (!skip) {
115  // Load final drive ratio
117  }
118  break;
119  case ENGINE_TAG_MASS:
120  if (!skip) {
121  // Loads mass information, i.e., mass in kg and mass factor which takes into account rotational parts of the engine
124  }
125  break;
126  case ENGINE_TAG_DRAG:
127  if (!skip) {
128  // Load air drag related data such as drag coefficient and maximum vehicle section
131  }
132  break;
133  case ENGINE_TAG_WHEELS:
134  if (!skip) {
135  // Load data about vehicle's wheels, such as diameter and friction coefficient
140  }
141  break;
142  case ENGINE_TAG_ENGINE:
143  if (!skip) {
144  // Load data about the engine, such as efficiency factor and cylinders
153  }
155  std::string mapType = attrs.getString(ENGINE_ATTR_ENGINE_TYPE);
156  if (mapType != "poly") {
157  throw ProcessError(TL("Invalid engine map type. Only \"poly\" is supported for now"));
158  }
159  }
160  break;
162  if (!skip) {
163  //check that the degree is within the maximum supported
164  if (attrs.hasAttribute("x" + toString(MAX_POLY_DEGREE))) {
165  std::stringstream ss;
166  ss << "Maximum degree for the engine polynomial is " << MAX_POLY_DEGREE << ". Please check your model's data";
167  throw ProcessError(ss.str());
168  }
169  //parse all polynomial coefficients
170  for (int i = 0; i < MAX_POLY_DEGREE; i++) {
171  const std::string param = "x" + toString(i);
172  if (attrs.hasAttribute(param)) {
173  engineParameters.engineMapping.x[i] = attrs.getFloat(param);
174  } else {
175  //save the actual degree
177  break;
178  }
179  }
180  }
181  break;
182  case ENGINE_TAG_SHIFTING:
183  if (!skip) {
186  }
187  break;
188  case ENGINE_TAG_BRAKES:
189  if (!skip) {
191  }
192  break;
193  case ENGINE_TAG_VEHICLES:
194  case ENGINE_TAG_GEARS:
195  break;
196  default:
197  WRITE_WARNINGF(TL("Unknown tag '%' while parsing."), toString(element));
198  }
199 }
200 
201 
202 void
204  switch (element) {
205  case ENGINE_TAG_GEARS:
206  delete[] engineParameters.gearRatios;
207  engineParameters.gearRatios = new double[gearRatios.size()];
208  for (int i = 0; i < (int)gearRatios.size(); i++) {
210  }
211  engineParameters.nGears = (int)gearRatios.size();
212  break;
213  case ENGINE_TAG_VEHICLES:
215  break;
216  default:
217  break;
218  }
219 }
220 
221 
222 /****************************************************************************/
#define MAX_POLY_DEGREE
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:296
#define TL(string)
Definition: MsgHandler.h:315
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
struct PolynomialEngineModelRpmToHp engineMapping
double tiresFrictionCoefficient
struct GearShiftingRules shiftingRule
A handler which converts occurring elements and attributes into enums.
Encapsulated SAX-Attributes.
virtual std::string getString(int id, bool *isPresent=nullptr) const =0
Returns the string-value of the named (by its enum-value) attribute.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list.
int getInt(int id) const
Returns the int-value of the named (by its enum-value) attribute.
double getFloat(int id) const
Returns the double-value of the named (by its enum-value) attribute.
virtual ~VehicleEngineHandler()
Destructor.
std::vector< double > gearRatios
EngineParameters engineParameters
VehicleEngineHandler(const std::string &toLoad)
void myEndElement(int element)
Called when a closing tag occurs.
static StringBijection< int >::Entry engineTags[]
The names of engine-XML elements (for passing to GenericSAXHandler)
static StringBijection< int >::Entry engineAttrs[]
The names of engine-XML attributes (for passing to GenericSAXHandler)
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.