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

fix: mock test launch option #1496

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions mock/cpp_mock_scenarios/launch/mock_test.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def launch_setup(context, *args, **kwargs):
scenario = LaunchConfiguration("scenario", default=Path("/dev/null"))
sensor_model = LaunchConfiguration("sensor_model", default="")
sigterm_timeout = LaunchConfiguration("sigterm_timeout", default=8)
simulate_localization = LaunchConfiguration("simulate_localization", default=True)
use_sim_time = LaunchConfiguration("use_sim_time", default=False)
vehicle_model = LaunchConfiguration("vehicle_model", default="")
scenario_package = LaunchConfiguration("package", default="cpp_mock_scenarios")
Expand All @@ -147,6 +148,7 @@ def launch_setup(context, *args, **kwargs):
print(f"scenario := {scenario.perform(context)}")
print(f"sensor_model := {sensor_model.perform(context)}")
print(f"sigterm_timeout := {sigterm_timeout.perform(context)}")
print(f"simulate_localization := {simulate_localization.perform(context)}")
print(f"use_sim_time := {use_sim_time.perform(context)}")
print(f"vehicle_model := {vehicle_model.perform(context)}")
print(f"scenario_package := {scenario_package.perform(context)}")
Expand All @@ -167,6 +169,7 @@ def make_parameters():
{"rviz_config": rviz_config},
{"sensor_model": sensor_model},
{"sigterm_timeout": sigterm_timeout},
{"simulate_localization": simulate_localization},
{"vehicle_model": vehicle_model},
{"global_real_time_factor": global_real_time_factor},
{"global_frame_rate": global_frame_rate},
Expand Down Expand Up @@ -224,6 +227,7 @@ def description():
DeclareLaunchArgument("scenario", default_value=scenario ),
DeclareLaunchArgument("sensor_model", default_value=sensor_model ),
DeclareLaunchArgument("sigterm_timeout", default_value=sigterm_timeout ),
DeclareLaunchArgument("simulate_localization", default_value=simulate_localization ),
DeclareLaunchArgument("use_sim_time", default_value=use_sim_time ),
DeclareLaunchArgument("vehicle_model", default_value=vehicle_model ),
DeclareLaunchArgument("scenario_package", default_value=scenario_package ),
Expand Down
28 changes: 26 additions & 2 deletions mock/cpp_mock_scenarios/src/respawn_ego/respawn_ego.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,39 @@ class RespawnEgoScenario : public cpp_mock_scenarios::CppScenarioNode
goal_msg.header.frame_id = "map";
goal_msg.pose = static_cast<geometry_msgs::msg::Pose>(goal_pose);
api_.respawn("ego", message, goal_msg);
})}
})},
has_done_respawn{false}
{
start();
}

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

if (api_.isInLanelet("ego", 34564, 0.1)) {
stop(cpp_mock_scenarios::Result::SUCCESS);
}

if (api_.getCurrentTime() >= 10 && !has_done_respawn) {
geometry_msgs::msg::PoseWithCovarianceStamped ego_pose;
ego_pose.header.frame_id = "map";
ego_pose.pose.pose = static_cast<geometry_msgs::msg::Pose>(
traffic_simulator::helper::constructCanonicalizedLaneletPose(
34576, 10.0, 0.0, api_.getHdmapUtils()));

geometry_msgs::msg::PoseStamped goal_pose;
goal_pose.header.frame_id = "map";
goal_pose.pose = static_cast<geometry_msgs::msg::Pose>(
traffic_simulator::helper::constructCanonicalizedLaneletPose(
34564, 10.0, 0.0, api_.getHdmapUtils()));
api_.respawn("ego", ego_pose, goal_pose);

has_done_respawn = true;
}
}

void onInitialize() override
Expand All @@ -65,6 +87,8 @@ class RespawnEgoScenario : public cpp_mock_scenarios::CppScenarioNode

const rclcpp::Subscription<geometry_msgs::msg::PoseWithCovarianceStamped>::SharedPtr
new_position_subscriber;

bool has_done_respawn;
};
} // namespace cpp_mock_scenarios

Expand Down
Loading