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

feat(default_ad_api): add door api #5737

Merged
merged 13 commits into from
Mar 27, 2024
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_auto_vehicle_msgs/msg/gear_report.hpp>
#include <autoware_auto_vehicle_msgs/msg/hazard_lights_report.hpp>
#include <autoware_auto_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_
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)

Check warning on line 24 in common/tier4_adapi_rviz_plugin/src/door_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_adapi_rviz_plugin/src/door_panel.cpp#L24

Added line #L24 was not covered by tests
{
status_ = new QLabel("Trying to get door layout.");
layout_ = new QGridLayout();
layout_->addWidget(status_, 0, 0, 1, 4);
setLayout(layout_);
}

Check warning on line 30 in common/tier4_adapi_rviz_plugin/src/door_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_adapi_rviz_plugin/src/door_panel.cpp#L26-L30

Added lines #L26 - L30 were not covered by tests

void DoorPanel::onInitialize()

Check warning on line 32 in common/tier4_adapi_rviz_plugin/src/door_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_adapi_rviz_plugin/src/door_panel.cpp#L32

Added line #L32 was not covered by tests
{
const auto on_layout = [this](const rclcpp::Client<DoorLayout::Service>::SharedFuture future) {

Check warning on line 34 in common/tier4_adapi_rviz_plugin/src/door_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_adapi_rviz_plugin/src/door_panel.cpp#L34

Added line #L34 was not covered by tests
const auto res = future.get();
if (!res->status.success) {
status_->setText(QString::fromStdString("failed to get layout: " + res->status.message));

Check warning on line 37 in common/tier4_adapi_rviz_plugin/src/door_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_adapi_rviz_plugin/src/door_panel.cpp#L36-L37

Added lines #L36 - L37 were not covered by tests
return;
}
const auto & layouts = res->doors;
for (size_t index = 0; index < layouts.size(); ++index) {

Check warning on line 41 in common/tier4_adapi_rviz_plugin/src/door_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_adapi_rviz_plugin/src/door_panel.cpp#L41

Added line #L41 was not covered by tests
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);

Check warning on line 48 in common/tier4_adapi_rviz_plugin/src/door_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_adapi_rviz_plugin/src/door_panel.cpp#L44-L48

Added lines #L44 - L48 were not covered by tests

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);

Check warning on line 53 in common/tier4_adapi_rviz_plugin/src/door_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_adapi_rviz_plugin/src/door_panel.cpp#L50-L53

Added lines #L50 - L53 were not covered by tests

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);

Check warning on line 59 in common/tier4_adapi_rviz_plugin/src/door_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_adapi_rviz_plugin/src/door_panel.cpp#L56-L59

Added lines #L56 - L59 were not covered by tests
}
status_->hide();
};

Check warning on line 62 in common/tier4_adapi_rviz_plugin/src/door_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_adapi_rviz_plugin/src/door_panel.cpp#L61-L62

Added lines #L61 - L62 were not covered by tests

const auto on_status = [this](const DoorStatus::Message::ConstSharedPtr msg) {

Check warning on line 64 in common/tier4_adapi_rviz_plugin/src/door_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_adapi_rviz_plugin/src/door_panel.cpp#L64

Added line #L64 was not covered by tests
using Status = autoware_adapi_v1_msgs::msg::DoorStatus;
if (doors_.size() != msg->doors.size()) {

Check warning on line 66 in common/tier4_adapi_rviz_plugin/src/door_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_adapi_rviz_plugin/src/door_panel.cpp#L66

Added line #L66 was not covered by tests
return;
}
for (size_t index = 0; index < doors_.size(); ++index) {

Check warning on line 69 in common/tier4_adapi_rviz_plugin/src/door_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_adapi_rviz_plugin/src/door_panel.cpp#L69

Added line #L69 was not covered by tests
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;

Check warning on line 89 in common/tier4_adapi_rviz_plugin/src/door_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_adapi_rviz_plugin/src/door_panel.cpp#L71-L89

Added lines #L71 - L89 were not covered by tests
}
}
};

Check warning on line 92 in common/tier4_adapi_rviz_plugin/src/door_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_adapi_rviz_plugin/src/door_panel.cpp#L92

Added line #L92 was not covered by tests

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

Check warning on line 95 in common/tier4_adapi_rviz_plugin/src/door_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_adapi_rviz_plugin/src/door_panel.cpp#L94-L95

Added lines #L94 - L95 were not covered by tests

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);

Check warning on line 100 in common/tier4_adapi_rviz_plugin/src/door_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_adapi_rviz_plugin/src/door_panel.cpp#L97-L100

Added lines #L97 - L100 were not covered by tests

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

Check warning on line 104 in common/tier4_adapi_rviz_plugin/src/door_panel.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Complex Method

DoorPanel::onInitialize has a cyclomatic complexity of 11, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.

