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

  • 1225
    • 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

  • 35
    • 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

  • 1225
    • 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

  • 35
    • 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

  • 35
    • 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

  • 1225
    • 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

  • 35
    • 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: 254

*

Offline LukeZ

  • 1225
    • 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

 

bomber-explosion