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

Function initializeMap

frontend/src/components/map-view.tsx:150–479  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

148 };
149
150 const initializeMap = async () => {
151 try {
152 console.log('Initializing map viewer...');
153 console.log('ROS2D available:', !!window.ROS2D);
154 console.log('createjs available:', !!window.createjs);
155
156 // Clear previous viewer if exists
157 if (viewerRef.current) {
158 viewerRef.current.scene.removeAllChildren();
159 }
160
161 if (!window.ROS2D) {
162 throw new Error('ROS2D library not loaded');
163 }
164
165 // Create the main viewer
166 const viewer = new window.ROS2D.Viewer({
167 divID: 'ros2d-map',
168 width: mapContainerRef.current!.clientWidth,
169 height: mapContainerRef.current!.clientHeight,
170 background: '#1a1a1a'
171 });
172 viewerRef.current = viewer;
173
174 // Setup the map client - use either costmap or regular map based on toggle
175 const mapTopic = showCostmap ? '/move_base/global_costmap/costmap' : '/map';
176 console.log(`Subscribing to map topic: ${mapTopic}`);
177
178 // Create the occupancy grid client with error handling
179 let gridClient;
180 try {
181 // First, let's verify the map topic exists and has data
182 const mapTestListener = new ROSLIB.Topic({
183 ros: connection.ros!,
184 name: mapTopic,
185 messageType: 'nav_msgs/OccupancyGrid'
186 });
187
188 let mapDataReceived = false;
189 mapTestListener.subscribe((msg: any) => {
190 if (!mapDataReceived) {
191 mapDataReceived = true;
192 console.log('Map test successful - data structure:', {
193 hasHeader: !!msg.header,
194 hasInfo: !!msg.info,
195 hasData: !!msg.data,
196 dataLength: msg.data?.length,
197 width: msg.info?.width,
198 height: msg.info?.height,
199 resolution: msg.info?.resolution,
200 origin: msg.info?.origin
201 });
202 mapTestListener.unsubscribe();
203 }
204 });
205
206 // Small delay to ensure ROS connection is stable
207 await new Promise(resolve => setTimeout(resolve, 500));

Callers 1

loadScriptsFunction · 0.85

Calls 2

testMapSubscriptionFunction · 0.85
logMethod · 0.80

Tested by

no test coverage detected