Revision: 7562
http://playerstage.svn.sourceforge.net/playerstage/?rev=7562&view=rev
Author: rtv
Date: 2009-03-31 02:47:55 +0000 (Tue, 31 Mar 2009)
Log Message:
-----------
added callbacks for flag push and pop, and vis improvements
Modified Paths:
--------------
code/stage/trunk/examples/ctrl/fasr.cc
code/stage/trunk/examples/ctrl/sink.cc
code/stage/trunk/examples/ctrl/source.cc
code/stage/trunk/libstage/canvas.cc
code/stage/trunk/libstage/model.cc
code/stage/trunk/libstage/model_callbacks.cc
code/stage/trunk/libstage/model_getset.cc
code/stage/trunk/libstage/powerpack.cc
code/stage/trunk/libstage/stage.hh
code/stage/trunk/libstage/world.cc
code/stage/trunk/libstage/worldgui.cc
code/stage/trunk/worlds/fasr.world
code/stage/trunk/worlds/simple.world
Added Paths:
-----------
code/stage/trunk/worlds/bitmaps/SFU_1920x1280.png
code/stage/trunk/worlds/bitmaps/SFU_640x480.png
code/stage/trunk/worlds/bitmaps/SFU_800x600.png
code/stage/trunk/worlds/large.world
Modified: code/stage/trunk/examples/ctrl/fasr.cc
===================================================================
--- code/stage/trunk/examples/ctrl/fasr.cc 2009-03-30 21:43:22 UTC (rev
7561)
+++ code/stage/trunk/examples/ctrl/fasr.cc 2009-03-31 02:47:55 UTC (rev
7562)
@@ -14,7 +14,7 @@
const int payload = 1;
double have[4][4] = {
- // { -120, -180, 180, 180 },
+ // { -120, -180, 180, 180 }
//{ -90, -120, 180, 90 },
{ 90, 180, 180, 180 },
{ 90, -90, 180, 90 },
@@ -94,6 +94,7 @@
pos->AddUpdateCallback( (stg_model_callback_t)PositionUpdate, this );
pos->Subscribe();
+
// LaserUpdate() controls the robot, by reading from laser and
// writing to position
laser->AddUpdateCallback( (stg_model_callback_t)LaserUpdate, this );
@@ -110,6 +111,9 @@
blobfinder->AddUpdateCallback(
(stg_model_callback_t)BlobFinderUpdate, this );
blobfinder->Subscribe();
}
+
+ //pos->AddFlagIncrCallback( (stg_model_callback_t)FlagIncr, NULL );
+ //pos->AddFlagDecrCallback( (stg_model_callback_t)FlagDecr, NULL );
}
void Dock()
@@ -480,18 +484,28 @@
return 0;
}
+
+ static int FlagIncr( Model* mod, Robot* robot )
+ {
+ printf( "model %s collected flag\n", mod->Token() );
+ return 0;
+ }
-
+ static int FlagDecr( Model* mod, Robot* robot )
+ {
+ printf( "model %s dropped flag\n", mod->Token() );
+ return 0;
+ }
};
// Stage calls this when the model starts up
extern "C" int Init( Model* mod )
{
- Robot* robot = new Robot( (ModelPosition*)mod,
-
mod->GetWorld()->GetModel( "source" ),
-
mod->GetWorld()->GetModel( "sink" ) );
-
+ new Robot( (ModelPosition*)mod,
+ mod->GetWorld()->GetModel( "source" ),
+ mod->GetWorld()->GetModel( "sink" ) );
+
return 0; //ok
}
Modified: code/stage/trunk/examples/ctrl/sink.cc
===================================================================
--- code/stage/trunk/examples/ctrl/sink.cc 2009-03-30 21:43:22 UTC (rev
7561)
+++ code/stage/trunk/examples/ctrl/sink.cc 2009-03-31 02:47:55 UTC (rev
7562)
@@ -8,11 +8,7 @@
// Stage calls this when the model starts up
extern "C" int Init( Model* mod )
{
- //for( int i=0; i<5; i++ )
- // mod->PushFlag( new Flag( stg_color_pack( 1,1,0,0), 0.5 ) );
-
mod->AddUpdateCallback( (stg_model_callback_t)Update, NULL );
-
return 0; //ok
}
Modified: code/stage/trunk/examples/ctrl/source.cc
===================================================================
--- code/stage/trunk/examples/ctrl/source.cc 2009-03-30 21:43:22 UTC (rev
7561)
+++ code/stage/trunk/examples/ctrl/source.cc 2009-03-31 02:47:55 UTC (rev
7562)
@@ -2,19 +2,15 @@
using namespace Stg;
const int INTERVAL = 200;
+const double FLAGSZ = 0.4;
int Update( Model* mod, void* dummy );
-const double flagsz = 0.4;
// Stage calls this when the model starts up
extern "C" int Init( Model* mod )
{
- for( int i=0; i<5; i++ )
- mod->PushFlag( new Flag( stg_color_pack( 1,1,0,0 ), flagsz ) );
-
- mod->AddUpdateCallback( (stg_model_callback_t)Update, NULL );
-
+ mod->AddUpdateCallback( (stg_model_callback_t)Update, NULL );
return 0; //ok
}
@@ -22,7 +18,7 @@
int Update( Model* mod, void* dummy )
{
if( mod->GetWorld()->GetUpdateCount() % INTERVAL == 0 )
- mod->PushFlag( new Flag( stg_color_pack( 1,1,0,0), flagsz ) );
+ mod->PushFlag( new Flag( stg_color_pack( 1,1,0,0), FLAGSZ ) );
return 0; // run again
}
Modified: code/stage/trunk/libstage/canvas.cc
===================================================================
--- code/stage/trunk/libstage/canvas.cc 2009-03-30 21:43:22 UTC (rev 7561)
+++ code/stage/trunk/libstage/canvas.cc 2009-03-31 02:47:55 UTC (rev 7562)
@@ -125,7 +125,8 @@
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
// install a font
- gl_font( FL_HELVETICA, 12 );
+ //gl_font( FL_HELVETICA, 12 );
+ gl_font( FL_COURIER, 12 );
blur = false;
@@ -955,8 +956,6 @@
glLoadIdentity();
glDisable( GL_DEPTH_TEST );
- // if trails are on, we need to clear the clock background
-
std::string clockstr = world->ClockString();
if( showFollow == true && last_selection )
clockstr.append( " [ FOLLOW MODE ]" );
@@ -975,18 +974,22 @@
glRectf( 0, 0, width, height );
colorstack.Push( 0,0,0 ); // black
Gl::draw_string( margin, margin, 0, clockstr.c_str() );
-
- // ENERGY BOX
- colorstack.Push( 0.8,1.0,0.8,0.85 ); // pale green
- glRectf( 0, height, width, 90 );
- colorstack.Push( 0,0,0 ); // black
- Gl::draw_string_multiline( margin, height + margin, txtWidth,
50, world->EnergyString().c_str(), (Fl_Align)( FL_ALIGN_LEFT | FL_ALIGN_BOTTOM)
);
-
- colorstack.Pop();
colorstack.Pop();
- colorstack.Pop();
colorstack.Pop();
-
+
+ // ENERGY BOX
+ if( PowerPack::global_capacity > 0 )
+ {
+ colorstack.Push( 0.8,1.0,0.8,0.85 ); // pale green
+ glRectf( 0, height, width, 90 );
+ colorstack.Push( 0,0,0 ); // black
+ Gl::draw_string_multiline( margin, height + margin,
txtWidth, 50,
+
world->EnergyString().c_str(),
+
(Fl_Align)( FL_ALIGN_LEFT | FL_ALIGN_BOTTOM) );
+ colorstack.Pop();
+ colorstack.Pop();
+ }
+
glEnable( GL_DEPTH_TEST );
glPopMatrix();
Modified: code/stage/trunk/libstage/model.cc
===================================================================
--- code/stage/trunk/libstage/model.cc 2009-03-30 21:43:22 UTC (rev 7561)
+++ code/stage/trunk/libstage/model.cc 2009-03-31 02:47:55 UTC (rev 7562)
@@ -197,7 +197,7 @@
blockgroup(),
blocks_dl(0),
boundary(false),
- callbacks( g_hash_table_new( g_int_hash, g_int_equal ) ),
+ callbacks( g_hash_table_new( g_direct_hash, g_direct_equal ) ),
color( 0xFFFF0000 ), // red
data_fresh(false),
disabled(false),
@@ -327,19 +327,28 @@
void Model::AddFlag( Flag* flag )
{
if( flag )
- flag_list = g_list_append( this->flag_list, flag );
+ {
+ flag_list = g_list_append( this->flag_list, flag );
+ CallCallbacks( &hooks.flag_incr );
+ }
}
void Model::RemoveFlag( Flag* flag )
{
if( flag )
- flag_list = g_list_remove( this->flag_list, flag );
+ {
+ flag_list = g_list_remove( this->flag_list, flag );
+ CallCallbacks( &hooks.flag_decr );
+ }
}
void Model::PushFlag( Flag* flag )
{
if( flag )
- flag_list = g_list_prepend( flag_list, flag);
+ {
+ flag_list = g_list_prepend( flag_list, flag);
+ CallCallbacks( &hooks.flag_incr );
+ }
}
Flag* Model::PopFlag()
@@ -347,9 +356,13 @@
if( flag_list == NULL )
return NULL;
+ printf( "pop flag" );
+
Flag* flag = (Flag*)flag_list->data;
flag_list = g_list_remove( flag_list, flag );
+ CallCallbacks( &hooks.flag_decr );
+
return flag;
}
Modified: code/stage/trunk/libstage/model_callbacks.cc
===================================================================
--- code/stage/trunk/libstage/model_callbacks.cc 2009-03-30 21:43:22 UTC
(rev 7561)
+++ code/stage/trunk/libstage/model_callbacks.cc 2009-03-31 02:47:55 UTC
(rev 7562)
@@ -1,19 +1,19 @@
#include "stage.hh"
using namespace Stg;
-int key_gen( Model* mod, void* address )
-{
- return ((int*)address) - ((int*)mod);
-}
+// int key_gen( Model* mod, void* address )
+// {
+// return ((int*)address) - ((int*)mod);
+// }
void Model::AddCallback( void* address,
stg_model_callback_t cb,
void* user )
{
- int* key = (int*)g_new( int, 1 );
- *key = key_gen( this, address );
+ ///int* key = (int*)g_new( int, 1 );
+ //*key = key_gen( this, address );
- GList* cb_list = (GList*)g_hash_table_lookup( callbacks, key );
+ GList* cb_list = (GList*)g_hash_table_lookup( callbacks, address );
//printf( "installing callback in model %s with key %d\n",
// mod->token, *key );
@@ -22,16 +22,16 @@
cb_list = g_list_prepend( cb_list, cb_create( cb, user ) );
// and replace the list in the hash table
- g_hash_table_insert( callbacks, key, cb_list );
+ g_hash_table_insert( callbacks, address, cb_list );
}
int Model::RemoveCallback( void* member,
stg_model_callback_t callback )
{
- int key = key_gen( this, member );
+ //int key = key_gen( this, member );
- GList* cb_list = (GList*)g_hash_table_lookup( callbacks, &key );
+ GList* cb_list = (GList*)g_hash_table_lookup( callbacks, member );
// find our callback in the list of stg_cbarg_t
GList* el = NULL;
@@ -52,7 +52,7 @@
cb_list = g_list_remove( cb_list, el->data);
// store the new, shorter, list of callbacks
- g_hash_table_insert( callbacks, &key, cb_list );
+ g_hash_table_insert( callbacks, member, cb_list );
// we're done with that
//free( el->data );
@@ -76,28 +76,32 @@
void Model::CallCallbacks( void* address )
{
+
assert( address );
- int key = key_gen( this, address );
+ //int key = key_gen( this, address );
+
+ //printf( "CallCallbacks for model %s %p key %p\n", this->Token(),
this, address );
//printf( "Model %s has %d callbacks. Checking key %d\n",
- // mod->token, g_hash_table_size( mod->callbacks ), key );
+ // this->token, g_hash_table_size( this->callbacks ), key );
- GList* cbs = (GList*)g_hash_table_lookup( callbacks, &key );
+ GList* cbs = (GList*)g_hash_table_lookup( callbacks, address );
//printf( "key %d has %d callbacks registered\n",
- // key, g_list_length( cbs ) );
-
+ // key, g_list_length( cbs ) );
+
// maintain a list of callbacks that should be cancelled
GList* doomed = NULL;
// for each callback in the list
while( cbs )
{
+ //printf( "cbs %p data %p cvs->next %p\n", cbs, cbs->data, cbs->next
);
+
stg_cb_t* cba = (stg_cb_t*)cbs->data;
+ assert( cba );
- //puts( "calling..." );
-
if( (cba->callback)( this, cba->arg ) )
{
//printf( "callback returned TRUE - schedule removal
from list\n" );
@@ -121,6 +125,7 @@
g_list_free( doomed );
}
+ //puts( "Callbacks done" );
}
Modified: code/stage/trunk/libstage/model_getset.cc
===================================================================
--- code/stage/trunk/libstage/model_getset.cc 2009-03-30 21:43:22 UTC (rev
7561)
+++ code/stage/trunk/libstage/model_getset.cc 2009-03-31 02:47:55 UTC (rev
7562)
@@ -212,7 +212,7 @@
on_velocity_list = true;
}
- CallCallbacks( &this->velocity );
+ //CallCallbacks( &this->velocity );
}
Modified: code/stage/trunk/libstage/powerpack.cc
===================================================================
--- code/stage/trunk/libstage/powerpack.cc 2009-03-30 21:43:22 UTC (rev
7561)
+++ code/stage/trunk/libstage/powerpack.cc 2009-03-31 02:47:55 UTC (rev
7562)
@@ -263,7 +263,7 @@
Gl::pose_inverse_shift( mod->GetPose() );
- glTranslatef( -width/2.0, -height/2.0, 0 );
+ glTranslatef( -width/2.0, -height/2.0, 0.01 );
glScalef( cellsize, cellsize, 1 );
for( unsigned int y=0; y<rows; y++ )
Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh 2009-03-30 21:43:22 UTC (rev 7561)
+++ code/stage/trunk/libstage/stage.hh 2009-03-31 02:47:55 UTC (rev 7562)
@@ -1432,8 +1432,8 @@
/** energy data packet */
class PowerPack
{
- //friend class World;
friend class WorldGui;
+ friend class Canvas;
protected:
@@ -1554,11 +1554,13 @@
class CallbackHooks
{
public:
- char load;
- char save;
- char shutdown;
- char startup;
- char update;
+ int flag_incr;
+ int flag_decr;
+ int load;
+ int save;
+ int shutdown;
+ int startup;
+ int update;
};
/** Records model state and functionality in the GUI, if used */
@@ -2105,7 +2107,19 @@
void RemoveUpdateCallback( stg_model_callback_t cb )
{ RemoveCallback( &hooks.update, cb ); }
+
+ void AddFlagIncrCallback( stg_model_callback_t cb, void* user )
+ { AddCallback( &hooks.flag_incr, cb, user ); }
+ void RemoveFlagIncrCallback( stg_model_callback_t cb )
+ { RemoveCallback( &hooks.flag_incr, cb ); }
+
+ void AddFlagDecrCallback( stg_model_callback_t cb, void* user )
+ { AddCallback( &hooks.flag_decr, cb, user ); }
+
+ void RemoveFlagDecrCallback( stg_model_callback_t cb )
+ { RemoveCallback( &hooks.flag_decr, cb ); }
+
/** named-property interface
*/
void* GetProperty( const char* key ) const;
Modified: code/stage/trunk/libstage/world.cc
===================================================================
--- code/stage/trunk/libstage/world.cc 2009-03-30 21:43:22 UTC (rev 7561)
+++ code/stage/trunk/libstage/world.cc 2009-03-31 02:47:55 UTC (rev 7562)
@@ -675,18 +675,6 @@
else if( dy > 0 )
n++;
- if( abs(sup.x) > 20 )
- printf( "raytracing at [ %.2f %.2f %.2f %.2f ] GLOB( %d %d ) SUP( %d %d
)\n",
- gpose.x,
- gpose.y,
- gpose.z,
- gpose.a,
- glob.x,
- glob.y,
- sup.x,
- sup.y );
-
-
// find the starting superregion
sr = GetSuperRegionCached( sup ); // possibly NULL, but unlikely
Modified: code/stage/trunk/libstage/worldgui.cc
===================================================================
--- code/stage/trunk/libstage/worldgui.cc 2009-03-30 21:43:22 UTC (rev
7561)
+++ code/stage/trunk/libstage/worldgui.cc 2009-03-31 02:47:55 UTC (rev
7562)
@@ -416,7 +416,7 @@
str += buf;
}
- snprintf( buf, 255, "%um%02us%03umsec [%.2f]", minutes, seconds, msec,
localratio );
+ snprintf( buf, 255, " %um %02us %03umsec [%.2f]", minutes, seconds, msec,
localratio );
str += buf;
if( paused == true )
Added: code/stage/trunk/worlds/bitmaps/SFU_1920x1280.png
===================================================================
(Binary files differ)
Property changes on: code/stage/trunk/worlds/bitmaps/SFU_1920x1280.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: code/stage/trunk/worlds/bitmaps/SFU_640x480.png
===================================================================
(Binary files differ)
Property changes on: code/stage/trunk/worlds/bitmaps/SFU_640x480.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: code/stage/trunk/worlds/bitmaps/SFU_800x600.png
===================================================================
(Binary files differ)
Property changes on: code/stage/trunk/worlds/bitmaps/SFU_800x600.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Modified: code/stage/trunk/worlds/fasr.world
===================================================================
--- code/stage/trunk/worlds/fasr.world 2009-03-30 21:43:22 UTC (rev 7561)
+++ code/stage/trunk/worlds/fasr.world 2009-03-31 02:47:55 UTC (rev 7562)
@@ -8,13 +8,13 @@
interval_sim 100 # simulation timestep in milliseconds
interval_real 0 # real-time interval between simulation updates in
milliseconds
-paused 0
+paused 1
resolution 0.02
# threads may speed things up here depending on available CPU cores & workload
- threadpool 8
-# threadpool 0
+# threadpool 8
+ threadpool 0
# configure the GUI window
@@ -22,9 +22,9 @@
(
size [ 788.000 842.000 ]
- center [ 0.240 -0.382 ]
+ center [ 0.121 -0.854 ]
rotate [ 0 0 ]
- scale 35.648
+ scale 42.424
pcam_loc [ 0 -4.000 2.000 ]
pcam_angle [ 70.000 0 ]
@@ -153,23 +153,23 @@
#puck( pose [ 1.067 3.367 0 0 ] )
#puck( pose [ 1.412 3.604 0 0 ] )
-autorob( pose [5.418 7.478 0 -163.478] joules 300000 )
-autorob( pose [7.574 6.269 0 -111.715] joules 100000 )
+autorob( pose [5.488 5.149 0 35.947] joules 300000 )
+autorob( pose [6.431 5.593 0 -111.715] joules 100000 )
autorob( pose [5.615 6.185 0 107.666] joules 200000 )
autorob( pose [7.028 6.502 0 -128.279] joules 400000 )
autorob( pose [5.750 4.137 0 -97.047] joules 100000 )
autorob( pose [4.909 6.097 0 -44.366] joules 200000 )
autorob( pose [6.898 4.775 0 -117.576] joules 300000 )
autorob( pose [7.394 5.595 0 129.497] joules 400000 )
-autorob( pose [6.468 6.708 0 170.743] joules 100000 )
+autorob( pose [5.422 7.030 0 170.743] joules 100000 )
autorob( pose [6.451 4.189 0 -61.453] joules 200000 )
-autorob( pose [5.060 6.868 0 -61.295] joules 300000 )
-autorob( pose [4.161 5.544 0 -147.713] joules 400000 )
-autorob( pose [4.911 4.552 0 -125.236] joules 100000 )
-autorob( pose [3.985 6.474 0 -158.025] joules 200000 )
-autorob( pose [5.440 5.317 0 -26.545] joules 300000 )
-autorob( pose [6.362 5.632 0 163.239] joules 400000 db_count 3 db [
"foo<int>42" "bar<float>6.75" "bash<string>my old shoe" ] )
+#autorob( pose [5.060 6.868 0 -61.295] joules 300000 )
+#autorob( pose [4.161 5.544 0 -147.713] joules 400000 )
+#autorob( pose [4.911 4.552 0 -125.236] joules 100000 )
+#autorob( pose [3.985 6.474 0 -158.025] joules 200000 )
+#autorob( pose [5.440 5.317 0 -26.545] joules 300000 )
+#autorob( pose [6.362 5.632 0 163.239] joules 400000 )
#autorob( pose [7.559 4.764 0 -139.066] )
#autorob( pose [5.471 7.446 0 77.301] )
Added: code/stage/trunk/worlds/large.world
===================================================================
--- code/stage/trunk/worlds/large.world (rev 0)
+++ code/stage/trunk/worlds/large.world 2009-03-31 02:47:55 UTC (rev 7562)
@@ -0,0 +1,60 @@
+# simple.world - basic world file example
+# Authors: Richard Vaughan
+# $Id$
+
+include "pioneer.inc"
+include "map.inc"
+include "sick.inc"
+
+interval_sim 100 # simulation timestep in milliseconds
+interval_real 0 # real-time interval between simulation updates in
milliseconds
+
+paused 1
+
+resolution 0.02
+
+# configure the GUI window
+window
+(
+ size [ 556.000 557.000 ] # in pixels
+ scale 28.116
+ # pixels per meter
+ center [ 8.058 7.757 ]
+ rotate [ 0 0 ]
+
+ show_data 1 # 1=on 0=off
+ show_grid 0
+)
+
+# load an environment bitmap
+floorplan
+(
+ name "cave"
+ size [1000.000 700.000 0.600]
+ pose [0 0 0 0]
+ bitmap "bitmaps/SFU_800x600.png"
+)
+
+
+define wanderer pioneer2dx
+(
+ sicklaser( size [0.3 0.3 0.2 ] samples 32 )
+ ctrl "wander"
+
+ # report error-free position in world coordinates
+ localization "gps"
+ localization_origin [ 0 0 0 0 ]
+)
+
+wanderer( pose [ 0 0 0 0 ] )
+wanderer( pose [ 1 0 0 0 ] )
+wanderer( pose [ 2 0 0 0 ] )
+wanderer( pose [ 3 0 0 0 ] )
+wanderer( pose [ 4 0 0 0 ] )
+wanderer( pose [ 5 0 0 0 ] )
+wanderer( pose [ 6 0 0 0 ] )
+wanderer( pose [ 7 0 0 0 ] )
+wanderer( pose [ 8 0 0 0 ] )
+wanderer( pose [ 9 0 0 0 ] )
+
+
Modified: code/stage/trunk/worlds/simple.world
===================================================================
--- code/stage/trunk/worlds/simple.world 2009-03-30 21:43:22 UTC (rev
7561)
+++ code/stage/trunk/worlds/simple.world 2009-03-31 02:47:55 UTC (rev
7562)
@@ -29,9 +29,9 @@
floorplan
(
name "cave"
- size [16.000 16.000 0.800]
- pose [8 8 0 0]
- bitmap "bitmaps/cave.png"
+ size [160.000 160.000 0.800]
+ pose [0 0 0 0]
+ bitmap "bitmaps/SFU_800x600.png"
)
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit