Regarding irMassageRecieve



  • Hi,

    I have modified the battle method in the cpp to return an integer if there is a hit by a opposing team.
    It seems like irMassageReceive does not contain the Missile.
    I have tried removing the
    "if(irMassageReceive == BLUE_MISSILE || irMassageReceive == GREEN_MISSILE || irMassageReceive == YELLOW_MISSILE || irMassageReceive == FREE_MISSILE)" and only check one at a time.

    The outer check of team-variable works. But I cant get it to sense the missile. Any ideas? The weapon is set to correct. I see the light flashing on the bluetooth so I know it receives data. And I know some data is received by the Receive() method since the irMassageReceive is larger than 0.


  • administrators

    @magnus I will get back to you on this, we have not used irMassageReceive in our Arduino tutorials. Can you post the modification you made? like the whole function.



  • void CoDroneClass::BattleBegin(byte teamSelect)
    {
    	team = teamSelect;
    	if(team == TEAM_RED)
    	{		
    		weapon = RED_MISSILE;
    	}		
    	else if	(team == TEAM_BLUE)
    	{		
    		weapon = BLUE_MISSILE;
    	}	
    	delay (300);
    
    }
    
    int CoDroneClass::BattleReceive()
    {
    	Receive();
    	int result = -1;
    
    	if(irMassageReceive > 0)
    	{		
    		if(team == TEAM_RED)
    		{
    			if(irMassageReceive == BLUE_MISSILE || irMassageReceive == GREEN_MISSILE || irMassageReceive == YELLOW_MISSILE || irMassageReceive == FREE_MISSILE)
    			{
    				result = 1;	
    			}			
    
    		}						
    		else if(team == TEAM_BLUE)
    		{
    
    			if(irMassageReceive == RED_MISSILE || irMassageReceive == GREEN_MISSILE || irMassageReceive == YELLOW_MISSILE || irMassageReceive == FREE_MISSILE)
    			{				
    				result = 2;
    
    			}			
    		}					
    
    		irMassageReceive = 0;
    	}
    
    	return result;
    }
    

    I first instantiate weapon and team in battlebegin. I just removed the color settings.
    Then I make the BattleRecieve function return a value if one drone gets hit by the opponent. (I also change the .h file ofcourse. Everything compile)

    I want to do this to send instructions to another drone. When one drone shoots the other should respond by taking off and perform its flightprogram.

    Next in my arduino:

    void setup
    {
         CoDrone.BattleBegin(TEAM_BLUE);
    }
    
    int information = -1;
    
    void loop
    {
        information = CoDrone.BattleReceive();
        byte bt8 = DrigitalRead(11);
    
        if(information==1)
       {
            //Flight instructions here
       }
       if(bt8)
       {
             CoDrone.BattleShooting();
       }
    }
    

    The Same code is used on the other drone except a different team color.
    I see that the bluetooth diod is flashing crazy when I shoot and hit the drone but I dont get the loop to start in my opponent
    .



  • @robolink_arnold and @robolink_whoseop Can you two take a look at this and get back to Magnus? Thanks!


  • administrators

    @magnus did you change the header file?



  • Yes. I changed it to match the instatiated methods in the cpp file.
    Meaning in the header:

    int BattleRecieve();
    instead of
    void BattleRecieve();


  • administrators

    Here is the modification I did

    unsigned long CoDroneClass::BattleReceive()
    {
    Receive();
    
    if(irMassageReceive > 0)
    {
    
    	if(team == TEAM_RED)
    	{
    		if(irMassageReceive == BLUE_MISSILE || irMassageReceive == GREEN_MISSILE || irMassageReceive == YELLOW_MISSILE || irMassageReceive == FREE_MISSILE)
    		{
    			BattleDamageProcess();		
    		}			
    	}						
    	else if(team == TEAM_BLUE)
    	{
    		if(irMassageReceive == RED_MISSILE || irMassageReceive == GREEN_MISSILE || irMassageReceive == YELLOW_MISSILE || irMassageReceive == FREE_MISSILE)
    		{				
    			BattleDamageProcess();
    		}			
    	}					
    	else if(team == TEAM_GREEN)
    	{
    		if(irMassageReceive == BLUE_MISSILE || irMassageReceive == RED_MISSILE || irMassageReceive == YELLOW_MISSILE || irMassageReceive == FREE_MISSILE)
    		{
    				BattleDamageProcess();				
    		}			
    	}		
    	else if(team == TEAM_YELLOW)
    	{
    		if(irMassageReceive == BLUE_MISSILE || irMassageReceive == GREEN_MISSILE || irMassageReceive == RED_MISSILE || irMassageReceive == FREE_MISSILE)
    		{				
    			BattleDamageProcess();
    		}			
    	}			
    	else if(team == FREE_PLAY)
    	{
    		if(irMassageReceive == RED_MISSILE || irMassageReceive == BLUE_MISSILE || irMassageReceive == GREEN_MISSILE || irMassageReceive == YELLOW_MISSILE || irMassageReceive == FREE_PLAY)
    		{				
    			BattleDamageProcess();
    		}			
    	}		
    	unsigned long returnIRMSG = irMassageReceive;
    	irMassageReceive = 0;
    	return returnIRMSG;
    }
    }
    

    and then in the main arduino code I call

      CoDrone.BattleShooting();
      unsigned long irmsg = CoDrone.BattleReceive();
      CoDrone.Send_LinkModeBroadcast(LinkModeMute);
      delay(200);
      Serial.println("-----------");
      Serial.println(irmsg);
      Serial.println("-----------");
      delay(200);
      CoDrone.Send_LinkModeBroadcast(LinkBroadcast_Active);
    

    I have the Drone shoot a wall so the IR code can bounce off. Let me know if this helps.


Log in to reply
 

Looks like your connection to Robolink community was lost, please wait while we try to reconnect.