Skip to content

Commit dfd6dee

Browse files
Navigate Observer Node (#546)
* initial file created * node runs --------- Co-authored-by: Akshanjay Kompelli <63443017+FireBoyAJ24@users.noreply.github.com>
1 parent 8f49699 commit dfd6dee

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

src/local_pathfinding/launch/main_launch.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def setup_launch(context: LaunchContext) -> List[Node]:
7373
launch_description_entities.append(get_mock_wind_sensor_node_description(context))
7474
launch_description_entities.append(get_mock_ais_node_description(context))
7575
launch_description_entities.append(get_mock_gps_node_description(context))
76+
launch_description_entities.append(get_navigate_observer_node_description(context))
7677
return launch_description_entities
7778

7879

@@ -199,3 +200,33 @@ def get_mock_gps_node_description(context: LaunchContext) -> Node:
199200
)
200201

201202
return node
203+
204+
205+
def get_navigate_observer_node_description(context: LaunchContext) -> Node:
206+
"""Gets the launch description for the navigate_observer node.
207+
208+
Args:
209+
context (LaunchContext): The current launch context.
210+
211+
Returns:
212+
Node: The node object that launches the navigate_observer node.
213+
"""
214+
node_name = "navigate_observer"
215+
mode = LaunchConfiguration("mode").perform(context)
216+
ros_parameters = [{"mode": mode}, LaunchConfiguration("config").perform(context)]
217+
ros_arguments: List[SomeSubstitutionsType] = [
218+
"--log-level",
219+
[f"{node_name}:=", LaunchConfiguration("log_level")],
220+
]
221+
222+
node = Node(
223+
package=PACKAGE_NAME,
224+
executable="navigate_observer",
225+
name=node_name,
226+
output="screen",
227+
emulate_tty=True,
228+
parameters=ros_parameters,
229+
ros_arguments=ros_arguments,
230+
)
231+
232+
return node
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""
2+
This node observes the navigate node by subscribing to the local_path ROS
3+
topic.
4+
"""
5+
6+
import custom_interfaces.msg as ci
7+
import rclpy
8+
from rclpy.node import Node
9+
10+
11+
def main(args=None):
12+
rclpy.init(args=args)
13+
sailbot = SailbotObserver()
14+
15+
rclpy.spin(node=sailbot)
16+
17+
sailbot.destroy_node()
18+
rclpy.shutdown()
19+
20+
21+
class SailbotObserver(Node):
22+
"""Observes the Sailbot node, through the local_path topic, as it navigates.
23+
24+
Subscribers:
25+
local_path_sub (Subscription): Subscribe to a `LPathData` msg.
26+
27+
Attributes From Subscribers:
28+
local_path: (ci.LPathData
29+
"""
30+
31+
def __init__(self):
32+
super().__init__(node_name="navigate_observer")
33+
34+
self.local_path_sub = self.create_subscription(
35+
msg_type=ci.LPathData,
36+
topic="local_path",
37+
callback=self.local_path_callback,
38+
qos_profile=10,
39+
)
40+
41+
def local_path_callback(self, msg: ci.GPS):
42+
self.get_logger().debug(f"Received data from {self.local_path_sub.topic}: {msg}")
43+
self.local_path_data = msg
44+
45+
46+
if __name__ == "__main__":
47+
main()

src/local_pathfinding/setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"mock_wind_sensor = local_pathfinding.node_mock_wind_sensor:main",
2929
"mock_ais = local_pathfinding.node_mock_ais:main",
3030
"mock_gps = local_pathfinding.node_mock_gps:main",
31+
"navigate_observer = local_pathfinding.node_navigate_observer:main",
3132
],
3233
},
3334
)

0 commit comments

Comments
 (0)