Skip to content

Commit

Permalink
PR #8860 from SergeySPF: C# example for pose stream (for T265 device)
Browse files Browse the repository at this point in the history
  • Loading branch information
maloel authored Jun 6, 2021
2 parents c279323 + 95d6407 commit b79b5ea
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 1 deletion.
3 changes: 2 additions & 1 deletion wrappers/csharp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ add_subdirectory(Intel.RealSense)
add_subdirectory(cs-tutorial-1-depth)
add_subdirectory(cs-tutorial-2-capture)
add_subdirectory(cs-tutorial-3-processing)
add_subdirectory(cs-tutorial-4-software-dev)
add_subdirectory(cs-tutorial-4-software-dev)
add_subdirectory(cs-tutorial-5-pose)
21 changes: 21 additions & 0 deletions wrappers/csharp/cs-tutorial-5-pose/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cmake_minimum_required( VERSION 3.8.0 )

project(cs-tutorial-5-pose)

add_executable(${PROJECT_NAME}
Program.cs
Properties/AssemblyInfo.cs
)

set_property(TARGET ${PROJECT_NAME} PROPERTY VS_DOTNET_TARGET_FRAMEWORK_VERSION "v${DOTNET_VERSION_EXAMPLES}")
# set_property(TARGET ${PROJECT_NAME} PROPERTY WIN32_EXECUTABLE TRUE)

add_dependencies(${PROJECT_NAME} Intel.RealSense)

set_property(TARGET ${PROJECT_NAME} PROPERTY VS_DOTNET_REFERENCES
"System"
)

set_target_properties (${PROJECT_NAME} PROPERTIES
FOLDER Wrappers/csharp
)
55 changes: 55 additions & 0 deletions wrappers/csharp/cs-tutorial-5-pose/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;

namespace Intel.RealSense
{
class Program
{
static void Main(string[] args)
{
using (var ctx = new Context())
{
DeviceList devices = ctx.QueryDevices();
if (devices.Count == 0)
{
Console.WriteLine("RealSense devices are not connected.");
return;
}

using (var pipeline = new Pipeline(ctx))
using (var config = new Config())
{
// Add pose stream
config.EnableStream(Stream.Pose, Format.SixDOF);
// Start pipeline with chosen configuration
using(var profile = pipeline.Start(config))
using (var streamprofile = profile.GetStream(Stream.Pose).As<PoseStreamProfile>())
{
Console.WriteLine($"\nDevice : {profile.Device.Info[CameraInfo.Name]}");
Console.WriteLine($" Serial number: {profile.Device.Info[CameraInfo.SerialNumber]}");
Console.WriteLine($" Firmware version: {profile.Device.Info[CameraInfo.FirmwareVersion]}");
Console.WriteLine($" Pose stream framerate: {streamprofile.Framerate}\n");
}

while (true)
{
// Wait for the next set of frames from the camera
using (FrameSet frameset = pipeline.WaitForFrames())
// Get a frame from the pose stream
using (PoseFrame frame = frameset.PoseFrame)
{
// Get pose frame data
Pose data = frame.PoseData;

// Print the x, y, z values of the translation, relative to initial position
Console.Write("\r" + new String(' ', 80));
Console.Write("\rDevice Position: {0} {1} {2} (meters)", data.translation.x.ToString("N3"), data.translation.y.ToString("N3"), data.translation.z.ToString("N3"));
}
}
}
}
}
}
}
33 changes: 33 additions & 0 deletions wrappers/csharp/cs-tutorial-5-pose/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Intel(R) RealSense(TM) SDK C# Wrapper Tutorial-5")]
[assembly: AssemblyDescription("Intel(R) RealSense(TM) SDK C# Wrapper Examples")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Intel(R) Corporation")]
[assembly: AssemblyProduct("Intel(R) RealSense(TM) SDK C# Wrapper")]
[assembly: AssemblyCopyright("Copyright © 2021, Intel Corporation. All rights reserved")]
[assembly: AssemblyTrademark("Intel(R) RealSense(TM)")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("71c85ee0-c7c2-4e2e-8020-6af818537a14")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
3 changes: 3 additions & 0 deletions wrappers/csharp/cs-tutorial-5-pose/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/></startup></configuration>

0 comments on commit b79b5ea

Please sign in to comment.