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

Feature/respawn entity #1198

Merged
merged 37 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
895e9fc
RespawnEntity added
pawellech1 Feb 21, 2024
61214c1
Interface to get vehicle parameters of entity
pawellech1 Feb 21, 2024
9fa8a44
Respawn logic moved to API
pawellech1 Feb 21, 2024
f2b0518
Respawn scenario simplification
pawellech1 Feb 21, 2024
b9ca1af
Code cleaning
pawellech1 Feb 21, 2024
22c608f
Spellcheck fix
pawellech1 Feb 21, 2024
f48075e
Adapting respawn_ego scenario time to tests timeout
pawellech1 Feb 22, 2024
9f1c8a3
Removing unnecessary changes in field_operator_application_for_autowa…
pawellech1 Feb 22, 2024
716726d
Code cleaning
pawellech1 Feb 22, 2024
474f841
CMakeList style
pawellech1 Feb 22, 2024
c94e858
Respawn ego scenario test time adjustment
pawellech1 Feb 22, 2024
d6e8506
Codestyle
pawellech1 Feb 28, 2024
d3caba9
RespawnEgo scenario temporarly removed from build
pawellech1 Feb 28, 2024
a45715c
Reducing the execution time of EgoEntitySimulation::makeSimulationModel
pawellech1 Feb 28, 2024
ca4d28b
Merge remote-tracking branch 'origin-ssh/master' into feature/respawn…
pawellech1 Feb 29, 2024
06eee85
Exceptions inside API::respawn
pawellech1 Feb 29, 2024
ee64d9c
Code cleaning
pawellech1 Mar 1, 2024
b3e63eb
QoS of the subscriber in respawn_ego scenario changed to match the on…
pawellech1 Mar 1, 2024
15e6c1c
updateFrame removed from API::respawn
pawellech1 Mar 4, 2024
d8a005e
Despawning and Spawning entity replaced with UpdateEntityStatusRequest
pawellech1 Mar 12, 2024
9e6e570
Merge remote-tracking branch 'origin/master' into feature/respawn-entity
pawellech1 Mar 14, 2024
56d9d2c
Merge branch 'master' into feature/respawn-entity
dmoszynski Mar 25, 2024
2e956c7
Merge branch 'master' into feature/respawn-entity
yamacir-kit Mar 26, 2024
40742a3
Merge remote-tracking branch 'origin/master' into feature/respawn-entity
dmoszynski Apr 2, 2024
351372f
fix(respawn): fix after merge - add updateFrame, adjust isEgo
dmoszynski Apr 3, 2024
7bee36d
feat(EgoEntity): add setControlledBySimulator
dmoszynski Apr 3, 2024
1b9639f
ref(respawn): improve current solution
dmoszynski Apr 3, 2024
bedf9ec
ref(respawn): remove engagable() check
dmoszynski Apr 4, 2024
d38635c
Merge remote-tracking branch 'origin/master' into feature/respawn-entity
dmoszynski Apr 5, 2024
cedf51d
Merge branch 'master' into feature/respawn-entity
yamacir-kit Apr 19, 2024
1578d30
ref(traffic_simulator, respawn): apply requested PR changes
dmoszynski Apr 22, 2024
dd7819f
Merge branch 'master' into feature/respawn-entity
dmoszynski May 6, 2024
fa0d043
Merge branch 'master' into feature/respawn-entity
yamacir-kit May 7, 2024
16f7c6b
ref(sss, concealer): apply requested PR changes - style
dmoszynski May 8, 2024
237d0f4
fix(sss): missing adaptation change - get_parameter
dmoszynski May 8, 2024
a37ad9c
Merge branch 'master' into feature/respawn-entity
dmoszynski May 8, 2024
7d75bb9
Merge branch 'master' into feature/respawn-entity
dmoszynski May 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ class FieldOperatorApplication : public rclcpp::Node
* -------------------------------------------------------------------------- */
virtual auto plan(const std::vector<geometry_msgs::msg::PoseStamped> &) -> void = 0;

virtual auto clearRoute() -> void = 0;

virtual auto getAutowareStateName() const -> std::string = 0;

virtual auto getMinimumRiskManeuverBehaviorName() const -> std::string = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#endif

