Open Panzer

Community Designs => Other Open Source Projects => Topic started by: LukeZ on January 18, 2017, 08:18:27 PM

Title: Standalone Tank IR
Post by: LukeZ on January 18, 2017, 08:18:27 PM
For the fun of it I've taken some code from the TCB having to do with IR, simplified it and packaged it as a self-contained sketch for running on any Arduino Uno/Nano/or other board with ATmega328 processor.

The sketch can be downloaded here: TankIR (https://github.com/OpenPanzerProject/TankIR)

What does it do? Basically it lets you send and receive tank IR signals. All common protocols are supported: Tamiya (1/16 and 1/35), Taigen (old and new), Heng Long, and others.

Sending (ie, "firing the cannon") can be triggered in three ways:
The sketch can also control a recoil servo which will articulate whenever the cannon is fired. A Taigen muzzle flash unit can be attached, and basic sounds can also be added with an inexpensive Adafruit Audio FX board.

The next post will go into more detail.
Title: Hardware Notes
Post by: LukeZ on January 18, 2017, 08:19:59 PM
Hardware Notes

Included in the project files (and attached below) is a simple schematic in PDF format, please review it for wiring details. An Arduino Nano is shown but the pins are the same for the Uno.

To trigger the cannon fire:

"Apple" (IR receiver)
You can connect a standard Tamiya "apple" directly to your Arduino (Tamiya 53447). The Tamiya apple combines an IR receiver and notification LEDs; the LEDs already have current limiting resistors included inside the apple.

If you want to build your own IR receiver and use your own hit notification LEDs, you need to include your own current limiting resistor appropriate to the notification LEDs you choose. Most Arduinos can't source more than 40mA per pin.


IR Emitter
For the IR transmitter you can use the Tamiya IR LED that is included with the Tamiya apple, or a Taigen/Heng Long IR LED.

We have also found the Vishay TSAL6100 (DigiKey 751-1203-ND (http://www.digikey.com/product-detail/en/TSAL6100/751-1203-ND/1681338)) to be a comparable replacement to the Tamiya.

For maximum distance the IR LED needs to be driven far beyond its typical current rating, but even so it still needs a current limiting resistor. The LED will survive the high current because the IR signal is very brief. In testing we have found a 3.3 ohm, 1 watt resistor to be the best compromise between range and LED longevity.

If you wish to send repair signals it is often desired to prevent the beam from traveling very far. In this case a higher value resistor is used inline with the IR emitter - we have found 1k ohm will give you a range of just a few feet.


Recoil Servo
Attach the signal wire of your recoil servo to Arduino pin D8. The servo will perform a recoil effect movement when the cannon is fired. Recoil servo adjustments (end points, reverse, retract and return times) can be set using the options at the top of the A_Setup.h file.


Taigen or similar Flash unit
A Taigen cannon flash unit can be used and will be flashed when the cannon is fired. Connect the flash signal wire to Arduino pin D6.


Sound
Up to 4 sounds can be added with the use of an Adafruit "Audio FX" board. They have several versions, you will want to use the ones with a built-in amplifer. They have a 2 MB version (https://www.adafruit.com/product/2210) and a 16 MB version (https://www.adafruit.com/product/2217).

These are the four sounds that can be played, add them to your Audio board with these names:
T01.wav - cannon fire sound
T02.wav - cannon "hit" sound
T03.wav - destroyed sound (device has received enough hits to be destroyed)
T04.wav - repair sound

These sounds will play when the cannon is fired, a cannon hit is received, the vehicle is destroyed, or a repair operation occurs, respectively.

Connect your Audio FX board trigger pins to your Arduino like so:
Audio FX Trigger Pin 1 > Arduino pin A1
Audio FX Trigger Pin 2 > Arduino pin A2
Audio FX Trigger Pin 3 > Arduino pin A3
Audio FX Trigger Pin 4 > Arduino pin A4

You don't have to add all four sounds if you don't want. Also make sure the Audio board and your Arduino share a common Ground connection, and of course both have power.

Here is Adafruit's tutorial (https://learn.adafruit.com/adafruit-audio-fx-sound-board/overview) on these boards for more information.


Firmware Notes

Compiling Firmware
The Arduino project has made and continues to make all sorts of changes to their compiler, and unfortunately this can sometimes cause problems, and this proejct is one of those cases. The code will compile but will not always be stable or operational. If a non-compatible version of the Arduino IDE is used, the most common sign that problems will occur is if you see see a compile message to the effect that "global memory usage is over 90%," with the warning "Low memory available, stability problems may occur." And indeed, stability problems will occur.

Here is the workaround:

Load this project in the Arduino IDE. Go to the Tools menu -> Board -> Arduino AVR Boards -> select "Arduino Nano". Note that this will still work with a UNO even though you select Nano.

Now once again go to the Tools menu and select Board -> Boards Manager. Wait for the Boards information to load, then find the "Arduino AVR Boards" section. Click the "Select Version" drop-down box and select version 1.6.20 (not 1.6.2) and then click Install. After installation has completed, click Close to close the Boards Manager, and then compile.

The compiled code size should show global memory usage somewhere in the 70% range with no warning about instability problems.


Firmware Settings
Within the sketch is a file called "A_Setup.h" (it will appear as a tab in your Arduino editor). That is where all user settings can be adjusted. Recoil servo, IR protocol selection, "weight class" and other settings are defined here. There are extensive notes in this file so just read through it and it should be self-explanatory. 


Troubleshooting
Leave your Arduino attached to your computer with a USB cable and open the Serial Monitor from within the Arduino IDE to see informational messages printed during operation.
Title: Re: Standalone Tank IR
Post by: Rileyelf on May 24, 2017, 02:17:27 PM
Hello, new bloke here!

I designed my own Arduino powered tank battle system a while back, great to see this project!    I did a cut down version like this specific part to run a Panzerturm...  This runs a servo for a random time, fires the cannon then rests for a reload period and starts again.   Adds an interesting feature to the battleground!    I have also designed my own tank sound system which works pretty well.

Here's a video of the Panzerturm during dev....

https://www.youtube.com/watch?v=LaTYOzBSGUo (https://www.youtube.com/watch?v=LaTYOzBSGUo)

Drew.
Title: Re: Standalone Tank IR
Post by: LukeZ on May 25, 2017, 12:36:52 PM
I've always known there were others working on Arduino tank projects, it's been nice to meet several of you recently. That's a good idea for your autonomous Panzerturm. A similar functionality could be added to the TankIR sketch, it is already set up to control up to 4 servos, right now only a single one is being used for the recoil. One of the others could be set to turret rotation and then as you did code it to turn and fire randomly. If you or anyone else would like to add these or other features don't hesitate to submit a pull request to the GitHub project.

I'm sure many people would be even more interested in your sound project. If you want to share more details about that feel free to start a thread in the Sound Forum (http://openpanzer.org/forum/index.php?board=8.0).
Title: Re: Standalone Tank IR
Post by: Wibbly on November 16, 2017, 02:50:53 AM
I built a standalone artillery gun, all of the IR cannon and hit functionality works, the gun is triggered via a microswitch acting as a hidden landmine, so when a tank runs over it, the gun is fired from a short distance away. Tanks can fire at the installation, and the led's flash in the diorama.

So far so good.

The one thing missing is a cannon sound.

To create a test bed I used a separate Uno and downloaded this sketch:
http://www.instructables.com/id/Audio-Player-Using-Arduino-With-Micro-SD-Card/ (http://www.instructables.com/id/Audio-Player-Using-Arduino-With-Micro-SD-Card/)

Quote
*/

#include <SPI.h>       //Enable use of SD library
#include <SD.h>        //Read MicroSD card
#include <TMRpcm.h>    //Play music from MicroSD card


//This value is assumed by the TMRpcm library, so I don't recommend altering it!
const int SD_ChipSelectPin = 4;

//Plug the speaker's red (non-GND) wire into this pin on the Arduino
//TMRpcm assumes this is 9 on Arduino, so I don't recommend altering it!
const int speakerP = 9;

//File name of the WAV audio file loaded on the MicroSD card
//Remember to include the file extension (should be .WAV)
const String audioFileTitle = "music.wav";

//Create TMRpcm object
TMRpcm tmrpcm;

void setup(){

  tmrpcm.speakerPin = speakerP;

  Serial.begin(9600);
  if (!SD.begin(SD_ChipSelectPin)) {  // see if the card is present and can be initialized:
    Serial.println("SD fail"); 
    return;   // don't do anything more if not
  }
 
  //Need to convert String variable to char*, per TMRpcm documentation
  char charBuf[audioFileTitle.length()+1];
  audioFileTitle.toCharArray(charBuf, 50);
 
  //Play the test sound
  //This sound file will play each time the Arduino powers up or is reset
  tmrpcm.play(charBuf);
 
  //Report to the user
  Serial.println("Sound file played!");
}

void loop()

tmrpcm.play("test.wav");
//delay(5000);
}

which is part of this project on Instructables.

To get a decent volume I used:

Arduino Uno
PAM8403 amplifier, the version with a volume control.
Voltage regulator set to 5v to power the amplifier (a resistor could be used)
SD card

After a bit of playing around, it all works. I get the cannon sound when I press the Uno reset button.

So, I now have a tank IR system, and a sound system, but running on separate Arduino's.

Does anyone know whether I can import the sound sketch into the Tank IR sketch, and where it should go in order that I get the sound when the cannon is fired? I am also concerned regarding the wiring/circuits, eg is there a conflict between the SD card hook up and the Tank IR?


 
Title: Re: Standalone Tank IR
Post by: LukeZ on November 16, 2017, 01:49:42 PM
Wibbly, I already added support for the Adafruit sound effects board to the project (as discussed here (https://www.rctankwarfare.co.uk/forums/viewtopic.php?p=218913#p218913)), no coding required, just use the sketch from the GitHub (https://github.com/OpenPanzerProject/TankIR). Read the instructions on that page for how to interface with the Adafruit board, you can see I've also updated the schematic. It supports 4 sounds, cannon fire, cannon hit, destroyed, and repair sound.
Title: Re: Standalone Tank IR
Post by: CodeWarrior on November 06, 2020, 07:26:21 AM
I hope it's OK to add a new post to an older topic but here goes:  I have downloaded the TankIR sketch into an Arduino Mega 2560 with the intention of using it with some of the Tamiya 1/35 tanks.  While I understand that it was pieced together from several other works it's nonetheless an amazing piece of code with clearly allot of effort having gone into it. 
I implemented the schematic exactly as shown in the .pdf and the code compiled properly without any problem.  The only change which was made was to the A_Setup file where the IR_FIRE_PROTOCOL was to to IR_TAMIYA_35.  The issue is that the circuit does not indicate a hit if one is received from my Tamiya Panther nor does the tank receive a hit when the circuit fires a shell.  Can someone confirm that the the code was tested on the Tamiya 1/35 platform and that no further changes were required other than what was already mentioned?  I would guess that the code was tested and that I have some issue with my setup but I wanted to ask the basic question before digging into things further.  I really don't want to take up anyone's time on this other than to get a quick response confirming that the setup should be working with the only change required having been the one I've already made. 
I would like to make sure that the TankIR authors (Luke + others?)  know that I am very appreciative of the work which has been done on it and the fact that it was made available to all of us.
Title: Re: Standalone Tank IR
Post by: LukeZ on November 08, 2020, 01:27:31 PM
Hi CodeWarrior, my apologies for the slow reply. Yes, the firmware has been tested with a 1/35 Tamiya model, I used the Sherman but they should all be the same.

One thing you mentioned is that you compiled the code on an Arduino Mega2560 board, however the standalone TankIR (https://github.com/OpenPanzerProject/TankIR) firmware is designed for use on an Arduino Uno/Nano/328-compatible board. I don't know if that is part of your problem or if you just made a typo when describing your setup.

You can easily verify that your circuit is at least sending a signal by watching the IR emitter with a digital camera, or your phone, or by hooking up a standard LED with human-visible light to the output instead of an IR LED. This will at least tell you if the firmware is trying to do what you think it should. Beyond that there are many troubleshooting avenues to take, and where to start depends on where you think the issue probably resides.

I do believe the firmware works, so be sure to double-check your wiring and such.

Keep me posted on what you find and I'm sure we can figure out the problem eventually.
Title: Re: Standalone Tank IR
Post by: CodeWarrior on November 08, 2020, 04:05:25 PM
     Luke- I'm happy to receive a reply no matter how long it takes.  I appreciate your taking the time to write and share the benefit of your experience.
     I used an Arduino Uno with much the same results as using the Mega 2560.  I figured they were a similar core (328 I believe) and I am able to see IR shells being transmitted from both the TankIR (Mega 3560) circuit and the Tamiya Panther.  I recorded 5 IR shells from each and plugged them into a Google Sheet to compare them.  I used a WIO Terminal to read and display the IR timing in the Arduino IDE monitor.  You did a very nice job of documenting the structure of the unusual Tamiya 1/35 protocol.  With the aid of it I was able to see that the IR signal looks basically identical between the Tamiya and TankIR software.  I've included a screenshot of the first byte of so of each of the two groups of 5 signals.  The issue I'm having is that the WIO terminal only shows the first 50 marks and 50 spaces giving me 100 total bits worth of data.  It could be that the signals lose commonality after the 6th byte, although that would be surprising giving how well the two systems agree for the first 6 bytes.
     My next step will be to try the TankIR circuit on an 'Uno as you suggest.  If I can locate a true-blue 'Uno (versus a clone) I'll use that.  I don't know if clones vary much from the performance of a real 'Uno.  If that doesn't yield any results I'll log the full IR transmission of both TankIR and Tamiya systems.  I don't know why the WIO doesn't log the entire transmission but I may just write some simple code to log the whole thing.
Title: Re: Standalone Tank IR
Post by: LukeZ on November 09, 2020, 12:48:35 PM
Ok, you have made good progress already! It seems you have almost completely confirmed the similarity of the signals, which is good. The marks and spaces you have measured correspond exactly with what I have measured, and with each other.

There is some debugging code including in the TankIR project, if you uncomment these lines at around line 315 in the "Tank.cpp" file:
Code: [Select]
    IR_Decoder.decode();
    Serial.print(F("Decoded: ")); Serial.print(ptrIRName(IR_Decoder.decode_type)); Serial.print(F(" Value: ")); Serial.println(IR_Decoder.value);
    IR_Decoder.DumpResults();

It might help you see the full signal coming in from the Tamiya tank, or whether anything is being received or not. But I feel quite certain, as you surmised, that in fact the signals are no doubt the same for all 8 bytes, if you have already confirmed the first 6 (and I confirmed all 8 once upon a time!)

I'm inclined to think you might have a hardware or wiring problem since the firmware seems to be working correctly. I would double-check that you have the IR connected to the right pins, etc... (Use the camera trick to confirm that the IR is indeed transmitting). What IR transmitter LED and receiver are you using for the Arduino side - is it 1/16th Tamiya gear, Taigen, something else?

PS: In fact the 2560 (Mega) boards and the UNO (and other variants) use a different microprocessor, the former use the ATmega2560 chip and the latter the ATmega328. Of course either one can work, we use the ATmega2560 on the TCB, and the Uno for the standalone IR code. If the standalone IR code compiles on the 2560 board, that is a coincidence! Anyway, I'm sure your clone Uno is fine, I have used several without problems, and we can see from your capture that the firmware is running correctly.
Title: Re: Standalone Tank IR
Post by: CodeWarrior on November 10, 2020, 02:18:01 PM
     I did the following today:
     I took the TankIR shield off the Mega 2560 and placed it on an 'Uno.  Still no joy in terms of the Tamiya Panther receiving an IR shell.  Time to employ the trusty oscilloscope.  Looking at the 'scope trace I found that the IR LED (Vishay TSAL6100 from DigiKey) was indeed being driven with a signal.  I scratched my head for a bit and then decided to position the Panther within 10cm of the TankIR transmitter and, et voila, the Panther was shaken by a deadly infrared shell.  Success!  I recalled that I had increased the size of the IR LED limiting resistor so as to not risk overloading the IR LED.  While the WIO terminal could read the IR signal it seems that the Tamiya Panther needs a stronger signal.  Replacing the 1kΩ IR LED limiting resistor with a 3.3Ω (!) resistor, just like the schematic indicated I was to use, gave the TankIR circuit a very acceptable range for it's IR shells.  Next step was to investigate the IR receiver behavior.
     As I was already working with the o'scope I naturally attached the scope probe to the output of my IR receiver.  The receiver is a Vishay TSOP-38238, ordered directly from DigiKey.  I was not going to risk a bunch of unnecessary troubleshooting just because of having purchased potentially inferior surplus parts.  I did as you suggested and uncommented the debugging code you directed me to.  I was indeed receiving, and demodulating, IR shells from the Panther.  I monitored the 'Uno's A2 port ("Incoming hit sound trigger") expecting that it would change state if an IR shell was properly decoded.  Although I pummeled the TankIR circuit with multiple shells Port A2 never seemed to changed states. The test code in Tank.cpp did output data when a shell was fired but it seemed to stumble a bit after every 50th bit.  I decoded the first 3 bytes and included screenshots of that plus a .zip file of the test code dump in case you may have the time to briefly check them out.  Having already had more success for one day than I could handle I decided to call it quits at this point. 
    As you know I really appreciate all of the help you have given me so far.  I've already had more success than I could have hoped for in such a short period of time.

Title: Re: Standalone Tank IR
Post by: LukeZ on November 12, 2020, 01:46:53 PM
Ok, you have made good progress. We are now halfway there! Yes, the 3.3 ohm resistor is very low, but we really have to overdrive the LED in order to get any range. I have found since the signal is so brief the LED can survive it quite well.

Now for receiving. In fact what you have reported tells me that some things are working as they should. It is actually as designed that the firmware seems to quit reading after the 50th bit, this limit is set by the RAWBUF define in the IRLib.h file (around line 247, there are some comments that go with it). You also found earlier some comments on how we send the 1/35 Tamiya signal - there is also a discussion on how we decode it, starting around line 378 in the IRLib.cpp file. You will see that for decoding of this particular signal, which is really quite different from the one all other models use (including Tamiya in 1/16th scale), we actually only read the first 3 bytes (no other protocol has those same first 3, or even the same receiving pattern, so we are not going to confuse it with something else). As you found with your Excel work, the firmware is actually detecting the first three bytes we would expect: 199, 242, 192

So we can rule out hardware issues, the Arduino is reading the signal from your Panther just fine, the issue is with decoding. I've spent some time refreshing my memory about what I wrote all those years ago, but I don't see any obvious problems with the code. The debug dump that you posted was exactly what we expect and it should have recognized it.

Let's try an even more detailed debugging routine. In file "IRLib.h" at or around line 52, you will see this line, which is also commented out:
Code: [Select]
// #define IRLIB_TRACE

Let's uncomment that, and also change it because it should be named this instead (so basically just replace that line with the following):
Code: [Select]
#define OP_IRLib_TRACE

Let's also change that dump test that we already uncommented earlier. This is what you had uncommented in "Tank.cpp" at around line 315:
Code: [Select]
    IR_Decoder.decode();
    Serial.print(F("Decoded: ")); Serial.print(ptrIRName(IR_Decoder.decode_type)); Serial.print(F(" Value: ")); Serial.println(IR_Decoder.value);
    IR_Decoder.DumpResults();

Let's change that first line to this:
Code: [Select]
    IR_Decoder.decode(BattleSettings.IR_FireProtocol);

This way it doesn't try to run through every possible protocol but only checks for the Tamiya 1/35 signal, since we already know that's what we're sending it.

Now give your Arduino a hit from your Panther and let us see what the Serial Monitor shows us...
Title: Re: Standalone Tank IR
Post by: CodeWarrior on November 13, 2020, 11:19:29 AM
Luke Z-   Once again thank you for your help.  Unfortunately the TankIR circuit/software still does not recognize a hit from the 1/35 Tamiya Panther.  I made the two changes which you suggested and fired a shell from the Panther. 
     I posted pictures of a side-by-side comparison of the previous IR dump from TankIR and the dump with your suggested edits above.  The results are shown in the two .jpg’s attached below.  Not too surprisingly the two results diverged in their behavior after bit 50.  As you noted only the first 50 IR bits (start bit * 2 + 3 bytes *8 bits/byte * 2 IR bits/bit) are used anyway so this shouldn’t matter. I also included the screen dump in zip file below.  I know that no hit was sensed by TankIR because I didn’t see a change in neither port A2 nor D5 nor did I see any output in the serial monitor indicating a hit was received.  I have verified that the Tamiya Panther can fire a shell which can be sensed as a hit by putting the ‘Panther in Test Mode and having it shoot itself by firing at an IR reflective surface.
      I am a bit concerned about the statement from the compiler indicating:
“Sketch uses 25100 bytes (77%) of program storage space. Maximum is 32256 bytes.
Global variables use 1864 bytes (91%) of dynamic memory, leaving 184 bytes for local variables. Maximum is 2048 bytes.
Low memory available, stability problems may occur.”
     This should not matter as anyone compiling for this core would get the same warning and yet the software was tested as functional.  FWIW I verified that the TankIR circuit can still produce shells which register a hit on the ‘Panther.
      I remain puzzled by the apparent inability of my TankIR implementation to receive infrared hits.


Title: Re: Standalone Tank IR
Post by: LukeZ on November 13, 2020, 03:36:51 PM
Ok, I see the changes I suggested weren't sufficient, if it had worked it would have given us even more information about what exactly is causing the decoder to fail to identify the signal, but it would not have changed any inherent ability.

However, this comment caught my attention:
I am a bit concerned about the statement from the compiler indicating:
“Sketch uses 25100 bytes (77%) of program storage space. Maximum is 32256 bytes.
Global variables use 1864 bytes (91%) of dynamic memory, leaving 184 bytes for local variables. Maximum is 2048 bytes.
Low memory available, stability problems may occur.”

In fact that should not happen, and to avoid that very situation is why we only decode the first 3 bytes of the 1/35th signal. Did you perhaps change the value of RAWBUF around line 246 in IRLib.h? That is the only thing I can think of that would blow up the global variable allocation (the value of RAWBUF should be 51). In fact the sketch should compile with something around 1,462 bytes of dynamic memory, around 71% of the total, not 91%.

Here is what I would suggest next - redownload the firmware from GitHub and start again clean, change only the IR_FIRE_PROTOCOL to IR_TAMIYA_35 in the A_Setup.h file, and try again and see what happens. If it still doesn't work, I will give you a sketch with the extra debugging options hopefully enabled this time.
Title: Re: Standalone Tank IR
Post by: CodeWarrior on November 14, 2020, 10:08:31 AM
Thank you for your extremely quick reply.  I did as you suggested: Reloaded TankIR from Github with the only change being made is to change IR_FIRE_PROTOCOL to IR_TAMIYA_35.  With just this being made compiling the code yielded the same statement from earlier:

“Sketch uses 25014 bytes (77%) of program storage space. Maximum is 32256 bytes.
Global variables use 1864 bytes (91%) of dynamic memory, leaving 184 bytes for local variables. Maximum is 2048 bytes.
Low memory available, stability problems may occur.”

This caution was present in the original code from the first time it compiled.  The behavior of the system with the reloaded code is the same as with the previous code:  The TankIR shells cause damage to the Tamiya Panther but there is no effect on the TankIR circuit from the ‘Panther shells.
You are right to think that I might investigate/consider changing RAWBUF to a larger value- I noted that the max value would be 255.  I figured this would not help the understanding of the issue as only the first 50 bits are read by TankIR to recognize a hit.  Because of this I didn’t make any changes other than what we discussed.
I’m wondering if there may have been changes made to the Arduino IDE which somehow altered the manner in which the code compiles.  It may be hard to see in the screenshot- I am using version 1.8.13 of the Arduino IDE.  I have included a screenshot of my Arduino IDE so you can see the compile environment being used.  It will be obvious that I use a "Dark Mode" color scheme as I find it a bit easier to view than the stock offering.  This should not have any effect on the compiler itself.
Title: Re: Standalone Tank IR
Post by: LukeZ on November 14, 2020, 12:05:19 PM
I’m wondering if there may have been changes made to the Arduino IDE which somehow altered the manner in which the code compiles.  It may be hard to see in the screenshot- I am using version 1.8.13 of the Arduino IDE.
I started thinking the same thing after I posted earlier. Since you haven't changed anything else, the only difference must be the IDE. I am using 1.8.5 which is actually prior to 1.8.13.

I've posted below a compiled version of the code from my IDE which only uses 71% of dynamic memory, and I changed the IR type to IR_TAMIYA_35. Can you give this one a test and see if it works? You can flash a hex file to your UNO using OP Config, on the Firmware tab select "Generic ATmega328" and then click the "Use your own Hex" button to select this file, then the "Flash" button to write it to your Arduino.
Title: Re: Standalone Tank IR
Post by: CodeWarrior on November 16, 2020, 08:45:39 AM
Luke- Success!  Using your code, without my Arduino IDE compiler in between, did the job!  I was able to both transmit and receive IR shells to and from my 1/35 Panther.  The flash effect for the hit LED was very nice.  Well done!  BTW- I checked for a reply yesterday from you but did not realize that our thread had reached a second page.  My bad.  I must report that I was not successful in using OP Config to upload the .hex code (screen snip attached).  Maybe that's the subject for another post once I thoroughly worked through OP Config to see what I might have done wrong.   Apparently I have bad luck everywhere with these things.  I used the process which was described here https://forum.arduino.cc/index.php?topic=410618.0 (https://forum.arduino.cc/index.php?topic=410618.0) with success (one exception: ensure the file path has no blank characters in it.)
     I have downloaded Arduino IDE 1.8.5 and will try it to see how things work with it.  I will report back with the results.  IDE 1.8.5 is many generations before 1.8.13, sequential numbering being the way that it is.  I'm just curious why you do not use the latest releases, other than the fact that it apparently breaks good, working code?
Title: Re: Standalone Tank IR
Post by: CodeWarrior on November 16, 2020, 03:41:59 PM
     I tried compiling the code using the Arduino 1.8.5 IDE, not installed using windows installer but just as a desktop client on my main laptop (I'll call it laptop A).  This yielded the same results as compiling with 1.8.13- TankIR is not able to register hits from the Panther.  The compiler output stated:

"Sketch uses 25014 bytes (77%) of program storage space. Maximum is 32256 bytes.
Global variables use 1864 bytes (91%) of dynamic memory, leaving 184 bytes for local variables. Maximum is 2048 bytes.
Low memory available, stability problems may occur."

     The only remaining differences that I can think of are the files which are included as part of the compile process which are not directly provided by GitHub.  There are only two of these:

#include <Arduino.h>
#include <avr/interrupt.h>

    Of these I suspect that it may be the interrupt.h file which is causing me the problem.  I went ahead and did a Windows installation on another machine (laptop B) after having deleted the existing 1.8.13 installation and all folders related to the Arduino IDE.  I used another machine as I didn't want to disrupt the other Arduino work I had going on laptop A- although not currently working on.  No joy.  It is clear to me that there is something wrong with my IDE, or at the very least different, between my Arduino IDE installation and yours.  Let me know if you have any thoughts as I would really like to be able to tailor the TankIR code to suit my needs.  On the other hand I fully understand if time does not permit you to offer much more help.  You’ve helped me immensely already.  I suspect that others have tried TankIR with more success than I.  Can you tell me if you know of other users which have had success with it?
Title: Re: Standalone Tank IR
Post by: LukeZ on November 18, 2020, 11:33:24 AM
Hi CodeWarrior - thanks for reporting back, it seems you have pinpointed where the problem must lie, and that is something to do with a difference between my IDE and yours.

You asked why I didn't use the most recent IDE for development, but probably several years ago when I posted the TankIR project 1.8.5 was about the most recent. But they release new versions all the time, and quite frequently code that worked on one version won't even compile on a later version, or have other issues as you have discovered, so if I get something working I rarely have much of an incentive to go back and break it.

But the strange thing this time is that you've tried IDE 1.8.5 and it doesn't seem to have made a difference as to how much memory the sketch takes when compiled (for you at least). I would be curious to see a file from your computer, it is called "platform.txt" and should be located here:
YourArduinoInstallDirectory\hardware\arduino\avr\platform.txt

If you could post that text file here I will take a look at it, and see if it matches mine in terms of Link Time Optimization (LTO) settings.

You asked if anyone else had used this project - WibblyWobbly at RC Tank Warfare is the one who has had the most experience with it, he has a thread here (https://www.rctankwarfare.co.uk/forums/viewtopic.php?f=208&t=22849) which you may have already seen.

I can also do some testing on my end and try to install the latest IDE and tinker around and see what I can discover. Ideally we would like to get this to compile in a functional manner with the latest version, now we know there is a problem.

Unfortunately at the present moment I am in the midst of moving across the globe and I won't be to my new place until next week, but then there is Thanksgiving, so I can't promise I'll have time to look at this in more depth until after the holiday.

However I haven't forgotten about this and I would like to get it sorted just for my own peace of mind, so I will definitely return to this topic when the dust has cleared.
Title: Re: Standalone Tank IR
Post by: CodeWarrior on November 18, 2020, 12:26:21 PM
Luke-   I have attached the platform.txt files for both my 1.8.13 and 1.8.5 IDE's.  Your logic on staying with the proven IDE is sound. 
     You are correct in thinking that I had seen WibblyWobbly’s comments on RC Tank Warfare.  I am known as CodeWarrior there as well.  I seem to recall some discussion about the type of sound card being used.  I tend to like  the Adafruit ‘board- it’s simple and convenient if not a bit more expensive than some of the other offerings.   I will write in to the RC Tank Warfare forum to determine how ‘Wibbly went about with his implementation.  I have had this feeling that there are only a handful of people interested in making a standalone battle unit and your input somewhat confirms these suspicions.  To my way of thinking it’s entirely logical that a solo battle unit might be a reasonable alternative when one can’t get a group of RC tankers together.  Ultimately I would like to cooperatively design a challenging solo battle system- but I’m not sure there is sufficient interest in this.
     It sounds like you're going to be rather busy for the next few weeks.  Moving is never any fun.  I wish you the best of luck with that extremely disruptive event.  Hopefully there will be some RC tankers in your new location. 
    I appreciate any input you can give me.  I’ll be looking forward to hearing from you later and will post any insights I may get here in the meanwhile.
Title: Re: Standalone Tank IR
Post by: CodeWarrior on November 23, 2020, 12:34:15 PM
Luke-  I hope all is going well with your move. 
      I am happy to inform you that I am now able to compile the TankIR sketch with it working on both sending and receiving IR shells (screenshot attached to unnecessarily provide proof).  I went ahead and uninstalled the Arduino IDE on my other laptop (laptop B) and reinstalled it letting it choose the install directory and use all default settings.  The compiler reported:

“Sketch uses 24284 bytes (75%) of program storage space. Maximum is 32256 bytes.
Global variables use 1462 bytes (71%) of dynamic memory, leaving 586 bytes for local variables. Maximum is 2048 bytes.”

     The net result of all of this is:  TankIR needs to compile on Arduino IDE 1.8.5 with the installation being done using all default settings.  I'm thinking that there were enough changes made to the compiler between 1.8.5 and 1.8.13 that the memory usage became much greater and the resulting low memory disallows properly registering a (Tamiya 1/35th) IR shell hit.

     My next step is to get a complete system working with the Adafruit FX in place and move it to a hand wired protoboard.  Assuming all goes well I will consider making a home-etched, or possibly a fabbed,  PCB to fit the Arduino form factor.  I’m thinking that others may take more of an interest in having a stand-alone battle unit if something were available off the shelf.  Even then, if something was available off the shelf I’m guessing there would not be a huge demand.  Let me know your thoughts once you’ve settled in from your move.  In the meanwhile I’ll contact ‘Wibbly to see if he, or anyone else, has used the stand-alone unit. 
      Once again thank you so much for your kindness, help and patience in getting me set up on TankIR.  Looking forward to hearing from you.
Title: Re: Standalone Tank IR
Post by: JPS99 on November 25, 2020, 06:38:44 AM
Hello, new bloke here!

I designed my own Arduino powered tank battle system a while back, great to see this project!    I did a cut down version like this specific part to run a Panzerturm...  This runs a servo for a random time, fires the cannon then rests for a reload period and starts again.   Adds an interesting feature to the battleground!    I have also designed my own tank sound system which works pretty well.

Here's a video of the Panzerturm during dev....

https://www.youtube.com/watch?v=LaTYOzBSGUo (https://www.youtube.com/watch?v=LaTYOzBSGUo)

Drew.

Sounds like you've done some interesting work. I'm always interested in seeing other people's projects and how they do things. There are so many different ways to solve a problem these days with Arduino! 

I'm building a T-35a which has a lot of turrets. I had thought of doing something to randomize motion on some of the turrets. With five to play with, it would be cool to see them all in action.

If you would care to share more photos or videos of what you have done, I'm always interested in viewing!
Cheers,
Joe
Title: Re: Standalone Tank IR
Post by: CodeWarrior on November 26, 2020, 08:38:14 AM
Joe-   I’ll start out by apologizing for the length of this post but it’s nice to relate to others with similar interests.
      Yes, I’ve been following your progress on the T-35.  It’s a very impressive effort.  I have also done a Panther PanzerTurm design from probably 10 years ago or so. 
     I have included several pictures of my past efforts.  I really enjoy designing things of all kinds- both electrical and mechanical.  My work on IR tank designs started about 20 years ago but tapered off significantly about 10 years ago.  We all know the story here: Very little time for fun when the time demands of the job became significantly greater.  Arduino was not generally known then and my designs were based on the Microchip PIC parts.  Since discovering Arduinos, and the huge amount of open-source designs out there, things have become much more easily done.  3D printers have also been a boon to us experimenters.  I have included pictures of my earlier designs, except for the PanzerTurm as I’ll have to dig that out.  They include:
    I’ve also have about a half-dozen motorized platforms, including a DF Robot Devastator  (https://www.dfrobot.com/product-1477.html), a Zumo 32u4 Robot (https://www.pololu.com/category/170/zumo-32u4-robot) and several hand-built ones I don’t have pictures of right now.
    I’m currently working on designing an IR battle system for solo (or multi-person) battles.  Luke’s TankIR is an extremely nice piece of work but I’m also nearly done with a design which will transmit and receive Tamiya 1/35 IR shells based on an ATTiny85, about the size of a grown man's thumbnail.  Idea is to use several of these to try and sense where an incoming IR round came from and move towards it, with an autonomous platform,  or at least aim at that area with a static platform.  Of course, I’ve been working this for nearly 20 years now, so we’ll see how it goes.
      If I were to get something which worked I would like to make it available to others.  I doubt there’s any money to be made at it, and I’m not looking to do that.   I’m just looking to have fun making a design that others may find useful. It would also be nice to potentially further the interest in IR tanks.
     I’m always looking for any others who may be interested in collaborating on such a design.
     As an aside- I also worked on a system for measuring RC car lap-timing based on IR signals as I occasionally run some RC cars.
     Please continue to keep us updated on your T-35 build- it looks to be a truly great effort and I admire your tenacity and vision to see it through to completion.
Title: Re: Standalone Tank IR
Post by: JPS99 on November 27, 2020, 09:57:38 AM
Hi CodeWarrior, thanks for the response.  I see you live outside of Detroit. Funny, we just moved from Ann Arbor to Erie, PA two years ago to retire.  I bought my Ender 5 at that time and learned 3D printing. My first big project was my 1/10 scale Tatra 815. You might have seen it on my Youtube channel.  Before I was even finished with it I became enthralled with Lubos Hort's  Is-1 tank which I came across on Thingiverse, and began printing it.  Both models were 1/10 scale and radio controlled. I also built TheDIYGuy999's ESP32 sound/light/motion control board for those models, as well as his 2.4ghz transmitter and micro receiver.  I really like the ESP32 boards and will also incorporate one into the 1/14 scale King Hauler I am building now.  (I know, too many projects, but Hey, I'm retired!) 

I dabble in electronics projects, but am not a designer.  There are so many great projects on the net that I'd be silly to try to design my own at this age. My focus is weakening, perhaps because I have so many projects going.  My wife bought me a keyboard for Christmas, so now I am learning to play the piano as well.  Retirement is tiring!

You mentioned PIC projects.. I recall working with Microchip's Basic Stamp. That was fun.. I was able to code in Basic, but never got into other languages unfortunately.  The only project that I've thought of lately, since I've gotten into RC modelling, is some kind of 'Convoy System'.  I will have two tanks and my Tatra and thought it would be cool if I could somehow be able to make one vehicle follow another and mimic its movements. This would open the way to some interesting video opportunities.  I have to do everything alone, so it is tough to get a nice action shot of my tank in motion, let alone two of them.  I see some interesting projects on Youtube, etc where guys have build ' RC travel cams' that ride along on a suspended cable and take video while moving along beside the subject of the video.  That looked like a fun way to capture shots.   I also have a nice little camera drone that I plan to use to capture video as well.  I also set up my iS-1 tank control system with a 'cruise control' so that I can set a speed and then set the transmitter down so I can take video. Looks like we're running out of weather for this year's outdoor fun though.

Anyway, enough foolishness from me.
Have a great Thanksgiving!
regards,
Joe
Title: Re: Standalone Tank IR
Post by: CodeWarrior on November 27, 2020, 02:12:12 PM
Joe-  Your 1/10th scale Tatra is an impressive build.  It sounds like you enjoy the creative process, both from the electrical and mechanical standpoints.  I’d be curious to know your impressions Ender 5-  I have a SeeMeCNC's Rostock MAX (https://www.seemecnc.com/products/rostock-max-complete-kit) which has fallen into disuse as the computer which I had attached to it crashed.  That would likely be a topic for another forum somewhere else. 
       I’ll have to check out DIYGuy999’s projects- I appreciate your mentioning it.  I like the ESP’s: They are very powerful ‘boards, in a small size at an excellent price. 
    I fight with having too many projects going on at once.  I’m striving to see things all the way to completion.  I too am retired and find that, since my life doesn’t revolve around work, I have much more time to get things done which I enjoy.
     Your convoy idea is intriguing and I believe it could be doable with the proper implementation.  I don’t know that the following tank could exactly mimic the lead tanks movement so much as follow it, at least with the way I could imagine designing the electronics.  I’m thinking that a photovore system, or perhaps IR-based system might work.
     From my side I got what is probably the more difficult part of the ATTiny85 battle system working.  It is now able to successfully fire an IR round at my Tamiya 1/35th Panther and have it cause damage.  I've included a .zip file of the video I shot of the circuit in action and also included some pictures of the breadboarded circuit.  I cannot say “Thanks” enough to Luke for his help.  Although the code for the ATTiny85 doesn’t include any code from the TankIR implementation it was Lukes sharing his knowledge of the Tamiya 1/35th IR protocol which made it possible. 
      I’m still a relative newb as far as forum etiquette goes.  I’m thinking this ATTiny project should perhaps be moved to it’s own topic, if it even belongs on OpenPanzer at all as it’s not an OpenPanzer offering.  I’d welcome a  response from anyone reading this who may provide some enlightenment to me.

Eric
Title: Re: Standalone Tank IR
Post by: LukeZ on November 30, 2020, 12:28:48 PM
Luke-   I have attached the platform.txt files for both my 1.8.13 and 1.8.5 IDE's.
Hi Eric, I'm back but still in the process of digging out from the backlog of emails and stuff at my job, so I have not gotten much work done but I can at least respond to your posts! I checked out the two platform files you posted and I really don't see any differences in the relevant sections, but it was worth the check.

I am happy to inform you that I am now able to compile the TankIR sketch with it working on both sending and receiving IR shells (screenshot attached to unnecessarily provide proof).  I went ahead and uninstalled the Arduino IDE on my other laptop (laptop B) and reinstalled it letting it choose the install directory and use all default settings.  The compiler reported:

“Sketch uses 24284 bytes (75%) of program storage space. Maximum is 32256 bytes.
Global variables use 1462 bytes (71%) of dynamic memory, leaving 586 bytes for local variables. Maximum is 2048 bytes.”

The net result of all of this is:  TankIR needs to compile on Arduino IDE 1.8.5 with the installation being done using all default settings.  I'm thinking that there were enough changes made to the compiler between 1.8.5 and 1.8.13 that the memory usage became much greater and the resulting low memory disallows properly registering a (Tamiya 1/35th) IR shell hit.
This is good news and thanks for being persistent. However there definitely is something weird going on because the same code should really compile to roughly the same size and in this case the difference between IDEs is not even close. I will need to do some more research and probably post a help request over at the Arduino forums, but I really would like to get to the bottom of this. Whenever I do, I will report back here what I find.

From my side I got what is probably the more difficult part of the ATTiny85 battle system working.  It is now able to successfully fire an IR round at my Tamiya 1/35th Panther and have it cause damage.  I've included a .zip file of the video I shot of the circuit in action and also included some pictures of the breadboarded circuit.  I cannot say “Thanks” enough to Luke for his help.  Although the code for the ATTiny85 doesn’t include any code from the TankIR implementation it was Lukes sharing his knowledge of the Tamiya 1/35th IR protocol which made it possible. 

I’m still a relative newb as far as forum etiquette goes.  I’m thinking this ATTiny project should perhaps be moved to it’s own topic, if it even belongs on OpenPanzer at all as it’s not an OpenPanzer offering.  I’d welcome a  response from anyone reading this who may provide some enlightenment to me.
Your ATtiny85 project is very interesting and I'm happy for you to talk about it here. This forum section we're in right now is called "Other Open Source Projects" and that was exactly the intention, to give a place for people to talk about their own creations. If you want to share more details about it then I agree a dedicated thread in this same subforum would be a good idea, since no one will think to look for it in this thread. But you are not breaking any etiquette rules and I welcome your contribution!
Title: Re: Standalone Tank IR
Post by: CodeWarrior on November 30, 2020, 02:31:12 PM
Hi Eric, I'm back but still in the process of digging out from the backlog of emails and stuff at my job, so I have not gotten much work done but I can at least respond to your posts! I checked out the two platform files you posted and I really don't see any differences in the relevant sections, but it was worth the check.
Luke-  Glad to hear that your move is complete, I suppose that now the settling will begin.  Thanks for taking the time to check out the files.

...there definitely is something weird going on because the same code should really compile to roughly the same size and in this case the difference between IDEs is not even close. I will need to do some more research and probably post a help request over at the Arduino forums, but I really would like to get to the bottom of this. Whenever I do, I will report back here what I find.
I appreciate your checking into the issue.  I would like to understand what's happening as well.  It would be most convenient to be able to use just one IDE on one machine.

...then I agree a dedicated thread in this same subforum would be a good idea, ...
Very good.  Once I make more progress on the ATtiny85 project, and have something more meaningful to report, I'll start a separate thread for it. 

     I must admit, having the public scrutiny (from all of the perhaps three people who may be reading these posts) forces me a bit to deliver on my ideas.  This could be a good thing.



Title: Re: Standalone Tank IR
Post by: JPS99 on November 30, 2020, 07:39:18 PM
Joe-  Your 1/10th scale Tatra is an impressive build.  It sounds like you enjoy the creative process, both from the electrical and mechanical standpoints.  I’d be curious to know your impressions Ender 5- 
Eric

Eric, Thanks, the Tatra was my first big project, probably took 400+ print hours. it is mechanically cool, but it's really fragile. I started my IS-1 tank because it looked a lot more robust (it is) but in preparation for building it I bought a second Creality Ender 5 because I had such reliable results with my first one.

As for TheDIYGuy999, he really supports his projects, he's up to version 5.6 on his ESP32 Sound/Light/Motion control board and just introduced and SMD version (minus the ESP32 module) which saves space. He designed it for his Tamiya King Hauler but has expanded and upgraded it and made it useful for almost anything that moves now including tanks, balancing robots, etc.  The inertia models he's built into the motion control are really impressive and the motor sound is quite configurable for a wide range of vehicle sounds. He even incorporated one I captured for my IS-1!    I also built his 2.4ghz transmitter and micro receiver because it looked fun and got me into SMD soldering. They are pretty cool and the receiver even incorporates a low power motor driver which he's used on some small scale model cars.

As for my convoy idea, my thinking is that the vehicle(s) following would maintain a set distance behind the leader and would make turns with  a time delay commensurate with the following distance and speed so that they would follow the same path (within reason) although I have no idea how to accomplish this.

I watched your video, that is very cool. The Tiny85 is a neat little device. I have a little scope something like yours.. they are pretty handy for rc troubleshooting!

Yes, Luke is super helpful, the board runs on his shoulders.  From what I've seen he is always helpful and is a pretty savvy guy when it comes to electronics and tank control systems.

So what part of Detroit are you in?  I lived in Milan, just outside of AA until Christmas 2018.

Take care,
Joe
Title: Re: Standalone Tank IR
Post by: LukeZ on April 04, 2021, 02:55:31 PM
However there definitely is something weird going on because the same code should really compile to roughly the same size and in this case the difference between IDEs is not even close. I will need to do some more research and probably post a help request over at the Arduino forums, but I really would like to get to the bottom of this. Whenever I do, I will report back here what I find.

Hi Eric, my apologies for taking such a long time to return to this issue. Unfortunately, I have not been able to find a simple resolution. I sought assistance with the Arduino team but they couldn't identify the problem either.

For now, if people want to compile this project, they can take one of two approaches:
In both cases, remember also that we are compiling for the Arduino Nano (in the IDE Tools -> Board -> Arduino AVR Boards -> Arduino Nano)

Neither approach is ideal, but the second one does offer the advantage that you can use the most recent IDE and it is fairly painless to switch back to the most recent Boards version for your other projects.

I suspect this project is not being very widely used, but for those that want to one of these methods should at least make it possible. I hope this helps, and my apologies for the hassle!
Title: Re: Standalone Tank IR
Post by: CodeWarrior on April 08, 2021, 08:02:26 AM
Luke-
      Absolutely no apologies necessary.  You do a great job running Open Panzer and supporting the many user requests.  You should know that your work is definitely appreciated. 
      I will try the solution you recommend and give you feedback once done.  I had embarked on another solution in the meanwhile using the ATTiny85 but would still very much like to get your Standalone implementation working.  It will be some time before I can work on this however due to a rather large home project I am working on.
     Thanks again for investigating this and providing a solution.
Title: Re: Standalone Tank IR
Post by: CodeWarrior on April 11, 2021, 10:01:41 AM
Luke-  I was able to compile successfully using 1.8.13 IDE and AVR board # 1.6.20.

The memory usage was as follows:
Sketch uses 24238 bytes (78%) of program storage space. Maximum is 30720 bytes.
Global variables use 1450 bytes (70%) of dynamic memory, leaving 598 bytes for local variables. Maximum is 2048 bytes.

Well done and thank you again for looking into, and solving, this.
Title: Re: Standalone Tank IR
Post by: LukeZ on April 11, 2021, 12:37:45 PM
Thank you for reporting back!
Title: Re: Standalone Tank IR
Post by: Rongyos on July 07, 2023, 04:16:24 PM
Hi Luke!

I'm just modifying the code for using relays for disconnect motors (to reduce advantages relating tamiya speed reducing function) and just dont understand the code below. After the "else" statement the HitLEDs_CannonHit object shouldn't be HitLEDs_MGHit? If yes my relay object shouldn't be there :)
Code: [Select]
if (DamagePct >= 100.0)
                {
                    // Don't let damage go above 100%
                    DamagePct = 100.0;
                                       
                    // After destruction, the tank becomes inoperative for some period of time (15 seconds is the Tamiya spec - NOT the same as recovery/invulnerability time!)
                    // After that time it will automatically recover itself. During invulnerability time, the tank can fire but is impervious to enemy fire.
                    // Invulnerabilty time is dependent on the weight class.
                    isDestroyed = true;
                    TankTimer->setTimeout(DESTROYED_INOPERATIVE_TIME_mS, ResetBattle);   // DESTROYED_INOPERATIVE_TIME_mS is defined in OP_BattleTimes.h
                    // Start the destroyed light effect
                    HitLEDs_CannonHit();   // After the cannon hit effect, because isDestroyed is true, the subsequent HitLEDs_Destroyed effect will start automatically
                    HitRelay();    //After the cannon hit effect the relay disconnect the motors. Tank cannot move
                    ClearHitRelay();
                }
                else
                {
                    // Flash the hit notification LEDs
                    HitLEDs_CannonHit();
                   HitRelay();
                    ClearHitRelay();
                    // Start a brief invulnerability timer. Each IR signal is sent multiple times, but we only want to count
                    // one hit per shot. For the next second after being hit, we ignore further hits
                    TankTimer->setTimeout(HIT_FILTER_mS, EnableHitReception);

Thanks and regards!
Rongyos
Title: Re: Standalone Tank IR
Post by: LukeZ on July 08, 2023, 03:29:05 PM
Hi Rongyos,

I don't know if I understand your question exactly, but I will try to explain this bit of code and maybe that will help you.

First of all, if we reach the code you have posted, we already know that we have received a cannon hit (not a machine gun hit).

By this point we have also already calculated our new damage percentage based on this cannon hit. All that has come before this code.

Now, in the code you posted, we have the first part of the "if" statement: if (DamagePct >= 100.0)

This means that we've added up all our damage and it's equal to or over 100%, therefore the tank is "destroyed" and must be disabled.

The second part of the "if" statement is the "else" condition: else we have been hit, and our damage has increased, but we are not yet destroyed (in other words, damage is less than 100%).

In that case we flash the LEDs in the apple that indicate a hit was received. We also enable an invulnerability timer, but only a very brief one. This is simply to prevent receiving multiple hits from a single shot of someone's cannon. As you know, the Tamiya signal lasts for a full second - that would be enough time for us to register many hits if we didn't have this brief timer.

I hope that helps!
Title: Re: Standalone Tank IR
Post by: Rongyos on July 10, 2023, 02:08:38 AM

First of all, if we reach the code you have posted, we already know that we have received a cannon hit (not a machine gun hit).

[...]

This means that we've added up all our damage and it's equal to or over 100%, therefore the tank is "destroyed" and must be disabled.

[...]
I hope that helps!

Hi Luke,

Yes, silly me tought that part of code is for determine if the hit is from cannon or MG. Thats why I didn't understand why cannon hit notification sent out to LEDS and not MG hit.
It is now clear for me, thanks.

Rongyos
Title: Re: Standalone Tank IR
Post by: Rongyos on October 26, 2023, 02:52:33 PM
Hi everybody!

I am stuck on modifying the code and cannot figure it out, I ask assistance:

I want to actively modify the WEIGHT CLASS value with a jumper which connect the pin D7 and GND (I defined the pin and pinMode as input_pullup) but cannot do so much stuff. I know the setup is in the begin() function so I dont want to modify the value of weight class during the loop.
Can you please help me where should I put a code like this? I am lost in the lot libraries :(
Just a draft, IDK what I am doing right now :(
Code: [Select]
 
  if (jumperState == LOW) {
    WEIGHT_CLASS = WC_HEAVY;
  } else {
    WEIGHT_CLASS = WC_MEDIUM;
  }

Thank you for your help.
Rongyos
Title: Re: Standalone Tank IR
Post by: LukeZ on October 27, 2023, 11:15:38 AM
Hi Rongyos,

This should be easy to do. You have the right idea. Try putting this code in the setup() routine of TankIR.ino, after the "RECOIL SERVO DEFINITION" and just before the "BATTLE SETTINGS" section (in other words, somewhere around line 139)

Code: [Select]
#define pin_WeightJumper   7
unsigned char WC;

pinMode(pin_WeightJumper, INPUT_PULLUP);

if (digitalRead(pin_WeightJumper) == LOW)
{
    WC = WC_HEAVY;
}
else
{
    WC = WC_MEDIUM;
}


Next, in the "BATTLE SETTINGS" section just below you just need to set BattleSettings.WeightClass to our new variable WC (replacing the WEIGHT_CLASS that was there before). This is currently at line 145:
Code: [Select]
    BattleSettings.WeightClass = WC;

The check will only occur once at startup, in other words, if you change the jumper after the board has power the code won't do anything, you will have to reboot before it checks again.

Let me know if it works!
Title: Re: Standalone Tank IR
Post by: Rongyos on October 27, 2023, 02:06:20 PM

Let me know if it works!

You are the MVP! The second one is jumper_on state :)

Title: Re: Standalone Tank IR
Post by: LukeZ on October 27, 2023, 02:10:38 PM
I'm glad to have helped!
Title: Re: Standalone Tank IR
Post by: Rongyos on January 03, 2024, 04:21:07 PM
Hi!

@Luke: I didn't find the "myreceiverobject.getPinNum" object where the receiver pin number has to be assigned to D2 pin of Nano.
Can you help me where I can get it? My receiver is not working right now.

An other question. Do you know where can I get constant 5V from the Taigen V3 MFU? It seems the CN2 is only providing around 1.8V

Mod.: Also when I provide 5V to my servo its little bit moving (the recoil look fine to me) when it shouldn't do that, like some kind of whitenoise

Thanks and regards!
Rongyos

Problem again: no servo recoil (every connection is good)

Problem again2: phantom cannon shot after switching on (do you remember this problem also appeared on TCB (https://openpanzer.org/forum/index.php?topic=17.msg3118#msg3118)):

15:10:15.520 -> ---------------------------------------------
15:10:15.520 -> BATTLE INFO
15:10:15.520 -> ---------------------------------------------
15:10:15.564 -> Is Repair Tank?   No
15:10:15.564 -> Fire Protocol:    Tamiya
15:10:15.564 -> Hit Protocol 2:   Heng Long
15:10:15.564 -> Repaired by:      Clark Repair
15:10:15.564 -> Send MG IR Code:  No
15:10:15.564 -> Accept MG Damage: No
15:10:15.564 -> Damage Profile:   Tamiya Spec
15:10:15.564 -> Weight Class:     Medium
15:10:15.564 -> (6 cannon hits, 5.0 sec reload, 12.0 sec recovery)
15:10:15.564 ->
15:10:15.564 ->
15:10:15.564 ->
15:10:21.556 -> Fire Cannon
Title: Re: Standalone Tank IR
Post by: LukeZ on January 04, 2024, 11:45:37 AM
Hi Rongyos,

I have a suspicion this is related to the Arduino IDE version issue that was discussed earlier in this thread (https://openpanzer.org/forum/index.php?topic=19.msg2740#msg2740). With certain versions of the IDE the code will compile but without enough memory available, and the sketch will operate very erratically, if at all.

The solution is listed in that post, or again on this page of GitHub (https://github.com/OpenPanzerProject/TankIR) under the "Compiling Firmware" section.

So I would suggest following the instructions of opening the Boards Manager in the Arduino IDE, finding the Arduino AVR Boards section, and then installing boards version 1.6.20 and try recompiling and see if that makes a difference. This could explain several of the problems you're seeing.

An other question. Do you know where can I get constant 5V from the Taigen V3 MFU? It seems the CN2 is only providing around 1.8V
I don't have one to test, but I believe you should be able to find 5 volts from the sound card port, and possibly also the IR port. I can't say which pin is what, but you can use a multimeter to verify. However, I can't say  how clean the voltage will be from the Taigen MFU, and it might be better to use a 5v regulator to power your receiver and Nano.
Title: Re: Standalone Tank IR
Post by: Rongyos on January 04, 2024, 12:53:03 PM
I have a suspicion this is related to the Arduino IDE version issue that was discussed earlier in this thread (https://openpanzer.org/forum/index.php?topic=19.msg2740#msg2740). With certain versions of the IDE the code will compile but without enough memory available, and the sketch will operate very erratically, if at all.

You were right, I try to get stable 5v from anywhere, uploaded sketch to 4 different nanos and so on but didn't find that solution :) Thanks, everything working. I downloaded the IDE 1.8.5 and board 1.6.20

Can I ask something? Can you add a simple led blink on HitLeds when cannon reloaded and a little bit longer blinking when tank destroyed?

I tried the reload blink like this, but no success:

Code: [Select]
void OP_Tank::HitLEDs_Reloaded(void)
{   
    if (CannonReloaded)
    {
        HitLEDs_Toggle();
    }
    else
    {   
        if (TankTimer->isEnabled(HitLED_TimerID)) TankTimer->deleteTimer(HitLED_TimerID);
        HitLEDs_Off();
    }

Also, look at the test, I call it "almost there" :) Unfortunately, fantom firing is still there :(

Code: [Select]
19:07:13.025 -> BATTLE INFO
19:07:13.025 -> ---------------------------------------------
19:07:13.025 -> Is Repair Tank?   No
19:07:13.025 -> Fire Protocol:    Tamiya
19:07:13.025 -> Hit Protocol 2:   Heng Long
19:07:13.025 -> Repaired by:      Clark Repair
19:07:13.025 -> Send MG IR Code:  No
19:07:13.025 -> Accept MG Damage: No
19:07:13.071 -> Damage Profile:   Tamiya Spec
19:07:13.071 -> Weight Class:     Medium
19:07:13.071 -> (6 cannon hits, 5.0 sec reload, 12.0 sec recovery)
19:07:13.071 ->
19:07:13.071 ->
19:07:13.071 ->


19:07:15.205 -> Fire Cannon


19:07:31.516 -> CANNON HIT! (Tamiya)
19:07:31.516 -> Health Level: 83%
19:07:41.921 -> CANNON HIT! (Tamiya)
19:07:41.921 -> Health Level: 67%
19:07:52.162 -> CANNON HIT! (Tamiya)
19:07:52.162 -> Health Level: 50%
19:08:02.223 -> CANNON HIT! (Tamiya)
19:08:02.223 -> Health Level: 33%
19:08:12.900 -> CANNON HIT! (Tamiya)
19:08:12.900 -> Health Level: 17%
19:08:23.038 -> CANNON HIT! (Tamiya)
19:08:23.038 -> Health Level: 0%
19:08:33.440 -> CANNON HIT! (Tamiya)
19:08:33.440 -> Health Level: 0%
19:08:33.440 -> TANK DESTROYED
19:08:48.467 -> TANK RESTORED

EDIT: I tried to rewrite the button state on the TankIR loop from wasReleased to isPressed and wasPressed, no success
I use INPUT_PULLUP pinmode for my input pin, changed back to INPUT but phantom firing still there. Don't know whats next. Of course, there is no periphery attached to arduino when I checked this on tests, only the Nano was attached to USB.


My friend helped me. I set the VoltageTrigger to OUTPUT and no phantom firing occured :)
Title: Re: Standalone Tank IR
Post by: LukeZ on January 06, 2024, 11:31:16 AM
Can I ask something? Can you add a simple led blink on HitLeds when cannon reloaded and a little bit longer blinking when tank destroyed?

Hi Rongyos, I've posted an update to the firmware to GitHub, there is now the option to have the apple Hit LEDs blink when the cannon reload time has completed. By default it is off, you can set it to true in the A_Setup.h file near the top. 
Code: [Select]
    // NOTIFICATION LED
    // --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------->>
    //
    #define CANNON_RELOAD_NOTIFY    false                   // << --- SET ME - set to True to blink the IR apple notification LEDs when canon reload time has transpired (CUSTOM_CANNON_RELOAD below)
 


I'm not sure how long the blink should be, and I don't have an Arduino right now to test. Currently it is set to 250mS, which is only 1/4 of a second. If you want to increase the time, modify this function at the very bottom of Tank.cpp:
Code: [Select]
//------------------------------------------------------------------------------------------------------------------------>>
// HIT NOTIFICATION LEDs CANON RELOADED - Short blink to notify  user the canon reload time has completed
//                                        Can be enabled/disabled with setting CANNON_RELOAD_NOTIFY on the A_Setup.h tab
//------------------------------------------------------------------------------------------------------------------------>>
void OP_Tank::HitLEDs_ReloadNotify(void)
{   
    HitLEDs_Blink(250);
}


As for increasing the length of the tank destroyed period, it is set to 15 seconds because that is the Tamiya standard. However if you want to change it, modify this value near the top of the Tank.h tab:
Code: [Select]
// Tanks is dead for 15 seconds
#define DESTROYED_INOPERATIVE_TIME_mS   15000   // How long is the vehicle immobilized after being destroyed. 15 seconds is the Tamiya spec. After this,
                                                // the vehicle will automatically re-generate with full health restored.


Finally, with regard to the "phantom firing" - I probably should have made this more clear, though it is shown in the included sample schematic PDF - but you need to place a resistor between A0 and ground. 10k is shown in the schematic though the value is not important.

What you have done by setting A0 (pin_VoltageTrigger) to OUTPUT will also work, but then of course you would have to change that if you were going to use this pin in the future as an input signal from some other MFU.

I guess you are using the manual pushbutton method to trigger the canon fire? Most people probably use the signal input so I suppose that is why we haven't caught this issue before.

I will update the documentation to make this more clear.
Title: Re: Standalone Tank IR
Post by: Rongyos on January 06, 2024, 05:16:57 PM
Hi Luke!

Thank you for your support! I will try it tomorrow and share the results of your modifications :)



As for increasing the length of the tank destroyed period, it is set to 15 seconds because that is the Tamiya standard. However if you want to change it, modify this value near the top of the Tank.h tab:
Code: [Select]
// Tanks is dead for 15 seconds
#define DESTROYED_INOPERATIVE_TIME_mS   15000   // How long is the vehicle immobilized after being destroyed. 15 seconds is the Tamiya spec. After this,
                                                // the vehicle will automatically re-generate with full health restored.
No, maybe I was not understandable, sorry if my English is not perfect. For me the "tankdestroyed" notify LED effects were very similar to simple hit notification. I just wanted some longer blinking after destroy to make it more clear for the user that the tank is out. If I modify this can I reach my goal? (More blinking time, significantly longer than simple hit notification, the value was 450ms before thats what your comment also said :) )

Code: [Select]
// Now set a timer to keep coming back here after a short interval so we can blink the lights
        DestroyedBlinkerID = TankTimer->setInterval(5450, HitLEDs_Destroyed);     // This is a slow blink, about half a second

I guess you are using the manual pushbutton method to trigger the canon fire? Most people probably use the signal input so I suppose that is why we haven't caught this issue before.
I will update the documentation to make this more clear.

Thanks Luke, my plan was to use the 4th pin of the regular 8pin connector which is the airsoft signal pin. It sends out gnd signal, so thats why I used INPUT_PULLUP function to trigger the cannon fire. I don't need the 5V receiving pin because of this. Achieving my plan will let the users use this unit with older Heng Long and Taigen boards (they just need to extend the 4th wire and connect to relevant connector to the battle unit). I also have 2 Taigens and my test were good except the "phantom firing", but with the simple solution from my friend it disappeared!
I will test your led modifications and let you know!

Thanks and regards
Rongyos
Title: Re: Standalone Tank IR
Post by: LukeZ on January 07, 2024, 10:10:47 AM
No, maybe I was not understandable, sorry if my English is not perfect. For me the "tankdestroyed" notify LED effects were very similar to simple hit notification. I just wanted some longer blinking after destroy to make it more clear for the user that the tank is out. If I modify this can I reach my goal? (More blinking time, significantly longer than simple hit notification, the value was 450ms before thats what your comment also said :) )

Code: [Select]
// Now set a timer to keep coming back here after a short interval so we can blink the lights
        DestroyedBlinkerID = TankTimer->setInterval(450, HitLEDs_Destroyed);     // This is a slow blink, about half a second

Yes, if you want to change the blink rate for the destroyed notification, then you can modify the 450 value that you mentioned above. If you use a smaller number the blinking will be faster, or if you use a larger number the blinking will be slower. Regardless it will continue to blink for 15 seconds (or whatever value you decide to specify for DESTROYED_INOPERATIVE_TIME_mS).


Thanks Luke, my plan was to use the 4th pin of the regular 8pin connector which is the airsoft signal pin. It sends out gnd signal, so thats why I used INPUT_PULLUP function to trigger the cannon fire. I don't need the 5V receiving pin because of this. Achieving my plan will let the users use this unit with older Heng Long and Taigen boards (they just need to extend the 4th wire and connect to relevant connector to the battle unit). I also have 2 Taigens and my test were good except the "phantom firing", but with the simple solution from my friend it disappeared!
Ok, I understand now. You're right, these Chinese MFUs often prefer to toggle the ground signal rather than the positive, so you were correct to use the button input D4 (which triggers when held to ground) rather than the 5 volt input A0 (which triggers when brought to 5 volts). Your friend correctly identified the problem with the 5v input which was left floating, and disabled it by setting it to OUTPUT. That works fine. For others reading this, you can do the same, or as mentioned before, add a resistor between A0 and ground if you don't want to change the code. 
Title: Re: Standalone Tank IR
Post by: Rongyos on January 07, 2024, 11:37:52 AM

Ok, I understand now. You're right, these Chinese MFUs often prefer to toggle the ground signal rather than the positive, so you were correct to use the button input D4 (which triggers when held to ground) rather than the 5 volt input A0 (which triggers when brought to 5 volts). Your friend correctly identified the problem with the 5v input which was left floating, and disabled it by setting it to OUTPUT. That works fine. For others reading this, you can do the same, or as mentioned before, add a resistor between A0 and ground if you don't want to change the code.

Hi Luke!

My happiness was not long. Unfortuntely, the phantom firing is not visible on the serial monitor, but still there.  I have another idea with this, can you please put a code which activates the IR emitter pin a little bit later? I mean, the ir pin activated or start to wait the cannon function after 2 secs from bootup.
I put a button state in every initial bootup but its value 1 every time.

IDK why this dump the battle info 3 times after uploading the code ... :/

Code: [Select]
18:27:40.756 -> Button State: 1
18:27:41.021 ->
18:27:41.021 -> ---------------------------------------------
18:27:41.021 -> BATTLE INFO
18:27:41.021 -> ---------------------------------------------
18:27:41.021 -> Is Repair Tank?   No
18:27:41.021 -> Fire Protocol:    Tamiya
18:27:41.021 -> Hit Protocol 2:   Heng Long
18:27:41.021 -> Repaired by:      Clark Repair
18:27:41.021 -> Send MG IR Code:  No
18:27:41.021 -> Accept MG Damage: No
18:27:41.021 -> Damage Profile:   Tamiya Spec
18:27:41.021 -> Weight Class:     Medium
18:27:41.021 -> (6 cannon hits, 5.0 sec reload, 20.0 sec recovery)
18:27:41.064 ->
18:27:41.064 ->
18:27:41.064 ->
18:27:51.406 -> Button State: 1
18:27:51.671 ->
18:27:51.671 -> ---------------------------------------------
18:27:51.671 -> BATTLE INFO
18:27:51.671 -> ---------------------------------------------
18:27:51.671 -> Is Repair Tank?   No
18:27:51.671 -> Fire Protocol:    Tamiya
18:27:51.671 -> Hit Protocol 2:   Heng Long
18:27:51.671 -> Repaired by:      Clark Repair
18:27:51.714 -> Send MG IR Code:  No
18:27:51.714 -> Accept MG Damage: No
18:27:51.714 -> Damage Profile:   Tamiya Spec
18:27:51.714 -> Weight Class:     Medium
18:27:51.714 -> (6 cannon hits, 5.0 sec reload, 20.0 sec recovery)
18:27:51.714 ->
18:27:51.714 ->
18:27:51.714 ->
18:28:27.490 -> Button State: 1
18:28:27.753 ->
18:28:27.753 -> ---------------------------------------------
18:28:27.753 -> BATTLE INFO
18:28:27.753 -> ---------------------------------------------
18:28:27.753 -> Is Repair Tank?   No
18:28:27.753 -> Fire Protocol:    Tamiya
.... cannot copy more lines ----> Rongyos

Referring the reload led notification, unfortunately its not working. If I set it true its on all the time, until it gets a hit, making hit notification effect but reload notification is not active.

MOD: I just realized I can shoot the cannon after being destroyed (during recovery time). It is not desirable, so I just modified the cannon.ino with this simple stuff (tested, working)

Code: [Select]
// CANNON FIRE
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------>>
void FireCannon()
{
    if (!Tank.isDestroyed) // Check if the tank is not destroyed
    {
        if (Tank.CannonReloaded()) // Only fire if reloading is complete
        {
            if (Tank.isRepairTank())
Title: Re: Standalone Tank IR
Post by: LukeZ on January 08, 2024, 02:04:58 PM
My happiness was not long. Unfortuntely, the phantom firing is not visible on the serial monitor, but still there.  I have another idea with this, can you please put a code which activates the IR emitter pin a little bit later? I mean, the ir pin activated or start to wait the cannon function after 2 secs from bootup.
I put a button state in every initial bootup but its value 1 every time.
Ok, up to now I have not thoroughly re-acquainted myself with the entirety of this project, and making changes until I've done so is always a mistake. I've spent a good deal of time today looking through everything, and hopefully I have a better idea of what is going on.

Ultimately what your friend did in setting the direction of the positive trigger pin to OUTPUT will not fix the phantom firing issue, though it might have improved it. The problem is we still have an interrupt defined on this pin which is causing the problems.

The solution is to create another setting in A_Setup.h where the user can specify whether they want to use this input or not. I've made it the first setting in that file, and by default it will be false (disabled):
Code: [Select]
    #define USE_5VOLT_TRIGGER       false

When false, the interrupt will not be created and the setup of the pin will be handled appropriately.

There is no need for a setting for the negative-input/pushbutton trigger, that one can always be active. It uses an internal pullup so isn't subject to stray voltages, also it doesn't use a hardware interrupt procedure and should ignore anything other than a very intentional signal.


Referring the reload led notification, unfortunately its not working. If I set it true its on all the time, until it gets a hit, making hit notification effect but reload notification is not active.
This was an error on my part. I've corrected it and it should work now. I also increased the blink time a little bit to 400mS.


MOD: I just realized I can shoot the cannon after being destroyed (during recovery time). It is not desirable, so I just modified the cannon.ino with this simple stuff (tested, working)
Wow, great catch! I can't believe I missed that. In fact the same bug is present on the TCB, I will fix that too.


The GitHub is now updated with all these changes. I hope now everything will work, please let me know your results.

Title: Re: Standalone Tank IR
Post by: Rongyos on January 09, 2024, 01:47:23 AM
The GitHub is now updated with all these changes. I hope now everything will work, please let me know your results.

Hi Luke!

Thank you again for you quick support. Unfortunatelly those mods are not working. The notify led is acting strange, when I shot the cannon some time (usually 4-5 times) the arduino reset itself and stay in a strange state ("L" board led is on, relay is on). You can see the pic what I mean. When I plug in the USB to see on the serial monitor what happens, this issue is not appearing (can it be a power supply issue? If yes, why servo, recoil and hit notification working?) MOD: well, in the pic the notification led is not on (3mm red one). But most of the time it freezed at staying on :)

When I only tried the 5V trigger mod of yours there wasn't any different operation then before. Phantom firing is still there. BUT I realized 2 things, maybe connected.

1. when I power on the arduino, there is ~20degree turn in the servo, like it start firing then stops. But, it does a firecannon function and everything works fine after that.

Code: [Select]
08:17:47.916 -> ---------------------------------------------
08:17:47.916 -> BATTLE INFO
08:17:47.916 -> ---------------------------------------------
08:17:47.916 -> Is Repair Tank?   No
08:17:47.916 -> Fire Protocol:    Tamiya
08:17:47.916 -> Hit Protocol 2:   Heng Long
08:17:47.916 -> Repaired by:      Clark Repair
08:17:47.916 -> Send MG IR Code:  No
08:17:47.916 -> Accept MG Damage: No
08:17:47.916 -> Damage Profile:   Tamiya Spec
08:17:47.916 -> Weight Class:     Medium
08:17:47.916 -> (6 cannon hits, 5.0 sec reload, 20.0 sec recovery)
08:17:47.916 ->
08:17:47.916 ->
08:17:47.916 ->

2. when the arduino is on and I push the reset button, the "setup" is incomplete (or cannot do the loop, IDK what happens) and relay stays in and you can see the servo do the same thing which I wrote in the point 1. I attached a video, it is showing what happens.


I dont know, but maybe the in the Tank.ino there is code part which is waiting for the initial cannon fire to go to the main loop.
Title: Re: Standalone Tank IR
Post by: LukeZ on January 09, 2024, 02:44:11 PM
Hi Rongyos,

At this point there are so many different symptoms which don't seem to have any relation to each other, that it is hard to say what is going on.

If the board board is reseting/freezing/locking, or just in general acting bizarre (not completing the serial statements, erratic servo behavior, etc...) something is not right, but yet I experience none of these on my end. So there are two possible explanations:

1. Possibly we are still struggling with a compiler issue. I kind of doubt it, but if you want to replicate my setup I am using Arduino IDE version 1.8.13 with the AVR Boards set to 1.6.20. We already discussed changing the boards to 1.6.20, but maybe there is a difference with the compiler itself. You could try downloading and installing 1.8.13 from this link (https://www.arduino.cc/en/software/OldSoftwareReleases), and again make sure the AVR Boards is set to 1.6.20, and see if that improves anything.

2. The second option, is that you are using modifications to the code that are causing problems, or there are electrical issue with your custom board. Those are things only you can troubleshoot, but through a process of elimination it is still possible to reduce the number of possibilities until you find the culprit.

I think you should try the sketch in its stock form, unmodified, on your Nano without your carrier board, powered by USB. You can attach the LEDs and servo directly to the Nano using jumper cables. It would even be wise to remove the Heng Long or whatever MFU you are using, and instead trigger with a button or just by holding a wire from D4 to ground.

I have even attached a Hex file below that I have compiled on my computer, and it works flawlessly here, at least for firing the cannon (I have no means of testing IR reception right now). All settings in this compiled Hex are at default, meaning the 5v input is disabled. I can fire the cannon time and time again and the servo always responds correctly, the IR is always sent, the reload notification LED always blinks, and all the serial statements are complete and accurate.

It is true that when the Arduino first boots up, the servo may move a little bit. This is normal and unavoidable. But once running, the servo shouldn't do anything unless you fire the cannon.

Honestly, when I watch your video, I don't really see anything out of the ordinary. Maybe the relays are acting strange, but the relays are not part of my sketch, so I don't know anything about that. I don't see the reload notification LED blinking, so either that is not enabled in Setup, or else it is not connected to the Arduino, I don't know. But when you fire the cannon, I do see the recoil servo working, and the IR LED transmitting.

In summary, the only way to solve any technical problem of this kind is to simplify everything down the absolute minimum until you arrive at a state where things work as they should. Only then can you begin to make changes, one at a time, testing at each step, until a problem occurs. Then you know what the problem is.
Title: Re: Standalone Tank IR
Post by: Rongyos on January 10, 2024, 10:11:55 AM
Hi Rongyos,

At this point there are so many different symptoms which don't seem to have any relation to each other, that it is hard to say what is going on.

If the board board is reseting/freezing/locking, or just in general acting bizarre (not completing the serial statements, erratic servo behavior, etc...) something is not right, but yet I experience none of these on my end. So there are two possible explanations:

1. Possibly we are still struggling with a compiler issue. I kind of doubt it, but if you want to replicate my setup I am using Arduino IDE version 1.8.13 with the AVR Boards set to 1.6.20. We already discussed changing the boards to 1.6.20, but maybe there is a difference with the compiler itself. You could try downloading and installing 1.8.13 from this link (https://www.arduino.cc/en/software/OldSoftwareReleases), and again make sure the AVR Boards is set to 1.6.20, and see if that improves anything.

2. The second option, is that you are using modifications to the code that are causing problems, or there are electrical issue with your custom board. Those are things only you can troubleshoot, but through a process of elimination it is still possible to reduce the number of possibilities until you find the culprit.
[...]

In summary, the only way to solve any technical problem of this kind is to simplify everything down the absolute minimum until you arrive at a state where things work as they should. Only then can you begin to make changes, one at a time, testing at each step, until a problem occurs. Then you know what the problem is.

Hi Luke,

I did some experiment with / without my motherboard; with your hex and with my hex also.
I realized that when I tought the arduino was freezed there were 2 option:

1. It wasn't, but I was 1d10t and did not set the relay pin default as "HIGH". So when I switch on the arduino the relay was always on (led is on) until I shot the cannon. Now, I made a simple digitalwrite HIGH command in the void setup and now, everything is working right :)

2. there WAS a freeze. But it is a hardware issue. I think during the experiments I burnt out the IR emitter transistor or IDK, but when I try firing now, it fires 1 or 2 and the arduino is freezing. When I remove the IR LED (only the led) there is no issue anymore. Strange, there wasn't this issue before I could make a lot of cannon fire with this PCB.


I have good news (?). The whole phantom firing is caused by the Taigen MFU. Finally I found an 5v BEC, krimped some connector and with this stable power supply (I mean the Taigen probably also stable but not the airsoft pin which I use for activate button firing) there is no phantom firing, only the servo positions itself to its home pos. SO the code was good regarding this (your and mine too). With my board, with relay, with my mods in code etc....

But, when I connect it to the MFU and power it on (via the MFU PSupply) it does a phantom firing. I tried to disconnect the airsoft wire and power it on by the MFU and it was fine, worked correctly without phantom firing (I should probably make a hotkey in windows to write "phantom firing" :D ). I assume the Taigen "switch on" this pin later. Or (worst case scenario) it is always on LOW? (When I put digitalRead its always said it is 1 (high, right?)

Can you guide me out of this mess?

Title: Re: Standalone Tank IR
Post by: LukeZ on January 10, 2024, 02:02:30 PM
Hi Rongyos,

Now we are making some good progress!

2. there WAS a freeze. But it is a hardware issue. I think during the experiments I burnt out the IR emitter transistor or IDK, but when I try firing now, it fires 1 or 2 and the arduino is freezing. When I remove the IR LED (only the led) there is no issue anymore. Strange, there wasn't this issue before I could make a lot of cannon fire with this PCB.
This is good information. If you damaged your LED, or maybe shorted it, you need to try a new one and see if that fixes the problem. Or like you say, maybe the transistor is damaged and needs to be replaced. At least you know there is a problem somewhere with this part of the circuit. If you want to post your schematic, components list and board design I'd be happy to take a look at it.

But, when I connect it to the MFU and power it on (via the MFU PSupply) it does a phantom firing. I tried to disconnect the airsoft wire and power it on by the MFU and it was fine, worked correctly without phantom firing (I should probably make a hotkey in windows to write "phantom firing" :D ). I assume the Taigen "switch on" this pin later. Or (worst case scenario) it is always on LOW? (When I put digitalRead its always said it is 1 (high, right?)
You are correct, if digitalRead returns 1 that means HIGH. I'm certain the Taigen MFU keeps this pin HIGH except when the airsoft is fired, at which point it is held to Ground, but that doesn't mean there couldn't be some "noise" or a very brief signal on this pin when the Taigen starts - not long enough to activate an airsoft unit, but long enough for the Arduino to detect it and fire the cannon.

Now that I am thinking about it, it is also likely the voltage of this pin from the MFU, when the airsoft is not active, is greater than 5 volts. Of course the Nano can be damaged with input voltages higher than 5 volts, so this could also be a source of problems. You should try to measure this pin from the Taigen MFU with a voltmeter. If it is greater than 5 volts, there are ways to protect the Arduino, but we need to know what the voltage is.

It would also be good to check some other outputs on the Taigen, there are two more options I can think of: the flash trigger, and the IR port. I don't have a Taigen to test and my memory is not perfect, but I believe the flash pins were 5 volts. If so, that would be a better choice to connect to the Arduino.

So those are some things to try, but already like I say you are making good progress!
Title: Re: Standalone Tank IR
Post by: Rongyos on January 10, 2024, 03:01:20 PM
Hi Luke!

I didn't check the obvious :(

You are correct, if digitalRead returns 1 that means HIGH. I'm certain the Taigen MFU keeps this pin HIGH except when the airsoft is fired, at which point it is held to Ground, but that doesn't mean there couldn't be some "noise" or a very brief signal on this pin when the Taigen starts - not long enough to activate an airsoft unit, but long enough for the Arduino to detect it and fire the cannon.

So every time at least 1.9V is there in this pin. BUT! When I checked this pin switched off (fortunately my switch is disconnecting the + wire) connecting multimeter to battery +  and airsoft pin it was around 7V visible (not much less then the battery actual voltage *DOUBLECHECKED it was 6,64 - 6,62Volts). When switching on the MFU its dropped from 7V to 1.99V and stayed there until I (I mean, my dear wife :D who helped me) fired the tank and it was 7.04V again (which is the actual battery voltage)

Now that I am thinking about it, it is also likely the voltage of this pin from the MFU, when the airsoft is not active, is greater than 5 volts. Of course the Nano can be damaged with input voltages higher than 5 volts, so this could also be a source of problems. You should try to measure this pin from the Taigen MFU with a voltmeter. If it is greater than 5 volts, there are ways to protect the Arduino, but we need to know what the voltage is.

I attached a schematic. Please ignore the voltage regulator and any other stuff connected to it because it is my "future" board. I dont have the current one because I overwrote it :D :(
Please see the blue ugly stuff, the 5V is supplied by taigen receiver connector (yes it has opportunity to connect aftermarket receivers and therefore TX-es to is. This connector provides 5,02V so I using it)


Unfortunatelly no other pin which provides 5V continuously. According to the schematic the IR connector is 5V but jI didnt get 5 volt from this pin, only 4.3 at max. Servo was not working with this.

It would also be good to check some other outputs on the Taigen, there are two more options I can think of: the flash trigger, and the IR port. I don't have a Taigen to test and my memory is not perfect, but I believe the flash pins were 5 volts. If so, that would be a better choice to connect to the Arduino.

No, those are not activated until receiving a signal from a microswitch (it is located in the airsoft or recoil unit and pushed mechanically by those units). The initial triggering signal is from the airsoft, anyway :( Or.... maybe that should be solution if I connect the airsoft signal to the microswitch pin and then, the MFU triggers the gun fire function then sends out the 5V to IR. If so, I have to redesign my board again, and order it from pcb manufacturer :'(
Title: Re: Standalone Tank IR
Post by: LukeZ on January 15, 2024, 12:22:46 PM
So every time at least 1.9V is there in this pin. BUT! When I checked this pin switched off (fortunately my switch is disconnecting the + wire) connecting multimeter to battery +  and airsoft pin it was around 7V visible (not much less then the battery actual voltage *DOUBLECHECKED it was 6,64 - 6,62Volts). When switching on the MFU its dropped from 7V to 1.99V and stayed there until I (I mean, my dear wife :D who helped me) fired the tank and it was 7.04V again (which is the actual battery voltage)
Ok, this is interesting, and I believe explains the "phantom firing" that you experience. On a 5 volt Arduino like the Nano, the documentation says that any signal over 3 volts is considered HIGH (1) and any signal less than 1.5 volts is considered LOW (0). In between 1.5 and 3 volts is where the pin switches from one state to another, and we can't  predict exactly whether the Arduino will read High or Low.

If I understand your description correctly, the Taigen airsoft pin initializes at 1.9 volts when the MFU is turned on, which is right in the in-between range on the Arduino, and sometimes the Arduino is interpreting this as Low and firing the cannon. After the first cannon fire of the Taigen, this pin reverts to +V Batt as we would expect (except at the moment when the cannon is fired, in which case I assume it must be held to Ground. Probably a better test would have been to connect your multimeter black wire to Ground, and the multimeter red wire to the Taigen airsoft pin.)

Anyway, there are two problems here. One is the fact that (at least after the first cannon fire) the Taigen airsoft pin rests at close to +V Batt, which is higher than the 5 volt limit of the Arduino pins. The easiest way to solve this is to use a voltage divider, I have attached a picture below. It is created with only two resistors so is easy to do. The absolute value of the resistors is not as important as is the ratio between them. I chose 3.3k and 4.7k because they are common values and give us a ratio that will cut the input voltage by about 40%, so 7 volts input will become something closer to 4 volts on the output, this will still be read as High by the Arduino, but it won't exceed the 5 volt input limit. This ratio will protect the Arduino even if you use a fully charged 2S LiPo that could be as high as 8.4 volts (will be divided down to 5 volts).

However, there still remains the second problem, which is that on startup the Taigen airsoft pin is basically in a low state, and that causes phantom firing on the Arduino until you fire the Taigen and only then does the Taigen begin to act in a reasonable way. I don't see an easy solution to this problem. It is bizarre that the Taigen acts this way, but I have come to expect bizarre behavior from Chinese electronics, and sadly this behavior is not what we want.


No, those are not activated until receiving a signal from a microswitch (it is located in the airsoft or recoil unit and pushed mechanically by those units). The initial triggering signal is from the airsoft, anyway :( Or.... maybe that should be solution if I connect the airsoft signal to the microswitch pin and then, the MFU triggers the gun fire function then sends out the 5V to IR. If so, I have to redesign my board again, and order it from pcb manufacturer :'(
You're right, I forgot! The Taigen does require that physical switch to be activated by the airsoft/recoil unit before it will do the Flash and IR. That is annoying. Yes, I suppose you can try your suggestion, and you can certainly at least do a test without a new PCB, just connect some temporary wires. The only thing I am not sure of is what the Taigen MFU expects from the trigger switch - is it expecting a high or low signal? And even if it is expecting a low signal, maybe it too will be confused by the 1.9 volts from the airsoft pin at startup, so you might end up with phantom firing anyway. But I guess you'd get the phantom fire out of the way the instant the Taigen is powered up, and in that case possibly a delay could be added to the Arduino to ignore it.

Only some testing can answer these questions. I'm sorry I don't have any of this to try on my end, but let me know what you discover.
Title: Re: Standalone Tank IR
Post by: Rongyos on January 25, 2024, 05:38:57 AM

Only some testing can answer these questions.

Hi Luke!

I can say that testing went good. In my case R1 = 2.4K; R2 = 10k. Now it has 1,3V at resting state and 5,28 when activated at charged 2cells liion. I think this is now good to go :)

Thanks
Rongyos
Title: Re: Standalone Tank IR
Post by: LukeZ on January 26, 2024, 11:30:50 AM
Very good! I suppose that does not solve the initial firing of the cannon when the Taigen MFU first powers up. I wonder if you tried your suggestion of connecting the airsoft pin to the airsoft/recoil switch? Or is it just something that will have to be accepted and lived with?
Title: Re: Standalone Tank IR
Post by: Rongyos on January 26, 2024, 01:14:03 PM
Very good! I suppose that does not solve the initial firing of the cannon when the Taigen MFU first powers up.

Yes, it solved the phantom firing. :)
Also I tried the airsoft-microswitch connect to try before, but somehow thats not worked. I had to wait for the big bunch of resistors I purchased.

Rongyos
Title: Re: Standalone Tank IR
Post by: LukeZ on January 26, 2024, 03:23:32 PM
Ah, well that's interesting. Perhaps the resistors in the voltage divider are acting as a pull-up circuit that is preventing the Taigen pin from floating in a low state on startup. If so, that's great, we've solved two problems with one solution.