-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Temperature Rewrite #150
base: master
Are you sure you want to change the base?
Temperature Rewrite #150
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,16 +75,16 @@ struct BrakePressureData : public SensorData { | |
}; | ||
|
||
struct Sensors : public Module { | ||
static constexpr size_t kNumImus = 4; | ||
static constexpr size_t kNumEncoders = 4; | ||
static constexpr size_t kNumBrakePressure = 2; | ||
static constexpr size_t kNumBrakeTemp = 2; | ||
static constexpr size_t kNumAmbientTemp = 4; | ||
static constexpr size_t kNumImus = 4; | ||
static constexpr size_t kNumEncoders = 4; | ||
static constexpr size_t kNumBrakePressure = 2; | ||
static constexpr size_t kNumBrakeSuspensionTemp = 4; | ||
static constexpr size_t kNumAmbientTemp = 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
TemperatureData temperature; | ||
AmbientPressureData ambient_pressure; | ||
|
||
std::array<TemperatureData, kNumBrakeTemp> brake_temperature_array; | ||
std::array<TemperatureData, kNumBrakeSuspensionTemp> brake_suspension_temperature_array; | ||
std::array<TemperatureData, kNumAmbientTemp> ambient_temperature_array; | ||
|
||
DataPoint<std::array<ImuData, kNumImus>> imu; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,19 +6,19 @@ | |
|
||
namespace hyped::sensors { | ||
|
||
Temperature::Temperature(const uint8_t pin) | ||
: log_("TEMPERATURE", utils::System::getSystem().config_.log_level_sensors), | ||
AmbientTemperature::AmbientTemperature(const uint8_t pin) | ||
: log_("AMBIENT TEMPERATURE", utils::System::getSystem().config_.log_level_sensors), | ||
pin_(pin) | ||
{ | ||
log_.info("started temperature for pin %u", pin); | ||
} | ||
|
||
Temperature::~Temperature() | ||
AmbientTemperature::~AmbientTemperature() | ||
{ | ||
log_.info("stopped temperature for pin"); | ||
log_.info("stopped ambient temperature for pin"); | ||
} | ||
|
||
void Temperature::run() | ||
void AmbientTemperature::run() | ||
{ | ||
uint16_t raw_value = pin_.read(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
log_.debug("raw value: %d", raw_value); | ||
|
@@ -27,15 +27,49 @@ void Temperature::run() | |
temperature_data_.operational = true; | ||
} | ||
|
||
int8_t Temperature::scaleData(const uint8_t raw_value) | ||
int8_t AmbientTemperature::scaleData(const uint8_t raw_value) | ||
{ | ||
// convert to degrees C | ||
double temp = static_cast<double>(raw_value) / 4095; | ||
temp = (temp * 175) - 50; | ||
return static_cast<int8_t>(temp); | ||
} | ||
|
||
uint8_t Temperature::getData() const | ||
uint8_t AmbientTemperature::getData() const | ||
{ | ||
return temperature_data_.temperature; | ||
} | ||
|
||
BrakesAndSuspensionTemperature::BrakesAndSuspensionTemperature(const uint8_t pin) | ||
: log_("BRAKE-SUSP TEMPERATURE", utils::System::getSystem().config_.log_level_sensors), | ||
pin_(pin) | ||
{ | ||
log_.info("started temperature for pin %u", pin); | ||
} | ||
|
||
BrakesAndSuspensionTemperature::~BrakesAndSuspensionTemperature() | ||
{ | ||
log_.info("stopped brake/suspension temperature for pin"); | ||
} | ||
|
||
void BrakesAndSuspensionTemperature::run() | ||
{ | ||
uint16_t raw_value = pin_.read(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
log_.debug("raw value: %d", raw_value); | ||
temperature_data_.temperature = scaleData(raw_value); | ||
log_.debug("scaled value: %d", temperature_data_.temperature); | ||
temperature_data_.operational = true; | ||
} | ||
|
||
int8_t BrakesAndSuspensionTemperature::scaleData(const uint8_t raw_value) | ||
{ | ||
// convert to degrees C | ||
double temp = static_cast<double>(raw_value) / 4095; | ||
temp = (temp * 175) - 50; | ||
return static_cast<int8_t>(temp); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like a convoluted way of doing this. Is there a datasheet somewhere? return std::round(static_cast<double>(raw_value) / 23.4 - 50); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may have to recast the result to make the compiler happy. Actually, we may want to assert that the result is in bounds, e.g. by checking |
||
} | ||
|
||
uint8_t BrakesAndSuspensionTemperature::getData() const | ||
{ | ||
return temperature_data_.temperature; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
namespace hyped::sensors { | ||
|
||
using AmbientTemperaturePins = std::array<uint8_t, data::Sensors::kNumAmbientTemp>; | ||
using BrakeTemperaturePins = std::array<uint8_t, data::Sensors::kNumBrakeTemp>; | ||
using BrakeTemperaturePins = std::array<uint8_t, data::Sensors::kNumBrakeSuspensionTemp>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BrakeAndSuspension |
||
|
||
class ITemperature { | ||
public: | ||
|
@@ -29,15 +29,55 @@ class ITemperature { | |
virtual uint8_t getData() const = 0; | ||
}; | ||
|
||
class Temperature : public ITemperature { | ||
class AmbientTemperature : public ITemperature { | ||
public: | ||
/** | ||
* @brief Construct a new Temperature object | ||
* @brief Construct a new Ambient Temperature object | ||
* | ||
* @param pin for specific ADC pin | ||
*/ | ||
Temperature(const uint8_t pin); | ||
~Temperature(); | ||
AmbientTemperature(const uint8_t pin); | ||
~AmbientTemperature(); | ||
|
||
/** | ||
* @brief | ||
* | ||
* @return int to set to data struct in sensors main | ||
*/ | ||
uint8_t getData() const override; | ||
|
||
/** | ||
* @brief one interation of checking sensors | ||
*/ | ||
void run() override; | ||
|
||
private: | ||
/** | ||
* @brief scale raw digital data to output in degrees C | ||
* | ||
* @param raw_value input voltage | ||
* @return int representation of temperature | ||
*/ | ||
static int8_t scaleData(uint8_t raw_value); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
utils::Logger log_; | ||
utils::io::Adc pin_; | ||
|
||
/** | ||
* @brief int from data structs | ||
*/ | ||
data::TemperatureData temperature_data_; | ||
}; | ||
|
||
class BrakesAndSuspensionTemperature : public ITemperature { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this should go into a separate file. |
||
public: | ||
/** | ||
* @brief Construct a new Brakes and Suspension Temperature object | ||
* | ||
* @param pin for specific ADC pin | ||
*/ | ||
BrakesAndSuspensionTemperature(const uint8_t pin); | ||
~BrakesAndSuspensionTemperature(); | ||
|
||
/** | ||
* @brief | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kNumBrakeAndSuspensionTemperature