Environment Setup
5 minute read
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.
-
In the
Main Menu
on the top left corner open:File → Settings
, then find thePlugins
menu. -
In the plugins menu search for
Motorcortex
. -
Install the
Motorcortex Templates
plugin and restart IDE. After that you can create new Motorcortex projects in the main menu. -
In the
Main Menu
open:File → New Project
, in the pop-up underC++
chooseC++ Motorcortex
select the location where you want to save your project and pressCreate
.
Set-up Remote Development
-
In the
Main Menu
openFile → Settings
underBuild, Execution, Deployment
you will find theToolchains
menu. -
Add a new toolchain by pressing the
+
button and selectRemote Host
. -
In the
Credentials
press the ⚙️ button to enter theSSH 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
-
Press the
Test Connection
button to make sure your connection is Ok. If not, re-check your controller connection. -
If the connection is good you can press Ok to close the
SSH Configurations
menu. -
Wait for
Make
and theC/C++ Compiler
to be detected then press theApply
button to save theToolchain
settings. -
Set
Toolchain
toRemote Host
. -
Press the Ok button to save the
CMake
settings and close theSettings
window. -
Wait for a couple of seconds while remote and local systems are synchronized.
-
Make sure that your controller is not running a Motorcortex application. Open the
Terminal
inCLion
and run the following command:ssh admin@192.168.2.100 'echo vectioneer | sudo -S motorcortex stop'
-
In
CLion
set yourRun/Debug Configuration
toDebug-Remote Host
. -
Press play to build and run the application.
-
To compile code with the latest modifications press
Rebuild Project
. -
Congratulations you are now ready to start remote developing your Motorcortex application.
Set-up Cross Compilation
-
For Cross compilation you will need a Motorcortex SDK. You can download the SDK (Software Development Kit) from the motorcortex.io store
-
Extract the archive and place the
.sh
file in a folder of your preference. -
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
-
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
-
Mounting
Sysroot
on your system.Generate a new key pair with the following command.
ssh-keygen -t rsa
Note
The prompt will ask you to set a password. This is not needed but optional if desired.
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 isvectioneer
.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/
Note
You will need to execute this last command every time after you logout or reboot your development system.
-
Configure toolchain in CLion.
Open
File → Settings → Build Execution Deployment → Toolchains
.Create a new
System Toolchain
with the namemotorcortex
.Open
Add environment → From file
.Fill the
environment
file of the Motorcortex SDK.CLion will fill all the required paths automatically as it shown in the image below.
Press Apply to save the changes.
-
Install
Motorcortex Toolchain
plugin. -
Open
File → Settings → Build, Execution, Deployment → Motorcortex SDK
and fill in theSysroot
path with the mounted folder:mcx-sysroot
. -
Add the connection to the remote Motorcortex host. Open
Tools → Deployment → Configuration
, add a newSFTP
connection namedmcx-host
. Press theAutodetect
button to set theRoot path
. -
In CLion open
Run/Debug Configuration
, press+
to add new configuration, selectMotorcortex Remote Application
. -
Fill
Name
of the new configuration:cross_mcx_example
. FillProgram arguments
with default path to the active configuration:-c /etc/motorcortex/config/config.json
. SelectDevelopment profile: mcx-host
. -
To install configuration to the controller press
Build → Install
.Note
If your application is based on the
Motorcortex Template
example,make install
command will copy the config folder to the target system to the following path/etc/motorcortex/apps-available
and will create a symbolic link on the target system:/etc/motorcortex/config
. -
To run a project on the controller press
Run
icon. -
To debug the project select
CrossDebug
configuration and pressDebug
.