Skip to content

Commit

Permalink
documenting units and making gravity a named constant, refs eclipse-s…
Browse files Browse the repository at this point in the history
  • Loading branch information
behrisch committed Oct 16, 2020
1 parent 4358260 commit fbb42d8
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/mesosim/MEVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class MEVehicle : public MSBaseVehicle {
double getAngle() const;


/** @brief Returns the slope of the road at vehicle's position
/** @brief Returns the slope of the road at vehicle's position in degrees
* @return The slope
*/
double getSlope() const;
Expand Down
6 changes: 0 additions & 6 deletions src/microsim/MSBaseVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,6 @@ MSBaseVehicle::getAcceleration() const {
}


double
MSBaseVehicle::getSlope() const {
return 0;
}


void
MSBaseVehicle::onDepart() {
myDeparture = MSNet::getInstance()->getCurrentTimeStep();
Expand Down
7 changes: 0 additions & 7 deletions src/microsim/MSBaseVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,6 @@ class MSBaseVehicle : public SUMOVehicle {
*/
virtual double getAcceleration() const;

/** @brief Returns the slope of the road at vehicle's position
*
* This default implementation returns always 0.
* @return The slope
*/
virtual double getSlope() const;

/** @brief Called when the vehicle is inserted into the network
*
* Sets optional information about departure time, informs the vehicle
Expand Down
2 changes: 1 addition & 1 deletion src/microsim/MSVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ class MSVehicle : public MSBaseVehicle {
/// @name Other getter methods
//@{

/** @brief Returns the slope of the road at vehicle's position
/** @brief Returns the slope of the road at vehicle's position in degrees
* @return The slope
*/
double getSlope() const;
Expand Down
3 changes: 1 addition & 2 deletions src/microsim/cfmodels/MSCFModel_KraussPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ MSCFModel_KraussPS::~MSCFModel_KraussPS() {}

double
MSCFModel_KraussPS::maxNextSpeed(double speed, const MSVehicle* const veh) const {
const double gravity = 9.80665;
const double aMax = MAX2(0., getMaxAccel() - gravity * sin(DEG2RAD(veh->getSlope())));
const double aMax = MAX2(0., getMaxAccel() - GRAVITY * sin(DEG2RAD(veh->getSlope())));
// assuming drag force is proportional to the square of speed
const double vMax = MAX2(
sqrt(aMax / getMaxAccel()) * myType->getMaxSpeed(),
Expand Down
8 changes: 3 additions & 5 deletions src/microsim/cfmodels/MSCFModel_Rail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
#include <microsim/lcmodels/MSAbstractLaneChangeModel.h>
#include "MSCFModel_Rail.h"

#define G 9.80665

MSCFModel_Rail::MSCFModel_Rail(const MSVehicleType* vtype) :
MSCFModel(vtype) {
const std::string trainType = vtype->getParameter().getCFParamString(SUMO_ATTR_TRAIN_TYPE, "NGT400");
Expand Down Expand Up @@ -117,7 +115,7 @@ double MSCFModel_Rail::maxNextSpeed(double speed, const MSVehicle* const veh) co
double res = getInterpolatedValueFromLookUpMap(speed, &(myTrainParams.resistance)); // kN

double slope = veh->getSlope();
double gr = myTrainParams.weight * G * sin(DEG2RAD(slope)); //kN
double gr = myTrainParams.weight * GRAVITY * sin(DEG2RAD(slope)); //kN

double totalRes = res + gr; //kN

Expand All @@ -143,7 +141,7 @@ double MSCFModel_Rail::maxNextSpeed(double speed, const MSVehicle* const veh) co
double MSCFModel_Rail::minNextSpeed(double speed, const MSVehicle* const veh) const {

const double slope = veh->getSlope();
const double gr = myTrainParams.weight * G * sin(DEG2RAD(slope)); //kN
const double gr = myTrainParams.weight * GRAVITY * sin(DEG2RAD(slope)); //kN
const double res = getInterpolatedValueFromLookUpMap(speed, &(myTrainParams.resistance)); // kN
const double totalRes = res + gr; //kN
const double a = myTrainParams.decl + totalRes / myTrainParams.rotWeight;
Expand Down Expand Up @@ -205,7 +203,7 @@ double MSCFModel_Rail::getInterpolatedValueFromLookUpMap(double speed, const Loo
double MSCFModel_Rail::getSpeedAfterMaxDecel(double /* speed */) const {

// //TODO: slope not known here
// double gr = 0; //trainParams.weight * 9.81 * edge.grade
// double gr = 0; //trainParams.weight * GRAVITY * edge.grade
//
// double a = 0;//trainParams.decl - gr/trainParams.rotWeight;
//
Expand Down
12 changes: 6 additions & 6 deletions src/utils/emissions/HelpersEnergy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ HelpersEnergy::compute(const SUMOEmissionClass /* c */, const PollutantsInterfac
const double mass = param->find(SUMO_ATTR_VEHICLEMASS)->second;

// calculate potential energy difference
double energyDiff = mass * 9.81 * sin(DEG2RAD(slope)) * SPEED2DIST(v);
double energyDiff = mass * GRAVITY * sin(DEG2RAD(slope)) * SPEED2DIST(v);

// kinetic energy difference of vehicle
energyDiff += 0.5 * mass * (v * v - lastV * lastV);
Expand All @@ -88,7 +88,7 @@ HelpersEnergy::compute(const SUMOEmissionClass /* c */, const PollutantsInterfac
// EnergyLoss,Tire = c_R [-] * F_N [N] * s [m]
// ... with c_R = ~0.012 (car tire on asphalt)
// ... with F_N [N] = myMass [kg] * g [m/s^2]
energyDiff += param->find(SUMO_ATTR_ROLLDRAGCOEFFICIENT)->second * 9.81 * mass * SPEED2DIST(v);
energyDiff += param->find(SUMO_ATTR_ROLLDRAGCOEFFICIENT)->second * GRAVITY * mass * SPEED2DIST(v);

// Energy loss through friction by radial force [Ws]
// If angle of vehicle was changed
Expand Down Expand Up @@ -167,16 +167,16 @@ HelpersEnergy::acceleration(const SUMOEmissionClass /* c */, const PollutantsInt
}

// calculate power drop due to a potential energy difference
Prest -= mass * 9.81 * sin(DEG2RAD(slope)) * (v);
const1 = mass * 9.81 * sin(DEG2RAD(slope)) * (TS);
Prest -= mass * GRAVITY * sin(DEG2RAD(slope)) * (v);
const1 = mass * GRAVITY * sin(DEG2RAD(slope)) * (TS);

// Power loss through Roll resistance [W]
// ... (fabs(veh.getSpeed())>=0.01) = 0, if vehicle isn't moving
// EnergyLoss,Tire = c_R [-] * F_N [N] * s [m]
// ... with c_R = ~0.012 (car tire on asphalt)
// ... with F_N [N] = myMass [kg] * g [m/s^2]
Prest -= param->find(SUMO_ATTR_ROLLDRAGCOEFFICIENT)->second * 9.81 * mass * v;
const1 += param->find(SUMO_ATTR_ROLLDRAGCOEFFICIENT)->second * 9.81 * mass * (TS);
Prest -= param->find(SUMO_ATTR_ROLLDRAGCOEFFICIENT)->second * GRAVITY * mass * v;
const1 += param->find(SUMO_ATTR_ROLLDRAGCOEFFICIENT)->second * GRAVITY * mass * (TS);

//Constant loads are omitted. We assume P as the max limit for the main traction drive. Constant loads are often covered by an auxiliary drive
//Power loss through constant loads (e.g. A/C) [W]
Expand Down
2 changes: 1 addition & 1 deletion src/utils/emissions/HelpersHBEFA.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class HelpersHBEFA : public PollutantsInterface::Helper {
return 0.;
}
const double* f = myFunctionParameter[index] + 6 * e;
const double alpha = asin(a / 9.81) * 180. / M_PI;
const double alpha = RAD2DEG(asin(a / GRAVITY));
return (double) MAX2((f[0] + f[1] * alpha * kmh + f[2] * alpha * alpha * kmh + f[3] * kmh + f[4] * kmh * kmh + f[5] * kmh * kmh * kmh) / scale, 0.);
}

Expand Down
1 change: 1 addition & 0 deletions src/utils/geom/GeomHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#define DEG2RAD(x) static_cast<double>((x) * M_PI / 180.)
#define RAD2DEG(x) static_cast<double>((x) * 180. / M_PI)
#define GRAVITY 9.80665


// ===========================================================================
Expand Down
2 changes: 1 addition & 1 deletion src/utils/vehicle/SUMOTrafficObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class SUMOTrafficObject : public Named {
*/
virtual const MSEdge* getEdge() const = 0;

/** @brief Returns the slope of the road at object's position
/** @brief Returns the slope of the road at object's position in degrees
* @return The slope
*/
virtual double getSlope() const = 0;
Expand Down

0 comments on commit fbb42d8

Please sign in to comment.