turtle.h
Go to the documentation of this file.
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/Pose.h>
39 # include <geometry_msgs/Twist.h>
40 # include <turtlesim/SetPen.h>
41 # include <turtlesim/TeleportRelative.h>
42 # include <turtlesim/TeleportAbsolute.h>
43 # include <turtlesim/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
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 geometry_msgs::Twist::ConstPtr& vel);
65  bool setPenCallback(turtlesim::SetPen::Request&, turtlesim::SetPen::Response&);
66  bool teleportRelativeCallback(turtlesim::TeleportRelative::Request&, turtlesim::TeleportRelative::Response&);
67  bool teleportAbsoluteCallback(turtlesim::TeleportAbsolute::Request&, turtlesim::TeleportAbsolute::Response&);
68 
69  void rotateImage();
70 
72 
73  QImage turtle_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 
90 
92 
93  float meter_;
94 
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 };
113 
114 }
115 
116 #endif
ros::Subscriber velocity_sub_
Definition: turtle.h:84
bool teleportAbsoluteCallback(turtlesim::TeleportAbsolute::Request &, turtlesim::TeleportAbsolute::Response &)
Definition: turtle.cpp:97
ros::ServiceServer set_pen_srv_
Definition: turtle.h:87
bool update(double dt, QPainter &path_painter, const QImage &path_image, qreal canvas_width, qreal canvas_height)
Definition: turtle.cpp:110
void rotateImage()
Definition: turtle.cpp:103
std::vector< TeleportRequest > V_TeleportRequest
Definition: turtle.h:109
QImage turtle_rotated_image_
Definition: turtle.h:74
qreal ang_vel_
Definition: turtle.h:80
qreal orient_
Definition: turtle.h:77
float meter_
Definition: turtle.h:93
void velocityCallback(const geometry_msgs::Twist::ConstPtr &vel)
Definition: turtle.cpp:66
QImage turtle_image_
Definition: turtle.h:73
bool teleportRelativeCallback(turtlesim::TeleportRelative::Request &, turtlesim::TeleportRelative::Response &)
Definition: turtle.cpp:91
ros::WallTime last_command_time_
Definition: turtle.h:91
boost::shared_ptr< Turtle > TurtlePtr
Definition: turtle.h:112
Turtle(const ros::NodeHandle &nh, const QImage &turtle_image, const QPointF &pos, float orient)
Definition: turtle.cpp:42
TeleportRequest(float x, float y, qreal _theta, qreal _linear, bool _relative)
Definition: turtle.h:97
ros::ServiceServer teleport_relative_srv_
Definition: turtle.h:88
ros::ServiceServer teleport_absolute_srv_
Definition: turtle.h:89
QPointF pos_
Definition: turtle.h:76
V_TeleportRequest teleport_requests_
Definition: turtle.h:110
ros::NodeHandle nh_
Definition: turtle.h:71
ros::Publisher color_pub_
Definition: turtle.h:86
qreal lin_vel_
Definition: turtle.h:79
ros::Publisher pose_pub_
Definition: turtle.h:85
void paint(QPainter &painter)
Definition: turtle.cpp:209
bool setPenCallback(turtlesim::SetPen::Request &, turtlesim::SetPen::Response &)
Definition: turtle.cpp:73


turtlesim
Author(s): Josh Faust
autogenerated on Fri Jun 7 2019 22:01:46