|
| 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 | +} |
0 commit comments