Skip to content

Commit

Permalink
feat(autoware.universe): merge branch main into autoware_msg
Browse files Browse the repository at this point in the history
Signed-off-by: liu cui <[email protected]>
  • Loading branch information
cyn-liu committed Apr 8, 2024
2 parents 1275177 + 35642a6 commit 0f7bbdf
Show file tree
Hide file tree
Showing 151 changed files with 4,135 additions and 1,109 deletions.
5 changes: 5 additions & 0 deletions build_depends.repos
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ repositories:
type: git
url: https://github.com/MORAI-Autonomous/MORAI-ROS2_morai_msgs.git
version: main
#vehicle
vehicle/sample_vehicle_launch:
type: git
url: https://github.com/autowarefoundation/sample_vehicle_launch.git
version: main
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@

#include <rclcpp/qos.hpp>

#include <autoware_adapi_v1_msgs/msg/door_status_array.hpp>
#include <autoware_adapi_v1_msgs/msg/vehicle_kinematics.hpp>
#include <autoware_adapi_v1_msgs/msg/vehicle_status.hpp>
#include <autoware_adapi_v1_msgs/srv/get_door_layout.hpp>
#include <autoware_adapi_v1_msgs/srv/get_vehicle_dimensions.hpp>
#include <autoware_adapi_v1_msgs/srv/set_door_command.hpp>

namespace autoware_ad_api::vehicle
{
Expand Down Expand Up @@ -48,6 +51,27 @@ struct Dimensions
static constexpr char name[] = "/api/vehicle/dimensions";
};

struct DoorCommand
{
using Service = autoware_adapi_v1_msgs::srv::SetDoorCommand;
static constexpr char name[] = "/api/vehicle/doors/command";
};

struct DoorLayout
{
using Service = autoware_adapi_v1_msgs::srv::GetDoorLayout;
static constexpr char name[] = "/api/vehicle/doors/layout";
};

struct DoorStatus
{
using Message = autoware_adapi_v1_msgs::msg::DoorStatusArray;
static constexpr char name[] = "/api/vehicle/doors/status";
static constexpr size_t depth = 1;
static constexpr auto reliability = RMW_QOS_POLICY_RELIABILITY_RELIABLE;
static constexpr auto durability = RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL;
};

} // namespace autoware_ad_api::vehicle

#endif // AUTOWARE_AD_API_SPECS__VEHICLE_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

#include <rclcpp/qos.hpp>

#include <autoware_adapi_v1_msgs/msg/door_status_array.hpp>
#include <autoware_adapi_v1_msgs/srv/get_door_layout.hpp>
#include <autoware_adapi_v1_msgs/srv/set_door_command.hpp>
#include <autoware_vehicle_msgs/msg/gear_report.hpp>
#include <autoware_vehicle_msgs/msg/hazard_lights_report.hpp>
#include <autoware_vehicle_msgs/msg/steering_report.hpp>
Expand Down Expand Up @@ -71,6 +74,27 @@ struct EnergyStatus
static constexpr auto durability = RMW_QOS_POLICY_DURABILITY_VOLATILE;
};

struct DoorCommand
{
using Service = autoware_adapi_v1_msgs::srv::SetDoorCommand;
static constexpr char name[] = "/vehicle/doors/command";
};

struct DoorLayout
{
using Service = autoware_adapi_v1_msgs::srv::GetDoorLayout;
static constexpr char name[] = "/vehicle/doors/layout";
};

struct DoorStatus
{
using Message = autoware_adapi_v1_msgs::msg::DoorStatusArray;
static constexpr char name[] = "/vehicle/doors/status";
static constexpr size_t depth = 1;
static constexpr auto reliability = RMW_QOS_POLICY_RELIABILITY_RELIABLE;
static constexpr auto durability = RMW_QOS_POLICY_DURABILITY_VOLATILE;
};

} // namespace vehicle_interface

#endif // COMPONENT_INTERFACE_SPECS__VEHICLE_HPP_
5 changes: 5 additions & 0 deletions common/global_parameter_loader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ project(global_parameter_loader)
find_package(autoware_cmake REQUIRED)
autoware_package()

