Skip to content

Commit

Permalink
Steering Angle Logic (#290)
Browse files Browse the repository at this point in the history
* created steering angle function

* fixed typo, removed unneeded import, and removed comment
  • Loading branch information
jabrap1 authored Nov 5, 2024
1 parent 790ce02 commit b4eeab0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
16 changes: 16 additions & 0 deletions firmware/shared/controls/steering_angle.h
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
34 changes: 34 additions & 0 deletions firmware/shared/controls/steering_angle_test.cc
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;
}

0 comments on commit b4eeab0

Please sign in to comment.