infratag / irsniff

Arduino project to read and report infrared laser tag packets from Recoil laser tag toys made by Skyrocket, LLC
MIT License
6 stars 1 forks source link

Invalid pulse length error #1

Open flatsiedatsie opened 2 years ago

flatsiedatsie commented 2 years ago

I'm testing your script, but an getting these errors:

IRSniff ready.
Invalid pulse length at pulse index 2 (394, 197): 1576 48 1376
Invalid pulse length at pulse index 26 (804, 402): 3216 1564 428 368 432 364 432 364 828 368 432 372 424 764 828 764 436 368 428 360 460 344 432 360 452 352 1504 80
000100111000000011001 invalid
110100111000000010011 invalid
011100111000000010000 invalid
01110011000000000000 invalid
101100111000000011010 invalid
Invalid pulse length at pulse index 6 (824, 412): 3296 1480 908 312 484 720 2492 692 908 688 476 316 480 316 476 320 484 320 476 316 472 324 480 316 888 712 468 328 880 308 484
001000111000000011100 invalid

Could it be the receiver I'm using?

1838 - 37.9KHZ

37.9 seems very close to 38khz, but perhaps that .1 difference is the culprit?

The gun isn't paired at the moment, is that required? I also don't have the LED's attached. Could that influence the timing?

flatsiedatsie commented 2 years ago

Success!

17:57:33.092 -> 111000100001100010110 
17:57:33.092 -> in decode printPacketInfo
17:57:33.092 -> 
17:57:33.092 -> gun shot 5, shooter 2

So it seems the gun must be connected.

For my project I don't need to the guns to be connected, as it's not about actual laser gaming/recoil, but more about a fun-fair style shooting gallery.

Would it theoretically be possible to:

BenjaminPelletier commented 2 years ago

It's unfortunately been a while since I've looked at this project so take my answers with a grain of salt and let me know if/when they don't make sense :)

The "Invalid pulse length" happens when the measured pulse lengths don't follow the expected pattern. For your first example, the detected pulse lengths were 1576us, 48us, 1376us. This doesn't seem even close to the expected pattern since the first pulse is far too short (about half the expected length) and the second pulse is 10x shorter than it should be -- I'd expect this was probably spurious noise, either from some other IR remote, or perhaps electrical. If it's electrical, there's a small chance adding a >= 0.1uF capacitor between the ground and power legs of your receiver might help.

For the other two invalid pulse lengths, it looks like you're getting a valid signal that is just corrupted in places. If you have an oscilloscope, seeing the trace on the output of the receiver would probably help identify the issue, but the most likely issue is just that the receiver isn't seeing a strong enough signal for some reason. Not pointing right at the receiver, being at the wrong angle relative to the receiver, being too far away, etc could all cause this problem. The long binary strings with "invalid" are a similar issue -- a series of pulses looked like a reasonable signal, but failed a check to see if the data was reasonable (probably due to a corrupt signal).

The LEDs should not influence timing at all.

If your receiver is like this one, then the -3dB (half-strength) bandwidth is about 3 kHz, so a difference of 0.1 kHz should make very little difference.

I'm afraid I don't remember the specifics of gun behavior control -- I don't think I ever looked at what happens when a gun isn't paired. I did make a lot of progress on controlling the gun behavior via Bluetooth (setting shooter/gun identity, etc), but apparently I didn't get it to the point of being polished enough to publish in a repo. The application I wanted to use this hardware for was a WiFi-connected laser tag system to enable interesting interactive game modes, so I always wanted something to be paired with the gun. But honestly, it was a pretty big pain to try and wrangle Bluetooth connections to a bunch of different phones for game prep, so if I continued the project today, I'd probably look into making custom ESP32-based Bluetooth controllers that could be strapped to the gun and connect to the gun's Bluetooth and the external WiFi at the same time. I haven't done that though; I've only done Bluetooth pairing with phones.

Would it theoretically be possible to: Detect individual guns?

Yes, absolutely, but each gun may need to be paired and commanded via Bluetooth to use a particular identity.

Would it theoretically be possible to: Detect the accuracy of the shot somehow?

Sort of maybe? The receiver is digital and can't give a signal strength indication (which would relate to accuracy). There might be something clever you could do with frequency of invalid packets (occasional invalid packets means the beam is somewhat off, mostly-invalid packets with occasional valid packets means the beam is pretty far off), but I don't think that would be particularly robust. What I would do is make an array of IR receivers spaced a few inches apart (depending on shooting gallery distance/size) and detect which ones received a valid packet. But, that means you'd need many receivers per target.

