From 4fb0ecd7c79fb3fd38e4cc0584fd3023e4ade489 Mon Sep 17 00:00:00 2001 From: rgarofalo Date: Tue, 24 Jul 2018 16:05:53 +0200 Subject: [PATCH 1/7] add target .NET Framework 4.6.2 added the possibility to compile the ros.net library for framework 4.6.2 --- .gitignore | 2 ++ Samples/Talker/Program.cs | 2 +- Samples/Talker/Talker.csproj | 13 +++++++++- .../TypeRegistryBase.cs | 16 +++++++++++- .../Uml.Robotics.Ros.MessageBase.csproj | 10 +++++++- .../Uml.Robotics.Ros.Transforms.csproj | 12 +++++++-- Uml.Robotics.Ros/ActionLib/ActionClient.cs | 7 ++++++ Uml.Robotics.Ros/ConnectionManager.cs | 2 +- Uml.Robotics.Ros/RemappingHelper.cs | 15 +++++++++-- Uml.Robotics.Ros/Subscription.cs | 4 +++ Uml.Robotics.Ros/TopicManager.cs | 8 ++++-- Uml.Robotics.Ros/TransportPublisherLink.cs | 2 +- Uml.Robotics.Ros/Uml.Robotics.Ros.csproj | 15 +++++++++-- Uml.Robotics.Ros/_Init.cs | 25 +++++++++++++++++-- .../Uml.Robotics.XmlRpc.csproj | 11 +++++++- Uml.Robotics.XmlRpc/XmlRpcClient.cs | 9 ++++++- 16 files changed, 135 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 2c814eec..9682bce8 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,5 @@ Release/*.pdb msg_gen/msg_gen.exe *.Debug.cachefile XmlRpc_Wrapper/XmlRpcWin32.instr.pdb + +\.vs/ diff --git a/Samples/Talker/Program.cs b/Samples/Talker/Program.cs index 1b8be01c..473299e4 100644 --- a/Samples/Talker/Program.cs +++ b/Samples/Talker/Program.cs @@ -24,7 +24,7 @@ private static void Main(string[] args) ROS.Info()("Publishing a chatter message: \"Blah blah blah " + count + "\""); String pow = new String("Blah blah blah " + (count++)); - Talker.publish(pow); + Talker.Publish(pow); spinner.SpinOnce(); Thread.Sleep(1000); } diff --git a/Samples/Talker/Talker.csproj b/Samples/Talker/Talker.csproj index 555fd32d..241695ce 100644 --- a/Samples/Talker/Talker.csproj +++ b/Samples/Talker/Talker.csproj @@ -5,17 +5,28 @@ - netcoreapp2.1 + netcoreapp2.1;net462 + true exe + + NETCORE + + + + NET462 + + + + diff --git a/Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs b/Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs index e0d4e963..c47873d8 100644 --- a/Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs +++ b/Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs @@ -7,6 +7,9 @@ using System.Runtime.Loader; using System.Text; +#if NETCORE +using System.Runtime.Loader; +#endif namespace Uml.Robotics.Ros { public class TypeRegistryBase @@ -44,14 +47,25 @@ public static IEnumerable GetCandidateAssemblies(params string[] tagAs if (tagAssemblies.Length == 0) throw new ArgumentException("At least one tag assembly name must be specified.", nameof(tagAssemblies)); + var referenceAssemblies = new HashSet(tagAssemblies, StringComparer.OrdinalIgnoreCase); + +#if NETCORE var context = DependencyContext.Load(Assembly.GetEntryAssembly()); var loadContext = AssemblyLoadContext.Default; - var referenceAssemblies = new HashSet(tagAssemblies, StringComparer.OrdinalIgnoreCase); return context.RuntimeLibraries .Where(x => x.Dependencies.Any(d => referenceAssemblies.Contains(d.Name))) .SelectMany(x => x.GetDefaultAssemblyNames(context)) .Select(x => loadContext.LoadFromAssemblyName(x)); +#else + //var entryAssembly = Assembly.Load(new AssemblyName(tagAssemblies[0])); + var context = DependencyContext.Load(Assembly.GetEntryAssembly()); + + return context.RuntimeLibraries + .Where(x => x.Dependencies.Any(d => referenceAssemblies.Contains(d.Name))) + .SelectMany(x => x.GetDefaultAssemblyNames(context)).Select(Assembly.Load); +#endif + } } } diff --git a/Uml.Robotics.Ros.MessageBase/Uml.Robotics.Ros.MessageBase.csproj b/Uml.Robotics.Ros.MessageBase/Uml.Robotics.Ros.MessageBase.csproj index 7a163320..5547676f 100644 --- a/Uml.Robotics.Ros.MessageBase/Uml.Robotics.Ros.MessageBase.csproj +++ b/Uml.Robotics.Ros.MessageBase/Uml.Robotics.Ros.MessageBase.csproj @@ -1,9 +1,17 @@  - netcoreapp2.1 + netcoreapp2.1;net462 + true + + NETCORE + + + + NET462 + diff --git a/Uml.Robotics.Ros.Transforms/Uml.Robotics.Ros.Transforms.csproj b/Uml.Robotics.Ros.Transforms/Uml.Robotics.Ros.Transforms.csproj index 4e757c30..1938fea3 100644 --- a/Uml.Robotics.Ros.Transforms/Uml.Robotics.Ros.Transforms.csproj +++ b/Uml.Robotics.Ros.Transforms/Uml.Robotics.Ros.Transforms.csproj @@ -1,7 +1,15 @@  - - netcoreapp2.1 + netcoreapp2.1;net462 + true + + + + NETCORE + + + + NET462 diff --git a/Uml.Robotics.Ros/ActionLib/ActionClient.cs b/Uml.Robotics.Ros/ActionLib/ActionClient.cs index 617f6709..1b5004dd 100644 --- a/Uml.Robotics.Ros/ActionLib/ActionClient.cs +++ b/Uml.Robotics.Ros/ActionLib/ActionClient.cs @@ -563,8 +563,15 @@ private void OnStatusMessage(GoalStatusArray statusArray) // Loop over all goal handles and update their state, mark goal handles that are done for deletion var completedGoals = new List(); +#if NETCORE foreach (var (key, value) in goalHandlesReferenceCopy) { +#else + foreach(KeyValuePair> kv in goalHandlesReferenceCopy) + { + var value = kv.Value; + var key= kv.Key; +#endif if (value.LatestResultAction == null || ROS.ToDateTime(value.LatestResultAction.Header.stamp) < ROS.ToDateTime(timestamp)) { var goalStatus = FindGoalInStatusList(statusArray, key); diff --git a/Uml.Robotics.Ros/ConnectionManager.cs b/Uml.Robotics.Ros/ConnectionManager.cs index 0cc8e7c1..de3225a8 100644 --- a/Uml.Robotics.Ros/ConnectionManager.cs +++ b/Uml.Robotics.Ros/ConnectionManager.cs @@ -125,7 +125,7 @@ public async Task CheckAndAccept() { cancel.ThrowIfCancellationRequested(); - var tcpClient = await listener.AcceptTcpClientAsync(); + var tcpClient = await listener.AcceptTcpClientAsync().ConfigureAwait(false); var connection = new Connection(tcpClient); AddConnection(connection); var t = StartReadHeader(connection); diff --git a/Uml.Robotics.Ros/RemappingHelper.cs b/Uml.Robotics.Ros/RemappingHelper.cs index d4adcecd..60b8af39 100644 --- a/Uml.Robotics.Ros/RemappingHelper.cs +++ b/Uml.Robotics.Ros/RemappingHelper.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Collections; namespace Uml.Robotics.Ros { @@ -41,13 +42,23 @@ public static bool GetRemappings(ref string[] args, out IDictionary NegotiateConnection(string xmlRpcUri) PendingConnectionDone(conn, requestTopicTask); +#if NETCORE return requestTopicTask.IsCompletedSuccessfully; +#else + return requestTopicTask.IsCompleted; +#endif } private void PendingConnectionDone(PendingConnection conn, Task callTask) diff --git a/Uml.Robotics.Ros/TopicManager.cs b/Uml.Robotics.Ros/TopicManager.cs index 2dc111d7..22056d09 100644 --- a/Uml.Robotics.Ros/TopicManager.cs +++ b/Uml.Robotics.Ros/TopicManager.cs @@ -701,10 +701,14 @@ private void PublisherUpdateCallback(XmlRpcValue parm, XmlRpcValue result) var pubUpdateTask = PubUpdate(topic, publicationUris); pubUpdateTask.WhenCompleted().WhenCompleted().Wait(); +#if NETCORE + if (pubUpdateTask.IsCompletedSuccessfully && pubUpdateTask.Result) - { +#else + if (pubUpdateTask.IsCompleted && pubUpdateTask.Result) + +#endif XmlRpcManager.ResponseInt(1, "", 0)(result); - } else { const string error = "Unknown error while handling XmlRpc call to pubUpdate"; diff --git a/Uml.Robotics.Ros/TransportPublisherLink.cs b/Uml.Robotics.Ros/TransportPublisherLink.cs index cb17dadb..4425f4ac 100644 --- a/Uml.Robotics.Ros/TransportPublisherLink.cs +++ b/Uml.Robotics.Ros/TransportPublisherLink.cs @@ -137,7 +137,7 @@ public async Task RunReceiveLoopAsync() logger.LogError(e, e.Message); - retryDelay = retryDelay * 2; + retryDelay = retryDelay + retryDelay; if (retryDelay > MAX_RETRY_DELAY) { retryDelay = MAX_RETRY_DELAY; diff --git a/Uml.Robotics.Ros/Uml.Robotics.Ros.csproj b/Uml.Robotics.Ros/Uml.Robotics.Ros.csproj index 392bed00..a39bdc00 100644 --- a/Uml.Robotics.Ros/Uml.Robotics.Ros.csproj +++ b/Uml.Robotics.Ros/Uml.Robotics.Ros.csproj @@ -1,12 +1,23 @@  - - netcoreapp2.1 + + netcoreapp2.1;net462 + true + + + + NETCORE + + + + NET462 + PackageReference + diff --git a/Uml.Robotics.Ros/_Init.cs b/Uml.Robotics.Ros/_Init.cs index 65bda945..bdf602a6 100644 --- a/Uml.Robotics.Ros/_Init.cs +++ b/Uml.Robotics.Ros/_Init.cs @@ -5,9 +5,12 @@ using System.Reflection; using System.Runtime.CompilerServices; using System.Threading; -using System.Runtime.Loader; +#if NETCORE +using System.Runtime.Loader; +#endif using Microsoft.Extensions.Logging; + using Uml.Robotics.XmlRpc; using std_msgs = Messages.std_msgs; using System.IO; @@ -286,11 +289,20 @@ public static void Init(IDictionary remappingArgs, string name, if (!atExitRegistered) { atExitRegistered = true; +#if NETCORE AssemblyLoadContext.Default.Unloading += (AssemblyLoadContext obj) => { Shutdown(); WaitForShutdown(); }; +#else + Process.GetCurrentProcess().EnableRaisingEvents = true; + Process.GetCurrentProcess().Exited += (o, args) => + { + _shutdown(); + WaitForShutdown(); + }; +#endif Console.CancelKeyPress += (o, args) => { @@ -317,6 +329,7 @@ public static void Init(IDictionary remappingArgs, string name, // Load RosMessages from MessageBase assembly msgRegistry.ParseAssemblyAndRegisterRosMessages(typeof(RosMessage).GetTypeInfo().Assembly); +#if NETCORE // Load RosMessages from all assemblies that depend on MessageBase var candidates = MessageTypeRegistry.GetCandidateAssemblies("Uml.Robotics.Ros.MessageBase"); foreach (var assembly in candidates) @@ -325,7 +338,15 @@ public static void Init(IDictionary remappingArgs, string name, msgRegistry.ParseAssemblyAndRegisterRosMessages(assembly); srvRegistry.ParseAssemblyAndRegisterRosServices(assembly); } - +#else + // Load RosMessages from Messages assembly + var msgAssembly = Assembly.LoadFrom("Uml.Robotics.Ros.dll"); + + logger.LogDebug($"Parse assembly: {msgAssembly.Location}"); + msgRegistry.ParseAssemblyAndRegisterRosMessages(msgAssembly); + srvRegistry.ParseAssemblyAndRegisterRosServices(msgAssembly); + +#endif initOptions = options; _ok = true; diff --git a/Uml.Robotics.XmlRpc/Uml.Robotics.XmlRpc.csproj b/Uml.Robotics.XmlRpc/Uml.Robotics.XmlRpc.csproj index 634a2cd0..87db562f 100644 --- a/Uml.Robotics.XmlRpc/Uml.Robotics.XmlRpc.csproj +++ b/Uml.Robotics.XmlRpc/Uml.Robotics.XmlRpc.csproj @@ -1,7 +1,16 @@  - netcoreapp2.1 + netcoreapp2.1;net462 + true + + + + NETCORE + + + + NET462 diff --git a/Uml.Robotics.XmlRpc/XmlRpcClient.cs b/Uml.Robotics.XmlRpc/XmlRpcClient.cs index 2becd190..fd6211ca 100644 --- a/Uml.Robotics.XmlRpc/XmlRpcClient.cs +++ b/Uml.Robotics.XmlRpc/XmlRpcClient.cs @@ -53,7 +53,11 @@ public async Task ExecuteAsync(string methodName, XmlRpcValue req.Method = "POST"; req.ContentType = "text/xml; charset=utf-8"; +#if NETCORE using (var stream = await req.GetRequestStreamAsync()) +#else + using (var stream = req.GetRequestStream()) +#endif { // serialize request into memory stream var buffer = new MemoryStream(); @@ -64,8 +68,11 @@ public async Task ExecuteAsync(string methodName, XmlRpcValue await buffer.CopyToAsync(stream); } - +#if NETCORE using (var response = await req.GetResponseAsync()) +#else + using (var response = req.GetResponse()) +#endif { var encoding = Encoding.UTF8; using (var reader = new StreamReader(response.GetResponseStream(), encoding)) From fcb151c3b1053c13534355ac70f6f0e25afbfb9e Mon Sep 17 00:00:00 2001 From: rgarofalo Date: Wed, 25 Jul 2018 19:05:02 +0200 Subject: [PATCH 2/7] fix Load RosMessages from Messages assembly --- Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs | 6 ++---- Uml.Robotics.Ros/_Init.cs | 14 ++++---------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs b/Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs index c47873d8..73f89b8e 100644 --- a/Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs +++ b/Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; -using System.Runtime.Loader; using System.Text; #if NETCORE @@ -48,9 +47,10 @@ public static IEnumerable GetCandidateAssemblies(params string[] tagAs throw new ArgumentException("At least one tag assembly name must be specified.", nameof(tagAssemblies)); var referenceAssemblies = new HashSet(tagAssemblies, StringComparer.OrdinalIgnoreCase); + var context = DependencyContext.Load(Assembly.GetEntryAssembly()); #if NETCORE - var context = DependencyContext.Load(Assembly.GetEntryAssembly()); + var loadContext = AssemblyLoadContext.Default; return context.RuntimeLibraries @@ -58,8 +58,6 @@ public static IEnumerable GetCandidateAssemblies(params string[] tagAs .SelectMany(x => x.GetDefaultAssemblyNames(context)) .Select(x => loadContext.LoadFromAssemblyName(x)); #else - //var entryAssembly = Assembly.Load(new AssemblyName(tagAssemblies[0])); - var context = DependencyContext.Load(Assembly.GetEntryAssembly()); return context.RuntimeLibraries .Where(x => x.Dependencies.Any(d => referenceAssemblies.Contains(d.Name))) diff --git a/Uml.Robotics.Ros/_Init.cs b/Uml.Robotics.Ros/_Init.cs index bdf602a6..89075e81 100644 --- a/Uml.Robotics.Ros/_Init.cs +++ b/Uml.Robotics.Ros/_Init.cs @@ -329,24 +329,18 @@ public static void Init(IDictionary remappingArgs, string name, // Load RosMessages from MessageBase assembly msgRegistry.ParseAssemblyAndRegisterRosMessages(typeof(RosMessage).GetTypeInfo().Assembly); -#if NETCORE - // Load RosMessages from all assemblies that depend on MessageBase + + // Load RosMessages from Messages assembly var candidates = MessageTypeRegistry.GetCandidateAssemblies("Uml.Robotics.Ros.MessageBase"); + foreach (var assembly in candidates) { logger.LogDebug($"Parse assembly: {assembly.Location}"); msgRegistry.ParseAssemblyAndRegisterRosMessages(assembly); srvRegistry.ParseAssemblyAndRegisterRosServices(assembly); } -#else - // Load RosMessages from Messages assembly - var msgAssembly = Assembly.LoadFrom("Uml.Robotics.Ros.dll"); - logger.LogDebug($"Parse assembly: {msgAssembly.Location}"); - msgRegistry.ParseAssemblyAndRegisterRosMessages(msgAssembly); - srvRegistry.ParseAssemblyAndRegisterRosServices(msgAssembly); - -#endif + initOptions = options; _ok = true; From d16444f17a6f987b69a82dd9528bb3d56778954b Mon Sep 17 00:00:00 2001 From: rgarofalo Date: Thu, 26 Jul 2018 12:23:42 +0200 Subject: [PATCH 3/7] fix merge --- Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs | 12 ++++-------- Uml.Robotics.Ros/TopicManager.cs | 1 - Uml.Robotics.Ros/_Init.cs | 13 +++++++++++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs b/Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs index cf7ae27c..587dd49d 100644 --- a/Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs +++ b/Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs @@ -50,22 +50,18 @@ public static IEnumerable GetCandidateAssemblies(params string[] tagAs #if NETCORE var context = DependencyContext.Load(Assembly.GetEntryAssembly()); - -#if NETCORE - var loadContext = AssemblyLoadContext.Default; - + return context.RuntimeLibraries .Where(x => x.Dependencies.Any(d => referenceAssemblies.Contains(d.Name))) .SelectMany(x => x.GetDefaultAssemblyNames(context)) - .Select(loadContext.LoadFromAssemblyName); + .Select(x => loadContext.LoadFromAssemblyName(x)); #else var context = DependencyContext.Load(Assembly.GetEntryAssembly()); return context.RuntimeLibraries - .Where(x => x.Dependencies.Any(d => referenceAssemblies.Contains(d.Name))) - .SelectMany(x => x.GetDefaultAssemblyNames(context)) - .Select(Assembly.Load); + .Where(x => x.Dependencies.Any(d => referenceAssemblies.Contains(d.Name))) + .SelectMany(x => x.GetDefaultAssemblyNames(context)).Select(Assembly.Load); #endif } } diff --git a/Uml.Robotics.Ros/TopicManager.cs b/Uml.Robotics.Ros/TopicManager.cs index 09a49979..3bd3e68c 100644 --- a/Uml.Robotics.Ros/TopicManager.cs +++ b/Uml.Robotics.Ros/TopicManager.cs @@ -703,7 +703,6 @@ private void PublisherUpdateCallback(XmlRpcValue parm, XmlRpcValue result) pubUpdateTask.WhenCompleted().WhenCompleted().Wait(); if (pubUpdateTask.HasCompletedSuccessfully() && pubUpdateTask.Result) - { XmlRpcManager.ResponseInt(1, "", 0)(result); else { diff --git a/Uml.Robotics.Ros/_Init.cs b/Uml.Robotics.Ros/_Init.cs index 80045c80..7c5129ce 100644 --- a/Uml.Robotics.Ros/_Init.cs +++ b/Uml.Robotics.Ros/_Init.cs @@ -330,16 +330,25 @@ public static void Init(IDictionary remappingArgs, string name, msgRegistry.ParseAssemblyAndRegisterRosMessages(typeof(RosMessage).GetTypeInfo().Assembly); // Load RosMessages from all assemblies that reference Uml.Robotics.Ros.MessageBas +#if NETCORE + // Load RosMessages from all assemblies that depend on MessageBase var candidates = MessageTypeRegistry.GetCandidateAssemblies("Uml.Robotics.Ros.MessageBase"); - foreach (var assembly in candidates) { logger.LogDebug($"Parse assembly: {assembly.Location}"); msgRegistry.ParseAssemblyAndRegisterRosMessages(assembly); srvRegistry.ParseAssemblyAndRegisterRosServices(assembly); } +#else + // Load RosMessages from Messages assembly + var msgAssembly = Assembly.LoadFrom("Uml.Robotics.Ros.dll"); + + logger.LogDebug($"Parse assembly: {msgAssembly.Location}"); + msgRegistry.ParseAssemblyAndRegisterRosMessages(msgAssembly); + srvRegistry.ParseAssemblyAndRegisterRosServices(msgAssembly); + +#endif - initOptions = options; _ok = true; From 2ab54bb1ef69263844770e9a07caaa480a252c62 Mon Sep 17 00:00:00 2001 From: rgarofalo Date: Thu, 24 Jan 2019 12:27:59 +0100 Subject: [PATCH 4/7] add streamcam sample and audiodata msgs --- Samples/StreamingCam/Program.cs | 140 ++++++++++++++++++++ Samples/StreamingCam/StreamingCam.csproj | 35 +++++ Samples/StreamingCam/view.Designer.cs | 77 +++++++++++ Samples/StreamingCam/view.cs | 53 ++++++++ Uml.Robotics.Ros.sln | 7 + common_msgs/audio_common_msgs/AudioData.msg | 1 + 6 files changed, 313 insertions(+) create mode 100644 Samples/StreamingCam/Program.cs create mode 100644 Samples/StreamingCam/StreamingCam.csproj create mode 100644 Samples/StreamingCam/view.Designer.cs create mode 100644 Samples/StreamingCam/view.cs create mode 100644 common_msgs/audio_common_msgs/AudioData.msg diff --git a/Samples/StreamingCam/Program.cs b/Samples/StreamingCam/Program.cs new file mode 100644 index 00000000..fbef7d09 --- /dev/null +++ b/Samples/StreamingCam/Program.cs @@ -0,0 +1,140 @@ +using System; +using System.Diagnostics; +using System.Threading; +using Uml.Robotics.Ros; +using std_msgs = Messages.std_msgs; +using Image = Messages.sensor_msgs.Image; +using System.Drawing; +using System.Drawing.Imaging; +using AForge.Video; +using AForge.Video.DirectShow; +using System.Linq; +using System.IO; +using System.Runtime.InteropServices; + +namespace StreamingCam +{ + class Program + { + static Bitmap video; + static void Main(string[] args) + { + + + FilterInfoCollection VideoCaptureDevices; + VideoCaptureDevice FinalVideo; + + + + Trace.Listeners.Add(new TextWriterTraceListener(Console.Out)); + ROS.Init(args, "Talker"); + var spinner = new SingleThreadSpinner(); + NodeHandle node = new NodeHandle(); + + Publisher Talker = node.Advertise("/video", 1); + int count = 0; + + + + VideoCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); + + FinalVideo = new VideoCaptureDevice(VideoCaptureDevices[0].MonikerString); + FinalVideo.NewFrame += new NewFrameEventHandler(FinalVideo_NewFrame); + FinalVideo.Start(); + + + + while (ROS.OK && !Console.KeyAvailable) + { + Console.WriteLine("publishing message"); + ROS.Info()("Publishing a chatter message: \"Blah blah blah " + ""); + + if (video != null) + { + Image img = new Image(); + img.header = new std_msgs.Header(); + img.header.seq = (uint)count++; + img.header.stamp = new std_msgs.Time(); + img.header.frame_id = "/jkfd"; + img.width = (uint)video.Width; + img.height = (uint)video.Height; + img.encoding = "rgb8"; + img.is_bigendian = 0; + img.step = 640 * 1 * 3; + byte[] tmp = BitmapToByteArray(video); + + //img.data = new byte[img.width * img.height * 3]; + //Array.Copy(tmp, 54, img.data, 0, tmp.Length - 54); + img.data = BitmapToByteArray(video); + //323704 + //921654 + + Talker.Publish(img); + spinner.SpinOnce(); + } + Thread.Sleep(300); + } + ROS.Shutdown(); + + //view v = new view(); + //v.ShowDialog(); + + + + } + + static void FinalVideo_NewFrame(object sender, NewFrameEventArgs eventArgs) + { + video = (Bitmap)eventArgs.Frame.Clone(); + //Bitmap v= new Bitmap() + //this.pictureBox1.Image = video; + + + + + + } + + public static byte[] BitmapToByteArray(Bitmap bitmap) + { + + BitmapData bmpdata = null; + + try + { + bmpdata = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, bitmap.PixelFormat); + int numbytes = bmpdata.Stride * bitmap.Height; + byte[] bytedata = new byte[numbytes]; + IntPtr ptr = bmpdata.Scan0; + + Marshal.Copy(ptr, bytedata, 0, numbytes); + + return bytedata; + } + finally + { + if (bmpdata != null) + bitmap.UnlockBits(bmpdata); + } + + } + + static byte[] ConvertBitMapToByteArray(Bitmap bitmap) + { + + bitmap.RotateFlip(RotateFlipType.Rotate180FlipNone); // in ros lo 0:0 si trova al top left + + MemoryStream stream = new MemoryStream(); + bitmap.Save(stream, ImageFormat.Bmp); + return stream.ToArray(); + + + + } + public static byte[] ImageToByte(Bitmap img) + { + ImageConverter converter = new ImageConverter(); + return (byte[])converter.ConvertTo(img, typeof(byte[])); + } + } +} diff --git a/Samples/StreamingCam/StreamingCam.csproj b/Samples/StreamingCam/StreamingCam.csproj new file mode 100644 index 00000000..f53c09bc --- /dev/null +++ b/Samples/StreamingCam/StreamingCam.csproj @@ -0,0 +1,35 @@ + + + + Exe + net462 + + + + + + + + + + ..\..\..\..\Git_repo\TPV_Aena\TPV C sharp\lib\AForge.dll + + + ..\..\..\..\Git_repo\TPV_Aena\TPV C sharp\lib\AForge.Imaging.dll + + + ..\..\..\..\Git_repo\TPV_Aena\TPV C sharp\lib\AForge.Video.dll + + + ..\..\..\..\Git_repo\TPV_Aena\TPV C sharp\lib\AForge.Video.DirectShow.dll + + + + + + + Form + + + + diff --git a/Samples/StreamingCam/view.Designer.cs b/Samples/StreamingCam/view.Designer.cs new file mode 100644 index 00000000..a04ab98c --- /dev/null +++ b/Samples/StreamingCam/view.Designer.cs @@ -0,0 +1,77 @@ +namespace StreamingCam +{ + partial class view + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.btnOK = new System.Windows.Forms.Button(); + + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.SuspendLayout(); + + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + + this.components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Text = "view"; + this.Controls.Add(this.pictureBox1); + this.Controls.Add(this.btnOK); + + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.view_FormClosing); + + // + // pictureBox1 + // + this.pictureBox1.Location = new System.Drawing.Point(361, 156); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(800, 700); + this.pictureBox1.TabIndex = 7; + this.pictureBox1.TabStop = false; + + // + // btnOK + // + this.btnOK.BackColor = System.Drawing.Color.LimeGreen; + this.btnOK.Font = new System.Drawing.Font("Microsoft Sans Serif", 10.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btnOK.ForeColor = System.Drawing.Color.White; + this.btnOK.Location = new System.Drawing.Point(506, 123); + this.btnOK.Name = "btnOK"; + this.btnOK.Size = new System.Drawing.Size(75, 54); + this.btnOK.TabIndex = 5; + this.btnOK.Text = "OK"; + this.btnOK.UseVisualStyleBackColor = false; + this.btnOK.Click += new System.EventHandler(this.btnOK_Click); + } + + private System.Windows.Forms.PictureBox pictureBox1; + private System.Windows.Forms.Button btnOK; + + #endregion + } +} \ No newline at end of file diff --git a/Samples/StreamingCam/view.cs b/Samples/StreamingCam/view.cs new file mode 100644 index 00000000..27ce2433 --- /dev/null +++ b/Samples/StreamingCam/view.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using AForge.Video; +using AForge.Video.DirectShow; + +namespace StreamingCam +{ + public partial class view: Form + { + private FilterInfoCollection VideoCaptureDevices; + private VideoCaptureDevice FinalVideo; + + public Bitmap video; + public view() + { + InitializeComponent(); + + VideoCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); + + FinalVideo = new VideoCaptureDevice(VideoCaptureDevices[0].MonikerString); + FinalVideo.NewFrame += new NewFrameEventHandler(FinalVideo_NewFrame); + + + + + + + } + + public void btnOK_Click(object sender, EventArgs e) + { + FinalVideo.Start(); + } + private void view_FormClosing(object sender, FormClosingEventArgs e) + { + FinalVideo.Stop(); + } + void FinalVideo_NewFrame(object sender, NewFrameEventArgs eventArgs) + { + video = (Bitmap)eventArgs.Frame.Clone(); + + this.pictureBox1.Image = video; + + } + } +} diff --git a/Uml.Robotics.Ros.sln b/Uml.Robotics.Ros.sln index 28f4746e..4823b78c 100644 --- a/Uml.Robotics.Ros.sln +++ b/Uml.Robotics.Ros.sln @@ -41,6 +41,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ActionServerSample", "Sampl EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PubSubTestbed", "Tests\PubSubTestbed\PubSubTestbed.csproj", "{1C8D0504-5236-4FFF-AA8F-2CFF6C564DC0}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StreamingCam", "Samples\StreamingCam\StreamingCam.csproj", "{BBBE254B-D17E-45A8-B97E-1FDA4D9DD0E5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -115,6 +117,10 @@ Global {1C8D0504-5236-4FFF-AA8F-2CFF6C564DC0}.Debug|Any CPU.Build.0 = Debug|Any CPU {1C8D0504-5236-4FFF-AA8F-2CFF6C564DC0}.Release|Any CPU.ActiveCfg = Release|Any CPU {1C8D0504-5236-4FFF-AA8F-2CFF6C564DC0}.Release|Any CPU.Build.0 = Release|Any CPU + {BBBE254B-D17E-45A8-B97E-1FDA4D9DD0E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BBBE254B-D17E-45A8-B97E-1FDA4D9DD0E5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BBBE254B-D17E-45A8-B97E-1FDA4D9DD0E5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BBBE254B-D17E-45A8-B97E-1FDA4D9DD0E5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -131,6 +137,7 @@ Global {4F0E93D5-6CC7-4971-BB91-A5139CF4B05E} = {9C75EAAD-EACA-4E4F-B9DA-D7BADB3B7577} {3041CF5C-222C-412E-8EE6-289C1DE0E567} = {9C75EAAD-EACA-4E4F-B9DA-D7BADB3B7577} {1C8D0504-5236-4FFF-AA8F-2CFF6C564DC0} = {EEE8759B-47AD-455B-8F32-0A36EAE2512B} + {BBBE254B-D17E-45A8-B97E-1FDA4D9DD0E5} = {9C75EAAD-EACA-4E4F-B9DA-D7BADB3B7577} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {23E67514-C5C2-464B-8371-A9A618DE03BA} diff --git a/common_msgs/audio_common_msgs/AudioData.msg b/common_msgs/audio_common_msgs/AudioData.msg new file mode 100644 index 00000000..c5fd6c87 --- /dev/null +++ b/common_msgs/audio_common_msgs/AudioData.msg @@ -0,0 +1 @@ +float32[] data \ No newline at end of file From 8d10685e7ba78941dd8f52e513ed32fae302aab5 Mon Sep 17 00:00:00 2001 From: roberto Date: Wed, 24 Nov 2021 16:11:13 +0100 Subject: [PATCH 5/7] fix loading Uml.Robotics.Ros.MessageBase --- Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs | 12 ++++++++---- Uml.Robotics.Ros/_Init.cs | 13 ++----------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs b/Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs index 587dd49d..aee53d24 100644 --- a/Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs +++ b/Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs @@ -57,11 +57,15 @@ public static IEnumerable GetCandidateAssemblies(params string[] tagAs .SelectMany(x => x.GetDefaultAssemblyNames(context)) .Select(x => loadContext.LoadFromAssemblyName(x)); #else - var context = DependencyContext.Load(Assembly.GetEntryAssembly()); + + Assembly[] a = AppDomain.CurrentDomain.GetAssemblies().; - return context.RuntimeLibraries - .Where(x => x.Dependencies.Any(d => referenceAssemblies.Contains(d.Name))) - .SelectMany(x => x.GetDefaultAssemblyNames(context)).Select(Assembly.Load); + return a.Where(x=> x.GetReferencedAssemblies().Any(y => referenceAssemblies.Contains(y.Name))); + + + + + #endif } } diff --git a/Uml.Robotics.Ros/_Init.cs b/Uml.Robotics.Ros/_Init.cs index 0db93618..f27d9cb8 100644 --- a/Uml.Robotics.Ros/_Init.cs +++ b/Uml.Robotics.Ros/_Init.cs @@ -377,7 +377,7 @@ public static void Init(IDictionary remappingArgs, string name, msgRegistry.ParseAssemblyAndRegisterRosMessages(typeof(RosMessage).GetTypeInfo().Assembly); // Load RosMessages from all assemblies that reference Uml.Robotics.Ros.MessageBas -#if NETCORE + var candidates = MessageTypeRegistry.GetCandidateAssemblies("Uml.Robotics.Ros.MessageBase") .Concat(messageAssemblies) .Distinct(); @@ -388,16 +388,7 @@ public static void Init(IDictionary remappingArgs, string name, msgRegistry.ParseAssemblyAndRegisterRosMessages(assembly); srvRegistry.ParseAssemblyAndRegisterRosServices(assembly); } -#else - // Load RosMessages from Messages assembly - var msgAssembly = Assembly.LoadFrom("Uml.Robotics.Ros.dll"); - - logger.LogDebug($"Parse assembly: {msgAssembly.Location}"); - msgRegistry.ParseAssemblyAndRegisterRosMessages(msgAssembly); - srvRegistry.ParseAssemblyAndRegisterRosServices(msgAssembly); - -#endif - + initOptions = options; _ok = true; From 2a372d9c355633150c46a0c2b0a5e3fd4055167a Mon Sep 17 00:00:00 2001 From: roberto Date: Thu, 25 Nov 2021 11:54:34 +0100 Subject: [PATCH 6/7] fix syntax --- Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs b/Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs index aee53d24..feef4cc7 100644 --- a/Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs +++ b/Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs @@ -58,7 +58,7 @@ public static IEnumerable GetCandidateAssemblies(params string[] tagAs .Select(x => loadContext.LoadFromAssemblyName(x)); #else - Assembly[] a = AppDomain.CurrentDomain.GetAssemblies().; + Assembly[] a = AppDomain.CurrentDomain.GetAssemblies(); return a.Where(x=> x.GetReferencedAssemblies().Any(y => referenceAssemblies.Contains(y.Name))); From e7c4ddf07adc2223bd08de4119d6266aa2671691 Mon Sep 17 00:00:00 2001 From: roberto Date: Thu, 25 Nov 2021 12:24:19 +0100 Subject: [PATCH 7/7] fix syntax for pull request --- Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs | 7 +------ Uml.Robotics.Ros/RemappingHelper.cs | 11 +++++++++++ Uml.Robotics.Ros/Uml.Robotics.Ros.csproj | 4 ---- Uml.Robotics.Ros/_Init.cs | 1 - 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs b/Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs index feef4cc7..3e70fe46 100644 --- a/Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs +++ b/Uml.Robotics.Ros.MessageBase/TypeRegistryBase.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; -using System.Runtime.Loader; #if NETCORE using System.Runtime.Loader; @@ -55,16 +54,12 @@ public static IEnumerable GetCandidateAssemblies(params string[] tagAs return context.RuntimeLibraries .Where(x => x.Dependencies.Any(d => referenceAssemblies.Contains(d.Name))) .SelectMany(x => x.GetDefaultAssemblyNames(context)) - .Select(x => loadContext.LoadFromAssemblyName(x)); + .Select(loadContext.LoadFromAssemblyName); #else Assembly[] a = AppDomain.CurrentDomain.GetAssemblies(); return a.Where(x=> x.GetReferencedAssemblies().Any(y => referenceAssemblies.Contains(y.Name))); - - - - #endif } diff --git a/Uml.Robotics.Ros/RemappingHelper.cs b/Uml.Robotics.Ros/RemappingHelper.cs index e6559291..f4b9d566 100644 --- a/Uml.Robotics.Ros/RemappingHelper.cs +++ b/Uml.Robotics.Ros/RemappingHelper.cs @@ -42,23 +42,34 @@ public static bool GetRemappings(ref string[] args, out IDictionaryNETCORE - - NETCORE - - NET462 PackageReference diff --git a/Uml.Robotics.Ros/_Init.cs b/Uml.Robotics.Ros/_Init.cs index f27d9cb8..52133f41 100644 --- a/Uml.Robotics.Ros/_Init.cs +++ b/Uml.Robotics.Ros/_Init.cs @@ -377,7 +377,6 @@ public static void Init(IDictionary remappingArgs, string name, msgRegistry.ParseAssemblyAndRegisterRosMessages(typeof(RosMessage).GetTypeInfo().Assembly); // Load RosMessages from all assemblies that reference Uml.Robotics.Ros.MessageBas - var candidates = MessageTypeRegistry.GetCandidateAssemblies("Uml.Robotics.Ros.MessageBase") .Concat(messageAssemblies) .Distinct();