Ejemplo n.º 1
0
//---------------------------------------------------------------------------
//Returns if the test was successful
bool TestRavindran::Execute()
{
  std::clog << "Starting TestRavindranLinux for '"
    << this->GetNewick() << "'\n";

  if (GetComplexity() > 1000000) return false;

  //Write parameters to file
  {
    std::ofstream file("theta.txt");
    file << GetTheta();
  }
  {
    //Older version expects a /n at end
    std::ofstream file("phylogeny.txt");
    file << GetNewick() << "\n\n";
  }

  #ifdef WIN32
  const std::string exe_filename = "../Exes/phy_prob_12.exe";
  const std::string full_command = "../Exes/phy_prob_12.exe";
  #else
  const std::string exe_filename = "../Exes/phy_prob_linux";
  const std::string full_command = "./../Exes/phy_prob_linux";
  #endif

  return Test::Execute(
    exe_filename,
    full_command,
    "expected_probability.txt");
}
Ejemplo n.º 2
0
bool Sector::Intersects(const Vector2D& position) const {
    Vector2D l(this->GetPosition() - position);
    if(l.GetLength() > GetRadius()) return false;
    if(Math::IsEqual(l.GetLength(), 0.0)) return true;

    Vector2D sF = Vector2D::GetFacingVector(this->GetArcCenter(), this->GetPosition());
    Vector2D sF_n(sF.Normalize());
    Vector2D P_to_S(l.Normalize());

    double angle = std::acos(Vector2D::DotProduct(sF_n, P_to_S));

    return (angle <= GetTheta() / 2.0);
}
Ejemplo n.º 3
0
//---------------------------------------------------------------------------
///Just call the executable TestTwoDigitNewickDebug
///with the parameters
bool TestManyDigitNewickDebug::Execute()
{
  #ifndef WIN32
  const std::string exe_filename = "../Exes/TestManyDigitNewickUbuntuDebug";
  #else
  const std::string exe_filename = "../Exes/TestManyDigitNewickWinDebug.exe";
  #endif

  const std::string command_full =
  #ifndef WIN32
    std::string("./") +
  #endif
    exe_filename
    + " "
    + boost::lexical_cast<std::string>(GetTheta())
    + " \""
    + GetNewick()
    + "\"";

  const std::string output_filename = "Result_probability.txt";

  return Test::Execute(exe_filename,command_full,output_filename);
}
Ejemplo n.º 4
0
//---------------------------------------------------------------------------
///Just call the executable ProjectRampalMain_Endversion2
///with the parameters
bool TestEndversion2::Execute()
{
  #ifndef WIN32
  const std::string exe_filename = "../Exes/ProjectRampalMain_Endversion2";
  #else
  const std::string exe_filename = "../Exes/ProjectRampal.exe";
  #endif

  const std::string command_full =
  #ifndef WIN32
    std::string("./") +
  #endif
    exe_filename
    + " "
    + boost::lexical_cast<std::string>(GetTheta())
    + " \""
    + GetNewick()
    + "\"";

  const std::string output_filename = "Result_probability.txt";

  return Test::Execute(exe_filename,command_full,output_filename);
}
Ejemplo n.º 5
0
jdouble JNICALL Java_ardrone_ARDrone_getTheta(JNIEnv *env, jclass cls)
{
	return GetTheta();
}
Ejemplo n.º 6
0
void Sector::CalculateArea() {
    _area = 0.5 * (GetRadius() * GetRadius() * GetTheta());
}
void PathPlanner(void)
{
if(QueryTankSM()!=DISABLED)
{

   static float CurrentPosition[3] = {0,0,0}; 
   static float CurrentWallLine[2];
   static int CurrentWallAngle;
   
   static ActivityState_t CurrentGoal;
   ES_Event ThinkTankEvent;
   ES_Event GameMonitorEvent;
   
   srand(ES_Timer_GetTime());
   
   if( CurrentGoal != QueryActivityControlSM())
   {
      //printf("clearing checkpoints\n\r");
     
	  wigglecounter = 0;
	  BinCheckPoints = 0;
	  WallCheckPoints = 0;
      
      
      // GOOD?
      ThinkTankEvent.EventType = WAIT_COMMAND;
      ThinkTankEvent.EventParam = WAIT_FOR_POSITION_FOUND;
      CurrentGoal = QueryActivityControlSM();
            
   } else
   {

   
   //ES_Event TankEvent;
   
   //CurrentGoal = QueryActivityControlSM();
   CurrentWallLine[0]= GetWallSlope(); 
   CurrentWallLine[1]= GetWallIntercept();
   CurrentWallAngle = GetWallAngle();
   UpdateCurrentPosition();
   CurrentPosition[X_COORDINATE] = GetX();
   CurrentPosition[Y_COORDINATE] = GetY();
   CurrentPosition[THETA] = GetTheta();
   //UpdateWallPoints(); // before getting staging points for wall
   
    switch (CurrentGoal)
   {
   //ES_Event ActionEvent;
      
      case RASTER :
      {
         static char i;
         
         //ThinkTankEvent.EventType = GO_COMMAND;
         //ThinkTankEvent.EventParam = 100;
         
          //Calibration test code
         /*
         if (i < 5)
         {
            ThinkTankEvent.EventType = GO_COMMAND;
            ThinkTankEvent.EventParam = STEP_DISTANCE; 
            i++;  
         } else if (i<6)
         {
            ThinkTankEvent.EventType = TURN_COMMAND;
            ThinkTankEvent.EventParam = 1080; 
            i++;  
         } else if (i<7)
         {
            ThinkTankEvent.EventType = TURN_COMMAND;
            ThinkTankEvent.EventParam = -1080; 
            i++;
         } else
         {
            ThinkTankEvent.EventType = WAIT_COMMAND;
            ThinkTankEvent.EventParam = WAIT_FOR_POSITION_FOUND; 
            i=0;
         }
         */ 
  
         
         // go forward thrice, turn randomly once, unless threatened by wall, then flee for safety.
         
         if (CurrentLocationIsSafe( CurrentPosition[0], CurrentPosition[1], CurrentPosition[2], CurrentWallAngle) == True)  //our current location is a safe one
         {
            
            if (i < 3)
            {
               if (SafeToTravel((float)STEP_DISTANCE/100.,CurrentPosition[0],CurrentPosition[1],CurrentPosition[2], CurrentWallAngle) == True)
               {
                  ThinkTankEvent.EventType = GO_COMMAND;
                  ThinkTankEvent.EventParam = STEP_DISTANCE;
                  
                  //SetMotorTimer(STEP_DISTANCE);
               } else
               {
                  ThinkTankEvent.EventType = TURN_COMMAND;
                  ThinkTankEvent.EventParam = (rand()%360) - 180; 
                  //SetMotorTimer(angle);
               }
               i++; 
            } else if (i<4)
            {
              ThinkTankEvent.EventType = WAIT_COMMAND;
              ThinkTankEvent.EventParam = WAIT_FOR_POSITION_FOUND;
              i++; 
            } else
            {
               ThinkTankEvent.EventType = TURN_COMMAND;
               ThinkTankEvent.EventParam = (rand()%360) - 180; 
               //SetMotorTimer(angle); 
               i = 0;    
            }
         } else
         {
            //go to safe point
            ThinkTankEvent = GenerateNextStep_EscapeWallPath(CurrentPosition,CurrentWallAngle);
         }
         
         
      }
      break;
      
      case CONTROL_LEFT_WALL :
         //printf("Wall Third Point is x: %d y: %d \n\r", PushPointX(),PushPointY());
         /*
         if(GetSeparationDistance( -- parameters  for push point -- ) < 6)
         {
            WallCheckPoints = 2;
         }
         */
         if (WallCheckPoints < 1)
         {
            float GoalPoint[2];
            //float NextGoalPoint[2];
            GoalPoint[0] = WallFirstPointX();
            GoalPoint[1] = WallFirstPointY();
            //NextGoalPoint[0] = WallStagingPointX(LEFT);
            //NextGoalPoint[1] = WallStagingPointY(LEFT);
            
            ThinkTankEvent = GenerateNextStep_GoalPoint(CurrentPosition,GoalPoint,WAIT_FOR_POSITION_FOUND);   


            
         } else if (WallCheckPoints < 2)
         {
            float GoalPoint[2];
            //float NextGoalPoint[2];
            GoalPoint[0] = WallStagingPointX(LEFT);
            GoalPoint[1] = WallStagingPointY(LEFT);
            //NextGoalPoint[0] = PushPointX();
            //NextGoalPoint[1] = PushPointY();
            
            ThinkTankEvent = GenerateNextStep_GoalPoint(CurrentPosition,GoalPoint,WAIT_FOR_POSITION_FOUND); 
         } else if  (WallCheckPoints < 3)
         {
            float GoalPoint[2];
            //float NextGoalPoint[2];
            GoalPoint[0] = PushPointX();
            GoalPoint[1] = PushPointY();
            // change this!!
            //NextGoalPoint[0] = PushPointX();
            //NextGoalPoint[1] = PushPointY();
            
            ThinkTankEvent = GenerateNextStep_GoalPoint(CurrentPosition,GoalPoint,WAIT_FOR_POSITION_FOUND);
         }  else
         {
            // THINK THROUGH THIS
            ThinkTankEvent.EventType = WAIT_COMMAND;
            ThinkTankEvent.EventParam = WAIT_FOR_A_TENTH_SECOND;
            //CurrentGoal = STAY_PUT (will start process over again)
            //WallCheckPointThree = False;
         }
         
      break;
      
      case CONTROL_RIGHT_WALL :
         //printf("Wall Third Point is x: %d y: %d \n\r", PushPointX(),PushPointY());
         /*
         if(GetSeparationDistance( -- parameters  for staging point -- ) < 8)
         {
            WallCheckPoints = 2;
         }
         */
         if (WallCheckPoints < 1)
         {
            float GoalPoint[2];
            //float NextGoalPoint[2];
            GoalPoint[0] = WallFirstPointX();
            GoalPoint[1] = WallFirstPointY();
            //NextGoalPoint[0] = WallStagingPointX(LEFT);
            //NextGoalPoint[1] = WallStagingPointY(LEFT);
            
            ThinkTankEvent = GenerateNextStep_GoalPoint(CurrentPosition,GoalPoint,WAIT_FOR_POSITION_FOUND);   


            
         } else if (WallCheckPoints < 2)
         {
            float GoalPoint[2];
            //float NextGoalPoint[2];
            GoalPoint[0] = WallStagingPointX(RIGHT);
            GoalPoint[1] = WallStagingPointY(RIGHT);
            //NextGoalPoint[0] = PushPointX();
            //NextGoalPoint[1] = PushPointY();
            
            ThinkTankEvent = GenerateNextStep_GoalPoint(CurrentPosition,GoalPoint,WAIT_FOR_POSITION_FOUND); 
         } else if  (WallCheckPoints < 3)
         {
            float GoalPoint[2];
            //float NextGoalPoint[2];
            GoalPoint[0] = PushPointX();
            GoalPoint[1] = PushPointY();
            // change this!!
            //NextGoalPoint[0] = PushPointX();
            //NextGoalPoint[1] = PushPointY();
            
            ThinkTankEvent = GenerateNextStep_GoalPoint(CurrentPosition,GoalPoint,WAIT_FOR_POSITION_FOUND);
         }  else
         {
            // THINK THROUGH THIS
            ThinkTankEvent.EventType = WAIT_COMMAND;
            ThinkTankEvent.EventParam = WAIT_FOR_A_TENTH_SECOND;
            //CurrentGoal = STAY_PUT (will start process over again)
            //WallCheckPointThree = False;
         }
         
      break;
      
      
      case DEPOSIT_IN_BIN_ONE :
         
         if (BinCheckPoints < 1)
         {
			ThinkTankEvent = GenerateNextStep_RadialPath(CurrentPosition,RADIUS_OF_SAFETY-2*HALF_BOT_LENGTH,WAIT_FOR_POSITION_FOUND);   
            
         } else if (BinCheckPoints < 2)
         {
            float GoalPoint[2];
            //float NextGoalPoint[2];
            GoalPoint[0] = StagingPointForBinOneX;
            GoalPoint[1] = StagingPointForBinOneY;
            //NextGoalPoint[0] = BinOneDepositX;
            //NextGoalPoint[1] = BinOneDepositY;
            GameMonitorEvent.EventType = START_AVERAGING;
			ThinkTankEvent = GenerateNextStep_GoalPoint(CurrentPosition,GoalPoint,WAIT_FOR_POSITION_FOUND); 
         } else if (BinCheckPoints < 3)
		 {
			ThinkTankEvent.EventType = WAIT_COMMAND;
			ThinkTankEvent.EventParam = WAIT_FOR_POSITION_FOUND; 
			BinCheckPoints++;
		} else if (BinCheckPoints < 4)
		 {
			ThinkTankEvent.EventType = WAIT_COMMAND;
			ThinkTankEvent.EventParam = WAIT_FOR_POSITION_FOUND; 
			BinCheckPoints++;
		} else if (BinCheckPoints < 5)
         {
            
			GameMonitorEvent.EventType = STOP_AVERAGING;
			
			ThinkTankEvent.EventType = WAIT_COMMAND;
			ThinkTankEvent.EventParam = WAIT_FOR_A_TENTH_SECOND;
			
			BinCheckPoints++;
		} else if (BinCheckPoints < 6) 
		{
			float GoalPoint[2];
            //float NextGoalPoint[2];
            GoalPoint[0] = DepositPointForBinOneX;
            GoalPoint[1] = DepositPointForBinOneY;
			//UpdateCurrentPosition();
			//CurrentPosition[X_COORDINATE] = GetX();
			//CurrentPosition[Y_COORDINATE] = GetY();
			//CurrentPosition[THETA] = GetTheta();
         ThinkTankEvent =  GenerateNextStep_GoalPoint(CurrentPosition,GoalPoint,WAIT_FOR_A_TENTH_SECOND);    /* checkpoint */     
         }  else
         {
            ThinkTankEvent.EventType = WAIT_COMMAND;
            ThinkTankEvent.EventParam = WAIT_FOR_A_TENTH_SECOND;
            Drive(GENTLE_FORWARD);
         }
      break;
      
      case DEPOSIT_IN_BIN_TWO :
         
         if (BinCheckPoints < 1)
         {
			ThinkTankEvent = GenerateNextStep_RadialPath(CurrentPosition,RADIUS_OF_SAFETY-2*HALF_BOT_LENGTH,WAIT_FOR_POSITION_FOUND);   
            
         } else if (BinCheckPoints < 2)
         {
            float GoalPoint[2];
            //float NextGoalPoint[2];
            GoalPoint[0] = StagingPointForBinTwoX;
            GoalPoint[1] = StagingPointForBinTwoY;
            //NextGoalPoint[0] = BinOneDepositX;
            //NextGoalPoint[1] = BinOneDepositY;
            GameMonitorEvent.EventType = START_AVERAGING;
			ThinkTankEvent = GenerateNextStep_GoalPoint(CurrentPosition,GoalPoint,WAIT_FOR_POSITION_FOUND); 
         } else if (BinCheckPoints < 3)
		 {
			ThinkTankEvent.EventType = WAIT_COMMAND;
			ThinkTankEvent.EventParam = WAIT_FOR_POSITION_FOUND; 
			BinCheckPoints++;
		} else if (BinCheckPoints < 4)
		 {
			ThinkTankEvent.EventType = WAIT_COMMAND;
			ThinkTankEvent.EventParam = WAIT_FOR_POSITION_FOUND; 
			BinCheckPoints++;
		} else if (BinCheckPoints < 5)
         {
            
			GameMonitorEvent.EventType = STOP_AVERAGING;
			
			ThinkTankEvent.EventType = WAIT_COMMAND;
			ThinkTankEvent.EventParam = WAIT_FOR_A_TENTH_SECOND;
			
			BinCheckPoints++;
		} else if (BinCheckPoints < 6) 
		{
			float GoalPoint[2];
            //float NextGoalPoint[2];
            GoalPoint[0] = DepositPointForBinTwoX;
            GoalPoint[1] = DepositPointForBinTwoY;
			//UpdateCurrentPosition();
			//CurrentPosition[X_COORDINATE] = GetX();
			//CurrentPosition[Y_COORDINATE] = GetY();
			//CurrentPosition[THETA] = GetTheta();
         ThinkTankEvent =  GenerateNextStep_GoalPoint(CurrentPosition,GoalPoint,WAIT_FOR_A_TENTH_SECOND);    /* checkpoint */     
         }  else
         {
            ThinkTankEvent.EventType = WAIT_COMMAND;
            ThinkTankEvent.EventParam = WAIT_FOR_A_TENTH_SECOND;
            Drive(GENTLE_FORWARD);
         }
      break;
      
      
      case DEPOSIT_IN_BIN_THREE :
         if (BinCheckPoints < 1)
         {
			ThinkTankEvent = GenerateNextStep_RadialPath(CurrentPosition,RADIUS_OF_SAFETY-2*HALF_BOT_LENGTH,WAIT_FOR_POSITION_FOUND);   
            
         } else if (BinCheckPoints < 2)
         {
            float GoalPoint[2];
            //float NextGoalPoint[2];
            GoalPoint[0] = StagingPointForBinThreeX;
            GoalPoint[1] = StagingPointForBinThreeY;
            //NextGoalPoint[0] = BinOneDepositX;
            //NextGoalPoint[1] = BinOneDepositY;
            GameMonitorEvent.EventType = START_AVERAGING;
			ThinkTankEvent = GenerateNextStep_GoalPoint(CurrentPosition,GoalPoint,WAIT_FOR_POSITION_FOUND); 
         } else if (BinCheckPoints < 3)
		 {
			ThinkTankEvent.EventType = WAIT_COMMAND;
			ThinkTankEvent.EventParam = WAIT_FOR_POSITION_FOUND; 
			BinCheckPoints++;
		} else if (BinCheckPoints < 4)
		 {
			ThinkTankEvent.EventType = WAIT_COMMAND;
			ThinkTankEvent.EventParam = WAIT_FOR_POSITION_FOUND; 
			BinCheckPoints++;
		} else if (BinCheckPoints < 5)
         {
            
			GameMonitorEvent.EventType = STOP_AVERAGING;
			
			ThinkTankEvent.EventType = WAIT_COMMAND;
			ThinkTankEvent.EventParam = WAIT_FOR_A_TENTH_SECOND;
			
			BinCheckPoints++;
		} else if (BinCheckPoints < 6)
		{
		   float GoalPoint[2];
         //float NextGoalPoint[2];
         GoalPoint[0] = DepositPointForBinThreeX;
         GoalPoint[1] = DepositPointForBinThreeY;

		   //UpdateCurrentPosition();
			//CurrentPosition[X_COORDINATE] = GetX();
			//CurrentPosition[Y_COORDINATE] = GetY();
			//CurrentPosition[THETA] = GetTheta();
			ThinkTankEvent =  GenerateNextStep_GoalPoint(CurrentPosition,GoalPoint,WAIT_FOR_A_TENTH_SECOND);    /* checkpoint */     
         }  else if (BinCheckPoints < 7)
         {
            
         
            ThinkTankEvent.EventType = WAIT_COMMAND;
            ThinkTankEvent.EventParam = WAIT_FOR_A_TENTH_SECOND;
            Drive(GENTLE_FORWARD);
            wigglecounter++;
            
            if (30 < wigglecounter)
            {
               ES_Event DummyEvent;
               DummyEvent.EventType = DEPOSIT_COMMAND;
               DummyEvent.EventParam = 1;
               ES_PostList00(DummyEvent);
               //printf("dpt tmr end - DUMP\n\r");
               
               
               BinCheckPoints++;
               wigglecounter = 0;
            }
            
         } else
         {
            static int done_wiggling;
            
            ThinkTankEvent.EventType = WAIT_COMMAND;
            ThinkTankEvent.EventParam = WAIT_FOR_A_WIGGLE_TIME;
            
            
               
            if(done_wiggling < 22)   
            {
               if (wigglecounter == 0)
               {
                  float param = 50;
                  Drive(0);
                  Rotate(param);//*GENTLE_FORWARD);  
                  puts("-"); 
                  ThinkTankEvent.EventParam = 3*WAIT_FOR_A_TENTH_SECOND;  // 4?
               } else if (wigglecounter == 1)
               {
                  float param = -75;
                  puts("+");
                  Drive(0);
                  Rotate(param);//GENTLE_FORWARD);      
               } else if(wigglecounter == 2) 
               {
                  float param = 50;
                  Drive(0);
                  Rotate(param);//*GENTLE_FORWARD);  
                  puts("-"); 
                  ThinkTankEvent.EventParam = 3*WAIT_FOR_A_TENTH_SECOND;
               } else if(wigglecounter == 3)
               {
                  float param = -75;
                  puts("+");
                  Drive(0);
                  Rotate(param);//GENTLE_FORWARD);
                  wigglecounter = 0;
               }
            
            } else if (done_wiggling == 6)
            {
              
               ES_Event DummyEvent;
                Drive(0);
               DummyEvent.EventType = DEPOSIT_COMPLETE;
               DummyEvent.EventParam = 1;
               //ES_PostList02(DummyEvent);   
            }
            
            wigglecounter++;
            done_wiggling++;
         }
      break;
      
      case DEPOSIT_IN_BIN_FOUR :
         if (BinCheckPoints < 1)
         {
			ThinkTankEvent = GenerateNextStep_RadialPath(CurrentPosition,RADIUS_OF_SAFETY-2*HALF_BOT_LENGTH,WAIT_FOR_POSITION_FOUND);   
            
         } else if (BinCheckPoints < 2)
         {
            float GoalPoint[2];
            //float NextGoalPoint[2];
            GoalPoint[0] = StagingPointForBinFourX;
            GoalPoint[1] = StagingPointForBinFourY;
            //NextGoalPoint[0] = BinOneDepositX;
            //NextGoalPoint[1] = BinOneDepositY;
            GameMonitorEvent.EventType = START_AVERAGING;
			ThinkTankEvent = GenerateNextStep_GoalPoint(CurrentPosition,GoalPoint,WAIT_FOR_POSITION_FOUND); 
         } else if (BinCheckPoints < 3)
		 {
			ThinkTankEvent.EventType = WAIT_COMMAND;
			ThinkTankEvent.EventParam = WAIT_FOR_POSITION_FOUND; 
			BinCheckPoints++;
		} else if (BinCheckPoints < 4)
		 {
			ThinkTankEvent.EventType = WAIT_COMMAND;
			ThinkTankEvent.EventParam = WAIT_FOR_POSITION_FOUND; 
			BinCheckPoints++;
		} else if (BinCheckPoints < 5)
         {
            
			GameMonitorEvent.EventType = STOP_AVERAGING;
			
			ThinkTankEvent.EventType = WAIT_COMMAND;
			ThinkTankEvent.EventParam = WAIT_FOR_A_TENTH_SECOND;
			
			BinCheckPoints++;
		} else if (BinCheckPoints < 6)
		{
		   float GoalPoint[2];
         //float NextGoalPoint[2];
         GoalPoint[0] = DepositPointForBinFourX;
         GoalPoint[1] = DepositPointForBinFourY;

		   //UpdateCurrentPosition();
			//CurrentPosition[X_COORDINATE] = GetX();
			//CurrentPosition[Y_COORDINATE] = GetY();
			//CurrentPosition[THETA] = GetTheta();
			ThinkTankEvent =  GenerateNextStep_GoalPoint(CurrentPosition,GoalPoint,WAIT_FOR_A_TENTH_SECOND);    /* checkpoint */     
         }  else if (BinCheckPoints < 7)
         {
            
         
            ThinkTankEvent.EventType = WAIT_COMMAND;
            ThinkTankEvent.EventParam = WAIT_FOR_A_TENTH_SECOND;
            Drive(GENTLE_FORWARD);
            wigglecounter++;
            
            if (30 < wigglecounter)
            {
               ES_Event DummyEvent;
               DummyEvent.EventType = DEPOSIT_COMMAND;
               DummyEvent.EventParam = 1;
               ES_PostList00(DummyEvent);
               //printf("dpt tmr end - DUMP\n\r");
               
               
               BinCheckPoints++;
               wigglecounter = 0;
            }
            
         } else
         {
            static int done_wiggling;
            
            ThinkTankEvent.EventType = WAIT_COMMAND;
            ThinkTankEvent.EventParam = WAIT_FOR_A_WIGGLE_TIME;
            
            
               
            if(done_wiggling < 22)   
            {
               if (wigglecounter == 0)
               {
                  float param = 50;
                  Drive(0);
                  Rotate(param);//*GENTLE_FORWARD);  
                  puts("-"); 
                  ThinkTankEvent.EventParam = 3*WAIT_FOR_A_TENTH_SECOND;  // 4?
               } else if (wigglecounter == 1)
               {
                  float param = -75;
                  puts("+");
                  Drive(0);
                  Rotate(param);//GENTLE_FORWARD);      
               } else if(wigglecounter == 2) 
               {
                  float param = 50;
                  Drive(0);
                  Rotate(param);//*GENTLE_FORWARD);  
                  puts("-"); 
                  ThinkTankEvent.EventParam = 3*WAIT_FOR_A_TENTH_SECOND;
               } else if(wigglecounter == 3)
               {
                  float param = -75;
                  puts("+");
                  Drive(0);
                  Rotate(param);//GENTLE_FORWARD);
                  wigglecounter = 0;
               }
            
            } else if (done_wiggling == 6)
            {
              
               ES_Event DummyEvent;
                Drive(0);
               DummyEvent.EventType = DEPOSIT_COMPLETE;
               DummyEvent.EventParam = 1;
               //ES_PostList02(DummyEvent);   
            }
            
            wigglecounter++;
            done_wiggling++;
         }
      break;
      
     
      
      
      
   }
  
  
   }
/*  
   switch(ThinkTankEvent.EventType)
{
   case(TURN_COMMAND)   :
   printf("Current Event is TURN_COMMAND\n\r");
   break;
   case(GO_COMMAND)  :
   printf("Current Event is GO_COMMAND\n\r");
   break;
   case(WAIT_COMMAND)  :
   printf("Current Event is WAIT_COMMAND\n\r");
   break;
   case(ARRIVED) :
   printf("Current Event is whimsical.\n\r");
   default:
   printf("epic fail\n\r");
   
   
}
*/

if(QueryTankSM()!=DISABLED)

   ES_PostList00(ThinkTankEvent);
   ES_PostList04(ThinkTankEvent);
   ES_PostList03(GameMonitorEvent);
   printf("We're at X = %f, Y= %f, and Theta = %f, Wall is at %d\n\r", CurrentPosition[0],CurrentPosition[1],CurrentPosition[2],CurrentWallAngle);

   //ES_PostList02(TankEvent);
   //printf("event param = %f",ThinkTankEvent.EventParam);
}
}
Ejemplo n.º 8
0
	void CPRS::DispCycle(void)
	{
		if(!m_fsm.IsInProgress(C_DISP_PRS_START, C_DISP_PRS_END))
			return;

		if(m_fsm.TmLimit(20000))
		{
			m_fsm.Set(C_ERROR, ER_DISP_PRS_TIME_OVER);
			return;
		}

		switch(m_fsm.Get())
		{
		case C_DISP_PRS_START:
			if(m_fsm.Once())
			{
				m_tmCycle.Reset();
				m_bStopCycle = FALSE;
				m_nCnt = 0;
				g_io.SetDO(oDisTopQcReset, TRUE);
			}
			else
			{
				if(!m_fsm.Delay(100))
					break;
				g_io.SetDO(oDisTopQcReset, FALSE);
				m_fsm.Set(C_DISP_PRS_MOVE);
			}	
			break;

		case C_DISP_PRS_MOVE:
			if(m_bStopCycle)
			{
				m_fsm.Set(C_IDLE);
				break;
			}

			if(!g_Disp.m_pMtX->IsRdy() || !g_Disp.m_pMtY->IsRdy())
				break;

			if(m_fsm.Once())
			{
				POINT2D ptXY = g_Disp.GetPRSPos(m_nCnt);
				g_Disp.m_pMtX->PMove(DISPENSER::P_DISPX_PRS, ptXY.x);
				g_Disp.m_pMtY->PMove(DISPENSER::P_DISPY_PRS, ptXY.y);
			}
			else 
			{
				if(!m_fsm.Delay(100))
					break;

				g_pNV->SetDDm(viDispTopWrComp, 0);
				g_Disp.m_trigTopVi.StartTrigOneShot();
				m_fsm.Set(C_DISP_PRS_WAIT_COMP);
			}
			break;

		case C_DISP_PRS_WAIT_COMP:
			if(g_io.AOn(iViDispTopPrsFail))
			{
				m_fsm.Set(C_ERROR, ER_DISP_TOP_VI_FAIL);
				break;
			}

			if(m_fsm.TmLimit(5000))
			{
				m_fsm.Set(C_ERROR, ER_DISP_TOP_VI_TIME_OVER);
				break;
			}


			if(0 == (int)g_pNV->GetDDm(viDispTopWrComp))
				break;

			if((10 < g_pNV->GetDDm(viDispTopX)) || (10 < g_pNV->GetDDm(viDispTopY)))
			{
				m_fsm.Set(C_ERROR, ER_DISP_TOP_VI_FAIL);
				break;
			}

			g_Disp.m_viVal[m_nCnt].x = g_pNV->GetDDm(viDispTopX);
			g_Disp.m_viVal[m_nCnt].y = g_pNV->GetDDm(viDispTopY);

			if(3 <= m_nCnt)
			{
				m_fsm.Set(C_DISP_PRS_END);
			}
			else
			{
				m_nCnt++;
				m_fsm.Set(C_DISP_PRS_MOVE);
			}
			break;

		case C_DISP_PRS_INIT:
			if(!g_Disp.MoveZInit())
				break;

			m_fsm.Set(C_DISP_PRS_START);
			break;

		case C_DISP_PRS_END:
			{
				POINT2D ptPRS[4];

				ptPRS[L_BTM].x = g_pNV->m_pNv->_prsCoord._coord[L_BTM]._dX;
				ptPRS[L_BTM].y = g_pNV->m_pNv->_prsCoord._coord[L_BTM]._dY;

				ptPRS[R_BTM].x = g_pNV->m_pNv->_prsCoord._coord[R_BTM]._dX;
				ptPRS[R_BTM].y = g_pNV->m_pNv->_prsCoord._coord[R_BTM]._dY;

				double dAdj = (ptPRS[R_BTM].x + g_Disp.m_viVal[R_BTM].x) - (ptPRS[L_BTM].x + g_Disp.m_viVal[L_BTM].x);
				double dOpp = (ptPRS[R_BTM].y + g_Disp.m_viVal[R_BTM].y) - (ptPRS[L_BTM].y + g_Disp.m_viVal[L_BTM].y);

				g_Disp.m_dGlassTheta = GetTheta(dAdj, dOpp);

				if(GST_DISP_PRS == g_pNV->GetNDm(procState))
					g_pNV->SetNDm(procState, GST_PP_PRS);

				double dCycleTime = m_tmCycle.Elapsed() / 1000.0;
				g_pNV->SetDDm(dispPRSTime, dCycleTime);

				m_fsm.Set(C_IDLE);
			}
			break;
		}
	}//--------------------------------------------------------------
