{"id":18740,"date":"2025-10-15T10:34:59","date_gmt":"2025-10-15T14:34:59","guid":{"rendered":"https:\/\/blogs.mathworks.com\/deep-learning\/?p=18740"},"modified":"2025-10-15T10:42:27","modified_gmt":"2025-10-15T14:42:27","slug":"matlab-on-github-codespaces-collaborate-on-ai-motor-control-between-matlab-and-simulink-users","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/deep-learning\/2025\/10\/15\/matlab-on-github-codespaces-collaborate-on-ai-motor-control-between-matlab-and-simulink-users\/","title":{"rendered":"MATLAB on GitHub Codespaces: Collaborate on AI Motor Control between MATLAB and Simulink users"},"content":{"rendered":"I am a MATLAB user. Even though I am familiar with the idea of Control Systems, I do need some help from my colleagues to work on projects that involve embedding AI into hardware. This example from the documentation about Motor Control is a perfect illustration: <a href=\"https:\/\/www.mathworks.com\/help\/mcb\/gs\/foc-pmsm-using-position-estimated-by-neural-network.html\">Field-Oriented Control of PMSM Using Position Estimated by Neural Network<\/a>.\r\n<h6><\/h6>\r\nAnother way to frame it is replacing physical sensors to measure the position of the rotor of an electric motor, by a virtual sensor for both cost and practicality reasons.\r\n<h6><\/h6>\r\nHere is the workflow we will follow in this post. The blue parts are the ones that my Simulink colleague will take care of. And I will:\r\n<ul>\r\n \t<li>Identify the appropriate neural network architecture<\/li>\r\n \t<li>Train the neural network<\/li>\r\n \t<li>(Push back my changes in the repository for my colleague to integrate into the simulation)<\/li>\r\n<\/ul>\r\n<h6><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-18743\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/10\/ai-motor-control-workflow.png\" alt=\"\" width=\"800\" height=\"331\" \/>\r\n<h6><\/h6>\r\n&nbsp;\r\n<h2>Spin up a Codespace with MATLAB<\/h2>\r\n<h6><\/h6>\r\nIn order to work on this demo with my colleague, I will leverage a feature from GitHub called Codespaces.\r\nGitHub Codespaces\u00ae are cloud-based development environments hosted by GitHub that allow users to quickly set up and work on code directly from their browsers or through Visual Studio Code. Each codespace is a containerized environment that can be pre-configured with the necessary tools, dependencies, and extensions specified by the repository, making it easier to start coding without worrying about local setup or compatibility issues. This approach streamlines collaboration and enables teams to develop, test, and share code more efficiently, regardless of their local operating system.\r\n<h6><\/h6>\r\nThere are a few options to run MATLAB on a Codespace. Those options are listed in a MathWorks repository as part of the reference architectures for using MATLAB in the Cloud: <a href=\"https:\/\/github.com\/mathworks-ref-arch\/matlab-codespaces\">https:\/\/github.com\/mathworks-ref-arch\/matlab-codespaces<\/a>.\r\n<h6><\/h6>\r\nThis repository is actually a <strong>Public template<\/strong>, so you will see a green button on the top right offering to use it as a template to derive your own repo.\r\n<h6><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-18746\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/10\/matlab-codespace-repo-banner.png\" alt=\"\" width=\"800\" height=\"108\" \/>\r\n<h6><\/h6>\r\n&nbsp;\r\n\r\nIn the section <strong>choose configuration<\/strong>, there are three options:\r\n<ol>\r\n \t<li><em>Use MATLAB only<\/em>. This isn\u2019t fitting my needs, as this example requires Simulink, Motor Control Blockset &amp; Deep Learning Toolbox.<\/li>\r\n \t<li><em>Customize MATLAB installation with specific toolboxes or other software, using a <\/em><a href=\"https:\/\/github.com\/mathworks-ref-arch\/matlab-dockerfile\"><em>Dockerfile<\/em><\/a>. This is the most flexible option, but since I don\u2019t need third party software, I\u2019ll keep this option for some other time. (If you don\u2019t know what Docker is, this isn\u2019t the option you\u2019re searching for.)<\/li>\r\n \t<li><strong>Add MATLAB to a <\/strong><a href=\"https:\/\/github.com\/mathworks-ref-arch\/matlab-codespaces\/blob\/main\/.devcontainer\/using-devcontainer-feature\/devcontainer.json\"><strong>json<\/strong><\/a><strong> configuration.<\/strong><\/li>\r\n<\/ol>\r\n<h6><\/h6>\r\nSorry for burying the lede. The third option is the configuration that I recommend in most cases (unless you just need MATLAB). The devcontainer feature can be more approachable without Docker knowledge.\r\n<h6><\/h6>\r\nTo create your own Codespace inside of one of your repos, all you need is to paste the <strong>devcontainer.json<\/strong> configuration file into a folder called <strong>.devcontainer\/<\/strong> at the root of the repo.\r\n<h6><\/h6>\r\nHere is mine: <a href=\"https:\/\/github.com\/yanndebray\/AI-Motor-Control\">https:\/\/github.com\/yanndebray\/AI-Motor-Control<\/a>.\r\n<h6><\/h6>\r\nOnce you have added the configuration file to your repo, you can spin up a Codespace from the green <strong>&lt;&gt; Code<\/strong> button on the top right. You might remember that this button was only able to provide the option to clone the code locally. But now, you have the ability to test the code on a remote cloud environment before considering cloning to your local machine.\r\n<h6><\/h6>\r\nBy creating a Codespace on the main branch of the repo, you will spin up an ephemeral development environment that you can play around with and throw away once you are done. Perfect to quickly test the code that a colleague shares with you. The following 1 min video shows what you will experience the first time that you create the Codespace (pre-built Codespaces provide near instant access to the dev environment).\r\n<h6><\/h6>\r\n<div class=\"row\"><div class=\"col-xs-12 containing-block\"><div class=\"bc-outer-container add_margin_20\"><videoplayer><div class=\"video-js-container\"><video data-video-id=\"6382798936112\" data-video-category=\"blog\" data-autostart=\"false\" data-account=\"62009828001\" data-omniture-account=\"mathwgbl\" data-player=\"rJ9XCz2Sx\" data-embed=\"default\" id=\"mathworks-brightcove-player\" class=\"video-js\" controls><\/video><script src=\"\/\/players.brightcove.net\/62009828001\/rJ9XCz2Sx_default\/index.min.js\"><\/script><script>if (typeof(playerLoaded) === 'undefined') {var playerLoaded = false;}(function isVideojsDefined() {if (typeof(videojs) !== 'undefined') {videojs(\"mathworks-brightcove-player\").on('loadedmetadata', function() {playerLoaded = true;});} else {setTimeout(isVideojsDefined, 10);}})();<\/script><\/div><\/videoplayer><\/div><\/div><\/div>\r\n<h6><\/h6>\r\n<h2>Run MATLAB and Simulink in the Codespace<\/h2>\r\nOnce your Codespace is ready, it will prompt you to enter your MATLAB license (via your MathWorks account email + password). Then, you should see something like this when starting your Codespace:\r\n\r\n(If not look at the <strong>gotcha section<\/strong>)\r\n<h6><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-18761\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/10\/start-codespace.png\" alt=\"\" width=\"800\" height=\"420\" \/>\r\n<h6><\/h6>\r\nYou can open the MATLAB development environment in a separate window or tab (or simply use MATLAB in VSCode if you feel comfortable in this development environment).\r\n<h6><\/h6>\r\nI ran the live script FOCPMSMUsingPosEstByNeuralNtwExample.m (yes live scripts can now be stored as .m plain text files for versioning). It performs a sweep operation over a large range of speed-torque operating points for the motor, in order to generate the dataset to train the neural network.\r\n<h6><\/h6>\r\nThe simulations take about 3 hours in total. So you need to update the <a href=\"https:\/\/docs.github.com\/en\/codespaces\/setting-your-user-preferences\/setting-your-timeout-period-for-github-codespaces\">default idle timeout<\/a> of your codespace in the settings: <a href=\"https:\/\/github.com\/settings\/codespaces\">https:\/\/github.com\/settings\/codespaces<\/a>.\r\n<h6><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-18755\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/10\/codespace-idle-timeout.png\" alt=\"\" width=\"800\" height=\"438\" \/>\r\n<h6><\/h6>\r\nThe benefit of running the simulation on a Codespace is that I can let it run in the background and continue working on my local machine without heating up and taking all my RAM and CPU.\r\n<h6><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-18788\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/10\/codespace-simulink.png\" alt=\"\" width=\"800\" height=\"420\" \/>\r\n<h6><\/h6>\r\nAfter scripting the simulation, generating 350MB of data, I\u2019m extracting the right inputs and outputs to train the neural network.\r\n<h6><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-18785\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/10\/codespace-deep-learning.png\" alt=\"\" width=\"800\" height=\"420\" \/>\r\n<h6><\/h6>\r\nI do not need a GPU for 50 epochs on a fairly shallow neural network, that can capture the non-linearities of the dynamic system. In fact, it only takes 1 min and a half to complete the training.\r\n<h6><\/h6>\r\n<h2>Collaborating on Codespaces<\/h2>\r\nNow that I have the AI model trained, I can ask my colleague to join my GitHub repo, and task him to integrate the neural network as a virtual sensor estimating the position of the rotor in real time, and pick up the deployment workflow from there, with rigorous testing.\r\n<h6><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-18782\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/10\/github-add-collaborator.png\" alt=\"\" width=\"800\" height=\"437\" \/>\r\n<h6><\/h6>\r\nThis workflow is convenient for me because it leverages the project management tools I am familiar with, like <strong>GitHub issues<\/strong>. If something is broken, I can simply create an issue and assign it to the person that needs to fix it (either my colleague, or future me, potentially with a little help from my friend Copilot).\r\n<h6><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-18779\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/10\/github-issue.png\" alt=\"\" width=\"800\" height=\"434\" \/>\r\n<h6><\/h6>\r\nAnd this is the end of the workflow for my part. This showed you how using cloud development environments revolving around your source code repository can facilitate the development process between different experts in a large project, like integrating AI in embedded systems. Don\u2019t hesitate to add a star to my repo if you find this useful.\r\n<h6><\/h6>\r\n<h2>Gotchas<\/h2>\r\nOne thing you will probably want to pay attention to when you add toolboxes to the devcontainer configuration is that you could reach the limit of the disk size of the virtual machine used to install all the products.\r\n<h6><\/h6>\r\nYou will see something like this in the <strong>creation.log<\/strong>\r\n<h6><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" width=\"1696\" height=\"382\" class=\"aligncenter size-full wp-image-18776\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/10\/codespace-creation-log.png\" alt=\"\" \/>\r\n<h6><\/h6>\r\nOne option would be that you change the machine type, to rent a bigger one. You might need to have a credit card on file for that, as machines over 4-cores are not part of the free tier of GitHub Codespaces.\r\n<h6><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-18773\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/10\/your-codespaces.png\" alt=\"\" width=\"800\" height=\"301\" \/><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-18770\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/10\/codespace-machine-size.png\" alt=\"\" width=\"800\" height=\"184\" \/>\r\n<h6><\/h6>\r\nYou can retrieve the github CLI to manage codespaces programmatically.\r\n<h6><\/h6>\r\n<pre>sudo apt update &amp;&amp; sudo apt install gh -y<\/pre>\r\n<h6><\/h6>\r\nFor instance one command enables you to check the timeout:\r\n<h6><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-18767\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/10\/codespace-list-view-timeout.png\" alt=\"\" width=\"800\" height=\"103\" \/>\r\n<h6><\/h6>\r\nPlease leave a comment if you find other gotchas. Happy coding.","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/10\/ai-motor-control-workflow.png\" onError=\"this.style.display ='none';\" \/><\/div><p>I am a MATLAB user. Even though I am familiar with the idea of Control Systems, I do need some help from my colleagues to work on projects that involve embedding AI into hardware. This example from... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/deep-learning\/2025\/10\/15\/matlab-on-github-codespaces-collaborate-on-ai-motor-control-between-matlab-and-simulink-users\/\">read more >><\/a><\/p>","protected":false},"author":230,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[71],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/posts\/18740"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/users\/230"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/comments?post=18740"}],"version-history":[{"count":8,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/posts\/18740\/revisions"}],"predecessor-version":[{"id":19006,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/posts\/18740\/revisions\/19006"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/media?parent=18740"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/categories?post=18740"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/tags?post=18740"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}