void LinearActuatorNoPot::Initialize(int retractedAngle, int extendedAngle, int actuatorLength, int actuatorSpeed, bool southernHemisphere) { pinMode(_enableActuator, OUTPUT); pinMode(_PWMa, OUTPUT); pinMode(_PWMb, OUTPUT); _southernHemisphere = southernHemisphere; _extendedAngle = FlipAngle(extendedAngle); _retractedAngle = FlipAngle(retractedAngle); _state = ActuatorState_Initializing; _actuatorLength = actuatorLength; _inchesPerSecond = actuatorSpeed / 100.0; Retract(); }
int main() { try { using once = Once; using times = Times; // run-time configurable: const int Nsweep = 1; const int Nsection = 2; const bool onceX = true; auto scanner = create_scanner ( "Z" ); const auto distance = create_condition( "123 nm" ); const auto threshold = create_condition( "chan1", "<=", "2.7 V" ); Curve curve; curve.times( Nsweep ) .scans( scanner ) .add ( Retract().stop_on( distance ) ).unless( onceX ) .add ( once ( Retract().stop_on( distance ) ) ).when ( onceX ) .add ( times( Nsection ) .add ( Dwell() ) .add ( Approach().stop_on( threshold ) ) .add ( Dwell() ) .add ( Retract ().stop_on( distance ) ) ) ; std::cout << "\n1.curve.sweep(): "; curve.sweep(); std::cout << "\n2.curve.sweep(): "; curve.sweep(); } catch ( std::exception const & e ) { std::cout << "Error: " << e.what() << std::endl; } }
globle int HandleExistingFuzzyFact( VOID **theFact) { struct fact *tempFact; struct factHashEntry *theFactHash; int hashValue; struct fact *theFactPtr = (struct fact *)*theFact; hashValue = HashFact(theFactPtr); /* Fuzzy facts never get duplicated ... they just get modified if they already exist ... always allow duplication for them... do the required modification to the fact if it already exists */ theFactHash = FactHashTable[hashValue]; tempFact = NULL; while (theFactHash != NULL) { if (theFactPtr->whichDeftemplate == theFactHash->theFact->whichDeftemplate) { /* same template definitions for fact */ if (MultifieldsEqual(&theFactPtr->theProposition, &theFactHash->theFact->theProposition)) { /* MultiFieldsEqual will compare fuzzy fields to be equal if they are both of the same FUZZY_VALUE type */ tempFact = theFactHash->theFact; #if CERTAINTY_FACTORS /* If facts are the same we need to perform global contribution calculation for CF */ changeCFofNewVsExistingFact(theFactPtr, tempFact); #endif /* fuzzy facts (ie. any fuzzy slots) perform global contribution calculation(s) for each fuzzy slot */ changeValueOfFuzzySlots(tempFact, theFactPtr); break; } } theFactHash = theFactHash->next; } if (tempFact != NULL) /* existing fact! retract it before new one gets asserted */ Retract(tempFact); return(hashValue); }
void DockingProbe::DockEvent(int dock, OBJHANDLE connected) { if (!FirstTimeStepDone) return; if (IgnoreNextDockEvent > 0) { Docked = (connected != NULL); IgnoreNextDockEvent--; return; } /// /// Advanced Orbiter Handling submitted by Artlav /// ~More realistic capture and retract /// if (connected == NULL) { Docked = false; Dockproc = DOCKINGPROBE_PROC_UNDOCKED; DOCKHANDLE dock = OurVessel->GetDockHandle(ourPort); OurVessel->SetDockParams(dock, Dockparam[0], Dockparam[1], Dockparam[2]); } else { Docked = true; DOCKHANDLE dock = OurVessel->GetDockHandle(ourPort); OurVessel->GetDockParams(dock, Dockparam[0], Dockparam[1], Dockparam[2]); if (!Enabled || Status != DOCKINGPROBE_STATUS_EXTENDED) { DockFailedSound.play(NOLOOP, 200); UndockNextTimestep = true; } else { Status = 0.9; CaptureSound.play(); Dockproc = DOCKINGPROBE_PROC_SOFTDOCKED; // Retract automatically if REALISM 0 if (!Realism) { Retract(); } } } }
inline void cut(Eigen::PlainObjectBase<DerivedO> &Handle_Seams) { F_visited.setConstant(F.rows(),0); Handle_Seams.setConstant(F.rows(),3,1); int index=0; for (unsigned f = 0; f<F.rows(); f++) { if (!F_visited(f)) { index++; FloodFill(f, Handle_Seams); } } Retract(Handle_Seams); for (unsigned int f=0;f<F.rows();f++) for (int j=0;j<3;j++) if (IsRotSeam(f,j)) Handle_Seams(f,j)=true; }
globle void RemoveAllFacts() { while (FactList != NULL) { Retract((void *) FactList); } }
void DockingProbe::TimeStep(double simt, double simdt) { if (!FirstTimeStepDone) { DoFirstTimeStep(); FirstTimeStepDone = true; return; } if (UndockNextTimestep) { UpdatePort(Dockparam[1] * 0.5, simdt); OurVessel->Undock(ourPort); UndockNextTimestep = false; } if (ExtendingRetracting > 0) { if (Status >= DOCKINGPROBE_STATUS_EXTENDED) { Status = DOCKINGPROBE_STATUS_EXTENDED; ExtendingRetracting = 0; Dockproc = DOCKINGPROBE_PROC_UNDOCKED; OurVessel->Undocking(ourPort); OurVessel->SetDockingProbeMesh(); } else { Status += 0.33 * simdt; } } else if (ExtendingRetracting < 0) { if (Status <= DOCKINGPROBE_STATUS_RETRACTED) { Status = DOCKINGPROBE_STATUS_RETRACTED; ExtendingRetracting = 0; OurVessel->HaveHardDocked(ourPort); OurVessel->SetDockingProbeMesh(); } else { Status -= 0.33 * simdt; } } if (Dockproc == DOCKINGPROBE_PROC_SOFTDOCKED) { UpdatePort(Dockparam[1] * 0.5, simdt); Dockproc = DOCKINGPROBE_PROC_HARDDOCKED; } else if (Dockproc == DOCKINGPROBE_PROC_HARDDOCKED) { if (Status > DOCKINGPROBE_STATUS_RETRACTED) { UpdatePort(Dockparam[1] * 0.5 * Status / 0.9, simdt); } else { UpdatePort(_V(0,0,0), simdt); Dockproc = DOCKINGPROBE_PROC_UNDOCKED; } } // sprintf(oapiDebugString(), "Docked %d Status %.3f Dockproc %d ExtendingRetracting %d", (Docked ? 1 : 0), Status, Dockproc, ExtendingRetracting); // Switching logic if (OurVessel->DockingProbeExtdRelSwitch.IsUp() && IsPowered()) { Extend(); } else if (OurVessel->DockingProbeExtdRelSwitch.IsDown()) { if ((!OurVessel->DockingProbeRetractPrimSwitch.IsCenter() && OurVessel->DockProbeMnACircuitBraker.IsPowered() && OurVessel->PyroBusA.Voltage() > SP_MIN_DCVOLTAGE) || (!OurVessel->DockingProbeRetractSecSwitch.IsCenter() && OurVessel->DockProbeMnBCircuitBraker.IsPowered() && OurVessel->PyroBusB.Voltage() > SP_MIN_DCVOLTAGE)) { int ActiveCharges = 0; if (OurVessel->DockingProbeRetractPrimSwitch.IsUp()) ActiveCharges = ActiveCharges | DOCKINGPROBE_CHARGE_PRIM1; if (OurVessel->DockingProbeRetractPrimSwitch.IsDown()) ActiveCharges = ActiveCharges | DOCKINGPROBE_CHARGE_PRIM2; if (OurVessel->DockingProbeRetractSecSwitch.IsUp()) ActiveCharges = ActiveCharges | DOCKINGPROBE_CHARGE_SEC1; if (OurVessel->DockingProbeRetractSecSwitch.IsDown()) ActiveCharges = ActiveCharges | DOCKINGPROBE_CHARGE_SEC2; if ((ActiveCharges & RetractChargesUsed)!= ActiveCharges) Retract(); RetractChargesUsed = RetractChargesUsed | ActiveCharges; // sprintf(oapiDebugString(), "Charge Used: P1%d P2%d S1%d S2%d", RetractChargesUsed & DOCKINGPROBE_CHARGE_PRIM1 , RetractChargesUsed & DOCKINGPROBE_CHARGE_PRIM2 , RetractChargesUsed & DOCKINGPROBE_CHARGE_SEC1 , RetractChargesUsed & DOCKINGPROBE_CHARGE_SEC2); } } /// /// Begin Advanced Docking Code /// if (DockingMethod > ADVANCED){ // Code that follows is largely lifted from Atlantis... // Goal is to handle close proximity docking between a probe and drogue VECTOR3 gdrgPos, gdrgDir, gprbPos, gprbDir, gvslPos, rvel, pos, dir, rot; OurVessel->Local2Global (Dockparam[0],gprbPos); //converts probe location to global OurVessel->GlobalRot (Dockparam[1],gprbDir); //rotates probe direction to global // Search the complete vessel list for a grappling candidate. // Not very scalable ... for (DWORD i = 0; i < oapiGetVesselCount(); i++) { OBJHANDLE hV = oapiGetVesselByIndex (i); if (hV == OurVessel->GetHandle()) continue; // we don't want to grapple ourselves ... oapiGetGlobalPos (hV, &gvslPos); if (dist (gvslPos, gprbPos) < oapiGetSize (hV)) { // in range VESSEL *v = oapiGetVesselInterface (hV); DWORD nAttach = v->AttachmentCount (true); for (DWORD j = 0; j < nAttach; j++) { // now scan all attachment points of the candidate ATTACHMENTHANDLE hAtt = v->GetAttachmentHandle (true, j); const char *id = v->GetAttachmentId (hAtt); if (strncmp (id, "PADROGUE", 8)) continue; // attachment point not compatible v->GetAttachmentParams (hAtt, pos, dir, rot); v->Local2Global (pos, gdrgPos); // converts found drogue position to global v->GlobalRot (dir, gdrgDir); // rotates found drogue direction to global if (dist (gdrgPos, gprbPos) < COLLISION_DETECT_RANGE && DockingMethod == ADVANCEDPHYSICS) { // found one less than a meter away! // Detect if collision has happend, if so, t will return intersection point along the probe line X(t) = gprbPos + t * gprbDir double t = CollisionDetection(gprbPos, gprbDir, gdrgPos, gdrgDir); // Calculate time of penetration according to current velocity OurVessel->GetRelativeVel(hV, rvel); // Determine resultant force //APPLY rforce to DockingProbe Vessel, and APPLY -rforce to Drogue Vessel return; } if (dist(gdrgPos, gprbPos) < CAPTURE_DETECT_RANGE && DockingMethod > ADVANCED) { // If we're within capture range, set docking port to attachment so docking can take place // Originally, I would have used the Attachment features to soft dock and move the LM during retract // but Artlav's docking method does this better and uses the docking port itself. // Attachment is being used as a placeholder for the docking port and to identify its orientation. OurVessel->GetAttachmentParams(hattPROBE, pos, dir, rot); DOCKHANDLE dock = OurVessel->GetDockHandle(ourPort); OurVessel->SetDockParams(dock, pos, dir, rot); } }//for nAttach }//if inRange }//for nVessel } }
Token* LexicalAnalyzer::GetNextToken() { if(IsEndOfFile()) return EndOfFileToken(); char c = NextChar(); m_lexemeBegin = m_forward; m_dfa->Reset(); int m_currentTokenTypeId = TOKEN_Unrecognized; while(true) { m_currentTokenTypeId = m_dfa->Move(c); if(m_currentTokenTypeId == TOKEN_Unrecognized) { c = NextChar(); } else { break; } } Retract(); if(IsIgnoredToken(m_currentTokenTypeId)) { return GetNextToken(); } else { Token* token; string lexeme; TokenValue* tokenValue; vector<PlainCharacter*>& buffer = m_buffer->InnerBuffer(); m_buffer->ExtractString(m_lexemeBegin, m_forward - m_lexemeBegin + 1, lexeme); tokenValue = new TokenValue("", buffer[m_lexemeBegin]->Row, buffer[m_lexemeBegin]->Column); token = new Token(m_currentTokenTypeId, tokenValue); if(IsCompositeToken(m_currentTokenTypeId)) { if(m_reservedWordsToTokenTypeIdMap.find(lexeme) != m_reservedWordsToTokenTypeIdMap.end()) { token->TypeId = g_TokenTypesMap[m_reservedWordsToTokenTypeIdMap[lexeme]]->Id; m_recognizedTokens.push_back(token); return token; } } if(IsSpecialToken(m_currentTokenTypeId)) { m_recognizedTokens.push_back(token); return token; } else if(IsIdentifierToken(m_currentTokenTypeId)) { // save the index of the identifier in the symbol table token->Value->Data = m_symbolTable.size(); m_symbolTable.push_back(token); } token->Value->Lexeme = lexeme; if(IsErrorToken(m_currentTokenTypeId)) { OnFail(token); } m_recognizedTokens.push_back(token); return token; } }