I'm on a high school robotics team and I'm trying to code a Xbox 360 controller so that it'll controller the motors with variable speed. So far it works alright, but where I'm quite the novice coder I'd like to have more experienced eyes peer at my code and see if they can find a better way, or more effective way to do the same thing. As of now, as the code shows, when the sticks are moved it causes the value (-1 to 1) to be multiplied by 100 and sent to the motor controller as a value for its speed. A timer is also attached to continuously update the values to have the most accuracy possible. So far the only issue I've encountered is a minor dead zone at each perfect diagonal. I've pondered just coding in the diagonals just like the other directions but I've had little luck. Any pointers would be appreciated! Here's the current code:
Private Sub JoySticks()
'Left Joystick drive motor controls.
Dim LY As Integer
Dim LX As Integer
LY = GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y * 100
LX = GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X * 100
HScrollLX.Value = LX
VScrollLY.Value = LY
If LY > 0 Then
MC1.Velocity(0) = LY
MC1.Velocity(1) = LY
ElseIf LY < 0 Then
MC1.Velocity(0) = LY
MC1.Velocity(1) = LY
ElseIf LX > 0 Then
MC1.Velocity(0) = LX
MC1.Velocity(1) = LX * -1
ElseIf LX < 0 Then
MC1.Velocity(0) = LX
MC1.Velocity(1) = LX * -1
ElseIf LX Or LY = 0 Then
MC1.Velocity(0) = 0
MC1.Velocity(1) = 0
End If
End Sub
Private Sub TimerJoysticks_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerJoysticks.Tick
JoySticks()
End Sub