This commit is contained in:
Brent Allen 2019-08-06 17:14:27 -07:00 коммит произвёл GitHub
Родитель 8937afde4b
Коммит c82126e3f0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 92 добавлений и 19 удалений

Просмотреть файл

@ -328,7 +328,7 @@ namespace Microsoft.Azure.Kinect.Sensor
using (LoggingTracer tracer = new LoggingTracer())
{
ImuSample sample = new ImuSample();
NativeMethods.k4a_imu_sample_t sample = new NativeMethods.k4a_imu_sample_t();
NativeMethods.k4a_wait_result_t result = NativeMethods.k4a_device_get_imu_sample(this.handle, sample, (int)timeout.TotalMilliseconds);
if (result == NativeMethods.k4a_wait_result_t.K4A_WAIT_RESULT_TIMEOUT)
@ -338,7 +338,7 @@ namespace Microsoft.Azure.Kinect.Sensor
AzureKinectException.ThrowIfNotSuccess(tracer, result);
return sample;
return sample.ToImuSample();
}
}
}

Просмотреть файл

@ -6,6 +6,8 @@
//------------------------------------------------------------------------------
using System;
using System.Buffers;
using System.Diagnostics;
using System.Numerics;
using System.Runtime.InteropServices;
namespace Microsoft.Azure.Kinect.Sensor
@ -355,7 +357,7 @@ namespace Microsoft.Azure.Kinect.Sensor
/// <summary>
/// Gets or sets the image time-stamp in the device's clock.
/// </summary>
public TimeSpan Timestamp
public TimeSpan DeviceTimestamp
{
get
{
@ -366,7 +368,7 @@ namespace Microsoft.Azure.Kinect.Sensor
throw new ObjectDisposedException(nameof(Image));
}
ulong timestamp = NativeMethods.k4a_image_get_timestamp_usec(this.handle);
ulong timestamp = NativeMethods.k4a_image_get_device_timestamp_usec(this.handle);
return TimeSpan.FromTicks(checked((long)timestamp) * 10);
}
}
@ -380,7 +382,45 @@ namespace Microsoft.Azure.Kinect.Sensor
throw new ObjectDisposedException(nameof(Image));
}
NativeMethods.k4a_image_set_timestamp_usec(this.handle, checked((ulong)value.Ticks / 10));
NativeMethods.k4a_image_set_device_timestamp_usec(this.handle, checked((ulong)value.Ticks / 10));
}
}
}
/// <summary>
/// Gets or sets the image timestamp in nanoseconds.
/// </summary>
/// <remarks>
/// The base of the timestamp clock is the same as Stopwatch.GetTimestamp(). Units need to be
/// converted between nanoseconds and the Stopwatch frequency to make comparisons.
/// </remarks>
public long SystemTimestampNsec
{
get
{
lock (this)
{
if (this.disposedValue)
{
throw new ObjectDisposedException(nameof(Image));
}
ulong timestamp = NativeMethods.k4a_image_get_system_timestamp_nsec(this.handle);
return (long)timestamp;
}
}
set
{
lock (this)
{
if (this.disposedValue)
{
throw new ObjectDisposedException(nameof(Image));
}
NativeMethods.k4a_image_set_system_timestamp_nsec(this.handle, (ulong)value);
}
}
}

Просмотреть файл

@ -24,9 +24,9 @@ namespace Microsoft.Azure.Kinect.Sensor
public Vector3 AccelerometerSample { get; set; }
/// <summary>
/// Gets or sets timestamp of the accerometer in microseconds.
/// Gets or sets timestamp of the accerometer.
/// </summary>
public long AccelerometerTimestampInUsec { get; set; }
public TimeSpan AccelerometerTimestamp { get; set; }
/// <summary>
/// Gets or sets gyroscope sample in radians per second.
@ -34,9 +34,8 @@ namespace Microsoft.Azure.Kinect.Sensor
public Vector3 GyroSample { get; set; }
/// <summary>
/// Gets or sets timestamp of the gyroscope in microseconds.
/// Gets or sets timestamp of the gyroscope.
/// </summary>
public long GyroTimestampInUsec { get; set; }
public TimeSpan GyroTimestamp { get; set; }
}
}

Просмотреть файл

