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");
81 for (
int i = 0; i < turtles.size(); ++i)
84 img.load(images_path + turtles[i]);
106 for(
int index = 0; index < turtles.size(); ++index)
108 QString name = turtles[index];
109 name = name.split(
".").first();
110 name.replace(QString(
"-"), QString(
""));
111 spawnTurtle(name.toStdString(), 1.0 + 1.5 * (index % 7), 1.0 + 1.5 * (index / 7),
PI / 2.0, index);
123 std::string name =
spawnTurtle(req.name, req.x, req.y, req.theta);
126 ROS_ERROR(
"A turtled named [%s] already exists", req.name.c_str());
137 M_Turtle::iterator it =
turtles_.find(req.name);
140 ROS_ERROR(
"Tried to kill turtle [%s], which does not exist", req.name.c_str());
162 std::string real_name = name;
163 if (real_name.empty())
167 std::stringstream ss;
169 real_name = ss.str();
184 ROS_INFO(
"Spawning turtle [%s] at x=[%f], y=[%f], theta=[%f]", real_name.c_str(), x, y, angle);
217 QPainter painter(
this);
221 M_Turtle::iterator it =
turtles_.begin();
222 M_Turtle::iterator end =
turtles_.end();
223 for (; it != end; ++it)
225 it->second->paint(painter);
237 bool modified =
false;
238 M_Turtle::iterator it =
turtles_.begin();
239 M_Turtle::iterator end =
turtles_.end();
240 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_