Project

General

Profile

Statistics
| Branch: | Revision:

robobuggy / buggyvis / include / buggyvis / buggy.h @ 066966cf

History | View | Annotate | Download (3.96 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
#endif
45

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

    
51
#define PI 3.14159265
52

    
53
namespace buggysim
54
{
55

    
56
class Turtle
57
{
58
 public:
59
  Turtle(const ros::NodeHandle& nh, 
60
         const QImage& wall_image,
61
         const QImage& turtle_image,
62
         const QPointF& pos, 
63
         float orient);
64
  
65
  //bool update(double dt, QPainter& path_painter, const QImage& path_image, 
66
  //              qreal canvas_width, qreal canvas_height);
67

    
68
  // TODO: turn update into pose callback
69
  bool update(QPainter& path_painter, 
70
              const QImage& path_image, 
71
                qreal canvas_width, 
72
              qreal canvas_height);
73

    
74

    
75
  void paint(QPainter &painter);
76

    
77
 private:
78
  //  void turnAngleCallback(const buggymsgs::DirectionConstPtr& dir);
79
  void poseCallback(const buggymsgs::PoseConstPtr& dir);
80

    
81
  bool setPenCallback(buggysim::SetPen::Request&, 
82
                      buggysim::SetPen::Response&);
83
  
84
  bool teleportRelativeCallback(buggysim::TeleportRelative::Request&, 
85
                                buggysim::TeleportRelative::Response&);
86

    
87
  bool teleportAbsoluteCallback(buggysim::TeleportAbsolute::Request&, 
88
                                buggysim::TeleportAbsolute::Response&);
89

    
90
  void rotateImage();
91

    
92
  ros::NodeHandle nh_;
93

    
94
  QImage turtle_image_;
95
  QImage turtle_rotated_image_;
96

    
97
  QImage wall_image_;
98
  // GUI parameters
99
  QPointF pos_;
100
  qreal orient_;
101
  qreal lin_vel_;
102

    
103
  // Current position
104
  ros::Subscriber pose_sub_;
105
  buggymsgs::Pose pose_;
106
  ros::WallTime last_command_time_;
107

    
108
  bool pen_on_;
109
  QPen pen_;
110

    
111
  ros::ServiceServer set_pen_srv_;
112
  ros::ServiceServer teleport_relative_srv_;
113
  ros::ServiceServer teleport_absolute_srv_;
114

    
115
  float meter_;
116

    
117
  struct TeleportRequest
118
  {
119
    TeleportRequest(float x, float y, qreal _theta, qreal _linear, bool _relative)
120
    : pos(x, y)
121
    , theta(_theta)
122
      , linear(_linear)
123
      , relative(_relative)
124
    {}
125

    
126
    QPointF pos;
127
    qreal theta;
128
    qreal linear;
129
    bool relative;
130
  };
131
  typedef std::vector<TeleportRequest> V_TeleportRequest;
132
  V_TeleportRequest teleport_requests_;
133
};
134

    
135
 typedef boost::shared_ptr<Turtle> TurtlePtr;
136

    
137
}
138

    
139
#endif