Skip to content

Commit

Permalink
example: fix after ActionResult -> Action::Result
Browse files Browse the repository at this point in the history
  • Loading branch information
julianoes committed Aug 26, 2018
1 parent d0252e9 commit 3763cd4
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 56 deletions.
17 changes: 9 additions & 8 deletions example/fly_mission/fly_mission.cpp
Expand Up @@ -32,7 +32,7 @@ using namespace std::chrono; // for seconds(), milliseconds()
using namespace std::this_thread; // for sleep_for()

// Handles Action's result
inline void handle_action_err_exit(ActionResult result, const std::string &message);
inline void handle_action_err_exit(Action::Result result, const std::string &message);
// Handles Mission's result
inline void handle_mission_err_exit(Mission::Result result, const std::string &message);
// Handles Connection result
Expand Down Expand Up @@ -189,7 +189,7 @@ int main(int argc, char **argv)
}

std::cout << "Arming..." << std::endl;
const ActionResult arm_result = action->arm();
const Action::Result arm_result = action->arm();
handle_action_err_exit(arm_result, "Arm failed: ");
std::cout << "Armed." << std::endl;

Expand Down Expand Up @@ -265,9 +265,10 @@ int main(int argc, char **argv)
{
// We are done, and can do RTL to go home.
std::cout << "Commanding RTL..." << std::endl;
const ActionResult result = action->return_to_launch();
if (result != ActionResult::SUCCESS) {
std::cout << "Failed to command RTL (" << action_result_str(result) << ")" << std::endl;
const Action::Result result = action->return_to_launch();
if (result != Action::Result::SUCCESS) {
std::cout << "Failed to command RTL (" << Action::result_str(result) << ")"
<< std::endl;
} else {
std::cout << "Commanded RTL." << std::endl;
}
Expand Down Expand Up @@ -302,10 +303,10 @@ std::shared_ptr<MissionItem> make_mission_item(double latitude_deg,
return new_item;
}

inline void handle_action_err_exit(ActionResult result, const std::string &message)
inline void handle_action_err_exit(Action::Result result, const std::string &message)
{
if (result != ActionResult::SUCCESS) {
std::cerr << ERROR_CONSOLE_TEXT << message << action_result_str(result)
if (result != Action::Result::SUCCESS) {
std::cerr << ERROR_CONSOLE_TEXT << message << Action::result_str(result)
<< NORMAL_CONSOLE_TEXT << std::endl;
exit(EXIT_FAILURE);
}
Expand Down
17 changes: 9 additions & 8 deletions example/fly_qgc_mission/fly_qgc_mission.cpp
Expand Up @@ -42,7 +42,7 @@ using namespace std::chrono; // for seconds(), milliseconds()
using namespace std::this_thread; // for sleep_for()

// Handles Action's result
inline void handle_action_err_exit(ActionResult result, const std::string &message);
inline void handle_action_err_exit(Action::Result result, const std::string &message);
// Handles Mission's result
inline void handle_mission_err_exit(Mission::Result result, const std::string &message);
// Handles Connection result
Expand Down Expand Up @@ -144,7 +144,7 @@ int main(int argc, char **argv)
}

std::cout << "Arming..." << std::endl;
const ActionResult arm_result = action->arm();
const Action::Result arm_result = action->arm();
handle_action_err_exit(arm_result, "Arm failed: ");
std::cout << "Armed." << std::endl;

Expand Down Expand Up @@ -176,9 +176,10 @@ int main(int argc, char **argv)
{
// Mission complete. Command RTL to go home.
std::cout << "Commanding RTL..." << std::endl;
const ActionResult result = action->return_to_launch();
if (result != ActionResult::SUCCESS) {
std::cout << "Failed to command RTL (" << action_result_str(result) << ")" << std::endl;
const Action::Result result = action->return_to_launch();
if (result != Action::Result::SUCCESS) {
std::cout << "Failed to command RTL (" << Action::result_str(result) << ")"
<< std::endl;
} else {
std::cout << "Commanded RTL." << std::endl;
}
Expand All @@ -187,10 +188,10 @@ int main(int argc, char **argv)
return 0;
}

inline void handle_action_err_exit(ActionResult result, const std::string &message)
inline void handle_action_err_exit(Action::Result result, const std::string &message)
{
if (result != ActionResult::SUCCESS) {
std::cerr << ERROR_CONSOLE_TEXT << message << action_result_str(result)
if (result != Action::Result::SUCCESS) {
std::cerr << ERROR_CONSOLE_TEXT << message << Action::result_str(result)
<< NORMAL_CONSOLE_TEXT << std::endl;
exit(EXIT_FAILURE);
}
Expand Down
14 changes: 7 additions & 7 deletions example/follow_me/follow_me.cpp
Expand Up @@ -31,7 +31,7 @@ using namespace std::this_thread; // for sleep_for()
#define TELEMETRY_CONSOLE_TEXT "\033[34m" // Turn text on console blue
#define NORMAL_CONSOLE_TEXT "\033[0m" // Restore normal console colour

inline void action_error_exit(ActionResult result, const std::string &message);
inline void action_error_exit(Action::Result result, const std::string &message);
inline void follow_me_error_exit(FollowMe::Result result, const std::string &message);
inline void connection_error_exit(ConnectionResult result, const std::string &message);

Expand Down Expand Up @@ -85,7 +85,7 @@ int main(int argc, char **argv)
std::cout << "System is ready" << std::endl;

// Arm
ActionResult arm_result = action->arm();
Action::Result arm_result = action->arm();
action_error_exit(arm_result, "Arming failed");
std::cout << "Armed" << std::endl;

Expand All @@ -100,7 +100,7 @@ int main(int argc, char **argv)
std::placeholders::_1));

// Takeoff
ActionResult takeoff_result = action->takeoff();
Action::Result takeoff_result = action->takeoff();
action_error_exit(takeoff_result, "Takeoff failed");
std::cout << "In Air..." << std::endl;
sleep_for(seconds(5)); // Wait for drone to reach takeoff altitude
Expand Down Expand Up @@ -131,7 +131,7 @@ int main(int argc, char **argv)
telemetry->flight_mode_async(nullptr);

// Land
const ActionResult land_result = action->land();
const Action::Result land_result = action->land();
action_error_exit(land_result, "Landing failed");
while (telemetry->in_air()) {
std::cout << "waiting until landed" << std::endl;
Expand All @@ -142,10 +142,10 @@ int main(int argc, char **argv)
}

// Handles Action's result
inline void action_error_exit(ActionResult result, const std::string &message)
inline void action_error_exit(Action::Result result, const std::string &message)
{
if (result != ActionResult::SUCCESS) {
std::cerr << ERROR_CONSOLE_TEXT << message << action_result_str(result)
if (result != Action::Result::SUCCESS) {
std::cerr << ERROR_CONSOLE_TEXT << message << Action::result_str(result)
<< NORMAL_CONSOLE_TEXT << std::endl;
exit(EXIT_FAILURE);
}
Expand Down
12 changes: 6 additions & 6 deletions example/offboard_velocity/offboard_velocity.cpp
Expand Up @@ -26,10 +26,10 @@ using std::chrono::seconds;
#define NORMAL_CONSOLE_TEXT "\033[0m" // Restore normal console colour

// Handles Action's result
inline void action_error_exit(ActionResult result, const std::string &message)
inline void action_error_exit(Action::Result result, const std::string &message)
{
if (result != ActionResult::SUCCESS) {
std::cerr << ERROR_CONSOLE_TEXT << message << action_result_str(result)
if (result != Action::Result::SUCCESS) {
std::cerr << ERROR_CONSOLE_TEXT << message << Action::result_str(result)
<< NORMAL_CONSOLE_TEXT << std::endl;
exit(EXIT_FAILURE);
}
Expand Down Expand Up @@ -213,11 +213,11 @@ int main(int argc, char **argv)
}
std::cout << "System is ready" << std::endl;

ActionResult arm_result = action->arm();
Action::Result arm_result = action->arm();
action_error_exit(arm_result, "Arming failed");
std::cout << "Armed" << std::endl;

ActionResult takeoff_result = action->takeoff();
Action::Result takeoff_result = action->takeoff();
action_error_exit(takeoff_result, "Takeoff failed");
std::cout << "In Air..." << std::endl;
sleep_for(seconds(5));
Expand All @@ -234,7 +234,7 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}

const ActionResult land_result = action->land();
const Action::Result land_result = action->land();
action_error_exit(land_result, "Landing failed");

// We are relying on auto-disarming but let's keep watching the telemetry for a bit longer.
Expand Down
18 changes: 9 additions & 9 deletions example/takeoff_land/takeoff_and_land.cpp
Expand Up @@ -100,19 +100,19 @@ int main(int argc, char **argv)

// Arm vehicle
std::cout << "Arming..." << std::endl;
const ActionResult arm_result = action->arm();
const Action::Result arm_result = action->arm();

if (arm_result != ActionResult::SUCCESS) {
std::cout << ERROR_CONSOLE_TEXT << "Arming failed:" << action_result_str(arm_result)
if (arm_result != Action::Result::SUCCESS) {
std::cout << ERROR_CONSOLE_TEXT << "Arming failed:" << Action::result_str(arm_result)
<< NORMAL_CONSOLE_TEXT << std::endl;
return 1;
}

// Take off
std::cout << "Taking off..." << std::endl;
const ActionResult takeoff_result = action->takeoff();
if (takeoff_result != ActionResult::SUCCESS) {
std::cout << ERROR_CONSOLE_TEXT << "Takeoff failed:" << action_result_str(takeoff_result)
const Action::Result takeoff_result = action->takeoff();
if (takeoff_result != Action::Result::SUCCESS) {
std::cout << ERROR_CONSOLE_TEXT << "Takeoff failed:" << Action::result_str(takeoff_result)
<< NORMAL_CONSOLE_TEXT << std::endl;
return 1;
}
Expand All @@ -121,9 +121,9 @@ int main(int argc, char **argv)
sleep_for(seconds(10));

std::cout << "Landing..." << std::endl;
const ActionResult land_result = action->land();
if (land_result != ActionResult::SUCCESS) {
std::cout << ERROR_CONSOLE_TEXT << "Land failed:" << action_result_str(land_result)
const Action::Result land_result = action->land();
if (land_result != Action::Result::SUCCESS) {
std::cout << ERROR_CONSOLE_TEXT << "Land failed:" << Action::result_str(land_result)
<< NORMAL_CONSOLE_TEXT << std::endl;
return 1;
}
Expand Down
36 changes: 18 additions & 18 deletions example/transition_vtol_fixed_wing/transition_vtol_fixed_wing.cpp
Expand Up @@ -97,19 +97,19 @@ int main(int argc, char **argv)

// Arm vehicle
std::cout << "Arming..." << std::endl;
const ActionResult arm_result = action->arm();
const Action::Result arm_result = action->arm();

if (arm_result != ActionResult::SUCCESS) {
std::cout << ERROR_CONSOLE_TEXT << "Arming failed:" << action_result_str(arm_result)
if (arm_result != Action::Result::SUCCESS) {
std::cout << ERROR_CONSOLE_TEXT << "Arming failed:" << Action::result_str(arm_result)
<< NORMAL_CONSOLE_TEXT << std::endl;
return 1;
}

// Take off
std::cout << "Taking off..." << std::endl;
const ActionResult takeoff_result = action->takeoff();
if (takeoff_result != ActionResult::SUCCESS) {
std::cout << ERROR_CONSOLE_TEXT << "Takeoff failed:" << action_result_str(takeoff_result)
const Action::Result takeoff_result = action->takeoff();
if (takeoff_result != Action::Result::SUCCESS) {
std::cout << ERROR_CONSOLE_TEXT << "Takeoff failed:" << Action::result_str(takeoff_result)
<< NORMAL_CONSOLE_TEXT << std::endl;
return 1;
}
Expand All @@ -118,11 +118,11 @@ int main(int argc, char **argv)
std::this_thread::sleep_for(std::chrono::seconds(10));

std::cout << "Transition to fixedwing..." << std::endl;
const ActionResult fw_result = action->transition_to_fixedwing();
const Action::Result fw_result = action->transition_to_fixedwing();

if (fw_result != ActionResult::SUCCESS) {
if (fw_result != Action::Result::SUCCESS) {
std::cout << ERROR_CONSOLE_TEXT
<< "Transition to fixed wing failed: " << action_result_str(fw_result)
<< "Transition to fixed wing failed: " << Action::result_str(fw_result)
<< NORMAL_CONSOLE_TEXT << std::endl;
// return 1;
}
Expand All @@ -131,10 +131,10 @@ int main(int argc, char **argv)
std::this_thread::sleep_for(std::chrono::seconds(10));

std::cout << "Transition back to multicopter..." << std::endl;
const ActionResult mc_result = action->transition_to_multicopter();
if (mc_result != ActionResult::SUCCESS) {
const Action::Result mc_result = action->transition_to_multicopter();
if (mc_result != Action::Result::SUCCESS) {
std::cout << ERROR_CONSOLE_TEXT
<< "Transition to multi copter failed:" << action_result_str(mc_result)
<< "Transition to multi copter failed:" << Action::result_str(mc_result)
<< NORMAL_CONSOLE_TEXT << std::endl;
// return 1;
}
Expand All @@ -144,10 +144,10 @@ int main(int argc, char **argv)

// Return to launch
std::cout << "Return to launch..." << std::endl;
const ActionResult rtl_result = action->return_to_launch();
if (rtl_result != ActionResult::SUCCESS) {
const Action::Result rtl_result = action->return_to_launch();
if (rtl_result != Action::Result::SUCCESS) {
std::cout << ERROR_CONSOLE_TEXT
<< "Returning to launch failed:" << action_result_str(rtl_result)
<< "Returning to launch failed:" << Action::result_str(rtl_result)
<< NORMAL_CONSOLE_TEXT << std::endl;
// return 1;
}
Expand All @@ -157,9 +157,9 @@ int main(int argc, char **argv)

// Land
std::cout << "Landing..." << std::endl;
const ActionResult land_result = action->land();
if (land_result != ActionResult::SUCCESS) {
std::cout << ERROR_CONSOLE_TEXT << "Land failed:" << action_result_str(land_result)
const Action::Result land_result = action->land();
if (land_result != Action::Result::SUCCESS) {
std::cout << ERROR_CONSOLE_TEXT << "Land failed:" << Action::result_str(land_result)
<< NORMAL_CONSOLE_TEXT << std::endl;
// return 1;
}
Expand Down

0 comments on commit 3763cd4

Please sign in to comment.