Skip to content

Commit 294dee6

Browse files
authored
Merge pull request tier4#1323 from tier4/fix/spawn_position_of_map_pose
Fill x/y value when spawning entity in map frame.
2 parents 6fbb5c9 + f9c45bb commit 294dee6

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed

mock/cpp_mock_scenarios/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ if(BUILD_CPP_MOCK_SCENARIOS)
5353
add_subdirectory(src/move_backward)
5454
add_subdirectory(src/pedestrian)
5555
add_subdirectory(src/random_scenario)
56+
add_subdirectory(src/spawn)
5657
add_subdirectory(src/speed_planning)
5758
add_subdirectory(src/traffic_source)
5859
add_subdirectory(src/synchronized_action)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
ament_auto_add_executable(spawn_in_map_frame
2+
spawn_in_map_frame.cpp
3+
)
4+
target_link_libraries(spawn_in_map_frame cpp_scenario_node)
5+
6+
install(TARGETS
7+
spawn_in_map_frame
8+
DESTINATION lib/cpp_mock_scenarios
9+
)
10+
11+
if(BUILD_TESTING)
12+
include(../../cmake/add_cpp_mock_scenario_test.cmake)
13+
add_cpp_mock_scenario_test(${PROJECT_NAME} "spawn_in_map_frame" "5.0")
14+
endif()
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright 2015 TIER IV, Inc. All rights reserved.
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 <ament_index_cpp/get_package_share_directory.hpp>
16+
#include <cpp_mock_scenarios/catalogs.hpp>
17+
#include <cpp_mock_scenarios/cpp_scenario_node.hpp>
18+
#include <memory>
19+
#include <rclcpp/rclcpp.hpp>
20+
#include <string>
21+
#include <traffic_simulator/api/api.hpp>
22+
#include <traffic_simulator_msgs/msg/behavior_parameter.hpp>
23+
#include <vector>
24+
25+
namespace cpp_mock_scenarios
26+
{
27+
class SpawnInMapFrameScenario : public cpp_mock_scenarios::CppScenarioNode
28+
{
29+
public:
30+
explicit SpawnInMapFrameScenario(const rclcpp::NodeOptions & option)
31+
: cpp_mock_scenarios::CppScenarioNode(
32+
"stop_at_crosswalk", ament_index_cpp::get_package_share_directory("kashiwanoha_map") + "/map",
33+
"lanelet2_map.osm", __FILE__, false, option)
34+
{
35+
start();
36+
}
37+
38+
private:
39+
void onUpdate() override
40+
{
41+
const auto map_pose = traffic_simulator::pose::toMapPose(
42+
traffic_simulator::helper::constructCanonicalizedLaneletPose(
43+
120545, 0.0, 0.0, api_.getHdmapUtils()));
44+
if (api_.reachPosition("ego", map_pose, 0.1)) {
45+
stop(cpp_mock_scenarios::Result::SUCCESS);
46+
} else {
47+
stop(cpp_mock_scenarios::Result::FAILURE);
48+
}
49+
}
50+
51+
void onInitialize() override
52+
{
53+
api_.spawn(
54+
"ego",
55+
traffic_simulator::pose::toMapPose(
56+
traffic_simulator::helper::constructCanonicalizedLaneletPose(
57+
120545, 0.0, 0.0, api_.getHdmapUtils())),
58+
getVehicleParameters());
59+
}
60+
};
61+
} // namespace cpp_mock_scenarios
62+
63+
int main(int argc, char * argv[])
64+
{
65+
rclcpp::init(argc, argv);
66+
rclcpp::NodeOptions options;
67+
auto component = std::make_shared<cpp_mock_scenarios::SpawnInMapFrameScenario>(options);
68+
rclcpp::spin(component);
69+
rclcpp::shutdown();
70+
return 0;
71+
}

simulation/traffic_simulator/include/traffic_simulator/entity/entity_manager.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ class EntityManager
480480
entity_status.pose = toMapPose(pose);
481481
return CanonicalizedEntityStatus(entity_status, pose);
482482
} else if constexpr (std::is_same_v<std::decay_t<Pose>, geometry_msgs::msg::Pose>) {
483+
entity_status.pose = pose;
483484
const auto canonicalized_lanelet_pose = toCanonicalizedLaneletPose(
484485
pose, parameters.bounding_box, include_crosswalk, matching_distance, hdmap_utils_ptr_);
485486
return CanonicalizedEntityStatus(entity_status, canonicalized_lanelet_pose);

0 commit comments

Comments
 (0)