Project

General

Profile

Revision 1efba872

ID1efba87256067aea69aae087664fa6fe90ab90d8
Parent f0c4b45e
Child 907874ca

Added by Tahm over 10 years ago

Added instructions for GUI, properly subclassed next-step-simulation, Broke: line.

View differences:

Todo.txt
5 5
msebek
6 6
------
7 7
Sim
8
 - Add courses/walls
8
 - Refactor into more AbstractClass/Class
9 9
 - Check heading/message output
10
 - Add maps/courses/walls
11
 - Give the buggy mass
10 12
 - Make sure services are relevant
11
 - MapServer? Existing Planner?
13

  
12 14
Nav
13 15
 - Print out Steering Angle
14
 - ??
16
 - Service to load with waypoints. 
17
 - Tight loop to determine the closest waypoint. navigate to it?
18
 - PID control of some sort. 
19

  
20
Planner
21
 - Given map, allow planning. 
22
 - Allow feedback
23
 - Optimizer (consider simulation feedback)
15 24

  
16 25
- Start figuring out nav/AI
17 26
- Lane Lines?
27
- Move Maps to a common folder
UsingQTCreatorWithBuggy.txt
1
Using QTCreator
2
===============
3

  
4
Sometimes, it's just nice to have an IDE. 
5
Note that QTCreator must be launched from the shell, 
6
 so that it will inherit the correct environment. 
7

  
8
1. Install QTCreator
9
     sudo apt-get install qtcreator
10

  
11
2. Run it from the shell
12
     cd ~/buggyworkspace/src
13
     qtcreator
buggysim/CMakeLists.txt
27 27
set(turtlesim_node_SRCS
28 28
  src/buggysim.cpp
29 29
  src/buggy.cpp
30
  src/adelaide.cpp
30 31
  src/sim_frame.cpp
31 32
)
32 33

  
buggysim/include/buggysim/buggy.h
54 54
namespace buggysim
55 55
{
56 56

  
57
   class Buggy
57
   class AbstractBuggy
58 58
   {
59 59
   public:
60
      Buggy(const ros::NodeHandle& nh,
60
      AbstractBuggy(const ros::NodeHandle& nh,
61 61
             const QImage& turtle_image,
62 62
             const QPointF& pos,
63 63
             float orient);
64 64

  
65
      bool update(double dt, QPainter& path_painter, const QImage& path_image,
66
                  qreal canvas_width, qreal canvas_height);
67 65

  
68 66
      void paint(QPainter &painter);
69 67
      
68
      virtual bool update(double dt, QPainter& path_painter, const QImage& path_image,
69
                  qreal canvas_width, qreal canvas_height);
70

  
71

  
72

  
70 73
   protected:
74

  
71 75
      ros::NodeHandle nh_;
72 76

  
73 77
      QPointF pos_;
74 78
      qreal orient_;
75 79

  
76
      qreal lin_vel_;
77
      //qreal ang_vel_;
78
      qreal turnAngle_;
79

  
80
      ros::Subscriber angle_sub_;
81
      ros::Publisher pose_pub_;
82

  
83 80
      float meter_;
84 81

  
85
      void turnAngleCallback(const buggymsgs::DirectionConstPtr& dir);
86

  
87
   private:
88
      bool setPenCallback(buggysim::SetPen::Request&,
89
                          buggysim::SetPen::Response&);
90

  
91
      bool teleportRelativeCallback(buggysim::TeleportRelative::Request&,
92
                                    buggysim::TeleportRelative::Response&);
93

  
94
      bool teleportAbsoluteCallback(buggysim::TeleportAbsolute::Request&,
95
                                    buggysim::TeleportAbsolute::Response&);
82
      ros::WallTime last_command_time_;
96 83

  
97 84
      void rotateImage();
98 85

  
99
      QImage turtle_image_;
100
      QImage turtle_rotated_image_;
101

  
102 86
      bool pen_on_;
103 87
      QPen pen_;
104 88

  
105
      //ros::Publisher color_pub_;
106
      ros::ServiceServer set_pen_srv_;
107
      ros::ServiceServer teleport_relative_srv_;
108
      ros::ServiceServer teleport_absolute_srv_;
109

  
110
      ros::WallTime last_command_time_;
111

  
89
      // TODO: Make teleporting in buggy.cpp, a protected function
112 90
      struct TeleportRequest {
113 91
         TeleportRequest(float x, float y, qreal _theta, qreal _linear, bool _relative)
114 92
            : pos(x, y)
......
122 100
         qreal linear;
123 101
         bool relative;
124 102
      };
103

  
125 104
      typedef std::vector<TeleportRequest> V_TeleportRequest;
126 105
      V_TeleportRequest teleport_requests_;
127
   };
128
   typedef boost::shared_ptr<Buggy> TurtlePtr;
129 106

  
107
   private:
108
      bool setPenCallback(buggysim::SetPen::Request&,
109
                          buggysim::SetPen::Response&);
110

  
111
      bool teleportRelativeCallback(buggysim::TeleportRelative::Request&,
112
                                    buggysim::TeleportRelative::Response&);
113

  
114
      bool teleportAbsoluteCallback(buggysim::TeleportAbsolute::Request&,
115
                                    buggysim::TeleportAbsolute::Response&);
116

  
117

  
118

  
119
      QImage turtle_image_;
120
      QImage turtle_rotated_image_;
121

  
122

  
123
      //ros::Publisher color_pub_;
124
      ros::ServiceServer set_pen_srv_;
125
      ros::ServiceServer teleport_relative_srv_;
126
      ros::ServiceServer teleport_absolute_srv_;
127

  
128
  };
129
   // TODO: What should I even make this?
130
   typedef boost::shared_ptr<AbstractBuggy> TurtlePtr;
130 131
}
131 132

  
133

  
132 134
#endif
buggysim/src/adelaide.cpp
2 2
//  simulator. Most other upgrades (painting, maps, spawning)
3 3
//  will be in AbstractBuggy.
4 4
// This file will focus on being a physics simulation engine.
5
/*
6
 * Copyright (c) 2009, Willow Garage, Inc.
7
 * All rights reserved.
8
 *
9
 * Redistribution and use in source and binary forms, with or without
10
 * modification, are permitted provided that the following conditions are met:
11
 *
12
 *     * Redistributions of source code must retain the above copyright
13
 *       notice, this list of conditions and the following disclaimer.
14
 *     * Redistributions in binary form must reproduce the above copyright
15
 *       notice, this list of conditions and the following disclaimer in the
16
 *       documentation and/or other materials provided with the distribution.
17
 *     * Neither the name of the Willow Garage, Inc. nor the names of its
18
 *       contributors may be used to endorse or promote products derived from
19
 *       this software without specific prior written permission.
20
 *
21
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
 * POSSIBILITY OF SUCH DAMAGE.
32
 */
