Skip to content

Repository files navigation

Flexiv DDK CSharp

License

Flexiv DDK CSharp provides .NET bindings for Flexiv DDK 1.3. Its structure follows the same approach used by flexiv_rdk_csharp: a small C++ shared library converts the C++ API to a stable C ABI, and the C# library calls that ABI with P/Invoke.

The binding mirrors the complete DDK 1.3 Client API: joint and Cartesian states, joint and Cartesian commands, plan information, primitive states, server time, system status, digital inputs, and the complete manipulability data structure.

Compatibility

Layer Supported system Requirement
Native wrapper Windows 10+, x64 MSVC v14.2+ and Flexiv DDK 1.3
Native wrapper Ubuntu 22.04+, x64/aarch64 GCC 11.4+ and Flexiv DDK 1.3
Managed library Platforms supported by the native DDK net5.0 or net8.0

csharp/csharp.csproj produces the .NET 5-compatible build. csharp/build.csproj uses the same source files and targets .NET 8 for development on a machine that only has the .NET 8 SDK.

Project Structure

  • cpp_wrapper/: C ABI wrapper around flexiv::ddk::Client.
  • csharp/csharp.csproj: .NET 5 project, matching the layout of flexiv_rdk_csharp.
  • csharp/build.csproj: .NET 8 build project over the same source tree.
  • csharp/csharp.sln: Visual Studio solution for the .NET 5 project.
  • csharp/Program.cs: shared example entry point.
  • csharp/FlexivDdk/: managed API and strongly typed data models.
  • csharp/Examples/: C# equivalents of all nine upstream DDK examples.
  • tests/FlexivDdk.Tests/: offline tests for the managed API, data models, and native JSON decoding.
  • released_dll/: output location for the native wrapper and its runtime dependencies.
  • third_party/: script that builds and installs the official Flexiv DDK dependency.

Build the Managed Projects

The managed projects do not require a robot or the native DLL at compile time:

dotnet build csharp\csharp.csproj -c Release
dotnet build csharp\build.csproj -c Release
dotnet run --project tests\FlexivDdk.Tests\FlexivDdk.Tests.csproj -c Release

Use build.csproj for local development with the installed .NET 8 SDK. Build csharp.csproj when producing the assembly intended for a .NET 5 application.

Build the Native Wrapper

Install Visual Studio 2019 or later with Desktop development with C++, CMake, and Git Bash. The full script downloads the DDK 1.3 source from GitHub into third_party/cloned/flexiv_ddk, builds its dependencies, builds this wrapper, and stages all DLLs in released_dll:

On Windows, run the following commands from Git Bash:

bash build_and_install_flexiv_ddk_dll.sh

To use another DDK 1.3 checkout, pass it as the first argument:

bash build_and_install_flexiv_ddk_dll.sh /path/to/flexiv_ddk

The native library is intentionally not committed as an unverifiable generated binary. After it is built, the C# projects automatically copy files from released_dll to their output directory. On Windows, Flexiv's official DDK 1.3 static library was compiled against the shared spdlog and Zenoh C runtimes, so the deployable set contains flexiv_ddk_csharp.dll, spdlog.dll, and zenohc.dll. These dependencies cannot be removed without a DDK library built by Flexiv for static third-party linkage.

Run an Example

List the examples:

dotnet run --project csharp\build.csproj -- --help

Run one after the native wrapper has been built:

dotnet run --project csharp\build.csproj -c Release -- `
  basics1_display_joint_states Rizon4s-123456

Press Ctrl+C to stop a polling example.

Use the API

Reference the assembly produced by csharp.csproj (for .NET 5+) or build.csproj (for .NET 8), ensure the native files are beside the application, then create a client:

using FlexivDdk;

using var client = new Client("Rizon4s-123456", ["10.42.0.1"]);
if (client.Connected())
    Console.WriteLine(client.JointStates());

Idiomatic PascalCase methods are the primary API. Lowercase aliases such as joint_states() and plan_info() preserve the exact C++ and Python DDK method names. The constructor exposes the DDK 1.3 network-interface whitelist and intentionally has no verbose argument.

Interop Design

STL containers and C++ exceptions never cross the DLL boundary. The native wrapper catches every exception, returns UTF-8 error text, and serializes each original DDK data structure to JSON. C# owns the returned buffer only long enough to deserialize it and always releases it in a finally block. Client uses SafeHandle, so native lifetime remains correct during P/Invoke calls and deterministic with using/Dispose.

License

Apache License 2.0. See LICENSE.

About

C# bindings for Flexiv DDK, providing a lightweight P/Invoke wrapper, Windows x64 support, and examples aligned with the native C++ API.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages