void Vehicles::update(double dt){ if (health <= 0){ isDead = true; } if (!isDead){ speedControl(dt); newVehicle.pathRoute(dt); Pos = newVehicle.getCurrentLocation(); updateHitbox(); SetInteraction(AABB(Vector3(Pos.x - InteractionMin.x, Pos.y - InteractionMin.y, Pos.z - InteractionMin.z), Vector3(Pos.x + InteractionMax.x, Pos.y + InteractionMax.y, Pos.z + InteractionMax.z))); Yaw = getRotationAngle(); if (currAttackTarget != nullptr){ newVehicle.updateWayPoints(currAttackTarget->Pos); } Pos.y = 0; } bulletCurrCooldown += dt; }
void idleDisplay() { speedControl(); if (displayMode == 1) { verticalBar(); } else if (displayMode == 2) { sineGradient(); } else if (displayMode == 3) { horizontalBar(); } else if (displayMode == 4) { solidCircle(); } if (runMode == 1) { glutPostRedisplay(); } }
qglviewer::Vec PosInterpolator::getPositionAt(int frame, bool* valid) { if(frame<start_frame_ or frame>last_frame_){ if(valid!=NULL) *valid = false; return qglviewer::Vec(); } int interval = chooseInterval(frame,PosInterpolator::kFrameBased); if(interval==-1 or interval==0){ if(valid!=NULL) *valid = false; return qglviewer::Vec(); } int interval_start_frame = steps_.at(interval -1).frame_; int interval_end_frame = steps_.at(interval).frame_; double current_step = (((double)(frame)) - ((double)(interval_start_frame)))/((double)(interval_end_frame - interval_start_frame)); if(current_step>1.0) current_step = 1.0; current_step = speedControl(current_step); std::pair<Curve*,ArcLength*> curve_and_length = curves_.at(interval-1); if(valid!=NULL) *valid = true; return curve_and_length.second->getByNormalizedS(current_step); }
void doSpeed() { speedControl(fanSpeed, fanDirection); }
void setupSpeed() { speedAddr = sw1type; sprintf(str,"Fan speed control enabled, using device %u.", speedAddr); mqtt.publish(mqttpub, str); speedControl(0,0); // direction 0, speed 0 }
void STORCommand::Execute() { namespace pt = boost::posix_time; namespace gd = boost::gregorian; fs::VirtualPath path(fs::PathFromUser(argStr)); util::Error e(acl::path::Filter(client.User(), path.Basename())); if (!e) { control.Reply(ftp::ActionNotOkay, "File name contains one or more invalid characters."); throw cmd::NoPostScriptError(); } off_t offset = data.RestartOffset(); if (offset > 0 && data.DataType() == ftp::DataType::ASCII) { control.Reply(ftp::BadCommandSequence, "Resume not supported on ASCII data type."); throw cmd::NoPostScriptError(); } if (!exec::PreCheck(client, path)) throw cmd::NoPostScriptError(); switch(ftp::Counter::Upload().Start(client.User().ID(), client.User().MaxSimUp(), client.User().HasFlag(acl::Flag::Exempt))) { case ftp::CounterResult::PersonalFail : { std::ostringstream os; os << "You have reached your maximum of " << client.User().MaxSimUp() << " simultaneous uploads(s)."; control.Reply(ftp::ActionNotOkay, os.str()); throw cmd::NoPostScriptError(); } case ftp::CounterResult::GlobalFail : { control.Reply(ftp::ActionNotOkay, "The server has reached it's maximum number of simultaneous uploads."); throw cmd::NoPostScriptError(); } case ftp::CounterResult::Okay : break; } auto countGuard = util::MakeScopeExit([&]{ ftp::Counter::Upload().Stop(client.User().ID()); }); if (data.DataType() == ftp::DataType::ASCII && !cfg::Get().AsciiUploads().Allowed(path.ToString())) { control.Reply(ftp::ActionNotOkay, "File can't be uploaded in ASCII, change to BINARY."); throw cmd::NoPostScriptError(); } fs::FileSinkPtr fout; try { if (data.RestartOffset() > 0) fout = fs::AppendFile(client.User(), path, data.RestartOffset()); else fout = fs::CreateFile(client.User(), path); } catch (const util::SystemError& e) { if (data.RestartOffset() == 0 && e.Errno() == EEXIST) { DupeMessage(path); } else { std::ostringstream os; os << "Unable to " << (data.RestartOffset() > 0 ? "append" : "create") << " file: " << e.Message(); control.Reply(ftp::ActionNotOkay, os.str()); } throw cmd::NoPostScriptError(); } catch (const util::RuntimeError& e) { std::ostringstream os; os << "Unable to " << (data.RestartOffset() > 0 ? "append" : "create") << " file: " << e.Message(); control.Reply(ftp::ActionNotOkay, os.str()); throw cmd::NoPostScriptError(); } bool fileOkay = data.RestartOffset() > 0; auto fileGuard = util::MakeScopeExit([&] { if (!fileOkay) { try { fs::DeleteFile(fs::MakeReal(path)); } catch (std::exception& e) { logs::Error("Failed to delete failed upload: %1%", e.what()); } } }); std::stringstream os; os << "Opening " << (data.DataType() == ftp::DataType::ASCII ? "ASCII" : "BINARY") << " connection for upload of " << fs::MakePretty(path).ToString(); if (data.Protection()) os << " using TLS/SSL"; os << "."; control.Reply(ftp::TransferStatusOkay, os.str()); try { data.Open(ftp::TransferType::Upload); } catch (const util::net::NetworkError&e ) { if (!data.RestartOffset()) fs::DeleteFile(fs::MakeReal(path)); control.Reply(ftp::CantOpenDataConnection, "Unable to open data connection: " + e.Message()); throw cmd::NoPostScriptError(); } auto dataGuard = util::MakeScopeExit([&] { if (data.State().Type() != ftp::TransferType::None) { data.Close(); if (data.State().Bytes() > 0) { db::stats::Upload(client.User(), data.State().Bytes() / 1024, data.State().Duration().total_milliseconds()); } } }); if (!data.ProtectionOkay()) { std::ostringstream os; os << "TLS is enforced on " << (data.IsFXP() ? "FXP" : "data") << " transfers."; control.Reply(ftp::ProtocolNotSupported, os.str()); return; } auto section = cfg::Get().SectionMatch(path.ToString()); auto transferLogGuard = util::MakeScopeExit([&] { if (cfg::Get().TransferLog().Uploads()) { bool okay = !std::uncaught_exception(); logs::Transfer(fs::MakeReal(path).ToString(), "up", client.User().Name(), client.User().PrimaryGroup(), (data.State().StartTime() - pt::ptime(gd::date(1970, 1, 1))).total_microseconds() / 1000000.0, data.State().Bytes() / 1024, data.State().Duration().total_microseconds() / 1000000.0, okay, section ? section->Name() : std::string()); } }); const size_t bufferSize = cfg::Get().DataBufferSize(); bool calcCrc = CalcCRC(path); std::unique_ptr<util::CRC32> crc32(cfg::Get().AsyncCRC() ? new util::AsyncCRC32(bufferSize, 10) : new util::CRC32()); bool aborted = false; fileOkay = false; try { ftp::UploadSpeedControl speedControl(client, path); ftp::OnlineTransferUpdater onlineUpdater(boost::this_thread::get_id(), stats::Direction::Upload, data.State().StartTime()); std::vector<char> asciiBuffer; std::vector<char> buffer; buffer.resize(bufferSize); while (true) { size_t len = data.Read(&buffer[0], buffer.size()); const char *bufp = buffer.data(); if (data.DataType() == ftp::DataType::ASCII) { ftp::ASCIITranscodeSTOR(bufp, len, asciiBuffer); len = asciiBuffer.size(); bufp = asciiBuffer.data(); } data.State().Update(len); fout->write(bufp, len); if (calcCrc) crc32->Update(reinterpret_cast<const uint8_t*>(bufp), len); onlineUpdater.Update(data.State().Bytes()); speedControl.Apply(); } } catch (const util::net::EndOfStream&) { } catch (const ftp::TransferAborted&) { aborted = true; } catch (const util::net::NetworkError& e) { control.Reply(ftp::DataCloseAborted, "Error while reading from data connection: " + e.Message()); throw cmd::NoPostScriptError(); } catch (const std::ios_base::failure& e) { control.Reply(ftp::DataCloseAborted, "Error while writing to disk: " + std::string(e.what())); throw cmd::NoPostScriptError(); } catch (const ftp::ControlError& e) { e.Rethrow(); } catch (const ftp::MinimumSpeedError& e) { logs::Debug("Aborted slow upload by %1%. %2% lower than %3%", client.User().Name(), stats::AutoUnitSpeedString(e.Speed()), stats::AutoUnitSpeedString(e.Limit())); aborted = true; } fout->close(); data.Close(); e = fs::Chmod(fs::MakeReal(path), completeMode); if (!e) control.PartReply(ftp::DataClosedOkay, "Failed to chmod upload: " + e.Message()); auto duration = data.State().Duration(); double speed = stats::CalculateSpeed(data.State().Bytes(), duration); if (aborted) { control.Reply(ftp::DataClosedOkay, "Transfer aborted @ " + stats::AutoUnitSpeedString(speed / 1024)); throw cmd::NoPostScriptError(); } if (exec::PostCheck(client, path, calcCrc ? crc32->HexString() : "000000", speed, section ? section->Name() : "")) { fileOkay = true; bool nostats = !section || acl::path::FileAllowed<acl::path::Nostats>(client.User(), path); db::stats::Upload(client.User(), data.State().Bytes() / 1024, duration.total_milliseconds(), nostats ? "" : section->Name()); client.User().IncrSectionCredits(section && section->SeparateCredits() ? section->Name() : "", data.State().Bytes() / 1024 * stats::UploadRatio(client.User(), path, section)); } control.Reply(ftp::DataClosedOkay, "Transfer finished @ " + stats::AutoUnitSpeedString(speed / 1024)); (void) countGuard; (void) fileGuard; (void) dataGuard; }
/* is set to 'yes' (#pragma interrupt saveall is generated before the ISR) */ void TI1_OnInterrupt(void) { oneMsCounter++; //------------------------------------------- g_nspeedControPeriod ++; speedControlOutput(); //___________________________________________ //------------------------------------------- g_nDirectionControlPeriod ++; DirectionControlOutput(); //___________________________________________ if(oneMsCounter == 1) { if(AD_Flag) updataSensor(); //读取ADC的值 } //-------------------------------------------------- else if(oneMsCounter == 2) { AngleCalculate(); //计算角度 AngleControl(); //角度的PD值控制 motorControl(); //电机输出控制 } //----------------------------------------------- else if(oneMsCounter == 3) { g_nSpeedControlCount++; oneHundredMsCounter++; if(g_nSpeedControlCount >= SPEED_CONTROL_COUNT) { speedControl(); //速度控制 g_nSpeedControlCount=0; g_nspeedControPeriod=0; } if(standFlag){ if(oneHundredMsCounter == 100) { if(CAR_SPEED_SET < speedNeed3) CAR_SPEED_SET += 10; else { CAR_SPEED_SET = speedNeed3; speedStarEndFlag = 1; } oneHundredMsCounter = 0; } } else { CAR_SPEED_SET = 0; oneHundredMsCounter = 0; speedStarEndFlag = 0; } } //-------------------------------------------------- else if(oneMsCounter == 4) { g_nDirectionControlCount ++; DianciCalculate(); DirectionVoltageSigma(); if(g_nDirectionControlCount >= DIRECTION_CONTROL_COUNT) { DirectionControl(); g_nDirectionControlCount = 0; g_nDirectionControlPeriod = 0; } } //------------------------------------------------- else if(oneMsCounter >= 5) { oneMsCounter = 0; GetMotorPulse(); UartFlag = 1; } }