dmadison / Sim-Racing-Arduino

A library to connect sim racing peripherals to Arduino development boards
GNU Lesser General Public License v3.0
65 stars 7 forks source link

Wrong button triggered too easily, coordinates are skewed #16

Closed hnry closed 5 months ago

hnry commented 5 months ago

Firstly, @dmadison thank you for all the work you've put into this.

I'm finding it very easy to get the wrong button as a result of 2 issues. 1- the coordinates to trigger a button are too eager for the top row. 2- the coordinates are too skewed to the left.

image

Crude diagram showing what I'm seeing. BLACK = physical plastic molding boundary internal of the shifter. RED = trigger point, and what gear it'll trigger as.

Top row triggers too early especially on 3, I'm barely past or close to the internal plastic housing and it'll trigger gear 3. And all the mistriggers have the same shifted to the left characteristic.

Another perspective: image I need to be intentional and hold left as I go down or up and "ride" the edge of the plastic housing left. Even a motion of left and down will be the wrong gear even though clearly I'm 'locked' inside the housing for gear 1 or gear 2.

The problem does not occur when hooked up directly to my logitech wheel.

I'm wondering if it's because every shifter is different and it'll report slightly different values for x, y? I'm guessing I can just add a offset for my specific shifter? If you could point me in the right direction that'll be great!

dmadison commented 5 months ago

Hello @hnry, and sorry you're having issues. I'm assuming you're using a Logitech G29 / G920 shifter?

If you could, please provide some more information:

hnry commented 5 months ago

Shifter is this one, https://www.amazon.com/gp/product/B00Z0UWV3O/ I actually followed your YouTube guide for the setup. I'm using the latest version of everything (Arduino 2.3.2), your sim racing lib 1.1.4 via the IDE manager, joystick library 2.1.1 via repo master zip. And using the included example sketch 'ShiftJoystick'.

I've double checked the wiring, but here is a picture incase I missed something...

image

The shifter itself seems fine plugged into the wheel. I do have another Leonardo I can test with, so I'll try that too same thing, but didn't re-do my wires, just swapped boards.

Otherwise, I don't know too much about Arduino, but I'm guessing from the sketch I can call shifter.setCalibration() ? which would call this https://github.com/dmadison/Sim-Racing-Arduino/blob/master/src/SimRacing.cpp#L786

hnry commented 5 months ago

Examples/ShiftPrint sketch

Shifted into 3rd [3] - XY: (549, 708) // straight up (but triggers too early)
Shifted into neutral [0] - XY: (546, 631)
Shifted into 4th [4] - XY: (548, 187) // straight down

Shifted into neutral [0] - XY: (585, 260)
Shifted into 1st [1] - XY: (346, 708) // pulling left along the edge of the housing to get 1
Shifted into neutral [0] - XY: (350, 631)
Shifted into 2nd [2] - XY: (330, 187) // pulling left along the edge of the housing to get 2
Shifted into neutral [0] - XY: (375, 260)

Shifted into 3rd [3] - XY: (381, 708) // within gear 1 housing, very early, barely left Neutral, should be 1
Shifted into neutral [0] - XY: (428, 631)
Shifted into 4th [4] - XY: (376, 187) // within gear 2 housing, should be 2 (left, down)
Shifted into neutral [0] - XY: (382, 260)

(Removed 'currently in neutral' prints, line breaks mine)

First part can show the top row triggering too early, going up to 3 from N difference of 70y~, but going down 4 from N is 450y~

Part 2 & Part 3 shows x difference 346 (is good) vs 381 (is considered 3rd, but 3rd gear is around x: 549~ according to straight up in part 1. Same for gear 2 & 4 x value, 330 (good) vs 376 (bad) vs x: 548 for straight down N->4.

hnry commented 5 months ago

Sorry for notification again, decided to fiddle more, first time around Arduino so not all obvious to me. But I realized you already had the foresight to add in calibration https://github.com/dmadison/Sim-Racing-Arduino/blob/master/src/SimRacing.cpp#L867 here, and it's easier to just call that. In which case it works better than plugging it directly into the wheel now.

I'm still not sure if there's something I specifically did to necessitate this. Or if everyone's unit is a little different. Closing this but if you have any thoughts about that I'd be interested to hear.

Calibration guide for any future users

  1. In Arduino IDE, open up the ShiftPrint sketch (menu File -> Examples -> Sim Racing Library -> Shifter -> ShiftPrint)
  2. Add this line shifter.serialCalibration(Serial); in setup and after serial connection opens, so it looks like this: image
  3. Set board and com to the correct values for your system/device. Instructions here: https://youtu.be/ngXsOidoWhI?si=66QDMe_uORGZH74W&t=230
  4. Upload your sketch, wait a second, and open Serial Monitor window (menu Tools -> Serial Monitor). Follow the instructions: image
  5. After you are done it will give you a piece of code to copy like shifter.setCalibration( {..., ...}, {..., ....}, {..., ...}, {..., ...}, {..., ...}, {..., ...}, {..., ...}, 0.70, 0.50, 0.60); , copy it and open up ShiftJoystick (menu File -> Examples -> Sim Racing Library -> Shifter -> ShiftJoystick).
  6. Paste the line after the comment mentioning calibration inside setup() like so: image
  7. Upload this new sketch like in step 3.

At this point it should work and be calibrated (you can open up 'Setup USB game controller' in Windows to test).

dmadison commented 5 months ago

Glad you got it working!

For what it's worth, the ShiftPrint example includes the serial calibration functionality. If you send any character through the serial monitor it will run the calibration and then revert back to the normal program once it's done. That way you can run the calibration as many times as you like and test the results.

The default calibration works for most people, but everyone's shifter is a little bit different. The Logitech shifter includes an EEPROM memory chip which presumably includes some information about the calibration. Without a wheel to sniff the communications though I didn't bother trying to reverse engineer the data, and the library does not bother with it. Hence the easily accessible calibration functions.

Because your shifter seems to be running 'low' on both axes, I did wonder if you were accidentally feeding 3.3V to the shifter instead of 5V. That would explain the ~2/3 range you were seeing, and it's a fairly common issue when working with potentiometers and varying microcontrollers. But your photo shows the power connection in the right pin, and unless there's some design or manufacturing defect on your board, that pin should be the same voltage as the board reference.