Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Temperature Rewrite #150

wants to merge 1 commit into from

Conversation

kshxtij
Copy link
Contributor

@kshxtij kshxtij commented May 5, 2022

#143 rewrite

Adds brakes and suspension temperatures

@kshxtij kshxtij requested a review from mifrandir as a code owner May 5, 2022 11:26
@kshxtij kshxtij requested a review from SnickeyX May 5, 2022 11:26
@kshxtij kshxtij added the sensors label May 5, 2022
@codecov-commenter
Copy link

Codecov Report

Merging #150 (90046b0) into master (516a539) will increase coverage by 0.06%.
The diff coverage is 27.27%.

@@            Coverage Diff             @@
##           master     #150      +/-   ##
==========================================
+ Coverage   38.20%   38.27%   +0.06%     
==========================================
  Files          69       69              
  Lines        3942     3977      +35     
==========================================
+ Hits         1506     1522      +16     
- Misses       2436     2455      +19     
Impacted Files Coverage Δ
src/data/data.hpp 100.00% <ø> (ø)
src/sensors/temperature.hpp 100.00% <ø> (ø)
src/sensors/temperature.cpp 8.33% <7.69%> (-8.34%) ⬇️
src/sensors/main.cpp 35.92% <31.70%> (+2.70%) ⬆️
src/debugging/observer.cpp 32.22% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 516a539...90046b0. Read the comment docs.

Copy link
Member

@mifrandir mifrandir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of things to start with.

// convert to degrees C
double temp = static_cast<double>(raw_value) / 4095;
temp = (temp * 175) - 50;
return static_cast<int8_t>(temp);
Copy link
Member

Choose a reason for hiding this comment

The 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?
Why not the following?

return std::round(static_cast<double>(raw_value) / 23.4  - 50);

Copy link
Member

Choose a reason for hiding this comment

The 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 std::numeric_limits<int8_t>::max() or INT8_MAX.

* @param raw_value input voltage
* @return int representation of temperature
*/
static int8_t scaleData(uint8_t raw_value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const

data::TemperatureData temperature_data_;
};

class BrakesAndSuspensionTemperature : public ITemperature {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should go into a separate file.


void BrakesAndSuspensionTemperature::run()
{
uint16_t raw_value = pin_.read();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const

}

void Temperature::run()
void AmbientTemperature::run()
{
uint16_t raw_value = pin_.read();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const

@@ -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>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BrakeAndSuspension

static constexpr size_t kNumImus = 4;
static constexpr size_t kNumEncoders = 4;
static constexpr size_t kNumBrakePressure = 2;
static constexpr size_t kNumBrakeSuspensionTemp = 4;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kNumBrakeAndSuspensionTemperature

static constexpr size_t kNumEncoders = 4;
static constexpr size_t kNumBrakePressure = 2;
static constexpr size_t kNumBrakeSuspensionTemp = 4;
static constexpr size_t kNumAmbientTemp = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kNumAmbientTemperature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants