Skip to content

Commit 7fd077b

Browse files
isamu-takagibadai-nguyen
authored andcommitted
feat(default_ad_api): add door api (autowarefoundation#5737)
Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp>
1 parent 7514ae8 commit 7fd077b

File tree

18 files changed

+556
-0
lines changed

18 files changed

+556
-0
lines changed

common/autoware_ad_api_specs/include/autoware_ad_api_specs/vehicle.hpp

+24
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717

1818
#include <rclcpp/qos.hpp>
1919

20+
#include <autoware_adapi_v1_msgs/msg/door_status_array.hpp>
2021
#include <autoware_adapi_v1_msgs/msg/vehicle_kinematics.hpp>
2122
#include <autoware_adapi_v1_msgs/msg/vehicle_status.hpp>
23+
#include <autoware_adapi_v1_msgs/srv/get_door_layout.hpp>
2224
#include <autoware_adapi_v1_msgs/srv/get_vehicle_dimensions.hpp>
25+
#include <autoware_adapi_v1_msgs/srv/set_door_command.hpp>
2326

2427
namespace autoware_ad_api::vehicle
2528
{
@@ -48,6 +51,27 @@ struct Dimensions
4851
static constexpr char name[] = "/api/vehicle/dimensions";
4952
};
5053

54+
struct DoorCommand
55+
{
56+
using Service = autoware_adapi_v1_msgs::srv::SetDoorCommand;
57+
static constexpr char name[] = "/api/vehicle/doors/command";
58+
};
59+
60+
struct DoorLayout
61+
{
62+
using Service = autoware_adapi_v1_msgs::srv::GetDoorLayout;
63+
static constexpr char name[] = "/api/vehicle/doors/layout";
64+
};
65+
66+
struct DoorStatus
67+
{
68+
using Message = autoware_adapi_v1_msgs::msg::DoorStatusArray;
69+
static constexpr char name[] = "/api/vehicle/doors/status";
70+
static constexpr size_t depth = 1;
71+
static constexpr auto reliability = RMW_QOS_POLICY_RELIABILITY_RELIABLE;
72+
static constexpr auto durability = RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL;
73+
};
74+
5175
} // namespace autoware_ad_api::vehicle
5276

5377
#endif // AUTOWARE_AD_API_SPECS__VEHICLE_HPP_

common/component_interface_specs/include/component_interface_specs/vehicle.hpp

+24
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
#include <rclcpp/qos.hpp>
1919

20+
#include <autoware_adapi_v1_msgs/msg/door_status_array.hpp>
21+
#include <autoware_adapi_v1_msgs/srv/get_door_layout.hpp>
22+
#include <autoware_adapi_v1_msgs/srv/set_door_command.hpp>
2023
#include <autoware_auto_vehicle_msgs/msg/gear_report.hpp>
2124
#include <autoware_auto_vehicle_msgs/msg/hazard_lights_report.hpp>
2225
#include <autoware_auto_vehicle_msgs/msg/steering_report.hpp>
@@ -71,6 +74,27 @@ struct EnergyStatus
7174
static constexpr auto durability = RMW_QOS_POLICY_DURABILITY_VOLATILE;
7275
};
7376

77+
struct DoorCommand
78+
{
79+
using Service = autoware_adapi_v1_msgs::srv::SetDoorCommand;
80+
static constexpr char name[] = "/vehicle/doors/command";
81+
};
82+
83+
struct DoorLayout
84+
{
85+
using Service = autoware_adapi_v1_msgs::srv::GetDoorLayout;
86+
static constexpr char name[] = "/vehicle/doors/layout";
87+
};
88+
89+
struct DoorStatus
90+
{
91+
using Message = autoware_adapi_v1_msgs::msg::DoorStatusArray;
92+
static constexpr char name[] = "/vehicle/doors/status";
93+
static constexpr size_t depth = 1;
94+
static constexpr auto reliability = RMW_QOS_POLICY_RELIABILITY_RELIABLE;
95+
static constexpr auto durability = RMW_QOS_POLICY_DURABILITY_VOLATILE;
96+
};
97+
7498
} // namespace vehicle_interface
7599

76100
#endif // COMPONENT_INTERFACE_SPECS__VEHICLE_HPP_

common/tier4_adapi_rviz_plugin/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
1212
ament_auto_add_library(${PROJECT_NAME} SHARED
1313
src/route_tool.cpp
1414
src/route_panel.cpp
15+
src/door_panel.cpp
1516
)
1617

