Esempio n. 1
0
//------------------------------------------------------------------------------
bool EndFiniteBurn::Execute()
{
   ValidateThrusters();

   // Only do this if the FiniteBurn is the one this command controls...
   bool forceActive = false;
   for (std::vector<PhysicalModel*>::iterator j = transientForces->begin();
        j != transientForces->end(); ++j)
   {
      if (((*j)->GetName()) == thrustName)
      {
         // ... and if it is set for the right spacecraft
         StringArray burnSatNames = (*j)->GetRefObjectNameArray(Gmat::SPACECRAFT);

         bool foundSats = false;
         UnsignedInt numberFound = 0;
         for (UnsignedInt i = 0; i < satNames.size(); ++i)
         {
            if (find(burnSatNames.begin(), burnSatNames.end(), satNames[i]) != burnSatNames.end())
            {
               foundSats = true;
               ++numberFound;
            }
         }
         if (foundSats)
         {
            #ifdef DEBUG_TRANSIENT_FORCES
               MessageInterface::ShowMessage("EndFiniteBurn::Execute(): The burn "
                     "is active\n");
            #endif

            forceActive = true;

            if (numberFound != satNames.size())
               MessageInterface::ShowMessage("*** WARNING *** Turning off the "
                     "finite burn %s, but the EndFiniteBurn command did not "
                     "list all of the spacecraft that are no longer "
                     "maneuvering.\n", burnName.c_str());

            break;
         }
      }
   }
   
   if (forceActive)
   {
      // Turn off all of the referenced thrusters
      for (std::vector<Thruster*>::iterator i = thrusters.begin();
           i != thrusters.end(); ++i)
      {
         Thruster *th = *i;
         #ifdef DEBUG_END_MANEUVER_EXE
            MessageInterface::ShowMessage
               ("EndFiniteBurn::Execute() Deactivating engine <%p>'%s'\n", th,
                th->GetName().c_str());
         #endif
         th->SetBooleanParameter(th->GetParameterID("IsFiring"), false);
   
         #ifdef DEBUG_END_MANEUVER_EXE
            MessageInterface::ShowMessage
               ("Checking to see if engine is inactive: returned %s\n",
                (th->GetBooleanParameter(th->GetParameterID("IsFiring")) ?
                 "true" : "false"));
         #endif
      }

      // Tell active spacecraft that they are no longer firing
      for (std::vector<Spacecraft*>::iterator s=sats.begin(); s!=sats.end(); ++s)
      {
         #ifdef DEBUG_END_MANEUVER_EXE
            MessageInterface::ShowMessage
                  ("EndFiniteBurn::Execute() Deactivating maneuvers on Spacecraft "
                   "<%p>'%s'\n", *s, (*s)->GetName().c_str());
         #endif
         /// todo: Be sure that no other maneuver has the spacecraft maneuvering;
         /// for R2013a this is not an issue since only 1 burn per spacecraft is
         /// allowed.  We'll need to fix this when that restriction is removed.
         (*s)->IsManeuvering(false);
      }

      // Remove the force from the list of transient forces
      for (std::vector<PhysicalModel*>::iterator j = transientForces->begin();
           j != transientForces->end(); ++j)
      {
         if (((*j)->GetName()) == thrustName)
         {
            #ifdef DEBUG_TRANSIENT_FORCES
            MessageInterface::ShowMessage
               ("EndFiniteBurn::Execute() Removing burnForce<%p>'%s' from "
                     "transientForces\n", *j, (*j)->GetName().c_str());
            #endif
            transientForces->erase(j);
            break;
         }
      }

      // Reset maneuvering to Publisher so that any subscriber can do its own action
      if (!sats.empty())
      {
         Real epoch = sats[0]->GetEpoch();
         publisher->SetManeuvering(this, false, epoch, satNames, "end of finite "
               "maneuver");
      }

      #ifdef DEBUG_END_MANEUVER_EXE
         MessageInterface::ShowMessage("EndFiniteBurn::Execute() Current TransientForces list:\n");
         for (std::vector<PhysicalModel*>::iterator j = transientForces->begin();
              j != transientForces->end(); ++j)
            MessageInterface::ShowMessage("   %s\n", (*j)->GetName().c_str());
      #endif
   }
   
   BuildCommandSummary(true);
   return true;
}
Esempio n. 2
0
//------------------------------------------------------------------------------
bool BeginFiniteBurn::Execute()
{
   ValidateThrusters();
   
   // Turn on all of the referenced thrusters
   #ifdef DEBUG_BEGIN_MANEUVER_EXE
   MessageInterface::ShowMessage
      ("BeginFiniteBurn::Execute() <%p>'%s' entered\n   "
       "There are %d thruster(s) in use\n", this,
       GetGeneratingString(Gmat::NO_COMMENTS).c_str(), thrusters.size());
   #endif
   for (std::vector<Thruster*>::iterator i = thrusters.begin(); 
        i != thrusters.end(); ++i)
   {
      Thruster *th = *i;
      #ifdef DEBUG_BEGIN_MANEUVER_EXE
         MessageInterface::ShowMessage
            ("Activating engine <%p>'%s'\n", th, th->GetName().c_str());
      #endif
      th->SetBooleanParameter(th->GetParameterID("IsFiring"), true);
      
      #ifdef DEBUG_BEGIN_MANEUVER_EXE
         MessageInterface::ShowMessage
            ("Checking to see if engine is active: returned %s\n", 
             (th->GetBooleanParameter(th->GetParameterID("IsFiring")) ? 
              "true" : "false"));
      #endif
   }
   
   // Tell active spacecraft that they are now firing
   for (std::vector<Spacecraft*>::iterator s=sats.begin(); s!=sats.end(); ++s)
   {
      (*s)->IsManeuvering(true);
   }

   if (transientForces == NULL)
      throw CommandException("Transient force list was NOT initialized; "
            "ABORTING RUN!!!\n\n");
   
   // Insert the force into the list of transient forces if not found
   if (transientForces->size() == 0)
   {
      #ifdef DEBUG_TRANSIENT_FORCES
      MessageInterface::ShowMessage
         ("BeginFiniteBurn::Execute() Adding first burnForce<%p>'%s' to "
               "transientForces\n", burnForce, burnForce->GetName().c_str());
      #endif
      transientForces->push_back(burnForce);
   }
   else
   {
      bool alreadyThere = false;
      for (std::vector<PhysicalModel*>::iterator i = transientForces->begin();
            i !=transientForces->end(); ++i)
      {
         if ((*i)->IsOfType("FiniteThrust"))
         {
            FiniteThrust *transient = (FiniteThrust*)(*i);
            if (transient == burnForce)
            {
               alreadyThere = true;
            }

            if ((*transient) == (*burnForce))
            {
               MessageInterface::ShowMessage("Burn activated by the line\n   "
                     "%s\noverlaps with an active finite burn.  No new finite "
                     "burn will be applied.\n",
                     GetGeneratingString(Gmat::NO_COMMENTS).c_str());
               alreadyThere = true;
            }
         }
      }
      if (alreadyThere == false)
      {
         #ifdef DEBUG_TRANSIENT_FORCES
         MessageInterface::ShowMessage("BeginFiniteBurn::Execute() Adding "
               "burnForce<%p>'%s' to transientForces\n", burnForce,
               burnForce->GetName().c_str());
         #endif
         transientForces->push_back(burnForce);
      }
   }
   
   // Set maneuvering to Publisher so that any subscriber can do its own action
   if (!sats.empty())
   {
      Real epoch = sats[0]->GetEpoch();
      publisher->SetManeuvering(this, true, epoch, satNames,
            "begin of finite maneuver");
   }
   
   #ifdef DEBUG_BEGIN_MANEUVER_EXE
      MessageInterface::ShowMessage
         ("There are %d transient force(s)\n", transientForces->size());
      MessageInterface::ShowMessage("Current TransientForces list:\n");
      for (std::vector<PhysicalModel*>::iterator j = transientForces->begin();
           j != transientForces->end(); ++j)
         MessageInterface::ShowMessage("   %s\n", (*j)->GetName().c_str());
   #endif
   
   BuildCommandSummary(true);
   return true;
}