空间传感器3 -流数据

本文关键字:数据 传感器 空间 | 更新日期: 2023-09-27 18:17:33

我在使用ThreeSpace_API.dll时遇到问题,同时试图添加对传感器的支持以释放epie。使用轮询方法工作得很好。然而,我有一个问题与流媒体。

使用VS 2012,这绝对可以正常工作。但是,在构建并尝试运行可执行文件后,它会崩溃,并出现以下错误:

Application: FreePIE.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException
Stack:
at FreePIE.Core.Plugins.Yei3Space.Api.tss_getLastStreamData(Int32, FreePIE.Core.Plugins.Yei3Space.TssStreamPacket ByRef, Int32)
at FreePIE.Core.Plugins.Yei3Space.Api.UpdateQuaternion(Int32,   FreePIE.Core.Plugins.SensorFusion.Quaternion)
at FreePIE.Core.Plugins.Yei3SpaceGlobalHolder.Update()

按如下方式调用:

//DLL Call to ThreeSpace_API.dll
[DllImport("ThreeSpace_API.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern TssError tss_getLastStreamData(int id, out TssStreamPacket packet, int size);
//Stream Packet Struct
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct TssStreamPacket
{
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
    public float[] quat;        
}
// Starts streaming asynchronous data
public static void StartStreamingU(int device_id)
{
    int count;
    byte[] stream_slots = new byte[8];
    stream_slots[0] = (byte)TssStreaming.TSS_GET_TARED_ORIENTATION_AS_QUATERNION;
    stream_slots[1] = (byte)TssStreaming.TSS_NULL;
    stream_slots[2] = (byte)TssStreaming.TSS_NULL;
    stream_slots[3] = (byte)TssStreaming.TSS_NULL;
    stream_slots[4] = (byte)TssStreaming.TSS_NULL;
    stream_slots[5] = (byte)TssStreaming.TSS_NULL;
    stream_slots[6] = (byte)TssStreaming.TSS_NULL;
    stream_slots[7] = (byte)TssStreaming.TSS_NULL;
    count=0;
    if( !is_streaming )
    {
        while( count < 3 )
        {
            if( tss_setStreamingTiming(device_id,0,-1,1500000) == 0 )
            {
                if( tss_setStreamingSlots(device_id,stream_slots) == 0 )
                {
                    if( tss_startStreaming(device_id) == 0 )
                    {
                        is_streaming=true;
                        break;
                    }
                }
            }
            count++;
        }
    }    
}
public static TssError UpdateQuaternion(int deviceId, Quaternion quaternion)
{
    uint timestamp;
    float[] fltQuat = new float[4];
    TssStreamPacket packet = new TssStreamPacket();            
    TssError error = TssError.TSS_NO_ERROR;            
    if(is_streaming)
    {
        try
        {
            error = tss_getLastStreamData(deviceId, out packet, 16);
            fltQuat[0] = packet.quat[0];
            fltQuat[1] = packet.quat[1];
            fltQuat[2] = packet.quat[2];
            fltQuat[3] = packet.quat[3];                                        
        }
        catch (System.AccessViolationException e)
        {
            return TssError.TSS_ERROR_READ;
        }
    }
}

令人讨厌的是,它通过调试器工作得很好,所以我不能做太多的测试。我已经尝试了各种各样的数据编组方法。有趣的是,通过一个普通的浮点数组来做这件事似乎会阻塞CPU。

如有任何建议,我将不胜感激。

空间传感器3 -流数据

包装器缺少时间戳参数。

这是yei_threespace_api的声明。

TSS_EXPORT TSS_Error tss_getLastStreamData(TSS_Device_Id device, char * output_data, unsigned int output_data_len, unsigned int * timestamp);

测试过了,现在工作正常!