#include <autoware_adapi_v1_msgs/msg/mrm_state.hpp>
#include <autoware_adapi_v1_msgs/srv/clear_route.hpp>
#include <autoware_adapi_v1_msgs/srv/initialize_localization.hpp>
#include <autoware_adapi_v1_msgs/srv/set_route_points.hpp>
#include <autoware_auto_control_msgs/msg/ackermann_control_command.hpp>
Expand Down Expand Up @@ -68,6 +69,7 @@ class FieldOperatorApplicationFor<AutowareUniverse>
ServiceWithValidation<tier4_external_api_msgs::srv::Engage> requestEngage;
ServiceWithValidation<autoware_adapi_v1_msgs::srv::InitializeLocalization> requestInitialPose;
ServiceWithValidation<autoware_adapi_v1_msgs::srv::SetRoutePoints> requestSetRoutePoints;
ServiceWithValidation<autoware_adapi_v1_msgs::srv::ClearRoute> requestClearRoute;
dmoszynski marked this conversation as resolved.
Show resolved Hide resolved
ServiceWithValidation<tier4_rtc_msgs::srv::AutoModeWithModule> requestSetRtcAutoMode;
ServiceWithValidation<tier4_external_api_msgs::srv::SetVelocityLimit> requestSetVelocityLimit;
// clang-format on
Expand Down Expand Up @@ -127,6 +129,7 @@ class FieldOperatorApplicationFor<AutowareUniverse>
requestInitialPose("/api/localization/initialize", *this),
// NOTE: /api/routing/set_route_points takes a long time to return. But the specified duration is not decided by any technical reasons.
requestSetRoutePoints("/api/routing/set_route_points", *this, std::chrono::seconds(10)),
requestClearRoute("/api/routing/clear_route", *this),
dmoszynski marked this conversation as resolved.
Show resolved Hide resolved
requestSetRtcAutoMode("/api/external/set/rtc_auto_mode", *this),
requestSetVelocityLimit("/api/autoware/set/velocity_limit", *this),
getPathWithLaneId("/planning/scenario_planning/lane_driving/behavior_planning/path_with_lane_id", *this)
Expand Down Expand Up @@ -159,6 +162,8 @@ class FieldOperatorApplicationFor<AutowareUniverse>

auto plan(const std::vector<geometry_msgs::msg::PoseStamped> &) -> void override;

auto clearRoute() -> void override;

auto requestAutoModeForCooperation(const std::string &, bool) -> void override;

auto restrictTargetSpeed(double) const -> double override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,15 @@ auto FieldOperatorApplicationFor<AutowareUniverse>::plan(
});
}

auto FieldOperatorApplicationFor<AutowareUniverse>::clearRoute() -> void
{
task_queue.delay([this] {
auto request = std::make_shared<autoware_adapi_v1_msgs::srv::ClearRoute::Request>();

requestClearRoute(request);
dmoszynski marked this conversation as resolved.
Show resolved Hide resolved
});
}

