Skip to content

Commit

Permalink
Remove usage of "using namespace std;"
Browse files Browse the repository at this point in the history
  • Loading branch information
rajat2004 committed Apr 2, 2022
1 parent d28514c commit 6043143
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
3 changes: 1 addition & 2 deletions DroneServer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "vehicles/multirotor/firmwares/mavlink/MavLinkMultirotorApi.hpp"
#include "common/Settings.hpp"

using namespace std;
using namespace msr::airlib;

/*
Expand All @@ -21,7 +20,7 @@ int main(int argc, const char* argv[])
if (argc != 2) {
std::cout << "Usage: " << argv[0] << " is_simulation" << std::endl;
std::cout << "\t where is_simulation = 0 or 1" << std::endl;
cout << "Start the DroneServer using the 'PX4' settings in ~/Documents/AirSim/settings.json." << endl;
std::cout << "Start the DroneServer using the 'PX4' settings in ~/Documents/AirSim/settings.json." << std::endl;
return 1;
}

Expand Down
11 changes: 5 additions & 6 deletions DroneShell/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ namespace msr
namespace airlib
{

using namespace std;
using namespace common_utils;

struct CommandContext
Expand Down Expand Up @@ -403,7 +402,7 @@ namespace airlib
}
}
if (path.size() == 0) {
std::cout << "incomplete path, please provide at least 3 numbers defining a 3d point" << endl;
std::cout << "incomplete path, please provide at least 3 numbers defining a 3d point" << std::endl;
return false;
}

Expand Down Expand Up @@ -1294,7 +1293,7 @@ See RecordPose for information about log file format")
auto image = context->client.simGetImage("0", imageType);

if (image.size() == 0) {
std::cout << "error getting image, check sim for error messages" << endl;
std::cout << "error getting image, check sim for error messages" << std::endl;
return;
}

Expand Down Expand Up @@ -1322,12 +1321,12 @@ See RecordPose for information about log file format")
std::string imageName = Utils::stringf("%s_%s%d.png", baseName.c_str(), typeName, image_index_++);
std::string file_path_name = FileSystem::combine(path, imageName);

ofstream file;
std::ofstream file;
FileSystem::createBinaryFile(file_path_name, file);
file.write(reinterpret_cast<const char*>(image.data()), image.size());
file.close();

std::cout << "Image saved to: " << file_path_name << " (" << image.size() << " bytes)" << endl;
std::cout << "Image saved to: " << file_path_name << " (" << image.size() << " bytes)" << std::endl;

context->sleep_for(pause_time / 1000);
}
Expand Down Expand Up @@ -1359,7 +1358,7 @@ See RecordPose for information about log file format")
imageType = ImageCaptureBase::ImageType::DisparityNormalized;
}
else {
cout << "Error: Invalid image type '" << type << "', expecting either 'depth', 'scene' or 'segmentation'" << endl;
std::cout << "Error: Invalid image type '" << type << "', expecting either 'depth', 'scene' or 'segmentation'" << std::endl;
return true;
}

Expand Down
19 changes: 10 additions & 9 deletions docs/apis_cpp.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
Please read [general API doc](apis.md) first if you haven't already. This document describes C++ examples and other C++ specific details.

## Quick Start

Fastest way to get started is to open AirSim.sln in Visual Studio 2019. You will see [Hello Car](https://github.com/Microsoft/AirSim/tree/master/HelloCar/) and [Hello Drone](https://github.com/Microsoft/AirSim/tree/master/HelloDrone/) examples in the solution. These examples will show you the include paths and lib paths you will need to setup in your VC++ projects. If you are using Linux then you will specify these paths either in your [cmake file](https://github.com/Microsoft/AirSim/tree/master/cmake//HelloCar/CMakeLists.txt) or on compiler command line.

#### Include and Lib Folders

* Include folders: `$(ProjectDir)..\AirLib\deps\rpclib\include;include;$(ProjectDir)..\AirLib\deps\eigen3;$(ProjectDir)..\AirLib\include`
* Dependencies: `rpc.lib`
* Lib folders: `$(ProjectDir)\..\AirLib\deps\MavLinkCom\lib\$(Platform)\$(Configuration);$(ProjectDir)\..\AirLib\deps\rpclib\lib\$(Platform)\$(Configuration);$(ProjectDir)\..\AirLib\lib\$(Platform)\$(Configuration)`
Expand All @@ -22,7 +24,7 @@ Here's how to use AirSim APIs using C++ to control simulated car (see also [Pyth
#include <iostream>
#include "vehicles/car/api/CarRpcLibClient.hpp"

int main()
int main()
{
msr::airlib::CarRpcLibClient client;
client.enableApiControl(true); //this disables manual control
Expand Down Expand Up @@ -60,34 +62,33 @@ Here's how to use AirSim APIs using C++ to control simulated quadrotor (see also
#include <iostream>
#include "vehicles/multirotor/api/MultirotorRpcLibClient.hpp"

int main()
int main()
{
using namespace std;
msr::airlib::MultirotorRpcLibClient client;

cout << "Press Enter to enable API control" << endl; cin.get();
std::cout << "Press Enter to enable API control\n"; std::cin.get();
client.enableApiControl(true);

cout << "Press Enter to arm the drone" << endl; cin.get();
std::cout << "Press Enter to arm the drone\n"; std::cin.get();
client.armDisarm(true);

cout << "Press Enter to takeoff" << endl; cin.get();
std::cout << "Press Enter to takeoff\n"; std::cin.get();
client.takeoffAsync(5)->waitOnLastTask();

cout << "Press Enter to move 5 meters in x direction with 1 m/s velocity" << endl; cin.get();
std::cout << "Press Enter to move 5 meters in x direction with 1 m/s velocity\n"; std::cin.get();
auto position = client.getMultirotorState().getPosition(); // from current location
client.moveToPositionAsync(position.x() + 5, position.y(), position.z(), 1)->waitOnLastTask();

cout << "Press Enter to land" << endl; cin.get();
std::cout << "Press Enter to land\n"; std::cin.get();
client.landAsync()->waitOnLastTask();

return 0;
}
```

## See Also

* [Examples](https://github.com/microsoft/AirSim/tree/master/Examples) of how to use internal infrastructure in AirSim in your other projects
* [DroneShell](https://github.com/microsoft/AirSim/tree/master/DroneShell) app shows how to make simple interface using C++ APIs to control drones
* [HelloSpawnedDrones](https://github.com/microsoft/AirSim/tree/master/HelloSpawnedDrones) app shows how to make additional vehicles on the fly
* [Python APIs](apis.md)

0 comments on commit 6043143

Please sign in to comment.