void snr (void) { uprintf("Command Excepted\r"); switch (ExtractNum(3)) { case 0:itoa(getCM(0xE2),dumb,10);break; case 1:itoa(getCM(0xE4),dumb,10);break; case 2:itoa(getCM(0xE6),dumb,10);break; } uprintf(dumb); uprintf("\r"); }
void Converter::convertText(tExcelRangeSp& r, wstring_t& text, wstring_t& textUnicode) { tFontSp font; string_t fontName, newFontName; font = r->getFont(); fontName = font->getName(); if (fontName.empty()) { logError(logger(), "empty font name"); return; } usedFonts_.insert(fontName); if (!canSkipFont(fontName)) { tCharMappingSp cm = getCM(fontName); if (cm) { textUnicode.clear(); text = r->getValue2(); cm->doConversion(text, textUnicode, fontName); newFontName = getFontSubstitution(cm, fontName); font->setName(newFontName); if (textUnicode.empty()) return; r->setValue2(textUnicode); } } }
int main(void) { setup(); printf("Distance: %dcm\n", getCM()); return 0; }
/** * The main functionality of the program. * */ int main(int argc, char *argv[]) { // Gets the number of measurements to display from the first parameter int numDisplayed = atoi(argv[1]); // Sets up the GPIO pins setup(); // Set the system start time sysStart = micros(); // Print the headers for each row printf("Time\t\t"); for (int m = 1; m < SENSORS + 1; m++) { printf("%d\t", m); } printf("\n"); // Start printing readings for (int i = 0; i < numDisplayed; i++) { for (int j = 0; j < READINGS; j++) { // Minimum 60us delay between readings delayMicroseconds(60); sendPulse(); // Print current time printf("%lu\t\t", (micros() - sysStart) / 1000); // Print CMs int cms[SENSORS]; for (int k = 0; k < SENSORS; k++) { cms[k] = getCM(k); if (cms[k] < 0) { cms[k] = 400; } A[k][j] = cms[k]; // print raw data printf("%d\t", cms[k]); } printf("\n"); // Wait for echos to die out delayMicroseconds(23000); } //int displayCm[SENSORS]; // Display the results //for (int l = 0; l < SENSORS; l++) { //displayCm[l] = selection_algorithm(0, READINGS - 1, SENSITVTY, l); //printf("%d\t", displayCm[l]); //} //printf("\n"); } return 0; }
int main(void) { setup(); while (1) { printf("Distance: %dcm\n", getCM()); delay(1000); } return 0; }
/** * Substracts the center of mass of the system from the coordinates so that * the system is centred at the origin * * @param at Atom list * @param dat Common data */ void recentre(ATOM at[],DATA *dat) { CM cm = getCM(at,dat); for(uint32_t i=0; i<dat->natom; i++) { at[i].x -= cm.cx; at[i].y -= cm.cy; at[i].z -= cm.cz; } }
tCharMappingSp& Converter::getCM( const string_t& font ) { /// select mapping auto it = fontCharMaps_.find(font); if (it == fontCharMaps_.end()) { string_t::size_type p = font.find(','); if (p != string_t::npos) { logInfo(logger(), "Reused \'" + font.substr(0, p) + "\' for \'" + font + "\'"); tCharMappingSp& reuseMapping = getCM(font.substr(0, p)); fontCharMaps_.insert(std::make_pair(font, reuseMapping)); return reuseMapping; } p = font.find("Bold"); if (p != string_t::npos) { logInfo(logger(), "Reused \'" + font.substr(0, p) + "\' for \'" + font + "\'"); tCharMappingSp& reuseMapping = getCM(font.substr(0, p)); fontCharMaps_.insert(std::make_pair(font, reuseMapping)); return reuseMapping; } p = font.find("Italic"); if (p != string_t::npos) { logInfo(logger(), "Reused \'" + font.substr(0, p) + "\' for \'" + font + "\'"); tCharMappingSp& reuseMapping = getCM(font.substr(0, p)); fontCharMaps_.insert(std::make_pair(font, reuseMapping)); return reuseMapping; } if ( !canSkipFont(font) ) { logError(logger(), "Font '" + font + "' is not found in mapping folder"); /// create empty mapping to avoid repeated errors fontCharMaps_.insert(std::make_pair(font, noMapping)); } return noMapping; } return it->second; }
void doPID(FILE *fp) { static int leftSpeed = ZERO; static int rightSpeed = ZERO; static float last_error = 0; static float integral = 0; int distance = getCM(); while(distance > 80) { setSpeed(fp, 0, 0); printf("too far %d\n", distance); distance = getCM(); } static int goodDistance = distance; float error = distance - goodDistance; float deriv = (error - last_error)/dt; if(abs(error) > MIN_ERROR) { integral = integral + error * dt; } float output = Kp * error + Ki * integral + Kd * deriv; if(output < MIN) { output = MIN; } else if (output > MAX) { output = MAX; } printf("Current output %f\n", output); //negative means go faster right //positive means go faster left leftSpeed = 190 + (55 * output/3); rightSpeed = ZERO - (190 - ZERO) + (55 * output/3); printf("left=%i right=%i", leftSpeed, rightSpeed); setSpeed(fp, leftSpeed, rightSpeed); last_error = error; }
void Converter::processRangeClassic( tRangeSp& r, wstring_t& text, wstring_t& textUnicode ) { tCharMappingSp cm; tFontSp font; string_t fontName, newFontName; font = r->getFont(); fontName = font->getName(); if (fontName.empty()) { logError(logger(), "empty font name"); return; } if ( !canSkipFont(fontName) ) { cm = getCM(fontName); if (cm) { textUnicode.clear(); text = r->getText(); cm->doConversion(text, textUnicode, fontName); newFontName = getFontSubstitution(cm, fontName); font->setName(newFontName); if (text.empty()) return; else if ( text.size() == 1 ) { if (specialChars_.find(text[0]) != string_t::npos) { return; } else if (text[0] <= 20 ) { logWarning(logger(), boost::lexical_cast<string_t>((int) text[0])); return; } } tParagraphFormatSp pf = r->getParagraphFormat(); int alignment = pf->getAlignment(); float lineSpacing = pf->getLineSpacing(); r->setText(textUnicode); if ( textUnicode.size() > 1 ) { pf->setAlignment(alignment); pf->setLineSpacing(lineSpacing); } } } }
int main(void) { setup(); pwmWrite(MOTOR0,965); pwmWrite(MOTOR1,964); char str[20]; printf("Nome do arquivo: "); fgets(str,20,stdin); if(str[strlen(str)-1]=='\n'){str[strlen(str)-1]='\0';} strcat(str,".txt"); puts(str); //fp = fopen(str,"w"); while(1){ delay(100); getCM(); } return 0; }
void Converter::processRangeClassic2( tRangeSp& r, wstring_t& text, wstring_t& textUnicode ) { static std::vector<int> offsets; tCharMappingSp cm; tFontSp font; string_t fontName, newFontName; font = r->getFont(); fontName = font->getName(); if (fontName.empty()) { logError(logger(), "empty font name"); return; } const wstring_t* specialChars = &specialChars_; usedFonts_.insert(fontName); if ( !canSkipFont(fontName) ) { cm = getCM(fontName); if (cm) { textUnicode.clear(); text = r->getText(); cm->doConversion(text, textUnicode, fontName); newFontName = getFontSubstitution(cm, fontName); font->setName(newFontName); if (fontName.find("Arafi") != string_t::npos) specialChars = &specialCharsArafi_; /// -------------------------------------------- int enPos = r->getEnd(); int stPos = r->getStart(); string_t::size_type off = 0; string_t::size_type pos = 0; offsets.clear(); bool somethingChanged = false; while ( true ) { pos = text.find_first_not_of(*specialChars, off); if (pos != string_t::npos) { offsets.push_back(pos); off = pos; somethingChanged = true; } else { break; } pos = text.find_first_of(*specialChars, off); if (pos != string_t::npos) { offsets.push_back(pos); off = pos + 1; somethingChanged = true; } else { offsets.push_back(text.size()); break; } } for (int i = 0; i < offsets.size(); i += 2) { int off1 = offsets[i]; int off2 = offsets[i+1]; r->setRange(stPos + off1, stPos + off2); if (wordVisible_) r->select(); r->setText(textUnicode.substr(off1, off2 - off1)); } if (somethingChanged) r->setRange(stPos, enPos); } } }
void Converter::convertSingleDocQuick( const string_t& fileName ) { tDocumentsSp docs = word()->getDocuments(); tDocumentSp doc = docs->open(toUtf16(getInputAbsPath(fileName))); if (!doc) { logError(logger(), "Error while opening document: " + fileName); return; } tCharMappingSp cm; string_t fontName, newFontName; wstring_t text, textUnicode, docAsText; int c = 0; tSelectionSp s = word()->getSelection(); int pos = 0; int totalCharsQty = s->getStoryLength(); do { s->setStart(pos); s->setEnd(pos + 1); s->selectCurrentFont(); fontName = s->getFont()->getName(); if ( canSkipFont(fontName) ) { //s->getFont()->haveCommonAttributes(); pos = s->getEnd(); docAsText += s->getText(); std::cout << "\r" << percentageStr(pos, totalCharsQty - 1); continue; } text = s->getText(); if ( fontName.empty() ) { saveSelection(s); fontName = makeGuess(s); restoreSelection(s); /// if after all we have empty font name, log about that event /// and go forward if (fontName.empty()) { logError(logger(), "EMPTY FONT NAME: Investigate"); pos = s->getEnd(); docAsText += text; std::cout << "\r" << percentageStr(pos, totalCharsQty - 1); continue; } } /// use mapping textUnicode.clear(); cm = getCM(fontName); if (cm) { bool spacingOnly = cm->doConversion(text, textUnicode, fontName); newFontName = getFontSubstitution(cm, fontName); //tFontSp fontDup = s->getFont()->duplicate(); s->setText(textUnicode); //s->getFont()->haveCommonAttributes(); s->getFont()->setName(newFontName); //s->setFont(fontDup); } /// extract text from the document as well docAsText += textUnicode; pos = s->getEnd(); std::cout << "\r" << percentageStr(pos, totalCharsQty - 1); } while ( pos < totalCharsQty - 1 ); /// -------------------------------------------/// /// now save result in the appropriate folder /// string_t outputDir = getOutputAbsPath(fileName); Poco::File(outputDir).createDirectories(); Poco::Path p(fileName); doc->saveAs( outputDir + p.getBaseName() + " QUICK." + p.getExtension() ); doc->close(); if ( config_->getBool("app.saveAlsoAsUTF8", false) ) writeFileAsBinary( outputDir + p.getBaseName() + " UTF8 QUICK.txt", toUtf8(docAsText)); }
void AnalysisVisitor::visit(ast::IfExp & e) { logger.log(L"IfExp", e.getLocation()); ast::Exp * shortcutExp = nullptr; // we apply the ConstantVisitor e.getTest().accept(cv); ast::Exp & test = e.getTest(); if (cv.getResult() && test.isConstExp()) { e.accept(cv); // we have a constant ! ast::ConstExp & ce = static_cast<ast::ConstExp &>(test); types::InternalType * pIT = ce.getConstant(); if (!pIT) { test.accept(cv.getExec()); pIT = ce.getConstant(); } if (pIT) { const bool result = pIT->isTrue(); if (result) { shortcutExp = &e.getThen(); e.getExps()[1] = nullptr; } else { shortcutExp = &e.getElse(); e.getExps()[2] = nullptr; } } } else { ast::Exp * val = nullptr; bool isEq; if (test.isOpExp()) { ast::OpExp & oe = static_cast<ast::OpExp &>(test); isEq = oe.getOper() == ast::OpExp::eq; if (isEq || oe.getOper() == ast::OpExp::ne) { if (oe.getLeft().isDoubleExp()) { ast::DoubleExp & de = static_cast<ast::DoubleExp &>(oe.getLeft()); if (types::InternalType * pIT = de.getConstant()) { if (pIT->isDouble()) { types::Double * pDbl = static_cast<types::Double *>(pIT); if (pDbl->isEmpty()) { val = &oe.getRight(); } } } } else if (oe.getRight().isDoubleExp()) { ast::DoubleExp & de = static_cast<ast::DoubleExp &>(oe.getRight()); if (types::InternalType * pIT = de.getConstant()) { if (pIT->isDouble()) { types::Double * pDbl = static_cast<types::Double *>(pIT); if (pDbl->isEmpty()) { val = &oe.getLeft(); } } } } } } else { ast::CallExp * ce = nullptr; if (test.isNotExp()) { ast::NotExp & ne = static_cast<ast::NotExp &>(test); if (ne.getExp().isCallExp()) { ce = &static_cast<ast::CallExp &>(ne.getExp()); isEq = false; } } else if (test.isCallExp()) { ce = &static_cast<ast::CallExp &>(test); isEq = true; } if (ce && ce->getName().isSimpleVar()) { ast::SimpleVar & var = static_cast<ast::SimpleVar &>(ce->getName()); const symbol::Symbol & sym = var.getSymbol(); const std::wstring & name = sym.getName(); if (name == L"isempty" && getCM().checkGlobalConstant(sym)) { const ast::exps_t args = ce->getArgs(); if (args.size() == 1) { val = args.front(); } } } } if (val) { // test is something like val == [], isempty(val), val ~= [], ~isempty(val) val->accept(*this); Result & res = getResult(); TIType & ty = res.getType(); if ((ty.ismatrix() && ty.isscalar()) || (getCM().check(ConstraintManager::STRICT_POSITIVE, ty.rows.getValue()) || getCM().check(ConstraintManager::STRICT_POSITIVE, ty.cols.getValue()))) { if (isEq) { shortcutExp = &e.getElse(); e.getExps()[2] = nullptr; } else { shortcutExp = &e.getThen(); e.getExps()[1] = nullptr; } } } } if (shortcutExp) { e.replace(shortcutExp); shortcutExp->accept(*this); } else { dm.addBlock(Block::EXCLUSIVE, &e); e.getTest().accept(*this); dm.releaseTmp(getResult().getTempId()); dm.addBlock(Block::NORMAL, &e.getThen()); e.getThen().accept(*this); dm.finalizeBlock(); dm.addBlock(Block::NORMAL, e.hasElse() ? &e.getElse() : nullptr); if (e.hasElse()) { e.getElse().accept(*this); } dm.finalizeBlock(); dm.finalizeBlock(); } }
bool AnalysisVisitor::getDimension(SymbolicDimension & dim, ast::Exp & arg, bool & safe, SymbolicDimension & out) { switch (arg.getType()) { case ast::Exp::COLONVAR : { out = dim; safe = true; arg.getDecorator().setDollarInfo(argIndices.top()); return true; } case ast::Exp::DOLLARVAR : // a($) { out = SymbolicDimension(getGVN(), 1.); safe = true; arg.getDecorator().setDollarInfo(argIndices.top()); return true; } case ast::Exp::DOUBLEEXP : // a(12) or a([1 2]) { ast::DoubleExp & de = static_cast<ast::DoubleExp &>(arg); if (types::InternalType * const pIT = de.getConstant()) { if (pIT->isDouble()) { types::Double * const pDbl = static_cast<types::Double *>(pIT); if (pDbl->isEmpty()) { out = SymbolicDimension(getGVN(), 0.); safe = true; return true; } const double * real = pDbl->getReal(); const int size = pDbl->getSize(); int64_t max; if (tools::asInteger(real[0], max)) { int64_t min = max; if (!pDbl->isComplex()) { for (int i = 0; i < size; ++i) { int64_t _real; if (tools::asInteger(real[i], _real)) { if (_real < min) { min = _real; } else if (_real > max) { max = _real; } } else { return false; } } out = SymbolicDimension(getGVN(), size); safe = (min >= 1) && getCM().check(ConstraintManager::GREATER, dim.getValue(), getGVN().getValue(max)); return true; } else { const double * imag = pDbl->getImg(); int i; for (i = 0; i < size; ++i) { if (imag[i]) { break; } int64_t _real; if (tools::asInteger(real[i], _real)) { if (_real < min) { min = _real; } else if (_real > max) { max = _real; } } } if (i == size) { out = SymbolicDimension(getGVN(), size); safe = (min >= 1) && getCM().check(ConstraintManager::GREATER, dim.getValue(), getGVN().getValue(max)); return true; } else { return false; } } } else { return false; } } else if (pIT->isImplicitList()) { types::ImplicitList * const pIL = static_cast<types::ImplicitList *>(pIT); double start, step, end; if (AnalysisVisitor::asDouble(pIL->getStart(), start) && AnalysisVisitor::asDouble(pIL->getStep(), step) && AnalysisVisitor::asDouble(pIL->getEnd(), end)) { double single; const int type = ForList64::checkList(start, end, step, single); switch (type) { case 0 : { out = SymbolicDimension(getGVN(), 0.); safe = true; return true; } case 1 : { out = SymbolicDimension(getGVN(), 1.); safe = false; return true; } case 2 : { const uint64_t N = ForList64::size(start, end, step); uint64_t max, min; if (step > 0) { min = start; max = (uint64_t)(start + (N - 1) * step); } else { max = start; min = (uint64_t)(start + (N - 1) * step); } out = SymbolicDimension(getGVN(), N); safe = (min >= 1) && getCM().check(ConstraintManager::GREATER, dim.getValue(), getGVN().getValue((int64_t)max)); return true; } } } } } else { out = SymbolicDimension(getGVN(), 1.); safe = (de.getValue() >= 1) && getCM().check(ConstraintManager::GREATER, dim.getValue(), getGVN().getValue(de.getValue())); return true; } return false; } case ast::Exp::BOOLEXP : // a(a > 1) => a([%f %t %t]) => a([2 3]) { ast::BoolExp & be = static_cast<ast::BoolExp &>(arg); if (types::InternalType * const pIT = be.getConstant()) { if (pIT->isBool()) { types::Bool * const pBool = static_cast<types::Bool *>(pIT); const int size = pBool->getSize(); const int * data = pBool->get(); int64_t max = -1; int64_t count = 0; for (int i = 0; i < size; ++i) { if (data[i]) { ++count; max = i; } } out = SymbolicDimension(getGVN(), count); safe = getCM().check(ConstraintManager::GREATER, dim.getValue(), getGVN().getValue(max)); return true; } } else { if (be.getValue()) { out = SymbolicDimension(getGVN(), int64_t(1)); } else { out = SymbolicDimension(getGVN(), int64_t(0)); } safe = true; return true; } return false; } case ast::Exp::LISTEXP : { ast::ListExp & le = static_cast<ast::ListExp &>(arg); SymbolicList sl; if (SymbolicList::get(*this, le, sl)) { if (sl.isSymbolic()) { sl.evalDollar(getGVN(), dim.getValue()); } TIType typ; if (sl.getType(getGVN(), typ)) { out = SymbolicDimension(getGVN(), typ.cols.getValue()); safe = false;//getCM().check(ConstraintManager::GREATER, dim.getValue(), getGVN().getValue(max)); return true; } } return false; } default : { arg.accept(*this); Result & _res = getResult(); SymbolicRange & range = _res.getRange(); if (range.isValid()) { //std::wcerr << *range.getStart()->poly << ":" << *range.getEnd()->poly << ",," << *dim.getValue()->poly << std::endl; safe = getCM().check(ConstraintManager::VALID_RANGE, range.getStart(), range.getEnd(), getGVN().getValue(int64_t(1)), dim.getValue()); out = _res.getType().rows * _res.getType().cols; return true; } if (GVN::Value * const v = _res.getConstant().getGVNValue()) { GVN::Value * w = v; if (GVN::Value * const dollar = getGVN().getExistingValue(symbol::Symbol(L"$"))) { if (GVN::Value * const x = SymbolicList::evalDollar(getGVN(), v, dollar, dim.getValue())) { w = x; } } bool b = getCM().check(ConstraintManager::GREATER, dim.getValue(), w); if (b) { safe = getCM().check(ConstraintManager::STRICT_POSITIVE, w); } else { safe = false; } out = SymbolicDimension(getGVN(), 1); return true; } // To use with find // e.g. a(find(a > 0)): find(a > 0) return a matrix where the max index is rc(a) so the extraction is safe if (_res.getType().ismatrix() && _res.getType().type != TIType::BOOLEAN) { out = _res.getType().rows * _res.getType().cols; SymbolicDimension & maxIndex = _res.getMaxIndex(); if (maxIndex.isValid()) { safe = getCM().check(ConstraintManager::GREATER, dim.getValue(), maxIndex.getValue()); } else { safe = false; } return true; } return false; } } }
double Sonar::getDistance(){ return getCM(); }
void AnalysisVisitor::visit(ast::ListExp & e) { logger.log(L"ListExp", e.getLocation()); if (e.getParent()->isVarDec()) { visitInVarDecCtxt(e); return; } e.getStart().accept(*this); Result & Rstart = e.getStart().getDecorator().getResult(); e.getEnd().accept(*this); Result & Rend = e.getEnd().getDecorator().getResult(); e.getStep().accept(*this); Result & Rstep = e.getStep().getDecorator().getResult(); double start = 1; double step = 1; double end = 1; if (Rstart.getConstant().getDblValue(start) && Rstep.getConstant().getDblValue(step) && Rend.getConstant().getDblValue(end)) { // Start, Step & End are constant ! double out; int type = ForList64::checkList(start, end, step, out); switch (type) { case 0: e.getDecorator().setResult(Result(TIType(dm.getGVN(), TIType::EMPTY), -1)); break; case 1: e.getDecorator().setResult(Result(TIType(dm.getGVN(), TIType::DOUBLE), -1)); break; case 2: { const uint64_t N = ForList64::size(start, end, step); TIType T(dm.getGVN(), TIType::DOUBLE, 1, N); if (N == 1) { out = start; } e.getDecorator().setResult(Result(T, dm.getTmpId(T, false))); break; } default: break; } e.setValues(start, step, end, out); setResult(e.getDecorator().res); return; } if (step == 0 || tools::isNaN(step) || !tools::isFinite(step) || tools::isNaN(start) || !tools::isFinite(start) || tools::isNaN(end) || !tools::isFinite(end)) { e.getDecorator().setResult(Result(TIType(dm.getGVN(), TIType::EMPTY), -1)); return; } if (!Rstep.getConstant().getDblValue(step) || (step != -1 && step != 1)) { Result & res = e.getDecorator().setResult(Result(TIType(dm.getGVN(), Rstart.getType().type, false), -1)); setResult(res); return; } if (!Rstart.getType().isscalar() || !Rend.getType().isscalar()) { Result & res = e.getDecorator().setResult(Result(TIType(dm.getGVN(), Rstart.getType().type, false), -1)); setResult(res); return; } GVN::Value * gvnStart; if (Rstart.getConstant().getDblValue(start)) { if (tools::getIntType(start) == tools::NOTANINT) { gvnStart = getGVN().getValue((double)tools::cast<int>(start + step)); } else { gvnStart = getGVN().getValue((double)tools::cast<int>(start)); } } else { gvnStart = Rstart.getConstant().getGVNValue(); if (!gvnStart) { Result & res = e.getDecorator().setResult(Result(TIType(dm.getGVN(), Rstart.getType().type, false), -1)); setResult(res); return; } } GVN::Value * gvnEnd; if (Rend.getConstant().getDblValue(end)) { if (tools::getIntType(end) == tools::NOTANINT) { gvnEnd = getGVN().getValue((double)tools::cast<int>(end - step)); } else { gvnEnd = getGVN().getValue((double)tools::cast<int>(end)); } } else { gvnEnd = Rend.getConstant().getGVNValue(); if (!gvnEnd) { Result & res = e.getDecorator().setResult(Result(TIType(dm.getGVN(), Rstart.getType().type, false), -1)); setResult(res); return; } } GVN::Value * ONEValue = getGVN().getValue(int64_t(1)); SymbolicDimension ONE(getGVN(), ONEValue); GVN::Value * v; if (gvnStart->value == gvnEnd->value) { Result & res = e.getDecorator().setResult(Result(TIType(getGVN(), TIType::DOUBLE, ONE, ONE))); setResult(res); return; } if (step == 1) { v = getGVN().getValue(OpValue::Kind::MINUS, *gvnEnd, *gvnStart); } else { v = getGVN().getValue(OpValue::Kind::MINUS, *gvnStart, *gvnEnd); } v = getGVN().getValue(OpValue::Kind::PLUS, *v, *ONEValue); if (v->poly->constant < 0 && v->poly->isCoeffNegative(false)) { TIType type(getGVN(), TIType::EMPTY); e.getDecorator().res = Result(type); } else { bool res = getCM().check(ConstraintManager::POSITIVE, v); if (res) { TIType type(getGVN(), TIType::DOUBLE, ONE, SymbolicDimension(getGVN(), v)); e.getDecorator().setResult(type); } else { Result & res = e.getDecorator().setResult(Result(TIType(dm.getGVN(), Rstart.getType().type, false), -1)); setResult(res); return; } } setResult(e.getDecorator().res); }