robobuggy / buggysim / include / buggysim / buggy.h @ 907874ca
History | View | Annotate | Download (3.74 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 Turtle |
58 |
{ |
59 |
public:
|
60 |
Turtle(const ros::NodeHandle& nh,
|
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 |
void paint(QPainter &painter);
|
69 |
|
70 |
private:
|
71 |
void turnAngleCallback(const buggymsgs::DirectionConstPtr& dir); |
72 |
|
73 |
bool setPenCallback(buggysim::SetPen::Request&,
|
74 |
buggysim::SetPen::Response&); |
75 |
|
76 |
bool teleportRelativeCallback(buggysim::TeleportRelative::Request&,
|
77 |
buggysim::TeleportRelative::Response&); |
78 |
|
79 |
bool teleportAbsoluteCallback(buggysim::TeleportAbsolute::Request&,
|
80 |
buggysim::TeleportAbsolute::Response&); |
81 |
|
82 |
void rotateImage();
|
83 |
|
84 |
ros::NodeHandle nh_; |
85 |
|
86 |
QImage turtle_image_; |
87 |
QImage turtle_rotated_image_; |
88 |
|
89 |
QPointF pos_; |
90 |
qreal orient_; |
91 |
|
92 |
qreal lin_vel_; |
93 |
//qreal ang_vel_;
|
94 |
qreal turnAngle_; |
95 |
bool pen_on_;
|
96 |
QPen pen_; |
97 |
|
98 |
ros::Subscriber angle_sub_; |
99 |
ros::Publisher pose_pub_; |
100 |
//ros::Publisher color_pub_;
|
101 |
ros::ServiceServer set_pen_srv_; |
102 |
ros::ServiceServer teleport_relative_srv_; |
103 |
ros::ServiceServer teleport_absolute_srv_; |
104 |
|
105 |
ros::WallTime last_command_time_; |
106 |
|
107 |
float meter_;
|
108 |
|
109 |
struct TeleportRequest
|
110 |
{ |
111 |
TeleportRequest(float x, float y, qreal _theta, qreal _linear, bool _relative) |
112 |
: pos(x, y) |
113 |
, theta(_theta) |
114 |
, linear(_linear) |
115 |
, relative(_relative) |
116 |
{} |
117 |
|
118 |
QPointF pos; |
119 |
qreal theta; |
120 |
qreal linear; |
121 |
bool relative;
|
122 |
}; |
123 |
typedef std::vector<TeleportRequest> V_TeleportRequest;
|
124 |
V_TeleportRequest teleport_requests_; |
125 |
}; |
126 |
typedef boost::shared_ptr<Turtle> TurtlePtr;
|
127 |
|
128 |
} |
129 |
|
130 |
#endif
|