Skip to content

Commit

Permalink
Merge pull request #91 from Northeastern-Electric-Racing/#6-Speed-Con…
Browse files Browse the repository at this point in the history
…troller

#6-Created-Speed-Controller
  • Loading branch information
Peyton-McKee authored Apr 1, 2024
2 parents 32e1e5a + bbb1525 commit fe356a8
Show file tree
Hide file tree
Showing 9 changed files with 268 additions and 0 deletions.
3 changes: 3 additions & 0 deletions NERODevelopment/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ set(PROJECT_SOURCES
src/utils/descriptioninfo.cpp

src/main.cpp

src/controllers/speedcontroller.h
src/controllers/speedcontroller.cpp
)

find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick Network Mqtt Protobuf)
Expand Down
112 changes: 112 additions & 0 deletions NERODevelopment/src/controllers/speedcontroller.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#include "speedcontroller.h"

SpeedController::SpeedController(Model *model, QObject* parent): ButtonController{model, parent}, m_tractionControl(), m_packTemp(),
m_motorTemp(), m_chargeState(), m_currentTime(), m_fastestTime(), m_lastTime(), m_currentSpeed(),
m_maxSpeed(), m_current(), m_maxCurrent(), m_currentDischarge(), m_maxCurrentDischarge(){
connect(m_model, &Model::onCurrentDataChange, this, &SpeedController::update);
}

bool SpeedController::tractionControl() const {return m_tractionControl;}
void SpeedController::setTractionControl(bool tractionStatus) {
if (tractionStatus != m_tractionControl) {
m_tractionControl = tractionStatus;
emit tractionControlChanged(tractionStatus);
}
}
float SpeedController::packTemp() const {return m_packTemp;}
void SpeedController::setPackTemp(float packTemp) {
if (packTemp != m_packTemp) {
m_packTemp = packTemp;
emit packTempChanged(packTemp);
}
}
float SpeedController::motorTemp() const {return m_motorTemp;}
void SpeedController::setMotorTemp(float motorTemp) {
if (motorTemp != m_motorTemp) {
m_motorTemp = motorTemp;
emit motorTempChanged(motorTemp);
}
}
float SpeedController::chargeState() const {return m_chargeState;}
void SpeedController::setChargeState(float chargeState) {
if (chargeState != m_chargeState) {
m_chargeState = chargeState;
emit packTempChanged(chargeState);
}
}
int SpeedController::currentTime() const {return m_currentTime;}
void SpeedController::setCurrentTime(int currentTime) {
if (currentTime != m_currentTime) {
m_currentTime = currentTime;
emit currentTimeChanged(currentTime);
}
}
int SpeedController::fastestTime() const {return m_fastestTime;}
void SpeedController::setFastestTime(int fastTime) {
if (fastTime != m_fastestTime) {
m_fastestTime = fastTime;
emit fastestTimeChanged(fastTime);
}
}
int SpeedController::lastTime() const {return m_lastTime;}
void SpeedController::setLastTime(int lastTime) {
if (lastTime != m_lastTime) {
m_lastTime = lastTime;
emit lastTimeChanged(lastTime);
}
}
int SpeedController::currentSpeed() const {return m_currentSpeed;}
void SpeedController::setCurrentSpeed(int currentSpeed) {
if (currentSpeed != m_currentSpeed) {
m_currentSpeed = currentSpeed;
emit currentSpeedChanged(currentSpeed);
}
}
int SpeedController::maxSpeed() const {return m_maxSpeed;}
void SpeedController::setMaxSpeed(int maxSpeed) {
if (maxSpeed != m_maxSpeed) {
m_maxSpeed = maxSpeed;
emit maxSpeedChanged(maxSpeed);
}
}
float SpeedController::current() const {return m_current;}
void SpeedController::setCurrent(float current) {
if (current != m_current) {
m_current = current;
emit currentChanged(current);
}
}
float SpeedController::maxCurrent() const {return m_maxCurrent;}
void SpeedController::setMaxCurrent(float maxCurrent) {
if (maxCurrent != m_maxCurrent) {
m_maxCurrent = maxCurrent;
emit maxCurrentChanged(maxCurrent);
}
}
float SpeedController::currentDischarge() const {return m_currentDischarge;}
void SpeedController::setCurrentDischarge(float currentDischarge) {
if (currentDischarge != m_currentDischarge) {
m_currentDischarge = currentDischarge;
emit currentDischargeChanged(currentDischarge);
}
}
float SpeedController::maxCurrentDischarge() const {return m_maxCurrentDischarge;}
void SpeedController::setMaxCurrentDischarge(float maxCurrentDischarge) {
if (maxCurrentDischarge != m_maxCurrentDischarge) {
m_maxCurrentDischarge = maxCurrentDischarge;
emit maxCurrentDischargeChanged(maxCurrentDischarge);
}
}

