From 8d66fb673a18f1293c070c718abd810d486e12e8 Mon Sep 17 00:00:00 2001 From: "ly.pechvattana" Date: Thu, 9 Mar 2023 15:10:45 +0700 Subject: [PATCH] adding makefile --- main.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ makefile | 12 ++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 main.cpp create mode 100644 makefile diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..c2a345c --- /dev/null +++ b/main.cpp @@ -0,0 +1,45 @@ +#include +#include +#include +#include "DynamixelHandler.h" + +// Global variables +DynamixelHandler _oDxlHandler; +std::string _poppyDxlPortName = "/dev/ttyUSB0"; +float _poppyDxlProtocol = 2.0; +int _poppyDxlBaudRate = 1000000; +int _nbJoints = 6; +float _minJointCmd = 0; +float _maxJointCmd = 1023; +float _minJointAngle = -180.0f; +float _maxJointAngle = 180.0f; + +int main() +{ + std::cout << "===Initialization of the Dynamixel Motor communication====" << std::endl; + _oDxlHandler.setDeviceName(_poppyDxlPortName); + _oDxlHandler.setProtocolVersion(_poppyDxlProtocol); + _oDxlHandler.openPort(); + _oDxlHandler.setBaudRate(_poppyDxlBaudRate); + _oDxlHandler.enableTorque(true); + std::cout << std::endl; + + // read current joint position + std::vector l_vCurrentJointPosition; + _oDxlHandler.readCurrentJointPosition(l_vCurrentJointPosition); + // display current joint position + std::cout <<"vCurrentJointPosition= (" << std::endl; + for (int l_joint=0; l_joint < l_vCurrentJointPosition.size(); l_joint++) + std::cout << l_vCurrentJointPosition[l_joint] << ", "; + std::cout << ")" << std::endl; + + // wait 1s + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + std::cout << "===Closing the Dynamixel Motor communication====" << std::endl; + _oDxlHandler.enableTorque(false); + _oDxlHandler.closePort(); + std::cout << std::endl; + + + return 0; +} diff --git a/makefile b/makefile new file mode 100644 index 0000000..5df077f --- /dev/null +++ b/makefile @@ -0,0 +1,12 @@ +all:dynamixel main + g++ DynamixelHandler.o main.o –L/usr/local/lib –ldxl_x64_cpp -lrt + +dynamixel: /home/vattana/Software/toolkit-dynamixel/src/DynamixelHandler.cpp + g++ -c -I/home/vattana/Software/toolkit-dynamixel/include /home/vattana/Software/toolkit-dynamixel/src/DynamixelHandler.cpp + +main: main.cpp + g++ -c -I/home/vattana/Software/toolkit-dynamixel/include main.cpp + +clean: + rm *.o + rm a.out