Walkthrough |
Preparing for development with Rubedos.Viper.Net SDK
Installed VIPER evaluation kit has following deployment scheme:
Client application shall be running on development machine and access VIPER services through Viper.Net assembly. Additionally there are other 3rdparty assemblies available:
OpenCV.Net - a wrapper around famous OpenCV library to work with images
Helix-toolkit on SharpDX - an extensive 3D visualisation library, for pointcloud rendering
Ros.Net - a set of assemblies to interface with ROS framework
log4net - is a logging tool
Download and install Viper.Net SDK and samples
Download and install ROS tools for windows. The tools shall greatly help you to quickly access VIPER data and topics, for example RVizWin can visualize active topics and PointCloudViewer shall render 3D view from VIPER in real-time
Once the steps are done, open up Visual Studio 2015 or higher and create a C# project (Console Application, WPF application or WinForms application). Add Viper.Net and related assemblies to your project references and compile following code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using Ros.Net.utilities; using Rubedos.Viper.Net; namespace ReadTopicsSample { class Program { private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); static void Main(string[] args) { try { // Specify VIPER IP here using (CvmDevice module = new CvmDevice("http://192.168.1.157:11311", null)) { module.RosNode = "ReadTopicsSample"; module.Connect(); if (!module.IsConnected) throw new InvalidOperationException("Cannot connect to VIPER!"); // Each image stream is associated with specific named topic. To receive images on needs to subscribe to the topic // and attach a sink where images must be cached when received. Since there are several image types in .NET, use // a corresponding sink type, e.g. BitmapSink for System.Drawing.Bitmap. // One image subscriber can have multiple sinks, if multiple types of the same topic image are needed. foreach (var topic in module.ImageTopics) { log.InfoFormat("Getting image from topic '{0}'", topic); using (ImageSubscriber<ImageHandler> subscriber = new ImageSubscriber<ImageHandler>()) { BitmapSink sink = new BitmapSink(); subscriber.AddSink(sink); AutoResetEvent waitHandle = new AutoResetEvent(false); // Once subsribed, this event shall notify when there are new images available in the topic. If event is not raised, it means image // has not been published for some reason. sink.Updated += (s, e) => { log.InfoFormat("Received image of size {0}", sink.Bitmap.Size); waitHandle.Set(); }; subscriber.Subscribe(topic); if (!waitHandle.WaitOne(3000)) log.WarnFormat("Topic has no images published"); } } module.Disconnect(); } } catch (Exception ex) { log.Error(ex); } } } }