-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* created steering angle function * fixed typo, removed unneeded import, and removed comment
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 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,16 @@ | ||
#pragma once | ||
|
||
// Peter Jabra | ||
|
||
namespace ctrl { | ||
|
||
template <typename T> | ||
T CalculateSteeringAngle(bool steering_error, T steering_angle) { | ||
if (steering_error) { | ||
return static_cast<T>(0.5); | ||
} else { | ||
return steering_angle; | ||
} | ||
} | ||
|
||
} // namespace ctrl |
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,34 @@ | ||
#include "steering_angle.h" | ||
|
||
#include <iostream> | ||
|
||
#include "testing.h" | ||
|
||
int main() { | ||
using namespace ctrl; | ||
|
||
// Test case 1: No error expected | ||
ASSERT_CLOSE(CalculateSteeringAngle(false, 0.8), 0.8); | ||
|
||
// Test case 2: No error expected | ||
ASSERT_CLOSE(CalculateSteeringAngle(false, 1.0), 1.0); | ||
|
||
// Test case 3: No error expected | ||
ASSERT_CLOSE(CalculateSteeringAngle(false, 0.0), 0.0); | ||
|
||
// Test case 4: No error expected | ||
ASSERT_CLOSE(CalculateSteeringAngle(false, 0.5), 0.5); | ||
|
||
// Test case 5: Error, steering angle should be reset to 0.5 | ||
ASSERT_CLOSE(CalculateSteeringAngle(true, 0.8), 0.5); | ||
|
||
// Test case 6: Error, steering angle should be reset to 0.5 | ||
ASSERT_CLOSE(CalculateSteeringAngle(true, 0.2), 0.5); | ||
|
||
// Test case 7: Error, steering angle should be reset to 0.5 | ||
ASSERT_CLOSE(CalculateSteeringAngle(true, 0.5), 0.5); | ||
|
||
std::cout << "All test cases passed!" << std::endl; | ||
|
||
return 0; | ||
} |