diff --git a/dfall_ws/src/dfall_pkg/src/nodes/CsoneControllerService.cpp b/dfall_ws/src/dfall_pkg/src/nodes/CsoneControllerService.cpp index 9de709b0cbfc8cb04a09dc3f7339587d582173e0..7a39c37ab2bbd2074b5fcbfe2b09fc7a693acd7b 100644 --- a/dfall_ws/src/dfall_pkg/src/nodes/CsoneControllerService.cpp +++ b/dfall_ws/src/dfall_pkg/src/nodes/CsoneControllerService.cpp @@ -186,12 +186,6 @@ bool calculateControlOutput(Controller::Request &request, Controller::Response & static int write_index = 0; static int read_index = 0; - // Write the new data to the buffer - m_x_inertial_buffer[write_index] = request.ownCrazyflie.x; - - // Read the data for this time step from the buffer - float inertial_x_for_this_time_step = m_x_inertial_buffer[read_index]; - // Increment the write index write_index += 1; // And wrap it back into range if necessary @@ -208,6 +202,11 @@ bool calculateControlOutput(Controller::Request &request, Controller::Response & read_index += m_x_inertial_buffer.size(); } + // Write the new data to the buffer + m_x_inertial_buffer[write_index] = request.ownCrazyflie.x; + + // Read the data for this time step from the buffer + float inertial_x_for_this_time_step = m_x_inertial_buffer[read_index]; // Define a local array to fill in with the state error