forked from autowarefoundation/autoware.universe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(default_ad_api): add localization api (autowarefoundation#1431)
* feat(default_ad_api): add localization api Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * docs: add readme Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * feat: add auto initial pose Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * feat(autoware_ad_api_msgs): define localization interface Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * fix(default_ad_api): fix interface definition Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * feat(default_ad_api): modify interface version api to use spec package Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * feat(default_ad_api): modify interface version api to use spec package Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * fix: pre-commit Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * fix: pre-commit Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * fix: pre-commit Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * fix: copyright Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * feat: split helper package Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * fix: change topic name to local Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * fix: style Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * fix: style Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * fix: style Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * fix: remove needless keyword Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * feat: change api helper node namespace Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * fix: fix launch file path Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp>
- Loading branch information
1 parent
17acebe
commit 7f3dc54
Showing
21 changed files
with
398 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2022 TIER IV, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "localization.hpp" | ||
|
||
namespace default_ad_api | ||
{ | ||
|
||
LocalizationNode::LocalizationNode(const rclcpp::NodeOptions & options) | ||
: Node("localization", options) | ||
{ | ||
const auto adaptor = component_interface_utils::NodeAdaptor(this); | ||
group_cli_ = create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive); | ||
adaptor.relay_message(pub_state_, sub_state_); | ||
adaptor.relay_service(cli_initialize_, srv_initialize_, group_cli_); | ||
} | ||
|
||
} // namespace default_ad_api | ||
|
||
#include <rclcpp_components/register_node_macro.hpp> | ||
RCLCPP_COMPONENTS_REGISTER_NODE(default_ad_api::LocalizationNode) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2022 TIER IV, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef LOCALIZATION_HPP_ | ||
#define LOCALIZATION_HPP_ | ||
|
||
#include <autoware_ad_api_specs/localization.hpp> | ||
#include <component_interface_specs/localization.hpp> | ||
#include <component_interface_utils/rclcpp.hpp> | ||
#include <rclcpp/rclcpp.hpp> | ||
|
||
// This file should be included after messages. | ||
#include "utils/types.hpp" | ||
|
||
namespace default_ad_api | ||
{ | ||
|
||
class LocalizationNode : public rclcpp::Node | ||
{ | ||
public: | ||
explicit LocalizationNode(const rclcpp::NodeOptions & options); | ||
|
||
private: | ||
rclcpp::CallbackGroup::SharedPtr group_cli_; | ||
Srv<autoware_ad_api::localization::Initialize> srv_initialize_; | ||
Pub<autoware_ad_api::localization::InitializationState> pub_state_; | ||
Cli<localization_interface::Initialize> cli_initialize_; | ||
Sub<localization_interface::InitializationState> sub_state_; | ||
}; | ||
|
||
} // namespace default_ad_api | ||
|
||
#endif // LOCALIZATION_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
system/default_ad_api_helpers/ad_api_adaptors/config/initial_pose.param.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/**: | ||
ros__parameters: | ||
|
||
# from initialpose (Rviz's 2DPoseEstimate) | ||
initial_pose_particle_covariance: | ||
[ | ||
4.0, 0.0, 0.0, 0.0, 0.0, 0.0, | ||
0.0, 4.0, 0.0, 0.0, 0.0, 0.0, | ||
0.0, 0.0, 0.01, 0.0, 0.0, 0.0, | ||
0.0, 0.0, 0.0, 0.01, 0.0, 0.0, | ||
0.0, 0.0, 0.0, 0.0, 0.01, 0.0, | ||
0.0, 0.0, 0.0, 0.0, 0.0, 1.0, | ||
] |
16 changes: 12 additions & 4 deletions
16
system/default_ad_api_helpers/ad_api_adaptors/launch/rviz_adaptors.launch.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
<launch> | ||
<node pkg="ad_api_adaptors" exec="initial_pose_adaptor" name="initial_pose_adaptor"> | ||
<remap from="~/input/goal" to="/planning/mission_planning/goal"/> | ||
<remap from="~/input/waypoint" to="/planning/mission_planning/checkpoint"/> | ||
</node> | ||
<group> | ||
<push-ros-namespace namespace="default_ad_api/helpers"/> | ||
<node pkg="ad_api_adaptors" exec="initial_pose_adaptor" name="initial_pose_adaptor"> | ||
<param from="$(find-pkg-share ad_api_adaptors)/config/initial_pose.param.yaml"/> | ||
<remap from="~/initialpose" to="/initialpose"/> | ||
<remap from="~/fit_map_height" to="/localization/util/fit_map_height"/> | ||
</node> | ||
<node pkg="ad_api_adaptors" exec="routing_adaptor" name="routing_adaptor"> | ||
<remap from="~/input/goal" to="/planning/mission_planning/goal"/> | ||
<remap from="~/input/waypoint" to="/planning/mission_planning/checkpoint"/> | ||
</node> | ||
</group> | ||
</launch> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
system/default_ad_api_helpers/ad_api_adaptors/src/initial_pose_adaptor.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2022 TIER IV, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "initial_pose_adaptor.hpp" | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace ad_api_adaptors | ||
{ | ||
template <class ServiceT> | ||
using Future = typename rclcpp::Client<ServiceT>::SharedFuture; | ||
|
||
std::array<double, 36> get_covariance_parameter(rclcpp::Node * node, const std::string & name) | ||
{ | ||
const auto vector = node->declare_parameter<std::vector<double>>(name); | ||
if (vector.size() != 36) { | ||
throw std::invalid_argument("The covariance parameter size is not 36."); | ||
} | ||
std::array<double, 36> array; | ||
std::copy_n(vector.begin(), array.size(), array.begin()); | ||
return array; | ||
} | ||
|
||
InitialPoseAdaptor::InitialPoseAdaptor() : Node("initial_pose_adaptor") | ||
{ | ||
rviz_particle_covariance_ = get_covariance_parameter(this, "initial_pose_particle_covariance"); | ||
cli_map_fit_ = create_client<RequestHeightFitting>("~/fit_map_height"); | ||
sub_initial_pose_ = create_subscription<PoseWithCovarianceStamped>( | ||
"~/initialpose", rclcpp::QoS(1), | ||
std::bind(&InitialPoseAdaptor::on_initial_pose, this, std::placeholders::_1)); | ||
|
||
const auto adaptor = component_interface_utils::NodeAdaptor(this); | ||
adaptor.init_cli(cli_initialize_); | ||
} | ||
|
||
void InitialPoseAdaptor::on_initial_pose(const PoseWithCovarianceStamped::ConstSharedPtr msg) | ||
{ | ||
const auto req = std::make_shared<RequestHeightFitting::Request>(); | ||
req->pose_with_covariance = *msg; | ||
cli_map_fit_->async_send_request(req, [this](Future<RequestHeightFitting> future) { | ||
const auto req = std::make_shared<Initialize::Service::Request>(); | ||
req->pose.push_back(future.get()->pose_with_covariance); | ||
req->pose.back().pose.covariance = rviz_particle_covariance_; | ||
cli_initialize_->async_send_request(req); | ||
}); | ||
} | ||
|
||
} // namespace ad_api_adaptors | ||
|
||
int main(int argc, char ** argv) | ||
{ | ||
rclcpp::init(argc, argv); | ||
rclcpp::executors::SingleThreadedExecutor executor; | ||
auto node = std::make_shared<ad_api_adaptors::InitialPoseAdaptor>(); | ||
executor.add_node(node); | ||
executor.spin(); | ||
executor.remove_node(node); | ||
rclcpp::shutdown(); | ||
} |
47 changes: 47 additions & 0 deletions
47
system/default_ad_api_helpers/ad_api_adaptors/src/initial_pose_adaptor.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2022 TIER IV, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef INITIAL_POSE_ADAPTOR_HPP_ | ||
#define INITIAL_POSE_ADAPTOR_HPP_ | ||
|
||
#include <autoware_ad_api_specs/localization.hpp> | ||
#include <component_interface_utils/rclcpp.hpp> | ||
#include <rclcpp/rclcpp.hpp> | ||
|
||
#include <geometry_msgs/msg/pose_with_covariance_stamped.hpp> | ||
#include <tier4_localization_msgs/srv/pose_with_covariance_stamped.hpp> | ||
|
||
namespace ad_api_adaptors | ||
{ | ||
|
||
class InitialPoseAdaptor : public rclcpp::Node | ||
{ | ||
public: | ||
InitialPoseAdaptor(); | ||
|
||
private: | ||
using PoseWithCovarianceStamped = geometry_msgs::msg::PoseWithCovarianceStamped; | ||
using Initialize = autoware_ad_api::localization::Initialize; | ||
using RequestHeightFitting = tier4_localization_msgs::srv::PoseWithCovarianceStamped; | ||
rclcpp::Subscription<PoseWithCovarianceStamped>::SharedPtr sub_initial_pose_; | ||
rclcpp::Client<RequestHeightFitting>::SharedPtr cli_map_fit_; | ||
component_interface_utils::Client<Initialize>::SharedPtr cli_initialize_; | ||
std::array<double, 36> rviz_particle_covariance_; | ||
|
||
void on_initial_pose(const PoseWithCovarianceStamped::ConstSharedPtr msg); | ||
}; | ||
|
||
} // namespace ad_api_adaptors | ||
|
||
#endif // INITIAL_POSE_ADAPTOR_HPP_ |
11 changes: 11 additions & 0 deletions
11
system/default_ad_api_helpers/automatic_pose_initializer/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
project(automatic_pose_initializer) | ||
|
||
find_package(autoware_cmake REQUIRED) | ||
autoware_package() | ||
|
||
ament_auto_add_executable(automatic_pose_initializer | ||
src/automatic_pose_initializer.cpp | ||
) | ||
|
||
ament_auto_package(INSTALL_TO_SHARE launch) |
11 changes: 11 additions & 0 deletions
11
system/default_ad_api_helpers/automatic_pose_initializer/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# automatic_pose_initializer | ||
|
||
## automatic_pose_initializer | ||
|
||
This node calls localization initialize API when the localization initialization state is uninitialized. | ||
Since the API uses GNSS pose when no pose is specified, initialization using GNSS can be performed automatically. | ||
|
||
| Interface | Local Name | Global Name | Description | | ||
| ------------ | ---------- | -------------------------------------- | ------------------------------------------ | | ||
| Subscription | - | /api/localization/initialization_state | The localization initialization state API. | | ||
| Client | - | /api/localization/initialize | The localization initialize API. | |
6 changes: 6 additions & 0 deletions
6
...lt_ad_api_helpers/automatic_pose_initializer/launch/automatic_pose_initializer.launch.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<launch> | ||
<group> | ||
<push-ros-namespace namespace="default_ad_api/helpers"/> | ||
<node pkg="automatic_pose_initializer" exec="automatic_pose_initializer" name="automatic_pose_initializer"/> | ||
</group> | ||
</launch> |
Oops, something went wrong.