{"id":4829,"date":"2020-12-22T21:26:03","date_gmt":"2020-12-22T20:26:03","guid":{"rendered":"https:\/\/blogs.mathworks.com\/student-lounge\/?p=4829"},"modified":"2020-12-22T21:26:03","modified_gmt":"2020-12-22T20:26:03","slug":"using-physical-modeling-to-design-and-simulate-an-electric-vehicle","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/student-lounge\/2020\/12\/22\/using-physical-modeling-to-design-and-simulate-an-electric-vehicle\/","title":{"rendered":"Using Physical Modeling to Design and Simulate an Electric Vehicle"},"content":{"rendered":"<p>Today&#8217;s blog post is written by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/11341644\">Veer Alakshendra<\/a>, Education Technical Evangelist on the Student Competition team at MathWorks. In this blog he talks about\u00a0<span data-contrast=\"auto\">how to\u00a0<\/span><span data-contrast=\"auto\">model and simulate an electric vehicle\u00a0<\/span><span data-contrast=\"auto\">using MATLAB and Simulink.<\/span><\/p>\n<h2>Introduction<\/h2>\n<p><span data-contrast=\"auto\">Modeling is a way to create a virtual representation of a real-world system that includes software and hardware.\u00a0<\/span><span data-contrast=\"auto\">\u00a0<\/span><span data-contrast=\"auto\">It<\/span><span data-contrast=\"auto\">\u00a0is valuable for<\/span><span data-contrast=\"auto\">\u00a0<\/span><span data-contrast=\"auto\">formula student\u00a0<\/span><span data-contrast=\"auto\">testing conditions that might be difficult to reproduce with hardware prototypes alone, especially in the early phase of the design process when hardware may not be available.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">To model the electric vehicle, we will\u00a0<\/span><span data-contrast=\"auto\">use the physical modeling approach<\/span><span data-contrast=\"auto\">,<\/span><span data-contrast=\"auto\">\u00a0which\u00a0<\/span><span data-contrast=\"auto\">is a way\u00a0<\/span><span data-contrast=\"auto\">of modeling and simulating systems that consist of real physical components. It employs a physical network approach, where\u00a0<\/span><a href=\"https:\/\/www.mathworks.com\/products\/simscape.html\"><span data-contrast=\"none\">Simscape<\/span><\/a><span data-contrast=\"auto\">\u00a0blocks correspond to physical elements, such as\u00a0<\/span><span data-contrast=\"auto\">gears<\/span><span data-contrast=\"auto\">,\u00a0<\/span><span data-contrast=\"auto\">tires<\/span><span data-contrast=\"auto\">, and\u00a0<\/span><span data-contrast=\"auto\">motors<\/span><span data-contrast=\"auto\">.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-4849 size-full align=\" src=\"https:\/\/blogs.mathworks.com\/racing-lounge\/files\/2020\/12\/0_GIF.gif\" alt=\"\" width=\"1920\" height=\"1076\" \/><\/p>\n<h2>Battery Pack<\/h2>\n<p>The battery pack consists of various batteries connected in series. We have modeled each battery using an equivalent circuit, which is relatively a simple electrical circuit containing a voltage source and several resistors and capacitors.<\/p>\n<p><div id=\"attachment_4833\" style=\"width: 610px\" class=\"wp-caption aligncenter center center center\"><img aria-describedby=\"caption-attachment-4833\" decoding=\"async\" loading=\"lazy\" class=\"wp-image-4833\" src=\"https:\/\/blogs.mathworks.com\/racing-lounge\/files\/2020\/12\/Fig1.png\" alt=\"Cells in series\" width=\"600\" height=\"301\" \/><p id=\"caption-attachment-4833\" class=\"wp-caption-text\">Fig 1. Cells in series<\/p><\/div><\/p>\n<p><span data-contrast=\"auto\">Another\u00a0<\/span><span data-contrast=\"auto\">important step while modeling a battery is\u00a0<\/span><span data-contrast=\"auto\">choosing the appropriate parameters of the physical blocks\u00a0<\/span><span data-contrast=\"auto\">so that it<\/span><span data-contrast=\"auto\">\u00a0<\/span><span data-contrast=\"auto\">respond<\/span><span data-contrast=\"auto\">s<\/span><span data-contrast=\"auto\">\u00a0as similarly as possible as a physical battery cell<\/span><span data-contrast=\"auto\">.<\/span><span data-contrast=\"auto\">\u00a0<\/span><span data-contrast=\"auto\">One possible\u00a0<\/span><span data-contrast=\"auto\">way<\/span><span data-contrast=\"auto\">\u00a0to determine\u00a0<\/span><span data-contrast=\"auto\">these<\/span><span data-contrast=\"auto\">\u00a0<\/span><span data-contrast=\"auto\">parameters is\u00a0<\/span><span data-contrast=\"auto\">by\u00a0<\/span><span data-contrast=\"auto\">performing parameter estimation<\/span><span data-contrast=\"auto\">\u00a0where we\u00a0<\/span><span data-contrast=\"auto\">define the design<\/span><span data-contrast=\"auto\">\u00a0<\/span><span data-contrast=\"auto\">requirements, and cost function<\/span><span data-contrast=\"auto\">s<\/span><span data-contrast=\"auto\">\u00a0to\u00a0<\/span><span data-contrast=\"auto\">optimize the model parameters<\/span><span data-contrast=\"auto\">.<\/span><span data-contrast=\"auto\">\u00a0To know more\u00a0<\/span><span data-contrast=\"auto\">about<\/span><span data-contrast=\"auto\">\u00a0how\u00a0<\/span><span data-contrast=\"auto\">we have used this technique<\/span><span data-contrast=\"auto\">\u00a0<\/span><span data-contrast=\"auto\">to estimate the battery parameters,<\/span><span data-contrast=\"auto\">\u00a0please check out this\u00a0<\/span><span data-contrast=\"auto\">video titled, \u201c<\/span><a href=\"https:\/\/www.mathworks.com\/videos\/modeling-batteries-using-simulink-and-simscape-1562930245321.html\"><span data-contrast=\"none\">Modeling Batteries Using Simulink and Simscape.<\/span><\/a><span data-contrast=\"auto\">\u201d<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<h2 aria-level=\"2\"><span data-contrast=\"none\">Buck Converter<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:40,&quot;335559739&quot;:0,&quot;335559740&quot;:259}\">\u00a0<\/span><\/h2>\n<p><span data-contrast=\"auto\">To convert the\u00a0<\/span><span data-contrast=\"auto\">high\u00a0<\/span><span data-contrast=\"auto\">battery voltage to low voltage, we\u00a0<\/span><span data-contrast=\"auto\">have\u00a0<\/span><span data-contrast=\"auto\">used<\/span><span data-contrast=\"auto\">\u00a0a DC-DC converter, specifically, a buck converter.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">In\u00a0<\/span><span data-contrast=\"auto\">this case, we have used an\u00a0<\/span><a href=\"https:\/\/www.mathworks.com\/help\/physmod\/sps\/ref\/averagevaluedcdcconverter.html\"><span data-contrast=\"none\">Average-Value DC-DC Converter<\/span><\/a><span data-contrast=\"auto\">\u00a0block<\/span><span data-contrast=\"auto\">\u00a0<\/span><span data-contrast=\"auto\">that represents a<\/span><span data-contrast=\"auto\">\u00a0controlled average-value DC-DC converter.<\/span><\/p>\n<p><div id=\"attachment_4835\" style=\"width: 610px\" class=\"wp-caption aligncenter center center center\"><img aria-describedby=\"caption-attachment-4835\" decoding=\"async\" loading=\"lazy\" class=\"wp-image-4835\" src=\"https:\/\/blogs.mathworks.com\/racing-lounge\/files\/2020\/12\/Fig2.png\" alt=\"Buck Converter\" width=\"600\" height=\"299\" \/><p id=\"caption-attachment-4835\" class=\"wp-caption-text\">Fig 2. Buck converter<\/p><\/div><\/p>\n<h2>Motor and Controller<\/h2>\n<p>The battery powers a \u00a0BLDC motor and is modeled using the <a href=\"https:\/\/www.mathworks.com\/help\/physmod\/sps\/ref\/bldc.html\">BLDC<\/a> block available in <a href=\"https:\/\/www.mathworks.com\/products\/simscape-electrical.html\">Simscape Electrical<\/a>. We have used the datasheet to set the values of the block parameters under the stator, rotor, and mechanical tabs.<\/p>\n<p>To control the motor at different speeds, first, we sense the angular position using an <a href=\"https:\/\/www.mathworks.com\/help\/physmod\/simscape\/ref\/idealrotationalmotionsensor.html\">Ideal Rotational Motion Sensor<\/a> block. Further, the angular position information is used by the hall sensor to determine when the rotor transitions from one sector to another. Next, we have built a commutation logic to compute the switching pattern for the three-phase inverter.<\/p>\n<p><div id=\"attachment_4837\" style=\"width: 610px\" class=\"wp-caption aligncenter center center center\"><img aria-describedby=\"caption-attachment-4837\" decoding=\"async\" loading=\"lazy\" class=\"wp-image-4837\" src=\"https:\/\/blogs.mathworks.com\/racing-lounge\/files\/2020\/12\/Fig3.png\" alt=\"Motor &amp; Controller\" width=\"600\" height=\"365\" \/><p id=\"caption-attachment-4837\" class=\"wp-caption-text\">Fig 3. Motor and controller<\/p><\/div><\/p>\n<p>To learn how to design motor controllers using Simscape, refer to this <a href=\"https:\/\/www.mathworks.com\/videos\/how-to-design-motor-controllers-using-simscape-electrical-part-2-modeling-a-three-phase-inverter-1567758371716.html\">video<\/a>.<\/p>\n<h2>Transmission<\/h2>\n<p>The transmission consists of the following components:<\/p>\n<ul>\n<li>Actuator block: It converts the gear shift signal to clutch plate pressure and outputs the pressure required to engage the clutch.<\/li>\n<li><a title=\"https:\/\/www.mathworks.com\/help\/physmod\/sdl\/ref\/diskfrictionclutch.html (link no longer works)\">Disk friction clutch<\/a>: The block restricts the transmission of torque between the driving and driven shafts.<\/li>\n<li>Gears: The gear blocks are used to build a 3-speed transmission system. We have used <a href=\"https:\/\/www.mathworks.com\/help\/physmod\/sdl\/ug\/simple-gear.html\">Simple Gear<\/a> blocks with two different gear ratios to create high and low gears.<\/li>\n<\/ul>\n<p><div id=\"attachment_4839\" style=\"width: 510px\" class=\"wp-caption aligncenter center center center\"><img aria-describedby=\"caption-attachment-4839\" decoding=\"async\" loading=\"lazy\" class=\"wp-image-4839 size-full\" src=\"https:\/\/blogs.mathworks.com\/racing-lounge\/files\/2020\/12\/Fig4.png\" alt=\"Transmission\" width=\"500\" height=\"324\" \/><p id=\"caption-attachment-4839\" class=\"wp-caption-text\">Fig. 4. Transmission<\/p><\/div><\/p>\n<p>To learn more about powertrain modeling using the physical modeling approach, refer to this <a href=\"https:\/\/www.mathworks.com\/videos\/student-competition-physical-modeling-training-part-4-powertrain-modeling-107486.html\">tutorial video<\/a>.<\/p>\n<h2>Vehicle System<\/h2>\n<p>We have modeled the longitudinal vehicle dynamics using the physical blocks from <a href=\"https:\/\/www.mathworks.com\/products\/simscape-driveline.html\">Simscape Driveline<\/a> which consists of the following subsystems:<\/p>\n<ul>\n<li>Brake: The brake is applied at the rear and front wheels. It has been modeled using the <a href=\"https:\/\/www.mathworks.com\/help\/physmod\/sdl\/ref\/loadedcontactrotationalfriction.html#:~:text=Brakes\">Loaded-Contact Rotational Friction<\/a> block that transmits torque between two rotating surfaces.<\/li>\n<li>Vehicle: To model a two-axle vehicle body in longitudinal motion we have used the <a href=\"https:\/\/www.mathworks.com\/help\/physmod\/sdl\/ref\/vehiclebody.html\">Vehicle Body<\/a> block in conjunction with a set of Tire blocks.<\/li>\n<li>Sensor: The Ideal <a href=\"https:\/\/www.mathworks.com\/help\/physmod\/simscape\/ref\/idealtranslationalmotionsensor.html\">Translational Motion Sensor<\/a> block measures the vehicle velocity and the distance traveled.<\/li>\n<\/ul>\n<p><div id=\"attachment_4841\" style=\"width: 610px\" class=\"wp-caption aligncenter center center center\"><img aria-describedby=\"caption-attachment-4841\" decoding=\"async\" loading=\"lazy\" class=\"wp-image-4841\" src=\"https:\/\/blogs.mathworks.com\/racing-lounge\/files\/2020\/12\/Fig5.png\" alt=\"Vehicle System\" width=\"600\" height=\"416\" \/><p id=\"caption-attachment-4841\" class=\"wp-caption-text\">Fig. 5. Vehicle system<\/p><\/div><\/p>\n<h2>Closed Loop Vehicle Model<\/h2>\n<p>Finally, we connect all these subsystems through physical connections to build a closed-loop simulation model. Additionally, we have added a reference speed to be tracked and a PI controller to output the required duty cycle control signal.<\/p>\n<p><div id=\"attachment_4863\" style=\"width: 710px\" class=\"wp-caption aligncenter center center center\"><img aria-describedby=\"caption-attachment-4863\" decoding=\"async\" loading=\"lazy\" class=\"wp-image-4863\" src=\"https:\/\/blogs.mathworks.com\/racing-lounge\/files\/2020\/12\/Capture.png\" alt=\"\" width=\"700\" height=\"299\" \/><p id=\"caption-attachment-4863\" class=\"wp-caption-text\">Fig. 6. Closed loop vehicle model<\/p><\/div><\/p>\n<p>Once we run the simulation, it is evident that the controller can reach the reference velocity of 40 km\/h and drops down to zero after ~30 seconds. The sudden change in the vehicle speed accounts for the gear shift.<\/p>\n<p><div id=\"attachment_4843\" style=\"width: 510px\" class=\"wp-caption aligncenter center center center\"><img aria-describedby=\"caption-attachment-4843\" decoding=\"async\" loading=\"lazy\" class=\"wp-image-4843\" src=\"https:\/\/blogs.mathworks.com\/racing-lounge\/files\/2020\/12\/Fig7.png\" alt=\"Velocity and gear shift plot\" width=\"500\" height=\"367\" \/><p id=\"caption-attachment-4843\" class=\"wp-caption-text\">Fig. 7. Velocity and gear shift plot<\/p><\/div><\/p>\n<h2>Learning Resources<\/h2>\n<p>Now that you have gone through all the steps, we have followed to build the electric vehicle model, you must be wondering where you can learn more in detail. So, don\u2019t worry! We have a proper set of tutorials to guide you to build your vehicle model.<\/p>\n<ul>\n<li><a href=\"https:\/\/www.mathworks.com\/learn\/tutorials\/matlab-onramp.html\">MATLAB Onramp<\/a><\/li>\n<li><a href=\"https:\/\/www.mathworks.com\/learn\/tutorials\/simulink-onramp.html\">Simulink Onramp<\/a><\/li>\n<li><a href=\"https:\/\/www.mathworks.com\/academia\/student-competitions\/tutorials-videos.html\">Student Tutorials and Videos<\/a><\/li>\n<li><a href=\"https:\/\/www.mathworks.com\/videos\/series\/student-competition-physical-modeling-training-107490.html\">Physical Modeling Tutorial<\/a><\/li>\n<li><a href=\"https:\/\/www.mathworks.com\/videos\/series\/brushless-dc-motors.html\">Motor Control Series<\/a><\/li>\n<\/ul>\n<p><div id=\"attachment_4845\" style=\"width: 610px\" class=\"wp-caption aligncenter center center center\"><img aria-describedby=\"caption-attachment-4845\" decoding=\"async\" loading=\"lazy\" class=\"wp-image-4845\" src=\"https:\/\/blogs.mathworks.com\/racing-lounge\/files\/2020\/12\/Fig8-1024x514.png\" alt=\"Learning Resources\" width=\"600\" height=\"301\" \/><p id=\"caption-attachment-4845\" class=\"wp-caption-text\">Fig. 8. Learning resources<\/p><\/div><\/p>\n<h2>Contact<\/h2>\n<p>Please feel free to reach out to us at <a href=\"mailto:racinglounge@mathworks.com\">racinglounge@mathworks.com<\/a> in case of any queries. Also, join our MATLAB and Simulink Racing Lounge <a href=\"https:\/\/www.facebook.com\/groups\/racinglounge\/\">Facebook<\/a> group for the latest technical articles, videos, and upcoming live sessions.<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/student-lounge\/files\/2020\/12\/Capture.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div>\n<p>Today&#8217;s blog post is written by Veer Alakshendra, Education Technical Evangelist on the Student Competition team at MathWorks. In this blog he talks about\u00a0how to\u00a0model and simulate an electric&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/student-lounge\/2020\/12\/22\/using-physical-modeling-to-design-and-simulate-an-electric-vehicle\/\">read more >><\/a><\/p>\n","protected":false},"author":174,"featured_media":4863,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,9],"tags":[445,447,449,115,443,117,18],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/posts\/4829"}],"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\/174"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/comments?post=4829"}],"version-history":[{"count":36,"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/posts\/4829\/revisions"}],"predecessor-version":[{"id":4923,"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/posts\/4829\/revisions\/4923"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/media\/4863"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/media?parent=4829"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/categories?post=4829"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/tags?post=4829"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}