Environment Setup

The main tool for building, testing and deploying software is CMake. It is widely accepted and supported by many IDEs, which means that the user is free to choose from various development environments.

To make things more convenient, there are Motorcortex plugins for CLion ( https://www.jetbrains.com/clion ). CLion is an advanced IDE with many tools that make programming a Motorcortex application easier. This IDE is available across platforms and is capable of cross-compiling and deploying Motorcortex applications to the target controller with a click of a button. This guide will show you how to install CLion, Motorcortex plugins from the CLion Marketplace and get started with developing Motorcortex applications.


Installing Motorcortex Template Plugin

After installing CLion the first step is to install the Motorcortex Templates plugin. This plugin will provide you the option to create a new Motorcortex project.

  1. In the Main Menu on the top left corner open: File → Settings, then find the Plugins menu.

  2. In the plugins menu search for Motorcortex.

  3. Install the Motorcortex Templates plugin and press restart IDE -> press Restart. After that you can create new Motorcortex projects in the main menu.

    image not found
  4. In the Main Menu open: File → New > Project..., in the pop-up under C++ choose C++ Motorcortex select the location where you want to save your project (../mcx-example) and press Create.

    image not found

Set-up Remote Development

Remote development is used to develop your motorcortex application direct on your motorcortex target system.

  1. In the Main Menu open File → Settings under Build, Execution, Deployment you will find the Toolchains menu.

  2. Add a new toolchain by pressing the button and select Remote Host.

    image not found
  3. In the Credentials: press the button to enter the SSH Configurations menu. Add a new configuration by pressing the button and fill in the following data:

    • Host: 192.168.2.100
    • Port: 22
    • User name: admin
    • Password: vectioneer
  4. Press the Test Connection button to make sure your connection is OK. If not, re-check your controller connection.

  5. If the connection is good you can press OK to close the SSH Configurations menu.

  6. Wait for Cmake and the C/C++ Compiler to be detected:

    • CMake: Remote host CMake
    • Build Tool: Default, Detected: make
    • C Compiler: Default, Detected: cc
    • C++ Compiler: Default, Detected: c++
    • Debugger:Remote Host GDB

    Press the Apply button to save the Toolchain settings.

  7. Under Build, Execution, Deployment open the Cmake menu, set ToolChain, to Remote Host with dropdown function. Set other parameters to (default):

    • Build type: Debug
    • Generator: Use default Unix Makefiles
    • Cmake options: -G "CodeBlocks - Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug
    • Build directory: cmake-build-debug-remote-host
    • Build options: -- -j 9
    image not found
  8. Press the OK button to save the CMake settings and close the Settings window.

  9. Wait for a couple of seconds while remote and local systems are synchronized.

  10. Make sure that your controller is not running a Motorcortex application. Open the Terminal in CLion and run the following command:

ssh admin@192.168.2.100 'echo vectioneer | sudo -S motorcortex stop'
  1. In CLion set your Run/Debug Configuration to Debug-Remote Host.

    image not found
  2. Press play to build and run the application.

  3. To compile code with the latest modifications press Rebuild Project.

    image not found
  4. Congratulations you are now ready to start remote developing your Motorcortex application.

Set-up Cross Compilation

Cross compilation is used to develop motorcortex application on your pc and deploy it to motorcortex target system.


  1. For Cross compilation you will need a Motorcortex SDK. You can download the SDK (Software Development Kit) from the motorcortex.io store

  2. Extract the archive and place the .sh file in a folder of your preference.

  3. In the terminal browse to the folder and run the .sh file from the terminal, for example:

    sh ./motorcortex-glibc-x86_64-motorcorcortex-image-dev-corei7-64-toolchain-X.X.X.sh
    
  4. You will be asked to enter the target directory where to install the SDK to. It is a good idea to keep the SDK in the home folder, where administrative rights are not required for example: ~/mcx-sdk.

    image not found
  5. Mounting Sysroot on your system.

    Generate a new key pair with the following command.

    ssh-keygen -t rsa
    
    image not found

    Use ssh-copy-id to install an SSH key on the remote Motorcortex host as an authorized key. Its purpose is to provision access without requiring a password for each login. To copy the SSH key you need to enter the password only once. Default password is vectioneer.

    ssh-copy-id admin@192.168.2.100
    

    Create a folder to mount the remote Motorcortex file system on with the following command.

    mkdir ~/mcx-sysroot
    

    Mount the Motorcortex file system with the following command.

    sshfs admin@192.168.2.100:/ ~/mcx-sysroot/
    
  6. Configure toolchain in CLion:

    • Open FileSettingsBuild Execution DeploymentToolchains.
    • Press to add System toolchain and name it motorcortex.
    • Open Add environment From file.
    • Select environment file of the Motorcortex SDK → press OK.
    image not found

    CLion will fill all the required paths automatically as shown in the image above:

    • Cmake: Bundled
    • Build Tool: Detected: ninja
    • C Compiler: Detected x86_64-mcx-linux-gcc
    • C++ Compiler: Detected x86_640mcx-linux-g++
    • Debugger: Bundled GDB

    Press Apply to save the changes.

  7. Install Motorcortex Toolchain plugin and press restart IDE → press Restart.

    image not found
  8. Open FileSettingsBuild, Execution, DeploymentMotorcortex SDK and fill in the Sysroot path: with the mounted folder: mcx-sysroot.

    image not found
  9. Add the connection to the remote Motorcortex host.

    • Open ToolsDeploymentConfiguration...
    • Select Remote Development, press to add a new SFTP connection and name it mcx-host.
    • Setup SSH connection → press → select admin@192.168.2.100:22.
    • Press Autodetect to set the root path.
    • Press OK
    image not found
  10. In CLion open Run/Debug Configuration, press to add Motorcortex Remote Application:

    • Fill in Name: of the configuration: cross_mcx-example.
    • Fill Program arguments with default path to the active configuration: -c /etc/motorcortex/config/config.json.
    • Select Deployment profile: mcx-host.
    • Press OK
    image not found
  11. Each time a Motorcortex Remote Application is made, inside FileSettingsBuild Execution DeploymentCMake, two profiles are added: CrossDebug and CrossRelease. It can happen that you accidentally delete one of these profiles, If this happens you can manually add a profile by means of pressing and fill in either CrossDebug or CrossRelease.


    
image not found

    
image not found
  1. To install configuration to the controller press Build → Install.

    image not found
  2. To run a project on the controller press Run icon.

    image not found
  3. To debug the project select CrossDebug configuration and press Debug.

    image not found

image not found

image not found

Set-up Remote Development:

After installing Visual Studio Code the first step is to install the Remote Development extension:

  • Remote Development, allows you to use a remote machine as full-feautured development environment.

Inside the primary side bar per default on the left side of your main menu, press Extensions(Crtl+Shift+X).

  1. Inside the EXTENSIONS tab use the search Extensions in Marketplace to find the following extension: Remote Development.

    image not found

  2. Press install, to install the Remote Development to your local machine.

Your local machine extensions are now installed!

  1. With Remote Development installed, inside the primary side bar an item REMOTE EXPLORER is added, press to open.

  2. Inside the REMOTE EXPLORER select SSH TARGETS press Add New.

  • Enter SSH Connection Command: ssh admin@192.168.2.100, press Enter to confirm.
    image not found
  • Select SSH configuration file to update: /home/username/.ssh/config (To update your config locally, use /etc/ssh/ssh_config to update remote.).
    image not found
  1. Right click on 192.168.2.100, press Connect to Host in Current Window.
    image not found
  • Enter password for $admin@192.168.2.100: vectioneer, press enter.
    image not found
  • In the bottom bar in green you see SSH:192.168.2.100, this means that the connection is established:
    image not found
  • The EXPLORER Window is now opend:
    image not found
  1. With the remote device connected you can install the C/C++ and Motorcortex Template extensions to your remote controller:
    image not found
  • Press: install in SSH:192.168.2.100.

Your controller has all extensions installed and is connected with Visual Studio Code!

Create and build a Motorcortex Project:

  1. Inside EXPLORER under NO FOLDER OPENED connect to remote, press OPEN FOLDER, select home/admin/ press OK.
    image not found
  • This opens in EXPLOROR Window -> ADMIN[SSH:192.168.2.100].
    image not found
  1. Inside ADMIN[SSH:192.168.2.100], Press New Folder... to create a new folder, Enter name: Test.

  2. Use keyboard shortcut ctrl+shift+p, search for: File: Open Folder..., enter: /home/admin/Test -> press OK.

    image not found

  • Enter password for $admin@192.168.2.100: vectioneer, press enter.
    image not found
  1. Inside this folder create a new Motorcortex Project, use keyboard shortcut ctrl+shift+p, search for Motorcortex Create Project.
    image not found
  • Name your Motorcortex project, for exampje: Test.
    image not found
  • Now your project is visual in the EXPLORER it should look like this:
    image not found
  1. This project inside TEST[SSH:192.168.2.100], uses CMake to build, for this you have to assign the following kit:
  • Use keyboard shortcut ctrl+shift+p, search for CMake: Select a Kit.
  • Select a Kit for Test: GCC 9.3.0 x86_64-mcx-linux.
    image not found
  • In the bottom bar in blue GCC 9.3.0 x86_64-mcx-linux, this will show you which kit is active:
    image not found
  1. Now you can try to build your program on the controller, go to top menu bar -> press Run -> press Run Without Debugging.
    image not found

Your Motorcortex program is now running on you controller!

Add Motorcortex Module to Motorcortex Project:

  1. Inside your Motorcortex Project, use keyboard shortcut ctrl+shift+p, search for Motorcortex Create Module.
  • Fill in the name of your file, example test:
    image not found
  • Fill in the name of your class, example testClass:
    image not found
  1. You have created your Motorcortex Module:
    image not found

Your Motorcortex Module is now added to your Motorcortex Project!