JRomainG/Driving-Force-Shifter-USB-Adapter

Funky X values in 4th gear

Lefa100 opened this issue · 7 comments

Hey! I recently got this project working-ish after some jvm.dll hurdles...however, when I'm in 4th gear, I get X values that exceed the values I get when I'm going to 5th or 6th gear. Reverse isn't working either, but I think that's got something to do with my wiring.
Anyhow, is there a way to fix this and to get my 5th and 6th gear usable?
Thanks in advance!

Hi @Lefa100!

If you're still having issues with jvm.dll, and you have an Arduino board compatible with the ArduinoJoystickLibrary, you can try out this separate branch.

For the reverse gear not working, if 5th and 6th gear are working correctly, there probably is an issue with the wiring to digital pin 2 on the Arduino. You may have simply connected the wrong pin (on the Arduino or the DB9 plug of the shifter), or it may be an issue with the soldering or a broken cable. You can try testing continuity with a multimeter for example, it might give you some ideas.

Regarding your main issue, I don't see any good reason why this would be happening in the software, so it must be a hardware issue. I'm assuming you flashed Test_Arduino_Shifter.ino to see which values were read in each gear? Could you paste some extracts of the output?
Do you see a consistent pattern in the X value displayed in 4th gear? If it always behaves in the "same weird way" and you just want to get it working, it should be easy to patch the software to handle your unusual X values. I can help you with that, if you have more details about the various values read by the Arduino.

Thank you for the swift response @JRomainG!
Looks like I had made an error in my original post; it is the X values of the 3rd gear that are causing me issues. Reverse also doesn't register as is_reverse, though I didn't notice anything wrong when I checked the wiring. But anyways, I flashed the test file on to my Uno and got the following values:

Neutral: x: 243, y: 440, is_reverse: 0
1st gear: x: 176, y: 735, is_reverse: 0
2nd gear: x: 103, y: 305, is_reverse: 0
3rd gear: x: 349, y: 746, is_reverse: 0
4th gear: x: 181, y: 291, is_reverse: 0
5th gear: x: 459, y: 753, is_reverse: 0
6th gear: x: 226, y: 299, is_reverse: 0
Reverse: x: 272, y: 379, is_reverse: 0

As for the UnoJoy library issues, those were solved by simply uploading the code to my Arduino Uno via an Ubuntu VM instead of Windows.

From what I'm seeing, it seems like the odd gears (with a high y value) seem to have a different x threshold than the even gear. It's not too much of an issue as it can be patched in the software, it's just a bit unexpected.
At this point, I think that if you can get the is_reverse flag to work, then tweaking G29_Shifter.ino would be enough to get it to work properly. Apart from a wiring issue, I'm not too sure what advice to give you on that...

Right, I see. Using these thresholds I was able to get gears 1-4 working, but 5 and 6 didn't work because of the x values.
XAXIS_LEFT_THRESH 150
XAXIS_RIGHT_THRESH 250
YAXIS_UP_THRESH 700
YAXIS_DOWN_THRESH 350
Any advice on how I could modify the .ino?

I tried finding some good offset with a small Python script based on the x and y values you gave me:

from enum import Enum

class Gear(Enum):
    Neutral = 0
    First   = 1
    Second  = 2
    Third   = 3
    Fourth  = 4
    Fifth   = 5
    Sixth   = 6
    Reverse = 7

def guess_gear(x: float, y: float, is_reverse: bool) -> Gear:
    if y > 700:
        if x < 250:
            return Gear.First
        elif x < 400:
            return Gear.Third
        else:
            return Gear.Fifth
    elif y < 400:
        if x < 150:
            return Gear.Second
        elif x < 200:
            return Gear.Fourth
        else:
            if is_reverse:
                return Gear.Reverse
            else:
                return Gear.Sixth

    return Gear.Neutral

test_coords = {
    Gear.Neutral: (243, 440, False),
    Gear.First:   (176, 735, False),
    Gear.Second:  (103, 305, False),
    Gear.Third:   (349, 746, False),
    Gear.Fourth:  (181, 291, False),
    Gear.Fifth:   (459, 753, False),
    Gear.Sixth:   (226, 299, False),
    Gear.Reverse: (272, 379, True),
}

for gear in test_coords.keys():
    coords = test_coords[gear]
    guessed_gear = guess_gear(*coords)
    if guessed_gear == gear:
        print(f"[OK] Guessed gear {guessed_gear} for {coords} matched expected {gear}")
    else:
        print(f"[FAIL] Guessed gear {guessed_gear} for {coords} did NOT match expected {gear}")

It works fine, the only issue being that your is_reverse is always 0, so the Reverse gear would still not be detected.
Nevertheless, I adapted the original .ino file to match the behavior of this Python script: see the attached file (I had to rename it with a .txt extension instead of .ino otherwise Github doesn't support upload).
Let me know if that helps!

Thank you so much! It works really well!
I think I'll be using my steering wheels paddle for going into reverse, for now at least. :D

Glad to hear that! I'll close this issue then, but feel free to reopen it if need be (or to open a new one if you have another issue).
Have fun! :)