This tutorial uses Visual Studio Code for code creation and CMake for the build system. YMConnect for Linux includes the header file and the Shared Object(SO) file.
Official minimum requirements are CMake 3.10 with gcc 11.4.0
Other compilers may work but are untested.
All terminal commands in this tutorial (steps 6-8) are run in the linux console.
Create a folder called "HelloYMConnect."
Drag and drop the included "YMConnect.h" and "libYMConnect.so" into the folder.
Open the folder in Visual Studio Code.
Create a file called "HelloYMConnect.cpp."
If not already installed, Visual Studio Code will prompt you to install the "C/C++ Extension Pack." This is not needed for this tutorial.
#include "YMConnect.h" // Include the YMConnect header file
int main()
{
StatusInfo status;
MotomanController* c = YMConnect::OpenConnection("192.168.1.31", status); // Open a connection to the robot controller
if (status.StatusCode != 0)
{
std::cout << status << std::endl;
return status.StatusCode;
}
status = c->ControlCommands->DisplayStringToPendant("Hello from YMConnect");
std::cout << status << std::endl;
YMConnect::CloseConnection(c);
return status.StatusCode;
}
cmake_minimum_required(VERSION 3.10)
project(HelloYMConnect)
set(CMAKE_CXX_STANDARD 17) #YMConnect requires C++17.
add_library(YMConnect SHARED IMPORTED)#Import the YMConnect library into the project.
set_property(TARGET YMConnect PROPERTY IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/libYMConnect_D.so") #Set the location of the YMConnect library.
add_executable(HelloYMConnect HelloYMConnect.cpp) #Create the executable.
TARGET_LINK_LIBRARIES(HelloYMConnect "YMConnect") #Link the executable to the YMConnect library.
Please note that this CMake file will set the imported location to this source folder (ex. /home/yourUsername/projects/HelloYMConnect). This means that the executable will look for the shared object here during run time. If you want it to look elsewhere, add libYMConnect.so to LD_LIBRARY_PATH or use RPATH in a custom CMakeLists.txt file. However these options are beyond the scope of this tutorial.
Since this tutorial is a debug build, use "libYMConnect_D.so." For a release build, use "libYMConnect.so."
cmake ../HelloYMConnect/
cmake --build .
./HelloYMConnect
If the project runs successfully, the terminal will output
Code (0): OK
The pendant will look like this...