auto FieldOperatorApplicationFor<AutowareUniverse>::engage() -> void
{
task_queue.delay([this]() {
Expand Down
2 changes: 2 additions & 0 deletions mock/cpp_mock_scenarios/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ if(BUILD_CPP_MOCK_SCENARIOS)
add_subdirectory(src/pedestrian)
add_subdirectory(src/random_scenario)
add_subdirectory(src/speed_planning)
# add_subdirectory(src/respawn_ego)
yamacir-kit marked this conversation as resolved.
Show resolved Hide resolved

endif()

install(
Expand Down
24 changes: 5 additions & 19 deletions mock/cpp_mock_scenarios/src/cpp_scenario_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ void CppScenarioNode::spawnEgoEntity(
api_.updateFrame();
std::this_thread::sleep_for(std::chrono::duration<double>(1.0 / 20.0));
api_.spawn("ego", spawn_lanelet_pose, parameters, traffic_simulator::VehicleBehavior::autoware());
api_.asFieldOperatorApplication("ego").declare_parameter<bool>("allow_goal_modification", true);
api_.attachLidarSensor("ego", 0.0);

api_.attachDetectionSensor("ego", 200.0, true, 0.0, 0, 0.0, 0.0);
Expand All @@ -112,30 +113,15 @@ void CppScenarioNode::spawnEgoEntity(
return configuration;
}());
api_.requestAssignRoute("ego", goal_lanelet_poses);

using namespace std::chrono_literals;
std::atomic<bool> initialized(false);
auto initialize_thread = std::thread([&]() {
while (!api_.asFieldOperatorApplication("ego").engaged()) {
api_.updateFrame();
std::this_thread::sleep_for(std::chrono::duration<double>(1.0 / 20.0));
}
initialized.store(true);
});
std::atomic<bool> engaged(false);
auto engage_thread = std::thread([&]() {
while (!api_.asFieldOperatorApplication("ego").engaged()) {
while (!api_.asFieldOperatorApplication("ego").engaged()) {
if (api_.asFieldOperatorApplication("ego").engageable()) {
api_.asFieldOperatorApplication("ego").engage();
std::this_thread::sleep_for(1000ms);
}
engaged.store(true);
});
while (!api_.asFieldOperatorApplication("ego").engaged() &&
!(initialized.load() && engaged.load())) {
// RCLCPP_INFO_STREAM(get_logger(), "Waiting for Autoware initialization...");
api_.updateFrame();
std::this_thread::sleep_for(std::chrono::duration<double>(1.0 / 20.0));
}
initialize_thread.join();
engage_thread.join();
}

void CppScenarioNode::checkConfiguration(const traffic_simulator::Configuration & configuration)
Expand Down
14 changes: 14 additions & 0 deletions mock/cpp_mock_scenarios/src/respawn_ego/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ament_auto_add_executable(respawn_ego
respawn_ego.cpp
)
target_link_libraries(respawn_ego cpp_scenario_node)

install(TARGETS
respawn_ego
DESTINATION lib/cpp_mock_scenarios
)

if(BUILD_TESTING)
include(../../cmake/add_cpp_mock_scenario_test.cmake)
add_cpp_mock_scenario_test(${PROJECT_NAME} "respawn_ego" "40.0")
endif()
78 changes: 78 additions & 0 deletions mock/cpp_mock_scenarios/src/respawn_ego/respawn_ego.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright 2015 TIER IV, Inc. All rights reserved.
//
// 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 <ament_index_cpp/get_package_share_directory.hpp>
#include <cpp_mock_scenarios/catalogs.hpp>
#include <cpp_mock_scenarios/cpp_scenario_node.hpp>
#include <memory>
#include <rclcpp/rclcpp.hpp>
#include <string>
#include <traffic_simulator/api/api.hpp>
#include <vector>

namespace cpp_mock_scenarios
{
class RespawnEgoScenario : public cpp_mock_scenarios::CppScenarioNode
{
public:
explicit RespawnEgoScenario(const rclcpp::NodeOptions & option)
: cpp_mock_scenarios::CppScenarioNode(
"respawn_ego", ament_index_cpp::get_package_share_directory("kashiwanoha_map") + "/map",
"lanelet2_map.osm", __FILE__, false, option),
goal_pose{
api_.canonicalize(traffic_simulator::helper::constructLaneletPose(34606, 0, 0, 0, 0, 0))},
new_position_subscriber{create_subscription<geometry_msgs::msg::PoseWithCovarianceStamped>(
"/initialpose", rclcpp::QoS(rclcpp::KeepLast(1)).reliable(),
[this](const geometry_msgs::msg::PoseWithCovarianceStamped & message) {
geometry_msgs::msg::PoseStamped goal_msg;
goal_msg.header.frame_id = "map";
goal_msg.pose = api_.toMapPose(goal_pose);
api_.respawn("ego", message, goal_msg);
})}
{
start();
}

private:
void onUpdate() override
{
if (api_.getCurrentTime() >= 30) {
stop(cpp_mock_scenarios::Result::SUCCESS);
}
}

void onInitialize() override
{
spawnEgoEntity(
api_.canonicalize(traffic_simulator::helper::constructLaneletPose(34621, 10, 0, 0, 0, 0)),
{goal_pose}, getVehicleParameters());
}

private:
const traffic_simulator::lanelet_pose::CanonicalizedLaneletPose goal_pose;

const rclcpp::Subscription<geometry_msgs::msg::PoseWithCovarianceStamped>::SharedPtr
new_position_subscriber;
};
} // namespace cpp_mock_scenarios

int main(int argc, char * argv[])
{
rclcpp::init(argc, argv);
rclcpp::NodeOptions options;
auto component = std::make_shared<cpp_mock_scenarios::RespawnEgoScenario>(options);
rclcpp::spin(component);
rclcpp::shutdown();
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ static auto getParameter(const std::string & name, T value = {})
return value;
}

template <typename T>
static auto getParameterFromExistingNode(
rclcpp::Node & node, const std::string & name, T value = {})
{
node.declare_parameter<T>(name, value);
node.get_parameter<T>(name, value);

return value;
}
dmoszynski marked this conversation as resolved.
Show resolved Hide resolved

EgoEntitySimulation::EgoEntitySimulation(
const traffic_simulator_msgs::msg::VehicleParameters & parameters, double step_time,
const std::shared_ptr<hdmap_utils::HdMapUtils> & hdmap_utils,
Expand Down Expand Up @@ -97,22 +107,23 @@ auto EgoEntitySimulation::makeSimulationModel(
const traffic_simulator_msgs::msg::VehicleParameters & parameters)
-> const std::shared_ptr<SimModelInterface>
{
rclcpp::Node node{"get_parameter", "simulation"};
// clang-format off
const auto acc_time_constant = getParameter<double>("acc_time_constant", 0.1);
const auto acc_time_delay = getParameter<double>("acc_time_delay", 0.1);
const auto acceleration_map_path = getParameter<std::string>("acceleration_map_path", "");
const auto debug_acc_scaling_factor = getParameter<double>("debug_acc_scaling_factor", 1.0);
const auto debug_steer_scaling_factor = getParameter<double>("debug_steer_scaling_factor", 1.0);
const auto steer_lim = getParameter<double>("steer_lim", parameters.axles.front_axle.max_steering); // 1.0
const auto steer_dead_band = getParameter<double>("steer_dead_band", 0.0);
const auto steer_rate_lim = getParameter<double>("steer_rate_lim", 5.0);
const auto steer_time_constant = getParameter<double>("steer_time_constant", 0.27);
const auto steer_time_delay = getParameter<double>("steer_time_delay", 0.24);
const auto vel_lim = getParameter<double>("vel_lim", parameters.performance.max_speed); // 50.0
const auto vel_rate_lim = getParameter<double>("vel_rate_lim", parameters.performance.max_acceleration); // 7.0
const auto vel_time_constant = getParameter<double>("vel_time_constant", 0.1); /// @note 0.5 is default value on simple_planning_simulator
const auto vel_time_delay = getParameter<double>("vel_time_delay", 0.1); /// @note 0.25 is default value on simple_planning_simulator
const auto wheel_base = getParameter<double>("wheel_base", parameters.axles.front_axle.position_x - parameters.axles.rear_axle.position_x);
const auto acc_time_constant = getParameterFromExistingNode<double>(node, "acc_time_constant", 0.1);
const auto acc_time_delay = getParameterFromExistingNode<double>(node, "acc_time_delay", 0.1);
const auto acceleration_map_path = getParameterFromExistingNode<std::string>(node, "acceleration_map_path", "");
const auto debug_acc_scaling_factor = getParameterFromExistingNode<double>(node, "debug_acc_scaling_factor", 1.0);
const auto debug_steer_scaling_factor = getParameterFromExistingNode<double>(node, "debug_steer_scaling_factor", 1.0);
const auto steer_lim = getParameterFromExistingNode<double>(node, "steer_lim", parameters.axles.front_axle.max_steering); // 1.0
const auto steer_dead_band = getParameterFromExistingNode<double>(node, "steer_dead_band", 0.0);
const auto steer_rate_lim = getParameterFromExistingNode<double>(node, "steer_rate_lim", 5.0);
const auto steer_time_constant = getParameterFromExistingNode<double>(node, "steer_time_constant", 0.27);
const auto steer_time_delay = getParameterFromExistingNode<double>(node, "steer_time_delay", 0.24);
const auto vel_lim = getParameterFromExistingNode<double>(node, "vel_lim", parameters.performance.max_speed); // 50.0
const auto vel_rate_lim = getParameterFromExistingNode<double>(node, "vel_rate_lim", parameters.performance.max_acceleration); // 7.0
const auto vel_time_constant = getParameterFromExistingNode<double>(node, "vel_time_constant", 0.1); /// @note 0.5 is default value on simple_planning_simulator
const auto vel_time_delay = getParameterFromExistingNode<double>(node, "vel_time_delay", 0.1); /// @note 0.25 is default value on simple_planning_simulator
const auto wheel_base = getParameterFromExistingNode<double>(node, "wheel_base", parameters.axles.front_axle.position_x - parameters.axles.rear_axle.position_x);
// clang-format on

switch (vehicle_model_type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ class API
bool despawn(const std::string & name);
bool despawnEntities();

void respawn(
const std::string & name, const geometry_msgs::msg::PoseWithCovarianceStamped & new_pose,
const geometry_msgs::msg::PoseStamped & goal_pose);
dmoszynski marked this conversation as resolved.
Show resolved Hide resolved

auto setEntityStatus(const std::string & name, const CanonicalizedEntityStatus &) -> void;
auto setEntityStatus(
const std::string & name, const geometry_msgs::msg::Pose & map_pose,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ class EgoEntity : public VehicleEntity

auto isControlledBySimulator() const -> bool override;

auto setControlledBySimulator(bool state) -> void override
{
is_controlled_by_simulator_ = state;
}

auto setBehaviorParameter(const traffic_simulator_msgs::msg::BehaviorParameter &)
-> void override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ class EntityBase

virtual auto getBehaviorParameter() const -> traffic_simulator_msgs::msg::BehaviorParameter = 0;

virtual auto getVehicleParameters() const
-> const traffic_simulator_msgs::msg::VehicleParameters = 0;
dmoszynski marked this conversation as resolved.
Show resolved Hide resolved

virtual auto getDefaultDynamicConstraints() const
-> const traffic_simulator_msgs::msg::DynamicConstraints & = 0;

Expand Down Expand Up @@ -186,6 +189,8 @@ class EntityBase

virtual auto isControlledBySimulator() const -> bool;

virtual auto setControlledBySimulator(bool) -> void;

virtual auto requestFollowTrajectory(
const std::shared_ptr<traffic_simulator_msgs::msg::PolylineTrajectory> &) -> void;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,15 @@ class EntityManager
FORWARD_TO_ENTITY(setAccelerationLimit, );
FORWARD_TO_ENTITY(setAccelerationRateLimit, );
FORWARD_TO_ENTITY(setBehaviorParameter, );
FORWARD_TO_ENTITY(setControlledBySimulator, );
FORWARD_TO_ENTITY(setDecelerationLimit, );
FORWARD_TO_ENTITY(setDecelerationRateLimit, );
FORWARD_TO_ENTITY(setLinearJerk, );
FORWARD_TO_ENTITY(setLinearVelocity, );
FORWARD_TO_ENTITY(setMapPose, );
FORWARD_TO_ENTITY(setTwist, );
FORWARD_TO_ENTITY(setVelocityLimit, );
FORWARD_TO_ENTITY(getVehicleParameters, );
dmoszynski marked this conversation as resolved.
Show resolved Hide resolved

#undef FORWARD_TO_ENTITY

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ class MiscObjectEntity : public EntityBase

auto getBehaviorParameter() const -> traffic_simulator_msgs::msg::BehaviorParameter override;

auto getVehicleParameters() const -> const traffic_simulator_msgs::msg::VehicleParameters override
{
THROW_SEMANTIC_ERROR("getVehicleParameters function cannot be used in MiscObjectEntity");
}

void setBehaviorParameter(const traffic_simulator_msgs::msg::BehaviorParameter &) override;

void setVelocityLimit(double) override{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ class PedestrianEntity : public EntityBase

void setBehaviorParameter(const traffic_simulator_msgs::msg::BehaviorParameter &);

auto getVehicleParameters() const -> const traffic_simulator_msgs::msg::VehicleParameters override
{
THROW_SEMANTIC_ERROR("getVehicleParameters function cannot be used in PedestrianEntity");
}
void setVelocityLimit(double linear_velocity) override;

void setAccelerationLimit(double acceleration) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ class VehicleEntity : public EntityBase

auto getWaypoints() -> const traffic_simulator_msgs::msg::WaypointsArray override;

auto getVehicleParameters() const
-> const traffic_simulator_msgs::msg::VehicleParameters override;

void onUpdate(double current_time, double step_time) override;

void requestAcquirePosition(const CanonicalizedLaneletPose &);
Expand Down
Loading
Loading