MCPcopy Create free account
hub / github.com/botbotrobotics/BotBrain / useNav2Waypoints

Function useNav2Waypoints

frontend/src/hooks/ros/useNav2Waypoints.tsx:84–610  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

82}
83
84export default function useNav2Waypoints() {
85 // Log deprecation warning once per mount
86 useEffect(() => {
87 console.warn(
88 '[DEPRECATED] useNav2Waypoints is deprecated. ' +
89 'Please migrate to useFollowWaypoints which properly uses the Nav2 FollowWaypoints action server.'
90 );
91 }, []);
92
93 const { connection } = useRobotConnection();
94 const robotPose = useMapPose();
95 const [isNavigating, setIsNavigating] = useState(false);
96 const [currentWaypointIndex, setCurrentWaypointIndex] = useState(0);
97 const [navigationError, setNavigationError] = useState<string | null>(null);
98 const [actionServerConnected, setActionServerConnected] = useState(false);
99 const [retryCount, setRetryCount] = useState(0);
100 const [useSingleGoalFallback, setUseSingleGoalFallback] = useState(false);
101 const [remainingWaypoints, setRemainingWaypoints] = useState<Waypoint[]>([]);
102 const [goalReachedThreshold] = useState({ position: 0.5, orientation: 0.5 }); // meters and radians
103 const lastLogTimeRef = useRef<number>(0);
104 const lastMonitorLogRef = useRef<number>(0);
105 const goalTopicRef = useRef<ROSLIB.Topic<unknown> | null>(null);
106 const maxRetries = 3;
107
108 // NavigateThroughPoses action client
109 const actionClient = useMemo(() => {
110 if (!connection.ros || !connection.online) return null;
111
112 // Create action client for NavigateThroughPoses
113 // Try without leading slash as some ROS2 setups don't use it
114 const client = new ROSLIB.ActionClient({
115 ros: connection.ros,
116 serverName: 'navigate_through_poses',
117 actionName: 'nav2_msgs/action/NavigateThroughPoses'
118 });
119
120 // Check if action server is available by querying the action server
121 // This is a workaround since ROSLIB doesn't have a direct connection check
122 try {
123 // Set a flag to indicate the client was created successfully
124 setActionServerConnected(true);
125 } catch (error) {
126 console.error('Failed to create Nav2 action client:', error);
127 setActionServerConnected(false);
128 }
129
130 return client;
131 }, [connection.ros, connection.online]);
132
133 // Check if action server is available when client changes
134 useEffect(() => {
135 if (actionClient && connection.ros && connection.online) {
136 // Test if server is available by checking ROS connection
137 // In a real implementation, you might want to check available action servers
138 const checkServerAvailability = () => {
139 // This is a simple check - a more robust solution would query available action servers
140 const isAvailable = !!(connection.ros && connection.online);
141 setActionServerConnected(isAvailable);

Callers 1

MapViewNav2Function · 0.85

Calls 5

useRobotConnectionFunction · 0.90
getRosTopicFunction · 0.90
useMapPoseFunction · 0.85
checkServerAvailabilityFunction · 0.85
logMethod · 0.80

Tested by

no test coverage detected