flatsiedatsie commented 2 years ago

Thanks for your detailed reply! It's appreciated!

The "Invalid pulse length" happens when the measured pulse lengths don't follow the expected pattern

I believe I've figured this one out. Then the gun is not paired, the pulse length is way longer (3000) vs when it's paired. So it was probaby just that.

a difference of 0.1 kHz should make very little difference.

Indeed, after the pairing I received valid data.

but each gun may need to be paired and commanded via Bluetooth to use a particular identity

yes, that's also what I found after testing. Unpaired guns all sens the same code. Although, not completely. Two guns gave me three codes somehow.

110100111000000010011 
110100111000000010011 
110100111000000010011 
011100111000000010000 <- anomaly
000100111000000011001 
000100111000000011001 
000100111000000011001

Would it theoretically be possible to: Detect the accuracy of the shot somehow?

Turns out I could answer my own question again :-) I tried connecting the universal IR receiver to the analog port of the arduino, hoping to be able to change the code to still discern the gun code, but only if the intensity it strong enough. But that was not possible. It seems the IR receiver has boolean output? It kept receiving the code perfectly, even if randomly aimed at walls in the room. But not what I needed. Even wrapping it in a toilet roll didn't work. Impressive tech.. but not what I needed.

I then tried another IR sensor from a line-detector board, wrapping the emitter LED in some cardboard. This time it worked perfectly, only giving low values if the gun was perfectly aimed at it.

This solution means I won't be able to detect individual guns... but that's ok. It will still be fun.

So now i have to un-order 20 universal IR receivers and order 20 line-following boards :-D

if I make any improvements to the code I'll share them back with you. Oh and about that old code you didn't finish: release early, release often! I've been looking into code that does exactly what you describe, so I'd love to have a look, even if just eductionally.

flatsiedatsie commented 2 years ago

Would you mind if I asked about something tangential?

The second hand guns I bought came without the clip-on parts. I was thinking perhaps I could make them myself with some old headphones and IR modules. Do you have any experience with those clips?

BenjaminPelletier commented 2 years ago

It seems the IR receiver has boolean output?

Yes; receivers like these output a binary signal -- basically "is 38 kHz IR present or not?"

if I make any improvements to the code I'll share them back with you

Awesome, thanks!

I've been looking into code that does exactly what you describe, so I'd love to have a look, even if just eductionally.

I'll see what I can remember & put together in a semi-coherent form :)

This contains more information than I would have written down :)

Do you have any experience with those clips?

I have many of these clips and I believe they're just those 38 kHz binary detectors. The plugs are standard 3.5mm stereo plugs and I'd be a bit shocked if the pins didn't correspond to ground, power, and signal, pin-for-pin match to the 38 kHz receiver. My expectation is that the gun essentially listens to all of its sensors at the same time (any time 38 kHz IR is detected by any sensor, the gun considers 38 kHz IR to be present). If a sensor is plugged into the port, I think it just provides a larger IR detection surface for the gun but doesn't change anything else. If those guesses are correct, you could certainly make your own clips fairly easily. I don't know the pinout, but I would expect it to be fairly easy to determine: make a 3.5mm plug to pigtail, then measure the voltage between each of the 3 combinations of 2 pins. I suspect measuring the voltage between signal and power will not yield a strong voltage (if signal on the gun is a high-impedance input), in which case a good 5V (or maybe 3.3V) will only be found when measuring from ground to power (making the third pin signal). But if the same voltage difference is measured on 2 of the 3 pin combinations, there is another test that could determine which pin is which.

Is that what you were interested in?

flatsiedatsie commented 2 years ago

If a sensor is plugged into the port, I think it just provides a larger IR detection surface for the gun but doesn't change anything else.

I was hoping it could be routed to a player's back, as without those sensors you're not really able to shoot someone from behind, which is a bit of a miss (literally).

It turns out you can purchase IR receivers with 3,5mm jacks. My guess is there's no need for hacking :-) https://aliexpress.com/item/32966595984.html https://aliexpress.com/item/32830738047.html

Well, maybe 3D printing a clip. Maybe attach it to a belt or neck clip-on.

This contains more information than I would have written down :)

You're right, I've found some useful resources too. Even better, I've found a Web Bluetooth based project: https://scope-lasertag.glitch.me/

With that there's no need to install an app. The big downside is that it only works on Android phones.

It's source code can be found here. Pretty amazing stuff.