From 26c0c5f439b9c9ad496d9a5445713965c78cce20 Mon Sep 17 00:00:00 2001 From: ziteh Date: Wed, 24 Nov 2021 22:35:02 +0800 Subject: [PATCH 01/26] Move define and include to header file --- CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp | 7 ------- CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.h | 7 +++++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp index a23546e..a36a136 100644 --- a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp +++ b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp @@ -1,13 +1,6 @@ #include "pch.h" #include "CoppeliaSimCSharpAPI.h" -/* For C++ using . */ -#define _USE_MATH_DEFINES -#include - -#define TO_RAD(degree) (degree*(M_PI/180)) -#define TO_DEGREE(rad) (rad*(180/M_PI)) - COPPELIASIMCSHARPAPI_API int Connect(char* address, int port) { int id = simxStart((char*)"127.0.0.1", port, true, true, 2000, 5); extApi_sleepMs(300); diff --git a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.h b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.h index 0cdfeeb..45bc25e 100644 --- a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.h +++ b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.h @@ -6,10 +6,17 @@ #define COPPELIASIMREMOTEAPI_API __declspec(dllimport) #endif +/* For C++ using . */ +#define _USE_MATH_DEFINES +#include + extern "C" { #include "extApi.h" } +#define TO_RAD(degree) (degree*(M_PI/180)) +#define TO_DEGREE(rad) (rad*(180/M_PI)) + extern "C" COPPELIASIMCSHARPAPI_API int Connect(char* address, int port); extern "C" COPPELIASIMCSHARPAPI_API int Disconnect(int id); extern "C" COPPELIASIMCSHARPAPI_API bool IsConnected(int id); From 38a20a6df5e5dc3f4a8e45588bc700194e95f8e5 Mon Sep 17 00:00:00 2001 From: ziteh Date: Wed, 24 Nov 2021 22:39:45 +0800 Subject: [PATCH 02/26] Update SendInfo --- CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp index a36a136..000d4c2 100644 --- a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp +++ b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp @@ -68,6 +68,5 @@ COPPELIASIMCSHARPAPI_API int GetObjectHandle(int id, const char* objectName) { } COPPELIASIMCSHARPAPI_API int SendInfo(int id, const char* message, bool blocking) { - int opMode = blocking ? simx_opmode_blocking : simx_opmode_oneshot; - return simxAddStatusbarMessage(id, message, opMode); + return simxAddStatusbarMessage(id, message, blocking ? simx_opmode_blocking : simx_opmode_oneshot); } \ No newline at end of file From 8cdb380ba67e612109e0dc5c7bcd9669e1b814cf Mon Sep 17 00:00:00 2001 From: ziteh Date: Wed, 24 Nov 2021 22:42:07 +0800 Subject: [PATCH 03/26] Create test console project --- .../CoppeliaSimCSharpAPI.TestConsole.cpp | 20 +++ .../CoppeliaSimCSharpAPI.TestConsole.vcxproj | 147 ++++++++++++++++++ ...iaSimCSharpAPI.TestConsole.vcxproj.filters | 22 +++ CoppeliaSimCSharpAPI.sln | 10 ++ 4 files changed, 199 insertions(+) create mode 100644 CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.cpp create mode 100644 CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj create mode 100644 CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj.filters diff --git a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.cpp b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.cpp new file mode 100644 index 0000000..84912f9 --- /dev/null +++ b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.cpp @@ -0,0 +1,20 @@ +// CoppeliaSimCSharpAPI.TestConsole.cpp : This file contains the 'main' function. Program execution begins and ends there. +// + +#include + +int main() +{ + std::cout << "Hello World!\n"; +} + +// Run program: Ctrl + F5 or Debug > Start Without Debugging menu +// Debug program: F5 or Debug > Start Debugging menu + +// Tips for Getting Started: +// 1. Use the Solution Explorer window to add/manage files +// 2. Use the Team Explorer window to connect to source control +// 3. Use the Output window to see build output and other messages +// 4. Use the Error List window to view errors +// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project +// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file diff --git a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj new file mode 100644 index 0000000..5846254 --- /dev/null +++ b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj @@ -0,0 +1,147 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {383015cd-779e-4a25-b200-0e4c1bf955c5} + CoppeliaSimCSharpAPITestConsole + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj.filters b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj.filters new file mode 100644 index 0000000..b475a93 --- /dev/null +++ b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/CoppeliaSimCSharpAPI.sln b/CoppeliaSimCSharpAPI.sln index e6f5b08..d4002e0 100644 --- a/CoppeliaSimCSharpAPI.sln +++ b/CoppeliaSimCSharpAPI.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.31105.61 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CoppeliaSimCSharpAPI", "CoppeliaSimCSharpAPI\CoppeliaSimCSharpAPI.vcxproj", "{6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CoppeliaSimCSharpAPI.TestConsole", "CoppeliaSimCSharpAPI.TestConsole\CoppeliaSimCSharpAPI.TestConsole.vcxproj", "{383015CD-779E-4A25-B200-0E4C1BF955C5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -21,6 +23,14 @@ Global {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Release|x64.Build.0 = Release|x64 {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Release|x86.ActiveCfg = Release|Win32 {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Release|x86.Build.0 = Release|Win32 + {383015CD-779E-4A25-B200-0E4C1BF955C5}.Debug|x64.ActiveCfg = Debug|x64 + {383015CD-779E-4A25-B200-0E4C1BF955C5}.Debug|x64.Build.0 = Debug|x64 + {383015CD-779E-4A25-B200-0E4C1BF955C5}.Debug|x86.ActiveCfg = Debug|Win32 + {383015CD-779E-4A25-B200-0E4C1BF955C5}.Debug|x86.Build.0 = Debug|Win32 + {383015CD-779E-4A25-B200-0E4C1BF955C5}.Release|x64.ActiveCfg = Release|x64 + {383015CD-779E-4A25-B200-0E4C1BF955C5}.Release|x64.Build.0 = Release|x64 + {383015CD-779E-4A25-B200-0E4C1BF955C5}.Release|x86.ActiveCfg = Release|Win32 + {383015CD-779E-4A25-B200-0E4C1BF955C5}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 813cee49a13629182c4fb6ea86e707f4838c3d4b Mon Sep 17 00:00:00 2001 From: ziteh Date: Wed, 24 Nov 2021 23:14:18 +0800 Subject: [PATCH 04/26] Add basic console code --- .../CoppeliaSimCSharpAPI.TestConsole.cpp | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.cpp b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.cpp index 84912f9..f92d8c9 100644 --- a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.cpp +++ b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.cpp @@ -1,20 +1,18 @@ -// CoppeliaSimCSharpAPI.TestConsole.cpp : This file contains the 'main' function. Program execution begins and ends there. -// #include +using namespace std; + int main() { - std::cout << "Hello World!\n"; -} + string command = ""; -// Run program: Ctrl + F5 or Debug > Start Without Debugging menu -// Debug program: F5 or Debug > Start Debugging menu + cout << "CoppeliaSim C# API Test Console\n\n"; + while (true) + { + cin >> command; + cout << "Get " << command << "\n"; + } + return 0; +} -// Tips for Getting Started: -// 1. Use the Solution Explorer window to add/manage files -// 2. Use the Team Explorer window to connect to source control -// 3. Use the Output window to see build output and other messages -// 4. Use the Error List window to view errors -// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project -// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file From 5a412606952d6cdf781a9a8b290971b46b5a4e66 Mon Sep 17 00:00:00 2001 From: ziteh Date: Wed, 24 Nov 2021 23:21:11 +0800 Subject: [PATCH 05/26] Add header file for test console --- .../CoppeliaSimCSharpAPI.TestConsole.cpp | 2 +- .../CoppeliaSimCSharpAPI.TestConsole.h | 3 +++ .../CoppeliaSimCSharpAPI.TestConsole.vcxproj | 3 +++ .../CoppeliaSimCSharpAPI.TestConsole.vcxproj.filters | 5 +++++ 4 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.h diff --git a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.cpp b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.cpp index f92d8c9..42e7670 100644 --- a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.cpp +++ b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.cpp @@ -1,5 +1,5 @@ -#include +#include "CoppeliaSimCSharpAPI.TestConsole.h" using namespace std; diff --git a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.h b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.h new file mode 100644 index 0000000..2339518 --- /dev/null +++ b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.h @@ -0,0 +1,3 @@ +#pragma once + +#include diff --git a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj index 5846254..b804f55 100644 --- a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj +++ b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj @@ -141,6 +141,9 @@ + + + diff --git a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj.filters b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj.filters index b475a93..199db3b 100644 --- a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj.filters +++ b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj.filters @@ -19,4 +19,9 @@ Source Files + + + Header Files + + \ No newline at end of file From 89af59df3dbce23bff1f75167c0e9f2c27c093f3 Mon Sep 17 00:00:00 2001 From: ziteh Date: Wed, 24 Nov 2021 23:31:08 +0800 Subject: [PATCH 06/26] Define some command --- .../CoppeliaSimCSharpAPI.TestConsole.cpp | 19 ++++++++++++++----- .../CoppeliaSimCSharpAPI.TestConsole.h | 4 ++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.cpp b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.cpp index 42e7670..ac81b25 100644 --- a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.cpp +++ b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.cpp @@ -3,15 +3,24 @@ using namespace std; -int main() -{ +int main() { string command = ""; cout << "CoppeliaSim C# API Test Console\n\n"; - while (true) - { + while (true) { cin >> command; - cout << "Get " << command << "\n"; + if (command == COMMAND_CONNECT) { + + } + else if (command == COMMAND_DISCONNECT) { + + } + else if (command == COMMAND_EXIT) { + break; + } + else { + + } } return 0; } diff --git a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.h b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.h index 2339518..77d69fc 100644 --- a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.h +++ b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.h @@ -1,3 +1,7 @@ #pragma once #include + +#define COMMAND_EXIT ("exit") +#define COMMAND_CONNECT ("connect") +#define COMMAND_DISCONNECT ("disconnect") From c761fc0621a101942034d769397fd1d15f3b9b47 Mon Sep 17 00:00:00 2001 From: ziteh Date: Wed, 24 Nov 2021 23:32:03 +0800 Subject: [PATCH 07/26] Add refence --- .../CoppeliaSimCSharpAPI.TestConsole.vcxproj | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj index b804f55..9494f99 100644 --- a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj +++ b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj @@ -144,6 +144,11 @@ + + + {6735f97b-5b21-4b2a-a1a4-edffccd825ba} + + From 603d5b4e77feff88d2b96350d74577b2c1c9a977 Mon Sep 17 00:00:00 2001 From: ZiTe Date: Thu, 25 Nov 2021 12:11:56 +0800 Subject: [PATCH 08/26] Setup include --- .../CoppeliaSimCSharpAPI.TestConsole.cpp | 1 + .../CoppeliaSimCSharpAPI.TestConsole.h | 1 + .../CoppeliaSimCSharpAPI.TestConsole.vcxproj | 6 +----- CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.vcxproj | 8 ++++---- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.cpp b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.cpp index ac81b25..9d82024 100644 --- a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.cpp +++ b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.cpp @@ -21,6 +21,7 @@ int main() { else { } + cout << "\n"; } return 0; } diff --git a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.h b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.h index 77d69fc..c6f3ac0 100644 --- a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.h +++ b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.h @@ -1,6 +1,7 @@ #pragma once #include +#include "CoppeliaSimCSharpAPI.h" #define COMMAND_EXIT ("exit") #define COMMAND_CONNECT ("connect") diff --git a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj index 9494f99..38eca70 100644 --- a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj +++ b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj @@ -116,6 +116,7 @@ true _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true + $(SolutionDir)CoppeliaSimCSharpAPI\;%(AdditionalIncludeDirectories) Console @@ -144,11 +145,6 @@ - - - {6735f97b-5b21-4b2a-a1a4-edffccd825ba} - - diff --git a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.vcxproj b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.vcxproj index c2cadd7..feb45d0 100644 --- a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.vcxproj +++ b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.vcxproj @@ -29,26 +29,26 @@ DynamicLibrary true - v142 + v143 Unicode DynamicLibrary false - v142 + v143 true Unicode DynamicLibrary true - v142 + v143 Unicode DynamicLibrary false - v142 + v143 true Unicode From 2aeaee11a997a33b55f07c86ee36adaf0166457d Mon Sep 17 00:00:00 2001 From: ZiTe Date: Thu, 25 Nov 2021 12:53:34 +0800 Subject: [PATCH 09/26] Remove test console project --- .../CoppeliaSimCSharpAPI.TestConsole.cpp | 3 +-- .../CoppeliaSimCSharpAPI.TestConsole.h | 2 ++ .../CoppeliaSimCSharpAPI.TestConsole.vcxproj | 4 ++-- CoppeliaSimCSharpAPI.sln | 14 ++------------ CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp | 2 +- CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.h | 2 +- 6 files changed, 9 insertions(+), 18 deletions(-) diff --git a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.cpp b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.cpp index 9d82024..1e54b63 100644 --- a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.cpp +++ b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.cpp @@ -10,10 +10,9 @@ int main() { while (true) { cin >> command; if (command == COMMAND_CONNECT) { - + //Connect("127.0.0.1", 3000); } else if (command == COMMAND_DISCONNECT) { - } else if (command == COMMAND_EXIT) { break; diff --git a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.h b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.h index c6f3ac0..62b4291 100644 --- a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.h +++ b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.h @@ -6,3 +6,5 @@ #define COMMAND_EXIT ("exit") #define COMMAND_CONNECT ("connect") #define COMMAND_DISCONNECT ("disconnect") + +//extern "C" int Connect(const char* address, int port); diff --git a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj index 38eca70..5844f0a 100644 --- a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj +++ b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj @@ -42,7 +42,7 @@ Application true - v142 + v143 Unicode @@ -116,7 +116,7 @@ true _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true - $(SolutionDir)CoppeliaSimCSharpAPI\;%(AdditionalIncludeDirectories) + $(SolutionDir)CoppeliaSimCSharpAPI\include\stack\;$(SolutionDir)CoppeliaSimCSharpAPI\include\;$(SolutionDir)CoppeliaSimCSharpAPI\remoteApi\;$(SolutionDir)CoppeliaSimCSharpAPI\;%(AdditionalIncludeDirectories) Console diff --git a/CoppeliaSimCSharpAPI.sln b/CoppeliaSimCSharpAPI.sln index d4002e0..2fe208a 100644 --- a/CoppeliaSimCSharpAPI.sln +++ b/CoppeliaSimCSharpAPI.sln @@ -1,12 +1,10 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.31105.61 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CoppeliaSimCSharpAPI", "CoppeliaSimCSharpAPI\CoppeliaSimCSharpAPI.vcxproj", "{6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CoppeliaSimCSharpAPI.TestConsole", "CoppeliaSimCSharpAPI.TestConsole\CoppeliaSimCSharpAPI.TestConsole.vcxproj", "{383015CD-779E-4A25-B200-0E4C1BF955C5}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -23,14 +21,6 @@ Global {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Release|x64.Build.0 = Release|x64 {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Release|x86.ActiveCfg = Release|Win32 {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Release|x86.Build.0 = Release|Win32 - {383015CD-779E-4A25-B200-0E4C1BF955C5}.Debug|x64.ActiveCfg = Debug|x64 - {383015CD-779E-4A25-B200-0E4C1BF955C5}.Debug|x64.Build.0 = Debug|x64 - {383015CD-779E-4A25-B200-0E4C1BF955C5}.Debug|x86.ActiveCfg = Debug|Win32 - {383015CD-779E-4A25-B200-0E4C1BF955C5}.Debug|x86.Build.0 = Debug|Win32 - {383015CD-779E-4A25-B200-0E4C1BF955C5}.Release|x64.ActiveCfg = Release|x64 - {383015CD-779E-4A25-B200-0E4C1BF955C5}.Release|x64.Build.0 = Release|x64 - {383015CD-779E-4A25-B200-0E4C1BF955C5}.Release|x86.ActiveCfg = Release|Win32 - {383015CD-779E-4A25-B200-0E4C1BF955C5}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp index 000d4c2..2037a15 100644 --- a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp +++ b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp @@ -1,7 +1,7 @@ #include "pch.h" #include "CoppeliaSimCSharpAPI.h" -COPPELIASIMCSHARPAPI_API int Connect(char* address, int port) { +COPPELIASIMCSHARPAPI_API int Connect(const char* address, int port) { int id = simxStart((char*)"127.0.0.1", port, true, true, 2000, 5); extApi_sleepMs(300); if (IsConnected(id)) { diff --git a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.h b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.h index 45bc25e..b411ce4 100644 --- a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.h +++ b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.h @@ -17,7 +17,7 @@ extern "C" { #define TO_RAD(degree) (degree*(M_PI/180)) #define TO_DEGREE(rad) (rad*(180/M_PI)) -extern "C" COPPELIASIMCSHARPAPI_API int Connect(char* address, int port); +extern "C" COPPELIASIMCSHARPAPI_API int Connect(const char* address, int port); extern "C" COPPELIASIMCSHARPAPI_API int Disconnect(int id); extern "C" COPPELIASIMCSHARPAPI_API bool IsConnected(int id); From 9a5d4823ede250f86fb00319b5e63525ef720457 Mon Sep 17 00:00:00 2001 From: ZiTe Date: Thu, 25 Nov 2021 12:56:51 +0800 Subject: [PATCH 10/26] Add type convert --- CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp index 2037a15..92eb037 100644 --- a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp +++ b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp @@ -68,5 +68,5 @@ COPPELIASIMCSHARPAPI_API int GetObjectHandle(int id, const char* objectName) { } COPPELIASIMCSHARPAPI_API int SendInfo(int id, const char* message, bool blocking) { - return simxAddStatusbarMessage(id, message, blocking ? simx_opmode_blocking : simx_opmode_oneshot); + return simxAddStatusbarMessage(id, message, blocking ? (simxInt)simx_opmode_blocking : (simxInt)simx_opmode_oneshot); } \ No newline at end of file From 8634dc3df15f41a2c7a07b10a9defcbec1baaf59 Mon Sep 17 00:00:00 2001 From: ZiTe Date: Thu, 25 Nov 2021 12:58:06 +0800 Subject: [PATCH 11/26] Remove cartesian function --- CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp | 8 -------- CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.h | 2 -- 2 files changed, 10 deletions(-) diff --git a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp index 92eb037..39bed62 100644 --- a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp +++ b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp @@ -44,10 +44,6 @@ COPPELIASIMCSHARPAPI_API int MoveJoint(int id, float position[6], int jointHandl return simxPauseCommunication(id, 0); } -COPPELIASIMCSHARPAPI_API int MoveCartesian(int id, float position[6], int jointHandle[6], bool inTorqueForceMode) { - return -99; -} - COPPELIASIMCSHARPAPI_API int GetJointPosition(int id, int jointHandle[6], float position[6]) { for (int i = 0; i < 6; i++) { float pos; @@ -57,10 +53,6 @@ COPPELIASIMCSHARPAPI_API int GetJointPosition(int id, int jointHandle[6], float return 0; } -COPPELIASIMCSHARPAPI_API int GetCartesianPosition(int id, int jointHandle[6], float position[6]) { - return -99; -} - COPPELIASIMCSHARPAPI_API int GetObjectHandle(int id, const char* objectName) { int objectHandle; simxGetObjectHandle(id, objectName, &objectHandle, simx_opmode_blocking); diff --git a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.h b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.h index b411ce4..4ddddee 100644 --- a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.h +++ b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.h @@ -22,10 +22,8 @@ extern "C" COPPELIASIMCSHARPAPI_API int Disconnect(int id); extern "C" COPPELIASIMCSHARPAPI_API bool IsConnected(int id); extern "C" COPPELIASIMCSHARPAPI_API int MoveJoint(int id, float position[6], int jointHandle[6], bool inTorqueForceMode); -extern "C" COPPELIASIMCSHARPAPI_API int MoveCartesian(int id, float position[6], int jointHandle[6], bool inTorqueForceMode); extern "C" COPPELIASIMCSHARPAPI_API int GetJointPosition(int id, int jointHandle[6], float position[6]); -extern "C" COPPELIASIMCSHARPAPI_API int GetCartesianPosition(int id, int jointHandle[6], float position[6]); extern "C" COPPELIASIMCSHARPAPI_API int GetObjectHandle(int id, const char* objectName); extern "C" COPPELIASIMCSHARPAPI_API int SendInfo(int id, const char* message, bool blocking); From 3f14ed269897e16bbe9a63b726bf510a5e66257b Mon Sep 17 00:00:00 2001 From: ZiTe Date: Thu, 25 Nov 2021 13:05:51 +0800 Subject: [PATCH 12/26] Using param address to connect --- CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp index 39bed62..759ebb5 100644 --- a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp +++ b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp @@ -2,7 +2,7 @@ #include "CoppeliaSimCSharpAPI.h" COPPELIASIMCSHARPAPI_API int Connect(const char* address, int port) { - int id = simxStart((char*)"127.0.0.1", port, true, true, 2000, 5); + int id = simxStart(address, port, true, true, 2000, 5); extApi_sleepMs(300); if (IsConnected(id)) { SendInfo(id, "[Remote API] Connected", false); From 7d9a6bac14840a7076a2e0f76c0a314251bf71e4 Mon Sep 17 00:00:00 2001 From: ZiTe Date: Thu, 25 Nov 2021 13:06:47 +0800 Subject: [PATCH 13/26] Create test form project --- CoppeliaSimCSharpAPI.TestForm/App.config | 6 + .../CoppeliaSimCSharpAPI.TestForm.csproj | 80 ++++++++++++ .../Form1.Designer.cs | 40 ++++++ CoppeliaSimCSharpAPI.TestForm/Form1.cs | 20 +++ CoppeliaSimCSharpAPI.TestForm/Program.cs | 22 ++++ .../Properties/AssemblyInfo.cs | 36 ++++++ .../Properties/Resources.Designer.cs | 71 +++++++++++ .../Properties/Resources.resx | 117 ++++++++++++++++++ .../Properties/Settings.Designer.cs | 30 +++++ .../Properties/Settings.settings | 7 ++ CoppeliaSimCSharpAPI.sln | 20 +++ 11 files changed, 449 insertions(+) create mode 100644 CoppeliaSimCSharpAPI.TestForm/App.config create mode 100644 CoppeliaSimCSharpAPI.TestForm/CoppeliaSimCSharpAPI.TestForm.csproj create mode 100644 CoppeliaSimCSharpAPI.TestForm/Form1.Designer.cs create mode 100644 CoppeliaSimCSharpAPI.TestForm/Form1.cs create mode 100644 CoppeliaSimCSharpAPI.TestForm/Program.cs create mode 100644 CoppeliaSimCSharpAPI.TestForm/Properties/AssemblyInfo.cs create mode 100644 CoppeliaSimCSharpAPI.TestForm/Properties/Resources.Designer.cs create mode 100644 CoppeliaSimCSharpAPI.TestForm/Properties/Resources.resx create mode 100644 CoppeliaSimCSharpAPI.TestForm/Properties/Settings.Designer.cs create mode 100644 CoppeliaSimCSharpAPI.TestForm/Properties/Settings.settings diff --git a/CoppeliaSimCSharpAPI.TestForm/App.config b/CoppeliaSimCSharpAPI.TestForm/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/CoppeliaSimCSharpAPI.TestForm/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/CoppeliaSimCSharpAPI.TestForm/CoppeliaSimCSharpAPI.TestForm.csproj b/CoppeliaSimCSharpAPI.TestForm/CoppeliaSimCSharpAPI.TestForm.csproj new file mode 100644 index 0000000..c21be10 --- /dev/null +++ b/CoppeliaSimCSharpAPI.TestForm/CoppeliaSimCSharpAPI.TestForm.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5} + WinExe + CoppeliaSimCSharpAPI.TestForm + CoppeliaSimCSharpAPI.TestForm + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + \ No newline at end of file diff --git a/CoppeliaSimCSharpAPI.TestForm/Form1.Designer.cs b/CoppeliaSimCSharpAPI.TestForm/Form1.Designer.cs new file mode 100644 index 0000000..1f64aa8 --- /dev/null +++ b/CoppeliaSimCSharpAPI.TestForm/Form1.Designer.cs @@ -0,0 +1,40 @@ +namespace CoppeliaSimCSharpAPI.TestForm +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Text = "Form1"; + } + + #endregion + } +} + diff --git a/CoppeliaSimCSharpAPI.TestForm/Form1.cs b/CoppeliaSimCSharpAPI.TestForm/Form1.cs new file mode 100644 index 0000000..71d736b --- /dev/null +++ b/CoppeliaSimCSharpAPI.TestForm/Form1.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace CoppeliaSimCSharpAPI.TestForm +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + } +} diff --git a/CoppeliaSimCSharpAPI.TestForm/Program.cs b/CoppeliaSimCSharpAPI.TestForm/Program.cs new file mode 100644 index 0000000..04f6e71 --- /dev/null +++ b/CoppeliaSimCSharpAPI.TestForm/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace CoppeliaSimCSharpAPI.TestForm +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/CoppeliaSimCSharpAPI.TestForm/Properties/AssemblyInfo.cs b/CoppeliaSimCSharpAPI.TestForm/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..71ba34f --- /dev/null +++ b/CoppeliaSimCSharpAPI.TestForm/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("CoppeliaSimCSharpAPI.TestForm")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("CoppeliaSimCSharpAPI.TestForm")] +[assembly: AssemblyCopyright("Copyright © 2021")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("fb8863f3-9ba4-47aa-83b2-c28513f2b7f5")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/CoppeliaSimCSharpAPI.TestForm/Properties/Resources.Designer.cs b/CoppeliaSimCSharpAPI.TestForm/Properties/Resources.Designer.cs new file mode 100644 index 0000000..96ca360 --- /dev/null +++ b/CoppeliaSimCSharpAPI.TestForm/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace CoppeliaSimCSharpAPI.TestForm.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CoppeliaSimCSharpAPI.TestForm.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/CoppeliaSimCSharpAPI.TestForm/Properties/Resources.resx b/CoppeliaSimCSharpAPI.TestForm/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/CoppeliaSimCSharpAPI.TestForm/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CoppeliaSimCSharpAPI.TestForm/Properties/Settings.Designer.cs b/CoppeliaSimCSharpAPI.TestForm/Properties/Settings.Designer.cs new file mode 100644 index 0000000..9c1b467 --- /dev/null +++ b/CoppeliaSimCSharpAPI.TestForm/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace CoppeliaSimCSharpAPI.TestForm.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/CoppeliaSimCSharpAPI.TestForm/Properties/Settings.settings b/CoppeliaSimCSharpAPI.TestForm/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/CoppeliaSimCSharpAPI.TestForm/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/CoppeliaSimCSharpAPI.sln b/CoppeliaSimCSharpAPI.sln index 2fe208a..6852155 100644 --- a/CoppeliaSimCSharpAPI.sln +++ b/CoppeliaSimCSharpAPI.sln @@ -5,22 +5,42 @@ VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CoppeliaSimCSharpAPI", "CoppeliaSimCSharpAPI\CoppeliaSimCSharpAPI.vcxproj", "{6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoppeliaSimCSharpAPI.TestForm", "CoppeliaSimCSharpAPI.TestForm\CoppeliaSimCSharpAPI.TestForm.csproj", "{FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Debug|Any CPU.ActiveCfg = Debug|x64 + {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Debug|Any CPU.Build.0 = Debug|x64 {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Debug|x64.ActiveCfg = Debug|x64 {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Debug|x64.Build.0 = Debug|x64 {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Debug|x86.ActiveCfg = Debug|Win32 {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Debug|x86.Build.0 = Debug|Win32 + {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Release|Any CPU.ActiveCfg = Release|x64 + {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Release|Any CPU.Build.0 = Release|x64 {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Release|x64.ActiveCfg = Release|x64 {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Release|x64.Build.0 = Release|x64 {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Release|x86.ActiveCfg = Release|Win32 {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Release|x86.Build.0 = Release|Win32 + {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Debug|x64.ActiveCfg = Debug|Any CPU + {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Debug|x64.Build.0 = Debug|Any CPU + {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Debug|x86.ActiveCfg = Debug|Any CPU + {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Debug|x86.Build.0 = Debug|Any CPU + {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Release|Any CPU.Build.0 = Release|Any CPU + {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Release|x64.ActiveCfg = Release|Any CPU + {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Release|x64.Build.0 = Release|Any CPU + {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Release|x86.ActiveCfg = Release|Any CPU + {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From f05e56f9d800b9809b3670727cf88a8479a98b20 Mon Sep 17 00:00:00 2001 From: ZiTe Date: Thu, 25 Nov 2021 13:09:10 +0800 Subject: [PATCH 14/26] Add Api.cs for import DLL --- CoppeliaSimCSharpAPI.TestForm/Api.cs | 23 +++++++++++++++++++ .../CoppeliaSimCSharpAPI.TestForm.csproj | 1 + 2 files changed, 24 insertions(+) create mode 100644 CoppeliaSimCSharpAPI.TestForm/Api.cs diff --git a/CoppeliaSimCSharpAPI.TestForm/Api.cs b/CoppeliaSimCSharpAPI.TestForm/Api.cs new file mode 100644 index 0000000..09a5d9a --- /dev/null +++ b/CoppeliaSimCSharpAPI.TestForm/Api.cs @@ -0,0 +1,23 @@ +using System; +using System.Runtime.InteropServices; + +namespace CoppeliaSimCSharpAPI.TestForm +{ + internal class Api + { + [DllImport("CoppeliaSimCSharpAPI.dll")] + public static extern int Connect(string address, int port); + + [DllImport("CoppeliaSimCSharpAPI.dll")] + public static extern int Disconnect(int id); + + [DllImport("CoppeliaSimCSharpAPI.dll")] + public static extern int GetJointPosition(int id, int[] jointHandle, float[] position); + + [DllImport("CoppeliaSimCSharpAPI.dll")] + public static extern int GetObjectHandle(int id, string objectName); + + [DllImport("CoppeliaSimCSharpAPI.dll")] + public static extern int MoveJoint(int id, float[] position, int[] jointHandle, bool inTorqueForceMode); + } +} diff --git a/CoppeliaSimCSharpAPI.TestForm/CoppeliaSimCSharpAPI.TestForm.csproj b/CoppeliaSimCSharpAPI.TestForm/CoppeliaSimCSharpAPI.TestForm.csproj index c21be10..85e547a 100644 --- a/CoppeliaSimCSharpAPI.TestForm/CoppeliaSimCSharpAPI.TestForm.csproj +++ b/CoppeliaSimCSharpAPI.TestForm/CoppeliaSimCSharpAPI.TestForm.csproj @@ -46,6 +46,7 @@ + Form From 271630da8612ea639a7244acf701038396ed8c95 Mon Sep 17 00:00:00 2001 From: ZiTe Date: Thu, 25 Nov 2021 16:33:48 +0800 Subject: [PATCH 15/26] Modify params order --- CoppeliaSimCSharpAPI.TestForm/Api.cs | 2 +- CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp | 2 +- CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CoppeliaSimCSharpAPI.TestForm/Api.cs b/CoppeliaSimCSharpAPI.TestForm/Api.cs index 09a5d9a..09a23d0 100644 --- a/CoppeliaSimCSharpAPI.TestForm/Api.cs +++ b/CoppeliaSimCSharpAPI.TestForm/Api.cs @@ -18,6 +18,6 @@ internal class Api public static extern int GetObjectHandle(int id, string objectName); [DllImport("CoppeliaSimCSharpAPI.dll")] - public static extern int MoveJoint(int id, float[] position, int[] jointHandle, bool inTorqueForceMode); + public static extern int MoveJoint(int id, int[] jointHandle, float[] position, bool inTorqueForceMode); } } diff --git a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp index 759ebb5..c45b509 100644 --- a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp +++ b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp @@ -29,7 +29,7 @@ COPPELIASIMCSHARPAPI_API bool IsConnected(int id) { return isConnected; } -COPPELIASIMCSHARPAPI_API int MoveJoint(int id, float position[6], int jointHandle[6], bool inTorqueForceMode) { +COPPELIASIMCSHARPAPI_API int MoveJoint(int id, int jointHandle[6], float position[6], bool inTorqueForceMode) { simxPauseCommunication(id, 1); if (inTorqueForceMode) { for (int i = 0; i < 6; i++) { diff --git a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.h b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.h index 4ddddee..248ec23 100644 --- a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.h +++ b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.h @@ -21,7 +21,7 @@ extern "C" COPPELIASIMCSHARPAPI_API int Connect(const char* address, int port); extern "C" COPPELIASIMCSHARPAPI_API int Disconnect(int id); extern "C" COPPELIASIMCSHARPAPI_API bool IsConnected(int id); -extern "C" COPPELIASIMCSHARPAPI_API int MoveJoint(int id, float position[6], int jointHandle[6], bool inTorqueForceMode); +extern "C" COPPELIASIMCSHARPAPI_API int MoveJoint(int id, int jointHandle[6], float position[6], bool inTorqueForceMode); extern "C" COPPELIASIMCSHARPAPI_API int GetJointPosition(int id, int jointHandle[6], float position[6]); From 71d6003c248b62953a8d75dd16d326a13c255e0e Mon Sep 17 00:00:00 2001 From: ZiTe Date: Thu, 25 Nov 2021 16:49:06 +0800 Subject: [PATCH 16/26] Add connection items --- .../CoppeliaSimCSharpAPI.TestForm.csproj | 23 ++++ .../Form1.Designer.cs | 74 ++++++++++- CoppeliaSimCSharpAPI.TestForm/Form1.cs | 12 ++ CoppeliaSimCSharpAPI.TestForm/Form1.resx | 120 ++++++++++++++++++ CoppeliaSimCSharpAPI.sln | 4 +- 5 files changed, 228 insertions(+), 5 deletions(-) create mode 100644 CoppeliaSimCSharpAPI.TestForm/Form1.resx diff --git a/CoppeliaSimCSharpAPI.TestForm/CoppeliaSimCSharpAPI.TestForm.csproj b/CoppeliaSimCSharpAPI.TestForm/CoppeliaSimCSharpAPI.TestForm.csproj index 85e547a..f1729a9 100644 --- a/CoppeliaSimCSharpAPI.TestForm/CoppeliaSimCSharpAPI.TestForm.csproj +++ b/CoppeliaSimCSharpAPI.TestForm/CoppeliaSimCSharpAPI.TestForm.csproj @@ -32,6 +32,26 @@ prompt 4 + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + 7.3 + prompt + true + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + 7.3 + prompt + true + @@ -55,6 +75,9 @@ + + Form1.cs + ResXFileCodeGenerator Resources.Designer.cs diff --git a/CoppeliaSimCSharpAPI.TestForm/Form1.Designer.cs b/CoppeliaSimCSharpAPI.TestForm/Form1.Designer.cs index 1f64aa8..93188c6 100644 --- a/CoppeliaSimCSharpAPI.TestForm/Form1.Designer.cs +++ b/CoppeliaSimCSharpAPI.TestForm/Form1.Designer.cs @@ -28,13 +28,81 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); + this.buttonConnect = new System.Windows.Forms.Button(); + this.buttonDisconnect = new System.Windows.Forms.Button(); + this.textBoxAddress = new System.Windows.Forms.TextBox(); + this.numericUpDownPort = new System.Windows.Forms.NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownPort)).BeginInit(); + this.SuspendLayout(); + // + // buttonConnect + // + this.buttonConnect.Location = new System.Drawing.Point(93, 61); + this.buttonConnect.Name = "buttonConnect"; + this.buttonConnect.Size = new System.Drawing.Size(159, 73); + this.buttonConnect.TabIndex = 0; + this.buttonConnect.Text = "Connect"; + this.buttonConnect.UseVisualStyleBackColor = true; + this.buttonConnect.Click += new System.EventHandler(this.buttonConnect_Click); + // + // buttonDisconnect + // + this.buttonDisconnect.Location = new System.Drawing.Point(93, 163); + this.buttonDisconnect.Name = "buttonDisconnect"; + this.buttonDisconnect.Size = new System.Drawing.Size(159, 73); + this.buttonDisconnect.TabIndex = 0; + this.buttonDisconnect.Text = "Disconnect"; + this.buttonDisconnect.UseVisualStyleBackColor = true; + this.buttonDisconnect.Click += new System.EventHandler(this.buttonDisconnect_Click); + // + // textBoxAddress + // + this.textBoxAddress.Location = new System.Drawing.Point(348, 138); + this.textBoxAddress.Name = "textBoxAddress"; + this.textBoxAddress.Size = new System.Drawing.Size(100, 31); + this.textBoxAddress.TabIndex = 1; + this.textBoxAddress.Text = "127.0.0.1"; + // + // numericUpDownPort + // + this.numericUpDownPort.Location = new System.Drawing.Point(477, 139); + this.numericUpDownPort.Maximum = new decimal(new int[] { + 99999, + 0, + 0, + 0}); + this.numericUpDownPort.Name = "numericUpDownPort"; + this.numericUpDownPort.Size = new System.Drawing.Size(120, 31); + this.numericUpDownPort.TabIndex = 2; + this.numericUpDownPort.Value = new decimal(new int[] { + 3000, + 0, + 0, + 0}); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 25F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; + this.ClientSize = new System.Drawing.Size(1270, 626); + this.Controls.Add(this.numericUpDownPort); + this.Controls.Add(this.textBoxAddress); + this.Controls.Add(this.buttonDisconnect); + this.Controls.Add(this.buttonConnect); + this.Name = "Form1"; + this.Text = "CoppeliaSim C# API Test Form"; + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownPort)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + } #endregion + + private System.Windows.Forms.Button buttonConnect; + private System.Windows.Forms.Button buttonDisconnect; + private System.Windows.Forms.TextBox textBoxAddress; + private System.Windows.Forms.NumericUpDown numericUpDownPort; } } diff --git a/CoppeliaSimCSharpAPI.TestForm/Form1.cs b/CoppeliaSimCSharpAPI.TestForm/Form1.cs index 71d736b..23b33d1 100644 --- a/CoppeliaSimCSharpAPI.TestForm/Form1.cs +++ b/CoppeliaSimCSharpAPI.TestForm/Form1.cs @@ -12,9 +12,21 @@ namespace CoppeliaSimCSharpAPI.TestForm { public partial class Form1 : Form { + private int _id; + public Form1() { InitializeComponent(); } + + private void buttonConnect_Click(object sender, EventArgs e) + { + _id = Api.Connect(textBoxAddress.Text, (int)numericUpDownPort.Value); + } + + private void buttonDisconnect_Click(object sender, EventArgs e) + { + Api.Disconnect(_id); + } } } diff --git a/CoppeliaSimCSharpAPI.TestForm/Form1.resx b/CoppeliaSimCSharpAPI.TestForm/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/CoppeliaSimCSharpAPI.TestForm/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CoppeliaSimCSharpAPI.sln b/CoppeliaSimCSharpAPI.sln index 6852155..d60e98a 100644 --- a/CoppeliaSimCSharpAPI.sln +++ b/CoppeliaSimCSharpAPI.sln @@ -31,8 +31,8 @@ Global {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Release|x86.Build.0 = Release|Win32 {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Debug|x64.ActiveCfg = Debug|Any CPU - {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Debug|x64.Build.0 = Debug|Any CPU + {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Debug|x64.ActiveCfg = Debug|x64 + {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Debug|x64.Build.0 = Debug|x64 {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Debug|x86.ActiveCfg = Debug|Any CPU {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Debug|x86.Build.0 = Debug|Any CPU {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Release|Any CPU.ActiveCfg = Release|Any CPU From ca449d83ce1851ec6e76636c496e66a9fa36af12 Mon Sep 17 00:00:00 2001 From: ZiTe Date: Thu, 25 Nov 2021 16:55:42 +0800 Subject: [PATCH 17/26] Add get joint handle --- CoppeliaSimCSharpAPI.TestForm/Form1.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CoppeliaSimCSharpAPI.TestForm/Form1.cs b/CoppeliaSimCSharpAPI.TestForm/Form1.cs index 23b33d1..e90e31c 100644 --- a/CoppeliaSimCSharpAPI.TestForm/Form1.cs +++ b/CoppeliaSimCSharpAPI.TestForm/Form1.cs @@ -13,6 +13,7 @@ namespace CoppeliaSimCSharpAPI.TestForm public partial class Form1 : Form { private int _id; + private int[] _jointHandle = new int[6]; public Form1() { @@ -22,6 +23,10 @@ public Form1() private void buttonConnect_Click(object sender, EventArgs e) { _id = Api.Connect(textBoxAddress.Text, (int)numericUpDownPort.Value); + for (int i = 0; i < _jointHandle.Length; i++) + { + _jointHandle[i] = Api.GetObjectHandle(_id, $"UR5_joint{i + 1}"); + } } private void buttonDisconnect_Click(object sender, EventArgs e) From 8d270705cd73f92cb0f48e303c2691639d9a73d3 Mon Sep 17 00:00:00 2001 From: ZiTe Date: Thu, 25 Nov 2021 17:03:16 +0800 Subject: [PATCH 18/26] Add motion items --- .../Form1.Designer.cs | 149 +++++++++++++++++- CoppeliaSimCSharpAPI.TestForm/Form1.cs | 14 ++ 2 files changed, 161 insertions(+), 2 deletions(-) diff --git a/CoppeliaSimCSharpAPI.TestForm/Form1.Designer.cs b/CoppeliaSimCSharpAPI.TestForm/Form1.Designer.cs index 93188c6..0d9b0bd 100644 --- a/CoppeliaSimCSharpAPI.TestForm/Form1.Designer.cs +++ b/CoppeliaSimCSharpAPI.TestForm/Form1.Designer.cs @@ -32,7 +32,20 @@ private void InitializeComponent() this.buttonDisconnect = new System.Windows.Forms.Button(); this.textBoxAddress = new System.Windows.Forms.TextBox(); this.numericUpDownPort = new System.Windows.Forms.NumericUpDown(); + this.buttonMove = new System.Windows.Forms.Button(); + this.numericUpDownJ1 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownJ2 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownJ3 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownJ4 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownJ5 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownJ6 = new System.Windows.Forms.NumericUpDown(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownPort)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ2)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ3)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ4)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ5)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ6)).BeginInit(); this.SuspendLayout(); // // buttonConnect @@ -57,7 +70,7 @@ private void InitializeComponent() // // textBoxAddress // - this.textBoxAddress.Location = new System.Drawing.Point(348, 138); + this.textBoxAddress.Location = new System.Drawing.Point(348, 82); this.textBoxAddress.Name = "textBoxAddress"; this.textBoxAddress.Size = new System.Drawing.Size(100, 31); this.textBoxAddress.TabIndex = 1; @@ -65,7 +78,7 @@ private void InitializeComponent() // // numericUpDownPort // - this.numericUpDownPort.Location = new System.Drawing.Point(477, 139); + this.numericUpDownPort.Location = new System.Drawing.Point(477, 83); this.numericUpDownPort.Maximum = new decimal(new int[] { 99999, 0, @@ -80,11 +93,130 @@ private void InitializeComponent() 0, 0}); // + // buttonMove + // + this.buttonMove.Location = new System.Drawing.Point(399, 484); + this.buttonMove.Name = "buttonMove"; + this.buttonMove.Size = new System.Drawing.Size(159, 73); + this.buttonMove.TabIndex = 3; + this.buttonMove.Text = "Move"; + this.buttonMove.UseVisualStyleBackColor = true; + this.buttonMove.Click += new System.EventHandler(this.buttonMove_Click); + // + // numericUpDownJ1 + // + this.numericUpDownJ1.Location = new System.Drawing.Point(414, 262); + this.numericUpDownJ1.Maximum = new decimal(new int[] { + 360, + 0, + 0, + 0}); + this.numericUpDownJ1.Name = "numericUpDownJ1"; + this.numericUpDownJ1.Size = new System.Drawing.Size(120, 31); + this.numericUpDownJ1.TabIndex = 4; + this.numericUpDownJ1.Value = new decimal(new int[] { + 90, + 0, + 0, + 0}); + // + // numericUpDownJ2 + // + this.numericUpDownJ2.Location = new System.Drawing.Point(414, 299); + this.numericUpDownJ2.Maximum = new decimal(new int[] { + 360, + 0, + 0, + 0}); + this.numericUpDownJ2.Name = "numericUpDownJ2"; + this.numericUpDownJ2.Size = new System.Drawing.Size(120, 31); + this.numericUpDownJ2.TabIndex = 4; + this.numericUpDownJ2.Value = new decimal(new int[] { + 90, + 0, + 0, + 0}); + // + // numericUpDownJ3 + // + this.numericUpDownJ3.Location = new System.Drawing.Point(414, 336); + this.numericUpDownJ3.Maximum = new decimal(new int[] { + 360, + 0, + 0, + 0}); + this.numericUpDownJ3.Name = "numericUpDownJ3"; + this.numericUpDownJ3.Size = new System.Drawing.Size(120, 31); + this.numericUpDownJ3.TabIndex = 4; + this.numericUpDownJ3.Value = new decimal(new int[] { + 90, + 0, + 0, + 0}); + // + // numericUpDownJ4 + // + this.numericUpDownJ4.Location = new System.Drawing.Point(414, 373); + this.numericUpDownJ4.Maximum = new decimal(new int[] { + 360, + 0, + 0, + 0}); + this.numericUpDownJ4.Name = "numericUpDownJ4"; + this.numericUpDownJ4.Size = new System.Drawing.Size(120, 31); + this.numericUpDownJ4.TabIndex = 4; + this.numericUpDownJ4.Value = new decimal(new int[] { + 90, + 0, + 0, + 0}); + // + // numericUpDownJ5 + // + this.numericUpDownJ5.Location = new System.Drawing.Point(414, 410); + this.numericUpDownJ5.Maximum = new decimal(new int[] { + 360, + 0, + 0, + 0}); + this.numericUpDownJ5.Name = "numericUpDownJ5"; + this.numericUpDownJ5.Size = new System.Drawing.Size(120, 31); + this.numericUpDownJ5.TabIndex = 4; + this.numericUpDownJ5.Value = new decimal(new int[] { + 90, + 0, + 0, + 0}); + // + // numericUpDownJ6 + // + this.numericUpDownJ6.Location = new System.Drawing.Point(414, 447); + this.numericUpDownJ6.Maximum = new decimal(new int[] { + 360, + 0, + 0, + 0}); + this.numericUpDownJ6.Name = "numericUpDownJ6"; + this.numericUpDownJ6.Size = new System.Drawing.Size(120, 31); + this.numericUpDownJ6.TabIndex = 4; + this.numericUpDownJ6.Value = new decimal(new int[] { + 90, + 0, + 0, + 0}); + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 25F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1270, 626); + this.Controls.Add(this.numericUpDownJ6); + this.Controls.Add(this.numericUpDownJ5); + this.Controls.Add(this.numericUpDownJ4); + this.Controls.Add(this.numericUpDownJ3); + this.Controls.Add(this.numericUpDownJ2); + this.Controls.Add(this.numericUpDownJ1); + this.Controls.Add(this.buttonMove); this.Controls.Add(this.numericUpDownPort); this.Controls.Add(this.textBoxAddress); this.Controls.Add(this.buttonDisconnect); @@ -92,6 +224,12 @@ private void InitializeComponent() this.Name = "Form1"; this.Text = "CoppeliaSim C# API Test Form"; ((System.ComponentModel.ISupportInitialize)(this.numericUpDownPort)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ2)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ3)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ4)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ5)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ6)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -103,6 +241,13 @@ private void InitializeComponent() private System.Windows.Forms.Button buttonDisconnect; private System.Windows.Forms.TextBox textBoxAddress; private System.Windows.Forms.NumericUpDown numericUpDownPort; + private System.Windows.Forms.Button buttonMove; + private System.Windows.Forms.NumericUpDown numericUpDownJ1; + private System.Windows.Forms.NumericUpDown numericUpDownJ2; + private System.Windows.Forms.NumericUpDown numericUpDownJ3; + private System.Windows.Forms.NumericUpDown numericUpDownJ4; + private System.Windows.Forms.NumericUpDown numericUpDownJ5; + private System.Windows.Forms.NumericUpDown numericUpDownJ6; } } diff --git a/CoppeliaSimCSharpAPI.TestForm/Form1.cs b/CoppeliaSimCSharpAPI.TestForm/Form1.cs index e90e31c..6af7280 100644 --- a/CoppeliaSimCSharpAPI.TestForm/Form1.cs +++ b/CoppeliaSimCSharpAPI.TestForm/Form1.cs @@ -33,5 +33,19 @@ private void buttonDisconnect_Click(object sender, EventArgs e) { Api.Disconnect(_id); } + + private void buttonMove_Click(object sender, EventArgs e) + { + var position = new float[] + { + (float)numericUpDownJ1.Value, + (float)numericUpDownJ2.Value, + (float)numericUpDownJ3.Value, + (float)numericUpDownJ4.Value, + (float)numericUpDownJ5.Value, + (float)numericUpDownJ6.Value + }; + Api.MoveJoint(_id, _jointHandle, position, true); + } } } From a7322e3c2ae5e877361c6078503e07c2da2d727e Mon Sep 17 00:00:00 2001 From: ZiTe Date: Thu, 25 Nov 2021 17:07:50 +0800 Subject: [PATCH 19/26] Add get position --- CoppeliaSimCSharpAPI.TestForm/Form1.Designer.cs | 13 +++++++++++++ CoppeliaSimCSharpAPI.TestForm/Form1.cs | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/CoppeliaSimCSharpAPI.TestForm/Form1.Designer.cs b/CoppeliaSimCSharpAPI.TestForm/Form1.Designer.cs index 0d9b0bd..87eea90 100644 --- a/CoppeliaSimCSharpAPI.TestForm/Form1.Designer.cs +++ b/CoppeliaSimCSharpAPI.TestForm/Form1.Designer.cs @@ -39,6 +39,7 @@ private void InitializeComponent() this.numericUpDownJ4 = new System.Windows.Forms.NumericUpDown(); this.numericUpDownJ5 = new System.Windows.Forms.NumericUpDown(); this.numericUpDownJ6 = new System.Windows.Forms.NumericUpDown(); + this.buttonGetPosition = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownPort)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ2)).BeginInit(); @@ -205,11 +206,22 @@ private void InitializeComponent() 0, 0}); // + // buttonGetPosition + // + this.buttonGetPosition.Location = new System.Drawing.Point(592, 484); + this.buttonGetPosition.Name = "buttonGetPosition"; + this.buttonGetPosition.Size = new System.Drawing.Size(159, 73); + this.buttonGetPosition.TabIndex = 5; + this.buttonGetPosition.Text = "Get Position"; + this.buttonGetPosition.UseVisualStyleBackColor = true; + this.buttonGetPosition.Click += new System.EventHandler(this.buttonGetPosition_Click); + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 25F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1270, 626); + this.Controls.Add(this.buttonGetPosition); this.Controls.Add(this.numericUpDownJ6); this.Controls.Add(this.numericUpDownJ5); this.Controls.Add(this.numericUpDownJ4); @@ -248,6 +260,7 @@ private void InitializeComponent() private System.Windows.Forms.NumericUpDown numericUpDownJ4; private System.Windows.Forms.NumericUpDown numericUpDownJ5; private System.Windows.Forms.NumericUpDown numericUpDownJ6; + private System.Windows.Forms.Button buttonGetPosition; } } diff --git a/CoppeliaSimCSharpAPI.TestForm/Form1.cs b/CoppeliaSimCSharpAPI.TestForm/Form1.cs index 6af7280..1eb4fb6 100644 --- a/CoppeliaSimCSharpAPI.TestForm/Form1.cs +++ b/CoppeliaSimCSharpAPI.TestForm/Form1.cs @@ -47,5 +47,17 @@ private void buttonMove_Click(object sender, EventArgs e) }; Api.MoveJoint(_id, _jointHandle, position, true); } + + private void buttonGetPosition_Click(object sender, EventArgs e) + { + var position = new float[6]; + Api.GetJointPosition(_id, _jointHandle, position); + MessageBox.Show($"{position[0]}, " + + $"{position[1]}, " + + $"{position[2]}, " + + $"{position[3]}, " + + $"{position[4]}, " + + $"{position[5]}"); + } } } From f8dba139a3862a9425c30a0cd356ac082cc74777 Mon Sep 17 00:00:00 2001 From: ZiTe Date: Thu, 25 Nov 2021 17:10:42 +0800 Subject: [PATCH 20/26] Update UI --- .../Form1.Designer.cs | 98 +++++++++++++------ 1 file changed, 66 insertions(+), 32 deletions(-) diff --git a/CoppeliaSimCSharpAPI.TestForm/Form1.Designer.cs b/CoppeliaSimCSharpAPI.TestForm/Form1.Designer.cs index 87eea90..e84fecf 100644 --- a/CoppeliaSimCSharpAPI.TestForm/Form1.Designer.cs +++ b/CoppeliaSimCSharpAPI.TestForm/Form1.Designer.cs @@ -40,6 +40,8 @@ private void InitializeComponent() this.numericUpDownJ5 = new System.Windows.Forms.NumericUpDown(); this.numericUpDownJ6 = new System.Windows.Forms.NumericUpDown(); this.buttonGetPosition = new System.Windows.Forms.Button(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownPort)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ2)).BeginInit(); @@ -47,11 +49,13 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ4)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ5)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ6)).BeginInit(); + this.groupBox1.SuspendLayout(); + this.groupBox2.SuspendLayout(); this.SuspendLayout(); // // buttonConnect // - this.buttonConnect.Location = new System.Drawing.Point(93, 61); + this.buttonConnect.Location = new System.Drawing.Point(6, 78); this.buttonConnect.Name = "buttonConnect"; this.buttonConnect.Size = new System.Drawing.Size(159, 73); this.buttonConnect.TabIndex = 0; @@ -61,7 +65,7 @@ private void InitializeComponent() // // buttonDisconnect // - this.buttonDisconnect.Location = new System.Drawing.Point(93, 163); + this.buttonDisconnect.Location = new System.Drawing.Point(184, 78); this.buttonDisconnect.Name = "buttonDisconnect"; this.buttonDisconnect.Size = new System.Drawing.Size(159, 73); this.buttonDisconnect.TabIndex = 0; @@ -71,7 +75,7 @@ private void InitializeComponent() // // textBoxAddress // - this.textBoxAddress.Location = new System.Drawing.Point(348, 82); + this.textBoxAddress.Location = new System.Drawing.Point(27, 31); this.textBoxAddress.Name = "textBoxAddress"; this.textBoxAddress.Size = new System.Drawing.Size(100, 31); this.textBoxAddress.TabIndex = 1; @@ -79,7 +83,7 @@ private void InitializeComponent() // // numericUpDownPort // - this.numericUpDownPort.Location = new System.Drawing.Point(477, 83); + this.numericUpDownPort.Location = new System.Drawing.Point(198, 31); this.numericUpDownPort.Maximum = new decimal(new int[] { 99999, 0, @@ -96,7 +100,7 @@ private void InitializeComponent() // // buttonMove // - this.buttonMove.Location = new System.Drawing.Point(399, 484); + this.buttonMove.Location = new System.Drawing.Point(17, 98); this.buttonMove.Name = "buttonMove"; this.buttonMove.Size = new System.Drawing.Size(159, 73); this.buttonMove.TabIndex = 3; @@ -106,14 +110,15 @@ private void InitializeComponent() // // numericUpDownJ1 // - this.numericUpDownJ1.Location = new System.Drawing.Point(414, 262); + this.numericUpDownJ1.DecimalPlaces = 1; + this.numericUpDownJ1.Location = new System.Drawing.Point(17, 46); this.numericUpDownJ1.Maximum = new decimal(new int[] { 360, 0, 0, 0}); this.numericUpDownJ1.Name = "numericUpDownJ1"; - this.numericUpDownJ1.Size = new System.Drawing.Size(120, 31); + this.numericUpDownJ1.Size = new System.Drawing.Size(80, 31); this.numericUpDownJ1.TabIndex = 4; this.numericUpDownJ1.Value = new decimal(new int[] { 90, @@ -123,14 +128,15 @@ private void InitializeComponent() // // numericUpDownJ2 // - this.numericUpDownJ2.Location = new System.Drawing.Point(414, 299); + this.numericUpDownJ2.DecimalPlaces = 1; + this.numericUpDownJ2.Location = new System.Drawing.Point(103, 46); this.numericUpDownJ2.Maximum = new decimal(new int[] { 360, 0, 0, 0}); this.numericUpDownJ2.Name = "numericUpDownJ2"; - this.numericUpDownJ2.Size = new System.Drawing.Size(120, 31); + this.numericUpDownJ2.Size = new System.Drawing.Size(80, 31); this.numericUpDownJ2.TabIndex = 4; this.numericUpDownJ2.Value = new decimal(new int[] { 90, @@ -140,14 +146,15 @@ private void InitializeComponent() // // numericUpDownJ3 // - this.numericUpDownJ3.Location = new System.Drawing.Point(414, 336); + this.numericUpDownJ3.DecimalPlaces = 1; + this.numericUpDownJ3.Location = new System.Drawing.Point(189, 46); this.numericUpDownJ3.Maximum = new decimal(new int[] { 360, 0, 0, 0}); this.numericUpDownJ3.Name = "numericUpDownJ3"; - this.numericUpDownJ3.Size = new System.Drawing.Size(120, 31); + this.numericUpDownJ3.Size = new System.Drawing.Size(80, 31); this.numericUpDownJ3.TabIndex = 4; this.numericUpDownJ3.Value = new decimal(new int[] { 90, @@ -157,14 +164,15 @@ private void InitializeComponent() // // numericUpDownJ4 // - this.numericUpDownJ4.Location = new System.Drawing.Point(414, 373); + this.numericUpDownJ4.DecimalPlaces = 1; + this.numericUpDownJ4.Location = new System.Drawing.Point(275, 46); this.numericUpDownJ4.Maximum = new decimal(new int[] { 360, 0, 0, 0}); this.numericUpDownJ4.Name = "numericUpDownJ4"; - this.numericUpDownJ4.Size = new System.Drawing.Size(120, 31); + this.numericUpDownJ4.Size = new System.Drawing.Size(80, 31); this.numericUpDownJ4.TabIndex = 4; this.numericUpDownJ4.Value = new decimal(new int[] { 90, @@ -174,14 +182,15 @@ private void InitializeComponent() // // numericUpDownJ5 // - this.numericUpDownJ5.Location = new System.Drawing.Point(414, 410); + this.numericUpDownJ5.DecimalPlaces = 1; + this.numericUpDownJ5.Location = new System.Drawing.Point(361, 46); this.numericUpDownJ5.Maximum = new decimal(new int[] { 360, 0, 0, 0}); this.numericUpDownJ5.Name = "numericUpDownJ5"; - this.numericUpDownJ5.Size = new System.Drawing.Size(120, 31); + this.numericUpDownJ5.Size = new System.Drawing.Size(80, 31); this.numericUpDownJ5.TabIndex = 4; this.numericUpDownJ5.Value = new decimal(new int[] { 90, @@ -191,14 +200,15 @@ private void InitializeComponent() // // numericUpDownJ6 // - this.numericUpDownJ6.Location = new System.Drawing.Point(414, 447); + this.numericUpDownJ6.DecimalPlaces = 1; + this.numericUpDownJ6.Location = new System.Drawing.Point(447, 46); this.numericUpDownJ6.Maximum = new decimal(new int[] { 360, 0, 0, 0}); this.numericUpDownJ6.Name = "numericUpDownJ6"; - this.numericUpDownJ6.Size = new System.Drawing.Size(120, 31); + this.numericUpDownJ6.Size = new System.Drawing.Size(80, 31); this.numericUpDownJ6.TabIndex = 4; this.numericUpDownJ6.Value = new decimal(new int[] { 90, @@ -208,7 +218,7 @@ private void InitializeComponent() // // buttonGetPosition // - this.buttonGetPosition.Location = new System.Drawing.Point(592, 484); + this.buttonGetPosition.Location = new System.Drawing.Point(212, 98); this.buttonGetPosition.Name = "buttonGetPosition"; this.buttonGetPosition.Size = new System.Drawing.Size(159, 73); this.buttonGetPosition.TabIndex = 5; @@ -216,23 +226,43 @@ private void InitializeComponent() this.buttonGetPosition.UseVisualStyleBackColor = true; this.buttonGetPosition.Click += new System.EventHandler(this.buttonGetPosition_Click); // + // groupBox1 + // + this.groupBox1.Controls.Add(this.textBoxAddress); + this.groupBox1.Controls.Add(this.numericUpDownPort); + this.groupBox1.Controls.Add(this.buttonConnect); + this.groupBox1.Controls.Add(this.buttonDisconnect); + this.groupBox1.Location = new System.Drawing.Point(27, 29); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(354, 167); + this.groupBox1.TabIndex = 6; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Connection"; + // + // groupBox2 + // + this.groupBox2.Controls.Add(this.numericUpDownJ1); + this.groupBox2.Controls.Add(this.numericUpDownJ2); + this.groupBox2.Controls.Add(this.buttonGetPosition); + this.groupBox2.Controls.Add(this.numericUpDownJ3); + this.groupBox2.Controls.Add(this.buttonMove); + this.groupBox2.Controls.Add(this.numericUpDownJ6); + this.groupBox2.Controls.Add(this.numericUpDownJ4); + this.groupBox2.Controls.Add(this.numericUpDownJ5); + this.groupBox2.Location = new System.Drawing.Point(27, 223); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(554, 204); + this.groupBox2.TabIndex = 7; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "Motion"; + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 25F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1270, 626); - this.Controls.Add(this.buttonGetPosition); - this.Controls.Add(this.numericUpDownJ6); - this.Controls.Add(this.numericUpDownJ5); - this.Controls.Add(this.numericUpDownJ4); - this.Controls.Add(this.numericUpDownJ3); - this.Controls.Add(this.numericUpDownJ2); - this.Controls.Add(this.numericUpDownJ1); - this.Controls.Add(this.buttonMove); - this.Controls.Add(this.numericUpDownPort); - this.Controls.Add(this.textBoxAddress); - this.Controls.Add(this.buttonDisconnect); - this.Controls.Add(this.buttonConnect); + this.ClientSize = new System.Drawing.Size(664, 479); + this.Controls.Add(this.groupBox2); + this.Controls.Add(this.groupBox1); this.Name = "Form1"; this.Text = "CoppeliaSim C# API Test Form"; ((System.ComponentModel.ISupportInitialize)(this.numericUpDownPort)).EndInit(); @@ -242,8 +272,10 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ4)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ5)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ6)).EndInit(); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.groupBox2.ResumeLayout(false); this.ResumeLayout(false); - this.PerformLayout(); } @@ -261,6 +293,8 @@ private void InitializeComponent() private System.Windows.Forms.NumericUpDown numericUpDownJ5; private System.Windows.Forms.NumericUpDown numericUpDownJ6; private System.Windows.Forms.Button buttonGetPosition; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.GroupBox groupBox2; } } From 3f84bae701ede7ec3e40979c07c85ee9aa52d4e7 Mon Sep 17 00:00:00 2001 From: ZiTe Date: Thu, 25 Nov 2021 17:14:41 +0800 Subject: [PATCH 21/26] Add form closing even --- CoppeliaSimCSharpAPI.TestForm/Form1.Designer.cs | 1 + CoppeliaSimCSharpAPI.TestForm/Form1.cs | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/CoppeliaSimCSharpAPI.TestForm/Form1.Designer.cs b/CoppeliaSimCSharpAPI.TestForm/Form1.Designer.cs index e84fecf..2ba0bad 100644 --- a/CoppeliaSimCSharpAPI.TestForm/Form1.Designer.cs +++ b/CoppeliaSimCSharpAPI.TestForm/Form1.Designer.cs @@ -265,6 +265,7 @@ private void InitializeComponent() this.Controls.Add(this.groupBox1); this.Name = "Form1"; this.Text = "CoppeliaSim C# API Test Form"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownPort)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ2)).EndInit(); diff --git a/CoppeliaSimCSharpAPI.TestForm/Form1.cs b/CoppeliaSimCSharpAPI.TestForm/Form1.cs index 1eb4fb6..5ee767d 100644 --- a/CoppeliaSimCSharpAPI.TestForm/Form1.cs +++ b/CoppeliaSimCSharpAPI.TestForm/Form1.cs @@ -59,5 +59,17 @@ private void buttonGetPosition_Click(object sender, EventArgs e) $"{position[4]}, " + $"{position[5]}"); } + + private void Form1_FormClosing(object sender, FormClosingEventArgs e) + { + try + { + buttonDisconnect.PerformClick(); + } + catch (Exception) + { + /* Do nothing. */ + } + } } } From 5a57986a5ac40c6cf4474007bfcf73ef57bb3eb8 Mon Sep 17 00:00:00 2001 From: ZiTe Date: Thu, 25 Nov 2021 18:48:50 +0800 Subject: [PATCH 22/26] Update message --- CoppeliaSimCSharpAPI.TestForm/Api.cs | 4 ++-- CoppeliaSimCSharpAPI.TestForm/Form1.cs | 17 +++++++++-------- CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp | 10 +++++----- CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.h | 8 ++++---- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/CoppeliaSimCSharpAPI.TestForm/Api.cs b/CoppeliaSimCSharpAPI.TestForm/Api.cs index 09a23d0..65175b0 100644 --- a/CoppeliaSimCSharpAPI.TestForm/Api.cs +++ b/CoppeliaSimCSharpAPI.TestForm/Api.cs @@ -12,12 +12,12 @@ internal class Api public static extern int Disconnect(int id); [DllImport("CoppeliaSimCSharpAPI.dll")] - public static extern int GetJointPosition(int id, int[] jointHandle, float[] position); + public static extern int GetJointPosition(int id, int[] jointHandle, float[] position, int jointCount); [DllImport("CoppeliaSimCSharpAPI.dll")] public static extern int GetObjectHandle(int id, string objectName); [DllImport("CoppeliaSimCSharpAPI.dll")] - public static extern int MoveJoint(int id, int[] jointHandle, float[] position, bool inTorqueForceMode); + public static extern int MoveJoint(int id, int[] jointHandle, float[] position, bool inTorqueForceMode, int jointCount); } } diff --git a/CoppeliaSimCSharpAPI.TestForm/Form1.cs b/CoppeliaSimCSharpAPI.TestForm/Form1.cs index 5ee767d..9ac2a94 100644 --- a/CoppeliaSimCSharpAPI.TestForm/Form1.cs +++ b/CoppeliaSimCSharpAPI.TestForm/Form1.cs @@ -45,19 +45,20 @@ private void buttonMove_Click(object sender, EventArgs e) (float)numericUpDownJ5.Value, (float)numericUpDownJ6.Value }; - Api.MoveJoint(_id, _jointHandle, position, true); + Api.MoveJoint(_id, _jointHandle, position, true, _jointHandle.Length); } private void buttonGetPosition_Click(object sender, EventArgs e) { var position = new float[6]; - Api.GetJointPosition(_id, _jointHandle, position); - MessageBox.Show($"{position[0]}, " + - $"{position[1]}, " + - $"{position[2]}, " + - $"{position[3]}, " + - $"{position[4]}, " + - $"{position[5]}"); + Api.GetJointPosition(_id, _jointHandle, position, _jointHandle.Length); + MessageBox.Show($"{position[0]}\r\n" + + $"{position[1]}\r\n" + + $"{position[2]}\r\n" + + $"{position[3]}\r\n" + + $"{position[4]}\r\n" + + $"{position[5]}", + "Now position"); } private void Form1_FormClosing(object sender, FormClosingEventArgs e) diff --git a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp index c45b509..2f66024 100644 --- a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp +++ b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp @@ -29,23 +29,23 @@ COPPELIASIMCSHARPAPI_API bool IsConnected(int id) { return isConnected; } -COPPELIASIMCSHARPAPI_API int MoveJoint(int id, int jointHandle[6], float position[6], bool inTorqueForceMode) { +COPPELIASIMCSHARPAPI_API int MoveJoint(int id, int jointHandle[], float position[], bool inTorqueForceMode, int jointCount) { simxPauseCommunication(id, 1); if (inTorqueForceMode) { - for (int i = 0; i < 6; i++) { + for (int i = 0; i < jointCount; i++) { simxSetJointTargetPosition(id, jointHandle[i], TO_RAD(position[i]), simx_opmode_oneshot); } } else { - for (int i = 0; i < 6; i++) { + for (int i = 0; i < jointCount; i++) { simxSetJointPosition(id, jointHandle[i], TO_RAD(position[i]), simx_opmode_oneshot); } } return simxPauseCommunication(id, 0); } -COPPELIASIMCSHARPAPI_API int GetJointPosition(int id, int jointHandle[6], float position[6]) { - for (int i = 0; i < 6; i++) { +COPPELIASIMCSHARPAPI_API int GetJointPosition(int id, int jointHandle[], float position[], int jointCount) { + for (int i = 0; i < jointCount; i++) { float pos; simxGetJointPosition(id, jointHandle[i], &pos, simx_opmode_blocking); position[i] = TO_DEGREE(pos); diff --git a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.h b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.h index 248ec23..82c94fd 100644 --- a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.h +++ b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.h @@ -14,16 +14,16 @@ extern "C" { #include "extApi.h" } -#define TO_RAD(degree) (degree*(M_PI/180)) -#define TO_DEGREE(rad) (rad*(180/M_PI)) +#define TO_RAD(degree) (degree * (M_PI / 180)) +#define TO_DEGREE(rad) (rad * (180 / M_PI)) extern "C" COPPELIASIMCSHARPAPI_API int Connect(const char* address, int port); extern "C" COPPELIASIMCSHARPAPI_API int Disconnect(int id); extern "C" COPPELIASIMCSHARPAPI_API bool IsConnected(int id); -extern "C" COPPELIASIMCSHARPAPI_API int MoveJoint(int id, int jointHandle[6], float position[6], bool inTorqueForceMode); +extern "C" COPPELIASIMCSHARPAPI_API int MoveJoint(int id, int jointHandle[], float position[], bool inTorqueForceMode, int jointCount); -extern "C" COPPELIASIMCSHARPAPI_API int GetJointPosition(int id, int jointHandle[6], float position[6]); +extern "C" COPPELIASIMCSHARPAPI_API int GetJointPosition(int id, int jointHandle[], float position[], int jointCount); extern "C" COPPELIASIMCSHARPAPI_API int GetObjectHandle(int id, const char* objectName); extern "C" COPPELIASIMCSHARPAPI_API int SendInfo(int id, const char* message, bool blocking); From 59ea1fcb89dbb71e6a9dbda675e5bc45153008ff Mon Sep 17 00:00:00 2001 From: ZiTe Date: Thu, 25 Nov 2021 18:52:20 +0800 Subject: [PATCH 23/26] Add IsConnected() and SendInfo() --- CoppeliaSimCSharpAPI.TestForm/Api.cs | 6 ++++++ CoppeliaSimCSharpAPI.TestForm/Form1.cs | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CoppeliaSimCSharpAPI.TestForm/Api.cs b/CoppeliaSimCSharpAPI.TestForm/Api.cs index 65175b0..a52dea8 100644 --- a/CoppeliaSimCSharpAPI.TestForm/Api.cs +++ b/CoppeliaSimCSharpAPI.TestForm/Api.cs @@ -11,6 +11,9 @@ internal class Api [DllImport("CoppeliaSimCSharpAPI.dll")] public static extern int Disconnect(int id); + [DllImport("CoppeliaSimCSharpAPI.dll")] + public static extern bool IsConnected(int id); + [DllImport("CoppeliaSimCSharpAPI.dll")] public static extern int GetJointPosition(int id, int[] jointHandle, float[] position, int jointCount); @@ -19,5 +22,8 @@ internal class Api [DllImport("CoppeliaSimCSharpAPI.dll")] public static extern int MoveJoint(int id, int[] jointHandle, float[] position, bool inTorqueForceMode, int jointCount); + + [DllImport("CoppeliaSimCSharpAPI.dll")] + public static extern int SendInfo(int id, string message, bool blocking); } } diff --git a/CoppeliaSimCSharpAPI.TestForm/Form1.cs b/CoppeliaSimCSharpAPI.TestForm/Form1.cs index 9ac2a94..7a34c49 100644 --- a/CoppeliaSimCSharpAPI.TestForm/Form1.cs +++ b/CoppeliaSimCSharpAPI.TestForm/Form1.cs @@ -23,9 +23,12 @@ public Form1() private void buttonConnect_Click(object sender, EventArgs e) { _id = Api.Connect(textBoxAddress.Text, (int)numericUpDownPort.Value); - for (int i = 0; i < _jointHandle.Length; i++) + if (Api.IsConnected(_id)) { - _jointHandle[i] = Api.GetObjectHandle(_id, $"UR5_joint{i + 1}"); + for (int i = 0; i < _jointHandle.Length; i++) + { + _jointHandle[i] = Api.GetObjectHandle(_id, $"UR5_joint{i + 1}"); + } } } From 8b2f9572701d38ce0e798b61f0025816333b7ee7 Mon Sep 17 00:00:00 2001 From: ZiTe Date: Thu, 25 Nov 2021 18:56:12 +0800 Subject: [PATCH 24/26] Add joint prefix --- CoppeliaSimCSharpAPI.TestForm/Form1.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CoppeliaSimCSharpAPI.TestForm/Form1.cs b/CoppeliaSimCSharpAPI.TestForm/Form1.cs index 7a34c49..9b6e960 100644 --- a/CoppeliaSimCSharpAPI.TestForm/Form1.cs +++ b/CoppeliaSimCSharpAPI.TestForm/Form1.cs @@ -12,6 +12,8 @@ namespace CoppeliaSimCSharpAPI.TestForm { public partial class Form1 : Form { + private const string _jointPrefix = "UR5_joint"; + private int _id; private int[] _jointHandle = new int[6]; @@ -27,7 +29,7 @@ private void buttonConnect_Click(object sender, EventArgs e) { for (int i = 0; i < _jointHandle.Length; i++) { - _jointHandle[i] = Api.GetObjectHandle(_id, $"UR5_joint{i + 1}"); + _jointHandle[i] = Api.GetObjectHandle(_id, _jointPrefix + (i + 1)); } } } From ae6cea2b518716a012196d73c1d10286cd0ce6c3 Mon Sep 17 00:00:00 2001 From: ZiTe Date: Thu, 25 Nov 2021 19:00:21 +0800 Subject: [PATCH 25/26] Add README.md --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..627cf47 --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# CoppeliaSim C# API + +The CoppeliaSim (V-REP) remote control API for C#. Using [CoppeliaSim Legacy remote API](https://www.coppeliarobotics.com/helpFiles/en/legacyRemoteApiOverview.htm). + +# Demo + +[Demo video (YouTube)](https://youtu.be/4fqbw-M2QbY) + +# Reference +- [CoppeliaRobotics/bubbleRobClient](https://github.com/CoppeliaRobotics/bubbleRobClient) + +# Dependency +- [CoppeliaRobotics/include](https://github.com/CoppeliaRobotics/include) +- [CoppeliaRobotics/remoteApi](https://github.com/CoppeliaRobotics/remoteApi) \ No newline at end of file From 4e0d25778185092a64a05102cde5966fe1b61543 Mon Sep 17 00:00:00 2001 From: ZiTe Date: Thu, 25 Nov 2021 19:00:28 +0800 Subject: [PATCH 26/26] Remove unused files --- .../CoppeliaSimCSharpAPI.TestConsole.cpp | 27 ---- .../CoppeliaSimCSharpAPI.TestConsole.h | 10 -- .../CoppeliaSimCSharpAPI.TestConsole.vcxproj | 151 ------------------ ...iaSimCSharpAPI.TestConsole.vcxproj.filters | 27 ---- 4 files changed, 215 deletions(-) delete mode 100644 CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.cpp delete mode 100644 CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.h delete mode 100644 CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj delete mode 100644 CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj.filters diff --git a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.cpp b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.cpp deleted file mode 100644 index 1e54b63..0000000 --- a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.cpp +++ /dev/null @@ -1,27 +0,0 @@ - -#include "CoppeliaSimCSharpAPI.TestConsole.h" - -using namespace std; - -int main() { - string command = ""; - - cout << "CoppeliaSim C# API Test Console\n\n"; - while (true) { - cin >> command; - if (command == COMMAND_CONNECT) { - //Connect("127.0.0.1", 3000); - } - else if (command == COMMAND_DISCONNECT) { - } - else if (command == COMMAND_EXIT) { - break; - } - else { - - } - cout << "\n"; - } - return 0; -} - diff --git a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.h b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.h deleted file mode 100644 index 62b4291..0000000 --- a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#include -#include "CoppeliaSimCSharpAPI.h" - -#define COMMAND_EXIT ("exit") -#define COMMAND_CONNECT ("connect") -#define COMMAND_DISCONNECT ("disconnect") - -//extern "C" int Connect(const char* address, int port); diff --git a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj deleted file mode 100644 index 5844f0a..0000000 --- a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj +++ /dev/null @@ -1,151 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - Win32Proj - {383015cd-779e-4a25-b200-0e4c1bf955c5} - CoppeliaSimCSharpAPITestConsole - 10.0 - - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - Application - true - v143 - Unicode - - - Application - false - v142 - true - Unicode - - - - - - - - - - - - - - - - - - - - - true - - - false - - - true - - - false - - - - Level3 - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - Level3 - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - $(SolutionDir)CoppeliaSimCSharpAPI\include\stack\;$(SolutionDir)CoppeliaSimCSharpAPI\include\;$(SolutionDir)CoppeliaSimCSharpAPI\remoteApi\;$(SolutionDir)CoppeliaSimCSharpAPI\;%(AdditionalIncludeDirectories) - - - Console - true - - - - - Level3 - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - - - - - - \ No newline at end of file diff --git a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj.filters b/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj.filters deleted file mode 100644 index 199db3b..0000000 --- a/CoppeliaSimCSharpAPI.TestConsole/CoppeliaSimCSharpAPI.TestConsole.vcxproj.filters +++ /dev/null @@ -1,27 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - - - Header Files - - - \ No newline at end of file