LCOV - code coverage report
Current view: top level - src/microsim/devices - MSDevice_Friction.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 54.0 % 50 27
Test Date: 2024-11-22 15:46:21 Functions: 75.0 % 8 6

            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        43644 : MSDevice_Friction::insertOptions(OptionsCont& oc) {
      45        43644 :     oc.addOptionSubTopic("Friction Device");
      46        87288 :     insertDefaultAssignmentOptions("friction", "Friction Device", oc);
      47        43644 :     oc.doRegister("device.friction.stdDev", new Option_Float(.1)); //default .1
      48        87288 :     oc.addDescription("device.friction.stdDev", "Friction Device", TL("The measurement noise parameter which can be applied to the friction device"));
      49        43644 :     oc.doRegister("device.friction.offset", new Option_Float(0.)); //default no offset
      50        87288 :     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        43644 : }
      52              : 
      53              : 
      54              : void
      55      5104363 : MSDevice_Friction::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into) {
      56      5104363 :     OptionsCont& oc = OptionsCont::getOptions();
      57     10208726 :     if (equippedByDefaultAssignmentOptions(oc, "friction", v, false)) {
      58              :         // build the device
      59           96 :         MSDevice_Friction* device = new MSDevice_Friction(v, "friction_" + v.getID(),
      60              :                 v.getFloatParam("device.friction.stdDev"), // stdDev noise deviation
      61          144 :                 v.getFloatParam("device.friction.offset")); // static offset
      62           48 :         into.push_back(device);
      63              :     }
      64      5104363 : }
      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              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1