Permalink
Browse files

added a shell of a wifi model

  • Loading branch information...
1 parent 96f5a7d commit b3184e2aa94a591fe0727c29f02f2a012074a269 gerkey committed Mar 2, 2006
Showing with 375 additions and 3 deletions.
  1. +3 −1 src/Makefile.am
  2. +176 −0 src/model_wifi.cc
  3. +5 −1 src/p_driver.cc
  4. +11 −0 src/p_driver.h
  5. +68 −0 src/p_wifi.cc
  6. +19 −1 src/stage.h
  7. +2 −0 src/typetable.c
  8. +37 −0 worlds/wifi.cfg
  9. +54 −0 worlds/wifi.world
View
4 src/Makefile.am
@@ -2,7 +2,7 @@
# Automake script to build Stage's Makefile
#
# RTV 20021026
-# $Id: Makefile.am,v 1.135 2006-02-27 21:35:14 rtv Exp $
+# $Id: Makefile.am,v 1.136 2006-03-02 23:19:00 gerkey Exp $
# also build Zoo referees
SUBDIRS = referees
@@ -44,6 +44,7 @@ libstage_la_SOURCES = \
model_ranger.c \
model_gripper.c \
model_ptz.c \
+ model_wifi.cc \
raytrace.c \
stage.c \
stage.h \
@@ -74,6 +75,7 @@ libstageplugin_la_SOURCES = \
p_driver.h \
p_laser.cc \
p_ptz.cc \
+ p_wifi.cc \
p_sonar.cc \
p_graphics2d.cc \
p_gripper.cc \
View
176 src/model_wifi.cc
@@ -0,0 +1,176 @@
+///////////////////////////////////////////////////////////////////////////
+//
+// File: model_wifi.cc
+// Authors: Benoit Morisset
+// Date: 2 March 2006
+//
+// CVS info:
+// $Source: /home/tcollett/stagecvs/playerstage-cvs/code/stage/src/model_wifi.cc,v $
+// $Author: gerkey $
+// $Revision: 1.1 $
+//
+///////////////////////////////////////////////////////////////////////////
+
+/**
+@ingroup model
+@defgroup model_wifi Wifi model
+
+@todo Fill this in
+
+<h2>Worldfile properties</h2>
+
+@todo Fill this in
+
+*/
+
+
+#include <sys/time.h>
+#include <math.h>
+#include "gui.h"
+
+// Number pulled directly from my ass
+#define STG_WIFI_WATTS 2.5
+
+//#define DEBUG
+
+#include "stage_internal.h"
+
+// standard callbacks
+extern "C" {
+
+int wifi_update( stg_model_t* mod );
+int wifi_startup( stg_model_t* mod );
+int wifi_shutdown( stg_model_t* mod );
+void wifi_load( stg_model_t* mod );
+
+int wifi_render_data( stg_model_t* mod, void* userp );
+int wifi_unrender_data( stg_model_t* mod, void* userp );
+
+void
+wifi_load( stg_model_t* mod )
+{
+ stg_wifi_config_t cfg;
+
+ // TODO: read wifi params from the world file
+
+ stg_model_set_cfg( mod, &cfg, sizeof(cfg));
+}
+
+int
+wifi_init( stg_model_t* mod )
+{
+ // we don't consume any power until subscribed
+ mod->watts = 0.0;
+
+ // override the default methods; these will be called by the simualtion
+ // engine
+ mod->f_startup = wifi_startup;
+ mod->f_shutdown = wifi_shutdown;
+ mod->f_update = wifi_update;
+ mod->f_load = wifi_load;
+
+ // sensible wifi defaults; it doesn't take up any physical space
+ stg_geom_t geom;
+ geom.pose.x = 0.0;
+ geom.pose.y = 0.0;
+ geom.pose.a = 0.0;
+ geom.size.x = 0.0;
+ geom.size.y = 0.0;
+ stg_model_set_geom( mod, &geom );
+
+ // wifi is invisible
+ stg_model_set_obstacle_return( mod, 0 );
+ stg_model_set_laser_return( mod, LaserTransparent );
+ stg_model_set_blob_return( mod, 0 );
+ stg_model_set_color( mod, (stg_color_t)0 );
+
+ // adds a menu item and associated on-and-off callbacks
+ stg_model_add_property_toggles( mod, &mod->data,
+ wifi_render_data, NULL,
+ wifi_unrender_data, NULL,
+ "wifi_data",
+ "wifi data",
+ TRUE );
+ return 0;
+}
+
+int
+wifi_update( stg_model_t* mod )
+{
+ // no work to do if we're unsubscribed
+ if( mod->subs < 1 )
+ return 0;
+
+ puts("wifi_update");
+
+ // Retrieve current configuration
+ stg_wifi_config_t cfg;
+ memcpy(&cfg, mod->cfg, sizeof(cfg));
+
+ // Retrieve current geometry
+ stg_geom_t geom;
+ stg_model_get_geom( mod, &geom );
+
+ // get the sensor's pose in global coords
+ stg_pose_t pz;
+ memcpy( &pz, &geom.pose, sizeof(pz) );
+ stg_model_local_to_global( mod, &pz );
+
+
+ // We'll store current data here
+ stg_wifi_data_t data;
+
+ // DO RADIO PROPAGATION HERE, and fill in the data structure
+
+ // publish the new stuff
+ stg_model_set_data( mod, &data, sizeof(data));
+
+ // inherit standard update behaviour
+ _model_update( mod );
+
+ return 0; //ok
+}
+
+int
+wifi_render_data( stg_model_t* mod, void* userp )
+{
+ //puts( "wifi render data" );
+
+ // only draw if someone is using the gripper
+ if( mod->subs < 1 )
+ return 0;
+
+ // DRAW WIFI DATA HERE. Look at other models for examples.
+
+ return 0;
+}
+
+int
+wifi_startup( stg_model_t* mod )
+{
+ PRINT_DEBUG( "wifi startup" );
+ stg_model_set_watts( mod, STG_WIFI_WATTS );
+ return 0; // ok
+}
+
+int
+wifi_shutdown( stg_model_t* mod )
+{
+ PRINT_DEBUG( "wifi shutdown" );
+ stg_model_set_watts( mod, 0 );
+
+ // unrender the data
+ //stg_model_fig_clear( mod, "wifi_data_fig" );
+ return 0; // ok
+}
+
+int
+wifi_unrender_data( stg_model_t* mod, void* userp )
+{
+ // CLEAR STUFF THAT YOU DREW
+ //stg_model_fig_clear( mod, "wifi_data_fig" );
+ return 1; // callback just runs one time
+}
+
+}
+
View
6 src/p_driver.cc
@@ -22,7 +22,7 @@
* Desc: A plugin driver for Player that gives access to Stage devices.
* Author: Richard Vaughan
* Date: 10 December 2004
- * CVS: $Id: p_driver.cc,v 1.31 2006-02-27 03:20:13 rtv Exp $
+ * CVS: $Id: p_driver.cc,v 1.32 2006-03-02 23:19:03 gerkey Exp $
*/
// DOCUMENTATION ------------------------------------------------------------
@@ -388,6 +388,10 @@ StgDriver::StgDriver(ConfigFile* cf, int section)
ifsrc = new InterfaceGripper( player_addr, this, cf, section );
break;
+ case PLAYER_WIFI_CODE:
+ ifsrc = new InterfaceWifi( player_addr, this, cf, section );
+ break;
+
default:
PRINT_ERR1( "error: stage driver doesn't support interface type %d\n",
player_addr.interf );
View
11 src/p_driver.h
@@ -122,6 +122,17 @@ class InterfaceGripper : public InterfaceModel
virtual void Publish( void );
};
+class InterfaceWifi : public InterfaceModel
+{
+ public:
+ InterfaceWifi( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section );
+ virtual ~InterfaceWifi( void ){ /* TODO: clean up*/ };
+ virtual int ProcessMessage(MessageQueue* resp_queue,
+ player_msghdr_t* hdr,
+ void* data);
+ virtual void Publish( void );
+};
+
class InterfaceLaser : public InterfaceModel
{
private:
View
68 src/p_wifi.cc
@@ -0,0 +1,68 @@
+/*
+ * Player - One Hell of a Robot Server
+ * Copyright (C) 2004, 2005 Richard Vaughan
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+/*
+ * Desc: A plugin driver for Player that gives access to Stage devices.
+ * Author: Richard Vaughan
+ * Date: 10 December 2004
+ * CVS: $Id: p_wifi.cc,v 1.1 2006-03-02 23:19:03 gerkey Exp $
+ */
+
+
+#include "p_driver.h"
+
+extern "C" {
+int wifi_init( stg_model_t* mod );
+}
+
+InterfaceWifi::InterfaceWifi( player_devaddr_t addr,
+ StgDriver* driver,
+ ConfigFile* cf,
+ int section )
+
+ : InterfaceModel( addr, driver, cf, section, wifi_init )
+{
+ // nothing to do
+}
+
+void InterfaceWifi::Publish( void )
+{
+ stg_wifi_data_t* sdata = (stg_wifi_data_t*)mod->data;
+ assert(sdata);
+
+ player_wifi_data_t pdata;
+ memset( &pdata, 0, sizeof(pdata) );
+
+ // Translate the Stage-formatted sdata into the Player-formatted pdata
+
+ // Publish it
+ this->driver->Publish(this->addr, NULL,
+ PLAYER_MSGTYPE_DATA,
+ PLAYER_WIFI_DATA_STATE,
+ (void*)&pdata, sizeof(pdata), NULL);
+}
+
+int InterfaceWifi::ProcessMessage(MessageQueue* resp_queue,
+ player_msghdr_t* hdr,
+ void* data)
+{
+ // PROCESS INCOMING REQUESTS HERE
+}
View
20 src/stage.h
@@ -29,7 +29,7 @@
* Andrew Howard ahowards@usc.edu
* Brian Gerkey gerkey@stanford.edu
* Date: 1 June 2003
- * CVS: $Id: stage.h,v 1.182 2006-03-02 07:52:30 rtv Exp $
+ * CVS: $Id: stage.h,v 1.183 2006-03-02 23:19:03 gerkey Exp $
*/
@@ -967,6 +967,24 @@ For help with libstage, please use the mailing list playerstage_users@lists.sour
/// set the current odometry estimate
void stg_model_position_set_odom( stg_model_t* mod, stg_pose_t* odom );
+ // WIFI MODEL --------------------------------------------------------
+
+ /** wifi config packet
+ */
+ typedef struct
+ {
+ // Configuration for the wifi model goes here. E.g., power, range of
+ // propagation.
+ } stg_wifi_config_t;
+
+ /** wifi data packet
+ */
+ typedef struct
+ {
+ // Simulated wifi data goes here. E.g., for each neighbor within
+ // range, record the corresponding signal strength.
+ } stg_wifi_data_t;
+
// end the group of all models
/**@}*/
View
2 src/typetable.c
@@ -11,6 +11,7 @@ int position_init( stg_model_t* mod );
int ranger_init( stg_model_t* mod );
//int energy_init( stg_model_t* mod );
int ptz_init( stg_model_t* mod );
+int wifi_init( stg_model_t* mod );
// map worldfile keywords onto initialization functions
stg_type_record_t typetable[] =
@@ -24,6 +25,7 @@ stg_type_record_t typetable[] =
{ "gripper", gripper_init },
//{ "power", energy_init },
{ "ptz", ptz_init },
+ { "wifi", wifi_init },
{ NULL, 0, NULL } // this must be the last entry
};
View
37 worlds/wifi.cfg
@@ -0,0 +1,37 @@
+
+# Desc: Player sample configuration file for controlling Stage devices
+# Author: Richard Vaughan
+# Date: 1 December 2004
+# CVS: $Id: wifi.cfg,v 1.1 2006-03-02 23:19:09 gerkey Exp $
+
+
+# load the Stage plugin simulation driver
+driver
+(
+ name "stage"
+ provides ["simulation:0" ]
+ plugin "libstageplugin"
+
+ # load the named file into the simulator
+ worldfile "wifi.world"
+)
+
+# Create a Stage driver and attach position2d and wifi interfaces
+# to the model "robot1"
+driver
+(
+ name "stage"
+ provides ["6665:position2d:0" "6665:wifi:0" ]
+ model "robot1"
+ alwayson 1
+)
+
+# Create a Stage driver and attach position2d and wifi interfaces
+# to the model "robot2"
+driver
+(
+ name "stage"
+ provides ["6666:position2d:0" "6666:wifi:0" ]
+ model "robot2"
+ alwayson 1
+)
View
54 worlds/wifi.world
@@ -0,0 +1,54 @@
+
+# Desc: 1 pioneer robot with laser
+# CVS: $Id: wifi.world,v 1.1 2006-03-02 23:19:09 gerkey Exp $
+
+# defines 'map' object used for floorplans
+include "map.inc"
+
+# size of the world in meters
+size [16 16]
+
+# set the resolution of the underlying raytrace model in meters
+resolution 0.02
+
+# update the screen every 10ms (we need fast update for the stest demo)
+gui_interval 20
+
+# configure the GUI window
+window
+(
+ size [ 591.000 638.000 ]
+ center [-0.010 -0.040]
+ scale 0.028
+)
+
+# load an environment bitmap
+map
+(
+ bitmap "bitmaps/cave.png"
+ size [16 16]
+ name "cave"
+)
+
+# define a wifi-equipped robot
+define commbot position
+(
+ size [0.25 0.25]
+ wifi ()
+)
+
+# create a robot
+commbot
+(
+ name "robot1"
+ color "red"
+ pose [-6.5 -6.5 45]
+)
+
+# create another robot
+commbot
+(
+ name "robot2"
+ color "blue"
+ pose [-3.5 -2.5 90]
+)

0 comments on commit b3184e2

Please sign in to comment.