-
Notifications
You must be signed in to change notification settings - Fork 48
Path manager restructure #157
base: pathManRestructure
Are you sure you want to change the base?
Changes from all commits
4002217
c11919f
b382551
9a3d1d4
cdc1139
500d287
b560747
093f631
81f0545
34a4d9a
9c3f7a4
5c18a1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,14 +17,28 @@ _CruisingState_Telemetry_Return CruisingFlight::_return_to_ground; | |
void CruisingFlight::execute(CruisingMode* cruise_mode) { | ||
Telemetry_PIGO_t telem_data = cruise_mode->getTelemetryData(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all this will now be from the jetson instead of the plane. When FW-CV Comms gets merged into devel, you will have to re-adapt this restructure |
||
SFOutput_t sf_data = cruise_mode->getSensorFusionData(); | ||
|
||
|
||
// Set waypoint manager input struct | ||
_input_data.track = sf_data.track; // Gets track | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where is _input_data defined? |
||
_input_data.longitude = sf_data.longitude; | ||
_input_data.latitude = sf_data.latitude; | ||
_input_data.altitude = sf_data.altitude; | ||
|
||
_ModifyFlightPathErrorCode edit_error = editFlightPath(&telem_data, cruising_state_manager, waypoint_id_array); // Edit flight path if applicable | ||
|
||
Telemetry_PIGO_t instr; | ||
_ModifyFlightPathErrorCode edit_error = MODIFY_CRUISING_SUCCESS; // Initialize to success, else if the instruction queue is empty, edit_error would not be initialized | ||
//Go over all instructions on the instruction queue | ||
while (!cruise_mode->getModeSelector()->flightPathEditInstructionsIsEmpty()) { | ||
instr = cruise_mode->getModeSelector()->dequeueflightPathEditInstructions(); | ||
|
||
edit_error = editFlightPath(&instr, cruising_state_manager, waypoint_id_array); // Edit flight path if applicable | ||
|
||
if (edit_error != MODIFY_CRUISING_SUCCESS) { //There has been an error, get out of the loop and handle the error first | ||
break; | ||
} | ||
} | ||
|
||
_GetNextDirectionsErrorCode path_error = pathFollow(&telem_data, cruising_state_manager, _input_data, &_output_data, going_home, in_hold); // Get next direction or modify flight behaviour pattern | ||
setReturnValues(&_return_to_ground, cruising_state_manager, edit_error, path_error); // Set error codes | ||
|
||
|
@@ -51,7 +65,7 @@ void CruisingFlight::execute(CruisingMode* cruise_mode) { | |
passby_control.throttlePassby = false; | ||
|
||
cruise_mode->getModeSelector()->setCoordinatedTurnInput(coord_turn_input); | ||
cruise_mode->getModeSelector()->setAltitdeAirspeedInput(alt_airspeed_input); | ||
cruise_mode->getModeSelector()->setAltitudeAirspeedInput(alt_airspeed_input); | ||
cruise_mode->getModeSelector()->setPassbyControl(passby_control); | ||
|
||
// Set output data to be sent back to PM commsWithTelemetry state | ||
|
@@ -75,4 +89,3 @@ CruisingModeStageManager& CruisingFlight::getInstance() { | |
static CruisingFlight singleton; | ||
return singleton; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,21 +15,85 @@ PathModeSelector* PathModeSelector::getInstance() { | |
|
||
PathModeSelector::PathModeSelector() : current_mode_enum {MODE_TESTING_NONE} { | ||
current_mode = nullptr; | ||
first_flight_path_edit_instr = nullptr; | ||
} | ||
|
||
#else | ||
|
||
PathModeSelector::PathModeSelector() : current_mode_enum {MODE_TAKEOFF} { | ||
current_mode = &TakeoffMode::getInstance(); | ||
first_flight_path_edit_instr = nullptr; | ||
} | ||
|
||
#endif | ||
|
||
void PathModeSelector::execute(Telemetry_PIGO_t telemetry_in, SFOutput_t sensor_fusion_in, IMU_Data_t imu_data_in) { | ||
|
||
// Check whether the telemetry_in has an editflightPath command. If so, we enqueue it into our InstructionQueue | ||
if (telemetry_in.waypointModifyFlightPathCommand != NO_FLIGHT_PATH_EDIT) { | ||
enqueueFlightPathEditInstructions(telemetry_in); | ||
} | ||
|
||
current_mode->execute(telemetry_in, sensor_fusion_in, imu_data_in); | ||
} | ||
|
||
void PathModeSelector::setAltitdeAirspeedInput(AltitudeAirspeedInput_t alt_airspeed_input) { | ||
bool PathModeSelector::flightPathEditInstructionsIsEmpty() { | ||
if (first_flight_path_edit_instr == nullptr) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
int PathModeSelector::checkflightPathEditInstructionsLength() { | ||
int count = 0; | ||
if (flightPathEditInstructionsIsEmpty()) { | ||
return count; | ||
} else { | ||
flightPathEditInstructionNode* latestInstruction = first_flight_path_edit_instr; | ||
|
||
while (latestInstruction != nullptr) { | ||
latestInstruction = latestInstruction->nextInstruction; | ||
count += 1; | ||
}; | ||
return count; | ||
} | ||
|
||
} | ||
|
||
Telemetry_PIGO_t PathModeSelector::dequeueflightPathEditInstructions() { | ||
// Assumes that Queue is non empty. | ||
flightPathEditInstructionNode* old_first_instruction = first_flight_path_edit_instr; | ||
Telemetry_PIGO_t instruction = old_first_instruction->instruction; | ||
// old_first_instruction->nextInstruction = nullptr; | ||
first_flight_path_edit_instr = first_flight_path_edit_instr->nextInstruction; //Update the head of the queue | ||
delete old_first_instruction; //Delete the old node | ||
return instruction; | ||
}; | ||
|
||
void PathModeSelector::enqueueFlightPathEditInstructions(Telemetry_PIGO_t newInstruction) { | ||
if (flightPathEditInstructionsIsEmpty()) { //If our Queue is empty (i.e. there are no editflightpath instructions), make it the first | ||
first_flight_path_edit_instr = new flightPathEditInstructionNode{}; | ||
first_flight_path_edit_instr->instruction = newInstruction; | ||
first_flight_path_edit_instr->nextInstruction = nullptr; | ||
} else { | ||
flightPathEditInstructionNode* latestInstruction = first_flight_path_edit_instr; | ||
|
||
while (latestInstruction->nextInstruction != nullptr) { | ||
latestInstruction = latestInstruction->nextInstruction; | ||
}; | ||
|
||
// Create new instructionQueueNode | ||
flightPathEditInstructionNode* newInstructionQueueNode = new flightPathEditInstructionNode{}; | ||
newInstructionQueueNode->instruction = newInstruction; | ||
newInstructionQueueNode->nextInstruction = nullptr; | ||
|
||
// Add new instructionQueueNode to the entire queue | ||
latestInstruction->nextInstruction = newInstructionQueueNode; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good. We should write two unit tests for this when the time comes tho :) Question: What do you think the tests should cover? |
||
} | ||
}; | ||
|
||
void PathModeSelector::setAltitudeAirspeedInput(AltitudeAirspeedInput_t alt_airspeed_input) { | ||
memcpy(&altitude_airspeed_input, &alt_airspeed_input, sizeof(AltitudeAirspeedInput_t)); | ||
} | ||
|
||
|
@@ -40,4 +104,3 @@ void PathModeSelector::setCoordinatedTurnInput(CoordinatedTurnInput_t coord_turn | |
void PathModeSelector::setPassbyControl(_PassbyControl passby) { | ||
memcpy(&passby_control_output, &passby, sizeof(_PassbyControl)); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,13 +111,14 @@ void modeExecutor::execute(pathManager* pathMgr) | |
mode_selector->setCurrentMode(CruisingMode::getInstance()); | ||
} | ||
|
||
Telemetry_PIGO_t telem_data; | ||
Telemetry_PIGO_t telem_data {}; | ||
|
||
// These were added to ensure CruisingMode_Fsm tests pass. | ||
// TODO: Ensure CruisingMode tests don't depend on this so we can delete this garbage | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just commenting this TODO to keep it visible |
||
telem_data.waypoints[0] = createTelemetryWaypoint(0.0, 0.0, 6, 0.0, 0); | ||
telem_data.waypoints[1] = createTelemetryWaypoint(0.0, 0.0, 7, 0.0, 0); | ||
telem_data.waypoints[2] = createTelemetryWaypoint(0.0, 0.0, 8, 0.0, 0); | ||
telem_data.waypoints[3] = createTelemetryWaypoint(0.0, 0.0, 9, 0.0, 0); | ||
|
||
telem_data.numWaypoints = 4; | ||
telem_data.waypointModifyFlightPathCommand = INITIALIZE_FLIGHT_PATH; | ||
telem_data.initializingHomeBase = 1; | ||
|
@@ -220,5 +221,3 @@ pathManagerState& fatalFailureMode::getInstance() | |
static fatalFailureMode singleton; | ||
return singleton; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Later on we'll have to change this to account for the states more relevant to multicopters (hover, no taxiing, etc.). Do you think its easily changeable for that once its implemented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think that makes more sense to sit in my PR for landing and takeoff