Skip to content

Commit

Permalink
HelloDrone: Fix variable naming to align with convention
Browse files Browse the repository at this point in the history
  • Loading branch information
rajat2004 committed Mar 5, 2021
1 parent 596e586 commit ede1459
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions HelloDrone/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ int main()
try {
client.confirmConnection();

std::cout << "Press Enter to get FPV image" << std::endl; std::cin.get();
vector<ImageRequest> request = { ImageRequest("0", ImageType::Scene), ImageRequest("1", ImageType::DepthPlanner, true) };
std::cout << "Press Enter to get FPV image" << std::endl;
std::cin.get();

vector<ImageRequest> request{ ImageRequest("0", ImageType::Scene), ImageRequest("1", ImageType::DepthPlanner, true) };
const vector<ImageResponse>& response = client.simGetImages(request);
std::cout << "# of images received: " << response.size() << std::endl;

Expand Down Expand Up @@ -56,7 +58,9 @@ int main()
}
}

std::cout << "Press Enter to arm the drone" << std::endl; std::cin.get();
std::cout << "Press Enter to arm the drone" << std::endl;
std::cin.get();

client.enableApiControl(true);
client.armDisarm(true);

Expand Down Expand Up @@ -91,8 +95,8 @@ int main()
// << "magnetometer_data.magnetic_field_covariance" << magnetometer_data.magnetic_field_covariance // not implemented in sensor

std::cout << "Press Enter to takeoff" << std::endl; std::cin.get();
float takeoffTimeout = 5;
client.takeoffAsync(takeoffTimeout)->waitOnLastTask();
float takeoff_timeout = 5;
client.takeoffAsync(takeoff_timeout)->waitOnLastTask();

// switch to explicit hover mode so that this is the fall back when
// move* commands are finished.
Expand All @@ -102,24 +106,26 @@ int main()
std::cout << "Press Enter to fly in a 10m box pattern at 3 m/s velocity" << std::endl; std::cin.get();
// moveByVelocityZ is an offboard operation, so we need to set offboard mode.
client.enableApiControl(true);

auto position = client.getMultirotorState().getPosition();
float z = position.z(); // current position (NED coordinate system).
const float speed = 3.0f;
const float size = 10.0f;
const float duration = size / speed;
DrivetrainType driveTrain = DrivetrainType::ForwardOnly;
DrivetrainType drivetrain = DrivetrainType::ForwardOnly;
YawMode yaw_mode(true, 0);

std::cout << "moveByVelocityZ(" << speed << ", 0, " << z << "," << duration << ")" << std::endl;
client.moveByVelocityZAsync(speed, 0, z, duration, driveTrain, yaw_mode);
client.moveByVelocityZAsync(speed, 0, z, duration, drivetrain, yaw_mode);
std::this_thread::sleep_for(std::chrono::duration<double>(duration));
std::cout << "moveByVelocityZ(0, " << speed << "," << z << "," << duration << ")" << std::endl;
client.moveByVelocityZAsync(0, speed, z, duration, driveTrain, yaw_mode);
client.moveByVelocityZAsync(0, speed, z, duration, drivetrain, yaw_mode);
std::this_thread::sleep_for(std::chrono::duration<double>(duration));
std::cout << "moveByVelocityZ(" << -speed << ", 0, " << z << "," << duration << ")" << std::endl;
client.moveByVelocityZAsync(-speed, 0, z, duration, driveTrain, yaw_mode);
client.moveByVelocityZAsync(-speed, 0, z, duration, drivetrain, yaw_mode);
std::this_thread::sleep_for(std::chrono::duration<double>(duration));
std::cout << "moveByVelocityZ(0, " << -speed << "," << z << "," << duration << ")" << std::endl;
client.moveByVelocityZAsync(0, -speed, z, duration, driveTrain, yaw_mode);
client.moveByVelocityZAsync(0, -speed, z, duration, drivetrain, yaw_mode);
std::this_thread::sleep_for(std::chrono::duration<double>(duration));

client.hoverAsync()->waitOnLastTask();
Expand Down

0 comments on commit ede1459

Please sign in to comment.