38 #define DEFAULT_BG_R 0x45 39 #define DEFAULT_BG_G 0x56 40 #define DEFAULT_BG_B 0xff 47 , path_image_(500, 500, QImage::Format_ARGB32)
48 , path_painter_(&path_image_)
52 setFixedSize(500, 500);
53 setWindowTitle(
"TurtleSim");
67 QVector<QString> turtles;
68 turtles.append(
"box-turtle.png");
69 turtles.append(
"robot-turtle.png");
70 turtles.append(
"sea-turtle.png");
71 turtles.append(
"diamondback.png");
72 turtles.append(
"electric.png");
73 turtles.append(
"fuerte.png");
74 turtles.append(
"groovy.png");
75 turtles.append(
"hydro.svg");
76 turtles.append(
"indigo.svg");
77 turtles.append(
"jade.png");
78 turtles.append(
"kinetic.png");
79 turtles.append(
"lunar.png");
82 for (
int i = 0; i < turtles.size(); ++i)
85 img.load(images_path + turtles[i]);
107 for(
int index = 0; index < turtles.size(); ++index)
109 QString name = turtles[index];
110 name = name.split(
".").first();
111 name.replace(QString(
"-"), QString(
""));
112 spawnTurtle(name.toStdString(), 1.0 + 1.5 * (index % 7), 1.0 + 1.5 * (index / 7),
PI / 2.0, index);
124 std::string name =
spawnTurtle(req.name, req.x, req.y, req.theta);
127 ROS_ERROR(
"A turtled named [%s] already exists", req.name.c_str());
138 M_Turtle::iterator it =
turtles_.find(req.name);
141 ROS_ERROR(
"Tried to kill turtle [%s], which does not exist", req.name.c_str());
163 std::string real_name = name;
164 if (real_name.empty())
168 std::stringstream ss;
170 real_name = ss.str();
185 ROS_INFO(
"Spawning turtle [%s] at x=[%f], y=[%f], theta=[%f]", real_name.c_str(), x, y, angle);
218 QPainter painter(
this);
222 M_Turtle::iterator it =
turtles_.begin();
223 M_Turtle::iterator end =
turtles_.end();
224 for (; it != end; ++it)
226 it->second->paint(painter);
238 bool modified =
false;
239 M_Turtle::iterator it =
turtles_.begin();
240 M_Turtle::iterator end =
turtles_.end();
241 for (; it != end; ++it)
bool hasTurtle(const std::string &name)
bool spawnCallback(turtlesim::Spawn::Request &, turtlesim::Spawn::Response &)
ros::ServiceServer kill_srv_
bool clearCallback(std_srvs::Empty::Request &, std_srvs::Empty::Response &)
void paintEvent(QPaintEvent *event)
ROSCPP_DECL const std::string & getName()
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
ros::ServiceServer clear_srv_
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
TurtleFrame(QWidget *parent=0, Qt::WindowFlags f=0)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
ROSLIB_DECL std::string getPath(const std::string &package_name)
bool killCallback(turtlesim::Kill::Request &, turtlesim::Kill::Response &)
bool resetCallback(std_srvs::Empty::Request &, std_srvs::Empty::Response &)
ros::ServiceServer spawn_srv_
ros::ServiceServer reset_srv_
std::string spawnTurtle(const std::string &name, float x, float y, float angle)
ROSCPP_DECL void spinOnce()
void setParam(const std::string &key, const XmlRpc::XmlRpcValue &v) const
ros::WallTime last_turtle_update_
QVector< QImage > turtle_images_