Project

General

Profile

Statistics
| Branch: | Revision:

robobuggy / turtlesim_ref / include / turtlesim / turtle.h @ dd5d7f53

History | View | Annotate | Download (3.73 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 <turtlesim_ref/Pose.h>
39
# include <turtlesim_ref/Velocity.h>
40
# include <turtlesim_ref/SetPen.h>
41
# include <turtlesim_ref/TeleportRelative.h>
42
# include <turtlesim_ref/TeleportAbsolute.h>
43
# include <turtlesim_ref/Color.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 turtlesim_ref
54
{
55

    
56
class Turtle
57
{
58
public:
59
  Turtle(const ros::NodeHandle& nh, const QImage& turtle_image, const QPointF& pos, float orient);
60

    
61
  bool update(double dt, QPainter& path_painter, const QImage& path_image, qreal canvas_width, qreal canvas_height);
62
  void paint(QPainter &painter);
63
private:
64
  void velocityCallback(const turtlesim_ref::VelocityConstPtr& vel);
65
  bool setPenCallback(turtlesim_ref::SetPen::Request&, turtlesim_ref::SetPen::Response&);
66
  bool teleportRelativeCallback(turtlesim_ref::TeleportRelative::Request&, turtlesim_ref::TeleportRelative::Response&);
67
  bool teleportAbsoluteCallback(turtlesim_ref::TeleportAbsolute::Request&, turtlesim_ref::TeleportAbsolute::Response&);
68

    
69
  void rotateImage();
70

    
71
  ros::NodeHandle nh_;
72

    
73
  QImage turtle_image_;
74
  QImage turtle_rotated_image_;
75

    
76
  QPointF pos_;
77
  qreal orient_;
78

    
79
  qreal lin_vel_;
80
  qreal ang_vel_;
81
  bool pen_on_;
82
  QPen pen_;
83

    
84
  ros::Subscriber velocity_sub_;
85
  ros::Publisher pose_pub_;
86
  ros::Publisher color_pub_;
87
  ros::ServiceServer set_pen_srv_;
88
  ros::ServiceServer teleport_relative_srv_;
89
  ros::ServiceServer teleport_absolute_srv_;
90

    
91
  ros::WallTime last_command_time_;
92

    
93
  float meter_;
94

    
95
  struct TeleportRequest
96
  {
97
    TeleportRequest(float x, float y, qreal _theta, qreal _linear, bool _relative)
98
    : pos(x, y)
99
    , theta(_theta)
100
    , linear(_linear)
101
    , relative(_relative)
102
    {}
103

    
104
    QPointF pos;
105
    qreal theta;
106
    qreal linear;
107
    bool relative;
108
  };
109
  typedef std::vector<TeleportRequest> V_TeleportRequest;
110
  V_TeleportRequest teleport_requests_;
111
};
112
typedef boost::shared_ptr<Turtle> TurtlePtr;
113

    
114
}
115

    
116
#endif