Eclipse SUMO - Simulation of Urban MObility
MSDevice_Friction.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2013-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 /****************************************************************************/
20 // A device which stands as an implementation Friction and which outputs movereminder calls
21 /****************************************************************************/
22 #include <config.h>
23 
29 #include <microsim/MSNet.h>
30 #include <microsim/MSLane.h>
31 #include <microsim/MSEdge.h>
32 #include <microsim/MSVehicle.h>
33 #include "MSDevice_Tripinfo.h"
34 #include "MSDevice_Friction.h"
35 
36 
37 // ===========================================================================
38 // method definitions
39 // ===========================================================================
40 // ---------------------------------------------------------------------------
41 // static initialisation methods
42 // ---------------------------------------------------------------------------
43 void
45  oc.addOptionSubTopic("Friction Device");
46  insertDefaultAssignmentOptions("friction", "Friction Device", oc);
47  oc.doRegister("device.friction.stdDev", new Option_Float(.1)); //default .1
48  oc.addDescription("device.friction.stdDev", "Friction Device", TL("The measurement noise parameter which can be applied to the friction device"));
49  oc.doRegister("device.friction.offset", new Option_Float(0.)); //default no offset
50  oc.addDescription("device.friction.offset", "Friction Device", TL("The measurement offset parameter which can be applied to the friction device -> e.g. to force false measurements"));
51 }
52 
53 
54 void
55 MSDevice_Friction::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into) {
57  if (equippedByDefaultAssignmentOptions(oc, "friction", v, false)) {
58  // build the device
59  MSDevice_Friction* device = new MSDevice_Friction(v, "friction_" + v.getID(),
60  getFloatParam(v, oc, "friction.stdDev", .1, false), // stdDev noise deviation
61  getFloatParam(v, oc, "friction.offset", 0., false)); // static offset
62  into.push_back(device);
63  }
64 }
65 
66 
67 // ---------------------------------------------------------------------------
68 // MSDevice_Friction-methods
69 // ---------------------------------------------------------------------------
70 MSDevice_Friction::MSDevice_Friction(SUMOVehicle& holder, const std::string& id, double stdDev, double offset) :
71  MSVehicleDevice(holder, id),
72  myMeasuredFrictionCoefficient(1.),
73  myRawFriction(1.),
74  myStdDeviation(stdDev),
75  myOffset(offset) {
76 }
77 
78 
80 }
81 
82 
83 bool
84 MSDevice_Friction::notifyMove(SUMOTrafficObject& /* tObject */, double /* oldPos */,
85  double /* newPos */, double /* newSpeed */) {
88  return true; // keep the device
89 }
90 
91 
92 std::string
93 MSDevice_Friction::getParameter(const std::string& key) const {
94  if (key == "frictionCoefficient") {
96  } else if (key == "stdDev") {
97  return toString(myStdDeviation);
98  } else if (key == "offset") {
99  return toString(myOffset);
100  } else if (key == "rawFriction") {
101  return toString(myRawFriction);
102  }
103  throw InvalidArgument("Parameter '" + key + "' is not supported for device of type '" + deviceName() + "'");
104 }
105 
106 
107 void
108 MSDevice_Friction::setParameter(const std::string& key, const std::string& value) {
109  try {
110  const double doubleValue = StringUtils::toDouble(value);
111  if (key == "frictionCoefficient") {
112  myMeasuredFrictionCoefficient = doubleValue;
113  } else if (key == "stdDev") {
114  myStdDeviation = doubleValue;
115  } else if (key == "offset") {
116  myOffset = doubleValue;
117  } else {
118  throw InvalidArgument("Setting parameter '" + key + "' is not supported for device of type '" + deviceName() + "'");
119  }
120  } catch (NumberFormatException&) {
121  throw InvalidArgument("Setting parameter '" + key + "' requires a number for device of type '" + deviceName() + "'");
122  }
123 }
124 
125 
126 /****************************************************************************/
#define TL(string)
Definition: MsgHandler.h:315
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
A device which collects info on current friction Coefficient on the road.
std::string getParameter(const std::string &key) const
try to retrieve the given parameter from this device. Throw exception for unsupported key
double myOffset
a value which is initialised based on a vType parameter
~MSDevice_Friction()
Destructor.
double myStdDeviation
a value which is initialised based on a vehicle parameter
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_Friction-options.
MSDevice_Friction(SUMOVehicle &holder, const std::string &id, double stdDev, double offset)
Constructor.
void setParameter(const std::string &key, const std::string &value)
try to set the given parameter for this device. Throw exception for unsupported key
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks for waiting steps when the vehicle moves.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
const std::string deviceName() const
return the name for this type of device
double myRawFriction
realValue from Road (without measurement model)
double myMeasuredFrictionCoefficient
a value which is initialised based on a commandline/configuration option
static double getFloatParam(const SUMOVehicle &v, const OptionsCont &oc, const std::string &paramName, const double deflt, bool required=false)
Definition: MSDevice.cpp:206
static void insertDefaultAssignmentOptions(const std::string &deviceName, const std::string &optionsTopic, OptionsCont &oc, const bool isPerson=false)
Adds common command options that allow to assign devices to vehicles.
Definition: MSDevice.cpp:155
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, DEVICEHOLDER &v, bool outputOptionSet, const bool isPerson=false)
Determines whether a vehicle should get a certain device.
Definition: MSDevice.h:203
double getFrictionCoefficient() const
Returns the lane's friction coefficient.
Definition: MSLane.h:591
Abstract in-vehicle device.
SUMOVehicle & myHolder
The vehicle that stores the device.
const std::string & getID() const
Returns the id.
Definition: Named.h:74
A storage for options typed value containers)
Definition: OptionsCont.h:89
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
void doRegister(const std::string &name, Option *o)
Adds an option under the given name.
Definition: OptionsCont.cpp:76
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:60
static double randNorm(double mean, double variance, SumoRNG *rng=nullptr)
Access to a random number from a normal distribution.
Definition: RandHelper.cpp:137
Representation of a vehicle, person, or container.
virtual SumoRNG * getRNG() const =0
Returns the associated RNG for this object.
virtual const MSLane * getLane() const =0
Returns the lane the object is currently at.
Representation of a vehicle.
Definition: SUMOVehicle.h:60
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter