-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved read brake and throttle into other file
- Loading branch information
1 parent
20758d9
commit 34a5d20
Showing
5 changed files
with
56 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
#include <mbed.h> | ||
#include <rtos.h> | ||
|
||
extern AnalogIn throttle_pedal; | ||
extern AnalogIn brake_pedal; |
This file contains 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,8 +1,9 @@ | ||
add_library(PowerBoard-lib | ||
src/PowerCANInterface.cpp | ||
src/MotorInterface.cpp | ||
src/ReadFiles.cpp | ||
) | ||
|
||
target_include_directories(PowerBoard-lib PUBLIC include) | ||
|
||
target_link_libraries(PowerBoard-lib mbed-os-lib Common-lib) | ||
target_link_libraries(PowerBoard-lib mbed-os-lib Common-lib) |
This file contains 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,5 @@ | ||
#include <mbed.h> | ||
#include <rtos.h> | ||
|
||
uint16_t read_throttle(); | ||
uint16_t read_brake(); |
This file contains 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,42 @@ | ||
#include <mbed.h> | ||
#include <rtos.h> | ||
#include "main.h" | ||
|
||
#define THROTTLE_LOW_VOLTAGE 0.66 | ||
#define THROTTLE_LOW_VOLTAGE_BUFFER 0.20 | ||
#define THROTTLE_HIGH_VOLTAGE 3.08 | ||
#define THROTTLE_HIGH_VOLTAGE_BUFFER 0.10 | ||
|
||
|
||
|
||
// Reads the throttle pedal value and returns a uint16_t | ||
uint16_t read_throttle() { | ||
float adjusted_throttle_input = | ||
((throttle_pedal.read_voltage() - THROTTLE_LOW_VOLTAGE - | ||
THROTTLE_LOW_VOLTAGE_BUFFER) / | ||
(THROTTLE_HIGH_VOLTAGE - THROTTLE_HIGH_VOLTAGE_BUFFER - | ||
THROTTLE_LOW_VOLTAGE - THROTTLE_LOW_VOLTAGE_BUFFER)); | ||
if (adjusted_throttle_input <= 0.0f) { | ||
return 0; | ||
} else if (adjusted_throttle_input >= 1.0f) { | ||
return 256; | ||
} else { | ||
return (uint16_t)(adjusted_throttle_input * 256.0); | ||
} | ||
} | ||
|
||
// Reads the brake pedal value and returns a uint16_t | ||
uint16_t read_brake() { | ||
float adjusted_brake_input = | ||
((brake_pedal.read_voltage() - THROTTLE_LOW_VOLTAGE - | ||
THROTTLE_LOW_VOLTAGE_BUFFER) / | ||
(THROTTLE_HIGH_VOLTAGE - THROTTLE_HIGH_VOLTAGE_BUFFER - | ||
THROTTLE_LOW_VOLTAGE - THROTTLE_LOW_VOLTAGE_BUFFER)); | ||
if (adjusted_brake_input <= 0.0f) { | ||
return 0; | ||
} else if (adjusted_brake_input >= 1.0f) { | ||
return 256; | ||
} else { | ||
return (uint16_t)(adjusted_brake_input * 256.0); | ||
} | ||
} |
This file contains 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