void SpeedController::update() {
setTractionControl(*m_model->getTractionControl());
setPackTemp(*m_model->getPackTemp());
setMotorTemp(*m_model->getMotorTemp());
setChargeState(*m_model->getStateOfCharge());
setCurrentTime(*m_model->getTime());
setFastestTime(m_model->getFastestTime());
setLastTime(m_model->getLastTime());
setCurrentSpeed(*m_model->getMph());
setMaxSpeed(m_model->getMaxSpeed());
setCurrent(*m_model->getCurrent());
}
107 changes: 107 additions & 0 deletions NERODevelopment/src/controllers/speedcontroller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#ifndef SPEEDCONTROLLER_H
#define SPEEDCONTROLLER_H

#include <QObject>
#include "../models/model.h"
#include "buttoncontroller.h"

class SpeedController : public ButtonController {
Q_OBJECT
Q_PROPERTY(bool tractionControl READ tractionControlStatus WRITE setTractionControl
NOTIFY tractionControlChanged);

Q_PROPERTY(float packTemp READ packTemp WRITE setPackTemp NOTIFY packTempChanged);

Q_PROPERTY(float motorTemp READ motorTemp WRITE setMotorTemp NOTIFY motorTempChanged);

Q_PROPERTY(float chargeState READ chargeState WRITE setChargeState NOTIFY chargeStateChanged);

Q_PROPERTY(int currentTime READ currentTime WRITE setCurrentTime NOTIFY currentTimeChanged);

Q_PROPERTY(int fastestTime READ fastestTime WRITE setFastestTime NOTIFY fastestTimeChanged);

Q_PROPERTY(int lastTime READ lastTime WRITE setLastTime NOTIFY lastTimeChanged);

Q_PROPERTY(int currentSpeed READ currentSpeed WRITE setCurrentSpeed NOTIFY currentSpeedChanged);

Q_PROPERTY(int maxSpeed READ maxSpeed WRITE setMaxSpeed NOTIFY maxSpeedChanged);

Q_PROPERTY(float current READ current WRITE setCurrent NOTIFY currentChanged);

Q_PROPERTY(float maxCurrent READ maxCurrent WRITE setMaxCurrent NOTIFY maxCurrentChanged);

Q_PROPERTY(float currentDischarge READ currentDischarge WRITE setCurrentDischarge NOTIFY currentDischargeChanged);

Q_PROPERTY(float maxCurrentDischarge READ maxCurrentDischarge WRITE setMaxCurrentDischarge
NOTIFY maxcurrentDischargeChanged);




public:
explicit SpeedController(Model *model ,QObject *parent = nullptr);

bool tractionControl() const;
float packTemp() const;
float motorTemp() const;
float chargeState() const;
int currentTime() const;
int fastestTime() const;
int lastTime() const;
int currentSpeed() const;
int maxSpeed() const;
float current() const;
float maxCurrent() const;
float currentDischarge() const;
float maxCurrentDischarge() const;

signals:
void tractionControlChanged(bool);
void packTempChanged(float);
void motorTempChanged(float);
void chargeStateChanged(float);
void currentTimeChanged(int);
void fastestTimeChanged(int);
void lastTimeChanged(int);
void currentSpeedChanged(int);
void maxSpeedChanged(int);
void currentChanged(float);
void maxCurrentChanged(float);
void currentDischargeChanged(float);
void maxCurrentDischargeChanged(float);

public slots:
void setTractionControl(bool);
void setPackTemp(float);
void setMotorTemp(float);
void setChargeState(float);
void setCurrentTime(int);
void setFastestTime(int);
void setLastTime(int);
void setCurrentSpeed(int);
void setMaxSpeed(int);
void setCurrent(float);
void setMaxCurrent(float);
void setCurrentDischarge(float);
void setMaxCurrentDischarge(float);

void update();

private:
bool m_tractionControl = false;
float m_packTemp = 0;
float m_motorTemp = 0;
float m_chargeState = 0;
int m_currentTime = 0;
int m_fastestTime = 0;
int m_lastTime = 0;
int m_currentSpeed = 0;
int m_maxSpeed = 0;
float m_current = 0;
float m_maxCurrent = 0;
float m_currentDischarge = 0;
float m_maxCurrentDischarge = 0;

};

