While Maneuvering My Aircraft, My Guns Keep Jamming! I'm Dying Up Here! Help!!!

Status
Not open for further replies.

Texas_Mike

New member
Back Story: After several years of designing the mechanical aspects of a universal DIY cockpit simulator, that attaches to any pneumatic piston executive office chair, I'm ready to tackle the basic joystick coding. My mechanically redesigned Thrustmaster HOTAS X PS3 joystick has a 12" extension tube added between the joystick base and hand grip. This extension greatly increases the pilot's bio-mechanical input precision. It also amplifies the Thrustmaster dead zone coding, so the centered hand grip dead zone, easily occupies a 3 1/2" hand grip travel area.

So I've turned to Teensy and the various joystick coding examples. I'm a noob (as you have guessed) and have pieced together two versions of similar code that almost work. I am slowly learning. Any help would be most appreciated by me and your assistance will be very appreciated by others, when I publish on Instructables.com later this year. There are a lot of flight sim builders and users out there, looking for inexpensive equipment setups that deliver higher price tag precision performance.

I complied the two codes using Arduino IDE 1.8.13 and Teensyduino 1.53.
The code was configured to run on;
Board: "Teensy 3.2/3.1"
USB Type: "Keyboard + Mouse + Joystick"
CPU Speed: "96 MHZ (overclock)"
Optimize: "Faster"

Testing is done on Windows 8.2. Will test on Windows 7 and 10 later.

Note: I added a 0.1uF 50V Ceramic Disc Capacitor (six total) to each pin of the six analog inputs (A0 thru A5). Also, A4 is not connected to a pot but has a lead wire with capacitor for future usage. This has all been soldered onto a small perf board and there doesn't seem to be any opens or shorts.

I have deliberately stayed away from changing any Arduino or Teensy files to make it easier for others to replicate my results, in the future.

Code version #1 includes Bounce.h and it almost works. Everything looks ok in joy.cpl but in "World of Warplanes", my guns (button #1 on 3.2 Teensy digital pin #0) jam sporadically. There doesn't seem to be an observable timing pattern to their jamming or un-jamming. Opening and closing the trigger (button #1), doesn't always resume the gun action. Maneuvering the aircraft (slewing pot axes) seems to make button#1 open sooner but it will still open without slewing the pots. When the button opens, my keyboard "spacebar" still activates the game's aircraft guns without regard to my pot slewing. This seems to be the only problem with version #1.

Note that in both code versions I have commented out (//) the hat switch codes for 45, 135, 225 and 315 degrees, because I couldn't get the Thrustmaster hat switch to read two hat buttons at once. I have an old TM hat switch and plan on examining it closely to determine if it is a 4-way or 8-way mechanical design. The TM hand grip is a PS3 HOTAS X.

Code version #2 does not include Bounce.h and it doesn't pass the joy.cpl test for various reasons, although the pots do slew and buttons 1 thru 10 (D0 thru D9) light up.
1 - The onboard Teensy 3.2 LED is dimly lit. This isn't the case with code version #1.
2 - Button #14 according to joy.cpl is constantly lit. This isn't the case with code version #1. I only have 10 buttons (D0 thru D9) plus the 4 buttons in the hat switch (D20 thru D23) hooked up.
3 - The "HU" arrow is always lit on the hat indicator of joy.cpl and doesn't change when operating the hat switch. In version #1 in joy.cpl, "HU" would only have an arrow when "HU" button D20 was pushed.

Thanks ahead of time for any assistance.

Both codes are below as well as a CAD PDF of the 3.2 Teensy and HOTAS X wiring schematic.
 

Attachments

  • 3.2 Teensy HOTAS X Schematic.pdf
    86.9 KB · Views: 59
  • version_1.ino
    6.1 KB · Views: 40
  • version_2.ino
    3 KB · Views: 40
Follow-up to Hat Switch inquiry: Yes, the Thrustmaster HOTAS X PS3 definitely has an 8 way switch. I took one apart and tested it. So now I have to find out what I'm doing wrong with the code. Any help would be appreciated. Thanks
 
Update
Code version #1 above with the intermittent Gun Trigger (joystick button #1) on pin #0 was fixed by setting the "debounce time" from 10 ms to 0 ms. I still haven't gotten the hat switch to read 8 ways, only 4 ways. I also noticed in the game test that there seemed to be a little lag in the response to axes slewing, so I changed the loop () delay from 5 to 50. It might be my imagination but axes response seems faster.

I'm now using the code, used by adrian and Drambit, found in post #53 of
https://forum.pjrc.com/threads/3218...use-pins-out-of-order/page3?highlight=pov+hat

I simply added the 6 analog axes inputs, adjusted the definition of buttons to pin, and changed the delay from 1 to 50. Everything works great in joy.cpl and world of warplanes.

This code is included below so that other Sim Builders (like myself) can hopefully find it and the answers they need, because no one on this forum is probably going to help you.
While reading lots of posts within this forum, I saw where several other Sim Builders had their questions ignored during the thread's active time-line. I also remember seeing an enthusiastic Arduino coder rudely informed that this forum is for Teensy only! I think he only made that one post on this site, if my memory is correct.
 

Attachments

  • 6_Axes_Joystick_with_8-Way_Hat.ino
    2.1 KB · Views: 38
Status
Not open for further replies.
Back
Top