当我为两者编码时,为什么只有Xbox 360控制器的一个轴工作? (VB.Net)

时间:2012-11-24 18:28:47

标签: vb.net xna joystick gamepad

首先,我想指出我是一个极端的新手,我担心我可能会在这里。我的问题在于尝试使Xbox 360控制器的左操纵杆控制每个轴上的单独功能。目前我正在尝试对控制器进行编码,以便以可变速度控制Phidg​​et电机控制器的输出。我已经设法构建我的代码,以便Y轴可以毫无问题地控制前进速度,但是如果我尝试单独编码X轴,以不同的方式移动电机,它就不起作用。没有错误,它只是没有发送到Phidg​​et。

我发现我可以让X轴像我想的那样工作,但只有当我删除Y轴的代码时才会这样。似乎那些,其他人不想,就好像它只是一次注册一个轴。除此之外,我发现它工作正常并且没有问题。我还要提一下,我有几个标签显示两根木棍的当前位置,它们完美无瑕地工作。任何帮助将不胜感激!谢谢!

Imports Microsoft.Xna.Framework
Imports Microsoft.Xna.Framework.Input
Public Class Form1
Dim WithEvents MC1 As Phidget21COM.PhidgetMotorControl

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    MC1 = New Phidget21COM.PhidgetMotorControl
    MC1.Open(15100)
    MC1.WaitForAttachment(3000)

    If MC1.IsAttached = True Then
        PhidStat.Text = "Phidget Attached!"
    Else
        PhidStat.Text = "No Phidget Found"
    End If

    JoyConnect.Text = ""
    Threading.Thread.Sleep(1000)
    If GamePad.GetState(PlayerIndex.One).IsConnected = True Then
        JoyConnect.Text = "Controller Connected!"
    Else
        JoyConnect.Text = "Not Connected. :("
    End If

End Sub

Private Sub Controller()
    Dim LX As String
    Dim RX As String
    Dim LY As String
    Dim RY As String

    'Left Joystick
    LX = GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X * 100 'Negetive value = Left, Positive = Right
    LX1.Text = LX
    If LX < 0 Then
        MC1.Velocity(0) = LX
        MC1.Velocity(1) = -1 * LX
    End If
    If LX > 0 Then
        MC1.Velocity(0) = LX
        MC1.Velocity(0) = -1 * LX
    End If

    LY = GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y * 100
    LY1.Text = LY
    MC1.Velocity(0) = LX
    MC1.Velocity(1) = LX

    'Right Joystick
    RX = GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.X * 100
    RX1.Text = RX

    RY = GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.Y * 100
    RY1.Text = RY

End Sub

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Controller()
End Sub
End Class

还有一件事。电动机控制器用于控制用于飞行ROV的电动机。当左摇杆向左移动(Negetive值)时,电机0将反向移动,1将向前移动以进行某种“点转向”,反之亦然,以便将左摇杆向右移动。此外,y轴一次控制正向或反向。

0 个答案:

没有答案