33

  
34
#include "buggysim/buggy.h"
35

  
36
#include <QColor>
37
#include <QRgb>
38

  
39
#define DEFAULT_PEN_R 0xb3
40
#define DEFAULT_PEN_G 0xb8
41
#define DEFAULT_PEN_B 0xff
42

  
43
namespace buggysim
44
{
45
class Adelaide: public AbstractBuggy
46
{
47
public:
48
    ros::NodeHandle nh_;
49

  
50
    // Linear velocity, measured in meters/sec
51
    qreal lin_vel_;
52
    //qreal ang_vel_;
53
    qreal turnAngle_;
54

  
55
    ros::Subscriber angle_sub_;
56
    ros::Publisher pose_pub_;
57

  
58
    float meter_;
59

  
60
    //void turnAngleCallback(const buggymsgs::DirectionConstPtr& dir);
61

  
62
    Adelaide(const ros::NodeHandle& nh, const QImage& turtle_image,
63
             const QPointF& pos, float orient)
64
        : AbstractBuggy(nh, turtle_image, pos, orient)
65
        , lin_vel_(1.0)
66
        //, ang_vel_(0.0)
67
        , turnAngle_(0.0) // turn angle is stored in degrees
68
        //, pen_on_(true)
69
        //, pen_(QColor(DEFAULT_PEN_R, DEFAULT_PEN_G, DEFAULT_PEN_B))
70
    {
71
        ROS_INFO("Namespace in childbuggy, unresolved: %s", nh_.getUnresolvedNamespace().data());
72
        ROS_INFO("Namespace in childbuggy: %s", nh_.getNamespace().data());
73
        //ROS_INFO("Namespace in childbuggy: %s", nh_.remapName());
74
        //ROS_INFO("Namespace in childbuggy, of arg: %s", nh.getNamespace().data());
75

  
76
        // TODO: fix this hack.
77
        angle_sub_ = nh_.subscribe
78
                      ("/buggy1/command_turnAngle", 1, &Adelaide::turnAngleCallback, this);
79
        pose_pub_ = nh_.advertise<buggymsgs::Pose>("/buggy1/pose", 1);
80

  
81

  
82
    }
83

  
84

  
85
    void turnAngleCallback(const buggymsgs::DirectionConstPtr& dir)
86
    {
87
        last_command_time_ = ros::WallTime::now();
88
        turnAngle_ = dir->turnAngle;
89
        //lin_vel_ = vel->linear;
90
        //ang_vel_ = vel->angular;
91
    }
92

  
93

  
94
    /**
95
    * TODO: convert this to take just an angle. And include drag.
96
    *       and include acceleration/joule dump
97
    */
98
    bool update(double dt, QPainter& path_painter, const QImage& path_image,
99
                qreal canvas_width, qreal canvas_height)
100
    {
101
        qreal old_orient = orient_;
102
        bool modified = false;
103
        //qreal old_orient = orient_;
104

  
105
        // first process any teleportation requests, in order
106
        /*V_TeleportRequest::iterator it = teleport_requests_.begin();
107
        V_TeleportRequest::iterator end = teleport_requests_.end();
108
        for (; it != end; ++it) {
109
           const TeleportRequest& req = *it;
110

  
111
           QPointF old_pos = pos_;
112
           if (req.relative) {
113
              orient_ += req.theta;
114
              pos_.rx() += std::sin(orient_ + PI/2.0) * req.linear;
115
              pos_.ry() += std::cos(orient_ + PI/2.0) * req.linear;
116
           } else {
117
              pos_.setX(req.pos.x());
118
              pos_.setY(std::max(0.0, static_cast<double>(canvas_height - req.pos.y())));
119
              orient_ = req.theta;
120
           }
121

  
122
           path_painter.setPen(pen_);
123
           path_painter.drawLine(pos_ * meter_, old_pos * meter_);
124
           modified = true;
125
        }
126

  
127
        teleport_requests_.clear();
128
        */
129
        // Stop moving after 1 second since-last command.
130
        //if (ros::WallTime::now() - last_command_time_ > ros::WallDuration(1.0))
131
        //{
132
        //  lin_vel_ = 0.0;
133
        //  ang_vel_ = 0.0;
134
        //}
135

  
136
        // Update my position
137
        QPointF old_pos = pos_;
138

  
139
        /* Convert coordinate systens
140
      orient_ = std::fmod(orient_ + ang_vel_ * dt, 2*PI);
141
      pos_.rx() += std::sin(orient_ + PI/2.0) * lin_vel_ * dt;
142
      pos_.ry() += std::cos(orient_ + PI/2.0) * lin_vel_ * dt;
143
      */
144
        // TODO: what direction does orientation start at 0?
145
        // TODO: orient might have to become negative
146
        //orient_ = std::fmod(orient_ + ((turnAngle_/2*PI) * dt), 2*PI);
147
        orient_ = std::fmod(orient_ + ((-turnAngle_/(2*PI)) * dt), 2*PI);
148
        // TODO: why add pi/2? is this just because they got the
149
        //       sin/cos mixed up?
150
        //pos_.rx() += std::sin(orient_ + PI/2.0) * lin_vel_ * dt;
151
        //pos_.ry() += std::cos(orient_ + PI/2.0) * lin_vel_ * dt;
152

  
153
        pos_.rx() += std::cos(orient_) * lin_vel_ * dt;
154
        pos_.ry() -= std::sin(orient_) * lin_vel_ * dt;
155

  
156

  
157
        // Find linear velocity
158
        //qreal lin_vel;
159
        // Find angular velocity
160
        //qreal ang_vel;
161

  
162
        // Clamp to screen size
163
        // TODO: change to use another image, to detect walls.
164
        if (pos_.x() < 0 || pos_.x() > canvas_width ||
165
                pos_.y() < 0 || pos_.y() > canvas_height) {
166
            ROS_WARN("Oh no! I hit the wall! (Clamping from [x=%f, y=%f])", pos_.x(),
167
                     pos_.y());
168
        }
169

  
170
        pos_.setX(std::min(std::max(static_cast<double>(pos_.x()), 0.0),
171
                           static_cast<double>(canvas_width)));
172
        pos_.setY(std::min(std::max(static_cast<double>(pos_.y()), 0.0),
173
                           static_cast<double>(canvas_height)));
174

  
175
        // Publish pose of the turtle
176
        buggymsgs::Pose p;
177
        p.x = pos_.x();
178
        p.y = canvas_height - pos_.y();
179
        p.angle = orient_;
180
        p.linear_velocity = lin_vel_;
181
        //p.angular_velocity = ang_vel;
182
        pose_pub_.publish(p);
183

  
184
        // Figure out (and publish) the color underneath the turtle
185
        /*{
186
        Color color;
187
        QRgb pixel = path_image.pixel((pos_ * meter_).toPoint());
188
        color.r = qRed(pixel);
189
        color.g = qGreen(pixel);
190
        color.b = qBlue(pixel);
191
        color_pub_.publish(color);
192
        }*/
193

  
194
        ROS_DEBUG("[%s]: pos_x: %f pos_y: %f theta: %f", nh_.getNamespace().c_str(),
195
                  pos_.x(), pos_.y(), orient_);
196

  
197
        if (orient_ != old_orient) {
198
            rotateImage();
199
            modified = true;
200
        }
201
        if (pos_ != old_pos) {
202
            if (pen_on_) {
203
                path_painter.setPen(pen_);
204
                path_painter.drawLine(pos_ * meter_, old_pos * meter_);
205
            }
206
            modified = true;
207
        }
208

  
209
        return modified;
210
    }
211

  
212

  
213
};
214
}
buggysim/src/buggy.cpp
39 39
namespace buggysim
40 40
{
41 41

  
42
   Buggy::Buggy(const ros::NodeHandle& nh, const QImage& turtle_image,
43
                  const QPointF& pos, float orient)
42
   AbstractBuggy::AbstractBuggy(const ros::NodeHandle& nh,
43
                                const QImage& turtle_image,
44
                                const QPointF& pos,
45
                                float orient)
44 46
      : nh_(nh)
45 47
      , turtle_image_(turtle_image)
46 48
      , pos_(pos)
47 49
      , orient_(orient)
48
      , lin_vel_(2.0)
50
      //, lin_vel_(2.0)
49 51
      //, ang_vel_(0.0)
50
      , turnAngle_(0.0)
52
      //, turnAngle_(0.0)
51 53
      , pen_on_(true)
52 54
      , pen_(QColor(DEFAULT_PEN_R, DEFAULT_PEN_G, DEFAULT_PEN_B))
53 55
   {
54 56
      pen_.setWidth(3);
55

  
56
      angle_sub_ = nh_.subscribe
57
                   ("command_turnAngle", 1, &Buggy::turnAngleCallback, this);
58
      pose_pub_ = nh_.advertise<buggymsgs::Pose>("pose", 1);
57
      ROS_INFO("Namespace in abstract buggy: %s", nh.getNamespace().data());
58
      ROS_INFO("Namespace in abstract buggy, stored: %s", nh_.getNamespace().data());
59
      //angle_sub_ = nh_.subscribe
60
      //             ("command_turnAngle", 1, &AbstractBuggy::turnAngleCallback, this);
61
      //pose_pub_ = nh_.advertise<buggymsgs::Pose>("pose", 1);
59 62

  
60 63
      //color_pub_ = nh_.advertise<Color>("color_sensor", 1);
61 64
      set_pen_srv_ = nh_.advertiseService
62
                     ("set_pen", &Buggy::setPenCallback, this);
65
                     ("set_pen", &AbstractBuggy::setPenCallback, this);
63 66
      teleport_relative_srv_ = nh_.advertiseService
64
                               ("teleport_relative", &Buggy::teleportRelativeCallback, this);
67
                               ("teleport_relative", &AbstractBuggy::teleportRelativeCallback, this);
65 68
      teleport_absolute_srv_ = nh_.advertiseService
66
                               ("teleport_absolute", &Buggy::teleportAbsoluteCallback, this);
69
                               ("teleport_absolute", &AbstractBuggy::teleportAbsoluteCallback, this);
70

  
67 71

  
68 72
      meter_ = turtle_image_.height();
69 73
      rotateImage();
70 74
   }
71 75

  
72

  
73
   void Buggy::turnAngleCallback(const buggymsgs::DirectionConstPtr& dir)
76
   // This is a virtual method, to be implemented by the subclass
77
   /*void AbstractBuggy::turnAngleCallback(const buggymsgs::DirectionConstPtr& dir)
74 78
   {
75 79
      last_command_time_ = ros::WallTime::now();
76 80
      turnAngle_ = dir->turnAngle;
77 81
      //lin_vel_ = vel->linear;
78 82
      //ang_vel_ = vel->angular;
79
   }
83
   }*/
80 84

  
81
   bool Buggy::setPenCallback(buggysim::SetPen::Request& req,
85
   bool AbstractBuggy::setPenCallback(buggysim::SetPen::Request& req,
82 86
                               buggysim::SetPen::Response&)
83 87
   {
84 88
      pen_on_ = !req.off;
......
95 99
      return true;
96 100
   }
97 101

  
98
   bool Buggy::teleportRelativeCallback(buggysim::TeleportRelative::Request& req,
102
   bool AbstractBuggy::teleportRelativeCallback(buggysim::TeleportRelative::Request& req,
99 103
                                         buggysim::TeleportRelative::Response&)
100 104
   {
101 105
      teleport_requests_.push_back(TeleportRequest(0, 0, req.angular, req.linear,
......
103 107
      return true;
104 108
   }
105 109

  
106
   bool Buggy::teleportAbsoluteCallback(buggysim::TeleportAbsolute::Request& req,
110
   bool AbstractBuggy::teleportAbsoluteCallback(buggysim::TeleportAbsolute::Request& req,
107 111
                                         buggysim::TeleportAbsolute::Response&)
108 112
   {
109 113
      teleport_requests_.push_back(TeleportRequest(req.x, req.y, req.theta, 0,
......
111 115
      return true;
112 116
   }
113 117

  
114
   void Buggy::rotateImage()
118
   void AbstractBuggy::rotateImage()
115 119
   {
116 120
      QTransform transform;
117 121
      transform.rotate(-orient_ * 180.0 / PI + 90.0);
118 122
      turtle_rotated_image_ = turtle_image_.transformed(transform);
119 123
   }
120 124

  
121
   /**
122
    * TODO: convert this to take just an angle. And include drag.
123
    *       and include acceleration/joule dump
124
    */
125
   bool Buggy::update(double dt, QPainter& path_painter, const QImage& path_image,
125
   bool AbstractBuggy::update(double dt, QPainter& path_painter, const QImage& path_image,
126 126
                       qreal canvas_width, qreal canvas_height)
127 127
   {
128
      bool modified = false;
129
      qreal old_orient = orient_;
130

  
131
      // first process any teleportation requests, in order
132
      V_TeleportRequest::iterator it = teleport_requests_.begin();
133
      V_TeleportRequest::iterator end = teleport_requests_.end();
134
      for (; it != end; ++it) {
135
         const TeleportRequest& req = *it;
136

  
137
         QPointF old_pos = pos_;
138
         if (req.relative) {
139
            orient_ += req.theta;
140
            pos_.rx() += std::sin(orient_ + PI/2.0) * req.linear;
141
            pos_.ry() += std::cos(orient_ + PI/2.0) * req.linear;
142
         } else {
143
            pos_.setX(req.pos.x());
144
            pos_.setY(std::max(0.0, static_cast<double>(canvas_height - req.pos.y())));
145
            orient_ = req.theta;
146
         }
147

  
148
         path_painter.setPen(pen_);
149
         path_painter.drawLine(pos_ * meter_, old_pos * meter_);
150
         modified = true;
151
      }
152 128

  
153
      teleport_requests_.clear();
154

  
155
      // Stop moving after 1 second since-last command.
156
      //if (ros::WallTime::now() - last_command_time_ > ros::WallDuration(1.0))
157
      //{
158
      //  lin_vel_ = 0.0;
159
      //  ang_vel_ = 0.0;
160
      //}
161

  
162
      // Update my position
163
      QPointF old_pos = pos_;
164

  
165
      /* Convert coordinate systens
166
      orient_ = std::fmod(orient_ + ang_vel_ * dt, 2*PI);
167
      pos_.rx() += std::sin(orient_ + PI/2.0) * lin_vel_ * dt;
168
      pos_.ry() += std::cos(orient_ + PI/2.0) * lin_vel_ * dt;
169
      */
170
      // TODO: what direction does orientation start at 0?
171
      // TODO: orient might have to become negative
172
      orient_ = std::fmod(orient_ - turnAngle_ * dt, 2*PI);
173
      // TODO: why add pi/2? is this just because they got the
174
      //       sin/cos mixed up?
175
      //pos_.rx() += std::sin(orient_ + PI/2.0) * lin_vel_ * dt;
176
      //pos_.ry() += std::cos(orient_ + PI/2.0) * lin_vel_ * dt;
177

  
178
      pos_.rx() += std::cos(orient_) * lin_vel_ * dt;
179
      pos_.ry() += std::sin(orient_) * lin_vel_ * dt;
180

  
181

  
182
      // Find linear velocity
183
      //qreal lin_vel;
184
      // Find angular velocity
185
      //qreal ang_vel;
186

  
187
      // Clamp to screen size
188
      // TODO: change to use another image, to detect walls.
189
      if (pos_.x() < 0 || pos_.x() > canvas_width ||
190
            pos_.y() < 0 || pos_.y() > canvas_height) {
191
         ROS_WARN("Oh no! I hit the wall! (Clamping from [x=%f, y=%f])", pos_.x(),
192
                  pos_.y());
193
      }
194

  
195
      pos_.setX(std::min(std::max(static_cast<double>(pos_.x()), 0.0),
196
                         static_cast<double>(canvas_width)));
197
      pos_.setY(std::min(std::max(static_cast<double>(pos_.y()), 0.0),
198
                         static_cast<double>(canvas_height)));
199

  
200
      // Publish pose of the turtle
201
      buggymsgs::Pose p;
202
      p.x = pos_.x();
203
      p.y = canvas_height - pos_.y();
204
      p.angle = orient_;
205
      p.linear_velocity = lin_vel_;
206
      //p.angular_velocity = ang_vel;
207
      pose_pub_.publish(p);
208

  
209
      // Figure out (and publish) the color underneath the turtle
210
      /*{
211
        Color color;
212
        QRgb pixel = path_image.pixel((pos_ * meter_).toPoint());
213
        color.r = qRed(pixel);
214
        color.g = qGreen(pixel);
215
        color.b = qBlue(pixel);
216
        color_pub_.publish(color);
217
        }*/
218

  
219
      ROS_DEBUG("[%s]: pos_x: %f pos_y: %f theta: %f", nh_.getNamespace().c_str(),
220
                pos_.x(), pos_.y(), orient_);
221

  
222
      if (orient_ != old_orient) {
223
         rotateImage();
224
         modified = true;
225
      }
226
      if (pos_ != old_pos) {
227
         if (pen_on_) {
228
            path_painter.setPen(pen_);
229
            path_painter.drawLine(pos_ * meter_, old_pos * meter_);
230
         }
231
         modified = true;
232
      }
129
       return false;
233 130

  
234
      return modified;
235 131
   }
236 132

  
237
   void Buggy::paint(QPainter& painter)
133
   void AbstractBuggy::paint(QPainter& painter)
238 134
   {
239 135
      QPointF p = pos_ * meter_;
240 136
      p.rx() -= 0.5 * turtle_rotated_image_.width();
buggysim/src/sim_frame.cpp
28 28
 */
29 29

  
30 30
#include "buggysim/sim_frame.h"
31
#include "adelaide.cpp"
31 32

  
32 33
#include <QPointF>
33 34

  
......
64 65
      nh_.setParam("background_g", DEFAULT_BG_G);
65 66
      nh_.setParam("background_b", DEFAULT_BG_B);
66 67

  
68
      // TODO: make it automatically pick up turtles?
69
      // Note: buggies must be added here to be chosen.
70
      // TODO: associate buggy with specific model.
67 71
      QVector<QString> turtles;
68
      turtles.append("box-turtle.png");
69 72
      turtles.append("robot-turtle.png");
70
      turtles.append("sea-turtle.png");
71
      turtles.append("diamondback.png");
72 73
      turtles.append("electric.png");
73 74
      turtles.append("fuerte.png");
74 75
      turtles.append("groovy.png");
75 76
      turtles.append("hydro.svg");
76 77

  
77 78
      QString images_path = (ros::package::getPath("buggysim") + "/images/").c_str();
79

  
78 80
      for (size_t i = 0; i < turtles.size(); ++i) {
79 81
         QImage img;
80 82
         img.load(images_path + turtles[i]);
81 83
         turtle_images_.append(img);
82 84
      }
83 85

  
86

  
84 87
      meter_ = turtle_images_[0].height();
85 88

  
86 89
      clear();
......
154 157
         }
155 158
      }
156 159

  
157
      TurtlePtr t(new Buggy(ros::NodeHandle(real_name),
158
                             turtle_images_[rand() % turtle_images_.size()], QPointF(x, y), angle));
160
      //ROS_INFO("Name: %s", name.data());
161
      //ROS_INFO("Realname: %s", real_name.data());
162
      // Load the correct implementation of turtle
163
      TurtlePtr t(new Adelaide(ros::NodeHandle(real_name),
164
                             turtle_images_[rand() % turtle_images_.size()],
165
                             QPointF(x, y),
166
                             angle));
167

  
159 168
      turtles_[real_name] = t;
160 169
      update();
161 170

  

Also available in: Unified diff