Ejemplo n.º 9
0
//---------------------------------------------------------------------------
///Just call the executable TestTwoDigitNewickRelease
///with the parameters
bool TestTwoDigitNewickRelease::Execute()
{
  #ifndef WIN32
  const std::string exe_filename = "../Exes/TestTwoDigitNewickUbuntuRelease";
  #else
  const std::string exe_filename = "../Exes/TestTwoDigitNewickWinRelease.exe";
  #endif

  const std::string command_full =
  #ifndef WIN32
    std::string("./") +
  #endif
    exe_filename
    + " "
    + boost::lexical_cast<std::string>(GetTheta())
    + " \""
    + GetNewick()
    + "\"";
  const std::string output_filename = "Result_probability.txt";
  return Test::Execute(exe_filename,command_full,output_filename);
  /*
  std::clog << "Starting TestTwoDigitNewickRelease for '"
    << this->GetNewick() << "'\n";
  const std::string filename
  #ifndef WIN32
    = "../../../Tools/ToolTestTwoDigitNewick-build-desktop/TestTwoDigitNewickUbuntuRelease";
  #else
    = "../../../Tools/ToolTestTwoDigitNewick/release/TestNewickVectorWinRelease.exe";
  #endif
  assert(FileExists(filename));
  if (!FileExists(filename))
  {
    std::cerr << "File '" << filename << "' not found\n";
  }
  const std::string command =
  #ifndef WIN32
    std::string("./") +
  #endif
    filename
    + " "
    + boost::lexical_cast<std::string>(GetTheta())
    + " \""
    + GetNewick()
    + "\"";

  const Stopwatch s;

  const int sys_error = std::system(command.c_str());

  if (sys_error == 0)
  {
    m_time = s.elapsed();
    const std::string result_filename = "Result_probability.txt";
    assert(FileExists(result_filename));
    m_probability = ReadDoubleFromFile(result_filename);
    return true;
  }
  else
  {
    m_time = 0;
    m_probability = 0.0;
    return false;
  }
  */
}
Ejemplo n.º 10
0
G4VSolid const* PlacedParallelepiped::ConvertToGeant4() const {
  return new G4Para(GetLabel(), GetX(), GetY(), GetZ(), GetAlpha(), GetTheta(),
                    GetPhi());
}
Ejemplo n.º 11
0
Archivo: reco.C Proyecto: FCALSW/LuCaS
void reco( Double_t dcut , Long64_t nwanted, TString fname )
{
  // attache dictionaries before file
	gSystem->Load("./lib/libLucasDict.so");
        TFile fin ( fname );
        TTree *Lcal = (TTree*)fin.Get("Lcal");
        if (Lcal == 0) return;
	pTracks = 0; 
        pHits   = 0;

       Lcal->SetBranchAddress("vX", &vX ); 
       Lcal->SetBranchAddress("vY", &vY ); 
       Lcal->SetBranchAddress("vZ", &vZ ); 
       Lcal->SetBranchAddress("numPrim", &numPrim );
       Lcal->SetBranchAddress("numHits", &numHits );
       Lcal->SetBranchAddress("Etot", Etot );
       Lcal->SetBranchAddress("Emax", &Emax );
       Lcal->SetBranchAddress("Tracks", &pTracks ); 
       Lcal->SetBranchAddress("Hits", &pHits );
   
   Int_t Nbins = 300;
   Double_t Xlo=   2.5;
   Double_t Xup= 1502.5;
   //
   TFile *out = new TFile("reco-plots-rot0-uncor.root","RECREATE");
   //
   TF1 *res1 = new TF1("res1","sqrt([0]*[0]/x+[1]*[1])",1.,1601.);
   res1->SetParNames("a","b");
   TF1 *cfun1 = new TF1("cfun1","1.+[0]*exp(-[1]*x*x)+[2]/(x*x+[3])",-45.,45.);
   cfun1->SetParNames("A1","W1","A2","W2");
   TF1 *cfun2 = new TF1("cfun2","1.+ [0]/(x*x+[1])",-45.,45.);
   cfun2->SetParNames("A2","W2");
   //
   TProfile *hpr1 = new TProfile("hpr1"," ;E_{beam} [GeV]; E_{vis} [GeV]",Nbins,Xlo,Xup,0.,1000.,"S");
   TH1D *sigeove =  new TH1D("sigeove"," ;E_{beam} [GeV]; #sigma_{E}/E",Nbins,Xlo,Xup);
   TH1D *rmseove =  new TH1D("rmseove"," ;E_{beam} [GeV]; RMS_{E}/E",Nbins,Xlo,Xup);
   TH1D *dErec[NSAMP_MAX];
   TH1D *euse = new TH1D ( "euse"," ; E_{used}  [GeV] ; Number of events",600, 0., 6. );
   TH1D *edep[NSAMP_MAX];
   TH1D *dphi[NSAMP_MAX], *Qmax[NSAMP_MAX];
   //   TProfile *dgap[NSAMP_MAX];
   TH2D *dgap[NSAMP_MAX];
   TH1D *dtheta[NSAMP_MAX];
   double qmax[NSAMP_MAX];
   TProfile *phioff = new TProfile("phioff","#phi offset;1/P  [GeV^{-1}];<#Delta#Phi>   [rad]",500,0.,0.25,-TWO_PI,TWO_PI,"E");
   for( int ih=0; ih<NSAMP_MAX; ih++){
     TString nam1("dphi");
     TString nam2("edep");
     TString nam3("dErec");
     TString nam4("dgap");
     TString nam5("dtheta");
     TString nam6("Qmax");
     nam1 += ih;
     nam2 += ih;
     nam3 += ih;
     nam4 += ih;
     nam5 += ih;
     nam6 += ih;
     dphi[ih] = new TH1D(nam1,"; #Delta#Phi   [rad]; Number of events", 300, -0.3, 0.3 );
     dtheta[ih] = new TH1D(nam5,"; #Delta#theta   [rad]; Number of events", 200, -0.002, 0.002 );
     edep[ih] = new TH1D(nam2," ; E_{VIS}  [GeV] ; Number of events",500,Elo[ih],Eup[ih]);   
     dErec[ih] = new TH1D( nam3 ," ; #DeltaE   [GeV]; Number of events",60, -25., 25. );
     //     dgap[ih] = new TProfile(nam4,"; distance from the gap [mm]; <E_{VIS}>/E_{VIS}",900,-45.,45.,0.,1000.,"E");
     dgap[ih] = new TH2D(nam4,"; distance from the gap [mm]; <E_{VIS}>/E_{VIS}",900,-45.,45.,100,0.5,1.5);
     Qmax[ih] = new TH1D(nam6,"; Q_{max}    pC; number of events ",40,0.,20.);
     //     dErec[ih]->SetBit(TH1::kCanRebin);
     //     edep[ih]->SetBit(TH1::kCanRebin);
     //     dphi[ih]->SetBit(TH1::kCanRebin);
   }
   //
   //
   std::vector < myHit > hits_P;  // list of hits z > 0
   std::vector < myHit > hits_N;  //              z < 0
   //
   cout << " Energy saturation at "<< E_MAX << " [MeV] " << endl;
   cout << " Energy treshold at   "<< E_MIN << " [MeV] " << endl;
   Long64_t nentries = Lcal->GetEntries();
#ifdef si500
     Double_t p0 =  6.13e-4;   // si 500
     Double_t p1 =  1.71e-2;;
#else
#ifdef rot3_hh
   Double_t p0 = 1.771e-3;  // si=320
   Double_t p1 = 1.122e-2;
#else
   Double_t p0 = 2.145e-3;  // si=320
   Double_t p1 = 1.131e-2;
#endif
#endif
   Double_t C_fac = 0.01138;
  
     /*     Double_t g0 = 1.006e-2;
     Double_t g1 = 2.367e-7;
     Double_t g2 = -7.476e-10;
     */
     // Long64_t nskip = 0;
   nentries = ( nwanted > 0 && nwanted < nentries ) ? nwanted : nentries ;
   cout << " Nentries "<< nentries << endl;
   for (Long64_t jentry=0; jentry< nentries ;jentry++) {
     Double_t theta_rec1 = 0., phi_rec1=0. ;
     Double_t theta_rec2 = 0., phi_rec2=0. ;
     Double_t     e_use1 = 0.,   e_use2=0. ;
     Double_t     e_vis1 = 0.,   e_vis2=0. ;
      hits_N.clear();
      hits_P.clear();
      e_vis2 = 0.;

      Lcal->GetEntry(jentry);
      if ( Etot[1] <= 0.) continue;
      //
      double E_gen=0., theta_gen=0., phi_gen=0.;
      int numtr = pTracks->size();
      for ( int it=0; it< numtr; it++){
      Track_t track = (*pTracks)[it];
      E_gen = sqrt( track.pX*track.pX + track.pY*track.pY + track.pZ*track.pZ )/1000.;
      theta_gen = atan ( sqrt( track.pX*track.pX + track.pY*track.pY)/fabs(track.pZ));
      phi_gen = atan2 ( track.pY , track.pX);
      phi_gen = ( phi_gen > 0. ) ? phi_gen : phi_gen + TWO_PI;
      }
      //
      if ( theta_gen < 0.041 || theta_gen > 0.068 ){ continue;}
      //
      int sample=0;
      switch( (int)E_gen ){
      case 5:
	sample = 0;
        break;
      case 15:
	sample = 1;
        break;
      case 25:
	sample = 2;
        break;
      case 50:
	sample = 3;
        break;
      case 100:
	sample = 4;
        break;
      case 150:
	sample = 5;
        break;
      case 200:
	sample = 6;
        break;
      case 250:
	sample = 7;
        break;
      case 500:
	sample = 8;
        break;
      case 1500:
	sample = 9;
        break;
      default:
	cout<< "uknown case " << (int)E_gen << endl;
      }
      //
      // Fill the list of hits
      //
      int nHits = pHits->size();
      qmax[sample] = 0.;
      for ( Int_t ih=0; ih<nHits ; ih++) {
	// Int_t layer   = (cellID[ih] >> 16) & 0xff ;
	//
        Hit_t hit = (*pHits)[ih];
	double ehit = ( hit.eHit > E_MAX ) ? E_MAX : hit.eHit ;
	if ( ehit < E_MIN ) continue ;
        if ( qmax[sample] < ehit ) qmax[sample]=ehit; 
	// 
	//        Double_t rCell = sqrt( hit.xCell*hit.xCell+hit.yCell*hit.yCell);
        Double_t rCell = sqrt( hit.xHit*hit.xHit + hit.yHit*hit.yHit);
        Double_t phiCell = atan2( hit.yCell, hit.xCell );
        if ( hit.zCell < 0. ) {
          hits_N.push_back ( myHit( ehit, rCell, phiCell, hit.zCell) );
	}
        else {
          hits_P.push_back ( myHit( ehit, rCell, phiCell, hit.zCell) );
	} 

      } // end hit loop
      //
      // sort hits in descending order
      //
      //      cout<< " accepted " << nskip << " " << hits_P.size()<< " " << hits_N.size() << endl;
     
     if ( hits_N.begin() != hits_N.end() ) {
	std::sort ( hits_N.begin(), hits_N.end(), SortByEnergy );
	theta_rec1 = GetTheta ( hits_N );
	phi_rec1 = GetPhi ( hits_N );
	    e_vis1 = GetEnergy( theta_rec1, hits_N );
      }

      if ( hits_P.begin() != hits_P.end() ) {
	std::sort ( hits_P.begin(), hits_P.end(), SortByEnergy );
	theta_rec2 = GetTheta( hits_P );
	phi_rec2 = GetPhi ( hits_P );
#ifdef rot3_hh
	double dist = GetDistance( theta_rec2, phi_rec2, 3.75);
#else
	double dist = GetDistance( theta_rec2, phi_rec2, 0.);
#endif
      
	//       	if ( CheckSector( phi_rec2 ) )continue;
      	if ( fabs(dist) < dcut ) continue;
	double avrEvis = p0 + p1*E_gen;
	    e_vis2 = GetEnergy(  hits_P )/1000.;
	    //       	    e_vis2 *= GetCorrection( sample, dist);
	    dgap[sample]->Fill( dist, avrEvis/e_vis2, 1.  );
      }

      //
      // fill histograms
      //
      C_fac = (e_vis2 - p0)/p1;
      Double_t delta_phi = phi_gen - (phi_rec2 + PHI_OFFSET[sample]);
      Double_t pT = 1./(E_gen*sin(theta_rec2));
      Double_t E_rec = C_fac ;
      //      double delta = p1*p1 - 4.*p2*(p0-e_vis2);
      //      if( delta >= 0. ) E_rec = (-p1+sqrt(delta))/(2.*p2);
      Qmax[sample]->Fill( qmax[sample]*E2Q );
      dtheta[sample] -> Fill ( theta_rec2 - theta_gen );
      dphi[sample]-> Fill ( delta_phi);
      phioff->Fill( pT , delta_phi );
      if ( e_vis2 > 0. ) {
             edep [sample]-> Fill ( e_vis2 );
	     hpr1->Fill(E_gen,e_vis2,1.);
	     dErec[sample]  -> Fill ( ( E_rec - E_gen));
	     euse -> Fill ( e_use2 );
      }
      if  ( e_use1 > 0.) euse -> Fill ( e_use1 );
      //
      //
      // end of event
      // 
   }
   // final operations with histograms 
   //
   int binum[NSAMP_MAX] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
   int ii = 1;
   for ( int ib=1; ib < hpr1->GetNbinsX()+1; ib++ ){
     double binc = hpr1->GetBinContent(ib);
     if( binc > 0.){
      binum[ii] = ib;
      cout << "bin: " << ii << "\t value: " << binc << endl;
      ii++;
      }
   }
  //
   //
   for ( int ih=0;ih<NSAMP_MAX;ih++){
     if( edep[ih]->Integral() > 0. ) {
       cout<< " fitting ih: " << ih << "\t"<<ebeam[ih] << endl;
       edep[ih]->Fit("gaus","QS0");
       TF1 *f = edep[ih]->GetFunction("gaus");
       double mean = f->GetParameter(1);
       double rmse = f->GetParameter(2);
       double ratio = rmse/mean;
       double e1 = f->GetParError(1);
       double e2 = f->GetParError(2);
       double err = sqrt(e1*e1/(mean*mean)+e2*e2/(rmse*rmse))*ratio;
       cout << "<E> " << mean << " sigma "<< rmse << endl;
       sigeove->SetBinContent( binum[ih], ratio );
       sigeove->SetBinError( binum[ih], err );
    //
       mean = edep[ih]->GetMean();
       rmse = edep[ih]->GetRMS();
       e1 = edep[ih]->GetMeanError();
       e2 = edep[ih]->GetRMSError();
       ratio = rmse/mean;
       err = sqrt(e1*e1/(mean*mean)+e2*e2/(rmse*rmse))*ratio;
       rmseove->SetBinContent( binum[ih], ratio);
       rmseove->SetBinError( binum[ih],2.*err);
       dErec[ih]->Fit("gaus","QW");
     }
    }
   sigeove->Fit("res1");
   rmseove->Fit("res1");
   //
   //
   Double_t P0[NSAMP_MAX],P1[NSAMP_MAX],P2[NSAMP_MAX],P3[NSAMP_MAX];
   for ( int ih=0; ih<NSAMP_MAX; ih++){
     P0[ih] = 0.;
     P1[ih] = 0.;
     P2[ih] = 0.;
     P3[ih] = 0.;
   }

     for( int ih=0; ih<NSAMP_MAX; ih++){
       if( dphi[ih]->Integral() > 0. ) {
	 cout<< " Fitting gap: "<< ih <<"\t E= "<<ebeam[ih]<<endl;
         dphi[ih]->Fit("gaus","QS0");
         dtheta[ih]->Fit("gaus","QS0");
	 dgap[ih]->Fit("cfun2","QW");
	 TF1 *f=dgap[ih]->GetFunction("cfun2");
     // P0[ih]=f->GetParameter(0);
     // P1[ih]=f->GetParameter(1);
       P2[ih]=f->GetParameter(0);
       P3[ih]=f->GetParameter(1);
    
       dgap[ih]->GetYaxis()->SetRangeUser(0.9, 2.5);
       }
     }
     //
     
     cout << "const double a1[NSAMP_MAX] = {" ;
     for (int ih=0;ih<9;ih++) printf("%5.3e%1s",P0[ih],", ");
     cout<<endl;
     cout << "const double w1[NSAMP_MAX] = {" ;
     for (int ih=0;ih<9;ih++) printf("%5.3e%1s",P1[ih],", ");
     cout<<endl;
     cout << "const double a2[NSAMP_MAX] = {" ;
     for (int ih=0;ih<9;ih++) printf("%5.3e%1s",P2[ih],", ");
     cout<<endl;
     cout << "const double w2[NSAMP_MAX] = {" ;
      for (int ih=0;ih<9;ih++) printf("%5.3e%1s",P3[ih],", ");
     cout<<endl;
     
     /*

     hpr1->Write();
     phioff->Write();
     sigeove->Write();
     rmseove->Write();
     */
     out->Write();
     //    out->Close();
}