This commit is contained in:
Travis Hunter 2024-08-16 18:18:49 -06:00
parent cb1a8c379b
commit 6ddba41dd6
5 changed files with 70 additions and 62 deletions

View File

@ -6,7 +6,7 @@ set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON) set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets LinguistTools) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets LinguistTools)

View File

@ -10,8 +10,6 @@
// qtrocket headers // qtrocket headers
#include "Logger.h" #include "Logger.h"
namespace utils
{
Logger* Logger::instance = nullptr; Logger* Logger::instance = nullptr;
Logger* Logger::getInstance() Logger* Logger::getInstance()
@ -40,29 +38,29 @@ void Logger::log(std::string_view msg, const LogLevel& lvl)
// all levels at or lower than the current level. // all levels at or lower than the current level.
switch(currentLevel) switch(currentLevel)
{ {
case PERF_: case LogLevel::PERF:
if(lvl == PERF_) if(lvl == LogLevel::PERF)
{ {
outFile << "[PERF] " << msg << std::endl; outFile << "[PERF] " << msg << std::endl;
std::cout << "[PERF] " << msg << "\n"; std::cout << "[PERF] " << msg << "\n";
} }
[[fallthrough]]; [[fallthrough]];
case DEBUG_: case LogLevel::DEBUG:
if(lvl == DEBUG_) if(lvl == LogLevel::DEBUG)
{ {
outFile << "[DEBUG] " << msg << std::endl; outFile << "[DEBUG] " << msg << std::endl;
std::cout << "[DEBUG] " << msg << "\n"; std::cout << "[DEBUG] " << msg << "\n";
} }
[[fallthrough]]; [[fallthrough]];
case INFO_: case LogLevel::INFO:
if(lvl == INFO_) if(lvl == LogLevel::INFO)
{ {
outFile << "[INFO] " << msg << std::endl; outFile << "[INFO] " << msg << std::endl;
std::cout << "[INFO] " << msg << "\n"; std::cout << "[INFO] " << msg << "\n";
} }
[[fallthrough]]; [[fallthrough]];
case WARN_: case LogLevel::WARN:
if(lvl == WARN_) if(lvl == LogLevel::WARN)
{ {
outFile << "[WARN] " << msg << std::endl; outFile << "[WARN] " << msg << std::endl;
std::cout << "[WARN] " << msg << "\n"; std::cout << "[WARN] " << msg << "\n";
@ -71,7 +69,7 @@ void Logger::log(std::string_view msg, const LogLevel& lvl)
// Regardless of what level is set, ERROR is always logged, so // Regardless of what level is set, ERROR is always logged, so
// rather than explicitly check for the ERROR case, we just use default case // rather than explicitly check for the ERROR case, we just use default case
default: default:
if(lvl == ERROR_) if(lvl == LogLevel::ERROR)
{ {
outFile << "[ERROR] " << msg << std::endl; outFile << "[ERROR] " << msg << std::endl;
std::cout << "[ERROR] " << msg << "\n"; std::cout << "[ERROR] " << msg << "\n";
@ -90,4 +88,3 @@ void Logger::log(std::ostream& o, const std::string& msg)
o << msg << std::endl; o << msg << std::endl;
} }
} // namespace utils

View File

@ -11,22 +11,19 @@
// 3rd party headers // 3rd party headers
/// \endcond /// \endcond
namespace utils
{
/** /**
* @todo write docs * @todo write docs
*/ */
class Logger class Logger
{ {
public: public:
enum LogLevel enum class LogLevel
{ {
ERROR_, ERROR,
WARN_, WARN,
INFO_, INFO,
DEBUG_, DEBUG,
PERF_ PERF
}; };
static Logger* getInstance(); static Logger* getInstance();
@ -39,11 +36,11 @@ public:
void setLogLevel(const LogLevel& lvl); void setLogLevel(const LogLevel& lvl);
inline void error(std::string_view msg) { log(msg, ERROR_); } inline void error(std::string_view msg) { log(msg, LogLevel::ERROR); }
inline void warn(std::string_view msg) { log(msg, WARN_); } inline void warn(std::string_view msg) { log(msg, LogLevel::WARN); }
inline void info(std::string_view msg) { log(msg, INFO_); } inline void info(std::string_view msg) { log(msg, LogLevel::INFO); }
inline void debug(std::string_view msg) { log(msg, DEBUG_); } inline void debug(std::string_view msg) { log(msg, LogLevel::DEBUG); }
inline void perf(std::string_view msg) { log(msg, PERF_); } inline void perf(std::string_view msg) { log(msg, LogLevel::PERF); }
void log(std::ostream& o, const std::string& msg); void log(std::ostream& o, const std::string& msg);
@ -58,5 +55,4 @@ private:
Logger(); Logger();
}; };
} // namespace utils
#endif // UTILS_LOGGER_H #endif // UTILS_LOGGER_H

View File

@ -12,11 +12,7 @@
/// \endcond /// \endcond
// qtrocket headers // qtrocket headers
#include "sim/DESolver.h" #include "Logger.h"
#include "utils/Logger.h"
#include "utils/math/MathTypes.h"
namespace sim {
/** /**
* @brief Runge-Kutta 4th order coupled ODE solver. * @brief Runge-Kutta 4th order coupled ODE solver.
@ -28,31 +24,28 @@ namespace sim {
* @tparam Ts * @tparam Ts
*/ */
template<typename T> template<typename T>
class RK4Solver : public DESolver<T> class RK4Solver
{ {
public: public:
RK4Solver(std::function<std::pair<T, T>(T&, T&)> func) RK4Solver(std::function<std::pair<T, T>(T&, T&)> func, double ts=0.1)
{ {
// This only works for Eigen Vector types. // static_assert(std::is_same<T, Vector3>::value,
// TODO: Figure out how to make this slightly more generic, but for now // "You can only use Vector3 or Quaternion valued functions in RK4Solver");
// we're only using this for Vector3 and Quaternion types
static_assert(std::is_same<T, Vector3>::value
|| std::is_same<T, Quaternion>::value,
"You can only use Vector3 or Quaternion valued functions in RK4Solver");
odes = func; odes = func;
setTimeStep(ts);
} }
virtual ~RK4Solver() {} ~RK4Solver() {}
void setTimeStep(double inTs) override { dt = inTs; halfDT = dt / 2.0; } void setTimeStep(double inTs) { dt = inTs; halfDT = dt / 2.0; }
std::pair<T, T> step(T& state, T& rate) override std::pair<T, T> step(T& state, T& rate)
{ {
std::pair<T, T> res; std::pair<T, T> res;
if(dt == std::numeric_limits<double>::quiet_NaN()) if(dt == std::numeric_limits<double>::quiet_NaN())
{ {
utils::Logger::getInstance()->error("Calling RK4Solver without setting dt first is an error"); Logger::getInstance()->error("Calling RK4Solver without setting dt first is an error");
return res; return res;
} }
@ -94,6 +87,4 @@ private:
}; };
} // namespace sim
#endif // SIM_RK4SOLVER_H #endif // SIM_RK4SOLVER_H

View File

@ -1,12 +1,23 @@
#include "MainWindow.h" /// \cond
// C Headers
// C++ Headers
#include <functional>
#include <utility>
// 3rd party headers
#include <QApplication> #include <QApplication>
#include <QLocale> #include <QLocale>
#include <QTranslator> #include <QTranslator>
/// \endcond
#include "MainWindow.h"
#include "Logger.h"
#include "RK4Solver.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
auto* logger = Logger::getInstance();
logger->setLogLevel(Logger::LogLevel::PERF);
QTranslator translator; QTranslator translator;
const QStringList uiLanguages = QLocale::system().uiLanguages(); const QStringList uiLanguages = QLocale::system().uiLanguages();
@ -17,7 +28,20 @@ int main(int argc, char *argv[])
break; break;
} }
} }
logger->debug("Starting MainWindow");
MainWindow w; MainWindow w;
w.show(); w.show();
return a.exec(); return a.exec();
} }
void test_RK4()
{
auto ode = [](double& x, double& r) -> std::pair<double, double>
{
}
}