Project

General

Profile

Statistics
| Branch: | Revision:

scoutos / scout / scoutsim / src / sim_frame.cpp @ 28999371

History | View | Annotate | Download (17.1 KB)

1 c492be62 Alex Zirbel
/**
2
 * The code in this package was developed using the structure of Willow
3
 * Garage's turtlesim package.  It was modified by the CMU Robotics Club
4
 * to be used as a simulator for the Colony Scout robot.
5 266ae7f2 Alex Zirbel
 *
6 c492be62 Alex Zirbel
 * All redistribution of this code is limited to the terms of Willow Garage's
7
 * licensing terms, as well as under permission from the CMU Robotics Club.
8
 * 
9
 * Copyright (c) 2011 Colony Project
10
 * 
11
 * Permission is hereby granted, free of charge, to any person
12
 * obtaining a copy of this software and associated documentation
13
 * files (the "Software"), to deal in the Software without
14
 * restriction, including without limitation the rights to use,
15
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
16
 * copies of the Software, and to permit persons to whom the
17
 * Software is furnished to do so, subject to the following
18
 * conditions:
19
 * 
20
 * The above copyright notice and this permission notice shall be
21
 * included in all copies or substantial portions of the Software.
22
 * 
23
 * Copyright (c) 2009, Willow Garage, Inc.
24 266ae7f2 Alex Zirbel
 * All rights reserved.
25 c492be62 Alex Zirbel
 * 
26
 * Redistribution and use in source and binary forms, with or without
27
 * modification, are permitted provided that the following conditions are met:
28
 * 
29
 *    Redistributions of source code must retain the above copyright
30
 *       notice, this list of conditions and the following disclaimer.
31
 *    Redistributions in binary form must reproduce the above copyright
32
 *       notice, this list of conditions and the following disclaimer in the
33
 *       documentation and/or other materials provided with the distribution.
34
 *    Neither the name of the Willow Garage, Inc. nor the names of its
35
 *       contributors may be used to endorse or promote products derived from
36
 *       this software without specific prior written permission.
37
 * 
38
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
39
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
40
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
41
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
42
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
43
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
44
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
45
 * OTHER DEALINGS IN THE SOFTWARE.
46 266ae7f2 Alex Zirbel
 */