#endif // SPEEDCONTROLLER_H
2 changes: 2 additions & 0 deletions NERODevelopment/src/models/mock_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class MockModel : public Model {
std::optional<bool> getIsTalking() override;
std::optional<int> getNumberOfCriticalFaults() override;
std::optional<int> getNumberOfNonCriticalFaults() override;
std::optional<float> getTime() override;

void sendMessage(const QString topic, const QString message) override;

private slots:
Expand Down
25 changes: 25 additions & 0 deletions NERODevelopment/src/models/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,31 @@ void Model::updateAverageCellTemps() {
averageCellTemps.append(getAveCellTemp() ? *getAveCellTemp() : 0);
}


int Model::getLastTime() {
return m_lastTime;
}

int Model::getFastestTime() {
return m_fastestTime;
}

int Model::getMaxSpeed() {
return m_maxSpeed;
}


void Model::updateStateOfChargeDeltas() {
if (stateOfChargeDeltas.size() >= 30) {
stateOfChargeDeltas.pop_front();
}
std::optional<float> soc = this->getStateOfCharge();
if (soc) {
stateOfChargeDeltas.append(*soc - prevSoc);
prevSoc = *soc;
}
}

QList<DebugTableRowValue> Model::getDebugTableValues() {
QList<DebugTableRowValue> table = {};
for (auto it = this->currentData.begin(); it != this->currentData.end();
Expand Down
12 changes: 12 additions & 0 deletions NERODevelopment/src/models/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,15 @@ class Model : public QObject {
virtual std::optional<bool> getIsTalking() = 0;
virtual std::optional<int> getNumberOfCriticalFaults() = 0;
virtual std::optional<int> getNumberOfNonCriticalFaults() = 0;
virtual std::optional<int> getTime() = 0;
virtual void sendMessage(QString topic, QString message) = 0;



int getFastestTime();
int getLastTime();
int getMaxSpeed();

QList<DebugTableRowValue> getDebugTableValues();
void updatePackTempData();
void addPinnedData(QString id);
Expand All @@ -104,6 +111,11 @@ private slots:
QList<float> packTempData;
QList<FaultInstance> faultInstances;
QList<float> averageCellTemps;
QList<float> stateOfChargeDeltas;
int m_fastestTime;
int m_lastTime;
int m_maxSpeed;

};

#define ModelInterfaceId "com.ner.model"
Expand Down
1 change: 1 addition & 0 deletions NERODevelopment/src/models/raspberry_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ std::optional<int> RaspberryModel::getNumberOfNonCriticalFaults() {
return std::nullopt;
}


int RaspberryModel::totalNumberOfOnesIn(float value) {
int total = 0;
std::string binary = std::bitset<8>(static_cast<int>(value)).to_string();
Expand Down
2 changes: 2 additions & 0 deletions NERODevelopment/src/models/raspberry_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class RaspberryModel : public Model {
std::optional<bool> getIsTalking() override;
std::optional<int> getNumberOfCriticalFaults() override;
std::optional<int> getNumberOfNonCriticalFaults() override;
std::optional<int> getTime() override;

void sendMessage(const QString topic, const QString message) override;

private slots:
Expand Down
4 changes: 4 additions & 0 deletions NERODevelopment/src/utils/data_type_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,9 @@
#define CRITICALFAULTS "CRITICAL FAULTS"
#define NONCRITICALFAULTS "NON CRITICAL FAULTS"
#define MICROPHONE "MICROPHONE"
#define FASTESTTIME "FASTESTTIME"
#define LASTTIME "LASTTIME"



#endif // DATATYPENAMES_H

0 comments on commit fe356a8

Please sign in to comment.