Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Move library resolver to driver
Browse files Browse the repository at this point in the history
  • Loading branch information
dmweis committed Nov 15, 2017
1 parent d834a37 commit 2278842
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 107 deletions.
34 changes: 34 additions & 0 deletions Quadruped.Driver/dynamixel_sdk/dynamixel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
/* Author: Ryu Woon Jung (Leon) */

using System;
using System.IO;
using System.Runtime.InteropServices;

namespace Quadruped.Driver.dynamixel_sdk
Expand All @@ -39,6 +40,39 @@ class dynamixel
{
const string dll_path = "dxl_lib.ds";

static dynamixel()
{
var assemblyPath = AppDomain.CurrentDomain.BaseDirectory;
var architecture = RuntimeInformation.OSArchitecture;
if (architecture == Architecture.Arm || architecture == Architecture.Arm64)
{
const string newFileName = "libdxl_sbc_c.so";
File.Copy(Path.Combine(assemblyPath, newFileName), Path.Combine(assemblyPath, dll_path), true);
}
else if (architecture == Architecture.X64)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
const string newFileName = "dxl_x64_c.dll";
File.Copy(Path.Combine(assemblyPath, newFileName), Path.Combine(assemblyPath, dll_path), true);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
const string newFileName = "libdxl_x64_c.so";
File.Copy(Path.Combine(assemblyPath, newFileName), Path.Combine(assemblyPath, dll_path), true);
}
else
{
throw new NotSupportedException("This OS is not supported!");
}
}
else
{
throw new NotSupportedException("This architecture is not supported!");
}
}


#region PortHandler
[DllImport(dll_path)]
public static extern int portHandler(string port_name);
Expand Down
55 changes: 0 additions & 55 deletions Quadruped.NetCore.TestConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,16 @@
using System.IO;
using System.Numerics;
using System.Reflection;
using System.Runtime.InteropServices;
using Newtonsoft.Json;
using Quadruped.Driver;

namespace Quadruped.NetCore.TestConsole
{
class Program
{
private const string DxlLib = "dxl_lib.ds";

private static void SaveCorrectDxlLibrary()
{
// This is an extremly ugly way to load the correct library for dynamixel
// TODO: figure out a better way
Console.ForegroundColor = ConsoleColor.Yellow;
var architecture = RuntimeInformation.OSArchitecture;
Console.WriteLine($"Current architecture {architecture}");
if (architecture == Architecture.Arm || architecture == Architecture.Arm64)
{
const string newFileName = "libdxl_sbc_c.so";
Console.WriteLine($"Saving library as {newFileName}");
File.Copy(newFileName, DxlLib, true);
}
else if (architecture == Architecture.X64)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Console.WriteLine($"Current OS is {OSPlatform.Windows}");
const string newFileName = "dxl_x64_c.dll";
Console.WriteLine($"Saving library as {newFileName}");
File.Copy(newFileName, DxlLib, true);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Console.WriteLine($"Current OS is {OSPlatform.Linux}");
const string newFileName = "libdxl_x64_c.so";
Console.WriteLine($"Saving library as {newFileName}");
File.Copy(newFileName, DxlLib, true);
}
else
{
throw new NotSupportedException("This OS is not supported!");
}
}
else
{
throw new NotSupportedException("This architecture is not supported!");
}
Console.ResetColor();
}
private static void DeleteDxlLibrary()
{
// This is an extremly ugly way to load the correct library for dynamixel
// TODO: figure out a better way
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine($"Deleting {DxlLib}");
File.Delete(DxlLib);
Console.ResetColor();
}

static void Main(string[] args)
{
Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location));
SaveCorrectDxlLibrary();
Console.WriteLine("Starting");
using (var driver = new DynamixelDriver(args.Length > 0 ? args[0] : "COM4"))
using (var quadruped = new QuadrupedIkDriver(driver))
Expand Down Expand Up @@ -132,7 +78,6 @@ static void Main(string[] args)
quadruped.DisableMotors();
}
}
DeleteDxlLibrary();
Console.WriteLine("Done");
}

Expand Down
52 changes: 0 additions & 52 deletions Quadruped.WebInterface/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ public class Program
{
public static void Main(string[] args)
{
try
{
SaveCorrectDxlLibrary();
}
catch (Exception )
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Failed to load library!!!");
Console.ResetColor();
}
BuildWebHost(args).Run();
}

Expand All @@ -36,47 +26,5 @@ public static IWebHost BuildWebHost(string[] args) =>
.UseUrls("http://0.0.0.0:50093/")
.Build();

private const string DxlLib = "dxl_lib.ds";

private static void SaveCorrectDxlLibrary()
{
// This is an extremly ugly way to load the correct library for dynamixel
// TODO: figure out a better way
Console.ForegroundColor = ConsoleColor.Yellow;
var architecture = RuntimeInformation.OSArchitecture;
Console.WriteLine($"Current architecture {architecture}");
if (architecture == Architecture.Arm || architecture == Architecture.Arm64)
{
const string newFileName = "libdxl_sbc_c.so";
Console.WriteLine($"Saving library as {newFileName}");
File.Copy(newFileName, DxlLib, true);
}
else if (architecture == Architecture.X64)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Console.WriteLine($"Current OS is {OSPlatform.Windows}");
const string newFileName = "dxl_x64_c.dll";
Console.WriteLine($"Saving library as {newFileName}");
File.Copy(newFileName, DxlLib, true);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Console.WriteLine($"Current OS is {OSPlatform.Linux}");
const string newFileName = "libdxl_x64_c.so";
Console.WriteLine($"Saving library as {newFileName}");
File.Copy(newFileName, DxlLib, true);
}
else
{
throw new NotSupportedException("This OS is not supported!");
}
}
else
{
throw new NotSupportedException("This architecture is not supported!");
}
Console.ResetColor();
}
}
}

0 comments on commit 2278842

Please sign in to comment.