Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read Vehicle Settings from settings.json through RPC #2415

Closed
nrakoski3 opened this issue Feb 12, 2020 · 1 comment · Fixed by #3536
Closed

Read Vehicle Settings from settings.json through RPC #2415

nrakoski3 opened this issue Feb 12, 2020 · 1 comment · Fixed by #3536

Comments

@nrakoski3
Copy link

nrakoski3 commented Feb 12, 2020

Hello,

I have a setup where I run a quadcopter in Unreal/ Airsim on a Windows machine and then control and get sensor data from the quadcopter using the MultirotorRpcLibClient from a Linux machine.

I saw that in airsim_ros_wrapper.cpp function AirsimROSWrapper::create_ros_pubs_from_settings_json() settings are pulled from the settings.json file and published as ROS topics.

I would like to pull my settings from the settings.json file into my logic on the Linux side, however when I use the code block below:

 // If we aren't connected to AirSim, try to connect.
    if (!client_connected_) {
        cout << "Connecting to AirSim: ip " << airsim_ip_ << ", port " << airsim_port_ << endl;
        sim_client_ = std::make_shared<ma::MultirotorRpcLibClient>(airsim_ip_,
                                                                   airsim_port_,
                                                                   airsim_timeout_s_);

        sim_client_->confirmConnection();

        // If we haven't been able to connect to AirSim, warn the user and return.
        if (sim_client_->getConnectionState() !=
            ma::RpcLibClientBase::ConnectionState::Connected) {
            client_connected_ = false;
            cout << "Warning: not connected to AirSim." << endl;

            // return std::make_shared<sc::MessageBase>();
            return true;
        }
        client_connected_ = true;
        sim_client_->enableApiControl(true);
    }

// Get Vehicles and Camera Settings

for (const auto& curr_vehicle_elem : AirSimSettings::singleton().vehicles) {
        // auto& vehicle_setting = curr_vehicle_elem.second;
        // auto curr_vehicle_name = curr_vehicle_elem.vehicle_setting.vehicle_name;
        auto& vehicle_setting = curr_vehicle_elem.second;
        auto curr_vehicle_name = curr_vehicle_elem.first;
        auto vehicle_setting_local = vehicle_setting.get();

        cout << "Vehicle Name" << endl;
        cout << curr_vehicle_name << endl;
        cout << "Vehicle Local" << endl;
        cout << vehicle_setting_local->vehicle_name << endl;

        //if (curr_vehicle_name=="SimpleFlight") {
        for (auto& curr_camera_elem : vehicle_setting_local->cameras) {
            auto& camera_setting = curr_camera_elem.second;
            auto& curr_camera_name = curr_camera_elem.first;

            cout << "Camera Name" << endl;
            cout << curr_camera_name << endl;

        }

        cout << "*************" << endl;
}

I get the print out:

Client Ver:1 (Min Req:1), Server Ver:1 (Min Req:1)
Vehicle Name
ComputerVision
Vehicle Local
ComputerVision
*************
Vehicle Name
PhysXCar
Vehicle Local
PhysXCar
*************
Vehicle Name
SimpleFlight
Vehicle Local
SimpleFlight
*************

My settings.json file only has a single quadcopter named "Drone1" with 4 camera settings, however using this method to pull AirSim Settings does not give me the vehicle I expect nor does it see the camera settings at all.

Questions:
Am I using this function wrong?
Is there a way to pull the settings.json file over RPC like the AirsimROSWrapper suggests?
Am I misunderstanding how the AirsimROSWrapper works?

Here is my settings.json:

{
  "SeeDocsAt": "https://github.com/Microsoft/AirSim/blob/master/docs/settings.md",
  "SettingsVersion": 1.2,
  "SimMode": "Multirotor",
  "LogMessagesVisible": true,
  "SpeedUnitFactor": 1.0,
  "SpeedUnitLabel": "m/s",
  "Recording": {
    "RecordOnMove": false,
    "RecordInterval": 0.05,
    "Cameras": [
		  { "CameraID": 0, "ImageType": 0, "PixelsAsFloat": false, "Compress": false },
		  { "CameraID": 0, "ImageType": 2, "PixelsAsFloat": true, "Compress": false },
		  { "CameraID": 0, "ImageType": 5, "PixelsAsFloat": false, "Compress": false },
          { "CameraID": 0, "ImageType": 7, "PixelsAsFloat": false, "Compress": false }
	  ]
  },
  "CameraDefaults": {
    "CaptureSettings": [
      {
        "ImageType": 0,
        "Width": 256,
        "Height": 144,
        "FOV_Degrees": 90,
        "AutoExposureSpeed": 100,
        "AutoExposureBias": 0,
        "AutoExposureMaxBrightness": 0.68,
        "AutoExposureMinBrightness": 0.03
      },
	  {
        "ImageType": 2,
        "Width": 256,
        "Height": 144,
        "FOV_Degrees": 90,
        "AutoExposureSpeed": 100,
        "AutoExposureBias": 0,
        "AutoExposureMaxBrightness": 0.68,
        "AutoExposureMinBrightness": 0.03
      },
	  {
        "ImageType": 5,
        "Width": 256,
        "Height": 144,
        "FOV_Degrees": 90,
        "AutoExposureSpeed": 100,
        "AutoExposureBias": 0,
        "AutoExposureMaxBrightness": 0.68,
        "AutoExposureMinBrightness": 0.03
      },
      {
        "ImageType": 7,
        "Width": 256,
        "Height": 144,
        "FOV_Degrees": 90,
        "AutoExposureSpeed": 100,
        "AutoExposureBias": 0,
        "AutoExposureMaxBrightness": 0.68,
        "AutoExposureMinBrightness": 0.03
      }
    ]  
  },
  "Vehicles": {
	"Drone1": {
			"VehicleType": "simpleflight",
			"AutoCreate": true,
			"Sensors": {
			    "Lidar1": { 
					"SensorType": 6,
					"Enabled" : true,
					"NumberOfChannels": 16,
					"RotationsPerSecond": 10,
					"PointsPerSecond": 100000,
					"X": 0, "Y": 0, "Z": -1,
					"Roll": 0, "Pitch": 0, "Yaw" : 0,
					"VerticalFOVUpper": -15,
					"VerticalFOVLower": -25,
					"HorizontalFOVStart": -20,
					"HorizontalFOVEnd": 20,
					"DrawDebugPoints": false,
					"DataFrame": "SensorLocalFrame"
				}
			}
	}
  }
}
@xapavlov
Copy link

Function create_ros_pubs_from_settings_json() (although named so) takes all the information not from json file, but from AirSimSettings singleton. Thus, you have to initialize AirSimSettingsParser class before using create_ros_pubs_from_settings_json(). This will run AirSimSettingsParser's constructor, parse settings.json and fill AirSimSettings.

In other words, what you are doing is ok, just put AirSimSettingsParser somewhere in the definition of your node class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants