diff --git a/src/propulsion/can/can_ids.hpp b/src/propulsion/can/can_ids.hpp new file mode 100644 index 00000000..8f9c6efd --- /dev/null +++ b/src/propulsion/can/can_ids.hpp @@ -0,0 +1,31 @@ +#pragma once +#include + +#include +namespace hyped { + +namespace propulsion { + +// Types of CANopen messages, these are used for CAN ID's +static constexpr uint32_t kNmtReceive = 0x000; +static constexpr uint32_t kEmgyTransmit = 0x80; +static constexpr uint32_t kPdo1Transmit = 0x180; +static constexpr uint32_t kPdo1Receive = 0x200; +static constexpr uint32_t kPdo2Transmit = 0x280; +static constexpr uint32_t kPdo2Receive = 0x300; +static constexpr uint32_t kPdo3Transmit = 0x380; +static constexpr uint32_t kPdo3Receive = 0x400; +static constexpr uint32_t kPdo4Transmit = 0x480; +static constexpr uint32_t kPdo4Receive = 0x500; +static constexpr uint32_t kSdoTransmit = 0x580; +static constexpr uint32_t kSdoReceive = 0x600; +static constexpr uint32_t kNmtTransmit = 0x700; +static constexpr uint32_t kNucleoTransmit = 0x900; // currently lowest priority, might change + +static constexpr std::array kCanIds + = {kNmtReceive, kEmgyTransmit, kPdo1Transmit, kPdo1Receive, kPdo2Transmit, + kPdo2Receive, kPdo3Transmit, kPdo3Receive, kPdo4Transmit, kPdo4Receive, + kSdoTransmit, kSdoReceive, kNmtTransmit, kNucleoTransmit}; + +} // namespace propulsion +} // namespace hyped diff --git a/src/propulsion/can/can_receiver.cpp b/src/propulsion/can/can_receiver.cpp new file mode 100644 index 00000000..a3ba5d8e --- /dev/null +++ b/src/propulsion/can/can_receiver.cpp @@ -0,0 +1,41 @@ +#include "can_receiver.hpp" + +namespace hyped::propulsion { + +CanReceiver::CanReceiver(const uint8_t node_id, IController &controller) + : log_("CAN-TRANSCEIVER", utils::System::getSystem().config_.log_level_propulsion), + node_id_(node_id), + controller_(controller), + can_(utils::io::Can::getInstance()) +{ + can_.start(); +} + +void CanReceiver::registerController() +{ + can_.registerProcessor(this); +} + +void CanReceiver::processNewData(utils::io::can::Frame &message) +{ + uint32_t id = message.id; + if (id == kEmgyTransmit + node_id_) { + controller_.processEmergencyMessage(message); + } else if (id == kSdoTransmit + node_id_) { + controller_.processSdoMessage(message); + } else if (id == kNmtTransmit + node_id_) { + controller_.processNmtMessage(message); + } else { + log_.error("Controller %d: CAN message not recognised", node_id_); + } +} + +bool CanReceiver::hasId(const uint32_t id, const bool extended) +{ + if (extended) { return false; } + for (uint32_t cobId : kCanIds) { + if (cobId + node_id_ == id) { return true; } + } + return false; +} +} // namespace hyped::propulsion diff --git a/src/propulsion/can/can_receiver.hpp b/src/propulsion/can/can_receiver.hpp new file mode 100644 index 00000000..ec852d56 --- /dev/null +++ b/src/propulsion/can/can_receiver.hpp @@ -0,0 +1,49 @@ +#pragma once + +#include "can_ids.hpp" +#include "receiver_interface.hpp" + +#include +#include + +#include +#include +#include +#include +#include + +namespace hyped::propulsion { + +class CanReceiver : public utils::io::ICanProcessor, public ICanReceiver { + public: + /** + * @brief Initialise the CanReceiver with the id and the controller as an + * attribute, to access it's attributes + */ + CanReceiver(const uint8_t node_id, IController &controller); + + /** + * @brief Registers the controller to process incoming CAN messages + */ + void registerController() override; + + /** + * @brief This function processes incoming CAN messages + */ + void processNewData(utils::io::can::Frame &message) override; + + /** + * @brief If this function returns true, the CAN message is ment for this CAN node + */ + bool hasId(const uint32_t id, bool extended) override; + + private: + utils::Logger log_; + uint8_t node_id_; + utils::io::Can &can_; + IController &controller_; + + static constexpr uint32_t kTimeout = 70000; // us +}; + +} // namespace hyped::propulsion diff --git a/src/propulsion/can/can_sender.cpp b/src/propulsion/can/can_sender.cpp index 94091009..75c3d098 100644 --- a/src/propulsion/can/can_sender.cpp +++ b/src/propulsion/can/can_sender.cpp @@ -1,65 +1,18 @@ #include "can_sender.hpp" -#include +#include namespace hyped::propulsion { - -CanSender::CanSender(utils::Logger &log, const uint8_t node_id, IController &controller) - : log_(log), - node_id_(node_id), - can_(utils::io::Can::getInstance()), - controller_(controller) +CanSender::CanSender() + : log_("CAN-SENDER", utils::System::getSystem().config_.log_level_propulsion), + can_(utils::io::Can::getInstance()) { - is_sending_ = false; can_.start(); } -bool CanSender::sendMessage(utils::io::can::Frame &message) +bool CanSender::sendMessage(const utils::io::can::Frame &message) { log_.info("Sending Message"); - can_.send(message); - is_sending_ = true; - const auto now = utils::Timer::getTimeMicros(); - while (is_sending_) { - if ((utils::Timer::getTimeMicros() - now) > kTimeout) { - // TODO(Iain): Test the latency and set the TIMEOUT to a reasonable value. - log_.error("Sender timeout reached"); - return false; - } - } - return true; -} - -void CanSender::registerController() -{ - can_.registerProcessor(this); -} - -void CanSender::processNewData(utils::io::can::Frame &message) -{ - is_sending_ = false; - uint32_t id = message.id; - if (id == kEmgyTransmit + node_id_) { - controller_.processEmergencyMessage(message); - } else if (id == kSdoTransmit + node_id_) { - controller_.processSdoMessage(message); - } else if (id == kNmtTransmit + node_id_) { - controller_.processNmtMessage(message); - } else { - log_.error("Controller %d: CAN message not recognised", node_id_); - } -} - -bool CanSender::hasId(uint32_t id, bool) -{ - for (uint32_t cobId : canIds) { - if (cobId + node_id_ == id) { return true; } - } - return false; -} - -bool CanSender::getIsSending() -{ - return is_sending_; + return can_.send(message); } } // namespace hyped::propulsion diff --git a/src/propulsion/can/can_sender.hpp b/src/propulsion/can/can_sender.hpp index cbe986d7..83182012 100644 --- a/src/propulsion/can/can_sender.hpp +++ b/src/propulsion/can/can_sender.hpp @@ -2,60 +2,19 @@ #include "sender_interface.hpp" -#include -#include - -#include -#include #include #include namespace hyped::propulsion { -class CanSender : public utils::io::ICanProcessor, public ISender { +class CanSender : public utils::io::ICanProcessor, public ICanSender { public: - /** - * @brief Initialise the CanSender with the logger, the id and the controller as an attribute, - * to access it's attributes - */ - CanSender(utils::Logger &log, const uint8_t node_id, IController &controller); - - /** - * @brief Sends CAN messages - */ - bool sendMessage(utils::io::can::Frame &message) override; - - /** - * @brief Registers the controller to process incoming CAN messages - */ - void registerController() override; - - /** - * @brief This function processes incoming CAN messages - */ - void processNewData(utils::io::can::Frame &message) override; + CanSender(); - /** - * @brief If this function returns true, the CAN message is ment for this CAN node - */ - bool hasId(uint32_t id, bool extended) override; - - /** - * @brief Return if the can_sender is sending a CAN message right now - */ - bool getIsSending() override; + bool sendMessage(const utils::io::can::Frame &message) override; private: - utils::Logger &log_; - uint8_t node_id_; utils::io::Can &can_; - std::atomic is_sending_; - IController &controller_; - - static constexpr uint32_t kEmgyTransmit = 0x80; - static constexpr uint32_t kSdoTransmit = 0x580; - static constexpr uint32_t kNmtTransmit = 0x700; - static constexpr uint64_t kTimeout = 70000; // us + utils::Logger log_; }; - } // namespace hyped::propulsion diff --git a/src/propulsion/can/fake_can_receiver.cpp b/src/propulsion/can/fake_can_receiver.cpp new file mode 100644 index 00000000..713e0fe2 --- /dev/null +++ b/src/propulsion/can/fake_can_receiver.cpp @@ -0,0 +1,30 @@ +#include "fake_can_receiver.hpp" + +namespace hyped::propulsion { +FakeCanReceiver::FakeCanReceiver() + : log_("FAKE-CAN-SENDER", utils::System::getSystem().config_.log_level_propulsion), + is_sending_(false), + can_endpoint_(*this) +{ +} + +void FakeCanReceiver::registerController() +{ +} + +void FakeCanReceiver::processNewData(utils::io::can::Frame &) +{ + log_.info("processNewData"); + is_sending_ = false; +} + +bool FakeCanReceiver::hasId(const uint32_t, bool) +{ + return true; +} + +bool FakeCanReceiver::getIsSending() +{ + return is_sending_; +} +} // namespace hyped::propulsion diff --git a/src/propulsion/can/fake_can_receiver.hpp b/src/propulsion/can/fake_can_receiver.hpp new file mode 100644 index 00000000..835310ad --- /dev/null +++ b/src/propulsion/can/fake_can_receiver.hpp @@ -0,0 +1,34 @@ +#pragma once + +#include "fake_can_endpoint.hpp" +#include "receiver_interface.hpp" + +#include +#include + +#include +#include +#include + +namespace hyped::propulsion { + +class FakeCanReceiver : public utils::io::ICanProcessor, public ICanReceiver { + public: + FakeCanReceiver(); + + void registerController() override; + + void processNewData(utils::io::can::Frame &message) override; + + bool hasId(const uint32_t id, bool extended) override; + + bool getIsSending(); + + private: + utils::Logger log_; + // Can& can_; + std::atomic is_sending_; + FakeCanEndpoint can_endpoint_; +}; + +} // namespace hyped::propulsion diff --git a/src/propulsion/can/fake_can_sender.cpp b/src/propulsion/can/fake_can_sender.cpp index 96001f71..d89de7fd 100644 --- a/src/propulsion/can/fake_can_sender.cpp +++ b/src/propulsion/can/fake_can_sender.cpp @@ -1,14 +1,14 @@ #include "fake_can_sender.hpp" namespace hyped::propulsion { -FakeCanSender::FakeCanSender(utils::Logger &log_, uint8_t) - : log_(log_), +FakeCanSender::FakeCanSender() + : log_("FAKE-CAN-SENDER", utils::System::getSystem().config_.log_level_propulsion), is_sending_(false), can_endpoint_(*this) { } -bool FakeCanSender::sendMessage(utils::io::can::Frame &) +bool FakeCanSender::sendMessage(const utils::io::can::Frame &) { log_.info("sending"); is_sending_ = true; @@ -19,21 +19,6 @@ bool FakeCanSender::sendMessage(utils::io::can::Frame &) return true; } -void FakeCanSender::registerController() -{ -} - -void FakeCanSender::processNewData(utils::io::can::Frame &) -{ - log_.info("processNewData"); - is_sending_ = false; -} - -bool FakeCanSender::hasId(uint32_t, bool) -{ - return true; -} - bool FakeCanSender::getIsSending() { return is_sending_; diff --git a/src/propulsion/can/fake_can_sender.hpp b/src/propulsion/can/fake_can_sender.hpp index 1ee7a438..2745497f 100644 --- a/src/propulsion/can/fake_can_sender.hpp +++ b/src/propulsion/can/fake_can_sender.hpp @@ -8,22 +8,17 @@ #include #include +#include namespace hyped::propulsion { -class FakeCanSender : public utils::io::ICanProcessor, public ISender { +class FakeCanSender : public utils::io::ICanProcessor, public ICanSender { public: - FakeCanSender(utils::Logger &log_, uint8_t id); + FakeCanSender(); - bool sendMessage(utils::io::can::Frame &message) override; + bool sendMessage(const utils::io::can::Frame &message) override; - void registerController() override; - - void processNewData(utils::io::can::Frame &message) override; - - bool hasId(uint32_t id, bool extended) override; - - bool getIsSending() override; + bool getIsSending(); private: utils::Logger log_; diff --git a/src/propulsion/can/receiver_interface.hpp b/src/propulsion/can/receiver_interface.hpp new file mode 100644 index 00000000..e5fbed60 --- /dev/null +++ b/src/propulsion/can/receiver_interface.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include + +namespace hyped { + +namespace propulsion { + +class ICanReceiver { + public: + /** + * @brief { Registers the controller to process incoming CAN messages} + * */ + virtual void registerController() = 0; + + virtual void processNewData(utils::io::can::Frame &message) = 0; + + virtual bool hasId(const uint32_t id, bool extended) = 0; +}; + +} // namespace propulsion +} // namespace hyped diff --git a/src/propulsion/can/sender_interface.hpp b/src/propulsion/can/sender_interface.hpp index e402d50d..5b2111d9 100644 --- a/src/propulsion/can/sender_interface.hpp +++ b/src/propulsion/can/sender_interface.hpp @@ -6,40 +6,12 @@ namespace hyped { namespace propulsion { -// Types of CANopen messages, these are used for CAN ID's -constexpr uint32_t kEmgyTransmit = 0x80; -constexpr uint32_t kSdoReceive = 0x600; -constexpr uint32_t kSdoTransmit = 0x580; -constexpr uint32_t kNmtReceive = 0x000; -constexpr uint32_t kNmtTransmit = 0x700; -constexpr uint32_t kPdo1Transmit = 0x180; -constexpr uint32_t kPdo1Receive = 0x200; -constexpr uint32_t kPdo2Transmit = 0x280; -constexpr uint32_t kPdo2Receive = 0x300; -constexpr uint32_t kPdo3Transmit = 0x380; -constexpr uint32_t kPdo3Receive = 0x400; -constexpr uint32_t kPdo4Transmit = 0x480; -constexpr uint32_t kPdo4Receive = 0x500; - -constexpr uint32_t canIds[13]{0x80, 0x600, 0x580, 0x000, 0x700, 0x180, 0x200, - 0x280, 0x300, 0x380, 0x400, 0x480, 0x500}; - -class ISender { +class ICanSender { public: /** * @brief { Sends CAN messages } */ - virtual bool sendMessage(utils::io::can::Frame &message) = 0; - - /** - * @brief { Registers the controller to process incoming CAN messages} - * */ - virtual void registerController() = 0; - - /** - * @brief { Return if the can_sender is sending a CAN message right now } - */ - virtual bool getIsSending() = 0; + virtual bool sendMessage(const utils::io::can::Frame &message) = 0; }; } // namespace propulsion diff --git a/src/propulsion/controller.cpp b/src/propulsion/controller.cpp index fca6e050..638dee97 100644 --- a/src/propulsion/controller.cpp +++ b/src/propulsion/controller.cpp @@ -2,8 +2,8 @@ namespace hyped::propulsion { -Controller::Controller(utils::Logger &log, uint8_t id) - : log_(log), +Controller::Controller(const uint8_t id) + : log_("CONTROLLER", utils::System::getSystem().config_.log_level_propulsion), data_(data::Data::getInstance()), motor_data_(data_.getMotorData()), state_(kNotReadyToSwitchOn), @@ -13,7 +13,8 @@ Controller::Controller(utils::Logger &log, uint8_t id) actual_torque_(0), motor_temperature_(0), controller_temperature_(0), - sender_(log, node_id_, *this) + receiver_(node_id_, *this), + sender_() { sdo_message_.id = kSdoReceive + node_id_; sdo_message_.extended = false; @@ -33,7 +34,7 @@ bool Controller::sendControllerMessage(const ControllerMessage message_template) void Controller::registerController() { - sender_.registerController(); + receiver_.registerController(); } void Controller::configure() diff --git a/src/propulsion/controller.hpp b/src/propulsion/controller.hpp index ad393d6f..7d0daa3c 100644 --- a/src/propulsion/controller.hpp +++ b/src/propulsion/controller.hpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -18,10 +19,9 @@ class Controller : public IController { public: /** * @brief Construct a new Controller object - * @param log * @param id */ - Controller(utils::Logger &log, uint8_t id); + Controller(const uint8_t id); /** * @brief Registers controller to recieve and transmit CAN messages. */ @@ -48,13 +48,14 @@ class Controller : public IController { * @brief Send the target velocity to the motor controller. * @param target_velocity - in rpm (calculated in speed calculator) */ - void sendTargetVelocity(int32_t target_velocity) override; + void sendTargetVelocity(const int32_t target_velocity) override; + /** * @brief Send the target torque to the motor controller. * * @param target_torque */ - void sendTargetTorque(int16_t target_torque); + void sendTargetTorque(const int16_t target_torque); /** * @brief Send a request to the motor controller to get the actual velocity. * @@ -164,7 +165,7 @@ class Controller : public IController { */ void throwCriticalFailure(); - utils::Logger &log_; + utils::Logger log_; data::Data &data_; data::Motors motor_data_; std::atomic state_; @@ -174,6 +175,7 @@ class Controller : public IController { std::atomic actual_torque_; std::atomic motor_temperature_; std::atomic controller_temperature_; + CanReceiver receiver_; CanSender sender_; utils::io::can::Frame sdo_message_; utils::io::can::Frame nmt_message_; diff --git a/src/propulsion/fake_controller.cpp b/src/propulsion/fake_controller.cpp index 7b02e236..1748edfe 100644 --- a/src/propulsion/fake_controller.cpp +++ b/src/propulsion/fake_controller.cpp @@ -2,8 +2,8 @@ namespace hyped::propulsion { -FakeController::FakeController(utils::Logger &log, const uint8_t id, const bool is_faulty) - : log_(log), +FakeController::FakeController(const uint8_t id, const bool is_faulty) + : log_("FAKE-CONTROLLER", utils::System::getSystem().config_.log_level_propulsion), data_(data::Data::getInstance()), id_(id), is_faulty_(is_faulty), diff --git a/src/propulsion/fake_controller.hpp b/src/propulsion/fake_controller.hpp index deeceee2..e50a6460 100644 --- a/src/propulsion/fake_controller.hpp +++ b/src/propulsion/fake_controller.hpp @@ -4,6 +4,7 @@ #include #include +#include #include namespace hyped::propulsion { @@ -13,7 +14,7 @@ class FakeController : public IController { /** * @brief Construct a new Fake Controller object */ - FakeController(utils::Logger &log, const uint8_t id, const bool is_faulty); + FakeController(const uint8_t id, const bool is_faulty); /** * @brief Registers controller to recieve and transmit CAN messages. * note: empty implementation. @@ -96,7 +97,7 @@ class FakeController : public IController { * @brief Times the duration of the run. Starts when we enter the accelerating state. */ void startTimer(); - utils::Logger &log_; + utils::Logger log_; data::Data &data_; ControllerState state_; utils::Timer timer_; diff --git a/src/propulsion/main.cpp b/src/propulsion/main.cpp index a4de79a4..5a33370f 100644 --- a/src/propulsion/main.cpp +++ b/src/propulsion/main.cpp @@ -6,7 +6,7 @@ Main::Main() : utils::concurrent::Thread( utils::Logger("PROPULSION", utils::System::getSystem().config_.log_level_propulsion)), is_running_(true), - state_processor_(log_) + state_processor_() { } diff --git a/src/propulsion/nucleo_manager.cpp b/src/propulsion/nucleo_manager.cpp new file mode 100644 index 00000000..4ca6be00 --- /dev/null +++ b/src/propulsion/nucleo_manager.cpp @@ -0,0 +1,24 @@ +#include "nucleo_manager.hpp" + +#include + +namespace hyped::propulsion { + +NucleoManager::NucleoManager() + : log_("NUCLEOMANAGER", utils::System::getSystem().config_.log_level_propulsion), + sender_() +{ + can_frame_.id = kNucleoTransmit; + can_frame_.extended = false; + can_frame_.len = 4; +} + +void NucleoManager::sendNucleoFrequency(uint32_t target_frequency) +{ + for (size_t i = 0; i < 4; ++i) { + can_frame_.data[i] = target_frequency & 0xff; + target_frequency >>= 8; + } + sender_.sendMessage(can_frame_); +} +} // namespace hyped::propulsion diff --git a/src/propulsion/nucleo_manager.hpp b/src/propulsion/nucleo_manager.hpp new file mode 100644 index 00000000..ac187b91 --- /dev/null +++ b/src/propulsion/nucleo_manager.hpp @@ -0,0 +1,26 @@ +#include +#include +#include +#include +#include + +namespace hyped::propulsion { + +class NucleoManager { + public: + /** + * @brief Initializes the nucleo manager + * */ + NucleoManager(); + /** + * @brief Send the target frequency to the nucleo board. + * @param target_frequency in Hz + */ + void sendNucleoFrequency(uint32_t target_frequency); + + private: + utils::Logger log_; + utils::io::can::Frame can_frame_; + CanSender sender_; +}; +} // namespace hyped::propulsion diff --git a/src/propulsion/rpm_regulator.cpp b/src/propulsion/rpm_regulator.cpp index 06dcd1d8..64939114 100644 --- a/src/propulsion/rpm_regulator.cpp +++ b/src/propulsion/rpm_regulator.cpp @@ -2,6 +2,8 @@ #include +#include + namespace hyped::propulsion { RpmRegulator::RpmRegulator() @@ -19,8 +21,8 @@ int32_t RpmRegulator::calculateRpm(const data::nav_t actual_velocity, const int3 int32_t RpmRegulator::calculateOptimalRpm(const data::nav_t actual_velocity) { // polynomial values from simulation - return std::round(0.32047 * actual_velocity * actual_velocity + 297.72578 * actual_velocity - + 1024.30824); + return static_cast(std::round(0.32047 * actual_velocity * actual_velocity + + 297.72578 * actual_velocity + 1024.30824)); } int32_t RpmRegulator::step(const int32_t optimal_rpm, const int32_t actual_rpm) diff --git a/src/propulsion/state_processor.cpp b/src/propulsion/state_processor.cpp index f606d942..c2376f1c 100644 --- a/src/propulsion/state_processor.cpp +++ b/src/propulsion/state_processor.cpp @@ -4,21 +4,22 @@ namespace hyped::propulsion { -StateProcessor::StateProcessor(utils::Logger &log) - : log_(log), +StateProcessor::StateProcessor() + : log_("PROPULSION-STATE-PROCESSOR", utils::System::getSystem().config_.log_level_propulsion), sys_(utils::System::getSystem()), data_(data::Data::getInstance()), - is_initialised_(false) + is_initialised_(false), + nucleo_manager_(std::make_unique()) { if (sys_.config_.use_fake_controller) { log_.info("constructing with fake controllers"); for (size_t i = 0; i < data::Motors::kNumMotors; ++i) { - controllers_.at(i) = std::make_unique(log_, i, false); + controllers_.at(i) = std::make_unique(i, false); } } else { // Use real controllers log_.info("constructing with real controllers"); for (size_t i = 0; i < data::Motors::kNumMotors; ++i) { - controllers_.at(i) = std::make_unique(log_, i); + controllers_.at(i) = std::make_unique(i); } } } @@ -62,6 +63,7 @@ void StateProcessor::prepareMotors() for (auto &controller : controllers_) { controller->enterOperational(); } + nucleo_manager_->sendNucleoFrequency(0); // Might not be correct value previous_acceleration_time_ = 0; } @@ -89,13 +91,14 @@ void StateProcessor::accelerate() const auto now = utils::Timer::getTimeMicros(); if (now - previous_acceleration_time_ > 5000) { previous_acceleration_time_ = now; - const auto velocity = data_.getNavigationData().velocity; - const auto act_rpm = calculateAverageRpm(); - const auto rpm = RpmRegulator::calculateRpm(velocity, act_rpm); + const data::nav_t velocity = data_.getNavigationData().velocity; + const uint32_t act_rpm = calculateAverageRpm(); + const uint32_t rpm = RpmRegulator::calculateRpm(velocity, act_rpm); log_.info("sending %d rpm as target", rpm); for (auto &controller : controllers_) { controller->sendTargetVelocity(rpm); } + nucleo_manager_->sendNucleoFrequency(std::round(static_cast(rpm) / 60.0)); } } @@ -115,7 +118,7 @@ bool StateProcessor::isOverLimits() return over_limits; } -int32_t StateProcessor::calculateAverageRpm() +uint32_t StateProcessor::calculateAverageRpm() { int32_t total = 0; for (auto &controller : controllers_) { diff --git a/src/propulsion/state_processor.hpp b/src/propulsion/state_processor.hpp index b2c57a9e..4f7a4b6c 100644 --- a/src/propulsion/state_processor.hpp +++ b/src/propulsion/state_processor.hpp @@ -1,6 +1,7 @@ #pragma once #include "controller_interface.hpp" +#include "nucleo_manager.hpp" #include "rpm_regulator.hpp" #include @@ -15,9 +16,9 @@ namespace hyped::propulsion { class StateProcessor { public: /** - * @brief Initializes the state processors with the amount of motors and the logger + * @brief Initializes the state processors with the amount of motors * */ - StateProcessor(utils::Logger &log); + StateProcessor(); /** * @brief Sends the desired settings to the motors @@ -84,7 +85,7 @@ class StateProcessor { * @brief Calculate the Average rpm of all motors * @return int32_t */ - int32_t calculateAverageRpm(); + uint32_t calculateAverageRpm(); /** * @brief calculate the max Current drawn out of all the motors @@ -101,12 +102,13 @@ class StateProcessor { int32_t calculateMaximumTemperature(); - utils::Logger &log_; + utils::Logger log_; utils::System &sys_; data::Data &data_; bool is_initialised_; std::array, data::Motors::kNumMotors> controllers_; uint64_t previous_acceleration_time_; + std::unique_ptr nucleo_manager_; }; } // namespace hyped::propulsion diff --git a/src/utils/io/spi.cpp b/src/utils/io/spi.cpp index 5f721d6b..43252e3d 100644 --- a/src/utils/io/spi.cpp +++ b/src/utils/io/spi.cpp @@ -266,6 +266,6 @@ Spi::~Spi() close(spi_fd_); } -} // namespace io } // namespace utils } // namespace hyped +} // namespace hyped