{"action":"created","comment":{"url":"https://api.github.com/repos/pvechersky/rotors_simulator/pulls/comments/98728825","pull_request_review_id":19379299,"id":98728825,"diff_hunk":"@@ -99,38 +115,68 @@ void GazeboWindPlugin::OnUpdate(const common::UpdateInfo& _info) {\n   // Get the current simulation time.\n   common::Time now = world_->GetSimTime();\n \n-  // Calculate the wind force.\n-  double wind_strength = wind_force_mean_ + wind_force_n_(random_generator_);\n-  math::Vector3 wind = wind_strength * wind_direction_;\n-  // Apply a force from the constant wind to the link.\n-  link_->AddForceAtRelativePosition(wind, xyz_offset_);\n-\n-  math::Vector3 wind_gust(0, 0, 0);\n-  // Calculate the wind gust force.\n-  if (now >= wind_gust_start_ && now < wind_gust_end_) {\n-    double wind_gust_strength = wind_gust_force_mean_ + wind_gust_force_n_(random_generator_);\n-    wind_gust = wind_gust_strength * wind_gust_direction_;\n-    // Apply a force from the wind gust to the link.\n-    link_->AddForceAtRelativePosition(wind_gust, xyz_offset_);\n-  }\n+  math::Vector3 wind_velocity = math::Vector3(0,0,0);\n+\n+  // Choose method for calculating wind velocity\n+  if (!custom_static_wind_field_) {\n+    // Calculate the wind force.\n+    double wind_strength = wind_force_mean_ + wind_force_n_(random_generator_);\n+    math::Vector3 wind = wind_strength * wind_direction_;\n+    // Apply a force from the constant wind to the link.\n+    link_->AddForceAtRelativePosition(wind, xyz_offset_);\n \n-  geometry_msgs::WrenchStamped wrench_msg;\n+    math::Vector3 wind_gust(0, 0, 0);\n+    // Calculate the wind gust force.\n+    if (now >= wind_gust_start_ && now < wind_gust_end_) {\n+      double wind_gust_strength = wind_gust_force_mean_ + wind_gust_force_n_(random_generator_);\n+      wind_gust = wind_gust_strength * wind_gust_direction_;\n+      // Apply a force from the wind gust to the link.\n+      link_->AddForceAtRelativePosition(wind_gust, xyz_offset_);\n+    }\n \n-  wrench_msg.header.frame_id = frame_id_;\n-  wrench_msg.header.stamp.sec = now.sec;\n-  wrench_msg.header.stamp.nsec = now.nsec;\n-  wrench_msg.wrench.force.x = wind.x + wind_gust.x;\n-  wrench_msg.wrench.force.y = wind.y + wind_gust.y;\n-  wrench_msg.wrench.force.z = wind.z + wind_gust.z;\n-  wrench_msg.wrench.torque.x = 0;\n-  wrench_msg.wrench.torque.y = 0;\n-  wrench_msg.wrench.torque.z = 0;\n+    geometry_msgs::WrenchStamped wrench_msg;\n \n-  wind_pub_.publish(wrench_msg);\n+    wrench_msg.header.frame_id = frame_id_;\n+    wrench_msg.header.stamp.sec = now.sec;\n+    wrench_msg.header.stamp.nsec = now.nsec;\n+    wrench_msg.wrench.force.x = wind.x + wind_gust.x;\n+    wrench_msg.wrench.force.y = wind.y + wind_gust.y;\n+    wrench_msg.wrench.force.z = wind.z + wind_gust.z;\n+    wrench_msg.wrench.torque.x = 0;\n+    wrench_msg.wrench.torque.y = 0;\n+    wrench_msg.wrench.torque.z = 0;\n \n-  // Calculate the wind speed\n-  double wind_speed = wind_speed_mean_; // + wind_speed_n_(random_generator_);\n-  math::Vector3 wind_velocity = wind_speed * wind_direction_;\n+    wind_pub_.publish(wrench_msg);\n+\n+    // Calculate the wind speed\n+    double wind_speed = wind_speed_mean_; // + wind_speed_n_(random_generator_);\n+    wind_velocity = wind_speed * wind_direction_;\n+  } else {\n+    // Get the current position of the aircraft in world coordinates\n+    math::Vector3 link_position = link_->GetWorldPose().pos;\n+\n+    // Find indices for x,y and minimal/maximal values of the vertical spacing factor of the four surrounding grid columns\n+    int i_inf = floor((link_position.x - min_x_) / res_x_);\n+    int i_sup = i_inf + 1;\n+    int j_inf = floor((link_position.y - min_y_) / res_y_);\n+    int j_sup = j_inf + 1;\n+\n+    float vertical_spacing_factor_0 = (link_position.z - bottom_z_[i_inf + (j_inf * n_x_)]) / (top_z_[i_inf + (j_inf * n_x_)] - bottom_z_[i_inf + (j_inf * n_x_)]);\n+    float vertical_spacing_factor_1 = (link_position.z - bottom_z_[i_sup + (j_inf * n_x_)]) / (top_z_[i_sup + (j_inf * n_x_)] - bottom_z_[i_sup + (j_inf * n_x_)]);\n+    float vertical_spacing_factor_4 = (link_position.z - bottom_z_[i_inf + (j_sup * n_x_)]) / (top_z_[i_inf + (j_sup * n_x_)] - bottom_z_[i_inf + (j_sup * n_x_)]);\n+    float vertical_spacing_factor_5 = (link_position.z - bottom_z_[i_sup + (j_sup * n_x_)]) / (top_z_[i_sup + (j_sup * n_x_)] - bottom_z_[i_sup + (j_sup * n_x_)]);\n+\n+    float vertical_spacing_factor_min = std::min(std::min(std::min(vertical_spacing_factor_0,vertical_spacing_factor_1),vertical_spacing_factor_4),vertical_spacing_factor_5);\n+    float vertical_spacing_factor_max = std::max(std::max(std::max(vertical_spacing_factor_0,vertical_spacing_factor_1),vertical_spacing_factor_4),vertical_spacing_factor_5);\n+\n+    // Check if aircraft is out of wind field or not, and act accordingly\n+    if (!( i_inf < 0 || j_inf < 0 || vertical_spacing_factor_max < 0 || i_sup > (n_x_ - 1) || j_sup > (n_y_ - 1) || vertical_spacing_factor_min > 1 )) {\n+      InterpolateWindVelocity(link_position, i_inf, i_sup, j_inf, j_sup, vertical_spacing_factor_0, vertical_spacing_factor_1, vertical_spacing_factor_4, vertical_spacing_factor_5, wind_velocity);","path":"rotors_gazebo_plugins/src/gazebo_wind_plugin.cpp","position":null,"original_position":160,"commit_id":"6689808939860ea8b17fe41c3f7144455ceb950c","original_commit_id":"e554cf53f8a17bbad5ef85ae473de68352cb9d9f","user":{"login":"nelhayek","id":22601818,"avatar_url":"https://avatars.githubusercontent.com/u/22601818?v=3","gravatar_id":"","url":"https://api.github.com/users/nelhayek","html_url":"https://github.com/nelhayek","followers_url":"https://api.github.com/users/nelhayek/followers","following_url":"https://api.github.com/users/nelhayek/following{/other_user}","gists_url":"https://api.github.com/users/nelhayek/gists{/gist_id}","starred_url":"https://api.github.com/users/nelhayek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nelhayek/subscriptions","organizations_url":"https://api.github.com/users/nelhayek/orgs","repos_url":"https://api.github.com/users/nelhayek/repos","events_url":"https://api.github.com/users/nelhayek/events{/privacy}","received_events_url":"https://api.github.com/users/nelhayek/received_events","type":"User","site_admin":false},"body":"I found the approach very neat indeed! I have extended it for it to work in the wind plugin. I have also modified the cell vertices numbering once more so that most of the code could be simplified with loops and arrays while staying consistent. ","created_at":"2017-01-31T17:52:25Z","updated_at":"2017-01-31T17:52:25Z","html_url":"https://github.com/pvechersky/rotors_simulator/pull/5#discussion_r98728825","pull_request_url":"https://api.github.com/repos/pvechersky/rotors_simulator/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/pvechersky/rotors_simulator/pulls/comments/98728825"},"html":{"href":"https://github.com/pvechersky/rotors_simulator/pull/5#discussion_r98728825"},"pull_request":{"href":"https://api.github.com/repos/pvechersky/rotors_simulator/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/pvechersky/rotors_simulator/pulls/5","id":102089487,"html_url":"https://github.com/pvechersky/rotors_simulator/pull/5","diff_url":"https://github.com/pvechersky/rotors_simulator/pull/5.diff","patch_url":"https://github.com/pvechersky/rotors_simulator/pull/5.patch","issue_url":"https://api.github.com/repos/pvechersky/rotors_simulator/issues/5","number":5,"state":"open","locked":false,"title":"Feature/fw wind plugin","user":{"login":"nelhayek","id":22601818,"avatar_url":"https://avatars.githubusercontent.com/u/22601818?v=3","gravatar_id":"","url":"https://api.github.com/users/nelhayek","html_url":"https://github.com/nelhayek","followers_url":"https://api.github.com/users/nelhayek/followers","following_url":"https://api.github.com/users/nelhayek/following{/other_user}","gists_url":"https://api.github.com/users/nelhayek/gists{/gist_id}","starred_url":"https://api.github.com/users/nelhayek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nelhayek/subscriptions","organizations_url":"https://api.github.com/users/nelhayek/orgs","repos_url":"https://api.github.com/users/nelhayek/repos","events_url":"https://api.github.com/users/nelhayek/events{/privacy}","received_events_url":"https://api.github.com/users/nelhayek/received_events","type":"User","site_admin":false},"body":"Extended the wind plugin to be able to read wind data from a text file, and accordingly publish the interpolated wind velocity at the aircraft location. Details about use and functioning have been added to the README. \r\n\r\n@pvechersky @tstastny @philipoe","created_at":"2017-01-18T15:38:16Z","updated_at":"2017-01-31T17:52:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7b590fb5ea3bc92db0220aceab888025fed44ed3","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/pvechersky/rotors_simulator/pulls/5/commits","review_comments_url":"https://api.github.com/repos/pvechersky/rotors_simulator/pulls/5/comments","review_comment_url":"https://api.github.com/repos/pvechersky/rotors_simulator/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pvechersky/rotors_simulator/issues/5/comments","statuses_url":"https://api.github.com/repos/pvechersky/rotors_simulator/statuses/6689808939860ea8b17fe41c3f7144455ceb950c","head":{"label":"nelhayek:feature/fw_wind_plugin","ref":"feature/fw_wind_plugin","sha":"6689808939860ea8b17fe41c3f7144455ceb950c","user":{"login":"nelhayek","id":22601818,"avatar_url":"https://avatars.githubusercontent.com/u/22601818?v=3","gravatar_id":"","url":"https://api.github.com/users/nelhayek","html_url":"https://github.com/nelhayek","followers_url":"https://api.github.com/users/nelhayek/followers","following_url":"https://api.github.com/users/nelhayek/following{/other_user}","gists_url":"https://api.github.com/users/nelhayek/gists{/gist_id}","starred_url":"https://api.github.com/users/nelhayek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nelhayek/subscriptions","organizations_url":"https://api.github.com/users/nelhayek/orgs","repos_url":"https://api.github.com/users/nelhayek/repos","events_url":"https://api.github.com/users/nelhayek/events{/privacy}","received_events_url":"https://api.github.com/users/nelhayek/received_events","type":"User","site_admin":false},"repo":{"id":73794226,"name":"rotors_simulator","full_name":"nelhayek/rotors_simulator","owner":{"login":"nelhayek","id":22601818,"avatar_url":"https://avatars.githubusercontent.com/u/22601818?v=3","gravatar_id":"","url":"https://api.github.com/users/nelhayek","html_url":"https://github.com/nelhayek","followers_url":"https://api.github.com/users/nelhayek/followers","following_url":"https://api.github.com/users/nelhayek/following{/other_user}","gists_url":"https://api.github.com/users/nelhayek/gists{/gist_id}","starred_url":"https://api.github.com/users/nelhayek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nelhayek/subscriptions","organizations_url":"https://api.github.com/users/nelhayek/orgs","repos_url":"https://api.github.com/users/nelhayek/repos","events_url":"https://api.github.com/users/nelhayek/events{/privacy}","received_events_url":"https://api.github.com/users/nelhayek/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nelhayek/rotors_simulator","description":"RotorS is a UAV gazebo simulator","fork":true,"url":"https://api.github.com/repos/nelhayek/rotors_simulator","forks_url":"https://api.github.com/repos/nelhayek/rotors_simulator/forks","keys_url":"https://api.github.com/repos/nelhayek/rotors_simulator/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nelhayek/rotors_simulator/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nelhayek/rotors_simulator/teams","hooks_url":"https://api.github.com/repos/nelhayek/rotors_simulator/hooks","issue_events_url":"https://api.github.com/repos/nelhayek/rotors_simulator/issues/events{/number}","events_url":"https://api.github.com/repos/nelhayek/rotors_simulator/events","assignees_url":"https://api.github.com/repos/nelhayek/rotors_simulator/assignees{/user}","branches_url":"https://api.github.com/repos/nelhayek/rotors_simulator/branches{/branch}","tags_url":"https://api.github.com/repos/nelhayek/rotors_simulator/tags","blobs_url":"https://api.github.com/repos/nelhayek/rotors_simulator/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nelhayek/rotors_simulator/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nelhayek/rotors_simulator/git/refs{/sha}","trees_url":"https://api.github.com/repos/nelhayek/rotors_simulator/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nelhayek/rotors_simulator/statuses/{sha}","languages_url":"https://api.github.com/repos/nelhayek/rotors_simulator/languages","stargazers_url":"https://api.github.com/repos/nelhayek/rotors_simulator/stargazers","contributors_url":"https://api.github.com/repos/nelhayek/rotors_simulator/contributors","subscribers_url":"https://api.github.com/repos/nelhayek/rotors_simulator/subscribers","subscription_url":"https://api.github.com/repos/nelhayek/rotors_simulator/subscription","commits_url":"https://api.github.com/repos/nelhayek/rotors_simulator/commits{/sha}","git_commits_url":"https://api.github.com/repos/nelhayek/rotors_simulator/git/commits{/sha}","comments_url":"https://api.github.com/repos/nelhayek/rotors_simulator/comments{/number}","issue_comment_url":"https://api.github.com/repos/nelhayek/rotors_simulator/issues/comments{/number}","contents_url":"https://api.github.com/repos/nelhayek/rotors_simulator/contents/{+path}","compare_url":"https://api.github.com/repos/nelhayek/rotors_simulator/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nelhayek/rotors_simulator/merges","archive_url":"https://api.github.com/repos/nelhayek/rotors_simulator/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nelhayek/rotors_simulator/downloads","issues_url":"https://api.github.com/repos/nelhayek/rotors_simulator/issues{/number}","pulls_url":"https://api.github.com/repos/nelhayek/rotors_simulator/pulls{/number}","milestones_url":"https://api.github.com/repos/nelhayek/rotors_simulator/milestones{/number}","notifications_url":"https://api.github.com/repos/nelhayek/rotors_simulator/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nelhayek/rotors_simulator/labels{/name}","releases_url":"https://api.github.com/repos/nelhayek/rotors_simulator/releases{/id}","deployments_url":"https://api.github.com/repos/nelhayek/rotors_simulator/deployments","created_at":"2016-11-15T08:47:00Z","updated_at":"2016-11-15T08:47:04Z","pushed_at":"2017-01-31T17:49:54Z","git_url":"git://github.com/nelhayek/rotors_simulator.git","ssh_url":"git@github.com:nelhayek/rotors_simulator.git","clone_url":"https://github.com/nelhayek/rotors_simulator.git","svn_url":"https://github.com/nelhayek/rotors_simulator","homepage":"","size":143047,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"pvechersky:feature/fixed_wing_sim","ref":"feature/fixed_wing_sim","sha":"7f7d0c2ec41a4588e77a4fc213815b43f5f8f40c","user":{"login":"pvechersky","id":11036394,"avatar_url":"https://avatars.githubusercontent.com/u/11036394?v=3","gravatar_id":"","url":"https://api.github.com/users/pvechersky","html_url":"https://github.com/pvechersky","followers_url":"https://api.github.com/users/pvechersky/followers","following_url":"https://api.github.com/users/pvechersky/following{/other_user}","gists_url":"https://api.github.com/users/pvechersky/gists{/gist_id}","starred_url":"https://api.github.com/users/pvechersky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pvechersky/subscriptions","organizations_url":"https://api.github.com/users/pvechersky/orgs","repos_url":"https://api.github.com/users/pvechersky/repos","events_url":"https://api.github.com/users/pvechersky/events{/privacy}","received_events_url":"https://api.github.com/users/pvechersky/received_events","type":"User","site_admin":false},"repo":{"id":54725773,"name":"rotors_simulator","full_name":"pvechersky/rotors_simulator","owner":{"login":"pvechersky","id":11036394,"avatar_url":"https://avatars.githubusercontent.com/u/11036394?v=3","gravatar_id":"","url":"https://api.github.com/users/pvechersky","html_url":"https://github.com/pvechersky","followers_url":"https://api.github.com/users/pvechersky/followers","following_url":"https://api.github.com/users/pvechersky/following{/other_user}","gists_url":"https://api.github.com/users/pvechersky/gists{/gist_id}","starred_url":"https://api.github.com/users/pvechersky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pvechersky/subscriptions","organizations_url":"https://api.github.com/users/pvechersky/orgs","repos_url":"https://api.github.com/users/pvechersky/repos","events_url":"https://api.github.com/users/pvechersky/events{/privacy}","received_events_url":"https://api.github.com/users/pvechersky/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pvechersky/rotors_simulator","description":"RotorS is a UAV gazebo simulator","fork":true,"url":"https://api.github.com/repos/pvechersky/rotors_simulator","forks_url":"https://api.github.com/repos/pvechersky/rotors_simulator/forks","keys_url":"https://api.github.com/repos/pvechersky/rotors_simulator/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pvechersky/rotors_simulator/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pvechersky/rotors_simulator/teams","hooks_url":"https://api.github.com/repos/pvechersky/rotors_simulator/hooks","issue_events_url":"https://api.github.com/repos/pvechersky/rotors_simulator/issues/events{/number}","events_url":"https://api.github.com/repos/pvechersky/rotors_simulator/events","assignees_url":"https://api.github.com/repos/pvechersky/rotors_simulator/assignees{/user}","branches_url":"https://api.github.com/repos/pvechersky/rotors_simulator/branches{/branch}","tags_url":"https://api.github.com/repos/pvechersky/rotors_simulator/tags","blobs_url":"https://api.github.com/repos/pvechersky/rotors_simulator/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pvechersky/rotors_simulator/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pvechersky/rotors_simulator/git/refs{/sha}","trees_url":"https://api.github.com/repos/pvechersky/rotors_simulator/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pvechersky/rotors_simulator/statuses/{sha}","languages_url":"https://api.github.com/repos/pvechersky/rotors_simulator/languages","stargazers_url":"https://api.github.com/repos/pvechersky/rotors_simulator/stargazers","contributors_url":"https://api.github.com/repos/pvechersky/rotors_simulator/contributors","subscribers_url":"https://api.github.com/repos/pvechersky/rotors_simulator/subscribers","subscription_url":"https://api.github.com/repos/pvechersky/rotors_simulator/subscription","commits_url":"https://api.github.com/repos/pvechersky/rotors_simulator/commits{/sha}","git_commits_url":"https://api.github.com/repos/pvechersky/rotors_simulator/git/commits{/sha}","comments_url":"https://api.github.com/repos/pvechersky/rotors_simulator/comments{/number}","issue_comment_url":"https://api.github.com/repos/pvechersky/rotors_simulator/issues/comments{/number}","contents_url":"https://api.github.com/repos/pvechersky/rotors_simulator/contents/{+path}","compare_url":"https://api.github.com/repos/pvechersky/rotors_simulator/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pvechersky/rotors_simulator/merges","archive_url":"https://api.github.com/repos/pvechersky/rotors_simulator/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pvechersky/rotors_simulator/downloads","issues_url":"https://api.github.com/repos/pvechersky/rotors_simulator/issues{/number}","pulls_url":"https://api.github.com/repos/pvechersky/rotors_simulator/pulls{/number}","milestones_url":"https://api.github.com/repos/pvechersky/rotors_simulator/milestones{/number}","notifications_url":"https://api.github.com/repos/pvechersky/rotors_simulator/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pvechersky/rotors_simulator/labels{/name}","releases_url":"https://api.github.com/repos/pvechersky/rotors_simulator/releases{/id}","deployments_url":"https://api.github.com/repos/pvechersky/rotors_simulator/deployments","created_at":"2016-03-25T14:57:57Z","updated_at":"2016-03-25T14:57:59Z","pushed_at":"2017-01-31T17:49:56Z","git_url":"git://github.com/pvechersky/rotors_simulator.git","ssh_url":"git@github.com:pvechersky/rotors_simulator.git","clone_url":"https://github.com/pvechersky/rotors_simulator.git","svn_url":"https://github.com/pvechersky/rotors_simulator","homepage":"","size":131453,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pvechersky/rotors_simulator/pulls/5"},"html":{"href":"https://github.com/pvechersky/rotors_simulator/pull/5"},"issue":{"href":"https://api.github.com/repos/pvechersky/rotors_simulator/issues/5"},"comments":{"href":"https://api.github.com/repos/pvechersky/rotors_simulator/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/pvechersky/rotors_simulator/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/pvechersky/rotors_simulator/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pvechersky/rotors_simulator/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/pvechersky/rotors_simulator/statuses/6689808939860ea8b17fe41c3f7144455ceb950c"}}}}
{"actor":{"display_login":"nelhayek"}}