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. - Copy and paste this code into the newly created .cpp file
#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;
}
6. Create a file called "CMakeLists.txt." Copy these contents into it.
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."
7. Open a terminal and navigate to the HelloYMConnect folder (ex. /home/yourUsername/projects/HelloYMConnect). Run this command to configure the project.
cmake ../HelloYMConnect/
8. Run this command to build the program.
cmake --build .
9. When the build is successful, run this command to execute the program.
./HelloYMConnect
If the project runs successfully, the terminal will output
Code (0): OK
The pendant will look like this...
Comments
0 comments
Please sign in to leave a comment.