首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >由IMU控制的鼠标

由IMU控制的鼠标
EN

Stack Overflow用户
提问于 2018-04-05 23:09:34
回答 1查看 208关注 0票数 1

我正在使用的俯仰和偏航角度从一个IMU来移动鼠标指针在vb.net中的PC。不幸的是,它不能稳定地工作。

首先,我设置了应该执行LOAD-Event的最大角度

代码语言:javascript
复制
 'set max angles in degree
  maxAngle_YawRight = 30
  maxAngle_YawLeft = -30
  maxAngle_PitchUp = 20
  maxAngle_PitchDown = -20
  calculateCurParameter(maxAngle_YawRight, Panel_Right.Location.X, maxAngle_YawLeft, Panel_Left.Location.X + Panel_Left.Width, maxAngle_PitchUp, Panel_Top.Location.Y+Panel_Top.Height, maxAngle_NickDown, Panel_Bottom.Location.Y)

我使用四个最大角度( pitch_up,pitch_down,yaw_right,yaw_left)将它们分配给表单的一部分,以获得4个点,例如(pitch_up,panel_2.location.Y) pitch_up和pitch_down用于鼠标指针的y坐标,yaw_right和yaw_left用于x坐标。这是由函数calculateCurParameter完成的。

然后我使用这四个点来计算线性方程的参数:

CursorPos=m*angle+b

所以对于每个新的角度,你都会得到一个新的光标位置。

代码语言:javascript
复制
Private mX As Double
Private bX As Double
Private mY As Double
Private bY As Double

..。

代码语言:javascript
复制
Private Sub calculateCurParameter(ByVal maxYawRight As Double, ByVal rightBorder As Double, ByVal maxYawLeft As Double, ByVal leftBorder As Double, ByVal maxPitchUp As Double, ByVal topBorder As Double, ByVal maxPitchDown As Double, ByVal bottomBorder As Double)

'this function calculates the parameter for Ycur=m*Xangle+b for each Pitch and Yaw

'calculate the parameter for the CursorPosition X
dim deltaX= maxYawLeft-maxYawRight
dim deltaY=leftBorder-rightBorder
mX=deltaY/deltaX
bX=rightBorder-mX*maxYawRight

'calculate the parameter for the CursorPosition Y
deltaX=bottomBorder-topBorder
deltaY=maxPitchDown-maxPitchUp
mY=deltaY/deltaX
bY=topBorder-mY*maxPitchUp
end Sub

在此计算之后,我使用一个二次加权移动平均(QWMA)作为由函数y=m*x+b计算的低通滤波器光标输出。

对于移动平均值,我使用每个角度的最后50个样本。之后,我将两个角度放在每个线性方程(cursorPos=m*angle+b)中,如上所述。

代码语言:javascript
复制
            'Timer-Event which is triggered each 8ms
        ' yaw and pitch are in degrees and are updated in this timer event before
                    Dim xCoordCur = Math.Round(mX * yaw + bX)
                    Dim yCoordCur = Math.Round(mY * pitch + bY)
                    arrayCurY(cursorCounter) = yCoordCur
                    arrayCurX(cursorCounter) = xCoordCur
                    If cursorCounter =50 Then 'need 50 samples to do the QWMA
                        Dim aqwmY = qwma_calculating(arrayCurY)'function to calculate the QWMA, seems to be working
                        Dim aqwmX = qwma_calculating(arrayCurX)
            'the mouse pointer should not leave the form    
                        If aqwmX > Panel_Right.Location.X Then
                            aqwmX = Panel_Right.Location.X
                        ElseIf aqwmX < (Panel_Left.Location.X + Panel_Left.Width) Then
                            aqwmX = Panel_Left.Location.X + Panel_Left.Width
                        End If
                        If aqwmY > Panel_Bottom.Location.Y Then
                            aqwmY = Panel_Bottom.Location.Y
                        ElseIf aqwmY < (Panel_Top.Location.Y + Panel_Top.Height) Then
                            aqwmY = Panel_Top.Location.Y + Panel_Top.Height
                        End If

            'Set the new Cursor Position
                        Cursor.Position = New Point(aqwmX, aqwmY)
                        arrayValuesMoving(arrayCurX)'function to move the values one index forward
                        arrayValuesMoving(arrayCurY)
                    Else
                        cursorCounter += 1
                    End If

在我的最后一步中,我设置了新的光标位置

代码语言:javascript
复制
Cursor.Position=New Point(xCoor,yCoor)

现在我可以通过移动IMU来控制鼠标指针,但它非常不稳定。例如,鼠标指针仍然移动,尽管IMU没有移动。

甚至不可能将鼠标悬停在某些表单元素上。我做错什么了?

提前感谢!

EN

回答 1

Stack Overflow用户

发布于 2018-04-11 19:35:05

我添加了以下代码:

代码语言:javascript
复制
                            If xCoor > Cursor.Position.X + 3 Or xCoor < Cursor.Position.X - 3 Then
                            istxCoor = True
                        Else
                            istxCoor = False
                        End If
                        If yCoor > Cursor.Position.Y + 3 Or yCoor < Cursor.Position.Y - 3 Then
                            istyCoor = True
                        Else
                            istyCoor = False
                        End If
                        If istxCoor And istyCoor Then
                            SetCursorPos(xCoor, yCoor)
                        ElseIf istxCoor Then
                            SetCursorPos(xCoor, Cursor.Position.Y)
                        ElseIf istyCoor Then
                            SetCursorPos(Cursor.Position.X, yCoor)
                        End If

它现在更稳定了,但现在有一个时间滞后。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49675791

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档