@ -181,6 +181,29 @@ namespace Microsoft.Azure.Kinect.Sensor
}
}
[StructLayout(LayoutKind.Sequential)]
[Native.NativeReference("k4a_imu_sample_t")]
public class k4a_imu_sample_t
{
public float temperature { get; set; }
public Vector3 acc_sample { get; set; }
public UInt64 acc_timestamp_usec { get; set; }
public Vector3 gyro_sample { get; set; }
public UInt64 gyro_timestamp_usec { get; set; }
public ImuSample ToImuSample()
{
return new ImuSample
{
Temperature = temperature,
AccelerometerSample = acc_sample,
AccelerometerTimestamp = TimeSpan.FromTicks(checked((long)acc_timestamp_usec) * 10),
GyroSample = gyro_sample,
GyroTimestamp = TimeSpan.FromTicks(checked((long)gyro_timestamp_usec) * 10)
};
}
}
[NativeReference]
[StructLayout(LayoutKind.Sequential)]
public struct k4a_device_configuration_t
@ -398,7 +421,7 @@ namespace Microsoft.Azure.Kinect.Sensor
[NativeReference]
public static extern k4a_wait_result_t k4a_device_get_imu_sample(
k4a_device_t device_handle,
ImuSample imu_sample,
[Out] k4a_imu_sample_t imu_sample,
Int32 timeout_in_ms);
[DllImport("k4a", CallingConvention = k4aCallingConvention)]
@ -502,11 +525,19 @@ namespace Microsoft.Azure.Kinect.Sensor
[DllImport("k4a", CallingConvention = k4aCallingConvention)]
[NativeReference]
public static extern UInt64 k4a_image_get_timestamp_usec(k4a_image_t image_handle);
public static extern UInt64 k4a_image_get_device_timestamp_usec(k4a_image_t image_handle);
[DllImport("k4a", CallingConvention = CallingConvention.Cdecl)]
[NativeReference]
public static extern void k4a_image_set_device_timestamp_usec(k4a_image_t image_handle, UInt64 value);
[DllImport("k4a", CallingConvention = CallingConvention.Cdecl)]
[NativeReference]
public static extern UInt64 k4a_image_get_system_timestamp_nsec(k4a_image_t image_handle);
[DllImport("k4a", CallingConvention = k4aCallingConvention)]
[NativeReference]
public static extern void k4a_image_set_timestamp_usec(k4a_image_t image_handle, UInt64 value);
public static extern void k4a_image_set_system_timestamp_nsec(k4a_image_t image_handle, UInt64 value);
[DllImport("k4a", CallingConvention = k4aCallingConvention)]
[NativeReference]

Просмотреть файл

@ -63,7 +63,7 @@ namespace Microsoft.Azure.Kinect.Sensor
this.calibration.color_camera_calibration.resolution_width,
this.calibration.color_camera_calibration.resolution_height)
{
Timestamp = depth.Timestamp,
DeviceTimestamp = depth.DeviceTimestamp,
};
this.DepthImageToColorCamera(depth, image);
@ -182,7 +182,8 @@ namespace Microsoft.Azure.Kinect.Sensor
{
Exposure = color.Exposure,
ISOSpeed = color.ISOSpeed,
Timestamp = color.Timestamp,
DeviceTimestamp = color.DeviceTimestamp,
SystemTimestampNsec = color.SystemTimestampNsec,
WhiteBalance = color.WhiteBalance,
};

Просмотреть файл

@ -7,6 +7,7 @@
using System;
using Microsoft.Azure.Kinect.Sensor.Test.StubGenerator;
using NUnit.Framework;
using System;
namespace Microsoft.Azure.Kinect.Sensor.UnitTests
{
@ -963,13 +964,14 @@ k4a_wait_result_t k4a_device_get_imu_sample(k4a_device_t device_handle, k4a_imu_
imu_sample->acc_sample.v[0] = 0.0f;
imu_sample->acc_sample.v[1] = 0.1f;
imu_sample->acc_sample.v[2] = 0.2f;
imu_sample->acc_timestamp_usec = 0x1000200030004000;
// 10 seconds
imu_sample->acc_timestamp_usec = 10000000;
imu_sample->gyro_sample.v[0] = 0.4f;
imu_sample->gyro_sample.v[1] = 0.5f;
imu_sample->gyro_sample.v[2] = 0.6f;
imu_sample->gyro_timestamp_usec = 0x2000200030004002;
imu_sample->gyro_timestamp_usec = 60000000;
return K4A_WAIT_RESULT_SUCCEEDED;
}
@ -987,12 +989,12 @@ k4a_wait_result_t k4a_device_get_imu_sample(k4a_device_t device_handle, k4a_imu_
Assert.AreEqual(0.0f, sample.AccelerometerSample.X);
Assert.AreEqual(0.1f, sample.AccelerometerSample.Y);
Assert.AreEqual(0.2f, sample.AccelerometerSample.Z);
Assert.AreEqual(0x1000200030004000, sample.AccelerometerTimestampInUsec);
Assert.AreEqual(TimeSpan.FromSeconds(10), sample.AccelerometerTimestamp);
Assert.AreEqual(0.4f, sample.GyroSample.X);
Assert.AreEqual(0.5f, sample.GyroSample.Y);
Assert.AreEqual(0.6f, sample.GyroSample.Z);
Assert.AreEqual(0x2000200030004002, sample.GyroTimestampInUsec);
Assert.AreEqual(TimeSpan.FromMinutes(1), sample.GyroTimestamp);
Assert.AreEqual(1, count.Calls("k4a_device_get_imu_sample"));