47
48 a8480867 Alex Zirbel
#include "sim_frame.h"
49 266ae7f2 Alex Zirbel
50 2eaafff2 Alex
#include <stdio.h>
51
52 266ae7f2 Alex Zirbel
#include <ros/package.h>
53
#include <cstdlib>
54
#include <ctime>
55
56 2eaafff2 Alex
using namespace std;
57 266ae7f2 Alex Zirbel
58
namespace scoutsim
59
{
60 2eaafff2 Alex
    SimFrame::SimFrame(wxWindow* parent, string map_name)
61 266ae7f2 Alex Zirbel
        : wxFrame(parent, wxID_ANY, wxT("ScoutSim"), wxDefaultPosition,
62
                  wxSize(500, 500), wxDEFAULT_FRAME_STYLE & ~wxRESIZE_BORDER)
63 144137a1 Alex Zirbel
          , frame_count(0)
64
          , id_counter(0)
65 266ae7f2 Alex Zirbel
    {
66 2eaafff2 Alex
        std::cout << "Constructing sim frame." << std::endl;
67
68 266ae7f2 Alex Zirbel
        srand(time(NULL));
69
70 144137a1 Alex Zirbel
        update_timer = new wxTimer(this);
71 c63c9752 Alex
        update_timer->Start(SCOUTSIM_REFRESH_RATE * 1000);
72 266ae7f2 Alex Zirbel
73 144137a1 Alex Zirbel
        Connect(update_timer->GetId(), wxEVT_TIMER,
74 266ae7f2 Alex Zirbel
                wxTimerEventHandler(SimFrame::onUpdate), NULL, this);
75
        Connect(wxEVT_PAINT, wxPaintEventHandler(SimFrame::onPaint),
76
                NULL, this);
77
78 594c3bb9 Alex
        images_path = ros::package::getPath("scoutsim") + "/images/";
79 266ae7f2 Alex Zirbel
80 ade1b7f9 Alex
        map_base_name =  ros::package::getPath("scoutsim") + "/maps/" +
81
                           map_name + ".bmp";
82
        map_lines_name = ros::package::getPath("scoutsim") + "/maps/" +
83
                           map_name + "_lines.bmp";
84 7ffad595 Alex
        map_walls_name = ros::package::getPath("scoutsim") + "/maps/" +
85
                           map_name + "_walls.bmp";
86 ade1b7f9 Alex
        display_map_name = map_base_name;
87
88
        wxBitmap lines_bitmap;
89 e2770306 Alex
        wxBitmap walls_bitmap;
90
        path_bitmap.LoadFile(wxString::FromAscii(display_map_name.c_str()));
91 eb9cff77 Hui Jun Tay
        sonar_visual_on = TRUE;
92 e2770306 Alex
93
        // Try to load the file; if it fails, make a new blank file
94
        if (!lines_bitmap.LoadFile(wxString::FromAscii(map_lines_name.c_str())))
95
        {
96
            lines_bitmap = wxBitmap(path_bitmap.GetWidth(), path_bitmap.GetHeight(), 3);
97
        }
98 ade1b7f9 Alex
        lines_image = lines_bitmap.ConvertToImage();
99
100 e2770306 Alex
        // Try to load the file; if it fails, make a new blank file
101
        if (!walls_bitmap.LoadFile(wxString::FromAscii(map_walls_name.c_str())))
102
        {
103
            walls_bitmap = wxBitmap(path_bitmap.GetWidth(), path_bitmap.GetHeight(), 3);
104
        }
105 7ffad595 Alex
        walls_image = walls_bitmap.ConvertToImage();
106
107 266ae7f2 Alex Zirbel
        clear();
108
109 144137a1 Alex Zirbel
        clear_srv = nh.advertiseService("clear",
110 4612f7e4 Alex Zirbel
                                        &SimFrame::clearCallback, this);
111 144137a1 Alex Zirbel
        reset_srv = nh.advertiseService("reset",
112 4612f7e4 Alex Zirbel
                                        &SimFrame::resetCallback, this);
113 144137a1 Alex Zirbel
        spawn_srv = nh.advertiseService("spawn",
114 4612f7e4 Alex Zirbel
                                        &SimFrame::spawnCallback, this);
115 144137a1 Alex Zirbel
        kill_srv = nh.advertiseService("kill",
116 4612f7e4 Alex Zirbel
                                       &SimFrame::killCallback, this);
117 266ae7f2 Alex Zirbel
118 82f3f746 Priya
        // Subscribe and publisher wirless from robots
119 7ffad595 Alex
        wireless_receive = nh.advertise< ::messages::WirelessPacket>(
120
            "/wireless/receive", 1000); 
121
        wireless_send = nh.subscribe("/wireless/send", 1000,
122
            &SimFrame::wirelessCallback, this);
123 82f3f746 Priya
124 0e77683c Alex
        // Teleop
125 ddfeb111 Priya
        teleop_type = TELEOP_PRECISE;
126 0e77683c Alex
        teleop_l_speed = 0;
127
        teleop_r_speed = 0;
128
        teleop_pub = nh.advertise<motors::set_motors>("/scout1/set_motors", 1000);
129
130 266ae7f2 Alex Zirbel
        ROS_INFO("Starting scoutsim with node name %s",
131
                 ros::this_node::getName().c_str()) ;
132
133 2eaafff2 Alex
        wxMenu *menuFile = new wxMenu;
134
        menuFile->Append(ID_ABOUT, _("&About"));
135
        menuFile->AppendSeparator();
136
        menuFile->Append(ID_QUIT, _("E&xit"));
137
138
        wxMenu *menuSim = new wxMenu;
139 68b23184 viki
        menuSim->Append(ID_SONAR, _("S&onar"));
140 2eaafff2 Alex
        menuSim->Append(ID_CLEAR, _("&Clear"));
141
142
        wxMenu *menuView = new wxMenu;
143
        menuView->Append(ID_MAP, _("&Map"));
144
        menuView->Append(ID_LINES, _("&Lines"));
145 7ffad595 Alex
        menuView->Append(ID_WALLS, _("&Walls"));
146 2eaafff2 Alex
147 0e77683c Alex
        wxMenu *menuTeleop = new wxMenu;
148
        menuTeleop->Append(ID_TELEOP_NONE, _("&None"));
149
        menuTeleop->Append(ID_TELEOP_PRECISE, _("&Precise"));
150
        menuTeleop->Append(ID_TELEOP_FLUID, _("&Fluid"));
151
152 2eaafff2 Alex
        wxMenuBar *menuBar = new wxMenuBar;
153
        menuBar->Append(menuFile, _("&File"));
154
        menuBar->Append(menuSim, _("&Sim"));
155
        menuBar->Append(menuView, _("&View"));
156 0e77683c Alex
        menuBar->Append(menuTeleop, _("&Teleop"));
157 2eaafff2 Alex
158
        SetMenuBar(menuBar);
159
160 c63c9752 Alex
        width_in_meters = GetSize().GetWidth() / PIX_PER_METER;
161
        height_in_meters = GetSize().GetHeight() / PIX_PER_METER;
162 25694a03 Priya
163
        spawnScout("scout1", 1.4, .78, 0);
164 266ae7f2 Alex Zirbel
    }
165
166
    SimFrame::~SimFrame()
167
    {
168 144137a1 Alex Zirbel
        delete update_timer;
169 266ae7f2 Alex Zirbel
    }
170
171 4612f7e4 Alex Zirbel
    bool SimFrame::spawnCallback(scoutsim::Spawn::Request  &req,
172
                                 scoutsim::Spawn::Response &res)
173 266ae7f2 Alex Zirbel
    {
174
        std::string name = spawnScout(req.name, req.x, req.y, req.theta);
175
        if (name.empty())
176
        {
177
            ROS_ERROR("A scout named [%s] already exists", req.name.c_str());
178
            return false;
179
        }
180
181
        res.name = name;
182
183
        return true;
184
    }
185
186
    bool SimFrame::killCallback(scoutsim::Kill::Request& req,
187
                                scoutsim::Kill::Response&)
188
    {
189 144137a1 Alex Zirbel
        M_Scout::iterator it = scouts.find(req.name);
190
        if (it == scouts.end())
191 266ae7f2 Alex Zirbel
        {
192
            ROS_ERROR("Tried to kill scout [%s], which does not exist",
193
                      req.name.c_str());
194
            return false;
195
        }
196
197 144137a1 Alex Zirbel
        scouts.erase(it);
198 266ae7f2 Alex Zirbel
199
        return true;
200
    }
201
202
    bool SimFrame::hasScout(const std::string& name)
203
    {
204 144137a1 Alex Zirbel
        return scouts.find(name) != scouts.end();
205 266ae7f2 Alex Zirbel
    }
206
207 9b3564f3 Alex Zirbel
    std::string SimFrame::spawnScout(const std::string& name,
208
                                     float x, float y, float angle)
209 266ae7f2 Alex Zirbel
    {
210
        std::string real_name = name;
211
        if (real_name.empty())
212
        {
213
            do
214
            {
215
                std::stringstream ss;
216 144137a1 Alex Zirbel
                ss << "scout" << ++id_counter;
217 266ae7f2 Alex Zirbel
                real_name = ss.str();
218
            } while (hasScout(real_name));
219
        }
220
        else
221
        {
222
            if (hasScout(real_name))
223
            {
224
                return "";
225
            }
226
        }
227
228 594c3bb9 Alex
        wxImage scout_image;
229
230
        // Try to load a name-specific image; if not, load the default scout
231
        string specific_name = images_path + name + ".png";
232
        if (fileExists(specific_name))
233
        {
234
            scout_image.LoadFile(wxString::FromAscii(specific_name.c_str()));
235
            scout_image.SetMask(true);
236
            scout_image.SetMaskColour(255, 255, 255);
237
        }
238
        else
239
        {
240
            scout_image.LoadFile(
241
                wxString::FromAscii((images_path + "scout.png").c_str()));
242
            scout_image.SetMask(true);
243
            scout_image.SetMaskColour(255, 255, 255);
244
        }
245
246 266ae7f2 Alex Zirbel
        ScoutPtr t(new Scout(ros::NodeHandle(real_name),
247 594c3bb9 Alex
                   scout_image, Vector2(x, y), &path_bitmap, angle));
248 144137a1 Alex Zirbel
        scouts[real_name] = t;
249 266ae7f2 Alex Zirbel
250 0e0ef125 Priya
        ghost_scouts.push_back(new GhostScout(ros::NodeHandle(real_name),
251
                scout_image, Vector2(x, y), &path_bitmap, angle, name));
252
253 266ae7f2 Alex Zirbel
        ROS_INFO("Spawning scout [%s] at x=[%f], y=[%f], theta=[%f]",
254
                 real_name.c_str(), x, y, angle);
255
256
        return real_name;
257
    }
258
259 2eaafff2 Alex
    void SimFrame::onQuit(wxCommandEvent& WXUNUSED(event))
260
    {
261
        Close(true);
262
    }
263
264
    void SimFrame::onAbout(wxCommandEvent& WXUNUSED(event))
265
    {
266
        wxMessageBox(_("Scoutsim is the simulator the Colony Project's scout robot.\n"
267
                       "\nThe Colony Project is a part of the Carnegie Mellon\n"
268
                       "Robotics Club. Our goal is to use cooperative low-cost\n"
269
                       "robots to solve challenging problems."),
270
                     _("About Scoutsim"),
271
                     wxOK | wxICON_INFORMATION, this );
272
    }
273
274
    void SimFrame::onClear(wxCommandEvent& WXUNUSED(event))
275 266ae7f2 Alex Zirbel
    {
276 2eaafff2 Alex
        clear();
277
    }
278 266ae7f2 Alex Zirbel
279 68b23184 viki
    void SimFrame::showSonar(wxCommandEvent& WXUNUSED(event))
280
    {
281 eb9cff77 Hui Jun Tay
        sonar_visual_on = not sonar_visual_on;
282 68b23184 viki
        clear();
283
    }
284
285
286 2eaafff2 Alex
    void SimFrame::showMap(wxCommandEvent& WXUNUSED(event))
287
    {
288 ade1b7f9 Alex
        display_map_name = map_base_name;
289 2eaafff2 Alex
        clear();
290
    }
291 266ae7f2 Alex Zirbel
292 2eaafff2 Alex
    void SimFrame::showLines(wxCommandEvent& WXUNUSED(event))
293
    {
294 ade1b7f9 Alex
        display_map_name = map_lines_name;
295 2eaafff2 Alex
        clear();
296
    }
297 7ffad595 Alex
    
298
    void SimFrame::showWalls(wxCommandEvent& WXUNUSED(event))
299
    {
300
        display_map_name = map_walls_name;
301
        clear();
302
    }
303 2eaafff2 Alex
304
    void SimFrame::clear()
305
    {
306
        path_dc.SetBackground(wxBrush(wxColour(100, 100, 100)));
307 144137a1 Alex Zirbel
        path_dc.Clear();
308 2eaafff2 Alex
309 6639ce9c viki
        sonar_dc.SetBackground(wxBrush(wxColour(255, 0, 0)));
310
        sonar_dc.Clear();
311
312
        sonar_dc.SelectObject(path_bitmap);
313
314 2eaafff2 Alex
        path_bitmap.LoadFile(wxString::FromAscii(display_map_name.c_str()));
315
        path_dc.SelectObject(path_bitmap);
316
        SetSize(wxSize(path_bitmap.GetWidth(), path_bitmap.GetHeight()));
317 266ae7f2 Alex Zirbel
    }
318
319 c63c9752 Alex
    // Runs every SCOUTSIM_REFRESH_RATE.
320 266ae7f2 Alex Zirbel
    void SimFrame::onUpdate(wxTimerEvent& evt)
321
    {
322
        ros::spinOnce();
323
324 0e77683c Alex
        teleop();
325
326 266ae7f2 Alex Zirbel
        updateScouts();
327
328
        if (!ros::ok())
329
        {
330
            Close();
331
        }
332 04114d13 Alex
333
        frame_count++;
334 266ae7f2 Alex Zirbel
    }
335
336
    void SimFrame::onPaint(wxPaintEvent& evt)
337
    {
338
        wxPaintDC dc(this);
339
340 144137a1 Alex Zirbel
        dc.DrawBitmap(path_bitmap, 0, 0, true);
341 266ae7f2 Alex Zirbel
342 144137a1 Alex Zirbel
        M_Scout::iterator it = scouts.begin();
343
        M_Scout::iterator end = scouts.end();
344 266ae7f2 Alex Zirbel
        for (; it != end; ++it)
345
        {
346
            it->second->paint(dc);
347
        }
348 0e0ef125 Priya
        for (unsigned int i=0; i<ghost_scouts.size(); ++i)
349
        {
350
            ghost_scouts.at(i)->paint(dc);
351
        }
352 266ae7f2 Alex Zirbel
    }
353
354 594c3bb9 Alex
    bool SimFrame::fileExists(const std::string& filename)
355
    {
356
        struct stat buf;
357
        if (stat(filename.c_str(), &buf) != -1)
358
        {
359
            return true;
360
        }
361
        return false;
362
    }
363
364 0e77683c Alex
    void SimFrame::stopTeleop(wxCommandEvent& event)
365
    {
366
        teleop_type = TELEOP_OFF;
367
        teleop_l_speed = 0;
368
        teleop_r_speed = 0;
369
    }
370
371
    void SimFrame::startTeleopPrecise(wxCommandEvent& event)
372
    {
373
        teleop_type = TELEOP_PRECISE;
374
        teleop_l_speed = 0;
375
        teleop_r_speed = 0;
376
    }
377
378
    void SimFrame::startTeleopFluid(wxCommandEvent& event)
379
    {
380
        teleop_type = TELEOP_FLUID;
381
        teleop_l_speed = 0;
382
        teleop_r_speed = 0;
383
        teleop_fluid_speed = 0;
384
        teleop_fluid_omega = 0;
385
    }
386
387
    void SimFrame::teleop_move_precise()
388
    {
389
        // Default to stop
390
        teleop_l_speed = 0;
391
        teleop_r_speed = 0;
392
393
        if (wxGetKeyState(WXK_UP))
394
        {
395
            teleop_l_speed = TELEOP_PRECISE_SPEED;
396
            teleop_r_speed = TELEOP_PRECISE_SPEED;
397
        }
398
        else if (wxGetKeyState(WXK_DOWN))
399
        {
400
            teleop_l_speed = -TELEOP_PRECISE_SPEED;
401
            teleop_r_speed = -TELEOP_PRECISE_SPEED;
402
        }
403
        else if (wxGetKeyState(WXK_LEFT))
404
        {
405 04114d13 Alex
            teleop_l_speed = -TELEOP_PRECISE_SPEED * 2;
406
            teleop_r_speed = TELEOP_PRECISE_SPEED * 2;
407 0e77683c Alex
        }
408
        else if (wxGetKeyState(WXK_RIGHT))
409
        {
410 04114d13 Alex
            teleop_l_speed = TELEOP_PRECISE_SPEED * 2;
411
            teleop_r_speed = -TELEOP_PRECISE_SPEED * 2;
412 0e77683c Alex
        }
413
    }
414
415
    void SimFrame::teleop_move_fluid()
416
    {
417
        if (wxGetKeyState(WXK_UP))
418
        {
419 c63c9752 Alex
            teleop_fluid_speed += TELEOP_FLUID_INC * 2;
420 0e77683c Alex
        }
421
        else if (wxGetKeyState(WXK_DOWN))
422
        {
423 c63c9752 Alex
            teleop_fluid_speed -= TELEOP_FLUID_INC * 2;
424 0e77683c Alex
        }
425 04114d13 Alex
        else if (teleop_fluid_speed > TELEOP_FLUID_INC)
426 0e77683c Alex
        {
427 c63c9752 Alex
            teleop_fluid_speed -= TELEOP_FLUID_INC;
428 0e77683c Alex
        }
429 04114d13 Alex
        else if (teleop_fluid_speed < -TELEOP_FLUID_INC)
430 0e77683c Alex
        {
431 c63c9752 Alex
            teleop_fluid_speed += TELEOP_FLUID_INC;
432 0e77683c Alex
        }
433 04114d13 Alex
        else
434
        {
435
            teleop_fluid_speed = 0;
436
        }
437 0e77683c Alex
438
        if (wxGetKeyState(WXK_LEFT))
439
        {
440 c63c9752 Alex
            teleop_fluid_omega -= TELEOP_FLUID_INC;
441 0e77683c Alex
        }
442
        else if (wxGetKeyState(WXK_RIGHT))
443
        {
444 c63c9752 Alex
            teleop_fluid_omega += TELEOP_FLUID_INC;
445 0e77683c Alex
        }
446 0076084e Alex
        else
447 0e77683c Alex
        {
448 0076084e Alex
            teleop_fluid_omega = 0;
449 0e77683c Alex
        }
450
451
        if (teleop_fluid_speed > TELEOP_FLUID_MAX_SPEED)
452
        {
453
            teleop_fluid_speed = TELEOP_FLUID_MAX_SPEED;
454
        }
455 c63c9752 Alex
        else if (teleop_fluid_speed < -TELEOP_FLUID_MAX_SPEED)
456
        {
457
            teleop_fluid_speed = -TELEOP_FLUID_MAX_SPEED;
458
        }
459 04114d13 Alex
        if (teleop_fluid_omega > TELEOP_FLUID_MAX_SPEED)
460 0e77683c Alex
        {
461 04114d13 Alex
            teleop_fluid_omega = TELEOP_FLUID_MAX_SPEED;
462 0e77683c Alex
        }
463 04114d13 Alex
        else if (teleop_fluid_omega < -TELEOP_FLUID_MAX_SPEED)
464 c63c9752 Alex
        {
465 04114d13 Alex
            teleop_fluid_omega = -TELEOP_FLUID_MAX_SPEED;
466 c63c9752 Alex
        }
467 0e77683c Alex
468 04114d13 Alex
        int l_speed = teleop_fluid_speed + teleop_fluid_omega;
469
        int r_speed = teleop_fluid_speed - teleop_fluid_omega;
470
471
        teleop_l_speed = max(MIN_ABSOLUTE_SPEED,
472
                             min(MAX_ABSOLUTE_SPEED, l_speed));
473
        teleop_r_speed = max(MIN_ABSOLUTE_SPEED,
474
                             min(MAX_ABSOLUTE_SPEED, r_speed));
475 0e77683c Alex
    }
476
477
    void SimFrame::teleop()
478
    {
479
        switch (teleop_type)
480
        {
481
            case TELEOP_OFF:
482
                return;
483
            case TELEOP_PRECISE:
484
                teleop_move_precise();
485
                break;
486
            case TELEOP_FLUID:
487
                teleop_move_fluid();
488
                break;
489
        }
490
491
        motors::set_motors msg;
492
        msg.fl_set = true;
493
        msg.fr_set = true;
494
        msg.bl_set = true;
495
        msg.br_set = true;
496
497
        msg.fl_speed = teleop_l_speed;
498
        msg.fr_speed = teleop_r_speed;
499
        msg.bl_speed = teleop_l_speed;
500
        msg.br_speed = teleop_r_speed;
501
502
        teleop_pub.publish(msg);
503
    }
504
505 266ae7f2 Alex Zirbel
    void SimFrame::updateScouts()
506
    {
507 144137a1 Alex Zirbel
        if (last_scout_update.isZero())
508 266ae7f2 Alex Zirbel
        {
509 144137a1 Alex Zirbel
            last_scout_update = ros::WallTime::now();
510 266ae7f2 Alex Zirbel
            return;
511
        }
512
513 04114d13 Alex
        path_image = path_bitmap.ConvertToImage();
514
        Refresh();
515 266ae7f2 Alex Zirbel
516 144137a1 Alex Zirbel
        M_Scout::iterator it = scouts.begin();
517
        M_Scout::iterator end = scouts.end();
518 e3f69e61 Alex
519
        world_state state;
520
        state.canvas_width = width_in_meters;
521
        state.canvas_height = height_in_meters;
522
523 266ae7f2 Alex Zirbel
        for (; it != end; ++it)
524
        {
525 04114d13 Alex
            it->second->update(SCOUTSIM_REFRESH_RATE,
526
                               path_dc,sonar_dc,sonar_visual_on,
527 a2e6bd4c Alex
                               path_image, lines_image, walls_image,
528 144137a1 Alex Zirbel
                               path_dc.GetBackground().GetColour(),
529 04114d13 Alex
                               sonar_dc.GetBackground().GetColour(),
530 e3f69e61 Alex
                               state);
531 266ae7f2 Alex Zirbel
        }
532
533 0e0ef125 Priya
        for (unsigned int i=0; i<ghost_scouts.size(); ++i)
534
        {
535
            ghost_scouts.at(i)->update(0.016, path_dc, sonar_dc,
536
                path_dc.GetBackground().GetColour(), state);
537
        }
538
539 c492be62 Alex Zirbel
        frame_count++;
540 266ae7f2 Alex Zirbel
    }
541
542
    bool SimFrame::clearCallback(std_srvs::Empty::Request&,
543
                                 std_srvs::Empty::Response&)
544
    {
545
        ROS_INFO("Clearing scoutsim.");
546
        clear();
547
        return true;
548
    }
549
550
    bool SimFrame::resetCallback(std_srvs::Empty::Request&,
551
                                 std_srvs::Empty::Response&)
552
    {
553
        ROS_INFO("Resetting scoutsim.");
554 144137a1 Alex Zirbel
        scouts.clear();
555
        id_counter = 0;
556
        spawnScout("", width_in_meters / 2.0, height_in_meters / 2.0, 0);
557 266ae7f2 Alex Zirbel
        clear();
558
        return true;
559
    }
560
561 1d1281cc Priya
    void SimFrame::wirelessCallback(const ::messages::WirelessPacket::ConstPtr& msg)
562 82f3f746 Priya
    {
563
        wireless_receive.publish(msg);
564
    }
565 266ae7f2 Alex Zirbel
}