1718
target_link_libraries(${PROJECT_NAME}

common/tier4_adapi_rviz_plugin/plugins/plugin_description.xml

+4
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@
88
<description>RoutePanel</description>
99
</class>
1010

11+
<class type="tier4_adapi_rviz_plugins::DoorPanel" base_class_type="rviz_common::Panel">
12+
<description>DoorPanel</description>
13+
</class>
14+
1115
</library>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// Copyright 2023 The Autoware Contributors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "door_panel.hpp"
16+
17+
#include <rviz_common/display_context.hpp>
18+
19+
#include <memory>
20+
21+
namespace tier4_adapi_rviz_plugins
22+
{
23+
24+
DoorPanel::DoorPanel(QWidget * parent) : rviz_common::Panel(parent)
25+
{
26+
status_ = new QLabel("Trying to get door layout.");
27+
layout_ = new QGridLayout();
28+
layout_->addWidget(status_, 0, 0, 1, 4);
29+
setLayout(layout_);
30+
}
31+
32+
void DoorPanel::onInitialize()
33+
{
34+
const auto on_layout = [this](const rclcpp::Client<DoorLayout::Service>::SharedFuture future) {
35+
const auto res = future.get();
36+
if (!res->status.success) {
37+
status_->setText(QString::fromStdString("failed to get layout: " + res->status.message));
38+
return;
39+
}
40+
const auto & layouts = res->doors;
41+
for (size_t index = 0; index < layouts.size(); ++index) {
42+
const auto & layout = layouts[index];
43+
DoorUI door;
44+
door.description = new QLabel(QString::fromStdString(layout.description));
45+
door.status = new QLabel("unknown");
46+
door.open = new QPushButton("open");
47+
door.close = new QPushButton("close");
48+
doors_.push_back(door);
49+
50+
layout_->addWidget(door.description, index + 1, 0);
51+
layout_->addWidget(door.status, index + 1, 1);
52+
layout_->addWidget(door.open, index + 1, 2);
53+
layout_->addWidget(door.close, index + 1, 3);
54+
55+
using Command = autoware_adapi_v1_msgs::msg::DoorCommand;
56+
const auto on_open = [this, index] { on_button(index, Command::OPEN); };
57+
const auto on_close = [this, index] { on_button(index, Command::CLOSE); };
58+
connect(door.open, &QPushButton::clicked, on_open);
59+
connect(door.close, &QPushButton::clicked, on_close);
60+
}
61+
status_->hide();
62+
};
63+
64+
const auto on_status = [this](const DoorStatus::Message::ConstSharedPtr msg) {
65+
using Status = autoware_adapi_v1_msgs::msg::DoorStatus;
66+
if (doors_.size() != msg->doors.size()) {
67+
return;
68+
}
69+
for (size_t index = 0; index < doors_.size(); ++index) {
70+
const auto & label = doors_[index].status;
71+
switch (msg->doors[index].status) {
72+
case Status::NOT_AVAILABLE:
73+
label->setText("not available");
74+
break;
75+
case Status::OPENED:
76+
label->setText("opened");
77+
break;
78+
case Status::CLOSED:
79+
label->setText("closed");
80+
break;
81+
case Status::OPENING:
82+
label->setText("opening");
83+
break;
84+
case Status::CLOSING:
85+
label->setText("closing");
86+
break;
87+
default:
88+
label->setText("unknown");
89+
break;
90+
}
91+
}
92+
};
93+
94+
auto lock = getDisplayContext()->getRosNodeAbstraction().lock();
95+
auto node = lock->get_raw_node();
96+
97+
const auto adaptor = component_interface_utils::NodeAdaptor(node.get());
98+
adaptor.init_cli(cli_command_);
99+
adaptor.init_cli(cli_layout_);
100+
adaptor.init_sub(sub_status_, on_status);
101+
102+
const auto req = std::make_shared<DoorLayout::Service::Request>();
103+
cli_layout_->async_send_request(req, on_layout);
104+
}
105+
106+
void DoorPanel::on_button(uint32_t index, uint8_t command)
107+
{
108+
const auto req = std::make_shared<DoorCommand::Service::Request>();
109+
req->doors.resize(1);
110+
req->doors.back().index = index;
111+
req->doors.back().command = command;
112+
cli_command_->async_send_request(req);
113+
}
114+
115+
} // namespace tier4_adapi_rviz_plugins
116+
117+
#include <pluginlib/class_list_macros.hpp>
118+
PLUGINLIB_EXPORT_CLASS(tier4_adapi_rviz_plugins::DoorPanel, rviz_common::Panel)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright 2023 The Autoware Contributors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef DOOR_PANEL_HPP_
16+
#define DOOR_PANEL_HPP_
17+
18+
#include <QGridLayout>
19+
#include <QLabel>
20+
#include <QPushButton>
21+
#include <autoware_ad_api_specs/vehicle.hpp>
22+
#include <component_interface_utils/rclcpp.hpp>
23+
#include <rclcpp/rclcpp.hpp>
24+
#include <rviz_common/panel.hpp>
25+
26+
#include <vector>
27+
28+
namespace tier4_adapi_rviz_plugins
29+
{
30+
31+
class DoorPanel : public rviz_common::Panel
32+
{
33+
Q_OBJECT
34+
using DoorCommand = autoware_ad_api::vehicle::DoorCommand;
35+
using DoorLayout = autoware_ad_api::vehicle::DoorLayout;
36+
using DoorStatus = autoware_ad_api::vehicle::DoorStatus;
37+
38+
public:
39+
explicit DoorPanel(QWidget * parent = nullptr);
40+
void onInitialize() override;
41+
42+
private:
43+
component_interface_utils::Client<DoorCommand>::SharedPtr cli_command_;
44+
component_interface_utils::Client<DoorLayout>::SharedPtr cli_layout_;
45+
component_interface_utils::Subscription<DoorStatus>::SharedPtr sub_status_;
46+
47+
struct DoorUI
48+
{
49+
QLabel * description;
50+
QLabel * status;
51+
QPushButton * open;
52+
QPushButton * close;
53+
};
54+
QGridLayout * layout_;
55+
QLabel * status_;
56+
std::vector<DoorUI> doors_;
57+
58+
private slots:
59+
void on_button(uint32_t index, uint8_t command);
60+
};
61+
62+
} // namespace tier4_adapi_rviz_plugins
63+
64+
#endif // DOOR_PANEL_HPP_

launch/tier4_simulator_launch/launch/simulator.launch.xml

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<arg name="launch_dummy_perception"/>
1111
<arg name="launch_dummy_vehicle"/>
1212
<arg name="launch_dummy_localization"/>
13+
<arg name="launch_dummy_doors"/>
1314
<arg name="launch_diagnostic_converter"/>
1415
<arg name="vehicle_info_param_file"/>
1516

@@ -132,6 +133,11 @@
132133
</include>
133134
</group>
134135

136+
<!-- Dummy doors -->
137+
<group if="$(var launch_dummy_doors)">
138+
<include file="$(find-pkg-share vehicle_door_simulator)/launch/vehicle_door_simulator.launch.xml"/>
139+
</group>
140+
135141
<!-- Diagnostic Converter -->
136142
<group if="$(var launch_diagnostic_converter)">
137143
<node name="diagnostic_converter" exec="diagnostic_converter" pkg="diagnostic_converter" output="screen">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
project(vehicle_door_simulator)
3+
4+
find_package(autoware_cmake REQUIRED)
5+
autoware_package()
6+
7+
ament_auto_add_executable(dummy_doors
8+
src/dummy_doors.cpp
9+
)
10+
11+
ament_auto_package(INSTALL_TO_SHARE launch)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# vehicle_door_simulator
2+
3+
This package is for testing operations on vehicle devices such as doors.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<launch>
2+
<node pkg="vehicle_door_simulator" exec="dummy_doors" name="dummy_doors">
3+
<remap from="~/doors/command" to="/vehicle/doors/command"/>
4+
<remap from="~/doors/layout" to="/vehicle/doors/layout"/>
5+
<remap from="~/doors/status" to="/vehicle/doors/status"/>
6+
</node>
7+
</launch>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="3">
4+
<name>vehicle_door_simulator</name>
5+
<version>0.1.0</version>
6+
<description>The vehicle_door_simulator package</description>
7+
<maintainer email="isamu.takagi@tier4.jp">Takagi, Isamu</maintainer>
8+
<license>Apache License 2.0</license>
9+
10+
<buildtool_depend>ament_cmake_auto</buildtool_depend>
11+
<buildtool_depend>autoware_cmake</buildtool_depend>
12+
13+
<depend>autoware_adapi_v1_msgs</depend>
14+
<depend>rclcpp</depend>
15+
16+
<test_depend>ament_lint_auto</test_depend>
17+
<test_depend>autoware_lint_common</test_depend>
18+
19+
<export>
20+
<build_type>ament_cmake</build_type>
21+
</export>
22+
</package>

0 commit comments

Comments
 (0)