void FindToolBar::openFind(bool focus) { setBackward(false); OpenFlags flags = UpdateAll; if (!focus) // remove focus flag flags = flags & ~UpdateFocusAndSelect; openFindToolBar(flags); }
//set dc position - moves back or forward according to PID and current position, //must be called on new input void DcMotor::setPosition(int newPosition, bool verbose) { if (newPosition >= 0 && newPosition <= BUFFER) newPosition = BUFFER; if (newPosition >= ROD_LENGTH - BUFFER && newPosition <= ROD_LENGTH) newPosition = ROD_LENGTH - BUFFER; if (newPosition <= ROD_LENGTH - BUFFER && newPosition >= BUFFER) { if (verbose) { Serial.write((char)ArduinoCodes::DC_RECEIVED_OK); } if (digitalRead(END_BUTTON) == LOW) (*_curPosPtr) = ROD_LENGTH; if (digitalRead(START_BUTTON) == LOW) (*_curPosPtr) = 0; _lastReceivedPosition = newPosition; _setpoint = newPosition; _input = *_curPosPtr; _pid->Compute(); if (_setpoint > (*_curPosPtr) + PID_ERROR) { if (digitalRead(END_BUTTON) != LOW) { setForward(); setSpeed(_output); } else { setSpeed(0); } } else if (_setpoint < (*_curPosPtr) - PID_ERROR) { if (digitalRead(START_BUTTON) != LOW) { setBackward(); setSpeed(_output*(-1)); } else { setSpeed(0); } } //Position reached else { setSpeed(0); } } else { if (verbose) Serial.write((char)ArduinoCodes::DC_RANGE_INVALID); } }
//set dc position - moves back or forward according to PID and current position, //must be called on new input TxCode DcMotor::setPosition(int newPosition) { TxCode result = TxCode::TX_NA; if (newPosition >= 0 && newPosition <= BUFFER) newPosition = BUFFER; if (newPosition >= ROD_LENGTH - BUFFER && newPosition <= ROD_LENGTH) newPosition = ROD_LENGTH - BUFFER; if (newPosition <= ROD_LENGTH - BUFFER && newPosition >= BUFFER) { if (digitalRead(END_BUTTON) == LOW) (*_curPosPtr) = ROD_LENGTH; if (digitalRead(START_BUTTON) == LOW) (*_curPosPtr) = 0; result = TxCode::TX_DC_RECEIVED_OK; _lastReceivedPosition = newPosition; _setpoint = newPosition; _input = *_curPosPtr; _pid->Compute(); if (_setpoint > (*_curPosPtr) + PID_ERROR) { if (digitalRead(END_BUTTON) != LOW) { setForward(); setSpeed(_output); } else { setSpeed(0); } } else if (_setpoint < (*_curPosPtr) - PID_ERROR) { if (digitalRead(START_BUTTON) != LOW) { setBackward(); setSpeed(_output*(-1)); } else { setSpeed(0); } } //Position reached else { setSpeed(0); } } else { result = TxCode::TX_DC_RANGE_INVALID; } return result; }
//calibrattion detects 0 position of a rod, must be called once at the begging of a programm //sets calibration flag as true, second call will be ignored void DcMotor::calibrate() { if (!_isCalibrated) { //move to start pin (0) while (digitalRead(START_BUTTON) != LOW) { setBackward(); setSpeed(INIT_SPEED); } setSpeed(0); *_curPosPtr = 0; _setpoint = *_curPosPtr; _isCalibrated = true; } }
//calibrattion detects 0 position of a rod, must be called once at the begging of a programm //sets calibration flag as true, second call will be ignored void DcMotor::calibrate() { if (!_isCalibrated) { //move to start pin (0) while (digitalRead(START_BUTTON) != LOW) { setBackward(); setSpeed(INIT_SPEED); } setSpeed(0); *_curPosPtr = 0; _setpoint = *_curPosPtr; _isCalibrated = true; Serial.write((char)ArduinoCodes::DC_CALIBRATED); } }
//!Perform initial calculation for Backward algorithm from ending state void basicTrellis::initBackward(){ sequencePosition=seq->getLength(); std::vector<state*>* ending=hmm->getEndingFrom(); for(unsigned int x=0;x<ending->size();x++){ currentStatePtr=(*ending)[x]; currentState = currentStatePtr->getIterator(); double backScore = getEndingTransition(currentState); setBackward(sequencePosition-1,currentState,backScore); DefinedStates->insert(currentStatePtr); _nextStates->insert(currentStatePtr->getFromBegin(),currentStatePtr->getFromEnd()); } return; }
//!Calculate backward score for the given cell void simpleTrellis::calcBackward() { //For all the possible states at this position for(currentStatesIterator = currentStates->begin(); currentStatesIterator!=currentStates->end(); currentStatesIterator++) { //Get pointer to current state currentStatePtr = (*currentStatesIterator); currentState = currentStatePtr->getIterator(); //Calculate emission for the current cell double emm; //If emission is not yet calculated for the cell if (!trell[sequencePosition][currentState].emmCalculated) { //Calculate emission emm=currentStatePtr->get_emission(*seq, sequencePosition); //Check for external definition if (externalDefinitionSet) { emm+=seq->getWeight(sequencePosition, currentState); } //Store emission value in cell trell[sequencePosition][currentState].emmCalculated=true; trell[sequencePosition][currentState].emm=emm; } else { //emm was previously calculated //Get previously calculated emm value; emm = trell[sequencePosition][currentState].emm; } std::vector<state*>::iterator it; //Get the possible transition to this state for(it=currentStatePtr->getFromBegin(); it!=currentStatePtr->getFromEnd(); it++) { //Get pointer to previous state previousStatePtr=(*it); previousState=previousStatePtr->getIterator(); // std::cout <<"Current " << currentStatePtr->getName() << " FROM "; // std::cout << previousStatePtr->getName() << std::endl; //std::cout << previousStatePtr->getIterator() << std::endl; //Only need to calculate transition if the viterbi > -INFINITY if (trell[sequencePosition][currentState].back!=-INFINITY) { //Calculate transition double trans; //If transition is already calculated if (trell[sequencePosition-1][currentState].trans.count(previousStatePtr)) { trans = trell[sequencePosition-1][currentState].trans[previousStatePtr]; } else { trans = getTransition(); trell[sequencePosition-1][currentState].trans[previousStatePtr]=trans; } // std::cout << "Position:\t" << sequencePosition <<std::endl; // std::cout << "State:\t" << currentState <<std::endl; // std::cout << "Previous State:\t"<<previousState << std::endl; // std::cout << "Transition:\t" << exp(trans) <<std::endl; // std::cout << "Emission:\t" << exp(emm) << std::endl; // std::cout <<std::endl; //Calculate viterbi value for cell double backward_value = emm + trans + trell[sequencePosition][currentState].back; //If current viterbi value > -Infinity then it's possible to transition from this state to next //Set the next possible states if(backward_value>-INFINITY) { _nextStates->insert(previousStatePtr->getToBegin(),previousStatePtr->getToEnd()); setBackward(sequencePosition-1,previousState,backward_value); //std::cout << exp(backward_value) << std::endl; } } } } ///Old backward functions // double prelim = getTransition() + previousStatePtr->get_emission(*seq,sequencePosition); // // if (externalDefinitionSet){ // prelim+=seq->getWeight(sequencePosition, previousStatePtr->getIterator()); // } // // //setBackward( prelim + getBackward( sequencePosition , previousStatePtr->getIterator() ) ); return; }