Registration Notice

Due to increased spam, forum registration must be manually approved by a moderator! Please see this post for instructions.

*

Offline CodeWarrior

  • 29
    • View Profile
  • Detroit suburb, Michigan, USA
Re: Standalone Tank IR
« Reply #30 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.
There are 10 kinds of people:  Those who understand binary and those who don't.

*

Offline LukeZ

  • 1241
    • View Profile
  • France
Re: Standalone Tank IR
« Reply #31 on: April 11, 2021, 12:37:45 PM »
Thank you for reporting back!
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline Rongyos

  • 44
    • View Profile
  • Hungary
Re: Standalone Tank IR
« Reply #32 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

*

Offline LukeZ

  • 1241
    • View Profile
  • France
Re: Standalone Tank IR
« Reply #33 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!
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline Rongyos

  • 44
    • View Profile
  • Hungary
Re: Standalone Tank IR
« Reply #34 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

*

Offline Rongyos

  • 44
    • View Profile
  • Hungary
Re: Standalone Tank IR
« Reply #35 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

*

Offline LukeZ

  • 1241
    • View Profile
  • France
Re: Standalone Tank IR
« Reply #36 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!
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline Rongyos

  • 44
    • View Profile
  • Hungary
Re: Standalone Tank IR
« Reply #37 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 :)

Battleinfo.JPG
Standalone Tank IR Battleinfo.JPG
Views: 733

*

Offline LukeZ

  • 1241
    • View Profile
  • France
Re: Standalone Tank IR
« Reply #38 on: October 27, 2023, 02:10:38 PM »
I'm glad to have helped!
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline Rongyos

  • 44
    • View Profile
  • Hungary
Re: Standalone Tank IR
« Reply #39 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):

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
*
schematic.pdf
(38.43 kB ~ Downloads: 45)
« Last Edit: January 04, 2024, 08:28:18 AM by Rongyos »

*

Offline LukeZ

  • 1241
    • View Profile
  • France
Re: Standalone Tank IR
« Reply #40 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. 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 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.
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline Rongyos

  • 44
    • View Profile
  • Hungary
Re: Standalone Tank IR
« Reply #41 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. 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 :)
« Last Edit: January 05, 2024, 04:07:57 PM by Rongyos »

*

Offline LukeZ

  • 1241
    • View Profile
  • France
Re: Standalone Tank IR
« Reply #42 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.
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline Rongyos

  • 44
    • View Profile
  • Hungary
Re: Standalone Tank IR
« Reply #43 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

*

Offline LukeZ

  • 1241
    • View Profile
  • France
Re: Standalone Tank IR
« Reply #44 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. 
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

 

bomber-explosion