Skip to content

Commit

Permalink
Fix k iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
gabekole committed Oct 15, 2024
1 parent a8e6546 commit 48c664d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 2 additions & 0 deletions include/Controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Controller{
Eigen::Matrix<double, 2* MissionConstants::kNumberControllerGains, 8> controller_gains;
double next_tvc_time;
double tvc_start_time;
double k_iteration_start_time;
std::vector<float> controller_gain_times;
// Eigen::Vector2d tvc_angles; [TODO MOVE TO HARDWARE]
int current_iteration_index = 0;
Expand All @@ -40,6 +41,7 @@ class Controller{
void Start(double current_time);
void Center();
void ImportControlParameters(std::string file_name);
void ResetKIteration(double current_time);
Eigen::Matrix<double, 2, 8> GetCurrentKMatrix();

};
2 changes: 1 addition & 1 deletion include/Mode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Mode
Mode::Phase UpdateTestTVC(Navigation& navigation, Controller& controller, double currentTime);
Mode::Phase UpdateIdle(Navigation& navigation, Controller& controller, double currentTime);
Mode::Phase UpdateLaunch(Navigation& navigation, Controller& controller, Igniter& igniter, double current_time);
Mode::Phase UpdateFreefall(Navigation& navigation, Igniter& igniter, double currentTime);
Mode::Phase UpdateFreefall(Navigation& navigation, Controller &controller, Igniter& igniter, double currentTime);
Mode::Phase UpdateLand(Navigation& navigation, Controller& controller, double current_time);
Mode::Phase UpdateSafeMode(Navigation& navigation, Controller& controller, double currentTime);
};
10 changes: 7 additions & 3 deletions src/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ void Controller::Start(double current_time){

tvc_start_time = current_time;
next_tvc_time = current_time;
ResetKIteration(current_time); // Sets iteration start time
}


Expand Down Expand Up @@ -122,8 +123,8 @@ void Controller::UpdateSafe(){
void Controller::GetNextController_Gain_Time_Index(double current_time){
// Determine if a certain amount of time has passed, and if so, then increase the current_iteration_index and get the next K value

double switch_time = (controller_gain_times[current_iteration_index+1] - controller_gain_times[current_iteration_index]) / 2.0;
if(current_time - tvc_start_time > switch_time)
double switch_time = (controller_gain_times[current_iteration_index+1] + controller_gain_times[current_iteration_index]) / 2.0;
if(current_time - k_iteration_start_time > switch_time)
{
current_iteration_index++;
}
Expand Down Expand Up @@ -173,11 +174,14 @@ void Controller::ImportControlParameters(std::string file_name){
controller_gains(i, j) = stod(item);
}
}


in.close();
}

void Controller::ResetKIteration(double current_time){
k_iteration_start_time = current_time;
}

Eigen::Matrix<double, 2, 8> Controller::GetCurrentKMatrix()
{
return controller_gains.block(current_iteration_index*2, 0, 2, 8);
Expand Down
5 changes: 3 additions & 2 deletions src/Mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Mode::Phase Mode::UpdateLaunch(Navigation& navigation, Controller& controller, I
}
}

Mode::Phase Mode::UpdateFreefall(Navigation& navigation, Igniter& igniter, double currentTime) {
Mode::Phase Mode::UpdateFreefall(Navigation& navigation, Controller &controller, Igniter& igniter, double currentTime) {

// Continue to update navigation
navigation.UpdateNavigation();
Expand All @@ -198,6 +198,7 @@ Mode::Phase Mode::UpdateFreefall(Navigation& navigation, Igniter& igniter, doubl
if (time_till_second_ignite < 0){
igniter.Ignite(Igniter::IgnitionSpecifier::LAND);
std::cout<< "Switching from Freefall to Land" << "\n";
controller.ResetKIteration(currentTime);
return Mode::Land;
}

Expand Down Expand Up @@ -272,7 +273,7 @@ bool Mode::Update(Navigation& navigation, Controller& controller, Igniter& ignit
break;
case Freefall:
Telemetry::GetInstance().RunTelemetry(navigation, controller, 0.01, 0.08);
this->eCurrentMode = UpdateFreefall(navigation, igniter, currentTime);
this->eCurrentMode = UpdateFreefall(navigation, controller, igniter, currentTime);
break;
case Land:
Telemetry::GetInstance().RunTelemetry(navigation, controller, 0.01, 0.08);
Expand Down

0 comments on commit 48c664d

Please sign in to comment.