{"id":1521,"date":"2026-01-15T13:49:11","date_gmt":"2026-01-15T18:49:11","guid":{"rendered":"https:\/\/blogs.mathworks.com\/autonomous-systems\/?p=1521"},"modified":"2026-01-17T11:52:24","modified_gmt":"2026-01-17T16:52:24","slug":"scalable-actor-behavior-design-for-randomized-traffic-in-roadrunner","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/autonomous-systems\/2026\/01\/15\/scalable-actor-behavior-design-for-randomized-traffic-in-roadrunner\/","title":{"rendered":"Scalable Actor Behavior Design for Randomized Traffic in RoadRunner"},"content":{"rendered":"<p>The <a href=\"https:\/\/blogs.mathworks.com\/autonomous-systems\/2026\/01\/05\/roadrunner-for-nvidia-sgd\/\">previous post<\/a> introduced a MATLAB-based traffic swarm framework capable of generating randomized ambient traffic with configurable safety and behavioral parameters. Realistic traffic scenarios require each vehicle to have a robust behavior model that can follow designated routes while autonomously avoiding collisions, especially at complex intersections.<\/p>\n<p>To fully leverage the Model-Based Design (MBD) workflow and enhance simulation performance, the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2025b\/driving\/ug\/co-simulate-roadrunner-with-agents-modeled-in-matlab.html\">MATLAB-based behavior model<\/a> has been transitioned to a <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2025b\/driving\/ug\/co-simulate-roadrunner-with-agents-modeled-in-simulink.html\">Simulink-based one<\/a>. In this article, we will explore the architecture of the Simulink actor behavior model shown below in detail.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"3536\" height=\"1105\" class=\"size-full wp-image-1522 alignleft\" src=\"http:\/\/blogs.mathworks.com\/autonomous-systems\/files\/2026\/01\/image1-1.png\" alt=\"\" \/><\/p>\n<h1>Lead Vehicle Detection via Ideal Ground Truth Sensors<\/h1>\n<p>Implementing Adaptive Cruise Control (ACC) requires accurate detection of the lead vehicle. This can be efficiently implemented by utilizing an <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2025b\/driving\/ref\/idealgroundtruthsensor.html\">ideal ground truth sensor<\/a> while co-simulating RoadRunner Scenario and Simulink. The process begins by specifying the sensor\u2019s mounting parameters, such as position and orientation, as well as its detection parameters, including field of view and detection range.<\/p>\n<p>The ideal sensor outputs the poses of detected targets within its field of view, reported in the ego vehicle\u2019s coordinate frame. The sensor also generates the ego lane boundaries when the detection type is configured to \u201cObjects and Lanes.\u201d Please refer to the following screenshot of the sensor settings for more information.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"1484\" height=\"1337\" class=\"aligncenter size-full wp-image-1523\" src=\"http:\/\/blogs.mathworks.com\/autonomous-systems\/files\/2026\/01\/image2.png\" alt=\"\" \/><\/p>\n<p>Detected targets are filtered to identify candidates for the lead vehicle within the ego lane boundaries. Among these, the vehicle with the minimum headway is selected as the lead vehicle\u2014for example, the blue cross-marked vehicle shown in the following figure. The rectangles depict the ground-truth vehicle poses within the field of view, while the red dot markers represent targets reported by the sensor. Note that, based on the sensor configuration, only the closest point on each vehicle is reported.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"2108\" height=\"1300\" class=\"aligncenter size-full wp-image-1524\" src=\"http:\/\/blogs.mathworks.com\/autonomous-systems\/files\/2026\/01\/image3-1.png\" alt=\"\" \/><\/p>\n<h1>Adaptive Cruise Control (ACC)<\/h1>\n<p>We implement a simple Adaptive Cruise Control (ACC) system based on <a href=\"https:\/\/www.sciencedirect.com\/science\/article\/abs\/pii\/0191261581900370?via%3Dihub\">Gipps\u2019 car-following model<\/a>, which balances free-flow driving objectives with safety constraints.<\/p>\n<p>A <strong>braking (safety) term<\/strong> first computes the maximum speed that allows the ego vehicle to stop safely if the lead vehicle brakes abruptly:<\/p>\n<pre><span style=\"color: #339966;\">% Inputs:\r\n%\u00a0\u00a0 s_leader\u00a0\u00a0\u00a0 - position of the lead vehicle [m]\r\n%\u00a0\u00a0 s_follower\u00a0 - position of the follower vehicle [m]\r\n%\u00a0\u00a0 v_leader\u00a0\u00a0\u00a0 - current speed of the lead vehicle [m\/s]\r\n% Parameters:\r\n%\u00a0\u00a0 s0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 - minimum desired gap [m]\r\n%\u00a0\u00a0 b_max\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 - comfortable deceleration of the follower [m\/s^2]\r\n%\u00a0\u00a0 tau\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 - reaction time (typically ~1.0s) [s]\r\n\r\n% Calculate gap between vehicles<\/span>\r\ng = s_leader - s_follower - s0;\r\ng = max(g, double(0.1));\r\n\r\n<span style=\"color: #339966;\">% Calculate Gipps braking term<\/span>\r\nv_brake = b_max * tau + sqrt(b_max^2 * tau^2 - b_max * (2*g - v_leader * tau - (v_leader^2 \/ b_max)));<\/pre>\n<p>An <strong>acceleration (comfort) term<\/strong> models smooth acceleration toward the desired free-flow speed. In this ACC implementation, the safety-limited speed is used as an upper bound to avoid aggressive acceleration when following:<\/p>\n<pre><span style=\"color: #339966;\">% Input:<\/span>\r\n<span style=\"color: #339966;\">%\u00a0\u00a0 v_follower\u00a0 - current speed of the following vehicle [m\/s]<\/span>\r\n<span style=\"color: #339966;\">% Parameter:<\/span>\r\n<span style=\"color: #339966;\">%\u00a0\u00a0 a_max\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 - maximum acceleration of the follower [m\/s^2]<\/span>\r\n\r\n<span style=\"color: #339966;\">% Calculate Gipps acceleration term<\/span>\r\nv_accel = v_follower + 2.5 * a_max * tau * (1 - v_follower \/ v_brake) * sqrt(0.025 + v_follower \/ v_brake);<\/pre>\n<p>The commanded speed is chosen conservatively as:<\/p>\n<pre>v_safe = min(v_accel, v_brake);<\/pre>\n<p>This formulation yields smooth acceleration in free flow and safe gap regulation during car following.<\/p>\n<h1>Intersection Collision Avoidance System<\/h1>\n<p>Finally, intersection collision avoidance is essential for the actor behavior model. When traffic signal information is available at the intersection, collisions can often be prevented by implementing a traffic signal follower (see this <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2025b\/driving\/ug\/traffic-signal-follower-with-roadrunner-scenario.html\">reference example<\/a> for more details). However, a dedicated collision avoidance system is still necessary, as some vehicles may disregard the traffic signal.<\/p>\n<p>The intersection collision avoidance system consists of a series of computational blocks that assess collision risk at intersections.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"2230\" height=\"300\" class=\"aligncenter size-full wp-image-1534\" src=\"http:\/\/blogs.mathworks.com\/autonomous-systems\/files\/2026\/01\/image4-1.png\" alt=\"\" \/><\/p>\n<p>It begins by reading vehicle dynamics information \u2014 including speed and yaw rate \u2014 to calculate the predicted radius of curvature for each vehicle. By analyzing the magnitude and sign of this radius, the system estimates the vehicle\u2019s maneuver type, such as going straight, turning right, or turning left.<\/p>\n<p>Next, the system calculates intersection points (IPs) between the predicted paths of the ego vehicle and oncoming target vehicles, as illustrated in the figure below.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"2156\" height=\"1034\" class=\"aligncenter size-full wp-image-1535\" src=\"http:\/\/blogs.mathworks.com\/autonomous-systems\/files\/2026\/01\/image5-1.png\" alt=\"\" \/><\/p>\n<p>It then determines the travel distances (Dist2IP) and estimated arrival times (Time2IP) of both the ego and target vehicles at each intersection point. Based on these measurements, the system assesses collision risk using logic described in the following code snippet:<\/p>\n<pre><span style=\"color: #339966;\">% Assess Warning Level based on time to IP and time gap between ego and target<\/span>\r\n<span style=\"color: #0000ff;\">function<\/span> ICWLevel = assessWarningLevel(time_ego,time_target,timeGap,params)\r\n\r\n<span style=\"color: #339966;\">% Determine warning level<\/span>\r\n<span style=\"color: #0000ff;\">if<\/span> timeGap &lt; params.MinTimeGap <span style=\"color: #339966;\">% time gap between ego and target is within MinTimeGap<\/span>\r\n   <span style=\"color: #0000ff;\">if<\/span> time_ego &lt; params.WarnTTC &amp;&amp; time_target &lt; params.WarnTTC\r\n                                    <span style=\"color: #339966;\">% both ego and target times are less than WarnTTC<\/span>\r\n      <span style=\"color: #0000ff;\">if<\/span> time_target &lt; params.MinTTC ... <span style=\"color: #339966;\">% target time is less than MinTTC<\/span>\r\n             &amp;&amp; time_ego &lt; params.MinTTC <span style=\"color: #339966;\">% and ego time is less than MinTTC<\/span>\r\n         ICWLevel = 3; <span style=\"color: #339966;\">% high level warning<\/span>\r\n      <span style=\"color: #0000ff;\">elseif<\/span> time_target &lt; params.MinTTC <span style=\"color: #339966;\">% only target time is less than MinTTC<\/span>\r\n         ICWLevel = 2; <span style=\"color: #339966;\">% mid level warning<\/span>\r\n      <span style=\"color: #0000ff;\">else<\/span>\r\n         ICWLevel = 1; <span style=\"color: #339966;\">% low level warning<\/span>\r\n      <span style=\"color: #0000ff;\">end<\/span>\r\n   <span style=\"color: #0000ff;\">else<\/span> <span style=\"color: #339966;\">% eith ego or target times are greater than WarnTTC<\/span>\r\n      ICWLevel = 0; % no warning\r\n   <span style=\"color: #0000ff;\">end<\/span>\r\n<span style=\"color: #0000ff;\">else<\/span> <span style=\"color: #339966;\">% time gap between ego and target is too big<\/span>\r\n   ICWLevel = 0; <span style=\"color: #339966;\">% no warning<\/span>\r\n<span style=\"color: #0000ff;\">end<\/span>\r\n<span style=\"color: #0000ff;\">end<\/span><\/pre>\n<p>When the system assesses collision risk, it activates autonomous emergency braking (AEB) as needed to prevent collisions. The video below illustrates how the intersection collision avoidance system works.<\/p>\n<p><div style=\"width: 1464px;\" class=\"wp-video\"><!--[if lt IE 9]><script>document.createElement('video');<\/script><![endif]-->\n<video class=\"wp-video-shortcode\" id=\"video-1521-1\" width=\"1464\" height=\"718\" loop=\"1\" autoplay=\"1\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"http:\/\/blogs.mathworks.com\/autonomous-systems\/files\/2026\/01\/ICWsim.mp4?_=1\" \/><a href=\"http:\/\/blogs.mathworks.com\/autonomous-systems\/files\/2026\/01\/ICWsim.mp4\">http:\/\/blogs.mathworks.com\/autonomous-systems\/files\/2026\/01\/ICWsim.mp4<\/a><\/video><\/div><\/p>\n<p>For more information about the algorithm, please see the following references:<\/p>\n<p>[1]. Reference example: <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2025b\/driving\/ug\/intersection-collision-warning-using-v2x-communication.html\">Intersection Collision Warning Using V2X Communication<\/a><\/p>\n<p>[2]. Park Seo-Wook, Raynier Suresh, and Anusha Ailuri, &#8220;<a href=\"https:\/\/www.sae.org\/papers\/collision-avoidance-system-urban-intersections-using-v2x-communication-2025-01-8030\">Collision Avoidance System at Urban Intersections Using V2X Communication<\/a>,&#8221; SAE Technical Paper 2025-01-8030, 2025.<\/p>\n<h1>Trajectory Follower<\/h1>\n<p>When randomized ambient traffic is generated, each vehicle\u2019s initial position and route are defined randomly. The actor behavior model is then responsible for controlling the vehicle to follow its predefined route. At the start of the simulation, the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2025b\/driving\/ref\/roadrunnerscenarioreader.html#mw_3314090f-e6b2-491a-bef9-73747b0174be\">Path Following Action<\/a> from the RoadRunner Scenario Reader generates a sequence of waypoints that define the desired path.<\/p>\n<p>The\u00a0<strong>HelperPolylineEvaluator<\/strong>\u00a0is a MATLAB System Object that facilitates vehicle movement along this polyline path by interpolating between sequential waypoints.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"3252\" height=\"1131\" class=\"aligncenter size-full wp-image-1537\" src=\"http:\/\/blogs.mathworks.com\/autonomous-systems\/files\/2026\/01\/image6-1.png\" alt=\"\" \/><\/p>\n<p>At each time step, it calculates a target distance based on the vehicle\u2019s current speed and the simulation\u2019s sampling interval, then identifies the corresponding segment on the polyline. The vehicle\u2019s 3D position (X, Y, Z) and orientation (yaw) are determined through linear interpolation and tangent blending between waypoints, ensuring smooth and continuous transitions along the path. Additionally, the object tracks the cumulative distance traveled and provides a flag to indicate when the vehicle has reached the end of its route.<\/p>\n<p>You can find this trajectory follower block in the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2025b\/driving\/ug\/traffic-signal-follower-with-roadrunner-scenario.html\">reference example<\/a>.<\/p>\n<h1>Publishing Ready-to-Run Actor Behaviors<\/h1>\n<p>To assign the same Simulink actor behavior to multiple actors in RoadRunner, you can publish a ready-to-run package from your Simulink behavior model. This approach enables RoadRunner to execute the compiled behavior directly, without rebuilding the Simulink model at runtime, and allows the same package to be reused by many actors.<\/p>\n<p>Use the following command to generate the package:<\/p>\n<pre>Simulink.publish.publishActor(<span style=\"color: #ff00ff;\">'TrafficFollowerSL'<\/span>,PackageType=<span style=\"color: #ff00ff;\">'ReadyToRun'<\/span>)<\/pre>\n<p><strong><em>Note:<\/em><\/strong><em>\u00a0Generating ready-to-run native code requires Simulink Coder, and often Embedded Coder or a supported code generation target. Ensure that your MATLAB\/Simulink installation and license include the necessary products for C\/C++ code generation. Also, the generated binaries must be compatible with the RoadRunner runtime platform (e.g., OS and architecture).<\/em><\/p>\n<p>The above command generates a ZIP file containing precompiled native binaries (such as MEX, DLL, or SO files) and metadata required by RoadRunner. You can create a new behavior asset by assigning the generated ZIP file, and then apply this behavior to all ambient traffic actors.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-1538\" src=\"http:\/\/blogs.mathworks.com\/autonomous-systems\/files\/2026\/01\/image7-1.png\" alt=\"\" width=\"399\" height=\"152\" \/><\/p>\n<p>While Simulink co-simulation is preferable for high-fidelity algorithm development, detailed vehicle modeling, or when full access to the Simulink toolchain is needed at runtime, executing behaviors with the ready-to-run package significantly reduces per-step inter-process communication (IPC) and instantiation overhead. This results in lower latency and much better scalability, especially in scenarios with many actors.<\/p>\n<p>For more information about this workflow and additional resources, please see the following link:<\/p>\n<ul>\n<li><a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2025b\/driving\/ug\/Create-and-Publish-Ready-to-Run-Actor-Behaviors-to-Improve-Simulation-Performance.html\">Publish Ready-to-Run Actor Behaviors for Reuse and Simulation Performance<\/a><\/li>\n<\/ul>\n<h1>Conclusion<\/h1>\n<p>Transitioning the actor behavior model from a MATLAB-based framework into Simulink enables us to fully leverage the Model-Based Design (MBD) workflow. By integrating fundamental controllers, Trajectory Following, Adaptive Cruise Control, and Intersection Collision Avoidance, we have developed a robust &#8220;brain&#8221; for our ambient traffic actors. The ability to publish these behaviors as ready-to-run packages allows us to efficiently assign the same behavior to multiple actors, significantly improving latency and scalability in large-scale simulations.<\/p>\n<p>To request the Simulink model or receive technical support for the workflow described in this post, please contact MathWorks at\u00a0<a href=\"mailto:automated-driving@mathworks.com\">automated-driving@mathworks.com<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"http:\/\/blogs.mathworks.com\/autonomous-systems\/files\/2026\/01\/image1-1.png\" onError=\"this.style.display ='none';\" \/><\/div>\n<p>The previous post introduced a MATLAB-based traffic swarm framework capable of generating randomized ambient traffic with configurable safety and behavioral parameters. Realistic traffic scenarios&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/autonomous-systems\/2026\/01\/15\/scalable-actor-behavior-design-for-randomized-traffic-in-roadrunner\/\">read more >><\/a><\/p>\n","protected":false},"author":191,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[233,231,232],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/autonomous-systems\/wp-json\/wp\/v2\/posts\/1521"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/autonomous-systems\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/autonomous-systems\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/autonomous-systems\/wp-json\/wp\/v2\/users\/191"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/autonomous-systems\/wp-json\/wp\/v2\/comments?post=1521"}],"version-history":[{"count":25,"href":"https:\/\/blogs.mathworks.com\/autonomous-systems\/wp-json\/wp\/v2\/posts\/1521\/revisions"}],"predecessor-version":[{"id":1586,"href":"https:\/\/blogs.mathworks.com\/autonomous-systems\/wp-json\/wp\/v2\/posts\/1521\/revisions\/1586"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/autonomous-systems\/wp-json\/wp\/v2\/media?parent=1521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/autonomous-systems\/wp-json\/wp\/v2\/categories?post=1521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/autonomous-systems\/wp-json\/wp\/v2\/tags?post=1521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}