45 #include <sys/types.h> 60 #include <FL/Fl_Box.H> 61 #include <FL/Fl_Gl_Window.H> 62 #include <FL/Fl_Menu_Bar.H> 63 #include <FL/Fl_Window.H> 64 #include <FL/fl_draw.H> 68 #include <OpenGL/glu.h> 105 const char COPYRIGHT[] =
"Copyright Richard Vaughan and contributors 2000-2017";
108 const char AUTHORS[] =
"Richard Vaughan, Brian Gerkey, Andrew Howard, Reed Hedges, Pooya Karimian, " 109 "Toby Collett, Jeremy Asher, Alex Couture-Beil, Adrian Böckenkamp and " 113 const char WEBSITE[] =
"http://playerstage.org";
116 const char DESCRIPTION[] =
"Robot simulation library\nPart of the Player Project";
120 "Stage robot simulation library\n" 121 "Copyright (C) 2000-2017 Richard Vaughan and contributors\n" 122 "Part of the Player Project [http://playerstage.org]\n" 124 "This program is free software; you can redistribute it and/or\n" 125 "modify it under the terms of the GNU General Public License\n" 126 "as published by the Free Software Foundation; either version 2\n" 127 "of the License, or (at your option) any later version.\n" 129 "This program is distributed in the hope that it will be useful,\n" 130 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" 131 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" 132 "GNU General Public License for more details.\n" 134 "You should have received a copy of the GNU General Public License\n" 135 "along with this program; if not, write to the Free Software\n" 136 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n" 138 "The text of the license may also be available online at\n" 139 "http://www.gnu.org/licenses/old-licenses/gpl-2.0.html\n";
153 return (r * 180.0 / M_PI);
159 return (d * M_PI / 180.0);
175 return (a < 0 ? -1 : 1);
179 inline double sgn(
double a)
181 return (a < 0 ? -1.0 : 1.0);
218 explicit Color(
double r,
double g,
double b,
double a = 1.0);
223 explicit Color(
const std::string &name);
230 void Print(
const char *prefix)
const;
237 void GLSet(
void) { glColor4f(r, g, b, a); }
245 Size(meters_t x, meters_t y, meters_t z) : x(x), y(y), z(z) { }
248 Size() : x(0.4), y(0.4), z(1.0) { }
251 void Save(
Worldfile *wf,
int section,
const char *keyword)
const;
253 void Zero() { x = y = z = 0.0; }
262 Pose(meters_t x, meters_t y, meters_t z, radians_t a) : x(x), y(y), z(z), a(a) { }
264 Pose() : x(0.0), y(0.0), z(0.0), a(0.0) { }
269 static Pose Random(meters_t xmin, meters_t xmax, meters_t ymin, meters_t ymax)
271 return Pose(xmin + drand48() * (xmax - xmin), ymin + drand48() * (ymax - ymin), 0,
278 virtual void Print(
const char *prefix)
const 280 printf(
"%s pose [x:%.3f y:%.3f z:%.3f a:%.3f]\n", prefix, x, y, z, a);
286 snprintf(buf, 256,
"[ %.3f %.3f %.3f %.3f ]", x, y, z, a);
287 return std::string(buf);
291 bool IsZero()
const {
return (!(x || y || z || a)); }
293 void Zero() { x = y = z = a = 0.0; }
295 void Save(
Worldfile *wf,
int section,
const char *keyword);
299 const double cosa = cos(a);
300 const double sina = sin(a);
302 return Pose(x + p.
x * cosa - p.
y * sina, y + p.
x * sina + p.
y * cosa, z + p.
z,
311 return ((y * y + x * x) < (p.
y * p.
y + p.
x * p.
x));
316 return (x == other.
x && y == other.
y && z == other.
z && a == other.
a);
321 return (x != other.
x || y != other.
y || z != other.
z || a != other.
a);
324 meters_t
Distance(
const Pose &other)
const {
return hypot(x - other.
x, y - other.
y); }
336 : pose(pose), mod(mod), color(color), range(range)
365 virtual void Print(
const char *prefix)
const 368 printf(
"%s", prefix);
370 printf(
"velocity [x:%.3f y:%.3f z:%3.f a:%.3f]\n", x, y, z,
a);
386 void Print(
const char *prefix)
const 389 printf(
"%s", prefix);
391 printf(
"geom pose: (%.2f,%.2f,%.2f) size: [%.2f,%.2f]\n", pose.
x, pose.
y, pose.
a, size.
x,
415 Bounds(
double min,
double max) : min(min), max(max) { }
420 double Constrain(
double value);
447 point_t(meters_t x, meters_t y) : x(x), y(y) {}
467 point3_t(meters_t x, meters_t y, meters_t z) : x(x), y(y), z(z) {}
499 void coord_shift(
double x,
double y,
double z,
double a);
502 void draw_string(
float x,
float y,
float z,
const char *
string);
506 void draw_octagon(
float x,
float y,
float w,
float h,
float m);
509 void draw_array(
float x,
float y,
float w,
float h,
float *data,
size_t len,
size_t offset,
510 float min,
float max);
511 void draw_array(
float x,
float y,
float w,
float h,
float *data,
size_t len,
size_t offset);
526 Visualizer(
const std::string &menu_name,
const std::string &worldfile_name)
527 : menu_name(menu_name), worldfile_name(worldfile_name)
532 virtual void Visualize(Model *mod,
Camera *cam) = 0;
545 double constrain(
double val,
double minval,
double maxval);
569 typedef bool (*
ray_test_func_t)(Model *candidate,
const Model *finder,
const void *arg);
573 #define VAR(V, init) __typeof(init) V = (init) 580 #define FOR_EACH(I, C) for (VAR(I, (C).begin()), ite = (C).end(); (I) != ite; ++(I)) 584 template <
class T,
class C>
void EraseAll(T thing, C &cont)
586 cont.erase(std::remove(cont.begin(), cont.end(), thing), cont.end());
590 #define PRINT_ERR(m) fprintf(stderr, "\033[41merr\033[0m: " m " (%s %s)\n", __FILE__, __FUNCTION__) 591 #define PRINT_ERR1(m, a) \ 592 fprintf(stderr, "\033[41merr\033[0m: " m " (%s %s)\n", a, __FILE__, __FUNCTION__) 593 #define PRINT_ERR2(m, a, b) \ 594 fprintf(stderr, "\033[41merr\033[0m: " m " (%s %s)\n", a, b, __FILE__, __FUNCTION__) 595 #define PRINT_ERR3(m, a, b, c) \ 596 fprintf(stderr, "\033[41merr\033[0m: " m " (%s %s)\n", a, b, c, __FILE__, __FUNCTION__) 597 #define PRINT_ERR4(m, a, b, c, d) \ 598 fprintf(stderr, "\033[41merr\033[0m: " m " (%s %s)\n", a, b, c, d, __FILE__, __FUNCTION__) 599 #define PRINT_ERR5(m, a, b, c, d, e) \ 600 fprintf(stderr, "\033[41merr\033[0m: " m " (%s %s)\n", a, b, c, d, e, __FILE__, __FUNCTION__) 603 #define PRINT_WARN(m) printf("\033[44mwarn\033[0m: " m " (%s %s)\n", __FILE__, __FUNCTION__) 604 #define PRINT_WARN1(m, a) printf("\033[44mwarn\033[0m: " m " (%s %s)\n", a, __FILE__, __FUNCTION__) 605 #define PRINT_WARN2(m, a, b) \ 606 printf("\033[44mwarn\033[0m: " m " (%s %s)\n", a, b, __FILE__, __FUNCTION__) 607 #define PRINT_WARN3(m, a, b, c) \ 608 printf("\033[44mwarn\033[0m: " m " (%s %s)\n", a, b, c, __FILE__, __FUNCTION__) 609 #define PRINT_WARN4(m, a, b, c, d) \ 610 printf("\033[44mwarn\033[0m: " m " (%s %s)\n", a, b, c, d, __FILE__, __FUNCTION__) 611 #define PRINT_WARN5(m, a, b, c, d, e) \ 612 printf("\033[44mwarn\033[0m: " m " (%s %s)\n", a, b, c, d, e, __FILE__, __FUNCTION__) 616 #define PRINT_MSG(m) printf("Stage: " m " (%s %s)\n", __FILE__, __FUNCTION__) 617 #define PRINT_MSG1(m, a) printf("Stage: " m " (%s %s)\n", a, __FILE__, __FUNCTION__) 618 #define PRINT_MSG2(m, a, b) printf("Stage: " m " (%s %s)\n", a, b, __FILE__, __FUNCTION__) 619 #define PRINT_MSG3(m, a, b, c) printf("Stage: " m " (%s %s)\n", a, b, c, __FILE__, __FUNCTION__) 620 #define PRINT_MSG4(m, a, b, c, d) \ 621 printf("Stage: " m " (%s %s)\n", a, b, c, d, __FILE__, __FUNCTION__) 622 #define PRINT_MSG5(m, a, b, c, d, e) \ 623 printf("Stage: " m " (%s %s)\n", a, b, c, d, e, __FILE__, __FUNCTION__) 625 #define PRINT_MSG(m) printf("Stage: " m "\n") 626 #define PRINT_MSG1(m, a) printf("Stage: " m "\n", a) 627 #define PRINT_MSG2(m, a, b) printf("Stage: " m "\n,", a, b) 628 #define PRINT_MSG3(m, a, b, c) printf("Stage: " m "\n", a, b, c) 629 #define PRINT_MSG4(m, a, b, c, d) printf("Stage: " m "\n", a, b, c, d) 630 #define PRINT_MSG5(m, a, b, c, d, e) printf("Stage: " m "\n", a, b, c, d, e) 635 #define PRINT_DEBUG(m) printf("debug: " m " (%s %s)\n", __FILE__, __FUNCTION__) 636 #define PRINT_DEBUG1(m, a) printf("debug: " m " (%s %s)\n", a, __FILE__, __FUNCTION__) 637 #define PRINT_DEBUG2(m, a, b) printf("debug: " m " (%s %s)\n", a, b, __FILE__, __FUNCTION__) 638 #define PRINT_DEBUG3(m, a, b, c) printf("debug: " m " (%s %s)\n", a, b, c, __FILE__, __FUNCTION__) 639 #define PRINT_DEBUG4(m, a, b, c, d) \ 640 printf("debug: " m " (%s %s)\n", a, b, c, d, __FILE__, __FUNCTION__) 641 #define PRINT_DEBUG5(m, a, b, c, d, e) \ 642 printf("debug: " m " (%s %s)\n", a, b, c, d, e, __FILE__, __FUNCTION__) 644 #define PRINT_DEBUG(m) 645 #define PRINT_DEBUG1(m, a) 646 #define PRINT_DEBUG2(m, a, b) 647 #define PRINT_DEBUG3(m, a, b, c) 648 #define PRINT_DEBUG4(m, a, b, c, d) 649 #define PRINT_DEBUG5(m, a, b, c, d, e) 669 std::map<std::string, void *>
props;
685 virtual void AddChild(Model *mod);
686 virtual void RemoveChild(Model *mod);
687 virtual Pose GetGlobalPose()
const;
689 const char *
Token()
const {
return token.c_str(); }
690 const std::string &
TokenStr()
const {
return token; }
698 PRINT_WARN(
"Ancestor::SetToken() called with zero length string. Ignored.");
702 void SetProperty(std::string &key,
void *value) { props[key] = value; }
706 std::map<std::string, void *>::iterator it = props.find(key);
707 return (it == props.end() ? NULL : it->second);
714 const void *arg,
const bool ztest)
715 : mod(mod), origin(origin), range(range), func(func), arg(arg), ztest(ztest)
719 Ray() : mod(NULL), origin(0, 0, 0, 0), range(0), func(NULL), arg(NULL), ztest(true) {}
740 LogEntry(usec_t timestamp, Model *mod);
743 static std::vector<LogEntry>
log;
746 static size_t Count() {
return log.size(); }
748 static void Clear() { log.clear(); }
758 CtrlArgs(std::string w, std::string c) : worldfile(w), cmdline(c) {}
770 friend class WorkerThread;
775 static std::vector<std::string>
args;
781 static void UpdateCb(World *world);
801 bool operator()(
const Model *
a,
const Model *
b)
const;
805 bool operator()(
const Model *
a,
const Model *
b)
const;
820 models_with_fiducials.push_back(mod);
826 void LoadWorldPostHook();
842 std::list<std::pair<world_callback_t, void *> >
848 std::list<PowerPack *>
859 void CallUpdateCallbacks();
865 virtual void Start() { paused =
false; }
866 virtual void Stop() { paused =
true; }
876 static const int DEFAULT_PPM = 50;
887 void Log(Model *mod);
896 virtual std::string ClockString(
void)
const;
898 Model *CreateModel(Model *parent,
const std::string &typestr);
900 void LoadModel(
Worldfile *wf,
int entity);
901 void LoadBlock(
Worldfile *wf,
int entity);
902 void LoadBlockGroup(
Worldfile *wf,
int entity);
903 void LoadSensor(
Worldfile *wf,
int entity);
908 void MapPoly(
const std::vector<point_int_t> &poly,
Block *block,
unsigned int layer);
920 return point_int_t(MetersToPixels(pt.
x), MetersToPixels(pt.
y));
942 const Model *finder,
const void *arg,
const bool ztest);
944 void Raytrace(
const Pose &gpose,
946 const Model *model,
const void *arg,
const bool ztest,
947 std::vector<RaytraceResult> &results);
952 virtual void AddModel(Model *mod);
953 virtual void RemoveModel(Model *mod);
955 void AddModelName(Model *mod,
const std::string &name);
963 void RecordRay(
double x1,
double y1,
double x2,
double y2);
969 static void *update_thread_entry(std::pair<World *, int> *info);
974 : time(time), mod(mod), cb(cb), arg(arg)
985 bool operator<(
const Event &other)
const;
1007 event_queues[queue_num].push(
Event(sim_time + delay, mod, cb, arg));
1026 void ConsumeQueue(
unsigned int queue_num);
1030 unsigned int GetEventQueue(Model *mod)
const;
1034 static bool UpdateAll();
1044 World(
const std::string &name =
"MyWorld",
double ppm = DEFAULT_PPM);
1056 virtual bool IsGUI()
const {
return false; }
1064 virtual bool Load(
const std::string &worldfile_path);
1077 virtual bool Load(std::istream &world_content,
const std::string &worldfile_path = std::string());
1079 virtual void UnLoad();
1081 virtual void Reload();
1085 virtual bool Save(
const char *filename);
1090 virtual bool Update(
void);
1111 Model *GetModel(
const std::string &name)
const;
1120 void RegisterOption(
Option *opt);
1148 void Map(
unsigned int layer);
1151 void UnMap(
unsigned int layer);
1154 void DrawSolid(
bool topview);
1157 void DrawFootPrint();
1160 void Translate(
double x,
double y);
1169 void SetCenterX(
double y);
1172 void SetCenterY(
double y);
1175 void SetCenter(
double x,
double y);
1178 void SetZ(
double min,
double max);
1180 void AppendTouchingModels(std::set<Model *> &touchers);
1183 Model *TestCollision();
1187 void Rasterize(uint8_t *data,
unsigned int width,
unsigned int height, meters_t cellwidth,
1188 meters_t cellheight);
1199 std::vector<Cell *> rendered_cells[2];
1219 void AppendBlock(
const Block &block);
1224 void AppendTouchingModels(std::set<Model *> &touchers);
1228 Model *TestCollision();
1231 void Map(
unsigned int layer);
1233 void UnMap(
unsigned int layer);
1237 void LoadBitmap(
const std::string &bitmapfile,
Worldfile *wf);
1240 void LoadBlock(
Worldfile *wf,
int entity);
1243 void Rasterize(uint8_t *data,
unsigned int width,
unsigned int height, meters_t cellwidth,
1244 meters_t cellheight);
1247 void DrawSolid(
const Geom &geom);
1252 void BuildDisplayList();
1255 void CallDisplayList();
1268 void DrawFootPrint(
const Geom &geom);
1278 Camera() : _pitch(0), _yaw(0), _x(0), _y(0), _z(0) {}
1280 virtual void Draw(
void)
const = 0;
1281 virtual void SetProjection(
void)
const = 0;
1283 double yaw(
void)
const {
return _yaw; }
1284 double pitch(
void)
const {
return _pitch; }
1285 double x(
void)
const {
return _x; }
1286 double y(
void)
const {
return _y; }
1287 double z(
void)
const {
return _z; }
1288 virtual void reset() = 0;
1307 virtual void Draw(
void)
const;
1308 virtual void SetProjection(
void)
const;
1312 void strafe(
double amount);
1313 void forward(
double amount);
1329 void move(
double x,
double y,
double z);
1330 void setFov(
double horiz_fov,
double vert_fov)
1332 _horiz_fov = horiz_fov;
1333 _vert_fov = vert_fov;
1347 else if (_pitch > 180)
1353 return _z_near * _z_far / (_z_far - z_buf_val * (_z_far - _z_near));
1383 OrthoCamera(
void) : _scale(15), _pixels_width(0), _pixels_height(0), _y_min(0), _y_max(0) {}
1384 virtual void Draw()
const;
1386 virtual void SetProjection(
double pixels_width,
double pixels_height,
double y_min,
double y_max);
1388 virtual void SetProjection(
void)
const;
1390 void move(
double x,
double y);
1400 else if (_pitch < 0)
1411 void scale(
double scale,
double shift_x = 0,
double h = 0,
double shift_y = 0,
double w = 0);
1459 static void windowCb(Fl_Widget *w,
WorldGui *wg);
1460 static void fileLoadCb(Fl_Widget *w,
WorldGui *wg);
1461 static void fileSaveCb(Fl_Widget *w,
WorldGui *wg);
1462 static void fileSaveAsCb(Fl_Widget *w,
WorldGui *wg);
1463 static void fileExitCb(Fl_Widget *w,
WorldGui *wg);
1466 static void helpAboutCb(Fl_Widget *w,
WorldGui *wg);
1467 static void pauseCb(Fl_Widget *w,
WorldGui *wg);
1468 static void onceCb(Fl_Widget *w,
WorldGui *wg);
1469 static void fasterCb(Fl_Widget *w,
WorldGui *wg);
1470 static void slowerCb(Fl_Widget *w,
WorldGui *wg);
1471 static void realtimeCb(Fl_Widget *w,
WorldGui *wg);
1472 static void fasttimeCb(Fl_Widget *w,
WorldGui *wg);
1473 static void resetViewCb(Fl_Widget *w,
WorldGui *wg);
1474 static void moreHelptCb(Fl_Widget *w,
WorldGui *wg);
1477 bool saveAsDialog();
1478 bool closeWindowQuery();
1480 virtual void AddModel(Model *mod);
1485 void LoadWorldGuiPostHook(usec_t load_start_time);
1488 virtual void PushColor(
Color col);
1489 virtual void PushColor(
double r,
double g,
double b,
double a);
1490 virtual void PopColor();
1492 void DrawOccupancy()
const;
1493 void DrawVoxels()
const;
1496 WorldGui(
int width,
int height,
const char *caption = NULL);
1500 virtual void Redraw(
void);
1502 virtual std::string ClockString()
const;
1504 virtual bool Load(
const std::string &worldfile_path);
1505 virtual bool Load(std::istream &world_content,
const std::string &worldfile_path = std::string());
1507 virtual void UnLoad();
1508 virtual bool Save(
const char *filename);
1509 virtual bool IsGUI()
const {
return true; }
1510 virtual Model *RecentlySelectedModel()
const;
1512 virtual void Start();
1513 virtual void Stop();
1515 usec_t RealTimeNow(
void)
const;
1517 void DrawBoundingBoxTree();
1524 std::string EnergyString(
void)
const;
1525 virtual void RemoveChild(Model *mod);
1537 float x,
y, w, h, min, max;
1542 const char *name,
const char *wfname);
1544 virtual void Visualize(Model *mod,
Camera *cam);
1545 void AppendValue(
float value);
1566 DissipationVis(meters_t width, meters_t height, meters_t cellsize);
1569 virtual void Visualize(Model *mod,
Camera *cam);
1571 void Accumulate(meters_t x, meters_t y, joules_t amount);
1608 void Visualize(
Camera *cam);
1611 joules_t RemainingCapacity()
const;
1614 void Add(joules_t j);
1617 void Subtract(joules_t j);
1620 void TransferTo(
PowerPack *dest, joules_t amount);
1628 printf(
"%s", prefix);
1630 printf(
"PowerPack %.2f/%.2f J\n", stored, capacity);
1633 joules_t GetStored()
const;
1634 joules_t GetCapacity()
const;
1635 joules_t GetDissipated()
const;
1636 void SetCapacity(joules_t j);
1637 void SetStored(joules_t j);
1644 void Dissipate(joules_t j);
1647 void Dissipate(joules_t j,
const Pose &p);
1673 const std::vector<Option *> &
getOptions()
const {
return drawOptions; }
1695 cb_t() : callback(NULL), arg(NULL) {}
1700 return (arg < other.
arg);
1716 void SetColor(
const Color &col);
1717 void SetSize(
double sz);
1722 Flag *Nibble(
double portion);
1726 void Draw(GLUquadric *quadric);
1827 virtual void Visualize(Model *mod,
Camera *cam);
1829 void SetData(uint8_t *data,
unsigned int width,
unsigned int height, meters_t cellwidth,
1830 meters_t cellheight);
1835 void AddPoint(meters_t x, meters_t y);
1909 if (str.size() > 0) {
1913 PRINT_ERR(
"Model::SetToken() called with zero length string. Ignored.");
1920 Model *GetChild(
const std::string &name)
const;
1936 void Save(
Worldfile *wf,
int wf_entity);
1945 void Rasterize(uint8_t *data,
unsigned int width,
unsigned int height, meters_t cellwidth,
1946 meters_t cellheight);
1955 explicit Model(
const Model &original);
1959 Model &operator=(
const Model &original);
1963 void RegisterOption(
Option *opt);
1965 void AppendTouchingModels(std::set<Model *> &touchers);
1971 Model *TestCollision();
1973 void Map(
unsigned int layer);
1982 void UnMap(
unsigned int layer);
1991 void MapWithChildren(
unsigned int layer);
1992 void UnMapWithChildren(
unsigned int layer);
1995 void MapFromRoot(
unsigned int layer);
1996 void UnMapFromRoot(
unsigned int layer);
2001 const void *arg,
const bool ztest)
2003 return world->
Raytrace(LocalToGlobal(pose), range, func,
this, arg, ztest);
2010 std::vector<RaytraceResult> &results)
2012 return world->
Raytrace(LocalToGlobal(pose), range, fov, func,
this, arg, ztest, results);
2015 virtual void UpdateCharge();
2024 void CallUpdateCallbacks(
void);
2026 meters_t ModelHeight()
const;
2028 void DrawBlocksTree();
2029 virtual void DrawBlocks();
2030 void DrawBoundingBox();
2031 void DrawBoundingBoxTree();
2032 virtual void DrawStatus(
Camera *cam);
2033 void DrawStatusTree(
Camera *cam);
2035 void DrawOriginTree();
2038 void PushLocalCoords();
2042 void DrawImage(uint32_t texture_id,
Camera *cam,
float alpha,
double width = 1.0,
2043 double height = 1.0);
2045 virtual void DrawPicker();
2046 virtual void DataVisualize(
Camera *cam);
2047 virtual void DrawSelected(
void);
2049 void DrawTrailFootprint();
2050 void DrawTrailBlocks();
2051 void DrawTrailArrows();
2054 void DataVisualizeTree(
Camera *cam);
2055 void DrawFlagList();
2056 void DrawPose(
Pose pose);
2078 bool PlaceInFreeSpace(meters_t xmin, meters_t xmax, meters_t ymin, meters_t ymax,
2079 size_t max_iter = 0);
2085 bool RandomPoseInFreeSpace(meters_t xmin, meters_t xmax, meters_t ymin, meters_t ymax,
2086 size_t max_iter = 0);
2091 static Model *
LookupId(uint32_t
id) {
return modelsbyid[id]; }
2093 Model(World *world, Model *parent = NULL,
const std::string &type =
"model",
2094 const std::string &name =
"");
2101 : mapped(false), alwayson(false), blockgroup(*this), boundary(false), data_fresh(false),
2102 disabled(true), friction(0), has_default_block(false), id(0), interval(0),
2103 interval_energy(0), last_update(0), log_state(false), map_resolution(0), mass(0),
2104 parent(NULL), power_pack(NULL), rebuild_displaylist(false), stack_children(true),
2105 stall(false), subs(0), thread_safe(false), trail_index(0), event_queue_num(0), used(false),
2106 watts(0), watts_give(0), watts_take(0), wf(NULL), wf_entity(0), world(NULL), world_gui(NULL)
2110 void Say(
const std::string &str);
2113 void AddVisualizer(
Visualizer *custom_visual,
bool on_by_default);
2117 void RemoveVisualizer(
Visualizer *custom_visual);
2119 void BecomeParentOf(Model *child);
2125 SetWorldfile(wf, wf_entity);
2133 this->wf_entity = wf_entity;
2137 virtual void Load();
2140 virtual void Save();
2143 void InitControllers();
2145 void AddFlag(
Flag *flag);
2146 void RemoveFlag(
Flag *flag);
2148 void PushFlag(
Flag *flag);
2164 void LoadControllerModule(
const char *lib);
2175 void LoadBlock(
Worldfile *wf,
int entity);
2179 void AddBlockRect(meters_t x, meters_t y, meters_t dx, meters_t dy, meters_t dz);
2186 Model *
Parent()
const {
return this->parent; }
2190 Model *
Root() {
return (parent ? parent->
Root() :
this); }
2191 bool IsAntecedent(
const Model *testmod)
const;
2194 bool IsDescendent(
const Model *testmod)
const;
2197 bool IsRelated(
const Model *testmod)
const;
2200 Pose GetGlobalPose()
const;
2209 void SetGlobalPose(
const Pose &gpose);
2212 void SetPose(
const Pose &pose);
2215 void AddToPose(
const Pose &pose);
2218 void AddToPose(
double dx,
double dy,
double dz,
double da);
2221 void SetGeom(
const Geom &src);
2225 void SetFiducialReturn(
int fid);
2231 void SetFiducialKey(
int key);
2237 kg_t GetTotalMass()
const;
2240 kg_t GetMassOfChildren()
const;
2243 int SetParent(Model *newparent);
2252 void SetColor(
Color col);
2253 void SetMass(kg_t mass);
2254 void SetStall(
bool stall);
2255 void SetGravityReturn(
bool val);
2256 void SetGripperReturn(
bool val);
2257 void SetStickyReturn(
bool val);
2258 void SetRangerReturn(
double val);
2259 void SetObstacleReturn(
bool val);
2260 void SetBlobReturn(
bool val);
2261 void SetRangerReturn(
bool val);
2262 void SetBoundary(
bool val);
2263 void SetGuiNose(
bool val);
2264 void SetGuiMove(
bool val);
2265 void SetGuiGrid(
bool val);
2266 void SetGuiOutline(
bool val);
2267 void SetWatts(watts_t watts);
2268 void SetMapResolution(meters_t
res);
2269 void SetFriction(
double friction);
2285 int CallCallbacks(callback_type_t type);
2287 virtual void Print(
char *prefix)
const;
2288 virtual const char *PrintWithPose()
const;
2292 Pose GlobalToLocal(
const Pose &pose)
const;
2298 std::vector<point_int_t> LocalToPixels(
const std::vector<point_t> &local)
const;
2306 Model *GetUnsubscribedModelOfType(
const std::string &type)
const;
2310 Model *GetUnusedModelOfType(
const std::string &type);
2323 virtual void Startup();
2324 virtual void Shutdown();
2336 uint32_t left,
top, right, bottom;
2343 explicit Vis(World *world);
2345 virtual void Visualize(Model *mod,
Camera *cam);
2359 static bool BlockMatcher(
Block *testblock, Model *finder);
2365 unsigned int scan_height;
2370 explicit ModelBlobfinder(World *world, Model *parent,
const std::string &type);
2374 virtual void Startup();
2375 virtual void Shutdown();
2377 virtual void Load();
2383 const std::vector<Blob> &
GetBlobs()
const {
return blobs; }
2388 void AddColor(
Color col);
2391 void RemoveColor(
Color col);
2395 void RemoveAllColors();
2404 void SetState(
bool isOn);
2407 virtual void DrawBlocks();
2452 double break_beam_inset[2];
2459 virtual void DataVisualize(
Camera *cam);
2462 void PositionPaddles();
2463 void UpdateBreakBeams();
2464 void UpdateContacts();
2478 ModelGripper(World *world, Model *parent,
const std::string &type);
2482 virtual void Load();
2483 virtual void Save();
2523 ModelBumper(World *world, Model *parent,
const std::string &type);
2526 virtual void Load();
2533 virtual void Startup();
2534 virtual void Shutdown();
2536 virtual void Print(
char *prefix)
const;
2542 virtual void Visualize(Model *mod,
Camera *cam);
2570 void AddModelIfVisible(Model *him);
2573 virtual void DataVisualize(
Camera *cam);
2581 ModelFiducial(World *world, Model *parent,
const std::string &type);
2584 virtual void Load();
2585 void Shutdown(
void);
2602 *count = fiducials.size();
2603 return &fiducials[0];
2613 ModelRanger(World *world, Model *parent,
const std::string &type);
2616 virtual void Print(
char *prefix)
const;
2626 explicit Vis(World *world);
2628 virtual void Visualize(Model *mod,
Camera *cam);
2648 : pose(0, 0, 0, 0), size(0.02, 0.02, 0.02),
2649 range(0.0, 5.0), fov(0.1), angle_noise(0.0), range_noise(0.0), range_noise_const(0.0),
2650 sample_count(1), color(
Color(0, 0, 1, 0.15)), ranges(), intensities(), bearings()
2656 std::string String()
const;
2661 const std::vector<Sensor> &
GetSensors()
const {
return sensors; }
2664 void LoadSensor(
Worldfile *wf,
int entity);
2670 virtual void Startup();
2671 virtual void Shutdown();
2690 virtual void Load();
2692 virtual void DataVisualize(
Camera *cam);
2717 static const int _depth = 4;
2734 ModelCamera(World *world, Model *parent,
const std::string &type);
2738 virtual void Load();
2747 virtual void DataVisualize(
Camera *cam);
2762 _pitch_offset = pitch;
2763 _valid_vertexbuf_cache =
false;
2770 _valid_vertexbuf_cache =
false;
2783 typedef enum { CONTROL_ACCELERATION, CONTROL_VELOCITY, CONTROL_POSITION }
ControlMode;
2789 typedef enum { DRIVE_DIFFERENTIAL, DRIVE_OMNI, DRIVE_CAR }
DriveMode;
2808 ModelPosition(World *world, Model *parent,
const std::string &type);
2815 void SetVelocity(
const Velocity &val);
2817 Velocity GetGlobalVelocity()
const;
2819 void SetGlobalVelocity(
const Velocity &gvel);
2827 Waypoint(meters_t x, meters_t y, meters_t z, radians_t
a,
Color color);
2842 virtual void Visualize(Model *mod,
Camera *cam);
2849 virtual void Visualize(Model *mod,
Camera *cam);
2853 void SetOdom(
Pose odom);
2857 void SetSpeed(
double x,
double y,
double a);
2858 void SetXSpeed(
double x);
2859 void SetYSpeed(
double y);
2860 void SetZSpeed(
double z);
2861 void SetTurnSpeed(
double a);
2868 void GoTo(
double x,
double y,
double a);
2869 void GoTo(
Pose pose);
2874 void SetAcceleration(
double x,
double y,
double a);
2882 virtual void Move();
2883 virtual void Startup();
2884 virtual void Shutdown();
2886 virtual void Load();
2917 ModelActuator(World *world, Model *parent,
const std::string &type);
2921 virtual void Startup();
2922 virtual void Shutdown();
2924 virtual void Load();
2928 void SetSpeed(
double speed);
2933 void GoTo(
double pose);
2938 ActuatorType
GetType()
const {
return actuator_type; }
radians_t fov
field of view
static bool quit_all
quit all worlds ASAP
meters_t range
range to the target
bool operator==(const Color &other) const
std::vector< point_int_t > rt_candidate_cells
virtual void PushColor(Color col)
Bounds local_z
z extent in local coords.
Geom(const Pose &p, const Size &s)
const PerspectiveCamera & getCamera(void) const
get reference to camera used
meters_t max_range_anon
maximum detection range
void coord_shift(double x, double y, double z, double a)
static Option showBlinkenData
msec_t period
duration of a complete cycle
Worldfile * GetWorldFile()
bool autosnatch
if true, cycle the gripper through open-close-up-down automatically
point3_t(meters_t x, meters_t y, meters_t z)
std::vector< Blob > blobs
meters_t size
rendered as a sphere with this diameter
int subs
the number of subscriptions to this model
Event(usec_t time, Model *mod, model_callback_t cb, void *arg)
const std::string & GetWorldfileName()
point_int_t(int x, int y)
pthread_cond_t threads_done_cond
signalled by last worker thread to unblock main thread
void Enqueue(unsigned int queue_num, usec_t delay, Model *mod, model_callback_t cb, void *arg)
Bounds y
volume extent along y axis, initially zero
radians_t heading
center of field of view
virtual void PushColor(Color col)
dummy implementations to be overloaded by GUI subclasses
double GetMinPosition() const
double Resolution() const
static joules_t global_input
bool operator==(const Pose &other) const
unsigned int FullVersion()
unsigned int GetFlagCount() const
usec_t GetEnergyInterval() const
Velocity GetVelocity() const
uint64_t updates
the number of simulated time steps executed so far
ActuatorType GetType() const
const std::string & GetMenuName()
bool stack_children
whether child models should be stacked on top of this model or not
bool graphics
true iff we have a GUI
double max
largest value in range, initially zero
int32_t MetersToPixels(meters_t x) const
The Stage library uses its own namespace.
std::set< Model *, ltx > models_with_fiducials_byx
std::vector< Fiducial > & GetFiducials()
fiducial detector?
void EnableEnergy(Model *m)
void setPose(double x, double y)
static std::vector< std::string > args
static const Color magenta
radians_t fov
Horizontal field of view in radians, in the range 0 to pi.
GLubyte * _frame_color_data
unsigned int show_clock_interval
updates between clock outputs
Pose operator+(const Pose &p) const
double lift_position
0.0 = full down, 1.0 full up
Verbed these to match the paddle state.
cb_t(model_callback_t cb, void *arg)
virtual void PushColor(double r, double g, double b, double a)
static joules_t global_capacity
std::map< point_int_t, SuperRegion * > superregions
int key
/// only detect fiducials with a key that matches this one (defaults 0)
ActuatorType actuator_type
CtrlArgs(std::string w, std::string c)
virtual void PushColor(double r, double g, double b, double a)
void Init(int *argc, char **argv[])
std::vector< Sensor > & GetSensorsMutable()
void addPose(double x, double y, double z)
void Raytrace(const Pose &pose, const meters_t range, const radians_t fov, const ray_test_func_t func, const void *arg, const bool ztest, std::vector< RaytraceResult > &results)
const std::string menu_name
pthread_cond_t threads_start_cond
signalled to unblock worker threads
static Color RandomColor()
cb_t(world_callback_t cb, void *arg)
static std::set< World * > world_set
all the worlds that exist
bool HasSubscribers() const
static joules_t global_stored
bool used
TRUE iff this model has been returned by GetUnusedModelOfType()
watts_t watts
power consumed by this model
int(* model_callback_t)(Model *mod, void *user)
void EraseAll(T thing, C &cont)
std::vector< point_t > pts
double min
smallest value in range, initially zero
std::vector< Color > colors
PerspectiveCamera _camera
void SetConfig(config_t &newcfg)
std::list< PowerPack * > powerpack_list
List of all the powerpacks attached to models in the world.
void draw_origin(double len)
void Print(const char *prefix) const
virtual Model * RecentlySelectedModel() const
double ppm
the resolution of the world model in pixels per meter
int displaylist
OpenGL displaylist that renders this blockgroup.
Pose & Load(Worldfile *wf, int section, const char *keyword)
std::vector< Fiducial > fiducials
double duty_cycle
mark/space ratio
FileManager * fileMan
Used to load and save worldfiles.
std::vector< Blob > & GetBlobsMutable()
std::string String() const
void draw_string_multiline(float x, float y, float w, float h, const char *string, Fl_Align align)
void setPose(double x, double y, double z)
unsigned int event_queue_num
usec_t interval_energy
time between updates of powerpack in usec
void Print(const char *prefix) const
std::vector< Sensor > sensors
usec_t time
time that event occurs
void Load(Worldfile *wf, int wf_entity)
unsigned int worker_threads
the number of worker threads to use
virtual void Print(const char *prefix) const
Bounds(double min, double max)
std::vector< TrailItem > trail
double ranger_return
0 - 1
void setFov(double horiz_fov, double vert_fov)
const std::string worldfile_name
const std::vector< Option * > & getOptions() const
const GLfloat * FrameDepth() const
get a reference to camera depth buffer
virtual ~WaypointVis(void)
const std::vector< Sensor > & GetSensors() const
meters_t z
location in 3 axes
std::set< ModelPosition * > active_velocity
point_t(meters_t x, meters_t y)
void draw_octagon(float x, float y, float w, float h, float m)
void SetWorldfile(Worldfile *wf, int wf_entity)
bool _valid_vertexbuf_cache
void Print(const char *prefix) const
Bounds global_z
z extent in global coordinates.
Pose LocalToGlobal(const Pose &pose) const
int total_subs
the total number of subscriptions to all models
uint64_t GetUpdateCount() const
std::set< Model *, lty > models_with_fiducials_byy
std::map< int, Model * > models_by_wfentity
std::list< std::pair< world_callback_t, void * > > cb_list
List of callback functions and arguments.
double horizFov(void) const
double GetMaxPosition() const
std::vector< point_t > pts
points defining a polygon.
bool operator==(const point_int_t &other) const
void pose_inverse_shift(const Pose &pose)
const GLubyte * FrameColor() const
get a reference to camera color image. 4 bytes (RGBA) per pixel
double normalize(double a)
std::vector< Model * > & GetChildren()
bool operator<(const Pose &p) const
a < b iff a is closer to the origin than b
unsigned int GetSubscriptionCount() const
const Color & Load(Worldfile *wf, int entity)
std::vector< double > bearings
std::list< Visualizer * > cv_list
Canvas * GetCanvas(void) const
WorldGui * world_gui
Pointer to the GUI world - NULL if running in non-gui mode.
Model * mod
model to pass into callback
virtual ~Visualizer(void)
std::vector< joules_t > cells
usec_t sim_time
the current sim time in this world in microseconds
void draw_centered_rect(float x, float y, float dx, float dy)
unsigned int sample_count
void setClip(double near, double far)
Size paddle_size
paddle dimensions
uint32_t GetCount() const
virtual void TogglePause()
const bounds3d_t & GetExtent() const
void FiducialErase(Model *mod)
static Pose Random(meters_t xmin, meters_t xmax, meters_t ymin, meters_t ymax)
const Block & GetBlock(unsigned int index) const
std::vector< Block > blocks
Contains the blocks in this group.
radians_t bearing
bearing to the target
unsigned int threads_working
the number of worker threads not yet finished
void addPitch(double pitch)
std::vector< usec_t > interval_log
meters_t Distance(const Pose &other) const
const std::string & TokenStr() const
int Update(Model *mod, info_t *info)
static unsigned int next_id
initially zero, used to allocate unique sequential world ids
pthread_mutex_t sync_mutex
protect the worker thread management stuff
bool operator==(const cb_t &other) const
bool dirty
iff true, a gui redraw would be required
int getWidth(void) const
width of captured image
model_callback_t callback
meters_t max_range_id
maximum range at which the ID can be read
std::string GetSayString()
void FiducialInsert(Model *mod)
Pose goal
the current velocity or pose to reach, depending on the value of control_mode
bounds3d_t extent
Describes the 3D volume of the world.
RaytraceResult Raytrace(const Pose &pose, const meters_t range, const ray_test_func_t func, const void *arg, const bool ztest)
void draw_grid(bounds3d_t vol)
void draw_vector(double x, double y, double z)
usec_t SimTimeNow(void) const
usec_t interval
time between updates in usec
radians_t pan
Horizontal pan angle in radians, in the range -pi to +pi.
std::map< std::string, void * > props
RaytraceResult Raytrace(const Ray &ray)
RaytraceResult(const Pose &pose, Model *mod, const Color &color, const meters_t range)
std::list< Flag * > flag_list
void pose_shift(const Pose &pose)
std::vector< point_int_t > rt_cells
static int UpdateWrapper(Model *mod, void *)
static Option showBumperData
const std::string & GetModelType() const
Visualizer(const std::string &menu_name, const std::string &worldfile_name)
void SetProperty(std::string &key, void *value)
void SetCommand(cmd_t cmd)
std::vector< Waypoint > waypoints
static std::vector< LogEntry > log
radians_t angle
width of viewing angle of sensor
void addPitch(double pitch)
std::map< std::string, Model * > models_by_name
static Option showCameraData
double farClip(void) const
virtual void SetToken(const std::string &str)
double close_limit
How far the gripper can close. If < 1.0, the gripper has its mouth full.
int polys_from_image_file(const std::string &filename, std::vector< std::vector< point_t > > &polys)
rotated rectangle
LocalizationMode localization_mode
global or local mode
Velocity & Load(Worldfile *wf, int section, const char *keyword)
Worldfile * wf
If set, points to the worldfile used to create this world.
virtual bool IsGUI() const
void draw_string(float x, float y, float z, const char *string)
bool stall
Set to true iff the model collided with something else.
bool operator<(const cb_t &other) const
static Model * LookupId(uint32_t id)
std::vector< Option * > drawOptions
Bounds x
volume extent along x axis, intially zero
bool confirm_on_quit
if true, show save dialog on (GUI) exit (default)
Bounds range
min and max range of sensor
double ProportionRemaining() const
Pose(meters_t x, meters_t y, meters_t z, radians_t a)
bool paused
if true, the simulation is stopped
std::vector< std::set< cb_t > > callbacks
std::vector< std::priority_queue< Event > > event_queues
bounds3d_t(const Bounds &x, const Bounds &y, const Bounds &z)
virtual void SetToken(const std::string &str)
bool operator!=(const Pose &other) const
point_int_t MetersToPixels(const point_t &pt) const
bool operator==(const point_t &other) const
bool show_clock
iff true, print the sim time on stdout
bool paddles_stalled
true iff some solid object stopped the paddles closing or opening
Bounds z
volume extent along z axis, initially zero
double realDistance(double z_buf_val) const
usec_t real_time_recorded
std::set< Model * > active_energy
void setScale(double scale)
double GetPosition() const
static std::map< std::string, creator_t > name_map
static joules_t global_peak_value
static Option showTransducers
void ShowClock(bool enable)
Control printing time to stdout.
int getHeight(void) const
height of captured image
const std::set< Model * > GetAllModels() const
bool operator<(const point_t &other) const
std::set< Option * > option_table
GUI options (toggles) registered by models.
static std::map< id_t, Model * > modelsbyid
Pose geom
size and relative angle of the target
World * world
Pointer to the world in which this model exists.
bool rebuild_displaylist
iff true, regenerate block display list before redraw
void setPitch(double pitch)
bool quit
quit this world ASAP
std::list< float * > ray_list
List of rays traced for debug visualization.
bool operator!=(const Color &other) const
bool operator<(const point_int_t &other) const
std::string say_string
if non-empty, this string is displayed in the GUI
std::vector< std::queue< Model * > > pending_update_callbacks
usec_t real_time_interval
void draw_speech_bubble(float x, float y, float z, const char *str)
virtual bool IsGUI() const
Velocity integration_error
errors to apply in simple odometry model
std::set< Model * > models
std::list< PowerPack * > pps_charging
Block & GetBlockMutable(unsigned int index)
std::vector< Model * > children
double constrain(double val, double minval, double maxval)
return val, or minval if val < minval, or maxval if val > maxval
static const Color yellow
radians_t a
rotation about the z axis.
static Option showStrikes
std::map< std::string, unsigned int > child_type_counts
meters_t min_range
minimum detection range
bool(* ray_test_func_t)(Model *candidate, const Model *finder, const void *arg)
void DisableEnergy(Model *m)
int GetFiducialReturn() const
void setAspect(double aspect)
update vertical fov based on window aspect and current horizontal fov
std::vector< meters_t > ranges
virtual void Print(const char *prefix) const
int(* world_callback_t)(World *world, void *user)
void setPitch(double pitch)
std::vector< double > intensities
void AddModelName(Model *mod, const std::string &name)
void setPitch(double pitch)
change the pitch
double paddle_position
0.0 = full open, 1.0 full closed
bool log_state
iff true, model state is logged
Velocity GetOdomError() const
usec_t GetUpdateInterval() const
static std::string ctrlargs
virtual void Redraw(void)
static joules_t global_dissipated
void setYaw(double yaw)
change the yaw
ColoredVertex * _vertexbuf_cache
bool operator+=(const point_t &other)
std::vector< Option * > drawOptions
point_t * unit_square_points_create()
Size(meters_t x, meters_t y, meters_t z)
std::vector< Model * > models_with_fiducials
Ray(const Model *mod, const Pose &origin, const meters_t range, const ray_test_func_t func, const void *arg, const bool ztest)
Fiducial * GetFiducials(unsigned int *count)
double nearClip(void) const
void draw_array(float x, float y, float w, float h, float *data, size_t len, size_t offset)
BlockGroup * group
The BlockGroup to which this Block belongs.
std::string caption_prefix
prefix of window caption (default PROJECT name constant)
void * GetProperty(std::string &key)
double vertFov(void) const
const char * Token() const
const std::vector< Blob > & GetBlobs() const
Velocity(double x, double y, double z, double a)
unsigned int scan_width
Width of the input image in pixels.
usec_t last_update
time of last update in us