From 86ce157db8d394720afd26efd24ddef83e314f67 Mon Sep 17 00:00:00 2001 From: leon Date: Mon, 20 Jun 2016 21:04:13 +0900 Subject: [PATCH] c ver. .dll binding example - c sharp uploaded --- .../win32/dynamixel.cs | 229 ++++++++++++ .../win64/dynamixel.cs | 229 ++++++++++++ .../bulk_read/win32/.vs/bulk_read/v14/.suo | Bin 0 -> 36352 bytes c#/protocol1.0/bulk_read/win32/bulk_read.sln | 28 ++ .../bulk_read/win32/bulk_read/App.config | 6 + .../bulk_read/win32/bulk_read/BulkRead.cs | 250 +++++++++++++ .../bulk_read/Properties/AssemblyInfo.cs | 36 ++ .../win32/bulk_read/bulk_read.csproj | 80 ++++ .../bulk_read/win32/bulk_read/dynamixel.cs | 229 ++++++++++++ .../bulk_read/win64/.vs/bulk_read/v14/.suo | Bin 0 -> 38912 bytes c#/protocol1.0/bulk_read/win64/bulk_read.sln | 28 ++ .../bulk_read/win64/bulk_read/App.config | 6 + .../bulk_read/win64/bulk_read/BulkRead.cs | 250 +++++++++++++ .../bulk_read/Properties/AssemblyInfo.cs | 36 ++ .../win64/bulk_read/bulk_read.csproj | 80 ++++ .../bulk_read/win64/bulk_read/dynamixel.cs | 229 ++++++++++++ .../multi_port/win32/.vs/multi_port/v14/.suo | Bin 0 -> 36352 bytes .../multi_port/win32/multi_port.sln | 28 ++ .../multi_port/win32/multi_port/App.config | 6 + .../multi_port/win32/multi_port/MultiPort.cs | 250 +++++++++++++ .../multi_port/Properties/AssemblyInfo.cs | 36 ++ .../multi_port/win32/multi_port/dynamixel.cs | 229 ++++++++++++ .../win32/multi_port/multi_port.csproj | 80 ++++ .../multi_port/win64/.vs/multi_port/v14/.suo | Bin 0 -> 47104 bytes .../multi_port/win64/multi_port.sln | 28 ++ .../multi_port/win64/multi_port/App.config | 6 + .../multi_port/win64/multi_port/MultiPort.cs | 250 +++++++++++++ .../multi_port/Properties/AssemblyInfo.cs | 36 ++ .../multi_port/win64/multi_port/dynamixel.cs | 229 ++++++++++++ .../win64/multi_port/multi_port.csproj | 80 ++++ c#/protocol1.0/ping/win32/.vs/ping/v14/.suo | Bin 0 -> 35840 bytes c#/protocol1.0/ping/win32/ping.sln | 28 ++ c#/protocol1.0/ping/win32/ping/App.config | 6 + c#/protocol1.0/ping/win32/ping/Ping.cs | 99 +++++ .../win32/ping/Properties/AssemblyInfo.cs | 36 ++ c#/protocol1.0/ping/win32/ping/dynamixel.cs | 229 ++++++++++++ c#/protocol1.0/ping/win32/ping/ping.csproj | 80 ++++ c#/protocol1.0/ping/win64/.vs/ping/v14/.suo | Bin 0 -> 47616 bytes c#/protocol1.0/ping/win64/ping.sln | 28 ++ c#/protocol1.0/ping/win64/ping/App.config | 6 + c#/protocol1.0/ping/win64/ping/Ping.cs | 99 +++++ .../win64/ping/Properties/AssemblyInfo.cs | 36 ++ c#/protocol1.0/ping/win64/ping/dynamixel.cs | 229 ++++++++++++ c#/protocol1.0/ping/win64/ping/ping.csproj | 80 ++++ .../read_write/win32/.vs/read_write/v14/.suo | Bin 0 -> 39936 bytes .../read_write/win32/read_write.sln | 28 ++ .../read_write/win32/read_write/App.config | 6 + .../read_write/Properties/AssemblyInfo.cs | 36 ++ .../read_write/win32/read_write/ReadWrite.cs | 170 +++++++++ .../read_write/win32/read_write/dynamixel.cs | 229 ++++++++++++ .../win32/read_write/read_write.csproj | 108 ++++++ .../win32/read_write/read_write.csproj.user | 17 + .../read_write/win64/.vs/read_write/v14/.suo | Bin 0 -> 35840 bytes .../read_write/win64/read_write.sln | 28 ++ .../read_write/win64/read_write/App.config | 6 + .../read_write/Properties/AssemblyInfo.cs | 36 ++ .../read_write/win64/read_write/ReadWrite.cs | 170 +++++++++ .../read_write/win64/read_write/dynamixel.cs | 229 ++++++++++++ .../win64/read_write/read_write.csproj | 107 ++++++ .../win64/read_write/read_write.csproj.user | 17 + c#/protocol1.0/reset/win32/.vs/reset/v14/.suo | Bin 0 -> 35840 bytes c#/protocol1.0/reset/win32/reset.sln | 28 ++ c#/protocol1.0/reset/win32/reset/App.config | 6 + .../win32/reset/Properties/AssemblyInfo.cs | 36 ++ c#/protocol1.0/reset/win32/reset/Reset.cs | 193 ++++++++++ c#/protocol1.0/reset/win32/reset/dynamixel.cs | 229 ++++++++++++ c#/protocol1.0/reset/win32/reset/reset.csproj | 80 ++++ c#/protocol1.0/reset/win64/.vs/reset/v14/.suo | Bin 0 -> 36864 bytes c#/protocol1.0/reset/win64/reset.sln | 28 ++ c#/protocol1.0/reset/win64/reset/App.config | 6 + .../win64/reset/Properties/AssemblyInfo.cs | 36 ++ c#/protocol1.0/reset/win64/reset/Reset.cs | 193 ++++++++++ c#/protocol1.0/reset/win64/reset/dynamixel.cs | 229 ++++++++++++ c#/protocol1.0/reset/win64/reset/reset.csproj | 80 ++++ .../sync_write/win32/.vs/sync_write/v14/.suo | Bin 0 -> 38400 bytes .../sync_write/win32/sync_write.sln | 28 ++ .../sync_write/win32/sync_write/App.config | 6 + .../sync_write/Properties/AssemblyInfo.cs | 36 ++ .../sync_write/win32/sync_write/SyncWrite.cs | 230 ++++++++++++ .../sync_write/win32/sync_write/dynamixel.cs | 229 ++++++++++++ .../win32/sync_write/sync_write.csproj | 80 ++++ .../sync_write/win64/.vs/sync_write/v14/.suo | Bin 0 -> 51712 bytes .../sync_write/win64/sync_write.sln | 28 ++ .../sync_write/win64/sync_write/App.config | 6 + .../sync_write/Properties/AssemblyInfo.cs | 36 ++ .../sync_write/win64/sync_write/SyncWrite.cs | 230 ++++++++++++ .../sync_write/win64/sync_write/dynamixel.cs | 229 ++++++++++++ .../win64/sync_write/sync_write.csproj | 80 ++++ .../win32/.vs/broadcast_ping/v14/.suo | Bin 0 -> 47616 bytes .../broadcast_ping/win32/broadcast_ping.sln | 28 ++ .../win32/broadcast_ping/App.config | 6 + .../win32/broadcast_ping/BroadcastPing.cs | 95 +++++ .../broadcast_ping/Properties/AssemblyInfo.cs | 36 ++ .../broadcast_ping/broadcast_ping.csproj | 80 ++++ .../win32/broadcast_ping/dynamixel.cs | 229 ++++++++++++ .../win64/.vs/broadcast_ping/v14/.suo | Bin 0 -> 47616 bytes .../broadcast_ping/win64/broadcast_ping.sln | 28 ++ .../win64/broadcast_ping/App.config | 6 + .../win64/broadcast_ping/BroadcastPing.cs | 95 +++++ .../broadcast_ping/Properties/AssemblyInfo.cs | 36 ++ .../broadcast_ping/broadcast_ping.csproj | 80 ++++ .../win64/broadcast_ping/dynamixel.cs | 229 ++++++++++++ .../win32/.vs/bulk_read_write/v14/.suo | Bin 0 -> 36352 bytes .../bulk_read_write/win32/bulk_read_write.sln | 28 ++ .../win32/bulk_read_write/App.config | 6 + .../win32/bulk_read_write/BulkReadWrite.cs | 257 +++++++++++++ .../Properties/AssemblyInfo.cs | 36 ++ .../bulk_read_write/bulk_read_write.csproj | 80 ++++ .../win32/bulk_read_write/dynamixel.cs | 229 ++++++++++++ .../win64/.vs/bulk_read_write/v14/.suo | Bin 0 -> 36352 bytes .../bulk_read_write/win64/bulk_read_write.sln | 28 ++ .../win64/bulk_read_write/App.config | 6 + .../win64/bulk_read_write/BulkReadWrite.cs | 257 +++++++++++++ .../Properties/AssemblyInfo.cs | 36 ++ .../bulk_read_write/bulk_read_write.csproj | 80 ++++ .../win64/bulk_read_write/dynamixel.cs | 229 ++++++++++++ .../win32/.vs/factory_reset/v14/.suo | Bin 0 -> 35328 bytes .../factory_reset/win32/factory_reset.sln | 28 ++ .../win32/factory_reset/App.config | 6 + .../win32/factory_reset/FactoryReset.cs | 195 ++++++++++ .../factory_reset/Properties/AssemblyInfo.cs | 36 ++ .../win32/factory_reset/dynamixel.cs | 229 ++++++++++++ .../win32/factory_reset/factory_reset.csproj | 80 ++++ .../win64/.vs/factory_reset/v14/.suo | Bin 0 -> 35328 bytes .../factory_reset/win64/factory_reset.sln | 28 ++ .../win64/factory_reset/App.config | 6 + .../win64/factory_reset/FactoryReset.cs | 195 ++++++++++ .../factory_reset/Properties/AssemblyInfo.cs | 36 ++ .../win64/factory_reset/dynamixel.cs | 229 ++++++++++++ .../win64/factory_reset/factory_reset.csproj | 80 ++++ .../win32/.vs/indirect_address/v14/.suo | Bin 0 -> 36864 bytes .../win32/indirect_address.sln | 28 ++ .../win32/indirect_address/App.config | 6 + .../win32/indirect_address/IndirectAddress.cs | 344 ++++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 ++ .../win32/indirect_address/dynamixel.cs | 229 ++++++++++++ .../indirect_address/indirect_address.csproj | 80 ++++ .../win64/.vs/indirect_address/v14/.suo | Bin 0 -> 36864 bytes .../win64/indirect_address.sln | 28 ++ .../win64/indirect_address/App.config | 6 + .../win64/indirect_address/IndirectAddress.cs | 344 ++++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 ++ .../win64/indirect_address/dynamixel.cs | 229 ++++++++++++ .../indirect_address/indirect_address.csproj | 80 ++++ .../multi_port/win32/.vs/multi_port/v14/.suo | Bin 0 -> 33792 bytes .../multi_port/win32/multi_port.sln | 28 ++ .../multi_port/win32/multi_port/App.config | 6 + .../multi_port/win32/multi_port/MultiPort.cs | 249 +++++++++++++ .../multi_port/Properties/AssemblyInfo.cs | 36 ++ .../multi_port/win32/multi_port/dynamixel.cs | 229 ++++++++++++ .../win32/multi_port/multi_port.csproj | 80 ++++ .../multi_port/win64/.vs/multi_port/v14/.suo | Bin 0 -> 33280 bytes .../multi_port/win64/multi_port.sln | 28 ++ .../multi_port/win64/multi_port/App.config | 6 + .../multi_port/win64/multi_port/MultiPort.cs | 249 +++++++++++++ .../multi_port/Properties/AssemblyInfo.cs | 36 ++ .../multi_port/win64/multi_port/dynamixel.cs | 229 ++++++++++++ .../win64/multi_port/multi_port.csproj | 80 ++++ c#/protocol2.0/ping/win32/.vs/ping/v14/.suo | Bin 0 -> 35840 bytes c#/protocol2.0/ping/win32/ping.sln | 28 ++ c#/protocol2.0/ping/win32/ping/App.config | 6 + c#/protocol2.0/ping/win32/ping/Ping.cs | 99 +++++ .../win32/ping/Properties/AssemblyInfo.cs | 36 ++ c#/protocol2.0/ping/win32/ping/dynamixel.cs | 229 ++++++++++++ c#/protocol2.0/ping/win32/ping/ping.csproj | 80 ++++ c#/protocol2.0/ping/win64/.vs/ping/v14/.suo | Bin 0 -> 15360 bytes c#/protocol2.0/ping/win64/ping.sln | 28 ++ c#/protocol2.0/ping/win64/ping/App.config | 6 + c#/protocol2.0/ping/win64/ping/Ping.cs | 99 +++++ .../win64/ping/Properties/AssemblyInfo.cs | 36 ++ c#/protocol2.0/ping/win64/ping/dynamixel.cs | 229 ++++++++++++ c#/protocol2.0/ping/win64/ping/ping.csproj | 80 ++++ .../read_write/win32/.vs/read_write/v14/.suo | Bin 0 -> 41472 bytes .../read_write/win32/read_write.sln | 28 ++ .../read_write/win32/read_write/App.config | 6 + .../read_write/Properties/AssemblyInfo.cs | 36 ++ .../read_write/win32/read_write/ReadWrite.cs | 170 +++++++++ .../read_write/win32/read_write/dynamixel.cs | 229 ++++++++++++ .../win32/read_write/read_write.csproj | 108 ++++++ .../win32/read_write/read_write.csproj.user | 17 + .../read_write/win64/.vs/read_write/v14/.suo | Bin 0 -> 32768 bytes .../read_write/win64/read_write.sln | 28 ++ .../read_write/win64/read_write/App.config | 6 + .../read_write/Properties/AssemblyInfo.cs | 36 ++ .../read_write/win64/read_write/ReadWrite.cs | 170 +++++++++ .../read_write/win64/read_write/dynamixel.cs | 229 ++++++++++++ .../win64/read_write/read_write.csproj | 107 ++++++ .../win64/read_write/read_write.csproj.user | 17 + .../reboot/win32/.vs/reboot/v14/.suo | Bin 0 -> 40960 bytes c#/protocol2.0/reboot/win32/reboot.sln | 28 ++ c#/protocol2.0/reboot/win32/reboot/App.config | 6 + .../win32/reboot/Properties/AssemblyInfo.cs | 36 ++ c#/protocol2.0/reboot/win32/reboot/Reboot.cs | 104 ++++++ .../reboot/win32/reboot/dynamixel.cs | 229 ++++++++++++ .../reboot/win32/reboot/reboot.csproj | 80 ++++ .../reboot/win64/.vs/reboot/v14/.suo | Bin 0 -> 47104 bytes c#/protocol2.0/reboot/win64/reboot.sln | 28 ++ c#/protocol2.0/reboot/win64/reboot/App.config | 6 + .../win64/reboot/Properties/AssemblyInfo.cs | 36 ++ c#/protocol2.0/reboot/win64/reboot/Reboot.cs | 104 ++++++ .../reboot/win64/reboot/dynamixel.cs | 229 ++++++++++++ .../reboot/win64/reboot/reboot.csproj | 80 ++++ .../win32/.vs/sync_read_write/v14/.suo | Bin 0 -> 36352 bytes .../sync_read_write/win32/sync_read_write.sln | 28 ++ .../win32/sync_read_write/App.config | 6 + .../Properties/AssemblyInfo.cs | 36 ++ .../win32/sync_read_write/SyncReadWrite.cs | 254 +++++++++++++ .../win32/sync_read_write/dynamixel.cs | 229 ++++++++++++ .../sync_read_write/sync_read_write.csproj | 80 ++++ .../win64/.vs/sync_read_write/v14/.suo | Bin 0 -> 58880 bytes .../sync_read_write/win64/sync_read_write.sln | 28 ++ .../win64/sync_read_write/App.config | 6 + .../Properties/AssemblyInfo.cs | 36 ++ .../win64/sync_read_write/SyncReadWrite.cs | 254 +++++++++++++ .../win64/sync_read_write/dynamixel.cs | 229 ++++++++++++ .../sync_read_write/sync_read_write.csproj | 80 ++++ .../win32/.vs/protocol_combined/v14/.suo | Bin 0 -> 37888 bytes .../win32/protocol_combined.sln | 28 ++ .../win32/protocol_combined/App.config | 6 + .../Properties/AssemblyInfo.cs | 36 ++ .../protocol_combined/ProtocolCombined.cs | 234 ++++++++++++ .../win32/protocol_combined/dynamixel.cs | 229 ++++++++++++ .../protocol_combined.csproj | 80 ++++ .../win64/.vs/protocol_combined/v14/.suo | Bin 0 -> 49152 bytes .../win64/protocol_combined.sln | 28 ++ .../win64/protocol_combined/App.config | 6 + .../Properties/AssemblyInfo.cs | 36 ++ .../protocol_combined/ProtocolCombined.cs | 234 ++++++++++++ .../win64/protocol_combined/dynamixel.cs | 229 ++++++++++++ .../protocol_combined.csproj | 80 ++++ 230 files changed, 19150 insertions(+) create mode 100644 c#/dynamixel_functions_csharp/win32/dynamixel.cs create mode 100644 c#/dynamixel_functions_csharp/win64/dynamixel.cs create mode 100644 c#/protocol1.0/bulk_read/win32/.vs/bulk_read/v14/.suo create mode 100644 c#/protocol1.0/bulk_read/win32/bulk_read.sln create mode 100644 c#/protocol1.0/bulk_read/win32/bulk_read/App.config create mode 100644 c#/protocol1.0/bulk_read/win32/bulk_read/BulkRead.cs create mode 100644 c#/protocol1.0/bulk_read/win32/bulk_read/Properties/AssemblyInfo.cs create mode 100644 c#/protocol1.0/bulk_read/win32/bulk_read/bulk_read.csproj create mode 100644 c#/protocol1.0/bulk_read/win32/bulk_read/dynamixel.cs create mode 100644 c#/protocol1.0/bulk_read/win64/.vs/bulk_read/v14/.suo create mode 100644 c#/protocol1.0/bulk_read/win64/bulk_read.sln create mode 100644 c#/protocol1.0/bulk_read/win64/bulk_read/App.config create mode 100644 c#/protocol1.0/bulk_read/win64/bulk_read/BulkRead.cs create mode 100644 c#/protocol1.0/bulk_read/win64/bulk_read/Properties/AssemblyInfo.cs create mode 100644 c#/protocol1.0/bulk_read/win64/bulk_read/bulk_read.csproj create mode 100644 c#/protocol1.0/bulk_read/win64/bulk_read/dynamixel.cs create mode 100644 c#/protocol1.0/multi_port/win32/.vs/multi_port/v14/.suo create mode 100644 c#/protocol1.0/multi_port/win32/multi_port.sln create mode 100644 c#/protocol1.0/multi_port/win32/multi_port/App.config create mode 100644 c#/protocol1.0/multi_port/win32/multi_port/MultiPort.cs create mode 100644 c#/protocol1.0/multi_port/win32/multi_port/Properties/AssemblyInfo.cs create mode 100644 c#/protocol1.0/multi_port/win32/multi_port/dynamixel.cs create mode 100644 c#/protocol1.0/multi_port/win32/multi_port/multi_port.csproj create mode 100644 c#/protocol1.0/multi_port/win64/.vs/multi_port/v14/.suo create mode 100644 c#/protocol1.0/multi_port/win64/multi_port.sln create mode 100644 c#/protocol1.0/multi_port/win64/multi_port/App.config create mode 100644 c#/protocol1.0/multi_port/win64/multi_port/MultiPort.cs create mode 100644 c#/protocol1.0/multi_port/win64/multi_port/Properties/AssemblyInfo.cs create mode 100644 c#/protocol1.0/multi_port/win64/multi_port/dynamixel.cs create mode 100644 c#/protocol1.0/multi_port/win64/multi_port/multi_port.csproj create mode 100644 c#/protocol1.0/ping/win32/.vs/ping/v14/.suo create mode 100644 c#/protocol1.0/ping/win32/ping.sln create mode 100644 c#/protocol1.0/ping/win32/ping/App.config create mode 100644 c#/protocol1.0/ping/win32/ping/Ping.cs create mode 100644 c#/protocol1.0/ping/win32/ping/Properties/AssemblyInfo.cs create mode 100644 c#/protocol1.0/ping/win32/ping/dynamixel.cs create mode 100644 c#/protocol1.0/ping/win32/ping/ping.csproj create mode 100644 c#/protocol1.0/ping/win64/.vs/ping/v14/.suo create mode 100644 c#/protocol1.0/ping/win64/ping.sln create mode 100644 c#/protocol1.0/ping/win64/ping/App.config create mode 100644 c#/protocol1.0/ping/win64/ping/Ping.cs create mode 100644 c#/protocol1.0/ping/win64/ping/Properties/AssemblyInfo.cs create mode 100644 c#/protocol1.0/ping/win64/ping/dynamixel.cs create mode 100644 c#/protocol1.0/ping/win64/ping/ping.csproj create mode 100644 c#/protocol1.0/read_write/win32/.vs/read_write/v14/.suo create mode 100644 c#/protocol1.0/read_write/win32/read_write.sln create mode 100644 c#/protocol1.0/read_write/win32/read_write/App.config create mode 100644 c#/protocol1.0/read_write/win32/read_write/Properties/AssemblyInfo.cs create mode 100644 c#/protocol1.0/read_write/win32/read_write/ReadWrite.cs create mode 100644 c#/protocol1.0/read_write/win32/read_write/dynamixel.cs create mode 100644 c#/protocol1.0/read_write/win32/read_write/read_write.csproj create mode 100644 c#/protocol1.0/read_write/win32/read_write/read_write.csproj.user create mode 100644 c#/protocol1.0/read_write/win64/.vs/read_write/v14/.suo create mode 100644 c#/protocol1.0/read_write/win64/read_write.sln create mode 100644 c#/protocol1.0/read_write/win64/read_write/App.config create mode 100644 c#/protocol1.0/read_write/win64/read_write/Properties/AssemblyInfo.cs create mode 100644 c#/protocol1.0/read_write/win64/read_write/ReadWrite.cs create mode 100644 c#/protocol1.0/read_write/win64/read_write/dynamixel.cs create mode 100644 c#/protocol1.0/read_write/win64/read_write/read_write.csproj create mode 100644 c#/protocol1.0/read_write/win64/read_write/read_write.csproj.user create mode 100644 c#/protocol1.0/reset/win32/.vs/reset/v14/.suo create mode 100644 c#/protocol1.0/reset/win32/reset.sln create mode 100644 c#/protocol1.0/reset/win32/reset/App.config create mode 100644 c#/protocol1.0/reset/win32/reset/Properties/AssemblyInfo.cs create mode 100644 c#/protocol1.0/reset/win32/reset/Reset.cs create mode 100644 c#/protocol1.0/reset/win32/reset/dynamixel.cs create mode 100644 c#/protocol1.0/reset/win32/reset/reset.csproj create mode 100644 c#/protocol1.0/reset/win64/.vs/reset/v14/.suo create mode 100644 c#/protocol1.0/reset/win64/reset.sln create mode 100644 c#/protocol1.0/reset/win64/reset/App.config create mode 100644 c#/protocol1.0/reset/win64/reset/Properties/AssemblyInfo.cs create mode 100644 c#/protocol1.0/reset/win64/reset/Reset.cs create mode 100644 c#/protocol1.0/reset/win64/reset/dynamixel.cs create mode 100644 c#/protocol1.0/reset/win64/reset/reset.csproj create mode 100644 c#/protocol1.0/sync_write/win32/.vs/sync_write/v14/.suo create mode 100644 c#/protocol1.0/sync_write/win32/sync_write.sln create mode 100644 c#/protocol1.0/sync_write/win32/sync_write/App.config create mode 100644 c#/protocol1.0/sync_write/win32/sync_write/Properties/AssemblyInfo.cs create mode 100644 c#/protocol1.0/sync_write/win32/sync_write/SyncWrite.cs create mode 100644 c#/protocol1.0/sync_write/win32/sync_write/dynamixel.cs create mode 100644 c#/protocol1.0/sync_write/win32/sync_write/sync_write.csproj create mode 100644 c#/protocol1.0/sync_write/win64/.vs/sync_write/v14/.suo create mode 100644 c#/protocol1.0/sync_write/win64/sync_write.sln create mode 100644 c#/protocol1.0/sync_write/win64/sync_write/App.config create mode 100644 c#/protocol1.0/sync_write/win64/sync_write/Properties/AssemblyInfo.cs create mode 100644 c#/protocol1.0/sync_write/win64/sync_write/SyncWrite.cs create mode 100644 c#/protocol1.0/sync_write/win64/sync_write/dynamixel.cs create mode 100644 c#/protocol1.0/sync_write/win64/sync_write/sync_write.csproj create mode 100644 c#/protocol2.0/broadcast_ping/win32/.vs/broadcast_ping/v14/.suo create mode 100644 c#/protocol2.0/broadcast_ping/win32/broadcast_ping.sln create mode 100644 c#/protocol2.0/broadcast_ping/win32/broadcast_ping/App.config create mode 100644 c#/protocol2.0/broadcast_ping/win32/broadcast_ping/BroadcastPing.cs create mode 100644 c#/protocol2.0/broadcast_ping/win32/broadcast_ping/Properties/AssemblyInfo.cs create mode 100644 c#/protocol2.0/broadcast_ping/win32/broadcast_ping/broadcast_ping.csproj create mode 100644 c#/protocol2.0/broadcast_ping/win32/broadcast_ping/dynamixel.cs create mode 100644 c#/protocol2.0/broadcast_ping/win64/.vs/broadcast_ping/v14/.suo create mode 100644 c#/protocol2.0/broadcast_ping/win64/broadcast_ping.sln create mode 100644 c#/protocol2.0/broadcast_ping/win64/broadcast_ping/App.config create mode 100644 c#/protocol2.0/broadcast_ping/win64/broadcast_ping/BroadcastPing.cs create mode 100644 c#/protocol2.0/broadcast_ping/win64/broadcast_ping/Properties/AssemblyInfo.cs create mode 100644 c#/protocol2.0/broadcast_ping/win64/broadcast_ping/broadcast_ping.csproj create mode 100644 c#/protocol2.0/broadcast_ping/win64/broadcast_ping/dynamixel.cs create mode 100644 c#/protocol2.0/bulk_read_write/win32/.vs/bulk_read_write/v14/.suo create mode 100644 c#/protocol2.0/bulk_read_write/win32/bulk_read_write.sln create mode 100644 c#/protocol2.0/bulk_read_write/win32/bulk_read_write/App.config create mode 100644 c#/protocol2.0/bulk_read_write/win32/bulk_read_write/BulkReadWrite.cs create mode 100644 c#/protocol2.0/bulk_read_write/win32/bulk_read_write/Properties/AssemblyInfo.cs create mode 100644 c#/protocol2.0/bulk_read_write/win32/bulk_read_write/bulk_read_write.csproj create mode 100644 c#/protocol2.0/bulk_read_write/win32/bulk_read_write/dynamixel.cs create mode 100644 c#/protocol2.0/bulk_read_write/win64/.vs/bulk_read_write/v14/.suo create mode 100644 c#/protocol2.0/bulk_read_write/win64/bulk_read_write.sln create mode 100644 c#/protocol2.0/bulk_read_write/win64/bulk_read_write/App.config create mode 100644 c#/protocol2.0/bulk_read_write/win64/bulk_read_write/BulkReadWrite.cs create mode 100644 c#/protocol2.0/bulk_read_write/win64/bulk_read_write/Properties/AssemblyInfo.cs create mode 100644 c#/protocol2.0/bulk_read_write/win64/bulk_read_write/bulk_read_write.csproj create mode 100644 c#/protocol2.0/bulk_read_write/win64/bulk_read_write/dynamixel.cs create mode 100644 c#/protocol2.0/factory_reset/win32/.vs/factory_reset/v14/.suo create mode 100644 c#/protocol2.0/factory_reset/win32/factory_reset.sln create mode 100644 c#/protocol2.0/factory_reset/win32/factory_reset/App.config create mode 100644 c#/protocol2.0/factory_reset/win32/factory_reset/FactoryReset.cs create mode 100644 c#/protocol2.0/factory_reset/win32/factory_reset/Properties/AssemblyInfo.cs create mode 100644 c#/protocol2.0/factory_reset/win32/factory_reset/dynamixel.cs create mode 100644 c#/protocol2.0/factory_reset/win32/factory_reset/factory_reset.csproj create mode 100644 c#/protocol2.0/factory_reset/win64/.vs/factory_reset/v14/.suo create mode 100644 c#/protocol2.0/factory_reset/win64/factory_reset.sln create mode 100644 c#/protocol2.0/factory_reset/win64/factory_reset/App.config create mode 100644 c#/protocol2.0/factory_reset/win64/factory_reset/FactoryReset.cs create mode 100644 c#/protocol2.0/factory_reset/win64/factory_reset/Properties/AssemblyInfo.cs create mode 100644 c#/protocol2.0/factory_reset/win64/factory_reset/dynamixel.cs create mode 100644 c#/protocol2.0/factory_reset/win64/factory_reset/factory_reset.csproj create mode 100644 c#/protocol2.0/indirect_address/win32/.vs/indirect_address/v14/.suo create mode 100644 c#/protocol2.0/indirect_address/win32/indirect_address.sln create mode 100644 c#/protocol2.0/indirect_address/win32/indirect_address/App.config create mode 100644 c#/protocol2.0/indirect_address/win32/indirect_address/IndirectAddress.cs create mode 100644 c#/protocol2.0/indirect_address/win32/indirect_address/Properties/AssemblyInfo.cs create mode 100644 c#/protocol2.0/indirect_address/win32/indirect_address/dynamixel.cs create mode 100644 c#/protocol2.0/indirect_address/win32/indirect_address/indirect_address.csproj create mode 100644 c#/protocol2.0/indirect_address/win64/.vs/indirect_address/v14/.suo create mode 100644 c#/protocol2.0/indirect_address/win64/indirect_address.sln create mode 100644 c#/protocol2.0/indirect_address/win64/indirect_address/App.config create mode 100644 c#/protocol2.0/indirect_address/win64/indirect_address/IndirectAddress.cs create mode 100644 c#/protocol2.0/indirect_address/win64/indirect_address/Properties/AssemblyInfo.cs create mode 100644 c#/protocol2.0/indirect_address/win64/indirect_address/dynamixel.cs create mode 100644 c#/protocol2.0/indirect_address/win64/indirect_address/indirect_address.csproj create mode 100644 c#/protocol2.0/multi_port/win32/.vs/multi_port/v14/.suo create mode 100644 c#/protocol2.0/multi_port/win32/multi_port.sln create mode 100644 c#/protocol2.0/multi_port/win32/multi_port/App.config create mode 100644 c#/protocol2.0/multi_port/win32/multi_port/MultiPort.cs create mode 100644 c#/protocol2.0/multi_port/win32/multi_port/Properties/AssemblyInfo.cs create mode 100644 c#/protocol2.0/multi_port/win32/multi_port/dynamixel.cs create mode 100644 c#/protocol2.0/multi_port/win32/multi_port/multi_port.csproj create mode 100644 c#/protocol2.0/multi_port/win64/.vs/multi_port/v14/.suo create mode 100644 c#/protocol2.0/multi_port/win64/multi_port.sln create mode 100644 c#/protocol2.0/multi_port/win64/multi_port/App.config create mode 100644 c#/protocol2.0/multi_port/win64/multi_port/MultiPort.cs create mode 100644 c#/protocol2.0/multi_port/win64/multi_port/Properties/AssemblyInfo.cs create mode 100644 c#/protocol2.0/multi_port/win64/multi_port/dynamixel.cs create mode 100644 c#/protocol2.0/multi_port/win64/multi_port/multi_port.csproj create mode 100644 c#/protocol2.0/ping/win32/.vs/ping/v14/.suo create mode 100644 c#/protocol2.0/ping/win32/ping.sln create mode 100644 c#/protocol2.0/ping/win32/ping/App.config create mode 100644 c#/protocol2.0/ping/win32/ping/Ping.cs create mode 100644 c#/protocol2.0/ping/win32/ping/Properties/AssemblyInfo.cs create mode 100644 c#/protocol2.0/ping/win32/ping/dynamixel.cs create mode 100644 c#/protocol2.0/ping/win32/ping/ping.csproj create mode 100644 c#/protocol2.0/ping/win64/.vs/ping/v14/.suo create mode 100644 c#/protocol2.0/ping/win64/ping.sln create mode 100644 c#/protocol2.0/ping/win64/ping/App.config create mode 100644 c#/protocol2.0/ping/win64/ping/Ping.cs create mode 100644 c#/protocol2.0/ping/win64/ping/Properties/AssemblyInfo.cs create mode 100644 c#/protocol2.0/ping/win64/ping/dynamixel.cs create mode 100644 c#/protocol2.0/ping/win64/ping/ping.csproj create mode 100644 c#/protocol2.0/read_write/win32/.vs/read_write/v14/.suo create mode 100644 c#/protocol2.0/read_write/win32/read_write.sln create mode 100644 c#/protocol2.0/read_write/win32/read_write/App.config create mode 100644 c#/protocol2.0/read_write/win32/read_write/Properties/AssemblyInfo.cs create mode 100644 c#/protocol2.0/read_write/win32/read_write/ReadWrite.cs create mode 100644 c#/protocol2.0/read_write/win32/read_write/dynamixel.cs create mode 100644 c#/protocol2.0/read_write/win32/read_write/read_write.csproj create mode 100644 c#/protocol2.0/read_write/win32/read_write/read_write.csproj.user create mode 100644 c#/protocol2.0/read_write/win64/.vs/read_write/v14/.suo create mode 100644 c#/protocol2.0/read_write/win64/read_write.sln create mode 100644 c#/protocol2.0/read_write/win64/read_write/App.config create mode 100644 c#/protocol2.0/read_write/win64/read_write/Properties/AssemblyInfo.cs create mode 100644 c#/protocol2.0/read_write/win64/read_write/ReadWrite.cs create mode 100644 c#/protocol2.0/read_write/win64/read_write/dynamixel.cs create mode 100644 c#/protocol2.0/read_write/win64/read_write/read_write.csproj create mode 100644 c#/protocol2.0/read_write/win64/read_write/read_write.csproj.user create mode 100644 c#/protocol2.0/reboot/win32/.vs/reboot/v14/.suo create mode 100644 c#/protocol2.0/reboot/win32/reboot.sln create mode 100644 c#/protocol2.0/reboot/win32/reboot/App.config create mode 100644 c#/protocol2.0/reboot/win32/reboot/Properties/AssemblyInfo.cs create mode 100644 c#/protocol2.0/reboot/win32/reboot/Reboot.cs create mode 100644 c#/protocol2.0/reboot/win32/reboot/dynamixel.cs create mode 100644 c#/protocol2.0/reboot/win32/reboot/reboot.csproj create mode 100644 c#/protocol2.0/reboot/win64/.vs/reboot/v14/.suo create mode 100644 c#/protocol2.0/reboot/win64/reboot.sln create mode 100644 c#/protocol2.0/reboot/win64/reboot/App.config create mode 100644 c#/protocol2.0/reboot/win64/reboot/Properties/AssemblyInfo.cs create mode 100644 c#/protocol2.0/reboot/win64/reboot/Reboot.cs create mode 100644 c#/protocol2.0/reboot/win64/reboot/dynamixel.cs create mode 100644 c#/protocol2.0/reboot/win64/reboot/reboot.csproj create mode 100644 c#/protocol2.0/sync_read_write/win32/.vs/sync_read_write/v14/.suo create mode 100644 c#/protocol2.0/sync_read_write/win32/sync_read_write.sln create mode 100644 c#/protocol2.0/sync_read_write/win32/sync_read_write/App.config create mode 100644 c#/protocol2.0/sync_read_write/win32/sync_read_write/Properties/AssemblyInfo.cs create mode 100644 c#/protocol2.0/sync_read_write/win32/sync_read_write/SyncReadWrite.cs create mode 100644 c#/protocol2.0/sync_read_write/win32/sync_read_write/dynamixel.cs create mode 100644 c#/protocol2.0/sync_read_write/win32/sync_read_write/sync_read_write.csproj create mode 100644 c#/protocol2.0/sync_read_write/win64/.vs/sync_read_write/v14/.suo create mode 100644 c#/protocol2.0/sync_read_write/win64/sync_read_write.sln create mode 100644 c#/protocol2.0/sync_read_write/win64/sync_read_write/App.config create mode 100644 c#/protocol2.0/sync_read_write/win64/sync_read_write/Properties/AssemblyInfo.cs create mode 100644 c#/protocol2.0/sync_read_write/win64/sync_read_write/SyncReadWrite.cs create mode 100644 c#/protocol2.0/sync_read_write/win64/sync_read_write/dynamixel.cs create mode 100644 c#/protocol2.0/sync_read_write/win64/sync_read_write/sync_read_write.csproj create mode 100644 c#/protocol_combined/win32/.vs/protocol_combined/v14/.suo create mode 100644 c#/protocol_combined/win32/protocol_combined.sln create mode 100644 c#/protocol_combined/win32/protocol_combined/App.config create mode 100644 c#/protocol_combined/win32/protocol_combined/Properties/AssemblyInfo.cs create mode 100644 c#/protocol_combined/win32/protocol_combined/ProtocolCombined.cs create mode 100644 c#/protocol_combined/win32/protocol_combined/dynamixel.cs create mode 100644 c#/protocol_combined/win32/protocol_combined/protocol_combined.csproj create mode 100644 c#/protocol_combined/win64/.vs/protocol_combined/v14/.suo create mode 100644 c#/protocol_combined/win64/protocol_combined.sln create mode 100644 c#/protocol_combined/win64/protocol_combined/App.config create mode 100644 c#/protocol_combined/win64/protocol_combined/Properties/AssemblyInfo.cs create mode 100644 c#/protocol_combined/win64/protocol_combined/ProtocolCombined.cs create mode 100644 c#/protocol_combined/win64/protocol_combined/dynamixel.cs create mode 100644 c#/protocol_combined/win64/protocol_combined/protocol_combined.csproj diff --git a/c#/dynamixel_functions_csharp/win32/dynamixel.cs b/c#/dynamixel_functions_csharp/win32/dynamixel.cs new file mode 100644 index 00000000..235af316 --- /dev/null +++ b/c#/dynamixel_functions_csharp/win32/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win32/output/dxl_x86_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/dynamixel_functions_csharp/win64/dynamixel.cs b/c#/dynamixel_functions_csharp/win64/dynamixel.cs new file mode 100644 index 00000000..d940e04b --- /dev/null +++ b/c#/dynamixel_functions_csharp/win64/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win64/output/dxl_x64_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol1.0/bulk_read/win32/.vs/bulk_read/v14/.suo b/c#/protocol1.0/bulk_read/win32/.vs/bulk_read/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..0413f956afc522e022f0580344c7764578c6bc65 GIT binary patch literal 36352 zcmeHQZHybod0xtLB3o*{?7C^1$c*E-PJCqeeWYyJ=BIS=$vTTC$&Kiq_Lh4m>XsiS zdD5wt@&P1;|D58r2@)qUf&k8sAaMfJF;E~Vg4jt~7l_-U{nP#lS_EhkplGZ< z&kl!NE|=tzcRC$u4lz5!+1Z(S=Y8j$ciwqt_tjV4`EOr-;XVJZ*xbX)Ey^3$Z&Ti4 zN%tVWPyT<0qU=YUX>VM=ex1p;z#}?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m4f`kY zHXuLFNzf8nym>hV3#lUT*0Fzl5dU`4vWu%%Y4|3$J!^OwS{Nkk}%ceo2~d=fi&>RwH&STI6K%O6<8-$mtl;>?@@S^*FBjd z0sNi`MU%l)Di!nvvhfT~J0^0zcs3mLWz&IlFdGYIQsL;etDVD$?HEoz;!^+@uWCmM zo95g7Yx3>>Mcdo`i}LOMjpD}OxBIsXw|q%}Y5c?h>brXN88xQOM%BpV6(5~*0g7Y@gwiBKpVN`^w$Qh&P}&DZb_ z(psTZ(TvTa-VH?o$7{_GT7;Hx`capF_%FDI;GZM}!CW+vNn~QaWH=r0MPli+FCNUq zec@0hn2ZN3z>vtO)!InFfa>$PjAIMS$4{qhU(0yl0cW^Yj8bKDt55@O zRxSwSh$Q!rWu|)Q987h-QL@pW@<;zhi4zyQNp-pSCQ2;9Q{406_^zGe#soB`+wS@A zdm;C9e*u(l96AGgdVYn7Z!HQAY#HrVU&DMm+1~)_)^j?aG<5C;OswWI@`k_iAPIh` zRV!;H$~DSc9;$2_#>38S8YR`8{F_9PJ1hU%C9=`vy}clhPlNnhD2>AFcp8l7Cbsv+ zif-z>+5C$zy}D=l*RUgG&KAJpjR@|zGQR^X)<12TZBMO#>|asqUi&0tX{>#cSo>uA sznG?b?K8Dt&elCET6@LNUwECZd$=eadEGO$!^XPi8RNS=lP>@LKL++ADgXcg literal 0 HcmV?d00001 diff --git a/c#/protocol1.0/bulk_read/win32/bulk_read.sln b/c#/protocol1.0/bulk_read/win32/bulk_read.sln new file mode 100644 index 00000000..6898b7cf --- /dev/null +++ b/c#/protocol1.0/bulk_read/win32/bulk_read.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 14 for Windows Desktop +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bulk_read", "bulk_read\bulk_read.csproj", "{25A1BBB1-0E8D-4F9F-8E31-EC0C1E61DB35}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {25A1BBB1-0E8D-4F9F-8E31-EC0C1E61DB35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {25A1BBB1-0E8D-4F9F-8E31-EC0C1E61DB35}.Debug|Any CPU.Build.0 = Debug|Any CPU + {25A1BBB1-0E8D-4F9F-8E31-EC0C1E61DB35}.Debug|x86.ActiveCfg = Debug|x86 + {25A1BBB1-0E8D-4F9F-8E31-EC0C1E61DB35}.Debug|x86.Build.0 = Debug|x86 + {25A1BBB1-0E8D-4F9F-8E31-EC0C1E61DB35}.Release|Any CPU.ActiveCfg = Release|Any CPU + {25A1BBB1-0E8D-4F9F-8E31-EC0C1E61DB35}.Release|Any CPU.Build.0 = Release|Any CPU + {25A1BBB1-0E8D-4F9F-8E31-EC0C1E61DB35}.Release|x86.ActiveCfg = Release|x86 + {25A1BBB1-0E8D-4F9F-8E31-EC0C1E61DB35}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/c#/protocol1.0/bulk_read/win32/bulk_read/App.config b/c#/protocol1.0/bulk_read/win32/bulk_read/App.config new file mode 100644 index 00000000..8e156463 --- /dev/null +++ b/c#/protocol1.0/bulk_read/win32/bulk_read/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/c#/protocol1.0/bulk_read/win32/bulk_read/BulkRead.cs b/c#/protocol1.0/bulk_read/win32/bulk_read/BulkRead.cs new file mode 100644 index 00000000..37acd838 --- /dev/null +++ b/c#/protocol1.0/bulk_read/win32/bulk_read/BulkRead.cs @@ -0,0 +1,250 @@ +/* +* bulk_read.cs +* +* Created on: 2016. 5. 16. +* Author: Leon Ryu Woon Jung +*/ + +// +// ********* Bulk Read Example ********* +// +// +// Available Dynamixel model on this example : MX or X series set to Protocol 1.0 +// This example is designed for using two Dynamixel MX-28, and an USB2DYNAMIXEL. +// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below variables yourself. +// Be sure that Dynamixel MX properties are already set as %% ID : 1 / Baudnum : 1 (Baudrate : 1000000) +// + +using System; +using dynamixel_sdk; + +namespace bulk_read +{ + class BulkRead + { + // Control table address + public const int ADDR_MX_TORQUE_ENABLE = 24; // Control table address is different in Dynamixel model + public const int ADDR_MX_GOAL_POSITION = 30; + public const int ADDR_MX_PRESENT_POSITION = 36; + public const int ADDR_MX_MOVING = 46; + + // Data Byte Length + public const int LEN_MX_GOAL_POSITION = 2; + public const int LEN_MX_PRESENT_POSITION = 2; + public const int LEN_MX_MOVING = 1; + + // Protocol version + public const int PROTOCOL_VERSION = 1; // See which protocol version is used in the Dynamixel + + // Default setting + public const int DXL1_ID = 1; // Dynamixel ID: 1 + public const int DXL2_ID = 2; // Dynamixel ID: 2 + public const int BAUDRATE = 1000000; + public const string DEVICENAME = "COM8"; // Check which port is being used on your controller + // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const int TORQUE_ENABLE = 1; // Value for enabling the torque + public const int TORQUE_DISABLE = 0; // Value for disabling the torque + public const int DXL_MINIMUM_POSITION_VALUE = 100; // Dynamixel will rotate between this value + public const int DXL_MAXIMUM_POSITION_VALUE = 4000; // and this value (note that the Dynamixel would not move when the position value is out of movable range. Check e-manual about the range of the Dynamixel you use.) + public const int DXL_MOVING_STATUS_THRESHOLD = 10; // Dynamixel moving status threshold + + public const byte ESC_ASCII_VALUE = 0x1b; + + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num = dynamixel.portHandler(DEVICENAME); + + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + // Initialize Groupbulkread Structs + int group_num = dynamixel.groupBulkRead(port_num, PROTOCOL_VERSION); + + int index = 0; + int dxl_comm_result = COMM_TX_FAIL; // Communication result + bool dxl_addparam_result = false; // AddParam result + bool dxl_getdata_result = false; // GetParam result + UInt16[] dxl_goal_position = new UInt16[2]{ DXL_MINIMUM_POSITION_VALUE, DXL_MAXIMUM_POSITION_VALUE }; // Goal position + + byte dxl_error = 0; // Dynamixel error + UInt16 dxl1_present_position = 0; // Present position + byte dxl2_moving = 0; // Dynamixel moving status + + // Open port + if (dynamixel.openPort(port_num)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port baudrate + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Enable Dynamixel#1 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL1_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("Dynamixel{0} has been successfully connected ", DXL1_ID); + } + + // Enable Dynamixel#2 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL2_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("Dynamixel{0} has been successfully connected ", DXL1_ID); + } + + // Add parameter storage for Dynamixel#1 present position value + dxl_addparam_result = dynamixel.groupBulkReadAddParam(group_num, DXL1_ID, ADDR_MX_PRESENT_POSITION, LEN_MX_PRESENT_POSITION); + if (dxl_addparam_result != true) + { + Console.WriteLine("[ID:{0}] groupBulkRead addparam failed", DXL1_ID); + return; + } + + // Add parameter storage for Dynamixel#2 present moving value + dxl_addparam_result = dynamixel.groupBulkReadAddParam(group_num, DXL2_ID, ADDR_MX_MOVING, LEN_MX_MOVING); + if (dxl_addparam_result != true) + { + Console.WriteLine("[ID:{0}] groupBulkRead addparam failed", DXL2_ID); + return; + } + + while (true) + { + Console.WriteLine("Press any key to continue! (or press ESC to quit!)"); + if (Console.ReadKey().KeyChar == ESC_ASCII_VALUE) + break; + + // Write Dynamixel#1 goal position + dynamixel.write2ByteTxRx(port_num, PROTOCOL_VERSION, DXL1_ID, ADDR_MX_GOAL_POSITION, dxl_goal_position[index]); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Write Dynamixel#2 goal position + dynamixel.write2ByteTxRx(port_num, PROTOCOL_VERSION, DXL2_ID, ADDR_MX_GOAL_POSITION, dxl_goal_position[index]); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + do + { + // Bulkread present position and moving status + dynamixel.groupBulkReadTxRxPacket(group_num); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + + dxl_getdata_result = dynamixel.groupBulkReadIsAvailable(group_num, DXL1_ID, ADDR_MX_PRESENT_POSITION, LEN_MX_PRESENT_POSITION); + if (dxl_getdata_result != true) + { + Console.WriteLine("[ID:{0}] groupBulkRead getdata failed", DXL1_ID); + return; + } + + dxl_getdata_result = dynamixel.groupBulkReadIsAvailable(group_num, DXL2_ID, ADDR_MX_MOVING, LEN_MX_MOVING); + if (dxl_getdata_result != true) + { + Console.WriteLine("[ID:{0}] groupBulkRead getdata failed", DXL2_ID); + return; + } + + // Get Dynamixel#1 present position value + dxl1_present_position = (UInt16)dynamixel.groupBulkReadGetData(group_num, DXL1_ID, ADDR_MX_PRESENT_POSITION, LEN_MX_PRESENT_POSITION); + + // Get Dynamixel#2 moving status value + dxl2_moving = (byte)dynamixel.groupBulkReadGetData(group_num, DXL2_ID, ADDR_MX_MOVING, LEN_MX_MOVING); + + Console.WriteLine("[ID:{0}] Present Position : {1} [ID:{2}] Is Moving : {3}", DXL1_ID, dxl1_present_position, DXL2_ID, dxl2_moving); + + } while (Math.Abs(dxl_goal_position[index] - dxl1_present_position) > DXL_MOVING_STATUS_THRESHOLD); + + // Change goal position + if (index == 0) + { + index = 1; + } + else + { + index = 0; + } + } + + // Disable Dynamixel#1 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL1_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Disable Dynamixel#2 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL2_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Close port + dynamixel.closePort(port_num); + + return; + } + } +} diff --git a/c#/protocol1.0/bulk_read/win32/bulk_read/Properties/AssemblyInfo.cs b/c#/protocol1.0/bulk_read/win32/bulk_read/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..e3b1468a --- /dev/null +++ b/c#/protocol1.0/bulk_read/win32/bulk_read/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("bulk_read")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("bulk_read")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("25a1bbb1-0e8d-4f9f-8e31-ec0c1e61db35")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol1.0/bulk_read/win32/bulk_read/bulk_read.csproj b/c#/protocol1.0/bulk_read/win32/bulk_read/bulk_read.csproj new file mode 100644 index 00000000..8126756e --- /dev/null +++ b/c#/protocol1.0/bulk_read/win32/bulk_read/bulk_read.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {25A1BBB1-0E8D-4F9F-8E31-EC0C1E61DB35} + Exe + Properties + bulk_read + bulk_read + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/c#/protocol1.0/bulk_read/win32/bulk_read/dynamixel.cs b/c#/protocol1.0/bulk_read/win32/bulk_read/dynamixel.cs new file mode 100644 index 00000000..235af316 --- /dev/null +++ b/c#/protocol1.0/bulk_read/win32/bulk_read/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win32/output/dxl_x86_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol1.0/bulk_read/win64/.vs/bulk_read/v14/.suo b/c#/protocol1.0/bulk_read/win64/.vs/bulk_read/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..78081c92f72213fe24f9bad7992daa6cd087b439 GIT binary patch literal 38912 zcmeHQYm6IL6&|N8Bs5U^pp;i?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=F9(P1*sLd@&CR3E@>k*CTqWU_I=2mvSR;-)3xi3i;V4#A8m=Fu@BM@ zJ8l7_+cSXe8h_dwk=cnOWt-(r1GdAue}MOgB{Scc&xbu{zE6L+HErb@%X0d>#LN6{ z{5SWgj~2h}#(z71Po3a3H~w33#k?dU77te%)zDz2R3T9%#bTS;h zdS!WCUtOweYBAqF^A{SmdiCO!!omDHUV+=l*L1a6s@B)?MXj;gtk!V6r0G0vR@Alf zhNd@)tNB9Xf?BWT@o2MJsOmv~pi^Z2a=8+Vn0~jP1hOkvo=U`0vyn(5j=Dw?sB0?b zi^pRLUmz9<#lwMUBsLql3cVQbnVr`@vak4)_dm3~+8OtSL+M~59>~U0!Q|B|#SMLF zBOY5S)Ig=qx&KmOL(-P77jEPiByH0z+8&)>Ja#IXPfOC~(vRc|4?K`BR|@)iQR~or z2}EDg%a!$we63nYC4b!CZeDvdV0Y+9}n64$kERTa%&}lQO7MfLK%K@JjjzoPZMDfkViX~rEQ%m8w zh^B>ObN)aeFdL3v;azjOM=}0v(sb#G7s&hK{{&=hOt*)g-iNsN?tkFq8=p=?!t!4j z_|_=7Q^vk1u3vw-h1I7VM3dn2o0atTV(v*cZm)UdUq~Iy_ZbFK#B`5?aYf7xN7UH~ z>dJpt{!gp?H~)k2X!4U%_1YHXr!P*K#AL-^54*cd(|Rn zuko#@MRc(;CBHAV`cxnpi$%j(Uvw@L@qmIHwM4tOI(OjgN1y-2-mkvx$F04#&ddC{XS;en%x})H^MWLe zcc88sYtzmPNAe$gI=K5+zrUudkNxuLGuppM3G@Cg^EvNLf_)44JDHmOIw`-ECQ&wQ*xxWj9OOUF(hk o5pJV#cM(tG{dJs&-83ErZY)O$9jyPqw7KJ-|BLu?{-@sm03ZcFp8x;= literal 0 HcmV?d00001 diff --git a/c#/protocol1.0/bulk_read/win64/bulk_read.sln b/c#/protocol1.0/bulk_read/win64/bulk_read.sln new file mode 100644 index 00000000..aa1eeb20 --- /dev/null +++ b/c#/protocol1.0/bulk_read/win64/bulk_read.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 14 for Windows Desktop +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bulk_read", "bulk_read\bulk_read.csproj", "{25A1BBB1-0E8D-4F9F-8E31-EC0C1E61DB35}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {25A1BBB1-0E8D-4F9F-8E31-EC0C1E61DB35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {25A1BBB1-0E8D-4F9F-8E31-EC0C1E61DB35}.Debug|Any CPU.Build.0 = Debug|Any CPU + {25A1BBB1-0E8D-4F9F-8E31-EC0C1E61DB35}.Debug|x64.ActiveCfg = Release|x64 + {25A1BBB1-0E8D-4F9F-8E31-EC0C1E61DB35}.Debug|x64.Build.0 = Release|x64 + {25A1BBB1-0E8D-4F9F-8E31-EC0C1E61DB35}.Release|Any CPU.ActiveCfg = Release|Any CPU + {25A1BBB1-0E8D-4F9F-8E31-EC0C1E61DB35}.Release|Any CPU.Build.0 = Release|Any CPU + {25A1BBB1-0E8D-4F9F-8E31-EC0C1E61DB35}.Release|x64.ActiveCfg = Release|x64 + {25A1BBB1-0E8D-4F9F-8E31-EC0C1E61DB35}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/c#/protocol1.0/bulk_read/win64/bulk_read/App.config b/c#/protocol1.0/bulk_read/win64/bulk_read/App.config new file mode 100644 index 00000000..8e156463 --- /dev/null +++ b/c#/protocol1.0/bulk_read/win64/bulk_read/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/c#/protocol1.0/bulk_read/win64/bulk_read/BulkRead.cs b/c#/protocol1.0/bulk_read/win64/bulk_read/BulkRead.cs new file mode 100644 index 00000000..37acd838 --- /dev/null +++ b/c#/protocol1.0/bulk_read/win64/bulk_read/BulkRead.cs @@ -0,0 +1,250 @@ +/* +* bulk_read.cs +* +* Created on: 2016. 5. 16. +* Author: Leon Ryu Woon Jung +*/ + +// +// ********* Bulk Read Example ********* +// +// +// Available Dynamixel model on this example : MX or X series set to Protocol 1.0 +// This example is designed for using two Dynamixel MX-28, and an USB2DYNAMIXEL. +// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below variables yourself. +// Be sure that Dynamixel MX properties are already set as %% ID : 1 / Baudnum : 1 (Baudrate : 1000000) +// + +using System; +using dynamixel_sdk; + +namespace bulk_read +{ + class BulkRead + { + // Control table address + public const int ADDR_MX_TORQUE_ENABLE = 24; // Control table address is different in Dynamixel model + public const int ADDR_MX_GOAL_POSITION = 30; + public const int ADDR_MX_PRESENT_POSITION = 36; + public const int ADDR_MX_MOVING = 46; + + // Data Byte Length + public const int LEN_MX_GOAL_POSITION = 2; + public const int LEN_MX_PRESENT_POSITION = 2; + public const int LEN_MX_MOVING = 1; + + // Protocol version + public const int PROTOCOL_VERSION = 1; // See which protocol version is used in the Dynamixel + + // Default setting + public const int DXL1_ID = 1; // Dynamixel ID: 1 + public const int DXL2_ID = 2; // Dynamixel ID: 2 + public const int BAUDRATE = 1000000; + public const string DEVICENAME = "COM8"; // Check which port is being used on your controller + // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const int TORQUE_ENABLE = 1; // Value for enabling the torque + public const int TORQUE_DISABLE = 0; // Value for disabling the torque + public const int DXL_MINIMUM_POSITION_VALUE = 100; // Dynamixel will rotate between this value + public const int DXL_MAXIMUM_POSITION_VALUE = 4000; // and this value (note that the Dynamixel would not move when the position value is out of movable range. Check e-manual about the range of the Dynamixel you use.) + public const int DXL_MOVING_STATUS_THRESHOLD = 10; // Dynamixel moving status threshold + + public const byte ESC_ASCII_VALUE = 0x1b; + + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num = dynamixel.portHandler(DEVICENAME); + + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + // Initialize Groupbulkread Structs + int group_num = dynamixel.groupBulkRead(port_num, PROTOCOL_VERSION); + + int index = 0; + int dxl_comm_result = COMM_TX_FAIL; // Communication result + bool dxl_addparam_result = false; // AddParam result + bool dxl_getdata_result = false; // GetParam result + UInt16[] dxl_goal_position = new UInt16[2]{ DXL_MINIMUM_POSITION_VALUE, DXL_MAXIMUM_POSITION_VALUE }; // Goal position + + byte dxl_error = 0; // Dynamixel error + UInt16 dxl1_present_position = 0; // Present position + byte dxl2_moving = 0; // Dynamixel moving status + + // Open port + if (dynamixel.openPort(port_num)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port baudrate + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Enable Dynamixel#1 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL1_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("Dynamixel{0} has been successfully connected ", DXL1_ID); + } + + // Enable Dynamixel#2 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL2_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("Dynamixel{0} has been successfully connected ", DXL1_ID); + } + + // Add parameter storage for Dynamixel#1 present position value + dxl_addparam_result = dynamixel.groupBulkReadAddParam(group_num, DXL1_ID, ADDR_MX_PRESENT_POSITION, LEN_MX_PRESENT_POSITION); + if (dxl_addparam_result != true) + { + Console.WriteLine("[ID:{0}] groupBulkRead addparam failed", DXL1_ID); + return; + } + + // Add parameter storage for Dynamixel#2 present moving value + dxl_addparam_result = dynamixel.groupBulkReadAddParam(group_num, DXL2_ID, ADDR_MX_MOVING, LEN_MX_MOVING); + if (dxl_addparam_result != true) + { + Console.WriteLine("[ID:{0}] groupBulkRead addparam failed", DXL2_ID); + return; + } + + while (true) + { + Console.WriteLine("Press any key to continue! (or press ESC to quit!)"); + if (Console.ReadKey().KeyChar == ESC_ASCII_VALUE) + break; + + // Write Dynamixel#1 goal position + dynamixel.write2ByteTxRx(port_num, PROTOCOL_VERSION, DXL1_ID, ADDR_MX_GOAL_POSITION, dxl_goal_position[index]); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Write Dynamixel#2 goal position + dynamixel.write2ByteTxRx(port_num, PROTOCOL_VERSION, DXL2_ID, ADDR_MX_GOAL_POSITION, dxl_goal_position[index]); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + do + { + // Bulkread present position and moving status + dynamixel.groupBulkReadTxRxPacket(group_num); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + + dxl_getdata_result = dynamixel.groupBulkReadIsAvailable(group_num, DXL1_ID, ADDR_MX_PRESENT_POSITION, LEN_MX_PRESENT_POSITION); + if (dxl_getdata_result != true) + { + Console.WriteLine("[ID:{0}] groupBulkRead getdata failed", DXL1_ID); + return; + } + + dxl_getdata_result = dynamixel.groupBulkReadIsAvailable(group_num, DXL2_ID, ADDR_MX_MOVING, LEN_MX_MOVING); + if (dxl_getdata_result != true) + { + Console.WriteLine("[ID:{0}] groupBulkRead getdata failed", DXL2_ID); + return; + } + + // Get Dynamixel#1 present position value + dxl1_present_position = (UInt16)dynamixel.groupBulkReadGetData(group_num, DXL1_ID, ADDR_MX_PRESENT_POSITION, LEN_MX_PRESENT_POSITION); + + // Get Dynamixel#2 moving status value + dxl2_moving = (byte)dynamixel.groupBulkReadGetData(group_num, DXL2_ID, ADDR_MX_MOVING, LEN_MX_MOVING); + + Console.WriteLine("[ID:{0}] Present Position : {1} [ID:{2}] Is Moving : {3}", DXL1_ID, dxl1_present_position, DXL2_ID, dxl2_moving); + + } while (Math.Abs(dxl_goal_position[index] - dxl1_present_position) > DXL_MOVING_STATUS_THRESHOLD); + + // Change goal position + if (index == 0) + { + index = 1; + } + else + { + index = 0; + } + } + + // Disable Dynamixel#1 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL1_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Disable Dynamixel#2 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL2_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Close port + dynamixel.closePort(port_num); + + return; + } + } +} diff --git a/c#/protocol1.0/bulk_read/win64/bulk_read/Properties/AssemblyInfo.cs b/c#/protocol1.0/bulk_read/win64/bulk_read/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..e3b1468a --- /dev/null +++ b/c#/protocol1.0/bulk_read/win64/bulk_read/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("bulk_read")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("bulk_read")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("25a1bbb1-0e8d-4f9f-8e31-ec0c1e61db35")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol1.0/bulk_read/win64/bulk_read/bulk_read.csproj b/c#/protocol1.0/bulk_read/win64/bulk_read/bulk_read.csproj new file mode 100644 index 00000000..67343260 --- /dev/null +++ b/c#/protocol1.0/bulk_read/win64/bulk_read/bulk_read.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {25A1BBB1-0E8D-4F9F-8E31-EC0C1E61DB35} + Exe + Properties + bulk_read + bulk_read + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/c#/protocol1.0/bulk_read/win64/bulk_read/dynamixel.cs b/c#/protocol1.0/bulk_read/win64/bulk_read/dynamixel.cs new file mode 100644 index 00000000..d940e04b --- /dev/null +++ b/c#/protocol1.0/bulk_read/win64/bulk_read/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win64/output/dxl_x64_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol1.0/multi_port/win32/.vs/multi_port/v14/.suo b/c#/protocol1.0/multi_port/win32/.vs/multi_port/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..74e1f9609901e56c394220b87ed089113fd5dfd0 GIT binary patch literal 36352 zcmeHQeT*B&bze%dE!%2S$BLS|sZ1+&zI9{7jPfBB&|6pMROIjp?-*1gKz zrgRVDhvfawD9RDUnfB&eZ@tCj!|;e6xC!ck=am|MEyb&3l`6u9vc;iv?M^6nZIAiM z0dILP{$c&~zy7}GLFD`P&xy2A3^-P?fUOU{3qrPG{rfue;Uu(SB$?6VX7T}JHq?mkHYhn`w_AY z?|?r6|FiJ#gy%3n1po8!?}GmYc;X4$?1g8!?2mWDzZafmN%ub7CoO66*-nOO)bUgB z8Tc&xG5DPB!Er2!I}FLsaZHH| z_rP;(xjvB2b9_k`NhgUD#09x7@Ll@jNMmS6|79LY|K+_5N&g>(e+>RT@LUV{?EUTV zafCDQK6pR;FTw}lgYY5vFnk0)3Lk@?h3ESTgs0)pz&`-ruPe9#zXRUbW5nWiFz*p&zcy8 zMdd2m(?Co!u&*hyIbO;CO4u1XW;8v>BTm{zM;s%U-vCCd!1x^6QO13*N}r) zPn_3{Yo}GGQ9oH3^0#j5=lo{fbQzRONGt7OYQp1lPcC7&yfoCYa69nK9u%kGWki`o0R< zSH@`MFdAherGeQ$$f5rYc?w~t8=brh$J=#22vsQT9%KKm*vAH?V}e z1onR&_XXs=22aj~_ZeU-`S%LOXwyhvMB3AMqM_WYc+xQP)e%zLL7tndY!Lg}0CH6@ z1IkD*p|6Q|+x25>x-kdC*oQmyhZE#NSNLOK^)!sH;EPu=vcxhmwnF=99*yDSp>r!=`}&Jl ze&t_3`jmDu^xaPlU&45AqyUeGnMKHiT&J)t>B-<3wP5|6c*@j^|fDt{3Fm`FY2Z2lCFEdvxHvQKuxV}eI)4*dqM2L#XIIJ_umqB zhURBZaWnt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ev/null +++ b/c#/protocol1.0/multi_port/win32/multi_port.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 14 for Windows Desktop +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "multi_port", "multi_port\multi_port.csproj", "{E974210C-6AEC-47D6-8359-0601C9725C6F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E974210C-6AEC-47D6-8359-0601C9725C6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E974210C-6AEC-47D6-8359-0601C9725C6F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E974210C-6AEC-47D6-8359-0601C9725C6F}.Debug|x86.ActiveCfg = Debug|x86 + {E974210C-6AEC-47D6-8359-0601C9725C6F}.Debug|x86.Build.0 = Debug|x86 + {E974210C-6AEC-47D6-8359-0601C9725C6F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E974210C-6AEC-47D6-8359-0601C9725C6F}.Release|Any CPU.Build.0 = Release|Any CPU + {E974210C-6AEC-47D6-8359-0601C9725C6F}.Release|x86.ActiveCfg = Release|x86 + {E974210C-6AEC-47D6-8359-0601C9725C6F}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/c#/protocol1.0/multi_port/win32/multi_port/App.config b/c#/protocol1.0/multi_port/win32/multi_port/App.config new file mode 100644 index 00000000..8e156463 --- /dev/null +++ b/c#/protocol1.0/multi_port/win32/multi_port/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/c#/protocol1.0/multi_port/win32/multi_port/MultiPort.cs b/c#/protocol1.0/multi_port/win32/multi_port/MultiPort.cs new file mode 100644 index 00000000..3dbee7ee --- /dev/null +++ b/c#/protocol1.0/multi_port/win32/multi_port/MultiPort.cs @@ -0,0 +1,250 @@ +/* +* multi_port.cs +* +* Created on: 2016. 5. 16. +* Author: Leon Ryu Woon Jung +*/ + +// +// ********* Multi Port Example ********* +// +// +// Available Dynamixel model on this example : All models using Protocol 1.0 +// This example is designed for using two Dynamixel MX-28, and two USB2DYNAMIXEL. +// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below variables yourself. +// Be sure that Dynamixel MX properties are already set as %% ID : 1 / Baudnum : 1 (Baudrate : 1000000 [1M]) +// + + +using System; +using dynamixel_sdk; + +namespace read_write +{ + class ReadWrite + { + // Control table address + public const int ADDR_MX_TORQUE_ENABLE = 24; // Control table address is different in Dynamixel model + public const int ADDR_MX_GOAL_POSITION = 30; + public const int ADDR_MX_PRESENT_POSITION = 36; + + // Protocol version + public const int PROTOCOL_VERSION = 1; // See which protocol version is used in the Dynamixel + + // Default setting + public const int DXL1_ID = 1; // Dynamixel ID: 1 + public const int DXL2_ID = 2; // Dynamixel ID: 2 + public const int BAUDRATE = 1000000; + public const string DEVICENAME1 = "COM8"; // Check which port is being used on your controller + public const string DEVICENAME2 = "COM4"; // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const int TORQUE_ENABLE = 1; // Value for enabling the torque + public const int TORQUE_DISABLE = 0; // Value for disabling the torque + public const int DXL_MINIMUM_POSITION_VALUE = 100; // Dynamixel will rotate between this value + public const int DXL_MAXIMUM_POSITION_VALUE = 4000; // and this value (note that the Dynamixel would not move when the position value is out of movable range. Check e-manual about the range of the Dynamixel you use.) + public const int DXL_MOVING_STATUS_THRESHOLD = 10; // Dynamixel moving status threshold + + public const byte ESC_ASCII_VALUE = 0x1b; + + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num1 = dynamixel.portHandler(DEVICENAME1); + int port_num2 = dynamixel.portHandler(DEVICENAME2); + + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + int index = 0; + int dxl_comm_result = COMM_TX_FAIL; // Communication result + UInt16[] dxl_goal_position = new UInt16[2]{ DXL_MINIMUM_POSITION_VALUE, DXL_MAXIMUM_POSITION_VALUE }; // Goal position + + byte dxl_error = 0; // Dynamixel error + UInt16 dxl1_present_position = 0, dxl2_present_position = 0; // Present position + + // Open port1 + if (dynamixel.openPort(port_num1)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Open port2 + if (dynamixel.openPort(port_num2)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port1 baudrate + if (dynamixel.setBaudRate(port_num1, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port2 baudrate + if (dynamixel.setBaudRate(port_num2, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Enable Dynamixel#1 Torque + dynamixel.write1ByteTxRx(port_num1, PROTOCOL_VERSION, DXL1_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num1, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num1, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("Dynamixel#{0} has been successfully connected ", DXL1_ID); + } + + // Enable Dynamixel#2 Torque + dynamixel.write1ByteTxRx(port_num2, PROTOCOL_VERSION, DXL2_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num2, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num2, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("Dynamixel#{0} has been successfully connected ", DXL2_ID); + } + + while (true) + { + Console.WriteLine("Press any key to continue! (or press ESC to quit!)"); + if (Console.ReadKey().KeyChar == ESC_ASCII_VALUE) + break; + + // Write Dynamixel#1 goal position + dynamixel.write2ByteTxRx(port_num1, PROTOCOL_VERSION, DXL1_ID, ADDR_MX_GOAL_POSITION, dxl_goal_position[index]); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num1, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num1, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Write Dynamixel#2 goal position + dynamixel.write2ByteTxRx(port_num2, PROTOCOL_VERSION, DXL2_ID, ADDR_MX_GOAL_POSITION, dxl_goal_position[index]); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num2, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num2, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + do + { + // Read Dynamixel#1 present position + dxl1_present_position = dynamixel.read2ByteTxRx(port_num1, PROTOCOL_VERSION, DXL1_ID, ADDR_MX_PRESENT_POSITION); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num1, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num1, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Read Dynamixel#2 present position + dxl2_present_position = dynamixel.read2ByteTxRx(port_num2, PROTOCOL_VERSION, DXL2_ID, ADDR_MX_PRESENT_POSITION); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num2, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num2, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + Console.WriteLine("[ID:{0}] GoalPos:{1} PresPos:{2} [ID:{3}] GoalPos:{4} PresPos:{5}", DXL1_ID, dxl_goal_position[index], dxl1_present_position, DXL2_ID, dxl_goal_position[index], dxl2_present_position); + + } while ((Math.Abs(dxl_goal_position[index] - dxl1_present_position) > DXL_MOVING_STATUS_THRESHOLD) || (Math.Abs(dxl_goal_position[index] - dxl2_present_position) > DXL_MOVING_STATUS_THRESHOLD)); + + // Change goal position + if (index == 0) + { + index = 1; + } + else + { + index = 0; + } + } + + // Disable Dynamixel#1 Torque + dynamixel.write1ByteTxRx(port_num1, PROTOCOL_VERSION, DXL1_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num1, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num1, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Disable Dynamixel#2 Torque + dynamixel.write1ByteTxRx(port_num2, PROTOCOL_VERSION, DXL2_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num2, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num2, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Close port1 + dynamixel.closePort(port_num1); + + // Close port2 + dynamixel.closePort(port_num2); + + return; + } + } +} diff --git a/c#/protocol1.0/multi_port/win32/multi_port/Properties/AssemblyInfo.cs b/c#/protocol1.0/multi_port/win32/multi_port/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..47770db0 --- /dev/null +++ b/c#/protocol1.0/multi_port/win32/multi_port/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("multi_port")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("multi_port")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("e974210c-6aec-47d6-8359-0601c9725c6f")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol1.0/multi_port/win32/multi_port/dynamixel.cs b/c#/protocol1.0/multi_port/win32/multi_port/dynamixel.cs new file mode 100644 index 00000000..235af316 --- /dev/null +++ b/c#/protocol1.0/multi_port/win32/multi_port/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win32/output/dxl_x86_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol1.0/multi_port/win32/multi_port/multi_port.csproj b/c#/protocol1.0/multi_port/win32/multi_port/multi_port.csproj new file mode 100644 index 00000000..132f67ce --- /dev/null +++ b/c#/protocol1.0/multi_port/win32/multi_port/multi_port.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {E974210C-6AEC-47D6-8359-0601C9725C6F} + Exe + Properties + multi_port + multi_port + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/c#/protocol1.0/multi_port/win64/.vs/multi_port/v14/.suo b/c#/protocol1.0/multi_port/win64/.vs/multi_port/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..7e8068ce710434f0a7878573330ebbf797d0876c GIT binary patch literal 47104 zcmeHQYm6jEeeXFxIOF3LjFUKUo-@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e5%~28oDWu)on*B*RH*kj}_u`>0Bm~O{QlfsX{6qnayTmkz_KHo=qfj ziMd4LdiF=JNAW8-%C}XjH7dqtRquzQv}`sz%}Ucq@RVI$0TR9B8-iab2;%eU+5Bui z6PZiqVv$rPmy68A^D~iTA|IcdiOpwn@vMaaEgagch|y~85TW9F#Ph=9%Bk~N+X>H) zKI#nDs!?lfZk1Y~&FUpd92w*vGFp42Mxkl_NE?;(qnMwu=ogvs{eA~mFsu^?vB6ti(?P}bwwPi-fcJH z(O9X@@xdW|=e~v9<;FKVhf|?0@WHSS)#>%h4aE?0)J>=IM_S z3G9D?{V(Nd>k90DgErB?{ukK)TBX4LN8@Z@{|oGYHQ2~_z9&xu=74En|7&0NHp)%9 G{qOf^OlpPz literal 0 HcmV?d00001 diff --git a/c#/protocol1.0/multi_port/win64/multi_port.sln b/c#/protocol1.0/multi_port/win64/multi_port.sln new file mode 100644 index 00000000..f11ecf68 --- /dev/null +++ b/c#/protocol1.0/multi_port/win64/multi_port.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 14 for Windows Desktop +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "multi_port", "multi_port\multi_port.csproj", "{E974210C-6AEC-47D6-8359-0601C9725C6F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E974210C-6AEC-47D6-8359-0601C9725C6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E974210C-6AEC-47D6-8359-0601C9725C6F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E974210C-6AEC-47D6-8359-0601C9725C6F}.Debug|x64.ActiveCfg = Release|x64 + {E974210C-6AEC-47D6-8359-0601C9725C6F}.Debug|x64.Build.0 = Release|x64 + {E974210C-6AEC-47D6-8359-0601C9725C6F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E974210C-6AEC-47D6-8359-0601C9725C6F}.Release|Any CPU.Build.0 = Release|Any CPU + {E974210C-6AEC-47D6-8359-0601C9725C6F}.Release|x64.ActiveCfg = Release|x64 + {E974210C-6AEC-47D6-8359-0601C9725C6F}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/c#/protocol1.0/multi_port/win64/multi_port/App.config b/c#/protocol1.0/multi_port/win64/multi_port/App.config new file mode 100644 index 00000000..8e156463 --- /dev/null +++ b/c#/protocol1.0/multi_port/win64/multi_port/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/c#/protocol1.0/multi_port/win64/multi_port/MultiPort.cs b/c#/protocol1.0/multi_port/win64/multi_port/MultiPort.cs new file mode 100644 index 00000000..3dbee7ee --- /dev/null +++ b/c#/protocol1.0/multi_port/win64/multi_port/MultiPort.cs @@ -0,0 +1,250 @@ +/* +* multi_port.cs +* +* Created on: 2016. 5. 16. +* Author: Leon Ryu Woon Jung +*/ + +// +// ********* Multi Port Example ********* +// +// +// Available Dynamixel model on this example : All models using Protocol 1.0 +// This example is designed for using two Dynamixel MX-28, and two USB2DYNAMIXEL. +// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below variables yourself. +// Be sure that Dynamixel MX properties are already set as %% ID : 1 / Baudnum : 1 (Baudrate : 1000000 [1M]) +// + + +using System; +using dynamixel_sdk; + +namespace read_write +{ + class ReadWrite + { + // Control table address + public const int ADDR_MX_TORQUE_ENABLE = 24; // Control table address is different in Dynamixel model + public const int ADDR_MX_GOAL_POSITION = 30; + public const int ADDR_MX_PRESENT_POSITION = 36; + + // Protocol version + public const int PROTOCOL_VERSION = 1; // See which protocol version is used in the Dynamixel + + // Default setting + public const int DXL1_ID = 1; // Dynamixel ID: 1 + public const int DXL2_ID = 2; // Dynamixel ID: 2 + public const int BAUDRATE = 1000000; + public const string DEVICENAME1 = "COM8"; // Check which port is being used on your controller + public const string DEVICENAME2 = "COM4"; // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const int TORQUE_ENABLE = 1; // Value for enabling the torque + public const int TORQUE_DISABLE = 0; // Value for disabling the torque + public const int DXL_MINIMUM_POSITION_VALUE = 100; // Dynamixel will rotate between this value + public const int DXL_MAXIMUM_POSITION_VALUE = 4000; // and this value (note that the Dynamixel would not move when the position value is out of movable range. Check e-manual about the range of the Dynamixel you use.) + public const int DXL_MOVING_STATUS_THRESHOLD = 10; // Dynamixel moving status threshold + + public const byte ESC_ASCII_VALUE = 0x1b; + + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num1 = dynamixel.portHandler(DEVICENAME1); + int port_num2 = dynamixel.portHandler(DEVICENAME2); + + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + int index = 0; + int dxl_comm_result = COMM_TX_FAIL; // Communication result + UInt16[] dxl_goal_position = new UInt16[2]{ DXL_MINIMUM_POSITION_VALUE, DXL_MAXIMUM_POSITION_VALUE }; // Goal position + + byte dxl_error = 0; // Dynamixel error + UInt16 dxl1_present_position = 0, dxl2_present_position = 0; // Present position + + // Open port1 + if (dynamixel.openPort(port_num1)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Open port2 + if (dynamixel.openPort(port_num2)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port1 baudrate + if (dynamixel.setBaudRate(port_num1, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port2 baudrate + if (dynamixel.setBaudRate(port_num2, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Enable Dynamixel#1 Torque + dynamixel.write1ByteTxRx(port_num1, PROTOCOL_VERSION, DXL1_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num1, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num1, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("Dynamixel#{0} has been successfully connected ", DXL1_ID); + } + + // Enable Dynamixel#2 Torque + dynamixel.write1ByteTxRx(port_num2, PROTOCOL_VERSION, DXL2_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num2, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num2, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("Dynamixel#{0} has been successfully connected ", DXL2_ID); + } + + while (true) + { + Console.WriteLine("Press any key to continue! (or press ESC to quit!)"); + if (Console.ReadKey().KeyChar == ESC_ASCII_VALUE) + break; + + // Write Dynamixel#1 goal position + dynamixel.write2ByteTxRx(port_num1, PROTOCOL_VERSION, DXL1_ID, ADDR_MX_GOAL_POSITION, dxl_goal_position[index]); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num1, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num1, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Write Dynamixel#2 goal position + dynamixel.write2ByteTxRx(port_num2, PROTOCOL_VERSION, DXL2_ID, ADDR_MX_GOAL_POSITION, dxl_goal_position[index]); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num2, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num2, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + do + { + // Read Dynamixel#1 present position + dxl1_present_position = dynamixel.read2ByteTxRx(port_num1, PROTOCOL_VERSION, DXL1_ID, ADDR_MX_PRESENT_POSITION); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num1, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num1, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Read Dynamixel#2 present position + dxl2_present_position = dynamixel.read2ByteTxRx(port_num2, PROTOCOL_VERSION, DXL2_ID, ADDR_MX_PRESENT_POSITION); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num2, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num2, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + Console.WriteLine("[ID:{0}] GoalPos:{1} PresPos:{2} [ID:{3}] GoalPos:{4} PresPos:{5}", DXL1_ID, dxl_goal_position[index], dxl1_present_position, DXL2_ID, dxl_goal_position[index], dxl2_present_position); + + } while ((Math.Abs(dxl_goal_position[index] - dxl1_present_position) > DXL_MOVING_STATUS_THRESHOLD) || (Math.Abs(dxl_goal_position[index] - dxl2_present_position) > DXL_MOVING_STATUS_THRESHOLD)); + + // Change goal position + if (index == 0) + { + index = 1; + } + else + { + index = 0; + } + } + + // Disable Dynamixel#1 Torque + dynamixel.write1ByteTxRx(port_num1, PROTOCOL_VERSION, DXL1_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num1, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num1, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Disable Dynamixel#2 Torque + dynamixel.write1ByteTxRx(port_num2, PROTOCOL_VERSION, DXL2_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num2, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num2, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Close port1 + dynamixel.closePort(port_num1); + + // Close port2 + dynamixel.closePort(port_num2); + + return; + } + } +} diff --git a/c#/protocol1.0/multi_port/win64/multi_port/Properties/AssemblyInfo.cs b/c#/protocol1.0/multi_port/win64/multi_port/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..47770db0 --- /dev/null +++ b/c#/protocol1.0/multi_port/win64/multi_port/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("multi_port")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("multi_port")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("e974210c-6aec-47d6-8359-0601c9725c6f")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol1.0/multi_port/win64/multi_port/dynamixel.cs b/c#/protocol1.0/multi_port/win64/multi_port/dynamixel.cs new file mode 100644 index 00000000..d940e04b --- /dev/null +++ b/c#/protocol1.0/multi_port/win64/multi_port/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win64/output/dxl_x64_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol1.0/multi_port/win64/multi_port/multi_port.csproj b/c#/protocol1.0/multi_port/win64/multi_port/multi_port.csproj new file mode 100644 index 00000000..c3730f9d --- /dev/null +++ b/c#/protocol1.0/multi_port/win64/multi_port/multi_port.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {E974210C-6AEC-47D6-8359-0601C9725C6F} + Exe + Properties + multi_port + multi_port + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/c#/protocol1.0/ping/win32/.vs/ping/v14/.suo b/c#/protocol1.0/ping/win32/.vs/ping/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..4396c67dc7ea7956a88760887d19a4fa5f8475da GIT binary patch literal 35840 zcmeHQYm6IL6(0AM^g&B$38j?OgiuJLDmitq;^p_Z4ZkdO*LDH8CbLMm#*_syNV9*ImxBpGCxxLDj%KPW9Rj#q5dl0`u{{OI| zT!lE(-ami-Jd>}4N7QvgGy)GR75o~CS4k^ngf-zxX)r0rC$@O%pYuZDM8Kl8uk5rrI5mQhPdDWd=M^Ol-bq|`*Vu2=QSO}Yt8aMgzzI~+_-68Zb8~d;je?g6@C<+ApSV~ z?eL#~zXSf0@Y~_J^`PESK(Pf z8lmj>z!eVR10Ur44{Uqyg3N#GumgO3orWCl{1?L{$Byef=>Tz`bD8s;_vBpIivKs7 zX{2?WFY+Gq(GBDLzuxSV=)w8(q@^-`IfR5EJ$W~-p@c1QVGBHAPP$K;&T-;eLA)Ry zaGd0`42d%gi342UKL#)9zsx7;zx*#l(tpxw(*MuEa}6NelanO}xEq&)`zIQ$I!6Y%mLnt4&&VelN}dNic~UZ;RQ z34Tmh^59GAXkl-+1DuDo;k|Q>f*RTG5{NP>Se~4@3IoJ+aZm)2V`c;g|Nnjaq ztCJg9XaDzu$150PUj`190F4ZwQ8H3$&c@%vdC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0>oPo-A_aJI z|4ge??!7ugeK$B)o+HMyA3VxNod|N#z99>llc|nyr%A_Y-n1pUc)2uxQ`i}_c4QJ z<0G0l%&Agq>=#E&iSKIG{duQnOeI%IaCh>x{^sZLEzfGMSk9N03wmoWa#QB%QXzh3 zQaFDwwnYpo(KOBrtG{ zl>`C~&FXSS*1n19{fCpbBeHhw>fA4J*jKI!*vz=+e_h_^f4S#>4CnbD)PqXL_*&2Z zSw8`F>3`Q#5{H2P6NlDw{^PONxp#z)agFCc?u4|U^#pQ$HS35WcM_)?iZ{i(o&QMH b%B!Y^Q=V6MX};6Z`b}M-arntaZ~6ZLPr?{% literal 0 HcmV?d00001 diff --git a/c#/protocol1.0/ping/win32/ping.sln b/c#/protocol1.0/ping/win32/ping.sln new file mode 100644 index 00000000..bd3e7438 --- /dev/null +++ b/c#/protocol1.0/ping/win32/ping.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 14 for Windows Desktop +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ping", "ping\ping.csproj", "{4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD}.Debug|x86.ActiveCfg = Debug|x86 + {4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD}.Debug|x86.Build.0 = Debug|x86 + {4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD}.Release|Any CPU.Build.0 = Release|Any CPU + {4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD}.Release|x86.ActiveCfg = Release|x86 + {4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/c#/protocol1.0/ping/win32/ping/App.config b/c#/protocol1.0/ping/win32/ping/App.config new file mode 100644 index 00000000..8e156463 --- /dev/null +++ b/c#/protocol1.0/ping/win32/ping/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/c#/protocol1.0/ping/win32/ping/Ping.cs b/c#/protocol1.0/ping/win32/ping/Ping.cs new file mode 100644 index 00000000..450615d1 --- /dev/null +++ b/c#/protocol1.0/ping/win32/ping/Ping.cs @@ -0,0 +1,99 @@ +/* +* ping.cs +* +* Created on: 2016. 5. 16. +* Author: Leon Ryu Woon Jung +*/ + +// +// ********* ping Example ********* +// +// +// Available Dynamixel model on this example : All models using Protocol 1.0 +// This example is designed for using a Dynamixel MX-28, and an USB2DYNAMIXEL. +// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below variables yourself. +// Be sure that Dynamixel MX properties are already set as %% ID : 1 / Baudnum : 1 (Baudrate : 1000000 [1M]) +// + +using System; +using dynamixel_sdk; + +namespace ping +{ + class Ping + { + // Protocol version + public const int PROTOCOL_VERSION = 1; // See which protocol version is used in the Dynamixel + + // Default setting + public const int DXL_ID = 1; // Dynamixel ID: 1 + public const int BAUDRATE = 1000000; + public const string DEVICENAME = "COM8"; // Check which port is being used on your controller + // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const byte ESC_ASCII_VALUE = 0x1b; + + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num = dynamixel.portHandler(DEVICENAME); + + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + int dxl_comm_result = COMM_TX_FAIL; // Communication result + + byte dxl_error = 0; // Dynamixel error + UInt16 dxl_model_number; // Dynamixel model number + + // Open port + if (dynamixel.openPort(port_num)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port baudrate + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + // Try to ping the Dynamixel + // Get Dynamixel model number + dxl_model_number = dynamixel.pingGetModelNum(port_num, PROTOCOL_VERSION, DXL_ID); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + Console.WriteLine("[ID:{0}] ping Succeeded. Dynamixel model number : {1}", DXL_ID, dxl_model_number); + + // Close port + dynamixel.closePort(port_num); + + return; + } + } +} diff --git a/c#/protocol1.0/ping/win32/ping/Properties/AssemblyInfo.cs b/c#/protocol1.0/ping/win32/ping/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..a97376c3 --- /dev/null +++ b/c#/protocol1.0/ping/win32/ping/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("ping")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ping")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("4d6dfb5c-0e72-47b4-9d9a-ac58f5dd3abd")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol1.0/ping/win32/ping/dynamixel.cs b/c#/protocol1.0/ping/win32/ping/dynamixel.cs new file mode 100644 index 00000000..235af316 --- /dev/null +++ b/c#/protocol1.0/ping/win32/ping/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win32/output/dxl_x86_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol1.0/ping/win32/ping/ping.csproj b/c#/protocol1.0/ping/win32/ping/ping.csproj new file mode 100644 index 00000000..6591c52b --- /dev/null +++ b/c#/protocol1.0/ping/win32/ping/ping.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD} + Exe + Properties + ping + ping + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/c#/protocol1.0/ping/win64/.vs/ping/v14/.suo b/c#/protocol1.0/ping/win64/.vs/ping/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..02241436bc1d2559a08135d5b5bd3307395671c7 GIT binary patch literal 47616 zcmeHQYm6J$bsoxcEXR)XaH{52nQ;`?wU#X3yDM2rNDe8flB`X*dL*K|=90q|y~9UH zuC!ZAfsvwUP@qME7D*7qKLR*N&>9621V|gC2AVIwS zzI%C>!y$(puEx=FcP?=_cV_O~$2sSod+xbs=Kkc3_x|*o-~G^kYqoGkdq8_@`(f=J zmg@n;52^F_Xxd@KdF`$3?QLFu0D!0;W(WhH)|&WrwV;;M8aTGKEt1l8II2CkL-S)3 zo@)K^&mZ~OKmSYM8Kisp{W9?qN^EK`YUfdU6|tPQIU$$9+eg8XPvR1Jk!T;hJNoQX zxD56cL6y&PTbhX)v^4`z04_=ZqnFO7&;4~l$7*%iLB?rg@&H~u( z^Emzi-~!+x;1b|Dz-7P^K;dXqezS1R%l@zW6wop*D0mS#n zf^8S~S^p2P53_%`ZNIhuD<0)IPdPw-ehl$Pdih!T`@!BdKJ#A0j{t~w(*4r_iuB(C z90mL~-~)gU0zL%zFyJGA-vMx(cmfavkao=PV>mw5i}U<<5kF%&=QS_GCy@6i0ck)6 zK%Urb{=`uM&o2Y60ImYA0j>i+1Nbc92EdBT-InF`bF34Ay4zs@X-r;t2tfK$)|0=; z4;%w1kI5gTyLy(#$9w0a=&#Z#`m1wwBoC1O99t;=d7bpI#fD-_>@}JL*lmFx^ zMSoQXb+pQVj!TsPyhr)3(%9ucug_|@0-b|ePf4pl*QsDkllqvUm7$k((CY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ftb#KO1Ao2_>9#XH%PMeYjPDK43%ZnfF27j>hv-fgyurBboe#v@yeQoXimm@A#i z`pRvw2P#rG+ud`eM#VJRa$D3+xP0f%OL`<1O((OdP$r&S3?*`jXlOB$iiG0vRB|yE z%f`~N*xk&Je-qU&V=LBHvDPS?8x>=)6~(1?v)e2;%@}t{HB>{wH(j^j-&G5u`Q)O$ zsHZ~dcs3GBq_Wx2LR4P}#bbIjy%5Q#veAr%0IgP^1g+K%5z3B4ID3Bi+?7mGS41f2 z7mDQ*Cq}nx#jG_pHj6FLX62?Nj=bc)Wwazp*`jHoL>`n}SV*NqkyIkK5RW7isrkg+ z!>$;RoO>?}c>N9b9Zee~oqGm64!OzwcGjUQbLXUW@y_E_F*M8lW9647o%#>4@O?;} zy|>G)eXt(fJ5ym$&{?*Ah zfAG`4c;>bFxj%d52lJUk2%<6_N@tS``J}GL(;5BlogLbQ%N;QwK^AU^0jZ@1q)Kl< zQsmwlkuV??%MRqmKoyVmiH_VM+|#M-d?Jxv2t{&!n5tAmNuyMaFD48lo>~k?B9Zy{!W}yke?SX>>6P^N?SFRs z9ISIMwkMzr_4jYMU~DZn*Nw*M;SDa>+1{r88^+mhu}1`%dF=iVOu*eFI0pOnUp3wh z>MYKCQv3E_-~MZgz0J8_XkYui4Xbzq7P7>S{noetLcsX;-w5TcZ~u+M@+H?VeETn@ z#3Wm%Z~q;(iTn0n-~QVw`u1NM=Y9LHZ~s*b>Ptfl>Ri_vx1g?L)s4H@*P*p;BCUz_ zSY5lYiv{(*2HcMg&ZT_&Zwq+E!oOH2G@%Oe+&c=$naB9G1K<9O + + + + + \ No newline at end of file diff --git a/c#/protocol1.0/ping/win64/ping/Ping.cs b/c#/protocol1.0/ping/win64/ping/Ping.cs new file mode 100644 index 00000000..450615d1 --- /dev/null +++ b/c#/protocol1.0/ping/win64/ping/Ping.cs @@ -0,0 +1,99 @@ +/* +* ping.cs +* +* Created on: 2016. 5. 16. +* Author: Leon Ryu Woon Jung +*/ + +// +// ********* ping Example ********* +// +// +// Available Dynamixel model on this example : All models using Protocol 1.0 +// This example is designed for using a Dynamixel MX-28, and an USB2DYNAMIXEL. +// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below variables yourself. +// Be sure that Dynamixel MX properties are already set as %% ID : 1 / Baudnum : 1 (Baudrate : 1000000 [1M]) +// + +using System; +using dynamixel_sdk; + +namespace ping +{ + class Ping + { + // Protocol version + public const int PROTOCOL_VERSION = 1; // See which protocol version is used in the Dynamixel + + // Default setting + public const int DXL_ID = 1; // Dynamixel ID: 1 + public const int BAUDRATE = 1000000; + public const string DEVICENAME = "COM8"; // Check which port is being used on your controller + // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const byte ESC_ASCII_VALUE = 0x1b; + + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num = dynamixel.portHandler(DEVICENAME); + + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + int dxl_comm_result = COMM_TX_FAIL; // Communication result + + byte dxl_error = 0; // Dynamixel error + UInt16 dxl_model_number; // Dynamixel model number + + // Open port + if (dynamixel.openPort(port_num)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port baudrate + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + // Try to ping the Dynamixel + // Get Dynamixel model number + dxl_model_number = dynamixel.pingGetModelNum(port_num, PROTOCOL_VERSION, DXL_ID); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + Console.WriteLine("[ID:{0}] ping Succeeded. Dynamixel model number : {1}", DXL_ID, dxl_model_number); + + // Close port + dynamixel.closePort(port_num); + + return; + } + } +} diff --git a/c#/protocol1.0/ping/win64/ping/Properties/AssemblyInfo.cs b/c#/protocol1.0/ping/win64/ping/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..a97376c3 --- /dev/null +++ b/c#/protocol1.0/ping/win64/ping/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("ping")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ping")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("4d6dfb5c-0e72-47b4-9d9a-ac58f5dd3abd")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol1.0/ping/win64/ping/dynamixel.cs b/c#/protocol1.0/ping/win64/ping/dynamixel.cs new file mode 100644 index 00000000..d940e04b --- /dev/null +++ b/c#/protocol1.0/ping/win64/ping/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win64/output/dxl_x64_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol1.0/ping/win64/ping/ping.csproj b/c#/protocol1.0/ping/win64/ping/ping.csproj new file mode 100644 index 00000000..36fea6a1 --- /dev/null +++ b/c#/protocol1.0/ping/win64/ping/ping.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD} + Exe + Properties + ping + ping + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/c#/protocol1.0/read_write/win32/.vs/read_write/v14/.suo b/c#/protocol1.0/read_write/win32/.vs/read_write/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..1496b139ac784ea7dd5f969e8dd5bd094515b413 GIT binary patch literal 39936 zcmeHQ3y@pYdAR2&e5Ys`HJsx+jCu11ADXr{>oaPmeBI>i`o*K(y=>VTeIBeYny!awR65a z|1U4U=GuaI_k2J`9z~7??SM9d+^2At&=#AdQvLdT^gwfUSHHD?`T~N{eT7r`Gv9eF zhY}Pu9WaKvNC9*sUOn#$?GzXDUxNtr>%}vNUxtS}jKQ>9TR<*3Eere!)25u`2q~IB zw7EzAE#toz>D*>C);iq(j0HD2j_3CwoMZoDfO^GnI^ue+Df|lDZvbotoDX2U_re#E zO_vYagqdE8+w1GZIUC_D@>YNc@F9Q~-~;#p0YDHC0)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nRCv7B3U{%`s>8SDN;+Esw~R zx0~&+R_?c2YInAAAE=c>ww{$DcfTq72%c5qV;2E`uTCbZ=KsmRv)4^_bf}t$n+Oab z(}nz0meTR+gYjoNnrF@Q&>-hqI+pWl+Rs%+U1hIwz4m9jK5aYVtjDrj zkyRfb_PCeC=%Q_dJZ-mUf7{vLDyyyil{~9P{&H*U<8QToxostCLyb-zGu3@GnEg7k z+Us8L_n%k;@fy0c)0!Lm8G4Vwhgg6A>9t4hfBJXd`q$jo|MSv+`pF-D>TBrW%O_9K zGK{V>zyEaXbCMi|PJTVI_xm5R<&GY${QifT60V&i)eLv?(jUF`r(Ma%O8gG0w7qmU$MjKU;_A1ljS^{|}2b2|)k= literal 0 HcmV?d00001 diff --git a/c#/protocol1.0/read_write/win32/read_write.sln b/c#/protocol1.0/read_write/win32/read_write.sln new file mode 100644 index 00000000..bda9dede --- /dev/null +++ b/c#/protocol1.0/read_write/win32/read_write.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 14 for Windows Desktop +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "read_write", "read_write\read_write.csproj", "{D1B60768-6B6B-492D-8E0A-D258D9B2CA27}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D1B60768-6B6B-492D-8E0A-D258D9B2CA27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D1B60768-6B6B-492D-8E0A-D258D9B2CA27}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D1B60768-6B6B-492D-8E0A-D258D9B2CA27}.Debug|x86.ActiveCfg = Debug|x86 + {D1B60768-6B6B-492D-8E0A-D258D9B2CA27}.Debug|x86.Build.0 = Debug|x86 + {D1B60768-6B6B-492D-8E0A-D258D9B2CA27}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D1B60768-6B6B-492D-8E0A-D258D9B2CA27}.Release|Any CPU.Build.0 = Release|Any CPU + {D1B60768-6B6B-492D-8E0A-D258D9B2CA27}.Release|x86.ActiveCfg = Release|x86 + {D1B60768-6B6B-492D-8E0A-D258D9B2CA27}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/c#/protocol1.0/read_write/win32/read_write/App.config b/c#/protocol1.0/read_write/win32/read_write/App.config new file mode 100644 index 00000000..8e156463 --- /dev/null +++ b/c#/protocol1.0/read_write/win32/read_write/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/c#/protocol1.0/read_write/win32/read_write/Properties/AssemblyInfo.cs b/c#/protocol1.0/read_write/win32/read_write/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..94be0145 --- /dev/null +++ b/c#/protocol1.0/read_write/win32/read_write/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("read_write")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("read_write")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("d1b60768-6b6b-492d-8e0a-d258d9b2ca27")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol1.0/read_write/win32/read_write/ReadWrite.cs b/c#/protocol1.0/read_write/win32/read_write/ReadWrite.cs new file mode 100644 index 00000000..185f9843 --- /dev/null +++ b/c#/protocol1.0/read_write/win32/read_write/ReadWrite.cs @@ -0,0 +1,170 @@ +/* +* read_write.cs +* +* Created on: 2016. 5. 16. +* Author: Leon Ryu Woon Jung +*/ + +// +// ********* Read and Write Example ********* +// +// +// Available DXL model on this example : All models using Protocol 1.0 +// This example is designed for using a Dynamixel MX-28, and an USB2DYNAMIXEL. +// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below variables yourself. +// Be sure that Dynamixel MX properties are already set as %% ID : 1 / Baudnum : 1 (Baudrate : 1000000 [1M]) +// + +using System; +using dynamixel_sdk; + +namespace read_write +{ + class ReadWrite + { + // Control table address + public const int ADDR_MX_TORQUE_ENABLE = 24; // Control table address is different in Dynamixel model + public const int ADDR_MX_GOAL_POSITION = 30; + public const int ADDR_MX_PRESENT_POSITION = 36; + + // Protocol version + public const int PROTOCOL_VERSION = 1; // See which protocol version is used in the Dynamixel + + // Default setting + public const int DXL_ID = 1; // Dynamixel ID: 1 + public const int BAUDRATE = 1000000; + public const string DEVICENAME = "COM8"; // Check which port is being used on your controller + // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const int TORQUE_ENABLE = 1; // Value for enabling the torque + public const int TORQUE_DISABLE = 0; // Value for disabling the torque + public const int DXL_MINIMUM_POSITION_VALUE = 100; // Dynamixel will rotate between this value + public const int DXL_MAXIMUM_POSITION_VALUE = 4000; // and this value (note that the Dynamixel would not move when the position value is out of movable range. Check e-manual about the range of the Dynamixel you use.) + public const int DXL_MOVING_STATUS_THRESHOLD = 10; // Dynamixel moving status threshold + + public const byte ESC_ASCII_VALUE = 0x1b; + + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num = dynamixel.portHandler(DEVICENAME); + + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + int index = 0; + int dxl_comm_result = COMM_TX_FAIL; // Communication result + UInt16[] dxl_goal_position = new UInt16[2]{ DXL_MINIMUM_POSITION_VALUE, DXL_MAXIMUM_POSITION_VALUE }; // Goal position + + byte dxl_error = 0; // Dynamixel error + UInt16 dxl_present_position = 0; // Present position + + // Open port + if (dynamixel.openPort(port_num)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port baudrate + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Enable DXL Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("Dynamixel has been successfully connected "); + } + + while (true) + { + Console.WriteLine("Press any key to continue! (or press ESC to quit!)"); + if (Console.ReadKey().KeyChar == ESC_ASCII_VALUE) + break; + + // Write goal position + dynamixel.write2ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_MX_GOAL_POSITION, dxl_goal_position[index]); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + do + { + // Read present position + dxl_present_position = dynamixel.read2ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_MX_PRESENT_POSITION); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + Console.WriteLine("[ID:{0}] GoalPos:{1} PresPos:{2}", DXL_ID, dxl_goal_position[index], dxl_present_position); + + } while ((Math.Abs(dxl_goal_position[index] - dxl_present_position) > DXL_MOVING_STATUS_THRESHOLD)); + + // Change goal position + if (index == 0) + { + index = 1; + } + else + { + index = 0; + } + } + + // Disable Dynamixel Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Close port + dynamixel.closePort(port_num); + + return; + } + } +} diff --git a/c#/protocol1.0/read_write/win32/read_write/dynamixel.cs b/c#/protocol1.0/read_write/win32/read_write/dynamixel.cs new file mode 100644 index 00000000..235af316 --- /dev/null +++ b/c#/protocol1.0/read_write/win32/read_write/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win32/output/dxl_x86_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol1.0/read_write/win32/read_write/read_write.csproj b/c#/protocol1.0/read_write/win32/read_write/read_write.csproj new file mode 100644 index 00000000..131b619a --- /dev/null +++ b/c#/protocol1.0/read_write/win32/read_write/read_write.csproj @@ -0,0 +1,108 @@ + + + + + Debug + AnyCPU + {D1B60768-6B6B-492D-8E0A-D258D9B2CA27} + Exe + Properties + read_write + read_write + v4.5 + 512 + false + 게시\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + prompt + MinimumRecommendedRules.ruleset + true + 0 + + + + + + + + + + + + + + + + + + + + + + False + Microsoft .NET Framework 4.5%28x86 및 x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + + + + \ No newline at end of file diff --git a/c#/protocol1.0/read_write/win32/read_write/read_write.csproj.user b/c#/protocol1.0/read_write/win32/read_write/read_write.csproj.user new file mode 100644 index 00000000..04baf14c --- /dev/null +++ b/c#/protocol1.0/read_write/win32/read_write/read_write.csproj.user @@ -0,0 +1,17 @@ + + + + 게시\ + + + + + + ko-KR + false + + + + + + \ No newline at end of file diff --git a/c#/protocol1.0/read_write/win64/.vs/read_write/v14/.suo b/c#/protocol1.0/read_write/win64/.vs/read_write/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..dfbfac890e79c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=Q^GFrS)*Gq*Gh}s+Wu^HY_RYN6_Uu>2CLj$9=xcuwcp8{ zBnPhjkKH8#=VW8Bij#Sm=Gy;w7Sql$X|~_-3n!gfHqGz5_CGlT>sQzQhiT~W{D!7N z7l&Y)MFiLW$79s?7R=_J6QYr8{{wA1f`wVPB)ay$g;_hTEdh46F4z9oY!emsKiB@_ z+J9X8k8A&N?LWezx3Vn=uKj2ES|W{JDArcVR&2ERx}IzQ5ho`3J&wB5W~%AyN7i4C zYVKRt{?q)8DB(`~$`V@U8eNCiz^~8B|Df*KZr1-S|MRo+vDbg(>PK>spMC$4(v$rU z{plP39;9wZTDas@e2QYB?O&`_;NF8mzfz-AC z!OP!0|L30n+HPHnYQOS>64XhKVu7b zz;kRroR@ii%A=Uib@W7I-e@A4@P>PXDQ_(8k9$+WNG#Qx2qxpfo)gCnAC0Zw`f^q6 zxD-z6OlilZCgpLdynb9NuO3y4I5stRUJA#hGP&wlwlbN)tJ-;^fX{FICM^zAg@VQi z;?q7?3v@V(6pto*!r^$#>raQ{-f$nzRmEb_xYr*I2V)_BBpmGtp8%0HoDO?$w{^99 z^es1cXsq?gJ@@Dv&n0$h`fND=^SsJ_WJyOe@`fO99x4aY*w^?w`+*wH-dZs zT(*2`J{%X!8BMb6O5 s{zKu3>ameUU8;4CCKJa2||4P<^ZU6uP literal 0 HcmV?d00001 diff --git a/c#/protocol1.0/read_write/win64/read_write.sln b/c#/protocol1.0/read_write/win64/read_write.sln new file mode 100644 index 00000000..6c6b9cde --- /dev/null +++ b/c#/protocol1.0/read_write/win64/read_write.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 14 for Windows Desktop +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "read_write", "read_write\read_write.csproj", "{D1B60768-6B6B-492D-8E0A-D258D9B2CA27}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D1B60768-6B6B-492D-8E0A-D258D9B2CA27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D1B60768-6B6B-492D-8E0A-D258D9B2CA27}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D1B60768-6B6B-492D-8E0A-D258D9B2CA27}.Debug|x64.ActiveCfg = Debug|x64 + {D1B60768-6B6B-492D-8E0A-D258D9B2CA27}.Debug|x64.Build.0 = Debug|x64 + {D1B60768-6B6B-492D-8E0A-D258D9B2CA27}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D1B60768-6B6B-492D-8E0A-D258D9B2CA27}.Release|Any CPU.Build.0 = Release|Any CPU + {D1B60768-6B6B-492D-8E0A-D258D9B2CA27}.Release|x64.ActiveCfg = Release|x64 + {D1B60768-6B6B-492D-8E0A-D258D9B2CA27}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/c#/protocol1.0/read_write/win64/read_write/App.config b/c#/protocol1.0/read_write/win64/read_write/App.config new file mode 100644 index 00000000..8e156463 --- /dev/null +++ b/c#/protocol1.0/read_write/win64/read_write/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/c#/protocol1.0/read_write/win64/read_write/Properties/AssemblyInfo.cs b/c#/protocol1.0/read_write/win64/read_write/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..94be0145 --- /dev/null +++ b/c#/protocol1.0/read_write/win64/read_write/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("read_write")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("read_write")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("d1b60768-6b6b-492d-8e0a-d258d9b2ca27")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol1.0/read_write/win64/read_write/ReadWrite.cs b/c#/protocol1.0/read_write/win64/read_write/ReadWrite.cs new file mode 100644 index 00000000..185f9843 --- /dev/null +++ b/c#/protocol1.0/read_write/win64/read_write/ReadWrite.cs @@ -0,0 +1,170 @@ +/* +* read_write.cs +* +* Created on: 2016. 5. 16. +* Author: Leon Ryu Woon Jung +*/ + +// +// ********* Read and Write Example ********* +// +// +// Available DXL model on this example : All models using Protocol 1.0 +// This example is designed for using a Dynamixel MX-28, and an USB2DYNAMIXEL. +// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below variables yourself. +// Be sure that Dynamixel MX properties are already set as %% ID : 1 / Baudnum : 1 (Baudrate : 1000000 [1M]) +// + +using System; +using dynamixel_sdk; + +namespace read_write +{ + class ReadWrite + { + // Control table address + public const int ADDR_MX_TORQUE_ENABLE = 24; // Control table address is different in Dynamixel model + public const int ADDR_MX_GOAL_POSITION = 30; + public const int ADDR_MX_PRESENT_POSITION = 36; + + // Protocol version + public const int PROTOCOL_VERSION = 1; // See which protocol version is used in the Dynamixel + + // Default setting + public const int DXL_ID = 1; // Dynamixel ID: 1 + public const int BAUDRATE = 1000000; + public const string DEVICENAME = "COM8"; // Check which port is being used on your controller + // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const int TORQUE_ENABLE = 1; // Value for enabling the torque + public const int TORQUE_DISABLE = 0; // Value for disabling the torque + public const int DXL_MINIMUM_POSITION_VALUE = 100; // Dynamixel will rotate between this value + public const int DXL_MAXIMUM_POSITION_VALUE = 4000; // and this value (note that the Dynamixel would not move when the position value is out of movable range. Check e-manual about the range of the Dynamixel you use.) + public const int DXL_MOVING_STATUS_THRESHOLD = 10; // Dynamixel moving status threshold + + public const byte ESC_ASCII_VALUE = 0x1b; + + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num = dynamixel.portHandler(DEVICENAME); + + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + int index = 0; + int dxl_comm_result = COMM_TX_FAIL; // Communication result + UInt16[] dxl_goal_position = new UInt16[2]{ DXL_MINIMUM_POSITION_VALUE, DXL_MAXIMUM_POSITION_VALUE }; // Goal position + + byte dxl_error = 0; // Dynamixel error + UInt16 dxl_present_position = 0; // Present position + + // Open port + if (dynamixel.openPort(port_num)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port baudrate + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Enable DXL Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("Dynamixel has been successfully connected "); + } + + while (true) + { + Console.WriteLine("Press any key to continue! (or press ESC to quit!)"); + if (Console.ReadKey().KeyChar == ESC_ASCII_VALUE) + break; + + // Write goal position + dynamixel.write2ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_MX_GOAL_POSITION, dxl_goal_position[index]); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + do + { + // Read present position + dxl_present_position = dynamixel.read2ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_MX_PRESENT_POSITION); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + Console.WriteLine("[ID:{0}] GoalPos:{1} PresPos:{2}", DXL_ID, dxl_goal_position[index], dxl_present_position); + + } while ((Math.Abs(dxl_goal_position[index] - dxl_present_position) > DXL_MOVING_STATUS_THRESHOLD)); + + // Change goal position + if (index == 0) + { + index = 1; + } + else + { + index = 0; + } + } + + // Disable Dynamixel Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Close port + dynamixel.closePort(port_num); + + return; + } + } +} diff --git a/c#/protocol1.0/read_write/win64/read_write/dynamixel.cs b/c#/protocol1.0/read_write/win64/read_write/dynamixel.cs new file mode 100644 index 00000000..d940e04b --- /dev/null +++ b/c#/protocol1.0/read_write/win64/read_write/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win64/output/dxl_x64_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol1.0/read_write/win64/read_write/read_write.csproj b/c#/protocol1.0/read_write/win64/read_write/read_write.csproj new file mode 100644 index 00000000..2104f52b --- /dev/null +++ b/c#/protocol1.0/read_write/win64/read_write/read_write.csproj @@ -0,0 +1,107 @@ + + + + + Debug + AnyCPU + {D1B60768-6B6B-492D-8E0A-D258D9B2CA27} + Exe + Properties + read_write + read_write + v4.5 + 512 + false + 게시\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + False + Microsoft .NET Framework 4.5%28x86 및 x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + + + + \ No newline at end of file diff --git a/c#/protocol1.0/read_write/win64/read_write/read_write.csproj.user b/c#/protocol1.0/read_write/win64/read_write/read_write.csproj.user new file mode 100644 index 00000000..04baf14c --- /dev/null +++ b/c#/protocol1.0/read_write/win64/read_write/read_write.csproj.user @@ -0,0 +1,17 @@ + + + + 게시\ + + + + + + ko-KR + false + + + + + + \ No newline at end of file diff --git a/c#/protocol1.0/reset/win32/.vs/reset/v14/.suo b/c#/protocol1.0/reset/win32/.vs/reset/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..c658c113caa7ae085edab62529de3229ecf58723 GIT binary patch literal 35840 zcmeHQYm8e*6~3FklBUp>mH=%@-4aTnYvcFYNt4#EO}5Qr8*d&EryH+*y>ZrS8{3=g z(gg7bR3RZjk)R+^0iqIAs0hRlKnO&|OCVIBLZAv2_zMUG2#Q*@;rnLptgo+q?d#1Z z8*e<;c*b+*&Y3wg=ggToXU4yJ{^mb@@f)}OS+lrZ+Ev=?=QnBBn$ky1aqT8eyAHpZ z_WJqr=lO_nM2BvGFmO<-;M34tT1qP;tZ7T^O2=-CcFl61Z|(7x>+Bz^Fa7-2BljZT zgKw3YCjqgdozf-%y?|IsTkKIv>*FojhGqCfd+XEAzfK?-!&f*3pKz;M2{ou`I(!wqfKdJiG?pDg3*U_W^^L4rmL2QqqcOKmDu;auO*uJHSRd;crI#E_kQ# z--o;(GvE^sukpnWj&#kk8PaVsV7$W!nRYYcZ-CzcuktZ{CGMR@xf_j;WrPra5Bz=b zqwsEc5Bz)Kz3@JGKYRc_2+ul%5stw};G^){;qQk}!taEC6TDshZt3#O?wvtSzm)WU zV&<9kNdGNk3B#wSTV?w18@`$T)z~HfA|D|AT#vY-h-j|F*%V^^)+T7>{q|37# zfPccJIPDbvRmhv+*D5)}Rj%J6ITlGj42S&x%H#h@jQtrw1Ehi)<~|*~h^ycw&CH8B z@g9z~(G}4DEqIS}C7l(19FTSJnK`V+E8snn+nQ@4-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>j&-y?0;b3^;f;JI%0 zm%fxc7LWVf$yg+qiicw3o<#+l=?YmW7;@(=M`4V?C@d<)6jGtquajsG> z6uJAUU3-6dp;X$%Xw$7`2M))d?JfV8?f4t?`-{y(|3d8khw=;MmuH)dLHj1+v@kHs zFQ&()XzM@7@}8r^Vo59iokN}UG`(PoD*0ul{~@vsr;VJzS9fReu(tU>L@1ek*RbYV zi(8J@n*aCrA1d;+tkR*#TRSi8{D}4cM@&Ow7`+4-;P@N<|If<*|EDwk*q!F!?v1=( zLeUQO2H#&}{xj_VmG}Rk%TG?{Pdiq$*7N6}(_iQM*OvK&`R;q`|3WApLLRB Bd%XYv literal 0 HcmV?d00001 diff --git a/c#/protocol1.0/reset/win32/reset.sln b/c#/protocol1.0/reset/win32/reset.sln new file mode 100644 index 00000000..488fdcc9 --- /dev/null +++ b/c#/protocol1.0/reset/win32/reset.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 14 for Windows Desktop +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "reset", "reset\reset.csproj", "{9E063190-2F38-4EC6-92B8-9106B4A076DA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9E063190-2F38-4EC6-92B8-9106B4A076DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9E063190-2F38-4EC6-92B8-9106B4A076DA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9E063190-2F38-4EC6-92B8-9106B4A076DA}.Debug|x86.ActiveCfg = Debug|x86 + {9E063190-2F38-4EC6-92B8-9106B4A076DA}.Debug|x86.Build.0 = Debug|x86 + {9E063190-2F38-4EC6-92B8-9106B4A076DA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9E063190-2F38-4EC6-92B8-9106B4A076DA}.Release|Any CPU.Build.0 = Release|Any CPU + {9E063190-2F38-4EC6-92B8-9106B4A076DA}.Release|x86.ActiveCfg = Release|x86 + {9E063190-2F38-4EC6-92B8-9106B4A076DA}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/c#/protocol1.0/reset/win32/reset/App.config b/c#/protocol1.0/reset/win32/reset/App.config new file mode 100644 index 00000000..8e156463 --- /dev/null +++ b/c#/protocol1.0/reset/win32/reset/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/c#/protocol1.0/reset/win32/reset/Properties/AssemblyInfo.cs b/c#/protocol1.0/reset/win32/reset/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..78520e53 --- /dev/null +++ b/c#/protocol1.0/reset/win32/reset/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("reset")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("reset")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("9e063190-2f38-4ec6-92b8-9106b4a076da")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol1.0/reset/win32/reset/Reset.cs b/c#/protocol1.0/reset/win32/reset/Reset.cs new file mode 100644 index 00000000..f1859dd7 --- /dev/null +++ b/c#/protocol1.0/reset/win32/reset/Reset.cs @@ -0,0 +1,193 @@ +/* +* reset.cs +* +* Created on: 2016. 5. 16. +* Author: Leon Ryu Woon Jung +*/ + +// +// ********* Factory Reset Example ********* +// +// +// Available Dynamixel model on this example : All models using Protocol 1.0 +// This example is designed for using a Dynamixel MX-28, and an USB2DYNAMIXEL. +// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below variables yourself. +// Be sure that Dynamixel PRO properties are already set as %% ID : 1 / Baudnum : 1 (Baudrate : 1000000 [1M]) +// + +// Be aware that: +// This example resets all properties of Dynamixel to default values, such as %% ID : 1 / Baudnum : 34 (Baudrate : 57600) +// + +using System; +using System.Threading; +using dynamixel_sdk; + +namespace reset +{ + class Reset + { + // Control table address + public const int ADDR_MX_BAUDRATE = 4; // Control table address is different in Dynamixel model + + // Protocol version + public const int PROTOCOL_VERSION = 1; // See which protocol version is used in the Dynamixel + + // Default setting + public const int DXL_ID = 1; // Dynamixel ID: 1 + public const int BAUDRATE = 1000000; + public const string DEVICENAME = "COM8"; // Check which port is being used on your controller + // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const int FACTORYRST_DEFAULTBAUDRATE = 57600; // Dynamixel baudrate set by factoryreset + public const int NEW_BAUDNUM = 1; // New baudnum to recover Dynamixel baudrate as it was + public const byte OPERATION_MODE = 0x00; // Mode is unavailable in Protocol 1.0 Reset + + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num = dynamixel.portHandler(DEVICENAME); + + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + int dxl_comm_result = COMM_TX_FAIL; // Communication result + + byte dxl_error = 0; // Dynamixel error + byte dxl_baudnum_read; // Read baudnum + + // Open port + if (dynamixel.openPort(port_num)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port baudrate + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + + // Read present baudrate of the controller + Console.WriteLine("Now the controller baudrate is : {0}", dynamixel.getBaudRate(port_num)); + + // Try factoryreset + Console.WriteLine("[ID:{0}] Try factoryreset : ", DXL_ID); + dynamixel.factoryReset(port_num, PROTOCOL_VERSION, DXL_ID, OPERATION_MODE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + Console.WriteLine("Aborted"); + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + return; + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Wait for reset + Console.WriteLine("Wait for reset..."); + Thread.Sleep(2000); + + Console.WriteLine("[ID:{0}] factoryReset Success!", DXL_ID); + + // Set controller baudrate to dxl default baudrate + if (dynamixel.setBaudRate(port_num, FACTORYRST_DEFAULTBAUDRATE)) + { + Console.WriteLine("Succeed to change the controller baudrate to : {0}", FACTORYRST_DEFAULTBAUDRATE); + } + else + { + Console.WriteLine("Failed to change the controller baudrate"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Read Dynamixel baudnum + dxl_baudnum_read = dynamixel.read1ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_MX_BAUDRATE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("[ID:{0}] Dynamixel baudnum is now : {1}", DXL_ID, dxl_baudnum_read); + } + + // Write new baudnum + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_MX_BAUDRATE, NEW_BAUDNUM); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("[ID:{0}] Set Dynamixel baudnum to : {1}", DXL_ID, NEW_BAUDNUM); + } + + // Set port baudrate to BAUDRATE + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeed to change the controller baudrate to : {0}", BAUDRATE); + } + else + { + Console.WriteLine("Failed to change the controller baudrate"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + Thread.Sleep(200); + + // Read Dynamixel baudnum + dxl_baudnum_read = dynamixel.read1ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_MX_BAUDRATE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("[ID:{0}] Dynamixel Baudnum is now : {1}", DXL_ID, dxl_baudnum_read); + } + + // Close port + dynamixel.closePort(port_num); + + return; + } + } +} diff --git a/c#/protocol1.0/reset/win32/reset/dynamixel.cs b/c#/protocol1.0/reset/win32/reset/dynamixel.cs new file mode 100644 index 00000000..235af316 --- /dev/null +++ b/c#/protocol1.0/reset/win32/reset/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win32/output/dxl_x86_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol1.0/reset/win32/reset/reset.csproj b/c#/protocol1.0/reset/win32/reset/reset.csproj new file mode 100644 index 00000000..1fb98459 --- /dev/null +++ b/c#/protocol1.0/reset/win32/reset/reset.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {9E063190-2F38-4EC6-92B8-9106B4A076DA} + Exe + Properties + reset + reset + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/c#/protocol1.0/reset/win64/.vs/reset/v14/.suo b/c#/protocol1.0/reset/win64/.vs/reset/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..07f24377a0fed90a185157cbb069f9842ff58d8b GIT binary patch literal 36864 zcmeHQYm6J!6`l)s|ufPB8 z*S{Uwf>L*XN)(+0#ENoEnE>=z9Ho@yj&)dXZUIN$gp1@wqTPDG-TD2vDBCLG6K+*0 zp#_?vB4>b$9J1Q30@Jna%7&rO;QS(Fr|@q?*?)83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R%xp2h;QC;5B?~75J*SHl4HrJHx^3xz2Rsg;T;VmN4=q7G7uZ}r=y8L z+(dwCwLyYvb(IKtTO#b4m>NG6&n6`iGRb?h`5imj_iMUTEH5o*tDw#FydaLa}KQC-1rC2aP+Jd}2#nqTX7PW&d(2m!s9*o?E5CT>PwX#WL@=lBIM|NauK6GI z_@4J+=qUUb6}~GT&?~VMGc@VEWY}co_trnmXjD6`ub~sV`k$-+Np0I_qX~4=bzJ?g zRVQ}!KUe>&W?lV{%DJomx%yv!|3A>x|4Ohpo!NgdcE_Rco4j@o_1FIVhoo3dzI@*G z!@PbmA2)v&Q>|41|$J9W~uO7!Jx)lT?x z>3^=@3N+K)eB3|!TmQdw0qf;<>sPy#Fs(4>a{by5{#_sA-i|_@ue + + + + + \ No newline at end of file diff --git a/c#/protocol1.0/reset/win64/reset/Properties/AssemblyInfo.cs b/c#/protocol1.0/reset/win64/reset/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..78520e53 --- /dev/null +++ b/c#/protocol1.0/reset/win64/reset/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("reset")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("reset")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("9e063190-2f38-4ec6-92b8-9106b4a076da")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol1.0/reset/win64/reset/Reset.cs b/c#/protocol1.0/reset/win64/reset/Reset.cs new file mode 100644 index 00000000..f1859dd7 --- /dev/null +++ b/c#/protocol1.0/reset/win64/reset/Reset.cs @@ -0,0 +1,193 @@ +/* +* reset.cs +* +* Created on: 2016. 5. 16. +* Author: Leon Ryu Woon Jung +*/ + +// +// ********* Factory Reset Example ********* +// +// +// Available Dynamixel model on this example : All models using Protocol 1.0 +// This example is designed for using a Dynamixel MX-28, and an USB2DYNAMIXEL. +// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below variables yourself. +// Be sure that Dynamixel PRO properties are already set as %% ID : 1 / Baudnum : 1 (Baudrate : 1000000 [1M]) +// + +// Be aware that: +// This example resets all properties of Dynamixel to default values, such as %% ID : 1 / Baudnum : 34 (Baudrate : 57600) +// + +using System; +using System.Threading; +using dynamixel_sdk; + +namespace reset +{ + class Reset + { + // Control table address + public const int ADDR_MX_BAUDRATE = 4; // Control table address is different in Dynamixel model + + // Protocol version + public const int PROTOCOL_VERSION = 1; // See which protocol version is used in the Dynamixel + + // Default setting + public const int DXL_ID = 1; // Dynamixel ID: 1 + public const int BAUDRATE = 1000000; + public const string DEVICENAME = "COM8"; // Check which port is being used on your controller + // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const int FACTORYRST_DEFAULTBAUDRATE = 57600; // Dynamixel baudrate set by factoryreset + public const int NEW_BAUDNUM = 1; // New baudnum to recover Dynamixel baudrate as it was + public const byte OPERATION_MODE = 0x00; // Mode is unavailable in Protocol 1.0 Reset + + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num = dynamixel.portHandler(DEVICENAME); + + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + int dxl_comm_result = COMM_TX_FAIL; // Communication result + + byte dxl_error = 0; // Dynamixel error + byte dxl_baudnum_read; // Read baudnum + + // Open port + if (dynamixel.openPort(port_num)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port baudrate + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + + // Read present baudrate of the controller + Console.WriteLine("Now the controller baudrate is : {0}", dynamixel.getBaudRate(port_num)); + + // Try factoryreset + Console.WriteLine("[ID:{0}] Try factoryreset : ", DXL_ID); + dynamixel.factoryReset(port_num, PROTOCOL_VERSION, DXL_ID, OPERATION_MODE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + Console.WriteLine("Aborted"); + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + return; + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Wait for reset + Console.WriteLine("Wait for reset..."); + Thread.Sleep(2000); + + Console.WriteLine("[ID:{0}] factoryReset Success!", DXL_ID); + + // Set controller baudrate to dxl default baudrate + if (dynamixel.setBaudRate(port_num, FACTORYRST_DEFAULTBAUDRATE)) + { + Console.WriteLine("Succeed to change the controller baudrate to : {0}", FACTORYRST_DEFAULTBAUDRATE); + } + else + { + Console.WriteLine("Failed to change the controller baudrate"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Read Dynamixel baudnum + dxl_baudnum_read = dynamixel.read1ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_MX_BAUDRATE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("[ID:{0}] Dynamixel baudnum is now : {1}", DXL_ID, dxl_baudnum_read); + } + + // Write new baudnum + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_MX_BAUDRATE, NEW_BAUDNUM); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("[ID:{0}] Set Dynamixel baudnum to : {1}", DXL_ID, NEW_BAUDNUM); + } + + // Set port baudrate to BAUDRATE + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeed to change the controller baudrate to : {0}", BAUDRATE); + } + else + { + Console.WriteLine("Failed to change the controller baudrate"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + Thread.Sleep(200); + + // Read Dynamixel baudnum + dxl_baudnum_read = dynamixel.read1ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_MX_BAUDRATE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("[ID:{0}] Dynamixel Baudnum is now : {1}", DXL_ID, dxl_baudnum_read); + } + + // Close port + dynamixel.closePort(port_num); + + return; + } + } +} diff --git a/c#/protocol1.0/reset/win64/reset/dynamixel.cs b/c#/protocol1.0/reset/win64/reset/dynamixel.cs new file mode 100644 index 00000000..d940e04b --- /dev/null +++ b/c#/protocol1.0/reset/win64/reset/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win64/output/dxl_x64_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol1.0/reset/win64/reset/reset.csproj b/c#/protocol1.0/reset/win64/reset/reset.csproj new file mode 100644 index 00000000..e91b53a4 --- /dev/null +++ b/c#/protocol1.0/reset/win64/reset/reset.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {9E063190-2F38-4EC6-92B8-9106B4A076DA} + Exe + Properties + reset + reset + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/c#/protocol1.0/sync_write/win32/.vs/sync_write/v14/.suo b/c#/protocol1.0/sync_write/win32/.vs/sync_write/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..e597a82c26ac4c09f8b9a86820f1cd6bcb3713cd GIT binary patch literal 38400 zcmeHQdyHFGnZHg0NgqoK?Pj|yo49Eyg^s;`KawWYuSteZ+G#yWx?87{JNEUAGalQu zJ(-zpvO-8(ttd!E7FI$C?Z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^=8G&-4(j$O?r74cdy2IT~^wh=*{peO2uQbjLs#KDW&t!h=vZl3gr z$^LTtTxp?Fts5!5VQ4Pb?UW00mNhB-e#KS?Yd__=Sb(N(ntN0a!pZhy4_9+9j~(w? zyCS=^dm3UfP5bTN0Hew$PKod1fZ=R+rHK?4xF5efmeET zv>vxr|0AwTuDsZooLjfbt>(DZwtW+CPJHdRiFfCcxdtZ6E}3_q{HtAjyUep(Ng5g&;7IDV!&sgW59L80DJ}_)PTKi6@^~Qtpkl6A(*vo=*?bkIo z#)27q<6uyJ-n-@bv6jhjdExG#3Dh0uF!8$tPWxXl;0ebw0Z%CE&v+8aq~DWH#6p>5 zI59byiCnx;SS!!1#UgY0+{T&re11)A3)Oqur98H`tmR6Te0il{j!(=kslkoG5HzR5_+pR`a=!-psoHTal>q5_*+ z_4sVXv8mbPCzH0XRy_Q0ce>`vrOL`$u2!u#=N2VR@|JVTXlr7GA!Fq6mx13^zP91MFxp;*$BO!;G;KqBmqB$LsR+%gP< zEOvRAGX8OY;YZIsy0dBBt)(3kxE<76>P}<*e`D+6P6G+q!dU-DA#@K{qw9Bjw_VX6 zpnsTIVmf2}pWiYXWSJQ2|20@ZHun`M+1RXe)2Te#!&v`EGaT#xO6zYOMMG&{i7?jx z3$XRJudTSA>n}z_|KD!9_ja&H>WF!&}PF@Q;kFMt$b(n_K?%y=<%;D3W`1}bz0}4}!Y2A@uL}_^Q zj*UFuy&l=$5;GO${!!llyWb9*-Q1q^i&1)2b717IYj6D5H~xFi<+F<)d+AyK%MW?( zp`gK?8m*!Go_bsPkyz_i?Gw5Yi0YAfpT`J>V8sf=VxD-UQ1pZiy%>y#3?mqcdwo7% zG#I-e>e{MAY=lq?W#Q%T3jmNTX{Qv&}BXXct literal 0 HcmV?d00001 diff --git a/c#/protocol1.0/sync_write/win32/sync_write.sln b/c#/protocol1.0/sync_write/win32/sync_write.sln new file mode 100644 index 00000000..93f94418 --- /dev/null +++ b/c#/protocol1.0/sync_write/win32/sync_write.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 14 for Windows Desktop +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sync_write", "sync_write\sync_write.csproj", "{23EAE323-3535-448B-BC18-2A516BB7759C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {23EAE323-3535-448B-BC18-2A516BB7759C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {23EAE323-3535-448B-BC18-2A516BB7759C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {23EAE323-3535-448B-BC18-2A516BB7759C}.Debug|x86.ActiveCfg = Debug|x86 + {23EAE323-3535-448B-BC18-2A516BB7759C}.Debug|x86.Build.0 = Debug|x86 + {23EAE323-3535-448B-BC18-2A516BB7759C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {23EAE323-3535-448B-BC18-2A516BB7759C}.Release|Any CPU.Build.0 = Release|Any CPU + {23EAE323-3535-448B-BC18-2A516BB7759C}.Release|x86.ActiveCfg = Release|x86 + {23EAE323-3535-448B-BC18-2A516BB7759C}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/c#/protocol1.0/sync_write/win32/sync_write/App.config b/c#/protocol1.0/sync_write/win32/sync_write/App.config new file mode 100644 index 00000000..8e156463 --- /dev/null +++ b/c#/protocol1.0/sync_write/win32/sync_write/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/c#/protocol1.0/sync_write/win32/sync_write/Properties/AssemblyInfo.cs b/c#/protocol1.0/sync_write/win32/sync_write/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..061150fb --- /dev/null +++ b/c#/protocol1.0/sync_write/win32/sync_write/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("sync_write")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("sync_write")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("23eae323-3535-448b-bc18-2a516bb7759c")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol1.0/sync_write/win32/sync_write/SyncWrite.cs b/c#/protocol1.0/sync_write/win32/sync_write/SyncWrite.cs new file mode 100644 index 00000000..40f9aab4 --- /dev/null +++ b/c#/protocol1.0/sync_write/win32/sync_write/SyncWrite.cs @@ -0,0 +1,230 @@ +/* +* sync_write.cs +* +* Created on: 2016. 5. 16. +* Author: Leon Ryu Woon Jung +*/ + +// +// ********* Sync Write Example ********* +// +// +// Available Dynamixel model on this example : All models using Protocol 1.0 +// This example is designed for using two Dynamixel MX-28, and an USB2DYNAMIXEL. +// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below variables yourself. +// Be sure that Dynamixel MX properties are already set as %% ID : 1 / Baudnum : 1 (Baudrate : 1000000 [1M]) +// + +using System; +using dynamixel_sdk; + +namespace sync_write +{ + class SyncWrite + { + // Control table address + public const int ADDR_MX_TORQUE_ENABLE = 24; // Control table address is different in Dynamixel model + public const int ADDR_MX_GOAL_POSITION = 30; + public const int ADDR_MX_PRESENT_POSITION = 36; + + // Data Byte Length + public const int LEN_MX_GOAL_POSITION = 2; + public const int LEN_MX_PRESENT_POSITION = 2; + + // Protocol version + public const int PROTOCOL_VERSION = 1; // See which protocol version is used in the Dynamixel + + // Default setting + public const int DXL1_ID = 1; // Dynamixel ID: 1 + public const int DXL2_ID = 2; // Dynamixel ID: 2 + public const int BAUDRATE = 1000000; + public const string DEVICENAME = "COM8"; // Check which port is being used on your controller + // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const int TORQUE_ENABLE = 1; // Value for enabling the torque + public const int TORQUE_DISABLE = 0; // Value for disabling the torque + public const int DXL_MINIMUM_POSITION_VALUE = 100; // Dynamixel will rotate between this value + public const int DXL_MAXIMUM_POSITION_VALUE = 4000; // and this value (note that the Dynamixel would not move when the position value is out of movable range. Check e-manual about the range of the Dynamixel you use.) + public const int DXL_MOVING_STATUS_THRESHOLD = 10; // Dynamixel moving status threshold + + public const byte ESC_ASCII_VALUE = 0x1b; + + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num = dynamixel.portHandler(DEVICENAME); + + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + // Initialize Groupsyncwrite instance + int group_num = dynamixel.groupSyncWrite(port_num, PROTOCOL_VERSION, ADDR_MX_GOAL_POSITION, LEN_MX_GOAL_POSITION); + + int index = 0; + int dxl_comm_result = COMM_TX_FAIL; // Communication result + bool dxl_addparam_result = false; // AddParam result + UInt16[] dxl_goal_position = new UInt16[2]{ DXL_MINIMUM_POSITION_VALUE, DXL_MAXIMUM_POSITION_VALUE }; // Goal position + + byte dxl_error = 0; // Dynamixel error + UInt16 dxl1_present_position = 0, dxl2_present_position = 0; // Present position + + // Open port + if (dynamixel.openPort(port_num)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port baudrate + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Enable Dynamixel#1 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL1_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("Dynamixel{0} has been successfully connected ", DXL1_ID); + } + + // Enable Dynamixel#2 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL2_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("Dynamixel{0} has been successfully connected ", DXL1_ID); + } + + while (true) + { + Console.WriteLine("Press any key to continue! (or press ESC to quit!)"); + if (Console.ReadKey().KeyChar == ESC_ASCII_VALUE) + break; + + // Add Dynamixel#1 goal position value to the Syncwrite storage + dxl_addparam_result = dynamixel.groupSyncWriteAddParam(group_num, DXL1_ID, dxl_goal_position[index], LEN_MX_GOAL_POSITION); + if (dxl_addparam_result != true) + { + Console.WriteLine("[ID:{0}] groupSyncWrite addparam failed", DXL1_ID); + return; + } + + // Add Dynamixel#2 goal position value to the Syncwrite parameter storage + dxl_addparam_result = dynamixel.groupSyncWriteAddParam(group_num, DXL2_ID, dxl_goal_position[index], LEN_MX_GOAL_POSITION); + if (dxl_addparam_result != true) + { + Console.WriteLine("[ID:{0}] groupSyncWrite addparam failed", DXL2_ID); + return; + } + + // Syncwrite goal position + dynamixel.groupSyncWriteTxPacket(group_num); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + + // Clear syncwrite parameter storage + dynamixel.groupSyncWriteClearParam(group_num); + + do + { + // Read Dynamixel#1 present position + dxl1_present_position = dynamixel.read2ByteTxRx(port_num, PROTOCOL_VERSION, DXL1_ID, ADDR_MX_PRESENT_POSITION); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Read Dynamixel#2 present position + dxl2_present_position = dynamixel.read2ByteTxRx(port_num, PROTOCOL_VERSION, DXL2_ID, ADDR_MX_PRESENT_POSITION); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + Console.WriteLine("[ID:{0}] GoalPos:{1} PresPos:{2} [ID:{3}] GoalPos:{4} PresPos:{5}", DXL1_ID, dxl_goal_position[index], dxl1_present_position, DXL2_ID, dxl_goal_position[index], dxl2_present_position); + + + } while ((Math.Abs(dxl_goal_position[index] - dxl1_present_position) > DXL_MOVING_STATUS_THRESHOLD) || (Math.Abs(dxl_goal_position[index] - dxl2_present_position) > DXL_MOVING_STATUS_THRESHOLD)); + + // Change goal position + if (index == 0) + { + index = 1; + } + else + { + index = 0; + } + } + + // Disable Dynamixel#1 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL1_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Disable Dynamixel#2 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL2_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Close port + dynamixel.closePort(port_num); + + return; + } + } +} diff --git a/c#/protocol1.0/sync_write/win32/sync_write/dynamixel.cs b/c#/protocol1.0/sync_write/win32/sync_write/dynamixel.cs new file mode 100644 index 00000000..235af316 --- /dev/null +++ b/c#/protocol1.0/sync_write/win32/sync_write/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win32/output/dxl_x86_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol1.0/sync_write/win32/sync_write/sync_write.csproj b/c#/protocol1.0/sync_write/win32/sync_write/sync_write.csproj new file mode 100644 index 00000000..8af481f2 --- /dev/null +++ b/c#/protocol1.0/sync_write/win32/sync_write/sync_write.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {23EAE323-3535-448B-BC18-2A516BB7759C} + Exe + Properties + sync_write + sync_write + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/c#/protocol1.0/sync_write/win64/.vs/sync_write/v14/.suo b/c#/protocol1.0/sync_write/win64/.vs/sync_write/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..390ebea9ba055e88b8e3c64bf4f40a254472c784 GIT binary patch literal 51712 zcmeHQdyE^$dEb-eSh5`}sa02XQt51~scIitzKHkpg>w6MbJ16TA%^aq9}r*PE({Uj6Q;*Xo~<&3%do1{Lu#r6fw{sD2gIB zB=z^(*&&z9CAqxgS;zAX@o{%&XLn}4Z|0ltF+20!w?Fx>Uw!k@f75K?ly;AH`_6vt zW0v?4obQp>pU||uIA`4LJ9q9d`W^sIRTv@+Jg=4Ut81fLN-N=5)iy{<*WnTE-UiLB zZN=#YmDj%b?tlLMKa3p0&DTFIQcNSqvbLm6A@_NlrL=XYM?1znqU{-Z9Cr@@i1v;N zEjM1lIhwB#Wd6*z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)@~i?YpdTN6X#hfBGlTl3$9t#ibP&MU!Gp?~s!vg8PGZO3_J? z6e}n6TedQ2m4POp8!{z##N&0+@W^p)Spj+^SEElO?kw(XUCkF(PUmqiZF&Ojdlw3; z{jmA{S}E)7&vde(8lBbhSIp+$IQorax88s6!gp?d@a$`rTk3QOFtF7=2EE3xJ1%w> z(+A<|i$Rvkl}qylYL(i@o-VBxi>C&G-gkDe{B5=T_Q#Wc^wq1M5B%5dKYZv{uKfE4 zU-{e&F(u`2d2C{jUz3oIcK?y`|8T!#?$*}n8)oJIQU0HPq$bhltP&{uojtUU%~mcT zQd(`(%KrlaP!3`nFj`s#L*@TzI`B6mwk!V+n${9JUDFez{6DS!-*%63cW;-oC!m+F zL-~K&ePYW0BPRwnT|vtK!#S3B+t;Q1KX!?(^R@E-Y});&{6BPVD*sQ5pI!NX`kjBy zxuw)1mH)@B&qS)5ABJDT+3x3Tucs}cUmuI||Fl~ + + + + + \ No newline at end of file diff --git a/c#/protocol1.0/sync_write/win64/sync_write/Properties/AssemblyInfo.cs b/c#/protocol1.0/sync_write/win64/sync_write/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..061150fb --- /dev/null +++ b/c#/protocol1.0/sync_write/win64/sync_write/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("sync_write")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("sync_write")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("23eae323-3535-448b-bc18-2a516bb7759c")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol1.0/sync_write/win64/sync_write/SyncWrite.cs b/c#/protocol1.0/sync_write/win64/sync_write/SyncWrite.cs new file mode 100644 index 00000000..40f9aab4 --- /dev/null +++ b/c#/protocol1.0/sync_write/win64/sync_write/SyncWrite.cs @@ -0,0 +1,230 @@ +/* +* sync_write.cs +* +* Created on: 2016. 5. 16. +* Author: Leon Ryu Woon Jung +*/ + +// +// ********* Sync Write Example ********* +// +// +// Available Dynamixel model on this example : All models using Protocol 1.0 +// This example is designed for using two Dynamixel MX-28, and an USB2DYNAMIXEL. +// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below variables yourself. +// Be sure that Dynamixel MX properties are already set as %% ID : 1 / Baudnum : 1 (Baudrate : 1000000 [1M]) +// + +using System; +using dynamixel_sdk; + +namespace sync_write +{ + class SyncWrite + { + // Control table address + public const int ADDR_MX_TORQUE_ENABLE = 24; // Control table address is different in Dynamixel model + public const int ADDR_MX_GOAL_POSITION = 30; + public const int ADDR_MX_PRESENT_POSITION = 36; + + // Data Byte Length + public const int LEN_MX_GOAL_POSITION = 2; + public const int LEN_MX_PRESENT_POSITION = 2; + + // Protocol version + public const int PROTOCOL_VERSION = 1; // See which protocol version is used in the Dynamixel + + // Default setting + public const int DXL1_ID = 1; // Dynamixel ID: 1 + public const int DXL2_ID = 2; // Dynamixel ID: 2 + public const int BAUDRATE = 1000000; + public const string DEVICENAME = "COM8"; // Check which port is being used on your controller + // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const int TORQUE_ENABLE = 1; // Value for enabling the torque + public const int TORQUE_DISABLE = 0; // Value for disabling the torque + public const int DXL_MINIMUM_POSITION_VALUE = 100; // Dynamixel will rotate between this value + public const int DXL_MAXIMUM_POSITION_VALUE = 4000; // and this value (note that the Dynamixel would not move when the position value is out of movable range. Check e-manual about the range of the Dynamixel you use.) + public const int DXL_MOVING_STATUS_THRESHOLD = 10; // Dynamixel moving status threshold + + public const byte ESC_ASCII_VALUE = 0x1b; + + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num = dynamixel.portHandler(DEVICENAME); + + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + // Initialize Groupsyncwrite instance + int group_num = dynamixel.groupSyncWrite(port_num, PROTOCOL_VERSION, ADDR_MX_GOAL_POSITION, LEN_MX_GOAL_POSITION); + + int index = 0; + int dxl_comm_result = COMM_TX_FAIL; // Communication result + bool dxl_addparam_result = false; // AddParam result + UInt16[] dxl_goal_position = new UInt16[2]{ DXL_MINIMUM_POSITION_VALUE, DXL_MAXIMUM_POSITION_VALUE }; // Goal position + + byte dxl_error = 0; // Dynamixel error + UInt16 dxl1_present_position = 0, dxl2_present_position = 0; // Present position + + // Open port + if (dynamixel.openPort(port_num)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port baudrate + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Enable Dynamixel#1 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL1_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("Dynamixel{0} has been successfully connected ", DXL1_ID); + } + + // Enable Dynamixel#2 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL2_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("Dynamixel{0} has been successfully connected ", DXL1_ID); + } + + while (true) + { + Console.WriteLine("Press any key to continue! (or press ESC to quit!)"); + if (Console.ReadKey().KeyChar == ESC_ASCII_VALUE) + break; + + // Add Dynamixel#1 goal position value to the Syncwrite storage + dxl_addparam_result = dynamixel.groupSyncWriteAddParam(group_num, DXL1_ID, dxl_goal_position[index], LEN_MX_GOAL_POSITION); + if (dxl_addparam_result != true) + { + Console.WriteLine("[ID:{0}] groupSyncWrite addparam failed", DXL1_ID); + return; + } + + // Add Dynamixel#2 goal position value to the Syncwrite parameter storage + dxl_addparam_result = dynamixel.groupSyncWriteAddParam(group_num, DXL2_ID, dxl_goal_position[index], LEN_MX_GOAL_POSITION); + if (dxl_addparam_result != true) + { + Console.WriteLine("[ID:{0}] groupSyncWrite addparam failed", DXL2_ID); + return; + } + + // Syncwrite goal position + dynamixel.groupSyncWriteTxPacket(group_num); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + + // Clear syncwrite parameter storage + dynamixel.groupSyncWriteClearParam(group_num); + + do + { + // Read Dynamixel#1 present position + dxl1_present_position = dynamixel.read2ByteTxRx(port_num, PROTOCOL_VERSION, DXL1_ID, ADDR_MX_PRESENT_POSITION); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Read Dynamixel#2 present position + dxl2_present_position = dynamixel.read2ByteTxRx(port_num, PROTOCOL_VERSION, DXL2_ID, ADDR_MX_PRESENT_POSITION); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + Console.WriteLine("[ID:{0}] GoalPos:{1} PresPos:{2} [ID:{3}] GoalPos:{4} PresPos:{5}", DXL1_ID, dxl_goal_position[index], dxl1_present_position, DXL2_ID, dxl_goal_position[index], dxl2_present_position); + + + } while ((Math.Abs(dxl_goal_position[index] - dxl1_present_position) > DXL_MOVING_STATUS_THRESHOLD) || (Math.Abs(dxl_goal_position[index] - dxl2_present_position) > DXL_MOVING_STATUS_THRESHOLD)); + + // Change goal position + if (index == 0) + { + index = 1; + } + else + { + index = 0; + } + } + + // Disable Dynamixel#1 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL1_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Disable Dynamixel#2 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL2_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Close port + dynamixel.closePort(port_num); + + return; + } + } +} diff --git a/c#/protocol1.0/sync_write/win64/sync_write/dynamixel.cs b/c#/protocol1.0/sync_write/win64/sync_write/dynamixel.cs new file mode 100644 index 00000000..d940e04b --- /dev/null +++ b/c#/protocol1.0/sync_write/win64/sync_write/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win64/output/dxl_x64_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol1.0/sync_write/win64/sync_write/sync_write.csproj b/c#/protocol1.0/sync_write/win64/sync_write/sync_write.csproj new file mode 100644 index 00000000..5da748f7 --- /dev/null +++ b/c#/protocol1.0/sync_write/win64/sync_write/sync_write.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {23EAE323-3535-448B-BC18-2A516BB7759C} + Exe + Properties + sync_write + sync_write + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/broadcast_ping/win32/.vs/broadcast_ping/v14/.suo b/c#/protocol2.0/broadcast_ping/win32/.vs/broadcast_ping/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..9612045a8f81d153a5cbc1d587221e4965899f82 GIT binary patch literal 47616 zcmeHQe~cX0U7xe_!%jldHX)P}+_h^$OT63teRp>3W`CW1u^nHtXFD_#E_1uH=grOS zZf5t+ca778N=Qf))Cwtp1c+8`g`kwSe}F*cS0yBbkWz#qBvc9dR}udpDkP9lV?LjG z^KNHncV}kr_Uzlsyw%&8dGqG|`o8yl-(T;&@4o&1fBWJ$KlFXY<<2RGm3MC+Rqk_y zPvQQMe14yz+=F|Dy?guiZ3Z8P$8G2)s0E%^n)r2;h*DA-xSGlqK^fRRuH3r~b94z$ z_srM+=$#+@{Xb5fLaaAGD55SP$ENa%GLPJAxGO1}o@uyWKCT>^iXiY2cs4sOzV2DX zkY$zmGvAhCpaiC(!{k!tk$6Ck{UdnhJBb5iJih1nCtbjMj?r=VY2tE@f0-w*gcq-qJpSMBsuSyT zw;f?fPuh+2+`aIGEpa{j0OtqdW6lADJ8>lY3SlI_<@Hhf`Nwg69R4TZImQ1Zyo~n* z?tj|xEW=MA>?80e;n|uKsr@bn`kVNG_=4@zAEQ5nZ6HI-$jPv1;5zOa zm`nIyLn&4eYFasqH}Z?#>nY?j7Z2Tk3Fg#}WO$oQefpm)&_FGjhVH~u9amvaKl*hy!XC;3OMErLM z>5NkUBI1*_r6YbJ#y2tYG>pGFl*7Pt+l2|mywsf=#Mh)P4^4dt569tI1{v;kb>cs- z`F8;=(MEYX@SGI~VdFURck&fp`O0^k)jrEcgKMCbS5V)McpUlvp&j5qX06)uZy9i| z*loRmdJ4Q3LqF)H3u5RY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`;h?%Mj@SyM>t9^!w$ zonW~FdzcL7&f@?5wu^PBN$$=wq>2t2ryFXL`?aZq=($OSyIVgj=YoE?yJNar!L3Oy zmdb?^POIsTkMM5yEg&_8Z2bq9>MM<=sTZ`iu1s0Sn)_zphMMmO10s-ycDvn#F|DBA z%X}ICE%-aN4wtkN_gUs{H`9o-(KKP^DQ@{E*7ryx~fAIFBU%CFsCFQ$+{$DTr z@`*nyeeLu+mEZiIO>XT5S5{_fkA3Ie?;N}I<=?4({Wp&N=j^bUh%8GYuT~0!{)Dx) zIMJ$(JZMcz{IZVX%DuT1<*Y4KI)ih56y-JSbyw;x37^e&RUuCuiNIA+agq zZ4}QuS67^*o5X2A1E5!5JY$i1q&CHgP(e!kp6wT%HiD)r5lP={m zxw*Mg_VruUO=D?uCc9Kox9?&bmCcsfeC5{g)0Q<&ZJYRHtD&vcH+5sFU0q$eX`P|j zRu`IP=YrO#8oDWt)ojNqw{E>wjF%F*Od%W1r!uqAbSa&P&gQf6XeyP>%qEkCWGzir|uvxkxfFpu}*UYIV*g>ChG&*~(EH%5% zsEsc52i^h$7e;9$Qi8%L!^8Zn1nSM*ap!;x!@_+Wc?l}bFY4m^g+fe>5 z+RaTr25HSu{trPjkG|lB{}p%xLS&l#`7yPj{6CccEArfsQ2sxv)}>z}?I&-~0iBIk g^ApPdL;3%1)fWy?bSVE1tl0?V|5E94x8?u;4=gas(EtDd literal 0 HcmV?d00001 diff --git a/c#/protocol2.0/broadcast_ping/win32/broadcast_ping.sln b/c#/protocol2.0/broadcast_ping/win32/broadcast_ping.sln new file mode 100644 index 00000000..133769ca --- /dev/null +++ b/c#/protocol2.0/broadcast_ping/win32/broadcast_ping.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 14 for Windows Desktop +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "broadcast_ping", "broadcast_ping\broadcast_ping.csproj", "{AF5022F2-06A2-41D5-A04F-128C8C1E0A7F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AF5022F2-06A2-41D5-A04F-128C8C1E0A7F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AF5022F2-06A2-41D5-A04F-128C8C1E0A7F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AF5022F2-06A2-41D5-A04F-128C8C1E0A7F}.Debug|x86.ActiveCfg = Release|x86 + {AF5022F2-06A2-41D5-A04F-128C8C1E0A7F}.Debug|x86.Build.0 = Release|x86 + {AF5022F2-06A2-41D5-A04F-128C8C1E0A7F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AF5022F2-06A2-41D5-A04F-128C8C1E0A7F}.Release|Any CPU.Build.0 = Release|Any CPU + {AF5022F2-06A2-41D5-A04F-128C8C1E0A7F}.Release|x86.ActiveCfg = Release|x86 + {AF5022F2-06A2-41D5-A04F-128C8C1E0A7F}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/c#/protocol2.0/broadcast_ping/win32/broadcast_ping/App.config b/c#/protocol2.0/broadcast_ping/win32/broadcast_ping/App.config new file mode 100644 index 00000000..8e156463 --- /dev/null +++ b/c#/protocol2.0/broadcast_ping/win32/broadcast_ping/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/broadcast_ping/win32/broadcast_ping/BroadcastPing.cs b/c#/protocol2.0/broadcast_ping/win32/broadcast_ping/BroadcastPing.cs new file mode 100644 index 00000000..0882c447 --- /dev/null +++ b/c#/protocol2.0/broadcast_ping/win32/broadcast_ping/BroadcastPing.cs @@ -0,0 +1,95 @@ +/* +* broadcast_ping.cs +* +* Created on: 2016. 5. 16. +* Author: Leon Ryu Woon Jung +*/ + +// +// ********* broadcastPing Example ********* +// +// +// Available Dynamixel model on this example : All models using Protocol 2.0 +// This example is designed for using a Dynamixel PRO 54-200, and an USB2DYNAMIXEL. +// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below variables yourself. +// Be sure that Dynamixel PRO properties are already set as %% ID : 1 / Baudnum : 3 (Baudrate : 1000000 [1M]) +// + +using System; +using dynamixel_sdk; + +namespace broadcast_ping +{ + class BroadcastPing + { + // Protocol version + public const int PROTOCOL_VERSION = 2; // See which protocol version is used in the Dynamixel + + // Default setting + public const int BAUDRATE = 1000000; + public const string DEVICENAME = "COM8"; // Check which port is being used on your controller + // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const byte ESC_ASCII_VALUE = 0x1b; + + public const int MAX_ID = 252; // Maximum ID value + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num = dynamixel.portHandler(DEVICENAME); + int id; + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + int dxl_comm_result = COMM_TX_FAIL; // Communication result + + // Open port + if (dynamixel.openPort(port_num)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port baudrate + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Try to broadcast ping the Dynamixel + dynamixel.broadcastPing(port_num, PROTOCOL_VERSION); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + + Console.WriteLine("Detected Dynamixel :"); + for (id = 0; id < MAX_ID; id++) + { + if (dynamixel.getBroadcastPingResult(port_num, PROTOCOL_VERSION, id)) + Console.WriteLine("[ID:{0}]", id); + } + + // Close port + dynamixel.closePort(port_num); + + return; + } + } +} diff --git a/c#/protocol2.0/broadcast_ping/win32/broadcast_ping/Properties/AssemblyInfo.cs b/c#/protocol2.0/broadcast_ping/win32/broadcast_ping/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..0dc882b9 --- /dev/null +++ b/c#/protocol2.0/broadcast_ping/win32/broadcast_ping/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("broadcast_ping")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("broadcast_ping")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("af5022f2-06a2-41d5-a04f-128c8c1e0a7f")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol2.0/broadcast_ping/win32/broadcast_ping/broadcast_ping.csproj b/c#/protocol2.0/broadcast_ping/win32/broadcast_ping/broadcast_ping.csproj new file mode 100644 index 00000000..c5295ef8 --- /dev/null +++ b/c#/protocol2.0/broadcast_ping/win32/broadcast_ping/broadcast_ping.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {AF5022F2-06A2-41D5-A04F-128C8C1E0A7F} + Exe + Properties + broadcast_ping + broadcast_ping + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/broadcast_ping/win32/broadcast_ping/dynamixel.cs b/c#/protocol2.0/broadcast_ping/win32/broadcast_ping/dynamixel.cs new file mode 100644 index 00000000..235af316 --- /dev/null +++ b/c#/protocol2.0/broadcast_ping/win32/broadcast_ping/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win32/output/dxl_x86_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol2.0/broadcast_ping/win64/.vs/broadcast_ping/v14/.suo b/c#/protocol2.0/broadcast_ping/win64/.vs/broadcast_ping/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..7b0ca4224216988b1a8b5e98c259ad409a20fe83 GIT binary patch literal 47616 zcmeHQZHyerS?;y(!@fK2lH75Ga5!Vf90|8G%=gaPXD9QqYwy`UZ*JE1k?Uixccy1O zx4koSGqd(C_9d4{Nc;#95z+w?ksyEs0RhP$1VjRY1PCE6{D_cHB*?Ew{6TyOkWkJ% zPgmDYPft&G&+P1ZXVW#R?w;!E`gq@}x88c+x2nGR&inu6*T4Fq?+gP(^#3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jp9Gg)fFe{ zCUI&|(ew$>**MXc_VoFM|^nJV9YciJ+Y<@>8^`nGPYcB&hzx6Ly&JL+1?qW z%_T~?XewDs-mNN&}6e*38BzuWh-;(w3ds;^|TfZ z&wuZ(ws2gq6OPXF=jHkD2gmv;TuCISU8HGr)QX4lUqWFG&=^fJbHDaLu*>sf*6z|$ z1{$6uVn4q$l>eHY{61g8^*cTr+)Rx!w6hW#IYxo|BpJ# zg!2DT{%=6)NINmVS&&^|%wEUyr9%1tu2edd|0|*V-(ALTmqds1|GjBDoHB1A4fd0D rhw}eHoyfGv|2gY)$NE_%l>hHlePI(thw}fxnvGEYFO@F$TmJw5e%!=p literal 0 HcmV?d00001 diff --git a/c#/protocol2.0/broadcast_ping/win64/broadcast_ping.sln b/c#/protocol2.0/broadcast_ping/win64/broadcast_ping.sln new file mode 100644 index 00000000..26806165 --- /dev/null +++ b/c#/protocol2.0/broadcast_ping/win64/broadcast_ping.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 14 for Windows Desktop +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "broadcast_ping", "broadcast_ping\broadcast_ping.csproj", "{AF5022F2-06A2-41D5-A04F-128C8C1E0A7F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AF5022F2-06A2-41D5-A04F-128C8C1E0A7F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AF5022F2-06A2-41D5-A04F-128C8C1E0A7F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AF5022F2-06A2-41D5-A04F-128C8C1E0A7F}.Debug|x64.ActiveCfg = Release|x64 + {AF5022F2-06A2-41D5-A04F-128C8C1E0A7F}.Debug|x64.Build.0 = Release|x64 + {AF5022F2-06A2-41D5-A04F-128C8C1E0A7F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AF5022F2-06A2-41D5-A04F-128C8C1E0A7F}.Release|Any CPU.Build.0 = Release|Any CPU + {AF5022F2-06A2-41D5-A04F-128C8C1E0A7F}.Release|x64.ActiveCfg = Release|x64 + {AF5022F2-06A2-41D5-A04F-128C8C1E0A7F}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/c#/protocol2.0/broadcast_ping/win64/broadcast_ping/App.config b/c#/protocol2.0/broadcast_ping/win64/broadcast_ping/App.config new file mode 100644 index 00000000..8e156463 --- /dev/null +++ b/c#/protocol2.0/broadcast_ping/win64/broadcast_ping/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/broadcast_ping/win64/broadcast_ping/BroadcastPing.cs b/c#/protocol2.0/broadcast_ping/win64/broadcast_ping/BroadcastPing.cs new file mode 100644 index 00000000..0882c447 --- /dev/null +++ b/c#/protocol2.0/broadcast_ping/win64/broadcast_ping/BroadcastPing.cs @@ -0,0 +1,95 @@ +/* +* broadcast_ping.cs +* +* Created on: 2016. 5. 16. +* Author: Leon Ryu Woon Jung +*/ + +// +// ********* broadcastPing Example ********* +// +// +// Available Dynamixel model on this example : All models using Protocol 2.0 +// This example is designed for using a Dynamixel PRO 54-200, and an USB2DYNAMIXEL. +// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below variables yourself. +// Be sure that Dynamixel PRO properties are already set as %% ID : 1 / Baudnum : 3 (Baudrate : 1000000 [1M]) +// + +using System; +using dynamixel_sdk; + +namespace broadcast_ping +{ + class BroadcastPing + { + // Protocol version + public const int PROTOCOL_VERSION = 2; // See which protocol version is used in the Dynamixel + + // Default setting + public const int BAUDRATE = 1000000; + public const string DEVICENAME = "COM8"; // Check which port is being used on your controller + // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const byte ESC_ASCII_VALUE = 0x1b; + + public const int MAX_ID = 252; // Maximum ID value + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num = dynamixel.portHandler(DEVICENAME); + int id; + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + int dxl_comm_result = COMM_TX_FAIL; // Communication result + + // Open port + if (dynamixel.openPort(port_num)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port baudrate + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Try to broadcast ping the Dynamixel + dynamixel.broadcastPing(port_num, PROTOCOL_VERSION); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + + Console.WriteLine("Detected Dynamixel :"); + for (id = 0; id < MAX_ID; id++) + { + if (dynamixel.getBroadcastPingResult(port_num, PROTOCOL_VERSION, id)) + Console.WriteLine("[ID:{0}]", id); + } + + // Close port + dynamixel.closePort(port_num); + + return; + } + } +} diff --git a/c#/protocol2.0/broadcast_ping/win64/broadcast_ping/Properties/AssemblyInfo.cs b/c#/protocol2.0/broadcast_ping/win64/broadcast_ping/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..0dc882b9 --- /dev/null +++ b/c#/protocol2.0/broadcast_ping/win64/broadcast_ping/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("broadcast_ping")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("broadcast_ping")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("af5022f2-06a2-41d5-a04f-128c8c1e0a7f")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol2.0/broadcast_ping/win64/broadcast_ping/broadcast_ping.csproj b/c#/protocol2.0/broadcast_ping/win64/broadcast_ping/broadcast_ping.csproj new file mode 100644 index 00000000..9dfdbc7a --- /dev/null +++ b/c#/protocol2.0/broadcast_ping/win64/broadcast_ping/broadcast_ping.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {AF5022F2-06A2-41D5-A04F-128C8C1E0A7F} + Exe + Properties + broadcast_ping + broadcast_ping + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/broadcast_ping/win64/broadcast_ping/dynamixel.cs b/c#/protocol2.0/broadcast_ping/win64/broadcast_ping/dynamixel.cs new file mode 100644 index 00000000..d940e04b --- /dev/null +++ b/c#/protocol2.0/broadcast_ping/win64/broadcast_ping/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win64/output/dxl_x64_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol2.0/bulk_read_write/win32/.vs/bulk_read_write/v14/.suo b/c#/protocol2.0/bulk_read_write/win32/.vs/bulk_read_write/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..50d3b86372e5f6f98db6d3b38800e6b46931faa6 GIT binary patch literal 36352 zcmeHQYm6J$bsowuIdU62el&GcdF{%M94#5XACe`Tuay)_*2Y{(ZcUe-C5OAza!F>$ zl~&EFX^RAC(Fc;ENcyKh3&a6p7zz9!ZUEofP-hO?<%XH&WkPiXhG+x#a+ zy!D5_`LCNd|LSi%O!wX=W#VO&Sl6y-XHj|?v8=W|BA4#RPk z@>y;}tD**`W&m=ag$^*Rbc0SuCMf^sklFXxaS$$OTPUTfRe(QX%~o;-cTAaV;1T6} zp2E}n0HnjfgtiAikNEvo`9~1{v7LZc{8`+84)6frV}OGImF#B_|2Tj&d<5_bz@vc2 z0FMKn0Q?kyP5jeKqniD*`$>Sa*%JYDb(~9^>EpQd~PDxl_KHRUvDxz&vL9B*0KZmo9 z=V_d`a7Who)CBgIj&jNC48!a%+Jxk-VPO*cZxtDSh6I~ZAl+3MH_IjTfGm1a7{@ev zlNUY7kMj~@0sJz!E`YO_!1-y=zo9j|iio29Y2UG5vkqMk2V4+!_AQ3X!s;!dO|PK@ z9qpuL98p5~CZ22}-cx>;o{+hYK2nx3yoNlhC`ktwZdhes0G5jHx=WMq z*pIZoDIdq7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cduxs#AEKpFbN$=>t*kB+8{f`S*KWU+b^Cm4WUha$ g!IIMkn1cSb_d)7ienV-le`o(c9J_sT?iBs||E;VyX8-^I literal 0 HcmV?d00001 diff --git a/c#/protocol2.0/bulk_read_write/win32/bulk_read_write.sln b/c#/protocol2.0/bulk_read_write/win32/bulk_read_write.sln new file mode 100644 index 00000000..71a1798f --- /dev/null +++ b/c#/protocol2.0/bulk_read_write/win32/bulk_read_write.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 14 for Windows Desktop +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bulk_read_write", "bulk_read_write\bulk_read_write.csproj", "{AE76B9AC-97EB-40B1-8161-576C3B15CCB8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AE76B9AC-97EB-40B1-8161-576C3B15CCB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AE76B9AC-97EB-40B1-8161-576C3B15CCB8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AE76B9AC-97EB-40B1-8161-576C3B15CCB8}.Debug|x86.ActiveCfg = Debug|x86 + {AE76B9AC-97EB-40B1-8161-576C3B15CCB8}.Debug|x86.Build.0 = Debug|x86 + {AE76B9AC-97EB-40B1-8161-576C3B15CCB8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AE76B9AC-97EB-40B1-8161-576C3B15CCB8}.Release|Any CPU.Build.0 = Release|Any CPU + {AE76B9AC-97EB-40B1-8161-576C3B15CCB8}.Release|x86.ActiveCfg = Release|x86 + {AE76B9AC-97EB-40B1-8161-576C3B15CCB8}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/c#/protocol2.0/bulk_read_write/win32/bulk_read_write/App.config b/c#/protocol2.0/bulk_read_write/win32/bulk_read_write/App.config new file mode 100644 index 00000000..8e156463 --- /dev/null +++ b/c#/protocol2.0/bulk_read_write/win32/bulk_read_write/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/bulk_read_write/win32/bulk_read_write/BulkReadWrite.cs b/c#/protocol2.0/bulk_read_write/win32/bulk_read_write/BulkReadWrite.cs new file mode 100644 index 00000000..8562657e --- /dev/null +++ b/c#/protocol2.0/bulk_read_write/win32/bulk_read_write/BulkReadWrite.cs @@ -0,0 +1,257 @@ +/* +* bulk_read_write.c +* +* Created on: 2016. 5. 16. +* Author: Leon Ryu Woon Jung +*/ + +// +// ********* Bulk Read and Bulk Write Example ********* +// +// +// Available Dynamixel model on this example : All models using Protocol 2.0 +// This example is designed for using two Dynamixel PRO 54-200, and an USB2DYNAMIXEL. +// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below variables yourself. +// Be sure that Dynamixel PRO properties are already set as %% ID : 1 and 2 / Baudnum : 3 (Baudrate : 1000000 [1M]) +// + +using System; +using dynamixel_sdk; + +namespace bulk_read_write +{ + class BulkReadWrite + { + // Control table address + public const int ADDR_PRO_TORQUE_ENABLE = 562; // Control table address is different in Dynamixel model + public const int ADDR_PRO_LED_RED = 563; + public const int ADDR_PRO_GOAL_POSITION = 596; + public const int ADDR_PRO_PRESENT_POSITION = 611; + + + // Data Byte Length + public const int LEN_PRO_LED_RED = 1; + public const int LEN_PRO_GOAL_POSITION = 4; + public const int LEN_PRO_PRESENT_POSITION = 4; + + // Protocol version + public const int PROTOCOL_VERSION = 2; // See which protocol version is used in the Dynamixel + + // Default setting + public const int DXL1_ID = 1; // Dynamixel ID: 1 + public const int DXL2_ID = 2; // Dynamixel ID: 2 + public const int BAUDRATE = 1000000; + public const string DEVICENAME = "COM8"; // Check which port is being used on your controller + // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const int TORQUE_ENABLE = 1; // Value for enabling the torque + public const int TORQUE_DISABLE = 0; // Value for disabling the torque + public const int DXL_MINIMUM_POSITION_VALUE = -150000; // Dynamixel will rotate between this value + public const int DXL_MAXIMUM_POSITION_VALUE = 150000; // and this value (note that the Dynamixel would not move when the position value is out of movable range. Check e-manual about the range of the Dynamixel you use.) + public const int DXL_MOVING_STATUS_THRESHOLD = 20; // Dynamixel moving status threshold + + public const byte ESC_ASCII_VALUE = 0x1b; + + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num = dynamixel.portHandler(DEVICENAME); + + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + // Initialize GroupBulkWrite Struct + int groupwrite_num = dynamixel.groupBulkWrite(port_num, PROTOCOL_VERSION); + + // Initialize Groupbulkread Structs + int groupread_num = dynamixel.groupBulkRead(port_num, PROTOCOL_VERSION); + + int index = 0; + int dxl_comm_result = COMM_TX_FAIL; // Communication result + bool dxl_addparam_result = false; // AddParam result + bool dxl_getdata_result = false; // GetParam result + int[] dxl_goal_position = new int[2]{ DXL_MINIMUM_POSITION_VALUE, DXL_MAXIMUM_POSITION_VALUE }; // Goal position + + byte dxl_error = 0; // Dynamixel error + byte[] dxl_led_value = new byte[2]{ 0x00, 0xFF }; // Dynamixel LED value for write + Int32 dxl1_present_position = 0; // Present position + byte dxl2_led_value_read = 0; // Dynamixel moving status + + // Open port + if (dynamixel.openPort(port_num)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port baudrate + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Enable Dynamixel#1 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL1_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("Dynamixel{0} has been successfully connected ", DXL1_ID); + } + + // Enable Dynamixel#2 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL2_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("Dynamixel{0} has been successfully connected ", DXL1_ID); + } + + // Add parameter storage for Dynamixel#1 present position value + dxl_addparam_result = dynamixel.groupBulkReadAddParam(groupread_num, DXL1_ID, ADDR_PRO_PRESENT_POSITION, LEN_PRO_PRESENT_POSITION); + if (dxl_addparam_result != true) + { + Console.WriteLine("[ID:{0}] groupBulkRead addparam failed", DXL1_ID); + return; + } + + // Add parameter storage for Dynamixel#2 present moving value + dxl_addparam_result = dynamixel.groupBulkReadAddParam(groupread_num, DXL2_ID, ADDR_PRO_LED_RED, LEN_PRO_LED_RED); + if (dxl_addparam_result != true) + { + Console.WriteLine("[ID:{0}] groupBulkRead addparam failed", DXL2_ID); + return; + } + + while (true) + { + Console.WriteLine("Press any key to continue! (or press ESC to quit!)"); + if (Console.ReadKey().KeyChar == ESC_ASCII_VALUE) + break; + + // Add parameter storage for Dynamixel#1 goal position + dxl_addparam_result = dynamixel.groupBulkWriteAddParam(groupwrite_num, DXL1_ID, ADDR_PRO_GOAL_POSITION, LEN_PRO_GOAL_POSITION, (UInt32)dxl_goal_position[index], LEN_PRO_GOAL_POSITION); + if (dxl_addparam_result != true) + { + Console.WriteLine("[ID:{0}] groupBulkWrite addparam failed", DXL1_ID); + return; + } + + // Add parameter storage for Dynamixel#2 LED value + dxl_addparam_result = dynamixel.groupBulkWriteAddParam(groupwrite_num, DXL2_ID, ADDR_PRO_LED_RED, LEN_PRO_LED_RED, dxl_led_value[index], LEN_PRO_LED_RED); + if (dxl_addparam_result != true) + { + Console.WriteLine("[ID:{0}] groupBulkWrite addparam failed", DXL2_ID); + return; + } + + // Bulkwrite goal position and LED value + dynamixel.groupBulkWriteTxPacket(groupwrite_num); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + + // Clear bulkwrite parameter storage + dynamixel.groupBulkWriteClearParam(groupwrite_num); + + do + { + // Bulkread present position and moving status + dynamixel.groupBulkReadTxRxPacket(groupread_num); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + + dxl_getdata_result = dynamixel.groupBulkReadIsAvailable(groupread_num, DXL1_ID, ADDR_PRO_PRESENT_POSITION, LEN_PRO_PRESENT_POSITION); + if (dxl_getdata_result != true) + { + Console.WriteLine("[ID:{0}] groupBulkRead getdata failed", DXL1_ID); + return; + } + + dxl_getdata_result = dynamixel.groupBulkReadIsAvailable(groupread_num, DXL2_ID, ADDR_PRO_LED_RED, LEN_PRO_LED_RED); + if (dxl_getdata_result != true) + { + Console.WriteLine("[ID:{0}] groupBulkRead getdata failed", DXL2_ID); + return; + } + + // Get Dynamixel#1 present position value + dxl1_present_position = (Int32)dynamixel.groupBulkReadGetData(groupread_num, DXL1_ID, ADDR_PRO_PRESENT_POSITION, LEN_PRO_PRESENT_POSITION); + + // Get Dynamixel#2 moving status value + dxl2_led_value_read = (byte)dynamixel.groupBulkReadGetData(groupread_num, DXL2_ID, ADDR_PRO_LED_RED, LEN_PRO_LED_RED); + + Console.WriteLine("[ID:{0}] Present Position : {1} [ID:{2}] LED Value : {3}", DXL1_ID, dxl1_present_position, DXL2_ID, dxl2_led_value_read); + + } while (Math.Abs(dxl_goal_position[index] - dxl1_present_position) > DXL_MOVING_STATUS_THRESHOLD); + + // Change goal position + if (index == 0) + { + index = 1; + } + else + { + index = 0; + } + } + + // Disable Dynamixel#1 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL1_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Disable Dynamixel#2 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL2_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Close port + dynamixel.closePort(port_num); + + return; + } + } +} diff --git a/c#/protocol2.0/bulk_read_write/win32/bulk_read_write/Properties/AssemblyInfo.cs b/c#/protocol2.0/bulk_read_write/win32/bulk_read_write/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..fbef6b56 --- /dev/null +++ b/c#/protocol2.0/bulk_read_write/win32/bulk_read_write/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("bulk_read_write")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("bulk_read_write")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("ae76b9ac-97eb-40b1-8161-576c3b15ccb8")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol2.0/bulk_read_write/win32/bulk_read_write/bulk_read_write.csproj b/c#/protocol2.0/bulk_read_write/win32/bulk_read_write/bulk_read_write.csproj new file mode 100644 index 00000000..fdd87e13 --- /dev/null +++ b/c#/protocol2.0/bulk_read_write/win32/bulk_read_write/bulk_read_write.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {AE76B9AC-97EB-40B1-8161-576C3B15CCB8} + Exe + Properties + bulk_read_write + bulk_read_write + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/bulk_read_write/win32/bulk_read_write/dynamixel.cs b/c#/protocol2.0/bulk_read_write/win32/bulk_read_write/dynamixel.cs new file mode 100644 index 00000000..235af316 --- /dev/null +++ b/c#/protocol2.0/bulk_read_write/win32/bulk_read_write/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win32/output/dxl_x86_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol2.0/bulk_read_write/win64/.vs/bulk_read_write/v14/.suo b/c#/protocol2.0/bulk_read_write/win64/.vs/bulk_read_write/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..fa096dca64071f4a18b461eba4d1154e5fdcddff GIT binary patch literal 36352 zcmeHQTZ|i586Kx;n>2;Cv<+=3i5o&`o3*jmm$j3ojc=P>l5NuNCR?d4?(BHHao20R zWABY_KtxpH0i^bY0um1hiqsMn$`eJ1mI@(+5KSKt65;^_4~7|)j_1tGne(6ja{m86*S+xWZGZaq8~6NKvV=#Z>!gd9c1kyxo_kDb=~hX) z3-^3>@zSMBe8n`9ZrDT=ctWb+uP%9|j8w)|la|Oz$6>d0{R+=_+I;oH+4JB0+ppjA zd>HxOzT3!r5)doWv(hM_7m&(Gi#DaSzTPcuTY*oqx4vzEH-^U$Up)x;gj^qIdbV8Z~l#)~g{*2Qm$Z0&$IstAx2Yk;>NV80*_#Z{y z8yfIGhV%yxyfh%A=*??L+Gh-5kM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5k6cmHq8K|MT)kBW@Z-T!Oe%iG-H+dXCe#&p&K3F_|uZGR$xyZ_gI@9pJYzvJ%z z<=Gg`zT7f)^Y*eA+1>x^?*Dc7|E^{GxV!)NN}Zv2dDj10*Y93y`+s@9p%>PICs6a` z*C`y4!*i&44(ICAsj_X(_shcabUOQw=TRAF{bh0f$&$XVo=|A3j5Edk*!5b%ALmco z=b-Ot4o8#6M>&Jm+euqoYg<6n5X%_rzdBeOxN@%CjB7g#r#C5vkAbpv@OK2ib)3N? z_{;q^W}GQAtvTCKfh(mpBcF{^r3LO>AJ&Sy@xC3#o0abZWBwnHvh-XRzFTuzsgTYb zA8n1}DV`DvBD$gP6mZWUTpvlrI*PTHLh1h{;#N4pWi2$Yw*FqrXm@^LFJ)ldzPIxW zErs{>{K7jy4HAU$uO4L+oL^{nW})4CVtSR%G&C4_dCo61%69VWo?qzhKQzt*w%Y@l zfH=AP58I#X+xz&XyZ_L7CKyz)yZ>Rc;d<#h#RO51F||eBuA$LJ~b4M_;6%n%omU53%-ad7eeu{ zs)nL*e;^PT3dNSK{^eZ~{}t-|%Hvz#zJN6UrIY!*)RotLNr?H6wHD^|{L@b5bKRAD z{%I%b*gt0njB)wOx4#6A7FO2#|Hsz*|F7&Rw6$}%_SgCU%Gf$*jkxw#|K}rW*6IWF f!Ty@{1?}!(MA!aq{{P|FZT*3n=e?z`w*CD-#{wfV literal 0 HcmV?d00001 diff --git a/c#/protocol2.0/bulk_read_write/win64/bulk_read_write.sln b/c#/protocol2.0/bulk_read_write/win64/bulk_read_write.sln new file mode 100644 index 00000000..178ce4e7 --- /dev/null +++ b/c#/protocol2.0/bulk_read_write/win64/bulk_read_write.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 14 for Windows Desktop +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bulk_read_write", "bulk_read_write\bulk_read_write.csproj", "{AE76B9AC-97EB-40B1-8161-576C3B15CCB8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AE76B9AC-97EB-40B1-8161-576C3B15CCB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AE76B9AC-97EB-40B1-8161-576C3B15CCB8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AE76B9AC-97EB-40B1-8161-576C3B15CCB8}.Debug|x64.ActiveCfg = Debug|x64 + {AE76B9AC-97EB-40B1-8161-576C3B15CCB8}.Debug|x64.Build.0 = Debug|x64 + {AE76B9AC-97EB-40B1-8161-576C3B15CCB8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AE76B9AC-97EB-40B1-8161-576C3B15CCB8}.Release|Any CPU.Build.0 = Release|Any CPU + {AE76B9AC-97EB-40B1-8161-576C3B15CCB8}.Release|x64.ActiveCfg = Release|x64 + {AE76B9AC-97EB-40B1-8161-576C3B15CCB8}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/c#/protocol2.0/bulk_read_write/win64/bulk_read_write/App.config b/c#/protocol2.0/bulk_read_write/win64/bulk_read_write/App.config new file mode 100644 index 00000000..8e156463 --- /dev/null +++ b/c#/protocol2.0/bulk_read_write/win64/bulk_read_write/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/bulk_read_write/win64/bulk_read_write/BulkReadWrite.cs b/c#/protocol2.0/bulk_read_write/win64/bulk_read_write/BulkReadWrite.cs new file mode 100644 index 00000000..8562657e --- /dev/null +++ b/c#/protocol2.0/bulk_read_write/win64/bulk_read_write/BulkReadWrite.cs @@ -0,0 +1,257 @@ +/* +* bulk_read_write.c +* +* Created on: 2016. 5. 16. +* Author: Leon Ryu Woon Jung +*/ + +// +// ********* Bulk Read and Bulk Write Example ********* +// +// +// Available Dynamixel model on this example : All models using Protocol 2.0 +// This example is designed for using two Dynamixel PRO 54-200, and an USB2DYNAMIXEL. +// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below variables yourself. +// Be sure that Dynamixel PRO properties are already set as %% ID : 1 and 2 / Baudnum : 3 (Baudrate : 1000000 [1M]) +// + +using System; +using dynamixel_sdk; + +namespace bulk_read_write +{ + class BulkReadWrite + { + // Control table address + public const int ADDR_PRO_TORQUE_ENABLE = 562; // Control table address is different in Dynamixel model + public const int ADDR_PRO_LED_RED = 563; + public const int ADDR_PRO_GOAL_POSITION = 596; + public const int ADDR_PRO_PRESENT_POSITION = 611; + + + // Data Byte Length + public const int LEN_PRO_LED_RED = 1; + public const int LEN_PRO_GOAL_POSITION = 4; + public const int LEN_PRO_PRESENT_POSITION = 4; + + // Protocol version + public const int PROTOCOL_VERSION = 2; // See which protocol version is used in the Dynamixel + + // Default setting + public const int DXL1_ID = 1; // Dynamixel ID: 1 + public const int DXL2_ID = 2; // Dynamixel ID: 2 + public const int BAUDRATE = 1000000; + public const string DEVICENAME = "COM8"; // Check which port is being used on your controller + // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const int TORQUE_ENABLE = 1; // Value for enabling the torque + public const int TORQUE_DISABLE = 0; // Value for disabling the torque + public const int DXL_MINIMUM_POSITION_VALUE = -150000; // Dynamixel will rotate between this value + public const int DXL_MAXIMUM_POSITION_VALUE = 150000; // and this value (note that the Dynamixel would not move when the position value is out of movable range. Check e-manual about the range of the Dynamixel you use.) + public const int DXL_MOVING_STATUS_THRESHOLD = 20; // Dynamixel moving status threshold + + public const byte ESC_ASCII_VALUE = 0x1b; + + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num = dynamixel.portHandler(DEVICENAME); + + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + // Initialize GroupBulkWrite Struct + int groupwrite_num = dynamixel.groupBulkWrite(port_num, PROTOCOL_VERSION); + + // Initialize Groupbulkread Structs + int groupread_num = dynamixel.groupBulkRead(port_num, PROTOCOL_VERSION); + + int index = 0; + int dxl_comm_result = COMM_TX_FAIL; // Communication result + bool dxl_addparam_result = false; // AddParam result + bool dxl_getdata_result = false; // GetParam result + int[] dxl_goal_position = new int[2]{ DXL_MINIMUM_POSITION_VALUE, DXL_MAXIMUM_POSITION_VALUE }; // Goal position + + byte dxl_error = 0; // Dynamixel error + byte[] dxl_led_value = new byte[2]{ 0x00, 0xFF }; // Dynamixel LED value for write + Int32 dxl1_present_position = 0; // Present position + byte dxl2_led_value_read = 0; // Dynamixel moving status + + // Open port + if (dynamixel.openPort(port_num)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port baudrate + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Enable Dynamixel#1 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL1_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("Dynamixel{0} has been successfully connected ", DXL1_ID); + } + + // Enable Dynamixel#2 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL2_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("Dynamixel{0} has been successfully connected ", DXL1_ID); + } + + // Add parameter storage for Dynamixel#1 present position value + dxl_addparam_result = dynamixel.groupBulkReadAddParam(groupread_num, DXL1_ID, ADDR_PRO_PRESENT_POSITION, LEN_PRO_PRESENT_POSITION); + if (dxl_addparam_result != true) + { + Console.WriteLine("[ID:{0}] groupBulkRead addparam failed", DXL1_ID); + return; + } + + // Add parameter storage for Dynamixel#2 present moving value + dxl_addparam_result = dynamixel.groupBulkReadAddParam(groupread_num, DXL2_ID, ADDR_PRO_LED_RED, LEN_PRO_LED_RED); + if (dxl_addparam_result != true) + { + Console.WriteLine("[ID:{0}] groupBulkRead addparam failed", DXL2_ID); + return; + } + + while (true) + { + Console.WriteLine("Press any key to continue! (or press ESC to quit!)"); + if (Console.ReadKey().KeyChar == ESC_ASCII_VALUE) + break; + + // Add parameter storage for Dynamixel#1 goal position + dxl_addparam_result = dynamixel.groupBulkWriteAddParam(groupwrite_num, DXL1_ID, ADDR_PRO_GOAL_POSITION, LEN_PRO_GOAL_POSITION, (UInt32)dxl_goal_position[index], LEN_PRO_GOAL_POSITION); + if (dxl_addparam_result != true) + { + Console.WriteLine("[ID:{0}] groupBulkWrite addparam failed", DXL1_ID); + return; + } + + // Add parameter storage for Dynamixel#2 LED value + dxl_addparam_result = dynamixel.groupBulkWriteAddParam(groupwrite_num, DXL2_ID, ADDR_PRO_LED_RED, LEN_PRO_LED_RED, dxl_led_value[index], LEN_PRO_LED_RED); + if (dxl_addparam_result != true) + { + Console.WriteLine("[ID:{0}] groupBulkWrite addparam failed", DXL2_ID); + return; + } + + // Bulkwrite goal position and LED value + dynamixel.groupBulkWriteTxPacket(groupwrite_num); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + + // Clear bulkwrite parameter storage + dynamixel.groupBulkWriteClearParam(groupwrite_num); + + do + { + // Bulkread present position and moving status + dynamixel.groupBulkReadTxRxPacket(groupread_num); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + + dxl_getdata_result = dynamixel.groupBulkReadIsAvailable(groupread_num, DXL1_ID, ADDR_PRO_PRESENT_POSITION, LEN_PRO_PRESENT_POSITION); + if (dxl_getdata_result != true) + { + Console.WriteLine("[ID:{0}] groupBulkRead getdata failed", DXL1_ID); + return; + } + + dxl_getdata_result = dynamixel.groupBulkReadIsAvailable(groupread_num, DXL2_ID, ADDR_PRO_LED_RED, LEN_PRO_LED_RED); + if (dxl_getdata_result != true) + { + Console.WriteLine("[ID:{0}] groupBulkRead getdata failed", DXL2_ID); + return; + } + + // Get Dynamixel#1 present position value + dxl1_present_position = (Int32)dynamixel.groupBulkReadGetData(groupread_num, DXL1_ID, ADDR_PRO_PRESENT_POSITION, LEN_PRO_PRESENT_POSITION); + + // Get Dynamixel#2 moving status value + dxl2_led_value_read = (byte)dynamixel.groupBulkReadGetData(groupread_num, DXL2_ID, ADDR_PRO_LED_RED, LEN_PRO_LED_RED); + + Console.WriteLine("[ID:{0}] Present Position : {1} [ID:{2}] LED Value : {3}", DXL1_ID, dxl1_present_position, DXL2_ID, dxl2_led_value_read); + + } while (Math.Abs(dxl_goal_position[index] - dxl1_present_position) > DXL_MOVING_STATUS_THRESHOLD); + + // Change goal position + if (index == 0) + { + index = 1; + } + else + { + index = 0; + } + } + + // Disable Dynamixel#1 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL1_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Disable Dynamixel#2 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL2_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Close port + dynamixel.closePort(port_num); + + return; + } + } +} diff --git a/c#/protocol2.0/bulk_read_write/win64/bulk_read_write/Properties/AssemblyInfo.cs b/c#/protocol2.0/bulk_read_write/win64/bulk_read_write/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..fbef6b56 --- /dev/null +++ b/c#/protocol2.0/bulk_read_write/win64/bulk_read_write/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("bulk_read_write")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("bulk_read_write")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("ae76b9ac-97eb-40b1-8161-576c3b15ccb8")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol2.0/bulk_read_write/win64/bulk_read_write/bulk_read_write.csproj b/c#/protocol2.0/bulk_read_write/win64/bulk_read_write/bulk_read_write.csproj new file mode 100644 index 00000000..8bbcd31c --- /dev/null +++ b/c#/protocol2.0/bulk_read_write/win64/bulk_read_write/bulk_read_write.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {AE76B9AC-97EB-40B1-8161-576C3B15CCB8} + Exe + Properties + bulk_read_write + bulk_read_write + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/bulk_read_write/win64/bulk_read_write/dynamixel.cs b/c#/protocol2.0/bulk_read_write/win64/bulk_read_write/dynamixel.cs new file mode 100644 index 00000000..d940e04b --- /dev/null +++ b/c#/protocol2.0/bulk_read_write/win64/bulk_read_write/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win64/output/dxl_x64_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol2.0/factory_reset/win32/.vs/factory_reset/v14/.suo b/c#/protocol2.0/factory_reset/win32/.vs/factory_reset/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..22b7db8ee59dc41292028ece4654b7faf30d1818 GIT binary patch literal 35328 zcmeHQTZ|i586KxCO>eZNp_J05PAH|N>%sT6lcue&Nt&eD)|;dyE}L0+!BP zU2o>Be$VmDne(6X-_Cz7zxUNwuKnxxp1JXFiY48xT%^4F-et-MO!r;LZ<61yQIw03 z=e>8|d+$Boz6gMH59j!Qp&j2lqIs#cDi1YUBcQ3!@ zx)SB?y+IV70>+ARLfH%K1>{o7;(%H@A72lNG?TmYY42~xa2w)lB#EDRt4awis3|%i z16pVRy;-i`tmXA~;9AT2*JIu1Q~zK6 zn!Ba{k5e#^r2d^x{ijZkQvWH#lDF*BpfqCrcdbVMWxFp&qiF}IgO?#M_5V}IOTA>- zwbXysZ%&s0_niRVqwQfk)-qj)`cIm2?BJFD9BED)Ecs7aplom);JD2(-faK*o&?%| z=B@UhG9$~F?Z3PyuN;eL^J)LdZ}NlopE5`}m;kV>+Pr#k^#S~V03Zkm0m6VuKm-s4 z>;UWp+y&tKcjI~w;9fus5C?GlNdi)UG+;Mi4`46gKEOV}e!v01{eXjjDZm4O2LTzt zG~f{6FyIJ4_Df!~xc3O)v!-Vn^0R;(AaA;lW}cUn1_e@z7qm-(20q0DN_ufkBj>|k z65nUgvow01fJanS>S$#mg$J$_2l7qodyOC9*_nfh#r^< z`qCpR<69p1Yj`q`d>8(f?X`=acqz+Fhf&`&uvg%N&Ej(roFw*Bz@0;GP}+|Evo7j~ zUHlKBEOm{k4F8Y)ZHTW!e_q-2KS@)&_%A})EI*Kv=yMKjAZ6+QoB44Fv>`2$pgg_d zUP%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ofg6Q4>C3%(eP*bM`g=M{LYBr z)kNa2Bis|3?w{1cvtExL2!=fP`H_ex8qOCyAzdp3qCs5`grln0>zxcl&RTuN8x$8N zSHCdbegS#L7xULZ8M8Tx<$p=)JW + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/factory_reset/win32/factory_reset/FactoryReset.cs b/c#/protocol2.0/factory_reset/win32/factory_reset/FactoryReset.cs new file mode 100644 index 00000000..86bd0978 --- /dev/null +++ b/c#/protocol2.0/factory_reset/win32/factory_reset/FactoryReset.cs @@ -0,0 +1,195 @@ +/* +* factory_reset.cs +* +* Created on: 2016. 5. 16. +* Author: Leon Ryu Woon Jung +*/ + +// +// ********* Factory Reset Example ********* +// +// +// Available Dynamixel model on this example : All models using Protocol 2.0 +// This example is designed for using a Dynamixel PRO 54-200, and an USB2DYNAMIXEL. +// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below variables yourself. +// Be sure that Dynamixel PRO properties are already set as %% ID : 1 / Baudnum : 3 (Baudrate : 1000000 [1M]) +// + +// Be aware that: +// This example resets all properties of Dynamixel to default values, such as %% ID : 1 / Baudnum : 1 (Baudrate : 57600) +// + +using System; +using System.Threading; +using dynamixel_sdk; + +namespace factory_reset +{ + class FactoryReset + { + // Control table address + public const int ADDR_PRO_BAUDRATE = 8; // Control table address is different in Dynamixel model + + // Protocol version + public const int PROTOCOL_VERSION = 2; // See which protocol version is used in the Dynamixel + + // Default setting + public const int DXL_ID = 1; // Dynamixel ID: 1 + public const int BAUDRATE = 1000000; + public const string DEVICENAME = "COM8"; // Check which port is being used on your controller + // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const int FACTORYRST_DEFAULTBAUDRATE = 57600; // Dynamixel baudrate set by factoryreset + public const int NEW_BAUDNUM = 3; // New baudnum to recover Dynamixel baudrate as it was + public const byte OPERATION_MODE = 0x01; // 0xFF : reset all values + // 0x01 : reset all values except ID + // 0x02 : reset all values except ID and baudrate + + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num = dynamixel.portHandler(DEVICENAME); + + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + int dxl_comm_result = COMM_TX_FAIL; // Communication result + + byte dxl_error = 0; // Dynamixel error + byte dxl_baudnum_read; // Read baudnum + + // Open port + if (dynamixel.openPort(port_num)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port baudrate + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + + // Read present baudrate of the controller + Console.WriteLine("Now the controller baudrate is : {0}", dynamixel.getBaudRate(port_num)); + + // Try factoryreset + Console.WriteLine("[ID:{0}] Try factoryreset : ", DXL_ID); + dynamixel.factoryReset(port_num, PROTOCOL_VERSION, DXL_ID, OPERATION_MODE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + Console.WriteLine("Aborted"); + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + return; + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Wait for reset + Console.WriteLine("Wait for reset..."); + Thread.Sleep(2000); + + Console.WriteLine("[ID:{0}] factoryReset Success!", DXL_ID); + + // Set controller baudrate to dxl default baudrate + if (dynamixel.setBaudRate(port_num, FACTORYRST_DEFAULTBAUDRATE)) + { + Console.WriteLine("Succeed to change the controller baudrate to : {0}", FACTORYRST_DEFAULTBAUDRATE); + } + else + { + Console.WriteLine("Failed to change the controller baudrate"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Read Dynamixel baudnum + dxl_baudnum_read = dynamixel.read1ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_BAUDRATE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("[ID:{0}] Dynamixel baudnum is now : {1}", DXL_ID, dxl_baudnum_read); + } + + // Write new baudnum + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_BAUDRATE, NEW_BAUDNUM); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("[ID:{0}] Set Dynamixel baudnum to : {1}", DXL_ID, NEW_BAUDNUM); + } + + // Set port baudrate to BAUDRATE + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeed to change the controller baudrate to : {0}", BAUDRATE); + } + else + { + Console.WriteLine("Failed to change the controller baudrate"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + Thread.Sleep(200); + + // Read Dynamixel baudnum + dxl_baudnum_read = dynamixel.read1ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_BAUDRATE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("[ID:{0}] Dynamixel Baudnum is now : {1}", DXL_ID, dxl_baudnum_read); + } + + // Close port + dynamixel.closePort(port_num); + + return; + } + } +} diff --git a/c#/protocol2.0/factory_reset/win32/factory_reset/Properties/AssemblyInfo.cs b/c#/protocol2.0/factory_reset/win32/factory_reset/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..b53b7246 --- /dev/null +++ b/c#/protocol2.0/factory_reset/win32/factory_reset/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("factory_reset")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("factory_reset")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("1ed1b9dd-d30b-4aa0-92a0-84b8109f3c9b")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol2.0/factory_reset/win32/factory_reset/dynamixel.cs b/c#/protocol2.0/factory_reset/win32/factory_reset/dynamixel.cs new file mode 100644 index 00000000..235af316 --- /dev/null +++ b/c#/protocol2.0/factory_reset/win32/factory_reset/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win32/output/dxl_x86_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol2.0/factory_reset/win32/factory_reset/factory_reset.csproj b/c#/protocol2.0/factory_reset/win32/factory_reset/factory_reset.csproj new file mode 100644 index 00000000..a1310476 --- /dev/null +++ b/c#/protocol2.0/factory_reset/win32/factory_reset/factory_reset.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {1ED1B9DD-D30B-4AA0-92A0-84B8109F3C9B} + Exe + Properties + factory_reset + factory_reset + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/factory_reset/win64/.vs/factory_reset/v14/.suo b/c#/protocol2.0/factory_reset/win64/.vs/factory_reset/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..1428ed463d479202f331cbf063577e55a0678682 GIT binary patch literal 35328 zcmeHQTZ|i586Kx;Nt%|nG=x&x)G48~WNqyAW$mO%>T7nJq*=O~q$sYov*X!~yIy-c z_9nX|K~NRZ2M`yDi-ZtGf)@mZsuHCYq8DDOzO+?^sE}F}9smgmgb=NS)P(Pw@v+CV z_ISqYO>>#EI-bipbN=&R&VT;%pUb}X>J9Jw_^F%!ELp-H=?dxWxsB3QruRP6y>z`K zZNf9(ojrH%9FusDTQ6Kh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$B>$K;$J|phh%klM2=5~ z0%{~03*gYxL?9V2&IDqrJQGPqRW%Y%21B9HNF;IEYA)U+`7pS8#`O9H+;gqI*?VhB z?(5duf8yl72ec1P+NYWA((KOPG1%45`scnF?R~T+6!7$~^-$ + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/factory_reset/win64/factory_reset/FactoryReset.cs b/c#/protocol2.0/factory_reset/win64/factory_reset/FactoryReset.cs new file mode 100644 index 00000000..86bd0978 --- /dev/null +++ b/c#/protocol2.0/factory_reset/win64/factory_reset/FactoryReset.cs @@ -0,0 +1,195 @@ +/* +* factory_reset.cs +* +* Created on: 2016. 5. 16. +* Author: Leon Ryu Woon Jung +*/ + +// +// ********* Factory Reset Example ********* +// +// +// Available Dynamixel model on this example : All models using Protocol 2.0 +// This example is designed for using a Dynamixel PRO 54-200, and an USB2DYNAMIXEL. +// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below variables yourself. +// Be sure that Dynamixel PRO properties are already set as %% ID : 1 / Baudnum : 3 (Baudrate : 1000000 [1M]) +// + +// Be aware that: +// This example resets all properties of Dynamixel to default values, such as %% ID : 1 / Baudnum : 1 (Baudrate : 57600) +// + +using System; +using System.Threading; +using dynamixel_sdk; + +namespace factory_reset +{ + class FactoryReset + { + // Control table address + public const int ADDR_PRO_BAUDRATE = 8; // Control table address is different in Dynamixel model + + // Protocol version + public const int PROTOCOL_VERSION = 2; // See which protocol version is used in the Dynamixel + + // Default setting + public const int DXL_ID = 1; // Dynamixel ID: 1 + public const int BAUDRATE = 1000000; + public const string DEVICENAME = "COM8"; // Check which port is being used on your controller + // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const int FACTORYRST_DEFAULTBAUDRATE = 57600; // Dynamixel baudrate set by factoryreset + public const int NEW_BAUDNUM = 3; // New baudnum to recover Dynamixel baudrate as it was + public const byte OPERATION_MODE = 0x01; // 0xFF : reset all values + // 0x01 : reset all values except ID + // 0x02 : reset all values except ID and baudrate + + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num = dynamixel.portHandler(DEVICENAME); + + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + int dxl_comm_result = COMM_TX_FAIL; // Communication result + + byte dxl_error = 0; // Dynamixel error + byte dxl_baudnum_read; // Read baudnum + + // Open port + if (dynamixel.openPort(port_num)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port baudrate + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + + // Read present baudrate of the controller + Console.WriteLine("Now the controller baudrate is : {0}", dynamixel.getBaudRate(port_num)); + + // Try factoryreset + Console.WriteLine("[ID:{0}] Try factoryreset : ", DXL_ID); + dynamixel.factoryReset(port_num, PROTOCOL_VERSION, DXL_ID, OPERATION_MODE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + Console.WriteLine("Aborted"); + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + return; + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Wait for reset + Console.WriteLine("Wait for reset..."); + Thread.Sleep(2000); + + Console.WriteLine("[ID:{0}] factoryReset Success!", DXL_ID); + + // Set controller baudrate to dxl default baudrate + if (dynamixel.setBaudRate(port_num, FACTORYRST_DEFAULTBAUDRATE)) + { + Console.WriteLine("Succeed to change the controller baudrate to : {0}", FACTORYRST_DEFAULTBAUDRATE); + } + else + { + Console.WriteLine("Failed to change the controller baudrate"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Read Dynamixel baudnum + dxl_baudnum_read = dynamixel.read1ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_BAUDRATE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("[ID:{0}] Dynamixel baudnum is now : {1}", DXL_ID, dxl_baudnum_read); + } + + // Write new baudnum + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_BAUDRATE, NEW_BAUDNUM); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("[ID:{0}] Set Dynamixel baudnum to : {1}", DXL_ID, NEW_BAUDNUM); + } + + // Set port baudrate to BAUDRATE + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeed to change the controller baudrate to : {0}", BAUDRATE); + } + else + { + Console.WriteLine("Failed to change the controller baudrate"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + Thread.Sleep(200); + + // Read Dynamixel baudnum + dxl_baudnum_read = dynamixel.read1ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_BAUDRATE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("[ID:{0}] Dynamixel Baudnum is now : {1}", DXL_ID, dxl_baudnum_read); + } + + // Close port + dynamixel.closePort(port_num); + + return; + } + } +} diff --git a/c#/protocol2.0/factory_reset/win64/factory_reset/Properties/AssemblyInfo.cs b/c#/protocol2.0/factory_reset/win64/factory_reset/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..b53b7246 --- /dev/null +++ b/c#/protocol2.0/factory_reset/win64/factory_reset/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("factory_reset")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("factory_reset")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("1ed1b9dd-d30b-4aa0-92a0-84b8109f3c9b")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol2.0/factory_reset/win64/factory_reset/dynamixel.cs b/c#/protocol2.0/factory_reset/win64/factory_reset/dynamixel.cs new file mode 100644 index 00000000..d940e04b --- /dev/null +++ b/c#/protocol2.0/factory_reset/win64/factory_reset/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win64/output/dxl_x64_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol2.0/factory_reset/win64/factory_reset/factory_reset.csproj b/c#/protocol2.0/factory_reset/win64/factory_reset/factory_reset.csproj new file mode 100644 index 00000000..094a322f --- /dev/null +++ b/c#/protocol2.0/factory_reset/win64/factory_reset/factory_reset.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {1ED1B9DD-D30B-4AA0-92A0-84B8109F3C9B} + Exe + Properties + factory_reset + factory_reset + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/indirect_address/win32/.vs/indirect_address/v14/.suo b/c#/protocol2.0/indirect_address/win32/.vs/indirect_address/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..cf37f21e62e0f5fb6725242bdf5f453d6265e55c GIT binary patch literal 36864 zcmeHQTZ|jmc^=AEEJtn}U!tatBh#{-+VPU*om|OMOb$tDZOK}jt4k|7>k&EJrIt%F zBv)G1QsT5RoB(l-HJG$z4Pw7@AC0207ShoK@@mSYv8Y=`L&!@$F-$hW>dNj`?TF_ZT?3i zzIy-e-#_^8Kl{0l>7M)(nRpf@Hna=c3`(ycmeW>8u z&vKhu4K-+KCZGUX7y#2sH|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B*w_sO!MGkL!PG&wL~PtM>0FJ$|#d{}*;m?8?2+8{8#5 zYKc~*805d@PW}$(a&`U#Tt>%|Kbv^|gV6uuoWH=;v0?t-8#(`BT>VR1CBu$~;G}=I zeD~)+>_a}p$*ugi>woUCv#NsF_~E+ye~(|~o-c;s&N&5V81#&320g!)XWTnPPw3G; zV<*0Q-WBQJ*Ay+|`F|^K{R_}PT(|N3zXzX95CnZZ|8K5ScD;B# z|8I`3d2)v5|IJ+vp8vP!|Er{@S)pNZnwt&)O{U1|I^{#{+|D--3K-errKN|Sf^L!cs`#y!T(hH(Rlu+ zp8x6kPPv}{soV1umYeX7F4b1bX4kEnr$Q8Gl|%I`PGmCG!4Sd4z7rvadC>l=@}Ldp zY+d^q3eNEIGYMYBiV2|70M^{aK`2U+=PR-at6kBb#*EPjx`x_D#X#5 zxnrj?j_vY~KRy_*`C7HUvRZ87tc&?YdDw+~<3rH9 zGgx_T$jHiEX=hBHIgo^!!z$WNl ayE@|Z=Q6<4znF%cz|(if_Tk%X{rms!3C;Qd literal 0 HcmV?d00001 diff --git a/c#/protocol2.0/indirect_address/win32/indirect_address.sln b/c#/protocol2.0/indirect_address/win32/indirect_address.sln new file mode 100644 index 00000000..b9a595aa --- /dev/null +++ b/c#/protocol2.0/indirect_address/win32/indirect_address.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 14 for Windows Desktop +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "indirect_address", "indirect_address\indirect_address.csproj", "{9FAC7287-571C-43FB-8DD6-259B8CB51BFC}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9FAC7287-571C-43FB-8DD6-259B8CB51BFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9FAC7287-571C-43FB-8DD6-259B8CB51BFC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9FAC7287-571C-43FB-8DD6-259B8CB51BFC}.Debug|x86.ActiveCfg = Debug|x86 + {9FAC7287-571C-43FB-8DD6-259B8CB51BFC}.Debug|x86.Build.0 = Debug|x86 + {9FAC7287-571C-43FB-8DD6-259B8CB51BFC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9FAC7287-571C-43FB-8DD6-259B8CB51BFC}.Release|Any CPU.Build.0 = Release|Any CPU + {9FAC7287-571C-43FB-8DD6-259B8CB51BFC}.Release|x86.ActiveCfg = Release|x86 + {9FAC7287-571C-43FB-8DD6-259B8CB51BFC}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/c#/protocol2.0/indirect_address/win32/indirect_address/App.config b/c#/protocol2.0/indirect_address/win32/indirect_address/App.config new file mode 100644 index 00000000..8e156463 --- /dev/null +++ b/c#/protocol2.0/indirect_address/win32/indirect_address/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/indirect_address/win32/indirect_address/IndirectAddress.cs b/c#/protocol2.0/indirect_address/win32/indirect_address/IndirectAddress.cs new file mode 100644 index 00000000..37a2c77b --- /dev/null +++ b/c#/protocol2.0/indirect_address/win32/indirect_address/IndirectAddress.cs @@ -0,0 +1,344 @@ +/* +* indirect_address.cs +* +* Created on: 2016. 5. 16. +* Author: Leon Ryu Woon Jung +*/ + +// +// ********* Indirect Address Example ********* +// +// +// Available Dynamixel model on this example : All models using Protocol 2.0 +// This example is designed for using a Dynamixel PRO 54-200, and an USB2DYNAMIXEL. +// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below variables yourself. +// Be sure that Dynamixel PRO properties are already set as %% ID : 1 / Baudnum : 3 (Baudrate : 1000000 [1M]) +// + +using System; +using dynamixel_sdk; + +namespace sync_write +{ + class SyncWrite + { + // Control table address // Control table address is different in Dynamixel model + public const int ADDR_PRO_INDIRECTADDRESS_FOR_WRITE = 49; // EEPROM region + public const int ADDR_PRO_INDIRECTADDRESS_FOR_READ = 59; // EEPROM region + public const int ADDR_PRO_TORQUE_ENABLE = 562; + public const int ADDR_PRO_LED_RED = 563; + public const int ADDR_PRO_GOAL_POSITION = 596; + public const int ADDR_PRO_MOVING = 610; + public const int ADDR_PRO_PRESENT_POSITION = 611; + public const int ADDR_PRO_INDIRECTDATA_FOR_WRITE = 634; + public const int ADDR_PRO_INDIRECTDATA_FOR_READ = 639; + + // Data Byte Length + public const int LEN_PRO_LED_RED = 1; + public const int LEN_PRO_GOAL_POSITION = 4; + public const int LEN_PRO_MOVING = 1; + public const int LEN_PRO_PRESENT_POSITION = 4; + public const int LEN_PRO_INDIRECTDATA_FOR_WRITE = 5; + public const int LEN_PRO_INDIRECTDATA_FOR_READ = 5; + + // Protocol version + public const int PROTOCOL_VERSION = 2; // See which protocol version is used in the Dynamixel + + // Default setting + public const int DXL_ID = 1; // Dynamixel ID: 1 + public const int BAUDRATE = 1000000; + public const string DEVICENAME = "COM8"; // Check which port is being used on your controller + // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const int TORQUE_ENABLE = 1; // Value for enabling the torque + public const int TORQUE_DISABLE = 0; // Value for disabling the torque + public const int DXL_MINIMUM_POSITION_VALUE = -150000; // Dynamixel will rotate between this value + public const int DXL_MAXIMUM_POSITION_VALUE = 150000; // and this value (note that the Dynamixel would not move when the position value is out of movable range. Check e-manual about the range of the Dynamixel you use.) + public const int DXL_MINIMUM_LED_VALUE = 0; // Dynamixel LED will light between this value + public const int DXL_MAXIMUM_LED_VALUE = 255; // and this value + public const int DXL_MOVING_STATUS_THRESHOLD = 20; // Dynamixel moving status threshold + + public const byte ESC_ASCII_VALUE = 0x1b; + + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num = dynamixel.portHandler(DEVICENAME); + + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + // Initialize Groupsyncwrite instance + int groupwrite_num = dynamixel.groupSyncWrite(port_num, PROTOCOL_VERSION, ADDR_PRO_INDIRECTDATA_FOR_WRITE, LEN_PRO_INDIRECTDATA_FOR_WRITE); + + // Initialize Groupsyncread Structs for Present Position + int groupread_num = dynamixel.groupSyncRead(port_num, PROTOCOL_VERSION, ADDR_PRO_INDIRECTDATA_FOR_READ, LEN_PRO_INDIRECTDATA_FOR_READ); + + int index = 0; + int dxl_comm_result = COMM_TX_FAIL; // Communication result + bool dxl_addparam_result = false; // AddParam result + bool dxl_getdata_result = false; // GetParam result + int[] dxl_goal_position = new int[2]{ DXL_MINIMUM_POSITION_VALUE, DXL_MAXIMUM_POSITION_VALUE }; // Goal position + + byte dxl_error = 0; // Dynamixel error + byte dxl_moving = 0; // Dynamixel moving status + byte[] dxl_led_value = new byte[2]{ 0x00, 0xFF }; // Dynamixel LED value + Int32 dxl_present_position = 0; // Present position + + // Open port + if (dynamixel.openPort(port_num)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port baudrate + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Disable Dynamixel Torque : + // Indirect address would not accessible when the torque is already enabled + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("Dynamixel has been successfully connected "); + } + + // INDIRECTDATA parameter storages replace LED, goal position, present position and moving status storages + dynamixel.write2ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_INDIRECTADDRESS_FOR_WRITE + 0, ADDR_PRO_GOAL_POSITION + 0); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + dynamixel.write2ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_INDIRECTADDRESS_FOR_WRITE + 2, ADDR_PRO_GOAL_POSITION + 1); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + dynamixel.write2ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_INDIRECTADDRESS_FOR_WRITE + 4, ADDR_PRO_GOAL_POSITION + 2); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + dynamixel.write2ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_INDIRECTADDRESS_FOR_WRITE + 6, ADDR_PRO_GOAL_POSITION + 3); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + dynamixel.write2ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_INDIRECTADDRESS_FOR_WRITE + 8, ADDR_PRO_LED_RED); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + dynamixel.write2ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_INDIRECTADDRESS_FOR_READ + 0, ADDR_PRO_PRESENT_POSITION + 0); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + dynamixel.write2ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_INDIRECTADDRESS_FOR_READ + 2, ADDR_PRO_PRESENT_POSITION + 1); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + dynamixel.write2ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_INDIRECTADDRESS_FOR_READ + 4, ADDR_PRO_PRESENT_POSITION + 2); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + dynamixel.write2ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_INDIRECTADDRESS_FOR_READ + 6, ADDR_PRO_PRESENT_POSITION + 3); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + dynamixel.write2ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_INDIRECTADDRESS_FOR_READ + 8, ADDR_PRO_MOVING); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Enable DXL Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Add parameter storage for Dynamixel present position value + dxl_addparam_result = dynamixel.groupSyncReadAddParam(groupread_num, DXL_ID); + if (dxl_addparam_result != true) + { + Console.WriteLine("[ID:{0}] groupSyncRead addparam failed", DXL_ID); + return; + } + + while (true) + { + Console.WriteLine("Press any key to continue! (or press ESC to quit!)"); + if (Console.ReadKey().KeyChar == ESC_ASCII_VALUE) + break; + + // Add values to the Syncwrite storage + dxl_addparam_result = dynamixel.groupSyncWriteAddParam(groupwrite_num, DXL_ID, (UInt32)dxl_goal_position[index], LEN_PRO_GOAL_POSITION); + if (dxl_addparam_result != true) + { + Console.WriteLine("[ID:{0}] groupSyncWrite addparam failed", DXL_ID); + return; + } + dxl_addparam_result = dynamixel.groupSyncWriteAddParam(groupwrite_num, DXL_ID, dxl_led_value[index], LEN_PRO_LED_RED); + if (dxl_addparam_result != true) + { + Console.WriteLine("[ID:{0}] groupSyncWrite addparam failed", DXL_ID); + return; + } + + // Syncwrite goal position + dynamixel.groupSyncWriteTxPacket(groupwrite_num); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + + // Clear syncwrite parameter storage + dynamixel.groupSyncWriteClearParam(groupwrite_num); + + do + { + // Syncread present position from indirectdata2 + dynamixel.groupSyncReadTxRxPacket(groupread_num); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + + // Check if groupsyncread data of Dyanamixel is available + dxl_getdata_result = dynamixel.groupSyncReadIsAvailable(groupread_num, DXL_ID, ADDR_PRO_INDIRECTDATA_FOR_READ, LEN_PRO_PRESENT_POSITION); + if (dxl_getdata_result != true) + { + Console.WriteLine("[ID:{0}] groupSyncRead getdata failed", DXL_ID); + return; + } + + // Check if groupsyncread data of Dyanamixel is available + dxl_getdata_result = dynamixel.groupSyncReadIsAvailable(groupread_num, DXL_ID, ADDR_PRO_INDIRECTDATA_FOR_READ + LEN_PRO_PRESENT_POSITION, LEN_PRO_MOVING); + if (dxl_getdata_result != true) + { + Console.WriteLine("[ID:{0}] groupSyncRead getdata failed", DXL_ID); + return; + } + + // Get Dynamixel present position value + dxl_present_position = (Int32)dynamixel.groupSyncReadGetData(groupread_num, DXL_ID, ADDR_PRO_INDIRECTDATA_FOR_READ, LEN_PRO_PRESENT_POSITION); + + // Get Dynamixel moving status value + dxl_moving = (byte)dynamixel.groupSyncReadGetData(groupread_num, DXL_ID, ADDR_PRO_INDIRECTDATA_FOR_READ + LEN_PRO_PRESENT_POSITION, LEN_PRO_MOVING); + + Console.WriteLine("[ID:{0}] GoalPos:{1} PresPos:{2} IsMoving:{3}", DXL_ID, dxl_goal_position[index], dxl_present_position, dxl_moving); + + } while (Math.Abs(dxl_goal_position[index] - dxl_present_position) > DXL_MOVING_STATUS_THRESHOLD); + + // Change goal position + if (index == 0) + { + index = 1; + } + else + { + index = 0; + } + } + + // Disable Dynamixel Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Close port + dynamixel.closePort(port_num); + + return; + } + } +} diff --git a/c#/protocol2.0/indirect_address/win32/indirect_address/Properties/AssemblyInfo.cs b/c#/protocol2.0/indirect_address/win32/indirect_address/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..aed7cd15 --- /dev/null +++ b/c#/protocol2.0/indirect_address/win32/indirect_address/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("indirect_address")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("indirect_address")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("9fac7287-571c-43fb-8dd6-259b8cb51bfc")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol2.0/indirect_address/win32/indirect_address/dynamixel.cs b/c#/protocol2.0/indirect_address/win32/indirect_address/dynamixel.cs new file mode 100644 index 00000000..235af316 --- /dev/null +++ b/c#/protocol2.0/indirect_address/win32/indirect_address/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win32/output/dxl_x86_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol2.0/indirect_address/win32/indirect_address/indirect_address.csproj b/c#/protocol2.0/indirect_address/win32/indirect_address/indirect_address.csproj new file mode 100644 index 00000000..3df91b3e --- /dev/null +++ b/c#/protocol2.0/indirect_address/win32/indirect_address/indirect_address.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {9FAC7287-571C-43FB-8DD6-259B8CB51BFC} + Exe + Properties + indirect_address + indirect_address + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/indirect_address/win64/.vs/indirect_address/v14/.suo b/c#/protocol2.0/indirect_address/win64/.vs/indirect_address/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..be9ff99f83d1e89584992414007d5f3039e95184 GIT binary patch literal 36864 zcmeHQYiu0V6`lLhu7<>5sMup{i>8r-DkTpbAvA6!k|HRf4LemHMYts#J+TRi#R(<&l2h%wF&8 zb7t&~6DM<5cOLiNx#ym9&pr3tb07QeJJ-Jd!&h(kyVT_NOIJvrp4%i{X$tq4o~6%8 z(p7k8*r(^tonsWA@#wlWM1cpT5`I<5D-B9T+%;)|RcYI8mo_Zb`6i36-aqrLH~x9{ z51wm~?!Ft0#G`;%l1@m&fIfw%L22G1m&WMr(z+%1Bzt3Q`?o^~2K(wxz$e_YR6q$d zNrfK+Eo6ALmafxn*D~PmL}stl8q;BE4p0hG9{AHwn;@qVqICjX3kQ79dOY6-Zx{aq zNV}y5pVjb52YzL{HoKdVR)p=qGii7&{B`hK;kUtm9)3Ig7vOJ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irect_address.sln new file mode 100644 index 00000000..70935824 --- /dev/null +++ b/c#/protocol2.0/indirect_address/win64/indirect_address.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 14 for Windows Desktop +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "indirect_address", "indirect_address\indirect_address.csproj", "{9FAC7287-571C-43FB-8DD6-259B8CB51BFC}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9FAC7287-571C-43FB-8DD6-259B8CB51BFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9FAC7287-571C-43FB-8DD6-259B8CB51BFC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9FAC7287-571C-43FB-8DD6-259B8CB51BFC}.Debug|x64.ActiveCfg = Debug|x64 + {9FAC7287-571C-43FB-8DD6-259B8CB51BFC}.Debug|x64.Build.0 = Debug|x64 + {9FAC7287-571C-43FB-8DD6-259B8CB51BFC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9FAC7287-571C-43FB-8DD6-259B8CB51BFC}.Release|Any CPU.Build.0 = Release|Any CPU + {9FAC7287-571C-43FB-8DD6-259B8CB51BFC}.Release|x64.ActiveCfg = Release|x64 + {9FAC7287-571C-43FB-8DD6-259B8CB51BFC}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/c#/protocol2.0/indirect_address/win64/indirect_address/App.config b/c#/protocol2.0/indirect_address/win64/indirect_address/App.config new file mode 100644 index 00000000..8e156463 --- /dev/null +++ b/c#/protocol2.0/indirect_address/win64/indirect_address/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/indirect_address/win64/indirect_address/IndirectAddress.cs b/c#/protocol2.0/indirect_address/win64/indirect_address/IndirectAddress.cs new file mode 100644 index 00000000..37a2c77b --- /dev/null +++ b/c#/protocol2.0/indirect_address/win64/indirect_address/IndirectAddress.cs @@ -0,0 +1,344 @@ +/* +* indirect_address.cs +* +* Created on: 2016. 5. 16. +* Author: Leon Ryu Woon Jung +*/ + +// +// ********* Indirect Address Example ********* +// +// +// Available Dynamixel model on this example : All models using Protocol 2.0 +// This example is designed for using a Dynamixel PRO 54-200, and an USB2DYNAMIXEL. +// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below variables yourself. +// Be sure that Dynamixel PRO properties are already set as %% ID : 1 / Baudnum : 3 (Baudrate : 1000000 [1M]) +// + +using System; +using dynamixel_sdk; + +namespace sync_write +{ + class SyncWrite + { + // Control table address // Control table address is different in Dynamixel model + public const int ADDR_PRO_INDIRECTADDRESS_FOR_WRITE = 49; // EEPROM region + public const int ADDR_PRO_INDIRECTADDRESS_FOR_READ = 59; // EEPROM region + public const int ADDR_PRO_TORQUE_ENABLE = 562; + public const int ADDR_PRO_LED_RED = 563; + public const int ADDR_PRO_GOAL_POSITION = 596; + public const int ADDR_PRO_MOVING = 610; + public const int ADDR_PRO_PRESENT_POSITION = 611; + public const int ADDR_PRO_INDIRECTDATA_FOR_WRITE = 634; + public const int ADDR_PRO_INDIRECTDATA_FOR_READ = 639; + + // Data Byte Length + public const int LEN_PRO_LED_RED = 1; + public const int LEN_PRO_GOAL_POSITION = 4; + public const int LEN_PRO_MOVING = 1; + public const int LEN_PRO_PRESENT_POSITION = 4; + public const int LEN_PRO_INDIRECTDATA_FOR_WRITE = 5; + public const int LEN_PRO_INDIRECTDATA_FOR_READ = 5; + + // Protocol version + public const int PROTOCOL_VERSION = 2; // See which protocol version is used in the Dynamixel + + // Default setting + public const int DXL_ID = 1; // Dynamixel ID: 1 + public const int BAUDRATE = 1000000; + public const string DEVICENAME = "COM8"; // Check which port is being used on your controller + // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const int TORQUE_ENABLE = 1; // Value for enabling the torque + public const int TORQUE_DISABLE = 0; // Value for disabling the torque + public const int DXL_MINIMUM_POSITION_VALUE = -150000; // Dynamixel will rotate between this value + public const int DXL_MAXIMUM_POSITION_VALUE = 150000; // and this value (note that the Dynamixel would not move when the position value is out of movable range. Check e-manual about the range of the Dynamixel you use.) + public const int DXL_MINIMUM_LED_VALUE = 0; // Dynamixel LED will light between this value + public const int DXL_MAXIMUM_LED_VALUE = 255; // and this value + public const int DXL_MOVING_STATUS_THRESHOLD = 20; // Dynamixel moving status threshold + + public const byte ESC_ASCII_VALUE = 0x1b; + + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num = dynamixel.portHandler(DEVICENAME); + + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + // Initialize Groupsyncwrite instance + int groupwrite_num = dynamixel.groupSyncWrite(port_num, PROTOCOL_VERSION, ADDR_PRO_INDIRECTDATA_FOR_WRITE, LEN_PRO_INDIRECTDATA_FOR_WRITE); + + // Initialize Groupsyncread Structs for Present Position + int groupread_num = dynamixel.groupSyncRead(port_num, PROTOCOL_VERSION, ADDR_PRO_INDIRECTDATA_FOR_READ, LEN_PRO_INDIRECTDATA_FOR_READ); + + int index = 0; + int dxl_comm_result = COMM_TX_FAIL; // Communication result + bool dxl_addparam_result = false; // AddParam result + bool dxl_getdata_result = false; // GetParam result + int[] dxl_goal_position = new int[2]{ DXL_MINIMUM_POSITION_VALUE, DXL_MAXIMUM_POSITION_VALUE }; // Goal position + + byte dxl_error = 0; // Dynamixel error + byte dxl_moving = 0; // Dynamixel moving status + byte[] dxl_led_value = new byte[2]{ 0x00, 0xFF }; // Dynamixel LED value + Int32 dxl_present_position = 0; // Present position + + // Open port + if (dynamixel.openPort(port_num)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port baudrate + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Disable Dynamixel Torque : + // Indirect address would not accessible when the torque is already enabled + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("Dynamixel has been successfully connected "); + } + + // INDIRECTDATA parameter storages replace LED, goal position, present position and moving status storages + dynamixel.write2ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_INDIRECTADDRESS_FOR_WRITE + 0, ADDR_PRO_GOAL_POSITION + 0); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + dynamixel.write2ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_INDIRECTADDRESS_FOR_WRITE + 2, ADDR_PRO_GOAL_POSITION + 1); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + dynamixel.write2ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_INDIRECTADDRESS_FOR_WRITE + 4, ADDR_PRO_GOAL_POSITION + 2); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + dynamixel.write2ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_INDIRECTADDRESS_FOR_WRITE + 6, ADDR_PRO_GOAL_POSITION + 3); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + dynamixel.write2ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_INDIRECTADDRESS_FOR_WRITE + 8, ADDR_PRO_LED_RED); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + dynamixel.write2ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_INDIRECTADDRESS_FOR_READ + 0, ADDR_PRO_PRESENT_POSITION + 0); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + dynamixel.write2ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_INDIRECTADDRESS_FOR_READ + 2, ADDR_PRO_PRESENT_POSITION + 1); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + dynamixel.write2ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_INDIRECTADDRESS_FOR_READ + 4, ADDR_PRO_PRESENT_POSITION + 2); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + dynamixel.write2ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_INDIRECTADDRESS_FOR_READ + 6, ADDR_PRO_PRESENT_POSITION + 3); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + dynamixel.write2ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_INDIRECTADDRESS_FOR_READ + 8, ADDR_PRO_MOVING); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Enable DXL Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Add parameter storage for Dynamixel present position value + dxl_addparam_result = dynamixel.groupSyncReadAddParam(groupread_num, DXL_ID); + if (dxl_addparam_result != true) + { + Console.WriteLine("[ID:{0}] groupSyncRead addparam failed", DXL_ID); + return; + } + + while (true) + { + Console.WriteLine("Press any key to continue! (or press ESC to quit!)"); + if (Console.ReadKey().KeyChar == ESC_ASCII_VALUE) + break; + + // Add values to the Syncwrite storage + dxl_addparam_result = dynamixel.groupSyncWriteAddParam(groupwrite_num, DXL_ID, (UInt32)dxl_goal_position[index], LEN_PRO_GOAL_POSITION); + if (dxl_addparam_result != true) + { + Console.WriteLine("[ID:{0}] groupSyncWrite addparam failed", DXL_ID); + return; + } + dxl_addparam_result = dynamixel.groupSyncWriteAddParam(groupwrite_num, DXL_ID, dxl_led_value[index], LEN_PRO_LED_RED); + if (dxl_addparam_result != true) + { + Console.WriteLine("[ID:{0}] groupSyncWrite addparam failed", DXL_ID); + return; + } + + // Syncwrite goal position + dynamixel.groupSyncWriteTxPacket(groupwrite_num); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + + // Clear syncwrite parameter storage + dynamixel.groupSyncWriteClearParam(groupwrite_num); + + do + { + // Syncread present position from indirectdata2 + dynamixel.groupSyncReadTxRxPacket(groupread_num); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + + // Check if groupsyncread data of Dyanamixel is available + dxl_getdata_result = dynamixel.groupSyncReadIsAvailable(groupread_num, DXL_ID, ADDR_PRO_INDIRECTDATA_FOR_READ, LEN_PRO_PRESENT_POSITION); + if (dxl_getdata_result != true) + { + Console.WriteLine("[ID:{0}] groupSyncRead getdata failed", DXL_ID); + return; + } + + // Check if groupsyncread data of Dyanamixel is available + dxl_getdata_result = dynamixel.groupSyncReadIsAvailable(groupread_num, DXL_ID, ADDR_PRO_INDIRECTDATA_FOR_READ + LEN_PRO_PRESENT_POSITION, LEN_PRO_MOVING); + if (dxl_getdata_result != true) + { + Console.WriteLine("[ID:{0}] groupSyncRead getdata failed", DXL_ID); + return; + } + + // Get Dynamixel present position value + dxl_present_position = (Int32)dynamixel.groupSyncReadGetData(groupread_num, DXL_ID, ADDR_PRO_INDIRECTDATA_FOR_READ, LEN_PRO_PRESENT_POSITION); + + // Get Dynamixel moving status value + dxl_moving = (byte)dynamixel.groupSyncReadGetData(groupread_num, DXL_ID, ADDR_PRO_INDIRECTDATA_FOR_READ + LEN_PRO_PRESENT_POSITION, LEN_PRO_MOVING); + + Console.WriteLine("[ID:{0}] GoalPos:{1} PresPos:{2} IsMoving:{3}", DXL_ID, dxl_goal_position[index], dxl_present_position, dxl_moving); + + } while (Math.Abs(dxl_goal_position[index] - dxl_present_position) > DXL_MOVING_STATUS_THRESHOLD); + + // Change goal position + if (index == 0) + { + index = 1; + } + else + { + index = 0; + } + } + + // Disable Dynamixel Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Close port + dynamixel.closePort(port_num); + + return; + } + } +} diff --git a/c#/protocol2.0/indirect_address/win64/indirect_address/Properties/AssemblyInfo.cs b/c#/protocol2.0/indirect_address/win64/indirect_address/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..aed7cd15 --- /dev/null +++ b/c#/protocol2.0/indirect_address/win64/indirect_address/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("indirect_address")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("indirect_address")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("9fac7287-571c-43fb-8dd6-259b8cb51bfc")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol2.0/indirect_address/win64/indirect_address/dynamixel.cs b/c#/protocol2.0/indirect_address/win64/indirect_address/dynamixel.cs new file mode 100644 index 00000000..d940e04b --- /dev/null +++ b/c#/protocol2.0/indirect_address/win64/indirect_address/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win64/output/dxl_x64_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol2.0/indirect_address/win64/indirect_address/indirect_address.csproj b/c#/protocol2.0/indirect_address/win64/indirect_address/indirect_address.csproj new file mode 100644 index 00000000..016cf97e --- /dev/null +++ b/c#/protocol2.0/indirect_address/win64/indirect_address/indirect_address.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {9FAC7287-571C-43FB-8DD6-259B8CB51BFC} + Exe + Properties + indirect_address + indirect_address + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/multi_port/win32/.vs/multi_port/v14/.suo b/c#/protocol2.0/multi_port/win32/.vs/multi_port/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..074cccb68c3da324fb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WlZRezHo&8_${+I3FJ6r<(-=i6Sz z90N`Kzv*8y5BqK6|2+#cVY_z^O#Htm{@?vP+{fRiq+iV*g(Qu()^xG z1)UaCC*4&GNjwYxZz&y<`|Gs@R8CQ!M`@3(`1j^PNQLUZvRRpt^0ig}---X1btKPL4uK>IC;nfSms6)tnDqOScXI8-|Laon z|Dyk1Ki{TV8jX*RXS@3y`U?}Xt;pZ_=JW^crgpK@SFdj0DU?k2h zv(aFz&z4!9HY~$4c(@;+Zkdfm<_mQklD<}+UlY&XGlezD8tRei%*AGn!_#v|P9!@{ zRKNG$T&Y?puNIA5i)H4)GxOzAb#*OQm-}zahAE=Fr@;~_U)rAlpL&vH+)z5?_r#MC zpC=fMgyVsL9!LZN=TmCi(PhQTzf<5w7>lsXTtGR9DQgasQWyjh^~8L{#48p45a*tm@gC2{YixY&ZI{9M+BRa u8qj9`v>?vNQgi9_o!cQh&>Ny<$cxFa{2$qQeRF0 literal 0 HcmV?d00001 diff --git a/c#/protocol2.0/multi_port/win32/multi_port.sln b/c#/protocol2.0/multi_port/win32/multi_port.sln new file mode 100644 index 00000000..f74039b1 --- /dev/null +++ b/c#/protocol2.0/multi_port/win32/multi_port.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 14 for Windows Desktop +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "multi_port", "multi_port\multi_port.csproj", "{E974210C-6AEC-47D6-8359-0601C9725C6F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E974210C-6AEC-47D6-8359-0601C9725C6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E974210C-6AEC-47D6-8359-0601C9725C6F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E974210C-6AEC-47D6-8359-0601C9725C6F}.Debug|x86.ActiveCfg = Debug|x86 + {E974210C-6AEC-47D6-8359-0601C9725C6F}.Debug|x86.Build.0 = Debug|x86 + {E974210C-6AEC-47D6-8359-0601C9725C6F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E974210C-6AEC-47D6-8359-0601C9725C6F}.Release|Any CPU.Build.0 = Release|Any CPU + {E974210C-6AEC-47D6-8359-0601C9725C6F}.Release|x86.ActiveCfg = Release|x86 + {E974210C-6AEC-47D6-8359-0601C9725C6F}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/c#/protocol2.0/multi_port/win32/multi_port/App.config b/c#/protocol2.0/multi_port/win32/multi_port/App.config new file mode 100644 index 00000000..8e156463 --- /dev/null +++ b/c#/protocol2.0/multi_port/win32/multi_port/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/multi_port/win32/multi_port/MultiPort.cs b/c#/protocol2.0/multi_port/win32/multi_port/MultiPort.cs new file mode 100644 index 00000000..5523577d --- /dev/null +++ b/c#/protocol2.0/multi_port/win32/multi_port/MultiPort.cs @@ -0,0 +1,249 @@ +/* +* multi_port.cs +* +* Created on: 2016. 5. 16. +* Author: Leon Ryu Woon Jung +*/ + +// +// ********* MultiPort Example ********* +// +// +// Available Dynamixel model on this example : All models using Protocol 2.0 +// This example is designed for using two Dynamixel PRO 54-200, and two USB2DYNAMIXELs. +// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below variables yourself. +// Be sure that Dynamixel PRO properties are already set as %% ID : 1 / Baudnum : 3 (Baudrate : 1000000) +// + +using System; +using dynamixel_sdk; + +namespace read_write +{ + class ReadWrite + { + // Control table address + public const int ADDR_PRO_TORQUE_ENABLE = 562; // Control table address is different in Dynamixel model + public const int ADDR_PRO_GOAL_POSITION = 596; + public const int ADDR_PRO_PRESENT_POSITION = 611; + + // Protocol version + public const int PROTOCOL_VERSION = 2; // See which protocol version is used in the Dynamixel + + // Default setting + public const int DXL1_ID = 1; // Dynamixel ID: 1 + public const int DXL2_ID = 2; // Dynamixel ID: 2 + public const int BAUDRATE = 1000000; + public const string DEVICENAME1 = "COM8"; // Check which port is being used on your controller + public const string DEVICENAME2 = "COM4"; // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const int TORQUE_ENABLE = 1; // Value for enabling the torque + public const int TORQUE_DISABLE = 0; // Value for disabling the torque + public const int DXL_MINIMUM_POSITION_VALUE = -150000; // Dynamixel will rotate between this value + public const int DXL_MAXIMUM_POSITION_VALUE = 150000; // and this value (note that the Dynamixel would not move when the position value is out of movable range. Check e-manual about the range of the Dynamixel you use.) + public const int DXL_MOVING_STATUS_THRESHOLD = 20; // Dynamixel moving status threshold + + public const byte ESC_ASCII_VALUE = 0x1b; + + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num1 = dynamixel.portHandler(DEVICENAME1); + int port_num2 = dynamixel.portHandler(DEVICENAME2); + + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + int index = 0; + int dxl_comm_result = COMM_TX_FAIL; // Communication result + int[] dxl_goal_position = new int[2]{ DXL_MINIMUM_POSITION_VALUE, DXL_MAXIMUM_POSITION_VALUE }; // Goal position + + byte dxl_error = 0; // Dynamixel error + Int32 dxl1_present_position = 0, dxl2_present_position = 0; // Present position + + // Open port1 + if (dynamixel.openPort(port_num1)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Open port2 + if (dynamixel.openPort(port_num2)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port1 baudrate + if (dynamixel.setBaudRate(port_num1, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port2 baudrate + if (dynamixel.setBaudRate(port_num2, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Enable Dynamixel#1 Torque + dynamixel.write1ByteTxRx(port_num1, PROTOCOL_VERSION, DXL1_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num1, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num1, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("Dynamixel#{0} has been successfully connected ", DXL1_ID); + } + + // Enable Dynamixel#2 Torque + dynamixel.write1ByteTxRx(port_num2, PROTOCOL_VERSION, DXL2_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num2, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num2, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("Dynamixel#{0} has been successfully connected ", DXL2_ID); + } + + while (true) + { + Console.WriteLine("Press any key to continue! (or press ESC to quit!)"); + if (Console.ReadKey().KeyChar == ESC_ASCII_VALUE) + break; + + // Write Dynamixel#1 goal position + dynamixel.write4ByteTxRx(port_num1, PROTOCOL_VERSION, DXL1_ID, ADDR_PRO_GOAL_POSITION, (UInt32)dxl_goal_position[index]); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num1, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num1, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Write Dynamixel#2 goal position + dynamixel.write4ByteTxRx(port_num2, PROTOCOL_VERSION, DXL2_ID, ADDR_PRO_GOAL_POSITION, (UInt32)dxl_goal_position[index]); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num2, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num2, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + do + { + // Read Dynamixel#1 present position + dxl1_present_position = (Int32)dynamixel.read4ByteTxRx(port_num1, PROTOCOL_VERSION, DXL1_ID, ADDR_PRO_PRESENT_POSITION); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num1, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num1, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Read Dynamixel#2 present position + dxl2_present_position = (Int32)dynamixel.read4ByteTxRx(port_num2, PROTOCOL_VERSION, DXL2_ID, ADDR_PRO_PRESENT_POSITION); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num2, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num2, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + Console.WriteLine("[ID:{0}] GoalPos:{1} PresPos:{2} [ID:{3}] GoalPos:{4} PresPos:{5}", DXL1_ID, dxl_goal_position[index], dxl1_present_position, DXL2_ID, dxl_goal_position[index], dxl2_present_position); + + } while ((Math.Abs(dxl_goal_position[index] - dxl1_present_position) > DXL_MOVING_STATUS_THRESHOLD) || (Math.Abs(dxl_goal_position[index] - dxl2_present_position) > DXL_MOVING_STATUS_THRESHOLD)); + + // Change goal position + if (index == 0) + { + index = 1; + } + else + { + index = 0; + } + } + + // Disable Dynamixel#1 Torque + dynamixel.write1ByteTxRx(port_num1, PROTOCOL_VERSION, DXL1_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num1, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num1, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Disable Dynamixel#2 Torque + dynamixel.write1ByteTxRx(port_num2, PROTOCOL_VERSION, DXL2_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num2, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num2, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Close port1 + dynamixel.closePort(port_num1); + + // Close port2 + dynamixel.closePort(port_num2); + + return; + } + } +} diff --git a/c#/protocol2.0/multi_port/win32/multi_port/Properties/AssemblyInfo.cs b/c#/protocol2.0/multi_port/win32/multi_port/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..47770db0 --- /dev/null +++ b/c#/protocol2.0/multi_port/win32/multi_port/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("multi_port")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("multi_port")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("e974210c-6aec-47d6-8359-0601c9725c6f")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol2.0/multi_port/win32/multi_port/dynamixel.cs b/c#/protocol2.0/multi_port/win32/multi_port/dynamixel.cs new file mode 100644 index 00000000..235af316 --- /dev/null +++ b/c#/protocol2.0/multi_port/win32/multi_port/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win32/output/dxl_x86_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol2.0/multi_port/win32/multi_port/multi_port.csproj b/c#/protocol2.0/multi_port/win32/multi_port/multi_port.csproj new file mode 100644 index 00000000..132f67ce --- /dev/null +++ b/c#/protocol2.0/multi_port/win32/multi_port/multi_port.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {E974210C-6AEC-47D6-8359-0601C9725C6F} + Exe + Properties + multi_port + multi_port + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/multi_port/win64/.vs/multi_port/v14/.suo b/c#/protocol2.0/multi_port/win64/.vs/multi_port/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..f0f9590ab7e95a6dd468beee547be851741ee767 GIT binary patch literal 33280 zcmeHQYm8e*6~0c>HfaN;Z3xho#0{aZtc~C6O`5cRZL-a7vaL5sp)OmmeRtPcziNAv zU7Db(2o)jms4BG;0we^8hft*=egLXODf|Hbq)46b@=vX%{YT)vht5+i<-}-M>%M zHshLU7cO4B$mFXKaXAbFgn@^&0)7?EuEn%G&LwS?U1>S&(5|laIY^>oc=Jntdj9Xf z`K|5!$n_)-2-B#spq&g2?jj#F=$6+=c6q;a;Zp{}@Ic5yU7WadQJ=|7*E2OYA5A zlQueqSDyBLll*@-GWC)FZKNU9XPxR-&-%>&4YZ=_=yWE3^pXF2uHVT2iYhtIQx1>^ zDI4F5$Y+YjdA+5Y#%szuKD)z^#`J!K>rv)M4dssFdN1M#q65*1_%TEmq8rhJ=tcA) z`Vj+&Y+DfLF~og{`w{O&Jb-u*@jgUFGyQ1upq4>AF;aKq7|MPnEnJJp{-)fgT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9+dk_}@9BZ~UdUZNK=p!G4zL6kqc; z@73glpE!5&7C3h{ zy^@_>2?l0UiQ1L(bZP~=NuN5~ek1B+GEpw!6}1obY&pF&i>;=yhaR@A#=g^sllgR3 zFUf87%Ffi;vrj}_F?Yxx2{^)D|CqxU^SK>k;egBG^#=T79#6y*@_5dLfA&r^KZULQ ziiu16J$#Ev z9B=qBn_HCMj&q2GKZ9S_Zx8#PKe@wtODoSv?z?Za=SUSmdI!I;t`J_XUHav}rt=%< zL{aUppEm8UUz2MPYpwRz|I4c{e*V7aK7Ia$@4bBN+0hGMH14l2_TDF(VJm;gj8Gsl z>hpzy4p+< + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/multi_port/win64/multi_port/MultiPort.cs b/c#/protocol2.0/multi_port/win64/multi_port/MultiPort.cs new file mode 100644 index 00000000..5523577d --- /dev/null +++ b/c#/protocol2.0/multi_port/win64/multi_port/MultiPort.cs @@ -0,0 +1,249 @@ +/* +* multi_port.cs +* +* Created on: 2016. 5. 16. +* Author: Leon Ryu Woon Jung +*/ + +// +// ********* MultiPort Example ********* +// +// +// Available Dynamixel model on this example : All models using Protocol 2.0 +// This example is designed for using two Dynamixel PRO 54-200, and two USB2DYNAMIXELs. +// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below variables yourself. +// Be sure that Dynamixel PRO properties are already set as %% ID : 1 / Baudnum : 3 (Baudrate : 1000000) +// + +using System; +using dynamixel_sdk; + +namespace read_write +{ + class ReadWrite + { + // Control table address + public const int ADDR_PRO_TORQUE_ENABLE = 562; // Control table address is different in Dynamixel model + public const int ADDR_PRO_GOAL_POSITION = 596; + public const int ADDR_PRO_PRESENT_POSITION = 611; + + // Protocol version + public const int PROTOCOL_VERSION = 2; // See which protocol version is used in the Dynamixel + + // Default setting + public const int DXL1_ID = 1; // Dynamixel ID: 1 + public const int DXL2_ID = 2; // Dynamixel ID: 2 + public const int BAUDRATE = 1000000; + public const string DEVICENAME1 = "COM8"; // Check which port is being used on your controller + public const string DEVICENAME2 = "COM4"; // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const int TORQUE_ENABLE = 1; // Value for enabling the torque + public const int TORQUE_DISABLE = 0; // Value for disabling the torque + public const int DXL_MINIMUM_POSITION_VALUE = -150000; // Dynamixel will rotate between this value + public const int DXL_MAXIMUM_POSITION_VALUE = 150000; // and this value (note that the Dynamixel would not move when the position value is out of movable range. Check e-manual about the range of the Dynamixel you use.) + public const int DXL_MOVING_STATUS_THRESHOLD = 20; // Dynamixel moving status threshold + + public const byte ESC_ASCII_VALUE = 0x1b; + + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num1 = dynamixel.portHandler(DEVICENAME1); + int port_num2 = dynamixel.portHandler(DEVICENAME2); + + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + int index = 0; + int dxl_comm_result = COMM_TX_FAIL; // Communication result + int[] dxl_goal_position = new int[2]{ DXL_MINIMUM_POSITION_VALUE, DXL_MAXIMUM_POSITION_VALUE }; // Goal position + + byte dxl_error = 0; // Dynamixel error + Int32 dxl1_present_position = 0, dxl2_present_position = 0; // Present position + + // Open port1 + if (dynamixel.openPort(port_num1)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Open port2 + if (dynamixel.openPort(port_num2)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port1 baudrate + if (dynamixel.setBaudRate(port_num1, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port2 baudrate + if (dynamixel.setBaudRate(port_num2, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Enable Dynamixel#1 Torque + dynamixel.write1ByteTxRx(port_num1, PROTOCOL_VERSION, DXL1_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num1, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num1, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("Dynamixel#{0} has been successfully connected ", DXL1_ID); + } + + // Enable Dynamixel#2 Torque + dynamixel.write1ByteTxRx(port_num2, PROTOCOL_VERSION, DXL2_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num2, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num2, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("Dynamixel#{0} has been successfully connected ", DXL2_ID); + } + + while (true) + { + Console.WriteLine("Press any key to continue! (or press ESC to quit!)"); + if (Console.ReadKey().KeyChar == ESC_ASCII_VALUE) + break; + + // Write Dynamixel#1 goal position + dynamixel.write4ByteTxRx(port_num1, PROTOCOL_VERSION, DXL1_ID, ADDR_PRO_GOAL_POSITION, (UInt32)dxl_goal_position[index]); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num1, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num1, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Write Dynamixel#2 goal position + dynamixel.write4ByteTxRx(port_num2, PROTOCOL_VERSION, DXL2_ID, ADDR_PRO_GOAL_POSITION, (UInt32)dxl_goal_position[index]); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num2, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num2, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + do + { + // Read Dynamixel#1 present position + dxl1_present_position = (Int32)dynamixel.read4ByteTxRx(port_num1, PROTOCOL_VERSION, DXL1_ID, ADDR_PRO_PRESENT_POSITION); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num1, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num1, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Read Dynamixel#2 present position + dxl2_present_position = (Int32)dynamixel.read4ByteTxRx(port_num2, PROTOCOL_VERSION, DXL2_ID, ADDR_PRO_PRESENT_POSITION); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num2, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num2, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + Console.WriteLine("[ID:{0}] GoalPos:{1} PresPos:{2} [ID:{3}] GoalPos:{4} PresPos:{5}", DXL1_ID, dxl_goal_position[index], dxl1_present_position, DXL2_ID, dxl_goal_position[index], dxl2_present_position); + + } while ((Math.Abs(dxl_goal_position[index] - dxl1_present_position) > DXL_MOVING_STATUS_THRESHOLD) || (Math.Abs(dxl_goal_position[index] - dxl2_present_position) > DXL_MOVING_STATUS_THRESHOLD)); + + // Change goal position + if (index == 0) + { + index = 1; + } + else + { + index = 0; + } + } + + // Disable Dynamixel#1 Torque + dynamixel.write1ByteTxRx(port_num1, PROTOCOL_VERSION, DXL1_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num1, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num1, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Disable Dynamixel#2 Torque + dynamixel.write1ByteTxRx(port_num2, PROTOCOL_VERSION, DXL2_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num2, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num2, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Close port1 + dynamixel.closePort(port_num1); + + // Close port2 + dynamixel.closePort(port_num2); + + return; + } + } +} diff --git a/c#/protocol2.0/multi_port/win64/multi_port/Properties/AssemblyInfo.cs b/c#/protocol2.0/multi_port/win64/multi_port/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..47770db0 --- /dev/null +++ b/c#/protocol2.0/multi_port/win64/multi_port/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("multi_port")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("multi_port")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("e974210c-6aec-47d6-8359-0601c9725c6f")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol2.0/multi_port/win64/multi_port/dynamixel.cs b/c#/protocol2.0/multi_port/win64/multi_port/dynamixel.cs new file mode 100644 index 00000000..d940e04b --- /dev/null +++ b/c#/protocol2.0/multi_port/win64/multi_port/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win64/output/dxl_x64_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol2.0/multi_port/win64/multi_port/multi_port.csproj b/c#/protocol2.0/multi_port/win64/multi_port/multi_port.csproj new file mode 100644 index 00000000..c3730f9d --- /dev/null +++ b/c#/protocol2.0/multi_port/win64/multi_port/multi_port.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {E974210C-6AEC-47D6-8359-0601C9725C6F} + Exe + Properties + multi_port + multi_port + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/ping/win32/.vs/ping/v14/.suo b/c#/protocol2.0/ping/win32/.vs/ping/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..333645605d8f229ceccc4f847515e88e3cc81494 GIT binary patch literal 35840 zcmeHQYm6gTl`fNnOqlT6WQSMiIAM5g+QyHv+daty{OXw|Gm|Fnd1S|-Q(Z3ic&6Gm zwtJ?B%s_qsLP$s;AwYrr0ELG_gaAc|MY|hq_7B=W$u3$zE0EydMj#=61SB3AzOQaw zyIgkJ)$Z=;agVQc>fWk*>%Pvt=bn4csp}VCc;m0X_Wig1Msd0Ol^c{-uH2%$+VMPq z@T=tg8x-Y6g!$~1D_5@Y@eKe3CvJ>-;31`kUrPxpd8G=!pLY{4SDNv zecz9M@?ZZQxE<*pf3rxufD&uUS!Eujml4V<>qBzsj^2k6>FnxzjQG!z3+KwoG8!%pYr?H{51yO7zhIdR|~RMt?6sZ`K@!iuBh9G)~pGS4f@58R1Z z=E;8WOz4O>jqu0p@^3--Z_W;MggLKYkN7tN7-pYk?J$$whVW|udjP!O3!nAa2Y3^J zD1Hmzt$?=y?f|?Uz;VJl2La6YZusv4Fc0b8jr;pu&t%+I`0q#F9{{8Qw*r`F4*qNH z@K%&D4tZS7`TydcJ9gvz4{*%iWRDwoLmks^_5A0$%<(p~a3pZfe>q0E&XW#sJ`y28%&YjK9f0irV)tvvYL)~S$?{I|Wv)$}Ve3N%0KSz9W zEZhtrUb#My#uK-slcbOAFOCcOE`5##`u_;uP5)&&N&n@&^hy8O@B0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oEX87~VusYx1c8#n&? zVlTVgN5=+t6Wh*-Z6{^TUL$#2HQ#PK20s*c_u0JdM$F3fWn$YovF((zdSct@wq=^w zb_)J;V%zEUUD?F86Ks#|xToB0oDMbe-S&-cp2#idW-siHUFXEM)A>cIn`3h0y<^iU zzk>0$?UXZSkiXORXIo%@FsOM$_4xb{eeIA4-xXc9ko92SI=&>+eo$t;`9J%@zd>h zW7+$zpzPoKxAZ-q{g1=n|G%eSxa}J!Uw=e-@yCBS_369+CI8HU|JA?zr*$4p2v<;2 z<=dZs<@u>2Pd!=s?w6*1KkJoJr1y6fyBTo~NX5g(#%YP;w*TQN5LsCGM65F)VhE|Q z|LwN18D#&%UDX9wxf`+n5&!eR8t$?Fcgbm+wAs4di(I>{oi>|e*!n)Q_nezB%!g>n zDo)PKz@(^zk~{WK{P(A=Y#F~bljoMpvv!8nA-&~waG&|ZuTL*3L5wG!{Wh#V@89zJ zIQwK{b>Rt`X_#;EL>!)rodrJ0<8xG!y1QE{&H*7-e~P2*`2QCH<=?mHMDo#2H0*N# zxqaL@4m8w~Iu10{aG;@~Y9Y0(TL&6y-3J{s^E@Ixnh&KjnP@1NPO14!B0V>kPhP%MS~r*0Q^_U0*bary>+9BO@!n@V zYFe?`z$@~w$t9dNxr9?CafBO=lCL#dhs6Q+;#9Y0SoeFveWrcF{dQJg$4PSaVx_8^ zYbB$*6~zVnZ2K4wc{5}~{GZXE`ME?ubS{B2`E$uoI-ZS$)MPdrN=0+2P&}54rc;r* zWHy>{AfS#j_a!oLh`vMuj_mh1q5shQ;^E^N*8%L=c)YHeueRjyh zOHX+Z>=FOMW8a(!2fn1Yc~@^fYr=tF*Z=>8Nq=4c|JP5S zCSNMQUY5Q%|J%>^A3H{^YD%n literal 0 HcmV?d00001 diff --git a/c#/protocol2.0/ping/win32/ping.sln b/c#/protocol2.0/ping/win32/ping.sln new file mode 100644 index 00000000..bd3e7438 --- /dev/null +++ b/c#/protocol2.0/ping/win32/ping.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 14 for Windows Desktop +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ping", "ping\ping.csproj", "{4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD}.Debug|x86.ActiveCfg = Debug|x86 + {4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD}.Debug|x86.Build.0 = Debug|x86 + {4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD}.Release|Any CPU.Build.0 = Release|Any CPU + {4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD}.Release|x86.ActiveCfg = Release|x86 + {4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/c#/protocol2.0/ping/win32/ping/App.config b/c#/protocol2.0/ping/win32/ping/App.config new file mode 100644 index 00000000..8e156463 --- /dev/null +++ b/c#/protocol2.0/ping/win32/ping/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/ping/win32/ping/Ping.cs b/c#/protocol2.0/ping/win32/ping/Ping.cs new file mode 100644 index 00000000..b8f6f140 --- /dev/null +++ b/c#/protocol2.0/ping/win32/ping/Ping.cs @@ -0,0 +1,99 @@ +/* +* ping.cs +* +* Created on: 2016. 5. 16. +* Author: Leon Ryu Woon Jung +*/ + +// +// ********* ping Example ********* +// +// +// Available Dynamixel model on this example : All models using Protocol 2.0 +// This example is designed for using a Dynamixel PRO 54-200, and an USB2DYNAMIXEL. +// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below variables yourself. +// Be sure that Dynamixel PRO properties are already set as %% ID : 1 / Baudnum : 3 (Baudrate : 1000000 [1M]) +// + +using System; +using dynamixel_sdk; + +namespace ping +{ + class Ping + { + // Protocol version + public const int PROTOCOL_VERSION = 2; // See which protocol version is used in the Dynamixel + + // Default setting + public const int DXL_ID = 1; // Dynamixel ID: 1 + public const int BAUDRATE = 1000000; + public const string DEVICENAME = "COM8"; // Check which port is being used on your controller + // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const byte ESC_ASCII_VALUE = 0x1b; + + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num = dynamixel.portHandler(DEVICENAME); + + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + int dxl_comm_result = COMM_TX_FAIL; // Communication result + + byte dxl_error = 0; // Dynamixel error + UInt16 dxl_model_number; // Dynamixel model number + + // Open port + if (dynamixel.openPort(port_num)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port baudrate + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + // Try to ping the Dynamixel + // Get Dynamixel model number + dxl_model_number = dynamixel.pingGetModelNum(port_num, PROTOCOL_VERSION, DXL_ID); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + Console.WriteLine("[ID:{0}] ping Succeeded. Dynamixel model number : {1}", DXL_ID, dxl_model_number); + + // Close port + dynamixel.closePort(port_num); + + return; + } + } +} diff --git a/c#/protocol2.0/ping/win32/ping/Properties/AssemblyInfo.cs b/c#/protocol2.0/ping/win32/ping/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..a97376c3 --- /dev/null +++ b/c#/protocol2.0/ping/win32/ping/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("ping")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ping")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("4d6dfb5c-0e72-47b4-9d9a-ac58f5dd3abd")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol2.0/ping/win32/ping/dynamixel.cs b/c#/protocol2.0/ping/win32/ping/dynamixel.cs new file mode 100644 index 00000000..235af316 --- /dev/null +++ b/c#/protocol2.0/ping/win32/ping/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win32/output/dxl_x86_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol2.0/ping/win32/ping/ping.csproj b/c#/protocol2.0/ping/win32/ping/ping.csproj new file mode 100644 index 00000000..6591c52b --- /dev/null +++ b/c#/protocol2.0/ping/win32/ping/ping.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD} + Exe + Properties + ping + ping + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/ping/win64/.vs/ping/v14/.suo b/c#/protocol2.0/ping/win64/.vs/ping/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..5a848c374fc1fa15e2250c482ecdb4abff6c2f5a GIT binary patch literal 15360 zcmeHOZHya78D6JfNgG=FK_~^TZW>BUZjHasPMfs$+Rml9Yp(TOk`hP9X1%_1ZqGKm zcJ7WQMXFRlNJtI>K?axw2IwV~oy?Jq$bhW2Efcy^e{BB9Q z5_y)rdGX>!7GD8C_Hw#}DDa3>$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W<57Z5bSImqhMmrom7Ha#i(_F|Q=X(f%<=P!1L}2YJpyq7|DMdDyKe za&g@IVcn4b5Lma;fp-}Bch22#ggfnXXQLe3z4mFdQT7DE%S-YBVR$ujZET1{Q9uIk3TRbHB3vG+h|T{oMPYOQSO zrn4=wLfZNBkLAMoNG72q+Q2B&6xFOU8@^W?vivdk{Ju%OXcXM*O-gu_Q>C+D)IoM1vRceJGK-`{;+^G3DSS}ireoB2hD zIZn~wGh@`i@hv22djdeo-Hrg9e3`m~Gru14Z4hsrbiVSt57x5%1f&HEa@=13BDP=V zoK)}=08-%v=quft;k{3{xKyL4NNs@W*PIN2&13581yL`giC3^Yfp*D6&SQt9gZYAwUy$?x{WeVg{H zy}3iLkA3UA@n?Aae5myOz@^9guaCX<)R!Lp>*rqlROZt!E&Tr9oG?RZ-t=I$sGLT5 zzu9pwx*=oTa?Vae?4^bDk?%MKwX$jJ0OOiTDiiT|CMAdS@r)cVV4+B*k{LOij7L+k za3Y?Zh+nv72J8-LvA=xg)IW-M%df7z_KS}#{P8*O(lm(RM1|mB$%;iC@o{>#9^IZu z_UL(B)uR(?@=RFPWATKHS*7H3vRsi9x>|{)3SLBoc literal 0 HcmV?d00001 diff --git a/c#/protocol2.0/ping/win64/ping.sln b/c#/protocol2.0/ping/win64/ping.sln new file mode 100644 index 00000000..224ef50f --- /dev/null +++ b/c#/protocol2.0/ping/win64/ping.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 14 for Windows Desktop +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ping", "ping\ping.csproj", "{4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD}.Debug|x64.ActiveCfg = Debug|x64 + {4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD}.Debug|x64.Build.0 = Debug|x64 + {4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD}.Release|Any CPU.Build.0 = Release|Any CPU + {4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD}.Release|x64.ActiveCfg = Release|x64 + {4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/c#/protocol2.0/ping/win64/ping/App.config b/c#/protocol2.0/ping/win64/ping/App.config new file mode 100644 index 00000000..8e156463 --- /dev/null +++ b/c#/protocol2.0/ping/win64/ping/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/ping/win64/ping/Ping.cs b/c#/protocol2.0/ping/win64/ping/Ping.cs new file mode 100644 index 00000000..b8f6f140 --- /dev/null +++ b/c#/protocol2.0/ping/win64/ping/Ping.cs @@ -0,0 +1,99 @@ +/* +* ping.cs +* +* Created on: 2016. 5. 16. +* Author: Leon Ryu Woon Jung +*/ + +// +// ********* ping Example ********* +// +// +// Available Dynamixel model on this example : All models using Protocol 2.0 +// This example is designed for using a Dynamixel PRO 54-200, and an USB2DYNAMIXEL. +// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below variables yourself. +// Be sure that Dynamixel PRO properties are already set as %% ID : 1 / Baudnum : 3 (Baudrate : 1000000 [1M]) +// + +using System; +using dynamixel_sdk; + +namespace ping +{ + class Ping + { + // Protocol version + public const int PROTOCOL_VERSION = 2; // See which protocol version is used in the Dynamixel + + // Default setting + public const int DXL_ID = 1; // Dynamixel ID: 1 + public const int BAUDRATE = 1000000; + public const string DEVICENAME = "COM8"; // Check which port is being used on your controller + // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const byte ESC_ASCII_VALUE = 0x1b; + + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num = dynamixel.portHandler(DEVICENAME); + + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + int dxl_comm_result = COMM_TX_FAIL; // Communication result + + byte dxl_error = 0; // Dynamixel error + UInt16 dxl_model_number; // Dynamixel model number + + // Open port + if (dynamixel.openPort(port_num)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port baudrate + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + // Try to ping the Dynamixel + // Get Dynamixel model number + dxl_model_number = dynamixel.pingGetModelNum(port_num, PROTOCOL_VERSION, DXL_ID); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + Console.WriteLine("[ID:{0}] ping Succeeded. Dynamixel model number : {1}", DXL_ID, dxl_model_number); + + // Close port + dynamixel.closePort(port_num); + + return; + } + } +} diff --git a/c#/protocol2.0/ping/win64/ping/Properties/AssemblyInfo.cs b/c#/protocol2.0/ping/win64/ping/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..a97376c3 --- /dev/null +++ b/c#/protocol2.0/ping/win64/ping/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("ping")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ping")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("4d6dfb5c-0e72-47b4-9d9a-ac58f5dd3abd")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol2.0/ping/win64/ping/dynamixel.cs b/c#/protocol2.0/ping/win64/ping/dynamixel.cs new file mode 100644 index 00000000..d940e04b --- /dev/null +++ b/c#/protocol2.0/ping/win64/ping/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win64/output/dxl_x64_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol2.0/ping/win64/ping/ping.csproj b/c#/protocol2.0/ping/win64/ping/ping.csproj new file mode 100644 index 00000000..36fea6a1 --- /dev/null +++ b/c#/protocol2.0/ping/win64/ping/ping.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {4D6DFB5C-0E72-47B4-9D9A-AC58F5DD3ABD} + Exe + Properties + ping + ping + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/read_write/win32/.vs/read_write/v14/.suo b/c#/protocol2.0/read_write/win32/.vs/read_write/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..7b2b476023885cd1ee36768bfa23018c9fe8cd56 GIT binary patch literal 41472 zcmeHQ3y@pYdA@5f#x^9RID|rK7UBX0OVN9G4K~qh?FAbz-nC7FV9`o<*YawmMbg^4 z!R8rAn&42DZm6tt_|sswQuJ<2^tA z^s#4O=y^Zl-FAtLJPeF^ZND}I>=U?(YjaIfseXKxwxXvOLF)mmc6d$Q?;{4fuW$-K z@y=*jUkT0|57|$32=)4e8lw`18Ju=3oKbJgYpw5O_*Z{Dbz!3 zgad!M{+;6Ai+8u2Dib&x-s^nP;y9+y#4}5-U<%+_+}5 z^Ii58m4?}8yO{6QHS5>~U^{OFFn^ojdjURx9}oZp0Un8~&B>uLAJh9q`Wr>;wz}7;ibdr5yhc9eHgr#(z~Cph=p# z?)a~af7N$aqt-YNSjRo*HI8A9U5<4=KN-GykG>lJYfRy4{F~$PT8)2exVm3!N<)Rw zSL2`4Rwu^)X-2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ZNVAHOdz*VgUAPwr7O509BzNF7v;aEjH;Zp}F`?TP@ZHO5p~$PRgI31=GF^X_wxJm3*-FOo0a9Ls;n~Rk@VIW_jaqDeVBcI z72n?a{RK=0UAK&CpfhXV+w=UF<-JPoGN@{+9TE-*Mt^VjY#XcXY4`hoJS=qSzW*m> zuJ$Wc`&8l5egCID32rSlyYStJ-Rh}mM#{V%jAEqKii RK{n3%k;%o + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/read_write/win32/read_write/Properties/AssemblyInfo.cs b/c#/protocol2.0/read_write/win32/read_write/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..94be0145 --- /dev/null +++ b/c#/protocol2.0/read_write/win32/read_write/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("read_write")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("read_write")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("d1b60768-6b6b-492d-8e0a-d258d9b2ca27")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol2.0/read_write/win32/read_write/ReadWrite.cs b/c#/protocol2.0/read_write/win32/read_write/ReadWrite.cs new file mode 100644 index 00000000..8b195296 --- /dev/null +++ b/c#/protocol2.0/read_write/win32/read_write/ReadWrite.cs @@ -0,0 +1,170 @@ +/* +* read_write.cs +* +* Created on: 2016. 5. 16. +* Author: Leon Ryu Woon Jung +*/ + +// +// ********* Read and Write Example ********* +// +// +// Available Dynamixel model on this example : All models using Protocol 2.0 +// This example is designed for using a Dynamixel PRO 54-200, and an USB2DYNAMIXEL. +// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below variables yourself. +// Be sure that Dynamixel PRO properties are already set as %% ID : 1 / Baudnum : 3 (Baudrate : 1000000 [1M]) +// + +using System; +using dynamixel_sdk; + +namespace read_write +{ + class ReadWrite + { + // Control table address + public const int ADDR_PRO_TORQUE_ENABLE = 562; // Control table address is different in Dynamixel model + public const int ADDR_PRO_GOAL_POSITION = 596; + public const int ADDR_PRO_PRESENT_POSITION = 611; + + // Protocol version + public const int PROTOCOL_VERSION = 2; // See which protocol version is used in the Dynamixel + + // Default setting + public const int DXL_ID = 1; // Dynamixel ID: 1 + public const int BAUDRATE = 1000000; + public const string DEVICENAME = "COM8"; // Check which port is being used on your controller + // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const int TORQUE_ENABLE = 1; // Value for enabling the torque + public const int TORQUE_DISABLE = 0; // Value for disabling the torque + public const int DXL_MINIMUM_POSITION_VALUE = -150000; // Dynamixel will rotate between this value + public const int DXL_MAXIMUM_POSITION_VALUE = 150000; // and this value (note that the Dynamixel would not move when the position value is out of movable range. Check e-manual about the range of the Dynamixel you use.) + public const int DXL_MOVING_STATUS_THRESHOLD = 20; // Dynamixel moving status threshold + + public const byte ESC_ASCII_VALUE = 0x1b; + + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num = dynamixel.portHandler(DEVICENAME); + + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + int index = 0; + int dxl_comm_result = COMM_TX_FAIL; // Communication result + int[] dxl_goal_position = new int[2]{ DXL_MINIMUM_POSITION_VALUE, DXL_MAXIMUM_POSITION_VALUE }; // Goal position + + byte dxl_error = 0; // Dynamixel error + Int32 dxl_present_position = 0; // Present position + + // Open port + if (dynamixel.openPort(port_num)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port baudrate + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Enable DXL Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("Dynamixel has been successfully connected "); + } + + while (true) + { + Console.WriteLine("Press any key to continue! (or press ESC to quit!)"); + if (Console.ReadKey().KeyChar == ESC_ASCII_VALUE) + break; + + // Write goal position + dynamixel.write4ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_GOAL_POSITION, (UInt32)dxl_goal_position[index]); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + do + { + // Read present position + dxl_present_position = (Int32)dynamixel.read4ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_PRESENT_POSITION); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + Console.WriteLine("[ID:{0}] GoalPos:{1} PresPos:{2}", DXL_ID, dxl_goal_position[index], dxl_present_position); + + } while ((Math.Abs(dxl_goal_position[index] - dxl_present_position) > DXL_MOVING_STATUS_THRESHOLD)); + + // Change goal position + if (index == 0) + { + index = 1; + } + else + { + index = 0; + } + } + + // Disable Dynamixel Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Close port + dynamixel.closePort(port_num); + + return; + } + } +} diff --git a/c#/protocol2.0/read_write/win32/read_write/dynamixel.cs b/c#/protocol2.0/read_write/win32/read_write/dynamixel.cs new file mode 100644 index 00000000..235af316 --- /dev/null +++ b/c#/protocol2.0/read_write/win32/read_write/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win32/output/dxl_x86_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol2.0/read_write/win32/read_write/read_write.csproj b/c#/protocol2.0/read_write/win32/read_write/read_write.csproj new file mode 100644 index 00000000..131b619a --- /dev/null +++ b/c#/protocol2.0/read_write/win32/read_write/read_write.csproj @@ -0,0 +1,108 @@ + + + + + Debug + AnyCPU + {D1B60768-6B6B-492D-8E0A-D258D9B2CA27} + Exe + Properties + read_write + read_write + v4.5 + 512 + false + 게시\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + prompt + MinimumRecommendedRules.ruleset + true + 0 + + + + + + + + + + + + + + + + + + + + + + False + Microsoft .NET Framework 4.5%28x86 및 x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/read_write/win32/read_write/read_write.csproj.user b/c#/protocol2.0/read_write/win32/read_write/read_write.csproj.user new file mode 100644 index 00000000..04baf14c --- /dev/null +++ b/c#/protocol2.0/read_write/win32/read_write/read_write.csproj.user @@ -0,0 +1,17 @@ + + + + 게시\ + + + + + + ko-KR + false + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/read_write/win64/.vs/read_write/v14/.suo b/c#/protocol2.0/read_write/win64/.vs/read_write/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..3f5e8f9e8a256794bbe0237eabcb8b5c10fb2d9b GIT binary patch literal 32768 zcmeHQ4RBo5b$)9D#x^7&ID{B#7UN)wwcA~-w32LW*gql1HWo;hop?c6?LJA1o_3er zl`X{rf(c35;82n#Wb!l9=4ZmtpD7)ZDQ%J_v_oCmsRL<4o9RrNcA6GS{-#NP2fN?* z?z^kEyKmons}&M5d*$=)d-vUY&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-Pdtnoc$5FPx2(Z_Ioa2 zFJ9TcxzQ5EH+n^*7u9-TJA3w2=DafNM@;Nd;!E9??OUrW zvvJ?Zo1a_Om1(xE@a)BY-mEFDaertfJiV;_sc%c`5|dncG!M19ch#DX)`2VbHV*Q!@ ze`@K!?f>z{^8aw6|F-{^J^k}-v-^*8jm_m~1^-I>f6)IxA3%@M=O+C>^wTpAz#_}H z{YP5!A8Fn*ClnkT5A}A3Q<+e>OAU43c_-zO^)v@wz{`2&V6zkh#9>)yctKrU@y!`X zl_rO>?^9t(UA+H}tc~PT>%Y_X{}JDa+xhQc*z~|P-1h(BZ)rJsCROY2#_%=a*;HL# z>M@J8pmW`~{eQ$Pa4a1CcW^G=_W!}LM{_?S*Y^L>PsF&++WtRoeUsY$KV~1K2-eQh z`XJHzYW9U{&gZ7>|I_yWDI{0B|4-ZhqwW7;_Zzs@C!B5n59wyU`hTlfe7o89|9EYG zX}Z;u;`(!Zc?!>ypSJ%8&#~%$oJE)KTKhJ~e%`FPW8=AM`+vw!ZRGF2xBWk?{0*1S z|HE$YclKXtw95?A(|C`{Y}`u75@90r{cWe@!nB<|u?WvDmLpdfYy5>oMm?r#_)?Xob%2DhI4K_;2an{8;2G4}I+D`(ON*E3@AU mHv9cQ`4 + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/read_write/win64/read_write/Properties/AssemblyInfo.cs b/c#/protocol2.0/read_write/win64/read_write/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..94be0145 --- /dev/null +++ b/c#/protocol2.0/read_write/win64/read_write/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("read_write")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("read_write")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("d1b60768-6b6b-492d-8e0a-d258d9b2ca27")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol2.0/read_write/win64/read_write/ReadWrite.cs b/c#/protocol2.0/read_write/win64/read_write/ReadWrite.cs new file mode 100644 index 00000000..8b195296 --- /dev/null +++ b/c#/protocol2.0/read_write/win64/read_write/ReadWrite.cs @@ -0,0 +1,170 @@ +/* +* read_write.cs +* +* Created on: 2016. 5. 16. +* Author: Leon Ryu Woon Jung +*/ + +// +// ********* Read and Write Example ********* +// +// +// Available Dynamixel model on this example : All models using Protocol 2.0 +// This example is designed for using a Dynamixel PRO 54-200, and an USB2DYNAMIXEL. +// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below variables yourself. +// Be sure that Dynamixel PRO properties are already set as %% ID : 1 / Baudnum : 3 (Baudrate : 1000000 [1M]) +// + +using System; +using dynamixel_sdk; + +namespace read_write +{ + class ReadWrite + { + // Control table address + public const int ADDR_PRO_TORQUE_ENABLE = 562; // Control table address is different in Dynamixel model + public const int ADDR_PRO_GOAL_POSITION = 596; + public const int ADDR_PRO_PRESENT_POSITION = 611; + + // Protocol version + public const int PROTOCOL_VERSION = 2; // See which protocol version is used in the Dynamixel + + // Default setting + public const int DXL_ID = 1; // Dynamixel ID: 1 + public const int BAUDRATE = 1000000; + public const string DEVICENAME = "COM8"; // Check which port is being used on your controller + // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const int TORQUE_ENABLE = 1; // Value for enabling the torque + public const int TORQUE_DISABLE = 0; // Value for disabling the torque + public const int DXL_MINIMUM_POSITION_VALUE = -150000; // Dynamixel will rotate between this value + public const int DXL_MAXIMUM_POSITION_VALUE = 150000; // and this value (note that the Dynamixel would not move when the position value is out of movable range. Check e-manual about the range of the Dynamixel you use.) + public const int DXL_MOVING_STATUS_THRESHOLD = 20; // Dynamixel moving status threshold + + public const byte ESC_ASCII_VALUE = 0x1b; + + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num = dynamixel.portHandler(DEVICENAME); + + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + int index = 0; + int dxl_comm_result = COMM_TX_FAIL; // Communication result + int[] dxl_goal_position = new int[2]{ DXL_MINIMUM_POSITION_VALUE, DXL_MAXIMUM_POSITION_VALUE }; // Goal position + + byte dxl_error = 0; // Dynamixel error + Int32 dxl_present_position = 0; // Present position + + // Open port + if (dynamixel.openPort(port_num)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port baudrate + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Enable DXL Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("Dynamixel has been successfully connected "); + } + + while (true) + { + Console.WriteLine("Press any key to continue! (or press ESC to quit!)"); + if (Console.ReadKey().KeyChar == ESC_ASCII_VALUE) + break; + + // Write goal position + dynamixel.write4ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_GOAL_POSITION, (UInt32)dxl_goal_position[index]); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + do + { + // Read present position + dxl_present_position = (Int32)dynamixel.read4ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_PRESENT_POSITION); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + Console.WriteLine("[ID:{0}] GoalPos:{1} PresPos:{2}", DXL_ID, dxl_goal_position[index], dxl_present_position); + + } while ((Math.Abs(dxl_goal_position[index] - dxl_present_position) > DXL_MOVING_STATUS_THRESHOLD)); + + // Change goal position + if (index == 0) + { + index = 1; + } + else + { + index = 0; + } + } + + // Disable Dynamixel Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Close port + dynamixel.closePort(port_num); + + return; + } + } +} diff --git a/c#/protocol2.0/read_write/win64/read_write/dynamixel.cs b/c#/protocol2.0/read_write/win64/read_write/dynamixel.cs new file mode 100644 index 00000000..d940e04b --- /dev/null +++ b/c#/protocol2.0/read_write/win64/read_write/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win64/output/dxl_x64_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol2.0/read_write/win64/read_write/read_write.csproj b/c#/protocol2.0/read_write/win64/read_write/read_write.csproj new file mode 100644 index 00000000..2104f52b --- /dev/null +++ b/c#/protocol2.0/read_write/win64/read_write/read_write.csproj @@ -0,0 +1,107 @@ + + + + + Debug + AnyCPU + {D1B60768-6B6B-492D-8E0A-D258D9B2CA27} + Exe + Properties + read_write + read_write + v4.5 + 512 + false + 게시\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + False + Microsoft .NET Framework 4.5%28x86 및 x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/read_write/win64/read_write/read_write.csproj.user b/c#/protocol2.0/read_write/win64/read_write/read_write.csproj.user new file mode 100644 index 00000000..04baf14c --- /dev/null +++ b/c#/protocol2.0/read_write/win64/read_write/read_write.csproj.user @@ -0,0 +1,17 @@ + + + + 게시\ + + + + + + ko-KR + false + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/reboot/win32/.vs/reboot/v14/.suo b/c#/protocol2.0/reboot/win32/.vs/reboot/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..0ebd696ae1d275f9e0c4cc17f232790021e3f403 GIT binary patch literal 40960 zcmeHQOKcm*8D80W*s+r|apIO&`XP;ZGs{wl0(u%QJ|-$kMz((QM71#N!0J#;fTA- zCApL(TaD9|GzUIesJF(-+1%kj}(jBtE^Q%onNoqVF>Rr+$*0^ zl-u#luutdb=NZL&+`6udFmO~U;#XBXN=hly<4$)g5k zMS~v&E>w7}maf@l+ak)}ip+*NSm2H*GbkmmWs&rMtft&*#tMehB_S_|5Qa-iP2n2mdhq zBk+&HKL)=Ao^|%X6Bn%ecKAEt2jH3C7jS*LcHdvSGQ3k4cku2;q)EUh;fb3;c*40K z*I{_}mjmzz;Sa$dhTjI?X{9VR-kexIYD-u7!1!(K08N@VV_T#sTqR*ZvIe#L4#OJ1e>Uli+wW z;6bOs>5~6Hp>v^GgkDsRDHWX;PU@Vnir(AkeBeJx4>rYue~UrIF|F3IoAG(eC5~K;o*)b6Igv5LTTk%+2r|&iHdSu zAq8peo~V^i+Q@pePAy_Nw;it~OaOWnWwEpzO1{`oi`F?VX8mEr{~#z}3Y0XA{{*P1 z7nIbG>mcp|_$Bc?u8iUN5aLy=kt(JNMQiYruXhT657Kh3p)>ZkL&(1Xe^&2xK4nDj ziv>JoQ9k7_C#}O;vM5Z*I(>P zqI75Fv+Xa{GC7VC#!wPR!36$ivHs)w^8(7x;I5rx|06EtTCH7r#&b<1@qY|3a@DH> z$HcQ-4{Io$W1yWw`3tZ+#lNxtwJX1!JYYNEC;!Q{=5myu1XeC!9FVuLbD%%h1^<4u zb5_TF0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z1&DIT?!rtyzn8ZQt}~7K&03u_O5a>vF~8lG)LrsE zje0+s!m1bG{O|4+Cid%0wpF!N5vc74Xx74vJCmALTVX7VCHirw1WS4tp*xL0rrpW_+*_>U}7@VABn2j zP&BNCBBxK2hhNWqOm5@fDmx%&DG)@o+*v!tXkDT>T~f>GvcA9ZQRp{=gf*% zdX$Yusfp$BeUV77@T${P<&sz9JMg~79!L&J^D zWdtLw*VqKvu^K4*DdaN#c$AX(wZ4<7S0VR>;ZDBfCAdZO(S#L?K1FgcE~!&eQ!$tHWstFLB*=A=jmbmYj9tuDw1C8=mA`Mb|%vyF9RBgn!qP*MrhnaVneKTcBMX z29~@IR$TDBg*nB8-Z6r+>)O@lnI*4}5htD1g);a7v>i{%x&X{3(4Jh4vR9J2S|Jr* zmhMuj>8l{%n~*|K;2vdIdvQzlH_z?EfQ!G?licaY?^41ak47V*L2o3M3VOqRfs}V3 z9uIhv1O4GtJTfpin2KJxoSn^&&-O>hGwFpp--XO9wqZPfxw&*&RnwI+UXlANj#si% z;}`WaG_l`fv0UA+7P5J*ERNNz_%hf(GU-nR1|o^5Hy(<_yx~+h;Elzjes3rgjl_b% zL~tM&yb}NAji`PGM|qagxk4sClhw>nq(|filssiqlYscnIfmf(5`w^BB$kXNquzl~ z!tV`76A5pBAldH?1(Sh+e*a)J5r`WapoEPvWn(~oFB>7#bQ{f~;j#V4;+9P=ckHl- zYdoJT%*>`sXq)kKqH#o!bI2%V=Awqqc3)4&Xk`w1|8QP-+=y1GzgjF>o$9aZdxx6Q L%5_6G>#zO~64wji literal 0 HcmV?d00001 diff --git a/c#/protocol2.0/reboot/win32/reboot.sln b/c#/protocol2.0/reboot/win32/reboot.sln new file mode 100644 index 00000000..20f6b874 --- /dev/null +++ b/c#/protocol2.0/reboot/win32/reboot.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 14 for Windows Desktop +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "reboot", "reboot\reboot.csproj", "{507A253C-9030-4EC6-8511-F8307D20C695}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {507A253C-9030-4EC6-8511-F8307D20C695}.Debug|Any CPU.ActiveCfg = Release|Any CPU + {507A253C-9030-4EC6-8511-F8307D20C695}.Debug|Any CPU.Build.0 = Release|Any CPU + {507A253C-9030-4EC6-8511-F8307D20C695}.Debug|x86.ActiveCfg = Release|x86 + {507A253C-9030-4EC6-8511-F8307D20C695}.Debug|x86.Build.0 = Release|x86 + {507A253C-9030-4EC6-8511-F8307D20C695}.Release|Any CPU.ActiveCfg = Release|Any CPU + {507A253C-9030-4EC6-8511-F8307D20C695}.Release|Any CPU.Build.0 = Release|Any CPU + {507A253C-9030-4EC6-8511-F8307D20C695}.Release|x86.ActiveCfg = Release|x86 + {507A253C-9030-4EC6-8511-F8307D20C695}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/c#/protocol2.0/reboot/win32/reboot/App.config b/c#/protocol2.0/reboot/win32/reboot/App.config new file mode 100644 index 00000000..8e156463 --- /dev/null +++ b/c#/protocol2.0/reboot/win32/reboot/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/reboot/win32/reboot/Properties/AssemblyInfo.cs b/c#/protocol2.0/reboot/win32/reboot/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..16e33359 --- /dev/null +++ b/c#/protocol2.0/reboot/win32/reboot/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("reboot")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("reboot")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("507a253c-9030-4ec6-8511-f8307d20c695")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol2.0/reboot/win32/reboot/Reboot.cs b/c#/protocol2.0/reboot/win32/reboot/Reboot.cs new file mode 100644 index 00000000..b4d13175 --- /dev/null +++ b/c#/protocol2.0/reboot/win32/reboot/Reboot.cs @@ -0,0 +1,104 @@ +/* +* reboot.cs +* +* Created on: 2016. 5. 16. +* Author: Leon Ryu Woon Jung +*/ + +// +// ********* reboot Example ********* +// +// +// Available Dynamixel model on this example : All models using Protocol 2.0 +// This example is designed for using a Dynamixel PRO 54-200, and an USB2DYNAMIXEL. +// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below variables yourself. +// Be sure that Dynamixel PRO properties are already set as %% ID : 1 / Baudnum : 3 (Baudrate : 1000000 [1M]) +// + +using System; +using dynamixel_sdk; + +namespace reboot +{ + class Reboot + { + // Protocol version + public const int PROTOCOL_VERSION = 2; // See which protocol version is used in the Dynamixel + + // Default setting + public const int DXL_ID = 1; // Dynamixel ID: 1 + public const int BAUDRATE = 1000000; + public const string DEVICENAME = "COM8"; // Check which port is being used on your controller + // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const byte ESC_ASCII_VALUE = 0x1b; + + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num = dynamixel.portHandler(DEVICENAME); + + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + int dxl_comm_result = COMM_TX_FAIL; // Communication result + + byte dxl_error = 0; // Dynamixel error + + // Open port + if (dynamixel.openPort(port_num)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port baudrate + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Trigger + Console.WriteLine("Press any key to reboot"); + Console.ReadKey(); + + Console.WriteLine("See the Dynamixel LED flickering"); + // Try reboot + // Dynamixel LED will flicker while it reboots + dynamixel.reboot(port_num, PROTOCOL_VERSION, DXL_ID); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + Console.WriteLine("[ID:{0}] reboot Succeeded", DXL_ID); + + // Close port + dynamixel.closePort(port_num); + + return; + } + } +} \ No newline at end of file diff --git a/c#/protocol2.0/reboot/win32/reboot/dynamixel.cs b/c#/protocol2.0/reboot/win32/reboot/dynamixel.cs new file mode 100644 index 00000000..235af316 --- /dev/null +++ b/c#/protocol2.0/reboot/win32/reboot/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win32/output/dxl_x86_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol2.0/reboot/win32/reboot/reboot.csproj b/c#/protocol2.0/reboot/win32/reboot/reboot.csproj new file mode 100644 index 00000000..6b2e3a7f --- /dev/null +++ b/c#/protocol2.0/reboot/win32/reboot/reboot.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {507A253C-9030-4EC6-8511-F8307D20C695} + Exe + Properties + reboot + reboot + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/reboot/win64/.vs/reboot/v14/.suo b/c#/protocol2.0/reboot/win64/.vs/reboot/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..b6dd33b11a70b59bfe255f18e28d1656fd050838 GIT binary patch literal 47104 zcmeHQTZ~&r89tldk~S223#CACODQQ?8{h41nzZZ7Zk8sgTW>Bj4x6*~*~HniwmJ4D zyEH+ls1h$o@WAZ>2_%pZR7e%PP@z&PR3ZA%@_>-~fGF1o9uVRIcxc1-o$;)XkB{x+ zjW=0u&RFAfn=>>2|IhsM&;S2t=FK zawE=p@7>FnFZ1>dh&c7a2w~u9rHWre@hMrQf}^3Vl9aB)F6E{*nxjed47oqNGx7J| z{C4aUNcH&pMbaEftSaY}8I-<&v#hexGY|X2UCOpGA8x)Ek!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}D>+=qy} zRPkv7T#~yG@%aSay#x(o3Hxldmn&9{vzE%;$=lP&x`}n)n0CAJ(2(o454jE-+V&N1 z<*K~_bQ`YZ*Fe)hi!&WqvBJM^==Er=8|1bQlS8kA9T(hhVO8;=b>z@k`{CrVq1VTX zlfmjj9sDF{$8`qJgYBh3PtHQwD#=~#kc#yV_9>0Rb70_iA%)<;W6F&7{O;1PKl?a3 zT7J(~`u;_+By${(A^hW*h*DC?h0r9%G9WHOpf#U`hwvhhn7ODp=^N-{oI zEUcXc&KFm(4fDB+-L=!ITBsX%MeeUWS1&EjT`>2+#D33Jqj6BJlyuDy+hW!OMeHA) z31&l+v2@&@io_=T(QGv2pGd`n{zxPqn+S)~;mL6LQtB61qxwZ`#aSzqD@A>|q_sm) z$jJ?;b8rIHBp`vat|9ongdj8(o5)OL;{M4^)Z&3=yb*^K*7+P?skHlg={eC_nLr*xw8Jl+~i z8$v1N+V8^I?sZJ*sU3Fl+zH}Q)%#0`?cdCI(%qiYjs^LRSnKHNe~U5W#V literal 0 HcmV?d00001 diff --git a/c#/protocol2.0/reboot/win64/reboot.sln b/c#/protocol2.0/reboot/win64/reboot.sln new file mode 100644 index 00000000..5c88904d --- /dev/null +++ b/c#/protocol2.0/reboot/win64/reboot.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 14 for Windows Desktop +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "reboot", "reboot\reboot.csproj", "{507A253C-9030-4EC6-8511-F8307D20C695}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {507A253C-9030-4EC6-8511-F8307D20C695}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {507A253C-9030-4EC6-8511-F8307D20C695}.Debug|Any CPU.Build.0 = Debug|Any CPU + {507A253C-9030-4EC6-8511-F8307D20C695}.Debug|x64.ActiveCfg = Release|x64 + {507A253C-9030-4EC6-8511-F8307D20C695}.Debug|x64.Build.0 = Release|x64 + {507A253C-9030-4EC6-8511-F8307D20C695}.Release|Any CPU.ActiveCfg = Release|Any CPU + {507A253C-9030-4EC6-8511-F8307D20C695}.Release|Any CPU.Build.0 = Release|Any CPU + {507A253C-9030-4EC6-8511-F8307D20C695}.Release|x64.ActiveCfg = Release|x64 + {507A253C-9030-4EC6-8511-F8307D20C695}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/c#/protocol2.0/reboot/win64/reboot/App.config b/c#/protocol2.0/reboot/win64/reboot/App.config new file mode 100644 index 00000000..8e156463 --- /dev/null +++ b/c#/protocol2.0/reboot/win64/reboot/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/reboot/win64/reboot/Properties/AssemblyInfo.cs b/c#/protocol2.0/reboot/win64/reboot/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..16e33359 --- /dev/null +++ b/c#/protocol2.0/reboot/win64/reboot/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("reboot")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("reboot")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("507a253c-9030-4ec6-8511-f8307d20c695")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol2.0/reboot/win64/reboot/Reboot.cs b/c#/protocol2.0/reboot/win64/reboot/Reboot.cs new file mode 100644 index 00000000..b4d13175 --- /dev/null +++ b/c#/protocol2.0/reboot/win64/reboot/Reboot.cs @@ -0,0 +1,104 @@ +/* +* reboot.cs +* +* Created on: 2016. 5. 16. +* Author: Leon Ryu Woon Jung +*/ + +// +// ********* reboot Example ********* +// +// +// Available Dynamixel model on this example : All models using Protocol 2.0 +// This example is designed for using a Dynamixel PRO 54-200, and an USB2DYNAMIXEL. +// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below variables yourself. +// Be sure that Dynamixel PRO properties are already set as %% ID : 1 / Baudnum : 3 (Baudrate : 1000000 [1M]) +// + +using System; +using dynamixel_sdk; + +namespace reboot +{ + class Reboot + { + // Protocol version + public const int PROTOCOL_VERSION = 2; // See which protocol version is used in the Dynamixel + + // Default setting + public const int DXL_ID = 1; // Dynamixel ID: 1 + public const int BAUDRATE = 1000000; + public const string DEVICENAME = "COM8"; // Check which port is being used on your controller + // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const byte ESC_ASCII_VALUE = 0x1b; + + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num = dynamixel.portHandler(DEVICENAME); + + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + int dxl_comm_result = COMM_TX_FAIL; // Communication result + + byte dxl_error = 0; // Dynamixel error + + // Open port + if (dynamixel.openPort(port_num)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port baudrate + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Trigger + Console.WriteLine("Press any key to reboot"); + Console.ReadKey(); + + Console.WriteLine("See the Dynamixel LED flickering"); + // Try reboot + // Dynamixel LED will flicker while it reboots + dynamixel.reboot(port_num, PROTOCOL_VERSION, DXL_ID); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + Console.WriteLine("[ID:{0}] reboot Succeeded", DXL_ID); + + // Close port + dynamixel.closePort(port_num); + + return; + } + } +} \ No newline at end of file diff --git a/c#/protocol2.0/reboot/win64/reboot/dynamixel.cs b/c#/protocol2.0/reboot/win64/reboot/dynamixel.cs new file mode 100644 index 00000000..d940e04b --- /dev/null +++ b/c#/protocol2.0/reboot/win64/reboot/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win64/output/dxl_x64_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol2.0/reboot/win64/reboot/reboot.csproj b/c#/protocol2.0/reboot/win64/reboot/reboot.csproj new file mode 100644 index 00000000..f61492da --- /dev/null +++ b/c#/protocol2.0/reboot/win64/reboot/reboot.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {507A253C-9030-4EC6-8511-F8307D20C695} + Exe + Properties + reboot + reboot + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/sync_read_write/win32/.vs/sync_read_write/v14/.suo b/c#/protocol2.0/sync_read_write/win32/.vs/sync_read_write/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..831ac0c4ce7e6741a26bcee3a5b227f5ed68e57e GIT binary patch literal 36352 zcmeHQYm6J$bsqXD*-qm4)zo$6wJSSvv}E{RQnuvqDQHs(rlYr5-Ma=1&0OEN>Q zcDG&?LE*OPj|ORhru~x^1)4uW;UYkRqD6tG`4P1J5v6X60_~5qK+%6iA3@O|fUSPt zy>rRo@HOPV#1$`bX70?~x%ZxP&pqed#~FVA)+hhv_rLY@ziN(fPPXv}#Ch+d+qZA?_Pqc^r(uF9@P<~yuc^&w8Lf)5sco|v+92b+5cBj?jH7k5BYbL{!ag1MG7I z;^XZ9s&DRB|5tV4nf>2>eGqZg{~tMovJV2kUS+VY$vZsLo@2X{_LTdS`D}B_fAR-p9S~<0YDHC z0)zn(Kol?shymgNzW*}LuK>;h&H-Kpd=8KRBmvYvs{ONwp9fq3%mY3Tcnz=sxCnS1 za0##o_yXV!Kn}13xD0UO^>euQ79bCJ+j_o?^E+0Y=?jP#0S2ICyN^fv8mh2AR#9pb zWsVabf&IY>(wyMgO&<3mQJx2coL0b3YJnTDcZ$OL^5K3BRuOHZGGbM<`2x;5o~Ll$ zz#UoRb7R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diff --git a/c#/protocol2.0/sync_read_write/win32/sync_read_write.sln b/c#/protocol2.0/sync_read_write/win32/sync_read_write.sln new file mode 100644 index 00000000..eb555e59 --- /dev/null +++ b/c#/protocol2.0/sync_read_write/win32/sync_read_write.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 14 for Windows Desktop +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sync_read_write", "sync_read_write\sync_read_write.csproj", "{886A86F8-4CC9-4595-9EAE-AF9DE6928753}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {886A86F8-4CC9-4595-9EAE-AF9DE6928753}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {886A86F8-4CC9-4595-9EAE-AF9DE6928753}.Debug|Any CPU.Build.0 = Debug|Any CPU + {886A86F8-4CC9-4595-9EAE-AF9DE6928753}.Debug|x86.ActiveCfg = Debug|x86 + {886A86F8-4CC9-4595-9EAE-AF9DE6928753}.Debug|x86.Build.0 = Debug|x86 + {886A86F8-4CC9-4595-9EAE-AF9DE6928753}.Release|Any CPU.ActiveCfg = Release|Any CPU + {886A86F8-4CC9-4595-9EAE-AF9DE6928753}.Release|Any CPU.Build.0 = Release|Any CPU + {886A86F8-4CC9-4595-9EAE-AF9DE6928753}.Release|x86.ActiveCfg = Release|x86 + {886A86F8-4CC9-4595-9EAE-AF9DE6928753}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/c#/protocol2.0/sync_read_write/win32/sync_read_write/App.config b/c#/protocol2.0/sync_read_write/win32/sync_read_write/App.config new file mode 100644 index 00000000..8e156463 --- /dev/null +++ b/c#/protocol2.0/sync_read_write/win32/sync_read_write/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/sync_read_write/win32/sync_read_write/Properties/AssemblyInfo.cs b/c#/protocol2.0/sync_read_write/win32/sync_read_write/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..b623627e --- /dev/null +++ b/c#/protocol2.0/sync_read_write/win32/sync_read_write/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("sync_read_write")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("sync_read_write")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("886a86f8-4cc9-4595-9eae-af9de6928753")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol2.0/sync_read_write/win32/sync_read_write/SyncReadWrite.cs b/c#/protocol2.0/sync_read_write/win32/sync_read_write/SyncReadWrite.cs new file mode 100644 index 00000000..8e94b235 --- /dev/null +++ b/c#/protocol2.0/sync_read_write/win32/sync_read_write/SyncReadWrite.cs @@ -0,0 +1,254 @@ +/* +* sync_read_write.cs +* +* Created on: 2016. 5. 16. +* Author: Leon Ryu Woon Jung +*/ + +// +// ********* Sync Read and Sync Write Example ********* +// +// +// Available Dynamixel model on this example : All models using Protocol 2.0 +// This example is designed for using two Dynamixel PRO 54-200, and an USB2DYNAMIXEL. +// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below variables yourself. +// Be sure that Dynamixel PRO properties are already set as %% ID : 1 / Baudnum : 3 (Baudrate : 1000000 [1M]) +// + +using System; +using dynamixel_sdk; + +namespace sync_write +{ + class SyncWrite + { + // Control table address + public const int ADDR_PRO_TORQUE_ENABLE = 562; // Control table address is different in Dynamixel model + public const int ADDR_PRO_GOAL_POSITION = 596; + public const int ADDR_PRO_PRESENT_POSITION = 611; + + // Data Byte Length + public const int LEN_PRO_GOAL_POSITION = 4; + public const int LEN_PRO_PRESENT_POSITION = 4; + + // Protocol version + public const int PROTOCOL_VERSION = 2; // See which protocol version is used in the Dynamixel + + // Default setting + public const int DXL1_ID = 1; // Dynamixel ID: 1 + public const int DXL2_ID = 2; // Dynamixel ID: 2 + public const int BAUDRATE = 1000000; + public const string DEVICENAME = "COM8"; // Check which port is being used on your controller + // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const int TORQUE_ENABLE = 1; // Value for enabling the torque + public const int TORQUE_DISABLE = 0; // Value for disabling the torque + public const int DXL_MINIMUM_POSITION_VALUE = -150000; // Dynamixel will rotate between this value + public const int DXL_MAXIMUM_POSITION_VALUE = 150000; // and this value (note that the Dynamixel would not move when the position value is out of movable range. Check e-manual about the range of the Dynamixel you use.) + public const int DXL_MOVING_STATUS_THRESHOLD = 20; // Dynamixel moving status threshold + + public const byte ESC_ASCII_VALUE = 0x1b; + + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num = dynamixel.portHandler(DEVICENAME); + + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + // Initialize Groupsyncwrite instance + int groupwrite_num = dynamixel.groupSyncWrite(port_num, PROTOCOL_VERSION, ADDR_PRO_GOAL_POSITION, LEN_PRO_GOAL_POSITION); + + // Initialize Groupsyncread Structs for Present Position + int groupread_num = dynamixel.groupSyncRead(port_num, PROTOCOL_VERSION, ADDR_PRO_PRESENT_POSITION, LEN_PRO_PRESENT_POSITION); + + int index = 0; + int dxl_comm_result = COMM_TX_FAIL; // Communication result + bool dxl_addparam_result = false; // AddParam result + bool dxl_getdata_result = false; // GetParam result + int[] dxl_goal_position = new int[2]{ DXL_MINIMUM_POSITION_VALUE, DXL_MAXIMUM_POSITION_VALUE }; // Goal position + + byte dxl_error = 0; // Dynamixel error + Int32 dxl1_present_position = 0, dxl2_present_position = 0; // Present position + + // Open port + if (dynamixel.openPort(port_num)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port baudrate + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Enable Dynamixel#1 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL1_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("Dynamixel{0} has been successfully connected ", DXL1_ID); + } + + // Enable Dynamixel#2 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL2_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("Dynamixel{0} has been successfully connected ", DXL1_ID); + } + + // Add parameter storage for Dynamixel#1 present position value + dxl_addparam_result = dynamixel.groupSyncReadAddParam(groupread_num, DXL1_ID); + if (dxl_addparam_result != true) + { + Console.WriteLine("[ID:{0}] groupSyncRead addparam failed", DXL1_ID); + return; + } + + // Add parameter storage for Dynamixel#2 present position value + dxl_addparam_result = dynamixel.groupSyncReadAddParam(groupread_num, DXL2_ID); + if (dxl_addparam_result != true) + { + Console.WriteLine("[ID:{0}] groupSyncRead addparam failed", DXL2_ID); + return; + } + + while (true) + { + Console.WriteLine("Press any key to continue! (or press ESC to quit!)"); + if (Console.ReadKey().KeyChar == ESC_ASCII_VALUE) + break; + + // Add Dynamixel#1 goal position value to the Syncwrite storage + dxl_addparam_result = dynamixel.groupSyncWriteAddParam(groupwrite_num, DXL1_ID, (UInt32)dxl_goal_position[index], LEN_PRO_GOAL_POSITION); + if (dxl_addparam_result != true) + { + Console.WriteLine("[ID:{0}] groupSyncWrite addparam failed", DXL1_ID); + return; + } + + // Add Dynamixel#2 goal position value to the Syncwrite parameter storage + dxl_addparam_result = dynamixel.groupSyncWriteAddParam(groupwrite_num, DXL2_ID, (UInt32)dxl_goal_position[index], LEN_PRO_GOAL_POSITION); + if (dxl_addparam_result != true) + { + Console.WriteLine("[ID:{0}] groupSyncWrite addparam failed", DXL2_ID); + return; + } + + // Syncwrite goal position + dynamixel.groupSyncWriteTxPacket(groupwrite_num); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + + // Clear syncwrite parameter storage + dynamixel.groupSyncWriteClearParam(groupwrite_num); + + do + { + // Syncread present position + dynamixel.groupSyncReadTxRxPacket(groupread_num); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + + // Check if groupsyncread data of Dynamixel#1 is available + dxl_getdata_result = dynamixel.groupSyncReadIsAvailable(groupread_num, DXL1_ID, ADDR_PRO_PRESENT_POSITION, LEN_PRO_PRESENT_POSITION); + if (dxl_getdata_result != true) + { + Console.WriteLine("[ID:{0}] groupSyncRead getdata failed", DXL1_ID); + return; + } + + // Check if groupsyncread data of Dynamixel#2 is available + dxl_getdata_result = dynamixel.groupSyncReadIsAvailable(groupread_num, DXL2_ID, ADDR_PRO_PRESENT_POSITION, LEN_PRO_PRESENT_POSITION); + if (dxl_getdata_result != true) + { + Console.WriteLine("[ID:{0}] groupSyncRead getdata failed", DXL2_ID); + return; + } + + // Get Dynamixel#1 present position value + dxl1_present_position = (Int32)dynamixel.groupSyncReadGetData(groupread_num, DXL1_ID, ADDR_PRO_PRESENT_POSITION, LEN_PRO_PRESENT_POSITION); + + // Get Dynamixel#2 present position value + dxl2_present_position = (Int32)dynamixel.groupSyncReadGetData(groupread_num, DXL2_ID, ADDR_PRO_PRESENT_POSITION, LEN_PRO_PRESENT_POSITION); + + Console.WriteLine("[ID:{0}] GoalPos:{1} PresPos:{2} [ID:{3}] GoalPos:{4} PresPos:{5}", DXL1_ID, dxl_goal_position[index], dxl1_present_position, DXL2_ID, dxl_goal_position[index], dxl2_present_position); + + } while ((Math.Abs(dxl_goal_position[index] - dxl1_present_position) > DXL_MOVING_STATUS_THRESHOLD) || (Math.Abs(dxl_goal_position[index] - dxl2_present_position) > DXL_MOVING_STATUS_THRESHOLD)); + + // Change goal position + if (index == 0) + { + index = 1; + } + else + { + index = 0; + } + } + + // Disable Dynamixel#1 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL1_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Disable Dynamixel#2 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL2_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Close port + dynamixel.closePort(port_num); + + return; + } + } +} diff --git a/c#/protocol2.0/sync_read_write/win32/sync_read_write/dynamixel.cs b/c#/protocol2.0/sync_read_write/win32/sync_read_write/dynamixel.cs new file mode 100644 index 00000000..235af316 --- /dev/null +++ b/c#/protocol2.0/sync_read_write/win32/sync_read_write/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win32/output/dxl_x86_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol2.0/sync_read_write/win32/sync_read_write/sync_read_write.csproj b/c#/protocol2.0/sync_read_write/win32/sync_read_write/sync_read_write.csproj new file mode 100644 index 00000000..486c7cda --- /dev/null +++ b/c#/protocol2.0/sync_read_write/win32/sync_read_write/sync_read_write.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {886A86F8-4CC9-4595-9EAE-AF9DE6928753} + Exe + Properties + sync_read_write + sync_read_write + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/sync_read_write/win64/.vs/sync_read_write/v14/.suo b/c#/protocol2.0/sync_read_write/win64/.vs/sync_read_write/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..fe5e9259edf283b4c4bb2b7a0806d8a21ee8480e GIT binary patch literal 58880 zcmeHQTZ|jmd7hPT@}-UwCvKWJGVLg?Z7nCfFITdhEH5jmUP)VXB^fo{)hsz&QOlc$ zT=3aF>>r)Ewe)ZfDLp|9{T;&;S4DKmWY*_Q(JI4}bWX|4?kwH=DiQEUAx9dJjbaYCI|!1D0Tc=NEhT4g#}LU}|55(T zU3mHkqF4AAk@og>`Cq{K&pq_lUvB5mvHm#DFC!9%A4mKI;{Ax9MEn%u1Bkzf_-RBo z^JfqrMC7}l!|@Q}Lx=%H;(~R56!9?PV~C$eOd~S=FW^Y{GKe0kxu+y~l#xZe=OZlZ zdF1`;h^vSf5jDg$!~$Xwk^QZNxQ=)Uv5ZJOY~WZytRmJB>xd1+7Z9I7+%4eObNt`; z7e_vd@jnv){2y!M0EeOBX{7MSzd)1hH=O552iVt0#}6X%{5Bjp2Jb-RIOM&%aoo-L z$EyR!KcCCM@h{J>*KtzEKj(?u~ zWqEe`&->RSoWpEFu1CY{qa#XwNXLxSQksB#aCl@F{10K1xehCT7(e(Z_#e`8@*c#O z%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001 diff --git a/c#/protocol2.0/sync_read_write/win64/sync_read_write.sln b/c#/protocol2.0/sync_read_write/win64/sync_read_write.sln new file mode 100644 index 00000000..9d0c4cda --- /dev/null +++ b/c#/protocol2.0/sync_read_write/win64/sync_read_write.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 14 for Windows Desktop +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sync_read_write", "sync_read_write\sync_read_write.csproj", "{886A86F8-4CC9-4595-9EAE-AF9DE6928753}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {886A86F8-4CC9-4595-9EAE-AF9DE6928753}.Debug|Any CPU.ActiveCfg = Release|Any CPU + {886A86F8-4CC9-4595-9EAE-AF9DE6928753}.Debug|Any CPU.Build.0 = Release|Any CPU + {886A86F8-4CC9-4595-9EAE-AF9DE6928753}.Debug|x64.ActiveCfg = Debug|x64 + {886A86F8-4CC9-4595-9EAE-AF9DE6928753}.Debug|x64.Build.0 = Debug|x64 + {886A86F8-4CC9-4595-9EAE-AF9DE6928753}.Release|Any CPU.ActiveCfg = Release|Any CPU + {886A86F8-4CC9-4595-9EAE-AF9DE6928753}.Release|Any CPU.Build.0 = Release|Any CPU + {886A86F8-4CC9-4595-9EAE-AF9DE6928753}.Release|x64.ActiveCfg = Release|x64 + {886A86F8-4CC9-4595-9EAE-AF9DE6928753}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/c#/protocol2.0/sync_read_write/win64/sync_read_write/App.config b/c#/protocol2.0/sync_read_write/win64/sync_read_write/App.config new file mode 100644 index 00000000..8e156463 --- /dev/null +++ b/c#/protocol2.0/sync_read_write/win64/sync_read_write/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/c#/protocol2.0/sync_read_write/win64/sync_read_write/Properties/AssemblyInfo.cs b/c#/protocol2.0/sync_read_write/win64/sync_read_write/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..b623627e --- /dev/null +++ b/c#/protocol2.0/sync_read_write/win64/sync_read_write/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("sync_read_write")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("sync_read_write")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("886a86f8-4cc9-4595-9eae-af9de6928753")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol2.0/sync_read_write/win64/sync_read_write/SyncReadWrite.cs b/c#/protocol2.0/sync_read_write/win64/sync_read_write/SyncReadWrite.cs new file mode 100644 index 00000000..8e94b235 --- /dev/null +++ b/c#/protocol2.0/sync_read_write/win64/sync_read_write/SyncReadWrite.cs @@ -0,0 +1,254 @@ +/* +* sync_read_write.cs +* +* Created on: 2016. 5. 16. +* Author: Leon Ryu Woon Jung +*/ + +// +// ********* Sync Read and Sync Write Example ********* +// +// +// Available Dynamixel model on this example : All models using Protocol 2.0 +// This example is designed for using two Dynamixel PRO 54-200, and an USB2DYNAMIXEL. +// To use another Dynamixel model, such as X series, see their details in E-Manual(support.robotis.com) and edit below variables yourself. +// Be sure that Dynamixel PRO properties are already set as %% ID : 1 / Baudnum : 3 (Baudrate : 1000000 [1M]) +// + +using System; +using dynamixel_sdk; + +namespace sync_write +{ + class SyncWrite + { + // Control table address + public const int ADDR_PRO_TORQUE_ENABLE = 562; // Control table address is different in Dynamixel model + public const int ADDR_PRO_GOAL_POSITION = 596; + public const int ADDR_PRO_PRESENT_POSITION = 611; + + // Data Byte Length + public const int LEN_PRO_GOAL_POSITION = 4; + public const int LEN_PRO_PRESENT_POSITION = 4; + + // Protocol version + public const int PROTOCOL_VERSION = 2; // See which protocol version is used in the Dynamixel + + // Default setting + public const int DXL1_ID = 1; // Dynamixel ID: 1 + public const int DXL2_ID = 2; // Dynamixel ID: 2 + public const int BAUDRATE = 1000000; + public const string DEVICENAME = "COM8"; // Check which port is being used on your controller + // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const int TORQUE_ENABLE = 1; // Value for enabling the torque + public const int TORQUE_DISABLE = 0; // Value for disabling the torque + public const int DXL_MINIMUM_POSITION_VALUE = -150000; // Dynamixel will rotate between this value + public const int DXL_MAXIMUM_POSITION_VALUE = 150000; // and this value (note that the Dynamixel would not move when the position value is out of movable range. Check e-manual about the range of the Dynamixel you use.) + public const int DXL_MOVING_STATUS_THRESHOLD = 20; // Dynamixel moving status threshold + + public const byte ESC_ASCII_VALUE = 0x1b; + + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num = dynamixel.portHandler(DEVICENAME); + + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + // Initialize Groupsyncwrite instance + int groupwrite_num = dynamixel.groupSyncWrite(port_num, PROTOCOL_VERSION, ADDR_PRO_GOAL_POSITION, LEN_PRO_GOAL_POSITION); + + // Initialize Groupsyncread Structs for Present Position + int groupread_num = dynamixel.groupSyncRead(port_num, PROTOCOL_VERSION, ADDR_PRO_PRESENT_POSITION, LEN_PRO_PRESENT_POSITION); + + int index = 0; + int dxl_comm_result = COMM_TX_FAIL; // Communication result + bool dxl_addparam_result = false; // AddParam result + bool dxl_getdata_result = false; // GetParam result + int[] dxl_goal_position = new int[2]{ DXL_MINIMUM_POSITION_VALUE, DXL_MAXIMUM_POSITION_VALUE }; // Goal position + + byte dxl_error = 0; // Dynamixel error + Int32 dxl1_present_position = 0, dxl2_present_position = 0; // Present position + + // Open port + if (dynamixel.openPort(port_num)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port baudrate + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Enable Dynamixel#1 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL1_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("Dynamixel{0} has been successfully connected ", DXL1_ID); + } + + // Enable Dynamixel#2 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL2_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + else + { + Console.WriteLine("Dynamixel{0} has been successfully connected ", DXL1_ID); + } + + // Add parameter storage for Dynamixel#1 present position value + dxl_addparam_result = dynamixel.groupSyncReadAddParam(groupread_num, DXL1_ID); + if (dxl_addparam_result != true) + { + Console.WriteLine("[ID:{0}] groupSyncRead addparam failed", DXL1_ID); + return; + } + + // Add parameter storage for Dynamixel#2 present position value + dxl_addparam_result = dynamixel.groupSyncReadAddParam(groupread_num, DXL2_ID); + if (dxl_addparam_result != true) + { + Console.WriteLine("[ID:{0}] groupSyncRead addparam failed", DXL2_ID); + return; + } + + while (true) + { + Console.WriteLine("Press any key to continue! (or press ESC to quit!)"); + if (Console.ReadKey().KeyChar == ESC_ASCII_VALUE) + break; + + // Add Dynamixel#1 goal position value to the Syncwrite storage + dxl_addparam_result = dynamixel.groupSyncWriteAddParam(groupwrite_num, DXL1_ID, (UInt32)dxl_goal_position[index], LEN_PRO_GOAL_POSITION); + if (dxl_addparam_result != true) + { + Console.WriteLine("[ID:{0}] groupSyncWrite addparam failed", DXL1_ID); + return; + } + + // Add Dynamixel#2 goal position value to the Syncwrite parameter storage + dxl_addparam_result = dynamixel.groupSyncWriteAddParam(groupwrite_num, DXL2_ID, (UInt32)dxl_goal_position[index], LEN_PRO_GOAL_POSITION); + if (dxl_addparam_result != true) + { + Console.WriteLine("[ID:{0}] groupSyncWrite addparam failed", DXL2_ID); + return; + } + + // Syncwrite goal position + dynamixel.groupSyncWriteTxPacket(groupwrite_num); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + + // Clear syncwrite parameter storage + dynamixel.groupSyncWriteClearParam(groupwrite_num); + + do + { + // Syncread present position + dynamixel.groupSyncReadTxRxPacket(groupread_num); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + + // Check if groupsyncread data of Dynamixel#1 is available + dxl_getdata_result = dynamixel.groupSyncReadIsAvailable(groupread_num, DXL1_ID, ADDR_PRO_PRESENT_POSITION, LEN_PRO_PRESENT_POSITION); + if (dxl_getdata_result != true) + { + Console.WriteLine("[ID:{0}] groupSyncRead getdata failed", DXL1_ID); + return; + } + + // Check if groupsyncread data of Dynamixel#2 is available + dxl_getdata_result = dynamixel.groupSyncReadIsAvailable(groupread_num, DXL2_ID, ADDR_PRO_PRESENT_POSITION, LEN_PRO_PRESENT_POSITION); + if (dxl_getdata_result != true) + { + Console.WriteLine("[ID:{0}] groupSyncRead getdata failed", DXL2_ID); + return; + } + + // Get Dynamixel#1 present position value + dxl1_present_position = (Int32)dynamixel.groupSyncReadGetData(groupread_num, DXL1_ID, ADDR_PRO_PRESENT_POSITION, LEN_PRO_PRESENT_POSITION); + + // Get Dynamixel#2 present position value + dxl2_present_position = (Int32)dynamixel.groupSyncReadGetData(groupread_num, DXL2_ID, ADDR_PRO_PRESENT_POSITION, LEN_PRO_PRESENT_POSITION); + + Console.WriteLine("[ID:{0}] GoalPos:{1} PresPos:{2} [ID:{3}] GoalPos:{4} PresPos:{5}", DXL1_ID, dxl_goal_position[index], dxl1_present_position, DXL2_ID, dxl_goal_position[index], dxl2_present_position); + + } while ((Math.Abs(dxl_goal_position[index] - dxl1_present_position) > DXL_MOVING_STATUS_THRESHOLD) || (Math.Abs(dxl_goal_position[index] - dxl2_present_position) > DXL_MOVING_STATUS_THRESHOLD)); + + // Change goal position + if (index == 0) + { + index = 1; + } + else + { + index = 0; + } + } + + // Disable Dynamixel#1 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL1_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Disable Dynamixel#2 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION, DXL2_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION, dxl_error); + } + + // Close port + dynamixel.closePort(port_num); + + return; + } + } +} diff --git a/c#/protocol2.0/sync_read_write/win64/sync_read_write/dynamixel.cs b/c#/protocol2.0/sync_read_write/win64/sync_read_write/dynamixel.cs new file mode 100644 index 00000000..d940e04b --- /dev/null +++ b/c#/protocol2.0/sync_read_write/win64/sync_read_write/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win64/output/dxl_x64_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol2.0/sync_read_write/win64/sync_read_write/sync_read_write.csproj b/c#/protocol2.0/sync_read_write/win64/sync_read_write/sync_read_write.csproj new file mode 100644 index 00000000..9c2f4bcc --- /dev/null +++ b/c#/protocol2.0/sync_read_write/win64/sync_read_write/sync_read_write.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {886A86F8-4CC9-4595-9EAE-AF9DE6928753} + Exe + Properties + sync_read_write + sync_read_write + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/c#/protocol_combined/win32/.vs/protocol_combined/v14/.suo b/c#/protocol_combined/win32/.vs/protocol_combined/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..43c1b6f7344d2211a294180596ba3b97b64456d9 GIT binary patch literal 37888 zcmeHQYm6J$bsox=EkDx4wc|RE%4=D5op{Oey`*F*=2KcrvNq;w?ZkA}v%{g5TE0SZ zrQKRe(*i+@76p?0NCE^25}-i8KsJAL)m6mx(*L22RnWKjv-&Y z{+S1U@gM*6&mJ$*efzy4@e(lBluODYuorQcQMQKU(*62Dalmf@{D1%;2nYeffCwN8SOCNTalkPE%l9O%Cjch_9|AlDNC1+6EWld+Q+PfN zxX%`EO|u{FcXRyz*}vSkAIEr>~;YAn(a<{ARUn3vJKe(l=sN@IUjJ| zkl*rpfBX5}xIPH@HNZoF_W)$N_v8N8EzdHZbJwGQqk!K4JO&``Jr4K)fV9Z8qyb)i zxK5h?r;ukFkO6QmI0Yd8Uj#f2I0HBfI0twJa2~J(_%PsEKn}1BxB!s#lGl$S?gc;| zPy~DounLgx*Kn@^3IM$we-YPpK&k!Av^x>9m;p1GNyGR}VK((*CiUZ*#a#e@X*{o@ zW?9rc1&OGxG*KcmL?M4rlw-fLeCC_}cN9HHYYfjBQcnSL*A-w;Apxn7fhd9b(7u$2 zs(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/win32/protocol_combined/Properties/AssemblyInfo.cs b/c#/protocol_combined/win32/protocol_combined/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..155b2616 --- /dev/null +++ b/c#/protocol_combined/win32/protocol_combined/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("protocol_combined")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("protocol_combined")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("7bbebb23-23e4-4beb-8b7d-343b5218a19b")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol_combined/win32/protocol_combined/ProtocolCombined.cs b/c#/protocol_combined/win32/protocol_combined/ProtocolCombined.cs new file mode 100644 index 00000000..08bde040 --- /dev/null +++ b/c#/protocol_combined/win32/protocol_combined/ProtocolCombined.cs @@ -0,0 +1,234 @@ +/* + * protocol_combined.cs + * + * Created on: 2016. 5. 16. + * Author: Leon Ryu Woon Jung + */ + +// +// ********* Protocol Combined Example ********* +// +// +// Available Dynamixel model on this example : All models using Protocol 1.0 and 2.0 +// This example is tested with a Dynamixel MX-28, a Dynamixel PRO 54-200 and an USB2DYNAMIXEL +// Be sure that properties of Dynamixel MX and PRO are already set as %% MX - ID : 1 / Baudnum : 1 (Baudrate : 1000000) , PRO - ID : 1 / Baudnum : 3 (Baudrate : 1000000) +// + +// Be aware that: +// This example configures two different control tables (especially, if it uses Dynamixel and Dynamixel PRO). It may modify critical Dynamixel parameter on the control table, if Dynamixels have wrong ID. +// + +using System; +using dynamixel_sdk; + +namespace protocol_combined +{ + class ProtocolCombined + { + // Control table address for Dynamixel MX + public const int ADDR_MX_TORQUE_ENABLE = 24; // Control table address is different in Dynamixel model + public const int ADDR_MX_GOAL_POSITION = 30; + public const int ADDR_MX_PRESENT_POSITION = 36; + + // Control table address for Dynamixel PRO + public const int ADDR_PRO_TORQUE_ENABLE = 562; + public const int ADDR_PRO_GOAL_POSITION = 596; + public const int ADDR_PRO_PRESENT_POSITION = 611; + + // Protocol version + public const int PROTOCOL_VERSION1 = 1; // See which protocol version is used in the Dynamixel + public const int PROTOCOL_VERSION2 = 2; + + // Default setting + public const int DXL1_ID = 1; // Dynamixel ID: 1 + public const int DXL2_ID = 2; // Dynamixel ID: 2 + public const int BAUDRATE = 1000000; + public const string DEVICENAME = "COM8"; // Check which port is being used on your controller + // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const int TORQUE_ENABLE = 1; // Value for enabling the torque + public const int TORQUE_DISABLE = 0; // Value for disabling the torque + public const int DXL1_MINIMUM_POSITION_VALUE = 100; // Dynamixel will rotate between this value + public const int DXL1_MAXIMUM_POSITION_VALUE = 4000; // and this value (note that the Dynamixel would not move when the position value is out of movable range. Check e-manual about the range of the Dynamixel you use.) + public const int DXL2_MINIMUM_POSITION_VALUE = -150000; + public const int DXL2_MAXIMUM_POSITION_VALUE = 150000; + public const int DXL1_MOVING_STATUS_THRESHOLD = 10; // Dynamixel MX moving status threshold + public const int DXL2_MOVING_STATUS_THRESHOLD = 20; // Dynamixel PRO moving status threshold + + public const byte ESC_ASCII_VALUE = 0x1b; + + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num = dynamixel.portHandler(DEVICENAME); + + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + int index = 0; + int dxl_comm_result = COMM_TX_FAIL; // Communication result + UInt16[] dxl1_goal_position = new UInt16[2]{ DXL1_MINIMUM_POSITION_VALUE, DXL1_MAXIMUM_POSITION_VALUE }; // Goal position of Dynamixel MX + int[] dxl2_goal_position = new int[2]{ DXL2_MINIMUM_POSITION_VALUE, DXL2_MAXIMUM_POSITION_VALUE }; // Goal position of Dynamixel PRO + + byte dxl_error = 0; // Dynamixel error + UInt16 dxl1_present_position = 0; // Present position of Dynamixel MX + Int32 dxl2_present_position = 0; // Present position of Dynamixel PRO + + + // Open port + if (dynamixel.openPort(port_num)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port baudrate + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Enable Dynamixel#1 torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION1, DXL1_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION1)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION1, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION1)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION1, dxl_error); + } + else + { + Console.WriteLine("Dynamixel#{0} has been successfully connected ", DXL1_ID); + } + + // Enable Dynamixel#2 torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION2, DXL2_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION2)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION2, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION2)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION2, dxl_error); + } + else + { + Console.WriteLine("Dynamixel#{0} has been successfully connected ", DXL2_ID); + } + + while (true) + { + Console.WriteLine("Press any key to continue! (or press ESC to quit!)"); + if (Console.ReadKey().KeyChar == ESC_ASCII_VALUE) + break; + + // Write Dynamixel#1 goal position + dynamixel.write2ByteTxRx(port_num, PROTOCOL_VERSION1, DXL1_ID, ADDR_MX_GOAL_POSITION, dxl1_goal_position[index]); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION1)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION1, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION1)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION1, dxl_error); + } + + // Write Dynamixel#2 goal position + dynamixel.write4ByteTxRx(port_num, PROTOCOL_VERSION2, DXL2_ID, ADDR_PRO_GOAL_POSITION, (UInt32)dxl2_goal_position[index]); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION2)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION2, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION2)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION2, dxl_error); + } + + do + { + // Read Dynamixel#1 present position + dxl1_present_position = dynamixel.read2ByteTxRx(port_num, PROTOCOL_VERSION1, DXL1_ID, ADDR_MX_PRESENT_POSITION); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION1)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION1, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION1)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION1, dxl_error); + } + + // Read Dynamixel#2 present position + dxl2_present_position = (Int32)dynamixel.read4ByteTxRx(port_num, PROTOCOL_VERSION2, DXL2_ID, ADDR_PRO_PRESENT_POSITION); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION2)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION2, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION2)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION2, dxl_error); + } + + Console.WriteLine("[ID:{0}] GoalPos:{1} PresPos:{2} [ID:{3}] GoalPos:{4} PresPos:{5}", DXL1_ID, dxl1_goal_position[index], dxl1_present_position, DXL2_ID, dxl2_goal_position[index], dxl2_present_position); + + } while ((Math.Abs(dxl1_goal_position[index] - dxl1_present_position) > DXL1_MOVING_STATUS_THRESHOLD) || (Math.Abs(dxl2_goal_position[index] - dxl2_present_position) > DXL2_MOVING_STATUS_THRESHOLD)); + + // Change goal position + if (index == 0) + { + index = 1; + } + else + { + index = 0; + } + } + + // Disable Dynamixel#1 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION1, DXL1_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION1)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION1, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION1)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION1, dxl_error); + } + + // Disable Dynamixel#2 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION2, DXL2_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION2)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION2, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION2)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION2, dxl_error); + } + + // Close port + dynamixel.closePort(port_num); + + return; + } + } +} diff --git a/c#/protocol_combined/win32/protocol_combined/dynamixel.cs b/c#/protocol_combined/win32/protocol_combined/dynamixel.cs new file mode 100644 index 00000000..235af316 --- /dev/null +++ b/c#/protocol_combined/win32/protocol_combined/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win32/output/dxl_x86_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol_combined/win32/protocol_combined/protocol_combined.csproj b/c#/protocol_combined/win32/protocol_combined/protocol_combined.csproj new file mode 100644 index 00000000..0015b985 --- /dev/null +++ b/c#/protocol_combined/win32/protocol_combined/protocol_combined.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {7BBEBB23-23E4-4BEB-8B7D-343B5218A19B} + Exe + Properties + protocol_combined + protocol_combined + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/c#/protocol_combined/win64/.vs/protocol_combined/v14/.suo b/c#/protocol_combined/win64/.vs/protocol_combined/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..1be13fe7463eb299a8b61d727aa7182bd50ee15c GIT binary patch literal 49152 zcmeHQYm6J$b)J>%Sc;vvsZ-ZY6L~GGu464(zLzUma`;+F)@$uuNp?+V#U+O;YWdiZ zTxmCwS|dP#B1M7pPtu}IfdG8~fl(kpf4C2%X@0f+;}mGo!03+@C{my)()LG@U$Odq z_wtf6Lk?$#qO?nDE^#=oJNMk@x#ymH&YADM|A`-b<6EElH_Z}GYWuYh?;g}XVz@tJ zIM;qg(>{u8-uv+G-Mf6mbDa8Nf@nE8k(Yq6p1XYue+fLr{}A@1dUGR2G97O+&c3d&DdH(<`XQAEb%29o z81wiywZ9{BL>Tk<_l(~-{#C!>JWo2n{!TcEYtl51b<%alCa1C9WG3Gf2omjN#VJ_~pWz_{#xJO**}O8@!ZF#4ZCnpr>&z_~!t zf6g_e{d|8A{eKP5UI#1#Rsfd(mjR4#gtu^ybH!Bv=|9_@&&xQj0g8YUKnL*tI*!)> zmCiNq-H%WQ|FI6NZQvOtJTU_QwGW8$`z5wzl)Q+Ulw9Bql(rk8a;l@zSWxhPI*AP`6DS-SWNa{ZFI*iI?NwE&ewVmt&h@1$bM)dk*c~LYpq5 z*OLctqgSx?TQZvMKkJ|UiMSbTBN`sOfpgL}2DUM|{3d!-0X=RJ`KaQ$)#;Phab83W z_B!@CUHtcQbqx4P(>SNQ#m})!+zeTy%aYbQDPIBpI(m6SyNMh$kdF$m$}!NxD&OUQ z2>8iMlFqutPhR-TB=QK0;DB>TC5HbDxaj~m=@5>KI1A&K#q}y$X%U=n1~s&4X^{l* zb1BE<+~Q}~SL4rE-t$PGtw4Iz#E4%Kby3Gv3HY0M!df!d0`Pa+-YtHh7jqepZy?Po zFcr`W8y(yiQOaR;&i7Pc|Kt2c+zjgeup`$1U+F}+jPk6Yok{K1@V|`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pT~24)C05dG%<4e*aO;Y5=S?c;!DwAgVJ!? zfxMH%OG0mVW}Ff_69VYV78-d;c%iwD>O0YqpBx8e(6n2i6KVWtWxT8%dHkoTqrd&P zr@!^VH{XBikFPv=PW#?p{_h*VdH64K?;iW-;_v=s`!je2VOdL-Kl$AczkBH1AAP;_ zXJ0$?-wSpz`2`A6xE@w|%#pr#Nc)U=liuCrHx(*2af~Th^Dlk>2gDZuawwhjJkOH3 zrHCbb$-$hriyrc?V*tpq9?=)ssW^=FywY=JViTLv0I_S>s zeB-=l+iu(iB)ez~+!gobztf|2>dSw9`LA(&@9z0H#G90z`SRbc>$!dbxi9}k5Ao%{ zUZkYH{MVQNI(cB`%rTYn-~U6w$OaRpL;mYRGJanKsrK7)c~QHE?~nY{B=j95;O%g9M+&;K%}sn` zKuJ8IDyk%%_%eZwcK4|>E2l4|^Je94H=kd)CMBTqiwy2dX4Htb`#^y^DKC5Oy-0bL z{`9C)Ubp(wc0y{dop)1zdbhhK%YQH5|L6$u_fFT&K3sb-Pjq)juz6Lr-%C;7J~5LR zJNpqgJ7o_P*%&NCNU2nK3@2%Tkq)Y75B8|&-v)He3edOMfSQdL`wzGDFE4iP`@a%E Z(b#U%zrm`F&U#ErLrX1FC)NJr{{aQxD60Sf literal 0 HcmV?d00001 diff --git a/c#/protocol_combined/win64/protocol_combined.sln b/c#/protocol_combined/win64/protocol_combined.sln new file mode 100644 index 00000000..d2dc9e68 --- /dev/null +++ b/c#/protocol_combined/win64/protocol_combined.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 14 for Windows Desktop +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "protocol_combined", "protocol_combined\protocol_combined.csproj", "{7BBEBB23-23E4-4BEB-8B7D-343B5218A19B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7BBEBB23-23E4-4BEB-8B7D-343B5218A19B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7BBEBB23-23E4-4BEB-8B7D-343B5218A19B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7BBEBB23-23E4-4BEB-8B7D-343B5218A19B}.Debug|x64.ActiveCfg = Release|x64 + {7BBEBB23-23E4-4BEB-8B7D-343B5218A19B}.Debug|x64.Build.0 = Release|x64 + {7BBEBB23-23E4-4BEB-8B7D-343B5218A19B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7BBEBB23-23E4-4BEB-8B7D-343B5218A19B}.Release|Any CPU.Build.0 = Release|Any CPU + {7BBEBB23-23E4-4BEB-8B7D-343B5218A19B}.Release|x64.ActiveCfg = Release|x64 + {7BBEBB23-23E4-4BEB-8B7D-343B5218A19B}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/c#/protocol_combined/win64/protocol_combined/App.config b/c#/protocol_combined/win64/protocol_combined/App.config new file mode 100644 index 00000000..8e156463 --- /dev/null +++ b/c#/protocol_combined/win64/protocol_combined/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/c#/protocol_combined/win64/protocol_combined/Properties/AssemblyInfo.cs b/c#/protocol_combined/win64/protocol_combined/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..155b2616 --- /dev/null +++ b/c#/protocol_combined/win64/protocol_combined/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("protocol_combined")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("protocol_combined")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("7bbebb23-23e4-4beb-8b7d-343b5218a19b")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로 +// 지정되도록 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/c#/protocol_combined/win64/protocol_combined/ProtocolCombined.cs b/c#/protocol_combined/win64/protocol_combined/ProtocolCombined.cs new file mode 100644 index 00000000..08bde040 --- /dev/null +++ b/c#/protocol_combined/win64/protocol_combined/ProtocolCombined.cs @@ -0,0 +1,234 @@ +/* + * protocol_combined.cs + * + * Created on: 2016. 5. 16. + * Author: Leon Ryu Woon Jung + */ + +// +// ********* Protocol Combined Example ********* +// +// +// Available Dynamixel model on this example : All models using Protocol 1.0 and 2.0 +// This example is tested with a Dynamixel MX-28, a Dynamixel PRO 54-200 and an USB2DYNAMIXEL +// Be sure that properties of Dynamixel MX and PRO are already set as %% MX - ID : 1 / Baudnum : 1 (Baudrate : 1000000) , PRO - ID : 1 / Baudnum : 3 (Baudrate : 1000000) +// + +// Be aware that: +// This example configures two different control tables (especially, if it uses Dynamixel and Dynamixel PRO). It may modify critical Dynamixel parameter on the control table, if Dynamixels have wrong ID. +// + +using System; +using dynamixel_sdk; + +namespace protocol_combined +{ + class ProtocolCombined + { + // Control table address for Dynamixel MX + public const int ADDR_MX_TORQUE_ENABLE = 24; // Control table address is different in Dynamixel model + public const int ADDR_MX_GOAL_POSITION = 30; + public const int ADDR_MX_PRESENT_POSITION = 36; + + // Control table address for Dynamixel PRO + public const int ADDR_PRO_TORQUE_ENABLE = 562; + public const int ADDR_PRO_GOAL_POSITION = 596; + public const int ADDR_PRO_PRESENT_POSITION = 611; + + // Protocol version + public const int PROTOCOL_VERSION1 = 1; // See which protocol version is used in the Dynamixel + public const int PROTOCOL_VERSION2 = 2; + + // Default setting + public const int DXL1_ID = 1; // Dynamixel ID: 1 + public const int DXL2_ID = 2; // Dynamixel ID: 2 + public const int BAUDRATE = 1000000; + public const string DEVICENAME = "COM8"; // Check which port is being used on your controller + // ex) "COM1" Linux: "/dev/ttyUSB0" + + public const int TORQUE_ENABLE = 1; // Value for enabling the torque + public const int TORQUE_DISABLE = 0; // Value for disabling the torque + public const int DXL1_MINIMUM_POSITION_VALUE = 100; // Dynamixel will rotate between this value + public const int DXL1_MAXIMUM_POSITION_VALUE = 4000; // and this value (note that the Dynamixel would not move when the position value is out of movable range. Check e-manual about the range of the Dynamixel you use.) + public const int DXL2_MINIMUM_POSITION_VALUE = -150000; + public const int DXL2_MAXIMUM_POSITION_VALUE = 150000; + public const int DXL1_MOVING_STATUS_THRESHOLD = 10; // Dynamixel MX moving status threshold + public const int DXL2_MOVING_STATUS_THRESHOLD = 20; // Dynamixel PRO moving status threshold + + public const byte ESC_ASCII_VALUE = 0x1b; + + public const int COMM_SUCCESS = 0; // Communication Success result value + public const int COMM_TX_FAIL = -1001; // Communication Tx Failed + + static void Main(string[] args) + { + // Initialize PortHandler Structs + // Set the port path + // Get methods and members of PortHandlerLinux or PortHandlerWindows + int port_num = dynamixel.portHandler(DEVICENAME); + + // Initialize PacketHandler Structs + dynamixel.packetHandler(); + + int index = 0; + int dxl_comm_result = COMM_TX_FAIL; // Communication result + UInt16[] dxl1_goal_position = new UInt16[2]{ DXL1_MINIMUM_POSITION_VALUE, DXL1_MAXIMUM_POSITION_VALUE }; // Goal position of Dynamixel MX + int[] dxl2_goal_position = new int[2]{ DXL2_MINIMUM_POSITION_VALUE, DXL2_MAXIMUM_POSITION_VALUE }; // Goal position of Dynamixel PRO + + byte dxl_error = 0; // Dynamixel error + UInt16 dxl1_present_position = 0; // Present position of Dynamixel MX + Int32 dxl2_present_position = 0; // Present position of Dynamixel PRO + + + // Open port + if (dynamixel.openPort(port_num)) + { + Console.WriteLine("Succeeded to open the port!"); + } + else + { + Console.WriteLine("Failed to open the port!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Set port baudrate + if (dynamixel.setBaudRate(port_num, BAUDRATE)) + { + Console.WriteLine("Succeeded to change the baudrate!"); + } + else + { + Console.WriteLine("Failed to change the baudrate!"); + Console.WriteLine("Press any key to terminate..."); + Console.ReadKey(); + return; + } + + // Enable Dynamixel#1 torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION1, DXL1_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION1)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION1, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION1)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION1, dxl_error); + } + else + { + Console.WriteLine("Dynamixel#{0} has been successfully connected ", DXL1_ID); + } + + // Enable Dynamixel#2 torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION2, DXL2_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_ENABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION2)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION2, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION2)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION2, dxl_error); + } + else + { + Console.WriteLine("Dynamixel#{0} has been successfully connected ", DXL2_ID); + } + + while (true) + { + Console.WriteLine("Press any key to continue! (or press ESC to quit!)"); + if (Console.ReadKey().KeyChar == ESC_ASCII_VALUE) + break; + + // Write Dynamixel#1 goal position + dynamixel.write2ByteTxRx(port_num, PROTOCOL_VERSION1, DXL1_ID, ADDR_MX_GOAL_POSITION, dxl1_goal_position[index]); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION1)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION1, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION1)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION1, dxl_error); + } + + // Write Dynamixel#2 goal position + dynamixel.write4ByteTxRx(port_num, PROTOCOL_VERSION2, DXL2_ID, ADDR_PRO_GOAL_POSITION, (UInt32)dxl2_goal_position[index]); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION2)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION2, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION2)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION2, dxl_error); + } + + do + { + // Read Dynamixel#1 present position + dxl1_present_position = dynamixel.read2ByteTxRx(port_num, PROTOCOL_VERSION1, DXL1_ID, ADDR_MX_PRESENT_POSITION); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION1)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION1, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION1)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION1, dxl_error); + } + + // Read Dynamixel#2 present position + dxl2_present_position = (Int32)dynamixel.read4ByteTxRx(port_num, PROTOCOL_VERSION2, DXL2_ID, ADDR_PRO_PRESENT_POSITION); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION2)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION2, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION2)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION2, dxl_error); + } + + Console.WriteLine("[ID:{0}] GoalPos:{1} PresPos:{2} [ID:{3}] GoalPos:{4} PresPos:{5}", DXL1_ID, dxl1_goal_position[index], dxl1_present_position, DXL2_ID, dxl2_goal_position[index], dxl2_present_position); + + } while ((Math.Abs(dxl1_goal_position[index] - dxl1_present_position) > DXL1_MOVING_STATUS_THRESHOLD) || (Math.Abs(dxl2_goal_position[index] - dxl2_present_position) > DXL2_MOVING_STATUS_THRESHOLD)); + + // Change goal position + if (index == 0) + { + index = 1; + } + else + { + index = 0; + } + } + + // Disable Dynamixel#1 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION1, DXL1_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION1)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION1, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION1)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION1, dxl_error); + } + + // Disable Dynamixel#2 Torque + dynamixel.write1ByteTxRx(port_num, PROTOCOL_VERSION2, DXL2_ID, ADDR_PRO_TORQUE_ENABLE, TORQUE_DISABLE); + if ((dxl_comm_result = dynamixel.getLastTxRxResult(port_num, PROTOCOL_VERSION2)) != COMM_SUCCESS) + { + dynamixel.printTxRxResult(PROTOCOL_VERSION2, dxl_comm_result); + } + else if ((dxl_error = dynamixel.getLastRxPacketError(port_num, PROTOCOL_VERSION2)) != 0) + { + dynamixel.printRxPacketError(PROTOCOL_VERSION2, dxl_error); + } + + // Close port + dynamixel.closePort(port_num); + + return; + } + } +} diff --git a/c#/protocol_combined/win64/protocol_combined/dynamixel.cs b/c#/protocol_combined/win64/protocol_combined/dynamixel.cs new file mode 100644 index 00000000..d940e04b --- /dev/null +++ b/c#/protocol_combined/win64/protocol_combined/dynamixel.cs @@ -0,0 +1,229 @@ +using System; +using System.Runtime.InteropServices; + +namespace dynamixel_sdk +{ + class dynamixel + { + const string dll_path = "../../../c/build/win64/output/dxl_x64_c.dll"; + + #region PortHandler + [DllImport(dll_path)] + public static extern int portHandler(string port_name); + + [DllImport(dll_path)] + public static extern bool openPort(int port_num); + [DllImport(dll_path)] + public static extern void closePort(int port_num); + [DllImport(dll_path)] + public static extern void clearPort(int port_num); + + [DllImport(dll_path)] + public static extern void setPortName(int port_num, string port_name); + [DllImport(dll_path)] + public static extern string getPortName(int port_num); + + [DllImport(dll_path)] + public static extern bool setBaudRate(int port_num, int baudrate); + [DllImport(dll_path)] + public static extern int getBaudRate(int port_num); + #endregion + + #region PacketHandler + [DllImport(dll_path)] + public static extern void packetHandler(); + + [DllImport(dll_path)] + public static extern void printTxRxResult(int protocol_version, int result); + [DllImport(dll_path)] + public static extern void printRxPacketError(int protocol_version, byte error); + + [DllImport(dll_path)] + public static extern int getLastTxRxResult(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte getLastRxPacketError(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void setDataWrite(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos, UInt32 data); + [DllImport(dll_path)] + public static extern UInt32 getDataRead(int port_num, int protocol_version, UInt16 data_length, UInt16 data_pos); + + [DllImport(dll_path)] + public static extern void txPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void rxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void txRxPacket(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern void ping(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern UInt16 pingGetModelNum(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void broadcastPing(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern bool getBroadcastPingResult(int port_num, int protocol_version, int id); + + [DllImport(dll_path)] + public static extern void reboot(int port_num, int protocol_version, byte id); + + [DllImport(dll_path)] + public static extern void factoryReset(int port_num, int protocol_version, byte id, byte option); + + [DllImport(dll_path)] + public static extern void readTx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void readRx(int port_num, int protocol_version, UInt16 length); + [DllImport(dll_path)] + public static extern void readTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void read1ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern byte read1ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern byte read1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read2ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt16 read2ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt16 read2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void read4ByteTx(int port_num, int protocol_version, byte id, UInt16 address); + [DllImport(dll_path)] + public static extern UInt32 read4ByteRx(int port_num, int protocol_version); + [DllImport(dll_path)] + public static extern UInt32 read4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address); + + [DllImport(dll_path)] + public static extern void writeTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void writeTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void write1ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, byte data); + [DllImport(dll_path)] + public static extern void write1ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, byte data); + + [DllImport(dll_path)] + public static extern void write2ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + [DllImport(dll_path)] + public static extern void write2ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 data); + + [DllImport(dll_path)] + public static extern void write4ByteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + [DllImport(dll_path)] + public static extern void write4ByteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt32 data); + + [DllImport(dll_path)] + public static extern void regWriteTxOnly(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + [DllImport(dll_path)] + public static extern void regWriteTxRx(int port_num, int protocol_version, byte id, UInt16 address, UInt16 length); + + [DllImport(dll_path)] + public static extern void syncReadTx(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + // syncReadRx -> GroupSyncRead + // syncReadTxRx -> GroupSyncRead + + [DllImport(dll_path)] + public static extern void syncWriteTxOnly(int port_num, int protocol_version, UInt16 start_address, UInt16 data_length, UInt16 param_length); + + [DllImport(dll_path)] + public static extern void bulkReadTx(int port_num, int protocol_version, UInt16 param_length); + // bulkReadRx -> GroupBulkRead + // bulkReadTxRx -> GroupBulkRead + + [DllImport(dll_path)] + public static extern void bulkWriteTxOnly(int port_num, int protocol_version, UInt16 param_length); + #endregion + + #region GroupBulkRead + [DllImport(dll_path)] + public static extern int groupBulkRead(int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkReadAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupBulkReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupBulkReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupBulkReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupBulkReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupBulkReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupBulkWrite + [DllImport(dll_path)] + public static extern int groupBulkWrite (int port_num, int protocol_version); + + [DllImport(dll_path)] + public static extern bool groupBulkWriteAddParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length); + [DllImport(dll_path)] + public static extern void groupBulkWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupBulkWriteChangeParam (int group_num, byte id, UInt16 start_address, UInt16 data_length, UInt32 data, UInt16 input_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupBulkWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupBulkWriteTxPacket (int group_num); + #endregion + + #region GroupSyncRead + [DllImport(dll_path)] + public static extern int groupSyncRead (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncReadAddParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern void groupSyncReadClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncReadTxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadRxPacket (int group_num); + [DllImport(dll_path)] + public static extern void groupSyncReadTxRxPacket (int group_num); + + [DllImport(dll_path)] + public static extern bool groupSyncReadIsAvailable (int group_num, byte id, UInt16 address, UInt16 data_length); + [DllImport(dll_path)] + public static extern UInt32 groupSyncReadGetData (int group_num, byte id, UInt16 address, UInt16 data_length); + #endregion + + #region GroupSyncWrite + [DllImport(dll_path)] + public static extern int groupSyncWrite (int port_num, int protocol_version, UInt16 start_address, UInt16 data_length); + + [DllImport(dll_path)] + public static extern bool groupSyncWriteAddParam(int group_num, byte id, UInt32 data, UInt16 data_length); + [DllImport(dll_path)] + public static extern void groupSyncWriteRemoveParam (int group_num, byte id); + [DllImport(dll_path)] + public static extern bool groupSyncWriteChangeParam (int group_num, byte id, UInt32 data, UInt16 data_length, UInt16 data_pos); + [DllImport(dll_path)] + public static extern void groupSyncWriteClearParam (int group_num); + + [DllImport(dll_path)] + public static extern void groupSyncWriteTxPacket(int group_num); + #endregion + } +} diff --git a/c#/protocol_combined/win64/protocol_combined/protocol_combined.csproj b/c#/protocol_combined/win64/protocol_combined/protocol_combined.csproj new file mode 100644 index 00000000..a78b4d0e --- /dev/null +++ b/c#/protocol_combined/win64/protocol_combined/protocol_combined.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {7BBEBB23-23E4-4BEB-8B7D-343B5218A19B} + Exe + Properties + protocol_combined + protocol_combined + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file