Environment Setup
8 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 pressrestart IDE
-> pressRestart
. 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 (../mcx-example
) and pressCreate
.
Set-up Remote Development
Remote development is used to develop your motorcortex application direct on your motorcortex target system.
-
In the
Main Menu
openFile → Settings
underBuild, Execution, Deployment
you will find theToolchains
menu. -
Add a new toolchain by pressing the
Remote Host
. -
In the
Credentials:
press theSSH Configurations
menu. Add a new configuration by pressing the- Host:
192.168.2.100
- Port:
22
- User name:
admin
- Password:
vectioneer
- Host:
-
Press the
Test Connection
button to make sure your connection isOK
. If not, re-check your controller connection. -
If the connection is good you can press
OK
to close theSSH Configurations
menu. -
Wait for
Cmake
and theC/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 theToolchain
settings. - CMake:
-
Under
Build, Execution, Deployment
open theCmake
menu, setToolChain
, toRemote Host
withdropdown
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
- Build type:
-
Press the
OK
button to save theCMake
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
tobuild
andrun
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
Cross compilation is used to develop motorcortex application on your pc and deploy it to motorcortex target system.
-
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
. - Press
System
toolchain and name itmotorcortex
. - Open
Add environment
→From file
. - Select
environment file
of the Motorcortex SDK → pressOK
.
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. - Open
-
Install
Motorcortex Toolchain
plugin and pressrestart IDE
→ pressRestart
. -
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...
- Select
Remote Development
, pressSFTP
connection and name itmcx-host
. - Setup
SSH connection
→ pressadmin@192.168.2.100:22
. - Press
Autodetect
to set theroot path
. - Press
OK
- Open
-
In CLion open
Run/Debug Configuration
, pressMotorcortex 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
- Fill in
-
Each time a
Motorcortex Remote Application
is made, insideFile
→Settings
→Build Execution Deployment
→CMake
, two profiles are added:CrossDebug
andCrossRelease
. It can happen that you accidentally delete one of these profiles, If this happens you can manually add aprofile
by means of pressingCrossDebug
orCrossRelease
.
-
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
.
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)
.
-
Inside the EXTENSIONS tab use the search
Extensions in Marketplace
to find the following extension:Remote Development
. -
Press
install
, to install theRemote Development
to your local machine.
Your local machine extensions are now installed!
-
With
Remote Development installed
, inside theprimary side bar
an itemREMOTE EXPLORER
is added, press to open. -
Inside the
REMOTE EXPLORER
selectSSH TARGETS
pressAdd New
.
- Enter SSH Connection Command:
ssh admin@192.168.2.100
, pressEnter
to confirm. - Select SSH configuration file to update:
/home/username/.ssh/config
(To update your config locally, use/etc/ssh/ssh_config
to update remote.).
Right click
on192.168.2.100
, pressConnect to Host in Current Window
.
- Enter password for $admin@192.168.2.100:
vectioneer
, pressenter
. - In the bottom bar in green you see
SSH:192.168.2.100
, this means that the connection is established: - The
EXPLORER Window
is now opend:
- With the
remote device connected
you can install theC/C++
andMotorcortex Template
extensions to your remote controller:
- 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:
- Inside
EXPLORER
underNO FOLDER OPENED
connect to remote, pressOPEN FOLDER
, selecthome/admin/
pressOK
.
- This opens in
EXPLOROR
Window ->ADMIN[SSH:192.168.2.100]
.
-
Inside ADMIN[SSH:192.168.2.100], Press
New Folder...
to create a new folder, Enter name:Test
. -
Use keyboard shortcut
ctrl+shift+p
, search for:File: Open Folder...
, enter:/home/admin/Test
-> pressOK
.
- Enter password for $admin@192.168.2.100:
vectioneer
, pressenter
.
- Inside this folder create a new Motorcortex Project, use keyboard shortcut
ctrl+shift+p
, search forMotorcortex Create Project
.
- Name your Motorcortex project, for exampje:
Test
. - Now your project is visual in the
EXPLORER
it should look like this:
- This project inside
TEST[SSH:192.168.2.100]
, usesCMake
to build, for this you have to assign the following kit:
- Use keyboard shortcut
ctrl+shift+p
, search forCMake: Select a Kit
. - Select a Kit for Test:
GCC 9.3.0 x86_64-mcx-linux
. - In the bottom bar in blue
GCC 9.3.0 x86_64-mcx-linux
, this will show you which kit is active:
- Now you can try to build your program on the controller, go to
top menu bar
-> pressRun
-> pressRun Without Debugging
.
Your Motorcortex program is now running on you controller!
Add Motorcortex Module to Motorcortex Project:
- Inside your Motorcortex Project, use keyboard shortcut
ctrl+shift+p
, search forMotorcortex Create Module
.
- Fill in the name of your file, example
test
: - Fill in the name of your class, example
testClass
:
- You have created your Motorcortex Module:
Your Motorcortex Module is now added to your Motorcortex Project!