generated from RIT-EVT/project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
[FWT-20] Out of the CR(H)IB and into the fire #3
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
Open
Ethan-Caracoglia
wants to merge
50
commits into
main
Choose a base branch
from
ErrorCheckingAndPosition
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 22 commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
84ff3b9
Added new git branch
Ethan-Caracoglia 213a367
Checking if commits work
Ethan-Caracoglia 363a9c8
Ready for testing
Ethan-Caracoglia e2d66d2
Ready for CAN, just need it to be implemented on f4
Ethan-Caracoglia d115e6b
Ready for CAN, just need it to be implemented on f4
Ethan-Caracoglia a85fdce
added vs folder
Ethan-Caracoglia cc93622
Saving work with the brake until we are ready to implement it
Ethan-Caracoglia 545394c
Should probably work now :)
Ethan-Caracoglia f070a6f
Working on fixes for the payload transference
Ethan-Caracoglia a9c7932
Need to change HIB for new ADCs
Ethan-Caracoglia f05b0e1
Getting things up to date
Ethan-Caracoglia 1cd87cb
Hopefully this works
Ethan-Caracoglia e7d3808
ADS8689IPWR driver created, needs to be tested and verified
Ethan-Caracoglia bb1e415
Merge remote-tracking branch 'origin/ErrorCheckingAndPosition' into E…
Ethan-Caracoglia 9782656
This is broken but I need to move the code
Ethan-Caracoglia e6f7b45
Almost done changing margin errors to a static voltage difference
Ethan-Caracoglia 40714d9
Hopefully a fully function driver with a few interface pins missing
Ethan-Caracoglia 464b4ea
CAN it do it? Yes it CAN!
Ethan-Caracoglia f4d830b
It CAN now go even faster
Ethan-Caracoglia d03b6fe
Attempted to fix the read issue on the ADCs
Ethan-Caracoglia 404a142
Really not sure how to fix this issue
Ethan-Caracoglia 122c140
I tried to prevent int overflow but that did not solve the problem
Ethan-Caracoglia 4ab2d07
Beginning to change statements to logger
Ethan-Caracoglia 00411da
Update for Oleg
Ethan-Caracoglia b0cdaa7
Altered Clang-Format path in the cmake file
Ethan-Caracoglia 61d82a6
Altered Clang-Format path in the cmake file
Ethan-Caracoglia 9b0b110
Apply suggestions from code review
Ethan-Caracoglia 127cef7
Saving progress on dependecy refactor
Ethan-Caracoglia 436f26c
Refactored a good deal of the code and altered the dependencies so no…
Ethan-Caracoglia c9adcbe
Fixed the macro and include errors for size_t
Ethan-Caracoglia eeecdf7
Attempting to fix build error by only building f446
Ethan-Caracoglia 8233985
Changed the EVT-core branch back to main
Ethan-Caracoglia 6ca79d4
Took main() out of hib namespace to avoid missing main reference
Ethan-Caracoglia 904e7ab
Sorrowful attempt to fix IWDG compilation error
Ethan-Caracoglia 12477c9
Sorrowful attempt to fix IWDG and timer compilation error
Ethan-Caracoglia 80af261
Errasign timer sample
Ethan-Caracoglia a8be383
Fully erasing timer
Ethan-Caracoglia e793e35
Trying to get the build to work by converting the build back to norma…
Ethan-Caracoglia 546606c
Reverting last change
Ethan-Caracoglia 346257a
Chained EVT-core target
Ethan-Caracoglia 416220c
Merge remote-tracking branch 'origin/ErrorCheckingAndPosition' into E…
Ethan-Caracoglia 3121aa5
Updated github workflow and main to read out can connect result
Ethan-Caracoglia 67a4416
Removed all samples to fix compile errors
Ethan-Caracoglia c8d49dd
Fixed namespace errors faulting on main()
Ethan-Caracoglia e3b4f32
Messed around with clang-format issue
Ethan-Caracoglia f407ffb
Applied Formatting Changes During GitHub Build
cc5b0a5
Ready to push (I am aware that the GPIO checking for the various Star…
Ethan-Caracoglia f4d4296
Applied Formatting Changes During GitHub Build
79d6375
Added Brake error information to the UART logging section just in cas…
Ethan-Caracoglia 5f2d57d
Merge remote-tracking branch 'origin/ErrorCheckingAndPosition' into E…
Ethan-Caracoglia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,66 @@ | ||
| #pragma once | ||
Ethan-Caracoglia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #include <core/io/UART.hpp> | ||
| #include <dev/ADS8689IPWR.hpp> | ||
Ethan-Caracoglia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #include <dev/RedundantADC.hpp> | ||
| #include <sys/types.h> | ||
|
|
||
| namespace HIB { | ||
|
|
||
| /** | ||
| * Counts that when exceeded throw an error to the VC | ||
Ethan-Caracoglia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| #define COMPARISON_ERROR_COUNT 1 | ||
| #define PRECISION_MARGIN_ERROR_COUNT 3 | ||
| #define ACCEPTABLE_MARGIN_ERROR_COUNT 5 | ||
|
|
||
| constexpr size_t payloadLength = 5; | ||
|
|
||
| /** | ||
| * HIB header file | ||
Ethan-Caracoglia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| class HIB { | ||
| public: | ||
| HIB(DEV::RedundantADC& throttle, DEV::RedundantADC& brake); | ||
|
|
||
| void process(); | ||
|
|
||
| uint8_t payload[payloadLength]; | ||
| uint32_t throttleVoltage = 0; | ||
| uint32_t brakeVoltage = 0; | ||
|
|
||
| // Counters for throttle errors | ||
| uint64_t acceptableThrottleMarginErrors = 0; | ||
| uint64_t precisionThrottleMarginErrors = 0; | ||
| uint64_t comparisonThrottleErrors = 0; | ||
|
|
||
| // Counters for brake errors | ||
| uint64_t acceptableBrakeMarginErrors = 0; | ||
| uint64_t precisionBrakeMarginErrors = 0; | ||
| uint64_t comparisonBrakeErrors = 0; | ||
Ethan-Caracoglia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| private: | ||
| void readThrottleVoltage(); | ||
|
|
||
| void readBrakeVoltage(); | ||
|
|
||
| DEV::RedundantADC& throttle; | ||
| DEV::RedundantADC& brake; | ||
|
|
||
| /** | ||
| * Payload for CAN transmission. | ||
| * Byte 0: MSB for Throttle Voltage | ||
| * Byte 1: LSB for Throttle Voltage | ||
| * Byte 2: MSB for Brake Voltage | ||
| * Byte 3: LSB for Brake Voltage | ||
| * Byte 4: Error Byte for triggering a shutdown | ||
| * Byte 4 layout: X X X X X X X X | ||
| * 7 6 5 4 3 2 1 0 | ||
| * ^ ^ | ||
| * | \ | ||
| * ________________/ \__________________ | ||
| * Brake Error Bit Throttle Error Bit | ||
| */ | ||
| uint8_t data[payloadLength]; | ||
Ethan-Caracoglia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| }// namespace HIB | ||
Ethan-Caracoglia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #pragma once | ||
|
|
||
| #include <core/io/GPIO.hpp> | ||
| #include <core/io/SPI.hpp> | ||
|
|
||
| #define RANGE_SEL_REG 0x14 // R/W Range selection register ---- | ||
| #define TWELVE_VOLT_SCALER 0b1000 | ||
Ethan-Caracoglia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #define HALF_WORD_WRITE 0b11010000 | ||
| #define EMPTY_BYTE 0b00000000 | ||
| #define NOP {EMPTY_BYTE, EMPTY_BYTE, EMPTY_BYTE, EMPTY_BYTE} | ||
| #define VOLTAGE_MAX 12288 | ||
|
|
||
| namespace io = core::io; | ||
|
|
||
| namespace HIB::DEV { | ||
|
|
||
| class ADS8689IPWR { | ||
Ethan-Caracoglia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public: | ||
| /** | ||
| * Creates a ADS8689IPWR object while configuring the range selector. | ||
| * | ||
| * @param spi SPI reference to interface with the ADC | ||
| * @param deviceNumber The number of the cs pin that the device is | ||
| */ | ||
| ADS8689IPWR(io::SPI& spi, uint8_t deviceNumber); | ||
|
|
||
| /** | ||
| * Reads out the voltage from the ADC with a blank command through SPI | ||
| * | ||
| * @param voltage reference to variable that is storing voltage | ||
| * @return the status of whether the transaction was successful | ||
|
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. it doesn't return this. It seems to return the voltage. Should be modified to return the SPIStatus and take a pointer to write the voltage. |
||
| */ | ||
| uint16_t read() const; | ||
| private: | ||
| io::SPI& spi; | ||
| const uint8_t deviceNumber; | ||
| }; | ||
|
|
||
| }// namespace HIB::DEV | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,98 @@ | ||
| #include <HIB.hpp> | ||
| #include <dev/RedundantADC.hpp> | ||
|
|
||
| namespace HIB { | ||
|
|
||
| }// namespace HIB | ||
| HIB::HIB(DEV::RedundantADC& throttle, DEV::RedundantADC& brake) | ||
| : throttle(throttle), brake(brake) { | ||
| // Initialize payload to 0's | ||
| for (uint8_t i = 0; i < payloadLength; i++) { | ||
| payload[i] = 0; | ||
| } | ||
| } | ||
|
|
||
| // Reads the 2 sets of 3 ADCs and processes their errors while packaging them for CAN | ||
| void HIB::process() { | ||
| // Read in the voltages from the throttle | ||
| readThrottleVoltage(); | ||
| readBrakeVoltage(); | ||
|
|
||
| if (throttleVoltage < 300) { | ||
| throttleVoltage = 0; | ||
| } | ||
|
|
||
| if (brakeVoltage < 300) { | ||
| brakeVoltage = 0; | ||
| } | ||
|
|
||
| payload[0] = static_cast<uint8_t>(throttleVoltage >> 8 & 0xFF); | ||
| payload[1] = static_cast<uint8_t>(throttleVoltage & 0xFF); | ||
| payload[2] = static_cast<uint8_t>(brakeVoltage >> 8 & 0xFF); | ||
| payload[3] = static_cast<uint8_t>(brakeVoltage & 0xFF); | ||
Ethan-Caracoglia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if (acceptableThrottleMarginErrors > ACCEPTABLE_MARGIN_ERROR_COUNT) { | ||
| acceptableThrottleMarginErrors = ACCEPTABLE_MARGIN_ERROR_COUNT + 1; | ||
| payload[4] |= 0b01; | ||
| } | ||
|
|
||
| if (acceptableBrakeMarginErrors > ACCEPTABLE_MARGIN_ERROR_COUNT) { | ||
| acceptableBrakeMarginErrors = ACCEPTABLE_MARGIN_ERROR_COUNT + 1; | ||
| payload[4] |= 0b10; | ||
| } | ||
|
|
||
| if (precisionThrottleMarginErrors > PRECISION_MARGIN_ERROR_COUNT) { | ||
| precisionThrottleMarginErrors = PRECISION_MARGIN_ERROR_COUNT + 1; | ||
| payload[4] |= 0b01; | ||
| } | ||
|
|
||
| if (precisionBrakeMarginErrors > PRECISION_MARGIN_ERROR_COUNT) { | ||
| precisionBrakeMarginErrors = PRECISION_MARGIN_ERROR_COUNT + 1; | ||
| payload[4] |= 0b10; | ||
| } | ||
|
|
||
| if (comparisonThrottleErrors > COMPARISON_ERROR_COUNT) { | ||
| comparisonThrottleErrors = COMPARISON_ERROR_COUNT + 1; | ||
| payload[4] |= 0b01; | ||
| } | ||
|
|
||
| if (comparisonBrakeErrors > COMPARISON_ERROR_COUNT) { | ||
| comparisonBrakeErrors = COMPARISON_ERROR_COUNT + 1; | ||
| payload[4] |= 0b10; | ||
Ethan-Caracoglia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| void HIB::readThrottleVoltage() { | ||
| const DEV::RedundantADC::Status status = throttle.read(throttleVoltage); // gets the errors and voltage from the ADC cluster | ||
|
|
||
| // Increment the status of each error if it is received | ||
| if (status == DEV::RedundantADC::Status::ACCEPTABLE_MARGIN_EXCEEDED) { | ||
| acceptableThrottleMarginErrors++; | ||
| } | ||
|
|
||
| if (status == DEV::RedundantADC::Status::PRECISION_MARGIN_EXCEEDED) { | ||
| precisionThrottleMarginErrors++; | ||
| } | ||
|
|
||
| if (status == DEV::RedundantADC::Status::COMPARISON_ERROR) { | ||
| comparisonThrottleErrors++; | ||
| } | ||
| } | ||
|
|
||
| void HIB::readBrakeVoltage() { | ||
| const DEV::RedundantADC::Status status = brake.read(brakeVoltage); // gets the errors and voltage from the ADC cluster | ||
|
|
||
| // Increment the status of each error if it is received | ||
| if (status == DEV::RedundantADC::Status::ACCEPTABLE_MARGIN_EXCEEDED) { | ||
| acceptableBrakeMarginErrors++; | ||
| } | ||
|
|
||
| if (status == DEV::RedundantADC::Status::PRECISION_MARGIN_EXCEEDED) { | ||
| precisionBrakeMarginErrors++; | ||
| } | ||
|
|
||
| if (status == DEV::RedundantADC::Status::COMPARISON_ERROR) { | ||
| comparisonBrakeErrors++; | ||
| } | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #include <core/utils/log.hpp> | ||
| #include <dev/ADS8689IPWR.hpp> | ||
|
|
||
| namespace HIB::DEV { | ||
|
|
||
| ADS8689IPWR::ADS8689IPWR(io::SPI& spi, const uint8_t deviceNumber) : spi(spi), deviceNumber(deviceNumber) { | ||
| uint8_t message[4] = {HALF_WORD_WRITE, RANGE_SEL_REG, EMPTY_BYTE, TWELVE_VOLT_SCALER}; | ||
| spi.startTransmission(deviceNumber); | ||
| spi.write(message, 4); | ||
| spi.endTransmission(deviceNumber); | ||
|
|
||
| // Begin the conversion with a NOP command | ||
| uint8_t nop[4] = NOP; | ||
| spi.startTransmission(deviceNumber); | ||
| spi.write(nop, 4); | ||
| spi.endTransmission(deviceNumber); | ||
| } | ||
|
|
||
| uint16_t ADS8689IPWR::read() const { | ||
| uint8_t bytes[4]; | ||
| spi.startTransmission(deviceNumber); | ||
| spi.read(bytes, 4); | ||
Ethan-Caracoglia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| spi.endTransmission(deviceNumber); | ||
|
|
||
| // First byte is MSB | ||
| uint32_t voltage = (bytes[0] << 8) + bytes[1]; | ||
|
|
||
| // Normalize the received info (divide by uint16_t(MAX)) and scale accordingly | ||
| voltage = voltage * VOLTAGE_MAX / UINT16_MAX; | ||
| return voltage; | ||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.