Skip to content

Latest commit

 

History

History
322 lines (246 loc) · 10.9 KB

File metadata and controls

322 lines (246 loc) · 10.9 KB

C++ examples

Table of Contents

Setup (C++ environment)

Set up PC environment

CMake

The C++ example projects in this repository use CMake.
The following link has the instructions to install CMake.

On Windows, make sure you add CMake to your PATH variable

CMake add to path

GCC compiler

To check which version of GCC is installed on Windows or Linux
Note: This procedure only works on Windows if you add the MinGW bin directory path to the PATH environment variable.

gcc --version

Procedure to install GCC under Linux (GCC 5.4 on Ubuntu 16.04, GCC 7.4 on Ubuntu 18.04, GCC 9.4 on Ubuntu 20.04)

sudo apt-get install build-essential

Procedure to install GCC 5.4 under Windows

Because GCC is not coded for the Windows operating system, a GCC port of MinGW-w64 for Windows is required. The '-w64' suffix indicates that it can support a 32-bit or 64-bit environment. The 32-bit versions are still available and one of them will be used to compile the affected project.

  1. Go to https://sourceforge.net/projects/mingw-w64
  2. Start the installer and click Next until you reach the installation options page
  3. On the options page ensure that the options look exactly like this (all options are the default values, except for version, which is the version of GCC we want to install - 5.4 in this case)

Gcc Setting

  1. Click Next until the end of the installation. The install directory by default is the one set in the build script included with the project.
  2. Add the path of the bin directory to the system path to make all the MinGW commands and tools available system wide:
    • Right-click on the Start Button
    • Select System from the context menu.
    • Click Advanced system settings
    • Go to the Advanced tab
    • Click Environment Variables…
    • Click variable called Path and click Edit…
    • Click New
    • Enter the path to the folder containing the binary you want on your PATH (e.g. C:\Program Files (x86)\mingw-w64\i686-5.4.0-posix-dwarf-rt_v5-rev0\mingw32\bin)

Conan

Using Conan

The C++ examples use the Conan (V1.X) package manager for fetching its dependencies. This is done by default and requires Conan to be installed.

Instructions are for conan V1.X only and it won't work for versions >=2.0.0

You can refer to the Conan Installation Tutorial for installing Conan.

Note: It is recommended to install Python3 for Conan. You can download and install Python3 from https://www.python.org/

When installing conan via pip the new directory might not be appended to the PATH. This can be solved on Ubuntu by restarting the terminal or by using source ~/.profile or by adding the installed PATH (that you can find with pip show conan) to your PATH environnement variable in Windows.

Next, enable the revision feature for Artifactory plugin

conan config set general.revisions_enabled=1

Create an automatically detected default profile

conan profile new default --detect 

After Conan is properly installed, build as specified in the build section.

Not using Conan

Although building with Conan is recommended, it is possible to disable it.

Doing so requires calling cmake with an additional option: -DUSE_CONAN=OFF.

Example (Linux):

 mkdir build  
 cd build  
 cmake .. -DUSE_CONAN=OFF -DCMAKE_BUILD_TYPE=release [-DKORTEX_SUB_DIR=<kortex_api_sub_folder dir name>]
 make  

This applies to all the manual build commands. The build scripts can also be modified to add this option.

Example (build-mingw.bat)

(line 17) cmake .. -G "MinGW Makefiles" -DUSE_CONAN=OFF -DCMAKE_BUILD_TYPE=%build_type% -DKORTEX_SUB_DIR=%kortex_api_sub_folder% && mingw32-make

This will effectively revert to the old build method. It requires downloading the Kortex Api library:

  • Download the archive via Kinova's Artifactory server: kortex_api
  • Uncompress the content of the archive and place it in the directory kortex_api.
examples/kortex_api  
┬  
├ include/
├ lib/  
└   ┬  
    ├ debug/  
    └ release/

You can also uncompress the content of the archive in a sub-directory kortex_api/<Something>. You will then have to use the KORTEX_SUB_DIR CMake argument to specify the Kortex API sub-directory.

examples/kortex_api  
┬  
├ Something/ [e.g. linux_gcc_x86-64]
└   ┬  
    ├ include/
    ├ lib/  
└       ┬  
        ├ debug/  
        └ release/

Build

Note: The C++ examples use the Conan package manager by default. Refer to the Conan section on how to install Conan or revert to building without Conan.

To build, you need change the current directory to the example directory. The build instructions then depend on your OS and compiler (see below).

my_example_repo  
┬  
├ api_cpp/
└   ┬  
    ├ doc/
    └ examples/     (you have to cd here)

Linux Ubuntu

You can run the build script:

./scripts/build-gcc.sh {release|debug}

You can also build manually:

mkdir build  
cd build  
cmake .. -DCMAKE_BUILD_TYPE=release [-DKORTEX_SUB_DIR=<kortex_api_sub_folder dir name>]
make  

Note: the name of the executable is mingw32-make.exe, even for the 64-bit version)

Windows - using GCC

You can run the build script:

scripts\build-mingw.bat {release|debug}

You can also build manually:

mkdir build  
cd build  
cmake .. -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=release [-DKORTEX_SUB_DIR=<kortex_api_sub_folder dir name>]  
mingw32-make  

Windows - using Visual Studio 2017
mkdir build  
cd build  
cmake .. -G "Visual Studio 15 2017 [arch]" -DCMAKE_SH=CMAKE_SH-NOTFOUND -DCMAKE_BUILD_TYPE=release [-DKORTEX_SUB_DIR=<kortex_api_sub_folder dir name>]  

Windows - using command-line MSVC build

Setup the build environment:

Note: Make sure to adjust the path to match the location of your installed BuildTools call:

C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvars64.bat

You can run the build script:

scripts\build-msvc.bat {release|debug} {static|dynamic}

You can also build manually:

mkdir build  
cmake .. -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release [-DKORTEX_SUB_DIR=<kortex_api_sub_folder dir name>]
nmake

Run

We assume the robot is using its default IP address: 192.168.1.10.

Before you start make sure you run the test in a safe area - some examples contain movement. Also verify that your robot is correctly afixed to your working surface.

Prerequisites:

  • The examples require a wired connection to your computer
  • Configure a static IP on your network interface (e.g: 192.168.1.11/24)

Each example has its own main function so you can run them individually from the examples folder.

On Linux :

./<your_build_folder>/<example_name>

On Windows :

<your_build_folder>\<example_name>.exe

C++ API documentation

Here is a link to the generated documentation:
API C++ Services Documentation

Reference

Useful Links

Google Proto Buffer generated C++: https://developers.google.com/protocol-buffers/docs/reference/cpp-generated

Back to root topic: readme.md