Check warning on line 104 in common/tier4_adapi_rviz_plugin/src/door_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_adapi_rviz_plugin/src/door_panel.cpp#L103-L104

Added lines #L103 - L104 were not covered by tests

void DoorPanel::on_button(uint32_t index, uint8_t command)

Check warning on line 106 in common/tier4_adapi_rviz_plugin/src/door_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_adapi_rviz_plugin/src/door_panel.cpp#L106

Added line #L106 was not covered by tests
{
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);
}

Check warning on line 113 in common/tier4_adapi_rviz_plugin/src/door_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_adapi_rviz_plugin/src/door_panel.cpp#L109-L113

Added lines #L109 - L113 were not covered by tests

} // namespace tier4_adapi_rviz_plugins

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

Check warning on line 118 in common/tier4_adapi_rviz_plugin/src/door_panel.cpp

View check run for this annotation

Codecov / codecov/patch

common/tier4_adapi_rviz_plugin/src/door_panel.cpp#L118

Added line #L118 was not covered by tests
64 changes: 64 additions & 0 deletions common/tier4_adapi_rviz_plugin/src/door_panel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// 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.

#ifndef DOOR_PANEL_HPP_
#define DOOR_PANEL_HPP_

#include <QGridLayout>
#include <QLabel>
#include <QPushButton>
#include <autoware_ad_api_specs/vehicle.hpp>
#include <component_interface_utils/rclcpp.hpp>
#include <rclcpp/rclcpp.hpp>
#include <rviz_common/panel.hpp>

#include <vector>

namespace tier4_adapi_rviz_plugins
{

class DoorPanel : public rviz_common::Panel
{
Q_OBJECT
using DoorCommand = autoware_ad_api::vehicle::DoorCommand;
using DoorLayout = autoware_ad_api::vehicle::DoorLayout;
using DoorStatus = autoware_ad_api::vehicle::DoorStatus;

public:
explicit DoorPanel(QWidget * parent = nullptr);
void onInitialize() override;

private:
component_interface_utils::Client<DoorCommand>::SharedPtr cli_command_;
component_interface_utils::Client<DoorLayout>::SharedPtr cli_layout_;
component_interface_utils::Subscription<DoorStatus>::SharedPtr sub_status_;

struct DoorUI
{
QLabel * description;
QLabel * status;
QPushButton * open;
QPushButton * close;
};
QGridLayout * layout_;
QLabel * status_;
std::vector<DoorUI> doors_;

private slots:
void on_button(uint32_t index, uint8_t command);
};

} // namespace tier4_adapi_rviz_plugins

#endif // DOOR_PANEL_HPP_
6 changes: 6 additions & 0 deletions launch/tier4_simulator_launch/launch/simulator.launch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<arg name="launch_dummy_perception"/>
<arg name="launch_dummy_vehicle"/>
<arg name="launch_dummy_localization"/>
<arg name="launch_dummy_doors"/>
<arg name="launch_diagnostic_converter"/>
<arg name="vehicle_info_param_file"/>

Expand Down Expand Up @@ -132,6 +133,11 @@
</include>
</group>

<!-- Dummy doors -->
<group if="$(var launch_dummy_doors)">
<include file="$(find-pkg-share vehicle_door_simulator)/launch/vehicle_door_simulator.launch.xml"/>
</group>

<!-- Diagnostic Converter -->
<group if="$(var launch_diagnostic_converter)">
<node name="diagnostic_converter" exec="diagnostic_converter" pkg="diagnostic_converter" output="screen">
Expand Down
11 changes: 11 additions & 0 deletions simulator/vehicle_door_simulator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.14)
project(vehicle_door_simulator)

find_package(autoware_cmake REQUIRED)
autoware_package()

ament_auto_add_executable(dummy_doors
src/dummy_doors.cpp
)

ament_auto_package(INSTALL_TO_SHARE launch)
3 changes: 3 additions & 0 deletions simulator/vehicle_door_simulator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# vehicle_door_simulator

This package is for testing operations on vehicle devices such as doors.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<launch>
<node pkg="vehicle_door_simulator" exec="dummy_doors" name="dummy_doors">
<remap from="~/doors/command" to="/vehicle/doors/command"/>
<remap from="~/doors/layout" to="/vehicle/doors/layout"/>
<remap from="~/doors/status" to="/vehicle/doors/status"/>
</node>
</launch>
22 changes: 22 additions & 0 deletions simulator/vehicle_door_simulator/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>vehicle_door_simulator</name>
<version>0.1.0</version>
<description>The vehicle_door_simulator package</description>
<maintainer email="isamu.takagi@tier4.jp">Takagi, Isamu</maintainer>
<license>Apache License 2.0</license>

<buildtool_depend>ament_cmake_auto</buildtool_depend>
<buildtool_depend>autoware_cmake</buildtool_depend>

<depend>autoware_adapi_v1_msgs</depend>
<depend>rclcpp</depend>

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

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
Loading
Loading