.VehicleInterfaces.Roads.Tutorial

Information

Tutorial - Defining a new road

This tutorial will guide you through the steps required to build the FlatRoad model.

  1. Create a new road model by extending the base definition which is VehicleInterfaces.Roads.Interfaces.Base
  2. The minimum steps necessary to define a road model are to provide definitions to the following partial function definitions included in the base road model.
  3. Define the position function. The road is to be defined as a line along the x-axis with the lateral direction along the y-axis. The inputs to the base position function are s and w and these have the following meaning in this road definition:
    s: x-coordinate in world frame (x-axis is road heading direction)
    w: y-coordinate in world frame (y-axis is lateral displacement)
          
    The input arguments s and w are common to all the road functions that we need to define and are included in the base function definitions. These definitions can then be used to define our position function as follows:
    function linePosition "Determine point on road"
      extends VehicleInterfaces.Roads.Interfaces.Base.position;
    algorithm
      r_0 := {s,w,0};
    end linePosition;
          
  4. Define the trackOffset function. This road is defined with a constant offset that can be non-zero so the function is defined as:
    function constantOffset "Determine offset from road centre line"
      extends VehicleInterfaces.Roads.Interfaces.Base.trackOffset;
      input Modelica.SIunits.Distance offset;
    algorithm
      trackOffset := {0,offset,0};
    end constantOffset;
          
  5. Define the normal function. This road is a flat road so the normal is always in the same direction along the z-axis and our normal function can be defined as:
    function lineNormal "Determine unit normal on road"
      extends VehicleInterfaces.Roads.Interfaces.Base.normal;
    algorithm
      e_n_0 := {0,0,1};
    end lineNormal;
          
  6. Define the headingDirection function. In step 3, we define the road as a line along the x-axis. This means that the heading direction is always in the same direction along the x-axis and our headingDirection function can be defined as:
    function lineHeadingDirection
      "Determine unit heading direction on road"
      extends VehicleInterfaces.Roads.Interfaces.Base.headingDirection;
    algorithm
      e_s_0 := {1,0,0};
    end lineHeadingDirection;
          
  7. Define the frictionCoefficient function. The friction coefficient could be defined to vary along the road surface but in this case we are going to define it as a constant. Our frictionCoefficient can be defined as:
    function lineFrictionCoefficient
      "Determine friction coefficient at point on road"
      extends VehicleInterfaces.Roads.Interfaces.Base.frictionCoefficient;
      input Real mu_fixed "Friction coefficient";
    algorithm
      mu := mu_fixed;
    end lineFrictionCoefficient;
          
  8. We now need to redeclare the functions in the base road definition to be the functions shown above. We do this with the following code assuming that the above functions have been defined within the class FlatRoad:
    model FlatRoad "Straight road along x-axis (perpendicular to world z-axis)"
      extends VehicleInterfaces.Roads.Interfaces.Base(
        redeclare final function position = linePosition,
        redeclare final function trackOffset = constantOffset(offset=offset)
        redeclare final function normal = lineNormal,
        redeclare final function headingDirection = lineHeadingDirection,
        redeclare final function frictionCoefficient = lineFrictionCoefficient(mu_fixed=mu));
    
      //rest of definition
      ...
    end FlatRoad;
          
  9. In redeclaring the functions we have also introduced new parameters mu and offset that need to be added to the model to define the friction coefficient of the road and the track offset from the road centre line.
  10. The FlatRoad model included in this package also includes animation of the road surface but this is not essential to the definition of the road and will not be described in this tutorial.
  11. The road model is complete and can now be used.

Generated at 2024-12-17T19:26:02Z by OpenModelicaOpenModelica 1.24.3 using GenerateDoc.mos