if(BUILD_TESTING)
file(GLOB_RECURSE test_files test/*.cpp)
ament_add_ros_isolated_gtest(test_global_params_launch ${test_files})
endif()

ament_auto_package(
INSTALL_TO_SHARE
launch
Expand Down
4 changes: 3 additions & 1 deletion common/global_parameter_loader/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
<buildtool_depend>ament_cmake_auto</buildtool_depend>
<buildtool_depend>autoware_cmake</buildtool_depend>

<exec_depend>vehicle_info_util</exec_depend>
<depend>sample_vehicle_description</depend>
<depend>vehicle_info_util</depend>

<test_depend>ament_cmake_ros</test_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>autoware_lint_common</test_depend>

Expand Down
44 changes: 44 additions & 0 deletions common/global_parameter_loader/test/test_global_params_launch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2023 The Autoware Foundation
//
// 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 <gtest/gtest.h>

#include <cstdlib>
#include <iostream>
#include <string>

TEST(TestLaunchFile, test_launch_file)
{
// Define the path of Python launch file
std::string global_params_launch_path = "global_params.launch.py";

// Define the parameters you want to pass to the launch file
std::string use_sim_time_param = "false";
std::string vehicle_model_param = "sample_vehicle";
// Construct the command to run the Python launch script with parameters
std::string command = "ros2 launch global_parameter_loader " + global_params_launch_path +
" use_sim_time:=" + use_sim_time_param +
" vehicle_model:=" + vehicle_model_param;

// Use the system() function to execute the command
int result = std::system(command.c_str());
// Check the result of running the launch file
EXPECT_EQ(result, 0);
}

int main(int argc, char * argv[])
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
namespace object_recognition_utils
{
using tier4_autoware_utils::Polygon2d;
// minimum area to avoid division by zero
static const double MIN_AREA = 1e-6;

inline double getConvexShapeArea(const Polygon2d & source_polygon, const Polygon2d & target_polygon)
{
Expand Down Expand Up @@ -66,10 +68,12 @@ template <class T1, class T2>
double get2dIoU(const T1 source_object, const T2 target_object, const double min_union_area = 0.01)
{
const auto source_polygon = tier4_autoware_utils::toPolygon2d(source_object);
if (boost::geometry::area(source_polygon) < MIN_AREA) return 0.0;
const auto target_polygon = tier4_autoware_utils::toPolygon2d(target_object);
if (boost::geometry::area(target_polygon) < MIN_AREA) return 0.0;

const double intersection_area = getIntersectionArea(source_polygon, target_polygon);
if (intersection_area == 0.0) return 0.0;
if (intersection_area < MIN_AREA) return 0.0;
const double union_area = getUnionArea(source_polygon, target_polygon);

const double iou =
Expand All @@ -81,7 +85,9 @@ template <class T1, class T2>
double get2dGeneralizedIoU(const T1 & source_object, const T2 & target_object)
{
const auto source_polygon = tier4_autoware_utils::toPolygon2d(source_object);
if (boost::geometry::area(source_polygon) < MIN_AREA) return 0.0;
const auto target_polygon = tier4_autoware_utils::toPolygon2d(target_object);
if (boost::geometry::area(target_polygon) < MIN_AREA) return 0.0;

const double intersection_area = getIntersectionArea(source_polygon, target_polygon);
const double union_area = getUnionArea(source_polygon, target_polygon);
Expand All @@ -95,11 +101,13 @@ template <class T1, class T2>
double get2dPrecision(const T1 source_object, const T2 target_object)
{
const auto source_polygon = tier4_autoware_utils::toPolygon2d(source_object);
const double source_area = boost::geometry::area(source_polygon);
if (source_area < MIN_AREA) return 0.0;
const auto target_polygon = tier4_autoware_utils::toPolygon2d(target_object);
if (boost::geometry::area(target_polygon) < MIN_AREA) return 0.0;

const double intersection_area = getIntersectionArea(source_polygon, target_polygon);
if (intersection_area == 0.0) return 0.0;
const double source_area = boost::geometry::area(source_polygon);
if (intersection_area < MIN_AREA) return 0.0;

return std::min(1.0, intersection_area / source_area);
}
Expand All @@ -108,11 +116,13 @@ template <class T1, class T2>
double get2dRecall(const T1 source_object, const T2 target_object)
{
const auto source_polygon = tier4_autoware_utils::toPolygon2d(source_object);
if (boost::geometry::area(source_polygon) < MIN_AREA) return 0.0;
const auto target_polygon = tier4_autoware_utils::toPolygon2d(target_object);
const double target_area = boost::geometry::area(target_polygon);
if (target_area < MIN_AREA) return 0.0;

const double intersection_area = getIntersectionArea(source_polygon, target_polygon);
if (intersection_area == 0.0) return 0.0;
const double target_area = boost::geometry::area(target_polygon);
if (intersection_area < MIN_AREA) return 0.0;

return std::min(1.0, intersection_area / target_area);
}
Expand Down
1 change: 1 addition & 0 deletions common/tier4_adapi_rviz_plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
ament_auto_add_library(${PROJECT_NAME} SHARED
src/route_tool.cpp
src/route_panel.cpp
src/door_panel.cpp
)

target_link_libraries(${PROJECT_NAME}
Expand Down
4 changes: 4 additions & 0 deletions common/tier4_adapi_rviz_plugin/plugins/plugin_description.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@
<description>RoutePanel</description>
</class>

<class type="tier4_adapi_rviz_plugins::DoorPanel" base_class_type="rviz_common::Panel">
<description>DoorPanel</description>
</class>

</library>
118 changes: 118 additions & 0 deletions common/tier4_adapi_rviz_plugin/src/door_panel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Copyright 2023 The Autoware Contributors
//
// 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 "door_panel.hpp"

#include <rviz_common/display_context.hpp>

#include <memory>

namespace tier4_adapi_rviz_plugins
{

DoorPanel::DoorPanel(QWidget * parent) : rviz_common::Panel(parent)
{
status_ = new QLabel("Trying to get door layout.");
layout_ = new QGridLayout();
layout_->addWidget(status_, 0, 0, 1, 4);
setLayout(layout_);
}

void DoorPanel::onInitialize()
{
const auto on_layout = [this](const rclcpp::Client<DoorLayout::Service>::SharedFuture future) {
const auto res = future.get();
if (!res->status.success) {
status_->setText(QString::fromStdString("failed to get layout: " + res->status.message));
return;
}
const auto & layouts = res->doors;
for (size_t index = 0; index < layouts.size(); ++index) {
const auto & layout = layouts[index];
DoorUI door;
door.description = new QLabel(QString::fromStdString(layout.description));
door.status = new QLabel("unknown");
door.open = new QPushButton("open");
door.close = new QPushButton("close");
doors_.push_back(door);

layout_->addWidget(door.description, index + 1, 0);
layout_->addWidget(door.status, index + 1, 1);
layout_->addWidget(door.open, index + 1, 2);
layout_->addWidget(door.close, index + 1, 3);

using Command = autoware_adapi_v1_msgs::msg::DoorCommand;
const auto on_open = [this, index] { on_button(index, Command::OPEN); };
const auto on_close = [this, index] { on_button(index, Command::CLOSE); };
connect(door.open, &QPushButton::clicked, on_open);
connect(door.close, &QPushButton::clicked, on_close);
}
status_->hide();
};

const auto on_status = [this](const DoorStatus::Message::ConstSharedPtr msg) {
using Status = autoware_adapi_v1_msgs::msg::DoorStatus;
if (doors_.size() != msg->doors.size()) {
return;
}
for (size_t index = 0; index < doors_.size(); ++index) {
const auto & label = doors_[index].status;
switch (msg->doors[index].status) {
case Status::NOT_AVAILABLE:
label->setText("not available");
break;
case Status::OPENED:
label->setText("opened");
break;
case Status::CLOSED:
label->setText("closed");
break;
case Status::OPENING:
label->setText("opening");
break;
case Status::CLOSING:
label->setText("closing");
break;
default:
label->setText("unknown");
break;
}
}
};

auto lock = getDisplayContext()->getRosNodeAbstraction().lock();
auto node = lock->get_raw_node();

const auto adaptor = component_interface_utils::NodeAdaptor(node.get());
adaptor.init_cli(cli_command_);
adaptor.init_cli(cli_layout_);
adaptor.init_sub(sub_status_, on_status);

const auto req = std::make_shared<DoorLayout::Service::Request>();
cli_layout_->async_send_request(req, on_layout);
}

void DoorPanel::on_button(uint32_t index, uint8_t command)
{
const auto req = std::make_shared<DoorCommand::Service::Request>();
req->doors.resize(1);
req->doors.back().index = index;
req->doors.back().command = command;
cli_command_->async_send_request(req);
}

} // namespace tier4_adapi_rviz_plugins

#include <pluginlib/class_list_macros.hpp>
PLUGINLIB_EXPORT_CLASS(tier4_adapi_rviz_plugins::DoorPanel, rviz_common::Panel)
Loading

0 comments on commit 0f7bbdf

Please sign in to comment.