{"id":456,"date":"2018-02-28T03:48:35","date_gmt":"2018-02-28T03:48:35","guid":{"rendered":"https:\/\/blogs.mathworks.com\/student-lounge\/?p=456"},"modified":"2018-03-07T09:06:03","modified_gmt":"2018-03-07T09:06:03","slug":"vehicle-modeling-simscape-language","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/student-lounge\/2018\/02\/28\/vehicle-modeling-simscape-language\/","title":{"rendered":"Custom Vehicle Modeling using Simscape Language"},"content":{"rendered":"<p>Today, I am happy to introduce\u00a0<a href=\"https:\/\/www.linkedin.com\/in\/andrea-casadio-aa28a0b9\/\">Andrea Casadio<\/a>, he is a junior mechanical engineer and first-time guest in this blog. <!--introduction--> Andrea is going to describe his thesis work at\u00a0<a href=\"https:\/\/www.polito.it\/?lang=en\">Politecnico di Torino<\/a>\u00a0in which he developed Simscape\u2122 libraries for vehicle modeling. <!--\/introduction--><\/p>\n<p>Thank you Andrea for providing the community with your work on <strong><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/65156-vehicle-modeling-with-simscape\">MATLAB Central FileExchange<\/a><\/strong>.<\/p>\n<p>&#8211; &#8211;<\/p>\n<p>When I studied vehicle dynamics at university, I spent a lot of time modeling in Simulink<sup>\u00ae<\/sup>. What I did in fact was creating models based on fundamental equations trying to mimic actual systems. This approach became increasingly\u00a0time consuming when I used more advanced system modeling approaches. Ultimately, I spent more time building vehicle models instead of developing and optimizing simulations.<\/p>\n<p>At this point, I discovered Simscape. Simscape allows me to speed-up creating models of physical systems within the Simulink\u00a0environment. Simscape blocks typically provide the functionality of a system of Simulink blocks within a single block.<\/p>\n<p>Anyway, describing pros and cons of Simscape is not the scope of this post. So, let\u2019s go with the work illustration!<\/p>\n<p>At the beginning of my project, I discovered that default\u00a0blocks of the Simscape Driveline library allow the simulation of longitudinal behavior only. The reason is that the tire blocks provided are based on mathematical models that take into account the longitudinal forces exchanged between tire and road. As expected, MathWorks offers functionality that allows to <a href=\"https:\/\/www.mathworks.com\/help\/physmod\/simscape\/lang\/creating-custom-components.html\">create custom components<\/a>\u00a0using the Simscape language<strong>.<\/strong><\/p>\n<p>For the reason above, the first target was to develop customized tire blocks based on more involved mathematical models like Pacejka \u201989 and \u201996, taking into account also the combination between lateral and longitudinal forces.<\/p>\n<p><a href=\"https:\/\/blogs.mathworks.com\/racing-lounge\/files\/2017\/11\/customized_tire_block.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-464 size-full\" src=\"https:\/\/blogs.mathworks.com\/racing-lounge\/files\/2017\/11\/customized_tire_block-e1511266130929.jpg\" width=\"199\" height=\"123\" \/><\/a><\/p>\n<p style=\"text-align: center;\">Fig. 1 &#8211;\u00a0Example of a customized tire block<\/p>\n<p>Lateral and longitudinal forces are functions of lateral and longitudinal tire slip, which depend on translational and rotational speed of the wheel. To develop such kinds of blocks it was necessary to use Simscape language to define:<\/p>\n<ul>\n<li>Conserving ports to transfer speed and force information;<\/li>\n<li>Declaration of domains, variables, parameters and equations.<\/li>\n<\/ul>\n<p>Conserving ports are the interface with other Simscape components, on the example shown above there are &#8220;HX&#8221; and &#8220;HY&#8221; being the conserving ports defined on the mechanical translational domain. There is also &#8220;A&#8221; which is the conserving port defined on the mechanical rotational domain.<\/p>\n<p>To validate the tire model, it was necessary to apply longitudinal and lateral motion to the tire model and it was possible to obtain the plots shown in Fig.2 and Fig.3.<\/p>\n<p><a href=\"https:\/\/blogs.mathworks.com\/racing-lounge\/files\/2018\/02\/Img2.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-994 size-full\" src=\"https:\/\/blogs.mathworks.com\/racing-lounge\/files\/2018\/02\/Img2.jpg\" width=\"560\" height=\"420\" \/><\/a><\/p>\n<p style=\"text-align: center;\">Fig.2 \u2013 Lateral force as a function of lateral slip at a different vertical loads \u2013 Pacejka \u201989 model<\/p>\n<p>Fig.2 displays the typical behavior of a tire when the longitudinal slip is zero (no braking or acceleration). The odd trend is a consequence of the Pacejka model. If you look at the block on Fig.1, there is no option to introduce a vertical load variable, this is introduced as a block parameter.<\/p>\n<p><a href=\"https:\/\/blogs.mathworks.com\/racing-lounge\/files\/2018\/02\/Img3.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-996 size-full\" src=\"https:\/\/blogs.mathworks.com\/racing-lounge\/files\/2018\/02\/Img3.jpg\" width=\"560\" height=\"420\" \/><\/a><\/p>\n<p style=\"text-align: center;\">Fig.3 &#8211; Lateral force as a function of longitudinal force at a different lateral slip angles \u2013 Pacejka \u201989 model<\/p>\n<p>Applying different inputs to the block of Fig.1 it\u2019s possible to obtain the graph on Fig.3, which displays how the lateral force between road and tire changes as a function of the longitudinal force for different lateral slip conditions (alpha). When the longitudinal force is zero, the lateral force is maximal. This is straightforward because tires&#8217; grip on the corners is higher when the driver doesn\u2019t apply brakes or throttle. The opposite condition is when the longitudinal force is maximal. In this case, the lateral force is zero. Even by common sense,\u00a0 you may agree that it is not a good idea to apply too much brakes or throttle on corners.<\/p>\n<p>As done for tires, starting from a 3 degree of freedom (DOF) model of a vehicle, it was possible to develop a block describing vehicle body dynamics:<\/p>\n<p><a href=\"https:\/\/blogs.mathworks.com\/racing-lounge\/files\/2018\/02\/Img4.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-998 size-full\" src=\"https:\/\/blogs.mathworks.com\/racing-lounge\/files\/2018\/02\/Img4.jpg\" width=\"407\" height=\"194\" \/><\/a><\/p>\n<p style=\"text-align: center;\">Fig.4 \u2013 3 DOF Vehicle model<\/p>\n<p>Here is a short description of the 3 DOF Vehicle model (Fig. 4):<\/p>\n<ul>\n<li>HXFR, HXFL, HXRR, HXRL are conserving ports defined on the mechanical translational domain. With these four connections it is possible to connect the vehicle body to other blocks (like tires), but only in the\u00a0<strong><u>longitudinal direction<\/u><\/strong>. There\u00a0is one port for every tire (FR means front right, RL means rear left, etc.)<\/li>\n<li>HYFR, HYFL, HYRR, HYRL are conserving ports defined on the mechanical translational domain. With these connections it is possible to connect the vehicle body to other blocks (like tires) in\u00a0<strong><u>lateral direction<\/u><\/strong><\/li>\n<li>NFR, NFL, NRR, NRL are the physical signal outputs representing the vertical loads. These ports are useful to make the block connectable with the one shown\u00a0in Fig.1. In fact, the 3-DOF model doesn\u2019t takes into account the load transfer during longitudinal or side acceleration. In this case, it\u2019s considered being a constant value, depending on the load distribution of the vehicle on static condition without any kind of slope. ST is the physical input representing the steering angle<\/li>\n<li>PX, PT and YAW are three outputs\u00a0representing\u00a0the position along x, y and yaw. Yaw is the angle of rotation of the vehicle with respect to its vertical axis\u00a0 through the center of gravity (COG).<\/li>\n<\/ul>\n<p><a href=\"https:\/\/blogs.mathworks.com\/racing-lounge\/files\/2018\/02\/Img5-1.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-1016 size-large\" src=\"https:\/\/blogs.mathworks.com\/racing-lounge\/files\/2018\/02\/Img5-1-1024x529.jpg\" width=\"1024\" height=\"529\" \/><\/a><\/p>\n<p style=\"text-align: center;\">[Click on image to enlarge]<\/p>\n<p style=\"text-align: center;\">Fig.5 \u2013 A complete 3-DOF project \u2013 4WD model with 3 differential<\/p>\n<p>Systems like the one in Fig.5 allow to model vehicle behavior with:<\/p>\n<ul>\n<li>Input: steering wheel angle (ST);<\/li>\n<li>Output: coordinate of center of mass and yaw angle (PX, PY YAW).<\/li>\n<\/ul>\n<p>To validate these blocks, four different configurations of a 4WD car with three differentials were defined, see Fig.6:<\/p>\n<ol>\n<li>All differentials opened<\/li>\n<li>Central differential locked<\/li>\n<li>Central and rear differential locked<\/li>\n<li>All differentials locked<\/li>\n<\/ol>\n<p><a href=\"https:\/\/blogs.mathworks.com\/racing-lounge\/files\/2018\/02\/Img6.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-1004 size-full\" src=\"https:\/\/blogs.mathworks.com\/racing-lounge\/files\/2018\/02\/Img6-e1519123819567.jpg\" width=\"480\" height=\"172\" \/><\/a><\/p>\n<p style=\"text-align: center;\">Fig.6 \u2013 The four different configurations used to simulate the 3-DOF model<\/p>\n<p>Saving on MATLAB workspace the center off mass coordinates, during the simulation, it was possible to plot the trajectory of the vehicle center of mass (see Fig.7). This plot shows, as expected, an increasing of under-steering behavior while the differentials have been locked.<\/p>\n<p><a href=\"https:\/\/blogs.mathworks.com\/racing-lounge\/files\/2018\/02\/Img8.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-1006 size-full\" src=\"https:\/\/blogs.mathworks.com\/racing-lounge\/files\/2018\/02\/Img8.jpg\" width=\"518\" height=\"419\" \/><\/a><\/p>\n<p style=\"text-align: center;\">Fig.7 \u2013 Vehicle trajectories at different working conditions<\/p>\n<p>Modeling vehicles with the previous defined customized blocks offers, in comparison with Simulink models, a cleaner representation of the system. However, it was not straightforward to define the vehicle dynamics block based on the equations of the physical system. No worries, as Christoph pointed out, I shared the material with you on\u00a0<a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/65156-vehicle-modeling-with-simscape\">MATLAB Central FileExchange<\/a>.<\/p>\n<p>Another alternative is using MathWorks&#8217; multi-body simulation tool called Simscape Multibody\u2122. Models look like the one shown on Fig.8 with its graphical representation in Fig.9.<\/p>\n<p><a href=\"https:\/\/blogs.mathworks.com\/racing-lounge\/files\/2018\/02\/Img9-1.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-1018 size-large\" src=\"https:\/\/blogs.mathworks.com\/racing-lounge\/files\/2018\/02\/Img9-1-1024x295.jpg\" width=\"1024\" height=\"295\" \/><\/a><\/p>\n<p style=\"text-align: center;\">[Click on image to enlarge]<\/p>\n<p style=\"text-align: center;\">Fig. 8 \u2013 A 6-DOF Vehicle model built with Simscape Multibody<\/p>\n<p><a href=\"https:\/\/blogs.mathworks.com\/racing-lounge\/files\/2018\/02\/Model.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-1010 size-full\" src=\"https:\/\/blogs.mathworks.com\/racing-lounge\/files\/2018\/02\/Model-e1519123979715.jpg\" width=\"480\" height=\"314\" \/><\/a><\/p>\n<p style=\"text-align: center;\">Fig.9 \u2013 A representation of the 6-DOF vehicle model<\/p>\n<p>At the end, admittedly, it is hard to give compact advice on whether to use Simscape or Simscape Multibody. In very brief, Simscape Multibody will provide a graphic representation of your model automatically as you build\u00a0the model. It will also allow you to model contact &#8211; find here a detailed <a href=\"https:\/\/blogs.mathworks.com\/racing-lounge\/2017\/09\/12\/introduction-to-contact-modeling\/\">introduction to contact modeling<\/a>. In contrast to Simscape, these additional features will require more CPU time for solving system equations.<\/p>\n<p>Let me refer you to a previous <a href=\"https:\/\/blogs.mathworks.com\/racing-lounge\/2017\/10\/20\/advantages-of-vehicle-modeling\/\">article in the racing lounge focusing on vehicle modeling<\/a>. Especially, the modeling approach using Simscape Multibody will\u00a0thoroughly discuss the pros and cons of Simscape Multibody. And even better, all models are provided on the <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/64648-matlab-and-simulink-racing-lounge--vehicle-modeling-with-simscape-multibody\">MATLAB Central FileExchange<\/a>.<\/p>\n<p>If there is one key takeaway of my work, it is this:\u00a0There are many\u00a0opportunities to simulate vehicle models and investigate the influence of different suspension parameters. No matter whether you are working in Simulink, Simscape or Simscape Multibody, parameters can always be modified\u00a0via the MATLAB workspace.<\/p>\n<p>This work was an interesting opportunity to see the great potential of MATLAB when it comes to vehicle modeling. For sure, there are a lot of future possible implementations, for example the development of further tire models to consider the load transfer or the variation of characteristics wheel angles during the suspension travel. I would love to hear your feedback about my work.<\/p>\n<p>Thank you MathWorks for the opportunity to publish in the racing lounge blog!<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/student-lounge\/files\/2018\/02\/Img4.jpg\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div>\n<p>Today, I am happy to introduce\u00a0Andrea Casadio, he is a junior mechanical engineer and first-time guest in this blog.  Andrea is going to describe his thesis work at\u00a0Politecnico di Torino\u00a0in which he&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/student-lounge\/2018\/02\/28\/vehicle-modeling-simscape-language\/\">read more >><\/a><\/p>\n","protected":false},"author":151,"featured_media":998,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,9,8,10,12],"tags":[38,36,32,34],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/posts\/456"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/users\/151"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/comments?post=456"}],"version-history":[{"count":29,"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/posts\/456\/revisions"}],"predecessor-version":[{"id":1046,"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/posts\/456\/revisions\/1046"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/media\/998"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/media?parent=456"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/categories?post=456"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/tags?post=456"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}