MCPcopy Create free account
hub / github.com/RoboJackets/software-training / MappingNode

Class MappingNode

mapping/src/mapping_node.cpp:44–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42}
43
44class MappingNode : public rclcpp::Node
45{
46public:
47 explicit MappingNode(const rclcpp::NodeOptions & options)
48 // BEGIN STUDENT CODE
49 : rclcpp::Node("mapping_node", options)
50 // END STUDENT CODE
51 {
52 map_frame_id_ = declare_parameter<std::string>("map_frame", "map");
53 robot_frame_id_ = declare_parameter<std::string>("robot_frame", "base_link");
54 distance_coefficient_ = declare_parameter<double>("distance_coefficient", 0.01);
55 hit_log_odds_ = toLogOdds(declare_parameter<double>("hit_probability", 0.7));
56 miss_log_odds_ = toLogOdds(declare_parameter<double>("miss_probability", 0.3));
57
58 const auto map_width = declare_parameter<double>("map_width", 1.2192); // meters
59 const auto map_height = declare_parameter<double>("map_height", 0.762); // meters
60 const auto map_resolution = declare_parameter<double>("map_resolution", 0.01); // meters/cell
61
62 map_info_.origin.position.x = -map_width / 2.0;
63 map_info_.origin.position.y = -map_height / 2.0;
64 map_info_.height = map_height / map_resolution;
65 map_info_.width = map_width / map_resolution;
66 map_info_.resolution = map_resolution;
67
68 const auto map_data_size = map_info_.height * map_info_.width;
69 map_data_.reserve(map_data_size);
70 std::fill_n(std::back_inserter(map_data_), map_data_size, 0.0);
71
72 map_publisher_ = create_publisher<nav_msgs::msg::OccupancyGrid>(
73 "~/map",
74 rclcpp::SystemDefaultsQoS());
75
76 // BEGIN STUDENT CODE
77 // END STUDENT CODE
78 }
79
80private:
81 // BEGIN STUDENT CODE
82 // END STUDENT CODE
83 std::string map_frame_id_;
84 std::string robot_frame_id_;
85 double distance_coefficient_;
86 double hit_log_odds_;
87 double miss_log_odds_;
88 std::vector<double> map_data_;
89 nav_msgs::msg::MapMetaData map_info_;
90 rclcpp::Publisher<nav_msgs::msg::OccupancyGrid>::SharedPtr map_publisher_;
91 rclcpp::Subscription<nav_msgs::msg::OccupancyGrid>::SharedPtr obstacles_subscription_;
92
93 void ObstaclesCallback(const nav_msgs::msg::OccupancyGrid::SharedPtr obstacles_msg)
94 {
95 // BEGIN STUDENT CODE
96 // END STUDENT CODE
97
98 AddObstaclesToMap(*obstacles_msg);
99
100 nav_msgs::msg::OccupancyGrid map_msg;
101 map_msg.header.frame_id = map_frame_id_;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected