|
| 1 | +// Copyright 2024 TIER IV, Inc. |
| 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 | + * Software License Agreement (BSD License) |
| 16 | + * |
| 17 | + * Copyright (c) 2012, Willow Garage, Inc. |
| 18 | + * All rights reserved. |
| 19 | + * |
| 20 | + * Redistribution and use in source and binary forms, with or without |
| 21 | + * modification, are permitted provided that the following conditions |
| 22 | + * are met: |
| 23 | + * |
| 24 | + * * Redistributions of source code must retain the above copyright |
| 25 | + * notice, this list of conditions and the following disclaimer. |
| 26 | + * * Redistributions in binary form must reproduce the above |
| 27 | + * copyright notice, this list of conditions and the following |
| 28 | + * disclaimer in the documentation and/or other materials provided |
| 29 | + * with the distribution. |
| 30 | + * * Neither the name of Willow Garage, Inc. nor the names of its |
| 31 | + * contributors may be used to endorse or promote products derived |
| 32 | + * from this software without specific prior written permission. |
| 33 | + * |
| 34 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 35 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 36 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 37 | + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 38 | + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 39 | + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 40 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 41 | + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 42 | + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 43 | + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 44 | + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 45 | + * POSSIBILITY OF SUCH DAMAGE. |
| 46 | + */ |
| 47 | + |
| 48 | +#include "automatic_checkpoint_append_tool.hpp" |
| 49 | + |
| 50 | +#ifdef ROS_DISTRO_GALACTIC |
| 51 | +#include <tf2_geometry_msgs/tf2_geometry_msgs.h> |
| 52 | +#else |
| 53 | +#include <tf2_geometry_msgs/tf2_geometry_msgs.hpp> |
| 54 | +#endif |
| 55 | +#include <tf2_ros/transform_listener.h> |
| 56 | + |
| 57 | +#include <string> |
| 58 | + |
| 59 | +namespace rviz_plugins |
| 60 | +{ |
| 61 | +AutowareAutomaticCheckpointTool::AutowareAutomaticCheckpointTool() |
| 62 | +{ |
| 63 | + shortcut_key_ = 'c'; |
| 64 | + |
| 65 | + pose_topic_property_ = new rviz_common::properties::StringProperty( |
| 66 | + "Pose Topic", "~/automatic_goal/checkpoint", "The topic on which to publish automatic_goal.", |
| 67 | + getPropertyContainer(), SLOT(updateTopic()), this); |
| 68 | + std_dev_x_ = new rviz_common::properties::FloatProperty( |
| 69 | + "X std deviation", 0.5, "X standard deviation for checkpoint pose [m]", getPropertyContainer()); |
| 70 | + std_dev_y_ = new rviz_common::properties::FloatProperty( |
| 71 | + "Y std deviation", 0.5, "Y standard deviation for checkpoint pose [m]", getPropertyContainer()); |
| 72 | + std_dev_theta_ = new rviz_common::properties::FloatProperty( |
| 73 | + "Theta std deviation", M_PI / 12.0, "Theta standard deviation for checkpoint pose [rad]", |
| 74 | + getPropertyContainer()); |
| 75 | + position_z_ = new rviz_common::properties::FloatProperty( |
| 76 | + "Z position", 0.0, "Z position for checkpoint pose [m]", getPropertyContainer()); |
| 77 | + std_dev_x_->setMin(0); |
| 78 | + std_dev_y_->setMin(0); |
| 79 | + std_dev_theta_->setMin(0); |
| 80 | + position_z_->setMin(0); |
| 81 | +} |
| 82 | + |
| 83 | +void AutowareAutomaticCheckpointTool::onInitialize() |
| 84 | +{ |
| 85 | + PoseTool::onInitialize(); |
| 86 | + setName("2D AppendCheckpoint"); |
| 87 | + updateTopic(); |
| 88 | +} |
| 89 | + |
| 90 | +void AutowareAutomaticCheckpointTool::updateTopic() |
| 91 | +{ |
| 92 | + rclcpp::Node::SharedPtr raw_node = context_->getRosNodeAbstraction().lock()->get_raw_node(); |
| 93 | + pose_pub_ = raw_node->create_publisher<geometry_msgs::msg::PoseStamped>( |
| 94 | + pose_topic_property_->getStdString(), 1); |
| 95 | + clock_ = raw_node->get_clock(); |
| 96 | +} |
| 97 | + |
| 98 | +void AutowareAutomaticCheckpointTool::onPoseSet(double x, double y, double theta) |
| 99 | +{ |
| 100 | + // pose |
| 101 | + std::string fixed_frame = context_->getFixedFrame().toStdString(); |
| 102 | + geometry_msgs::msg::PoseStamped pose; |
| 103 | + pose.header.frame_id = fixed_frame; |
| 104 | + pose.header.stamp = clock_->now(); |
| 105 | + pose.pose.position.x = x; |
| 106 | + pose.pose.position.y = y; |
| 107 | + pose.pose.position.z = position_z_->getFloat(); |
| 108 | + |
| 109 | + tf2::Quaternion quat; |
| 110 | + quat.setRPY(0.0, 0.0, theta); |
| 111 | + pose.pose.orientation = tf2::toMsg(quat); |
| 112 | + RCLCPP_INFO( |
| 113 | + rclcpp::get_logger("AutowareAutomaticCheckpointTool"), |
| 114 | + "Setting pose: %.3f %.3f %.3f %.3f [frame=%s]", x, y, position_z_->getFloat(), theta, |
| 115 | + fixed_frame.c_str()); |
| 116 | + pose_pub_->publish(pose); |
| 117 | +} |
| 118 | + |
| 119 | +} // end namespace rviz_plugins |
| 120 | + |
| 121 | +#include <pluginlib/class_list_macros.hpp> |
| 122 | +PLUGINLIB_EXPORT_CLASS(rviz_plugins::AutowareAutomaticCheckpointTool, rviz_common::Tool) |
0 commit comments