Project

General

Profile

Statistics
| Branch: | Revision:

robobuggy / buggysim / include / buggysim / buggy.h @ 1efba872

History | View | Annotate | Download (4 KB)

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

    
30
#ifndef TURTLESIM_TURTLE_H
31
#define TURTLESIM_TURTLE_H
32

    
33
// This prevents a MOC error with versions of boost >= 1.48
34
#ifndef Q_MOC_RUN  // See: https://bugreports.qt-project.org/browse/QTBUG-22829
35
# include <ros/ros.h>
36
# include <boost/shared_ptr.hpp>
37

    
38
# include <buggymsgs/Pose.h>
39
# include <buggymsgs/Direction.h>
40

    
41
# include <buggysim/SetPen.h>
42
# include <buggysim/TeleportRelative.h>
43
# include <buggysim/TeleportAbsolute.h>
44
//# include <turtlesim/Color.h>
45
#endif
46

    
47
#include <QImage>
48
#include <QPainter>
49
#include <QPen>
50
#include <QPointF>
51

    
52
#define PI 3.14159265
53

    
54
namespace buggysim
55
{
56

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

    
65

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

    
71

    
72

    
73
   protected:
74

    
75
      ros::NodeHandle nh_;
76

    
77
      QPointF pos_;
78
      qreal orient_;
79

    
80
      float meter_;
81

    
82
      ros::WallTime last_command_time_;
83

    
84
      void rotateImage();
85

    
86
      bool pen_on_;
87
      QPen pen_;
88

    
89
      // TODO: Make teleporting in buggy.cpp, a protected function
90
      struct TeleportRequest {
91
         TeleportRequest(float x, float y, qreal _theta, qreal _linear, bool _relative)
92
            : pos(x, y)
93
            , theta(_theta)
94
            , linear(_linear)
95
            , relative(_relative)
96
         {}
97

    
98
         QPointF pos;
99
         qreal theta;
100
         qreal linear;
101
         bool relative;
102
      };
103

    
104
      typedef std::vector<TeleportRequest> V_TeleportRequest;
105
      V_TeleportRequest teleport_requests_;
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;
131
}
132

    
133

    
134
#endif