-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CARLA waypoint publisher to ROS bridge (#164)
* Add waypoint publisher * change topic name * Fix code style issues with Autopep8 * Fix code style issues with clang_format --------- Co-authored-by: WATonomousAdmin <[email protected]>
- Loading branch information
1 parent
3f71d36
commit 17cd0c5
Showing
5 changed files
with
107 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
Node to add frame IDs to the waypoints being published by carla_waypoint_publisher | ||
*/ | ||
|
||
#include "nav_msgs/msg/path.hpp" | ||
#include "rclcpp/rclcpp.hpp" | ||
|
||
class Waypoint_Modifier_Node : public rclcpp::Node { | ||
public: | ||
Waypoint_Modifier_Node() : Node("carla_waypoint_fix") { | ||
// Declare Parameters | ||
this->declare_parameter("input_topic", "/carla/ego/waypointsOld"); | ||
this->declare_parameter("output_topic", "/carla/ego/waypoints"); | ||
|
||
// Get Parameters | ||
std::string input_topic = this->get_parameter("input_topic").as_string(); | ||
std::string output_topic = this->get_parameter("output_topic").as_string(); | ||
|
||
// Subscribe to path | ||
pathSub = this->create_subscription<nav_msgs::msg::Path>( | ||
input_topic, 1, | ||
std::bind(&Waypoint_Modifier_Node::publish_path, this, std::placeholders::_1)); | ||
|
||
// Create Publisher | ||
auto qos = rclcpp::QoS(rclcpp::KeepAll()) | ||
.reliability(RMW_QOS_POLICY_RELIABILITY_RELIABLE) | ||
.durability(RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL); | ||
this->pathPub = this->create_publisher<nav_msgs::msg::Path>(output_topic, qos); | ||
} | ||
|
||
private: | ||
void publish_path(nav_msgs::msg::Path::SharedPtr pathIn) { | ||
std::string frame_id = pathIn->header.frame_id; | ||
path.header = pathIn->header; | ||
path.poses = pathIn->poses; | ||
for (auto &pose : path.poses) { | ||
pose.header.frame_id = frame_id; | ||
} | ||
pathPub->publish(path); | ||
} | ||
|
||
rclcpp::Subscription<nav_msgs::msg::Path>::SharedPtr pathSub; | ||
rclcpp::Publisher<nav_msgs::msg::Path>::SharedPtr pathPub; | ||
|
||
nav_msgs::msg::Path path; | ||
}; | ||
|
||
int main(int argc, char **argv) { | ||
// Initialize ROS2 | ||
rclcpp::init(argc, argv); | ||
|
||
// Create Node | ||
auto node = std::make_shared<Waypoint_Modifier_Node>(); | ||
|
||
rclcpp::spin(node); | ||
|
||
rclcpp::shutdown(); | ||
|
||
return 0; | ||
} |