Line data Source code
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 : /****************************************************************************/ 14 : /// @file MSDevice_Friction.cpp 15 : /// @author Daniel Krajzewicz 16 : /// @author Michael Behrisch 17 : /// @author Jakob Erdmann 18 : /// @date 11.06.2013 19 : /// 20 : // A device which stands as an implementation Friction and which outputs movereminder calls 21 : /****************************************************************************/ 22 : #include <config.h> 23 : 24 : #include <utils/common/RandHelper.h> 25 : #include <utils/common/StringUtils.h> 26 : #include <utils/options/OptionsCont.h> 27 : #include <utils/iodevices/OutputDevice.h> 28 : #include <utils/vehicle/SUMOVehicle.h> 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 44 36322 : MSDevice_Friction::insertOptions(OptionsCont& oc) { 45 36322 : oc.addOptionSubTopic("Friction Device"); 46 72644 : insertDefaultAssignmentOptions("friction", "Friction Device", oc); 47 36322 : oc.doRegister("device.friction.stdDev", new Option_Float(.1)); //default .1 48 72644 : oc.addDescription("device.friction.stdDev", "Friction Device", TL("The measurement noise parameter which can be applied to the friction device")); 49 36322 : oc.doRegister("device.friction.offset", new Option_Float(0.)); //default no offset 50 72644 : 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 36322 : } 52 : 53 : 54 : void 55 4655763 : MSDevice_Friction::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into) { 56 4655763 : OptionsCont& oc = OptionsCont::getOptions(); 57 9311526 : if (equippedByDefaultAssignmentOptions(oc, "friction", v, false)) { 58 : // build the device 59 48 : MSDevice_Friction* device = new MSDevice_Friction(v, "friction_" + v.getID(), 60 96 : getFloatParam(v, oc, "friction.stdDev", .1, false), // stdDev noise deviation 61 96 : getFloatParam(v, oc, "friction.offset", 0., false)); // static offset 62 48 : into.push_back(device); 63 : } 64 4655763 : } 65 : 66 : 67 : // --------------------------------------------------------------------------- 68 : // MSDevice_Friction-methods 69 : // --------------------------------------------------------------------------- 70 48 : MSDevice_Friction::MSDevice_Friction(SUMOVehicle& holder, const std::string& id, double stdDev, double offset) : 71 : MSVehicleDevice(holder, id), 72 48 : myMeasuredFrictionCoefficient(1.), 73 48 : myRawFriction(1.), 74 48 : myStdDeviation(stdDev), 75 48 : myOffset(offset) { 76 48 : } 77 : 78 : 79 96 : MSDevice_Friction::~MSDevice_Friction() { 80 96 : } 81 : 82 : 83 : bool 84 3556 : MSDevice_Friction::notifyMove(SUMOTrafficObject& /* tObject */, double /* oldPos */, 85 : double /* newPos */, double /* newSpeed */) { 86 3556 : myRawFriction = myHolder.getLane()->getFrictionCoefficient(); 87 3556 : myMeasuredFrictionCoefficient = myOffset + RandHelper::randNorm(myRawFriction, myStdDeviation, myHolder.getRNG()); 88 3556 : return true; // keep the device 89 : } 90 : 91 : 92 : std::string 93 0 : MSDevice_Friction::getParameter(const std::string& key) const { 94 0 : if (key == "frictionCoefficient") { 95 0 : return toString(myMeasuredFrictionCoefficient); 96 0 : } else if (key == "stdDev") { 97 0 : return toString(myStdDeviation); 98 0 : } else if (key == "offset") { 99 0 : return toString(myOffset); 100 0 : } else if (key == "rawFriction") { 101 0 : return toString(myRawFriction); 102 : } 103 0 : throw InvalidArgument("Parameter '" + key + "' is not supported for device of type '" + deviceName() + "'"); 104 : } 105 : 106 : 107 : void 108 0 : MSDevice_Friction::setParameter(const std::string& key, const std::string& value) { 109 : try { 110 0 : const double doubleValue = StringUtils::toDouble(value); 111 0 : if (key == "frictionCoefficient") { 112 0 : myMeasuredFrictionCoefficient = doubleValue; 113 0 : } else if (key == "stdDev") { 114 0 : myStdDeviation = doubleValue; 115 0 : } else if (key == "offset") { 116 0 : myOffset = doubleValue; 117 : } else { 118 0 : throw InvalidArgument("Setting parameter '" + key + "' is not supported for device of type '" + deviceName() + "'"); 119 : } 120 0 : } catch (NumberFormatException&) { 121 0 : throw InvalidArgument("Setting parameter '" + key + "' requires a number for device of type '" + deviceName() + "'"); 122 0 : } 123 0 : } 124 : 125 : 126 : /****************************************************************************/