getReferencePosition
Description
gets the reference position position = getReferencePosition(vehicle,vehicleBodyLocation)position of the vehicle
vehicle at the specified vehicle body location
vehicleBodyLocation.
Examples
Create a driving scenario object.
scenario = drivingScenario;
Add road and lane segments to the driving scenario.
roadCenters = [10.3 25.94 0;
34.8 0.45 0;
19.1 -21.74 0];
laneSpecification = lanespec(2,Width=5);
road(scenario,roadCenters,Lanes=laneSpecification,Name="Road")ans =
Road with properties:
Name: "Road"
RoadID: 1
RoadCenters: [3×3 double]
RoadWidth: 10.1500
BankAngle: [3×1 double]
Heading: [3×1 double]
Add a vehicle to the scenario, and specify waypoint positions and speeds. Use the waypoints and speeds to create a trajectory for the vehicle, with reference to the front axle for steering.
egoVehicle = vehicle(scenario, ... ClassID=2, ... Length=8.2, ... Width=2.5, ... Height=3.5, ... Position=[21.4185032445924 18.4409098505372 0.01], ... RearOverhang=1, ... FrontOverhang=0.9, ... Mesh=driving.scenario.truckMesh, ... Name="Truck"); waypoints = [21.41 18.44 0.01; 29.9 12.34 0.01; 35.3 5.85 0.01; 36.99 0.75 0.01; 36.4 -6.25 0.01; 33.2 -12.24 0.01; 28.6 -17.14 0.01]; speed = [30 30 30 30 30 30 30]'; trajectory(egoVehicle,waypoints,speed,ReferenceSteerPosition="front-axle")
Plot the scenario, run the simulation, and get the position of the vehicle at its front-axle location and rear-axle location for each frame.
plot(scenario,Waypoints="on",RoadCenters="on",ShowRearAxle="on") frames = 1; while advance(scenario) frontAxlePosition(frames,:) = getReferencePosition(egoVehicle,"front-axle"); rearAxlePosition(frames,:) = getReferencePosition(egoVehicle,"rear-axle"); frames = frames + 1; pause(0.1) end

Display the position of the vehicle at its front-axle location and rear-axle location for the first few frames. Units are in meters.
head(frontAxlePosition,5)
21.6616 18.2765 0.0100 21.9131 18.1130 0.0100 22.1645 17.9494 0.0100 22.4158 17.7856 0.0100 22.6670 17.6215 0.0100
head(rearAxlePosition,5)
16.3788 21.7091 0.0100 16.6304 21.5457 0.0100 16.8819 21.3822 0.0100 17.1335 21.2187 0.0100 17.3850 21.0552 0.0100
Plot the wheel base, and position of the vehicle at its front-axle location and rear-axle location.
clf plot(frontAxlePosition(:,2),frontAxlePosition(:,1)) hold on plot(rearAxlePosition(:,2),rearAxlePosition(:,1)) i = 1; while i <= length(frontAxlePosition(:,1)) f = scatter(frontAxlePosition(i,2),frontAxlePosition(i,1)); r = scatter(rearAxlePosition(i,2),rearAxlePosition(i,1)); f.MarkerFaceColor = "#4DBEEE"; r.Marker = "*"; r.MarkerEdgeColor = "#D95319"; plot([frontAxlePosition(i,2),rearAxlePosition(i,2)],[frontAxlePosition(i,1),rearAxlePosition(i,1)],"k"); i = i + 20; end legend(["Front Axle Trajectory","Rear Axle Trajectory","","","Wheelbase"]) xlim([-20 30]) ylim([0 50])

Input Arguments
Vehicle belonging to a drivingScenario object, specified as a
Vehicle object. To create a Vehicle object, use the
vehicle function.
Vehicle body location for which to obtain the vehicle reference position, specified
as one of these options: "front-bumper",
"rear-bumper", "front-axle", or
"rear-axle".
Data Types: string
Output Arguments
Reference position of the vehicle, returned as a three-element row vector in the
form [x
y
z]. Units are in meters. The vehicleBodyLocation
input argument specifies the vehicle body location for which to obtain the vehicle
reference position position.
Data Types: single | double
Version History
Introduced in R2024b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Seleccione un país/idioma
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
Cómo obtener el mejor rendimiento
Seleccione China (en idioma chino o inglés) para obtener el mejor rendimiento. Los sitios web de otros países no están optimizados para ser accedidos desde su ubicación geográfica.
América
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)