Revision: 7387
http://playerstage.svn.sourceforge.net/playerstage/?rev=7387&view=rev
Author: gerkey
Date: 2009-03-08 05:30:33 +0000 (Sun, 08 Mar 2009)
Log Message:
-----------
got proof of concept working with webgazebo
Modified Paths:
--------------
code/branches/federation/gazebo/webgazebo/SConscript
code/branches/federation/gazebo/webgazebo/WebGazebo.cc
code/branches/federation/gazebo/webgazebo/WebGazebo.hh
code/branches/federation/gazebo/webgazebo/http.cc
code/branches/federation/gazebo/webgazebo/main.cc
Modified: code/branches/federation/gazebo/webgazebo/SConscript
===================================================================
--- code/branches/federation/gazebo/webgazebo/SConscript 2009-03-08
05:05:57 UTC (rev 7386)
+++ code/branches/federation/gazebo/webgazebo/SConscript 2009-03-08
05:30:33 UTC (rev 7387)
@@ -16,7 +16,9 @@
#SHLINKCOMSTR = 'Linking $TARGET',
#LINKCOMSTR = 'Linking $TARGET',
- LIBS=Split('event'),
+ LIBS=Split('event gazebo'),
+ LIBPATH=Split('#libgazebo'),
+ CPPPATH=Split('#.')
)
sources = Split('WebGazebo.cc')
@@ -40,9 +42,13 @@
#SHLINKCOMSTR = 'Linking $TARGET',
#LINKCOMSTR = 'Linking $TARGET',
- LIBS=Split('webgazebo event'),
- LIBPATH=Split(os.getcwd()),
+ LIBS=Split('webgazebo event gazebo'),
+ LIBPATH=Split('#libgazebo ' + os.getcwd()),
CPPPATH=Split('#.')
)
webgazebo = exeEnv.Program('webgazebo', 'main.cc')
+
+env.Install(install_prefix+'/lib', sharedLib)
+env.Install(install_prefix+'/lib', staticLib)
+env.Install(install_prefix+'/bin', webgazebo)
Modified: code/branches/federation/gazebo/webgazebo/WebGazebo.cc
===================================================================
--- code/branches/federation/gazebo/webgazebo/WebGazebo.cc 2009-03-08
05:05:57 UTC (rev 7386)
+++ code/branches/federation/gazebo/webgazebo/WebGazebo.cc 2009-03-08
05:30:33 UTC (rev 7387)
@@ -3,32 +3,91 @@
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
+#include <time.h>
WebGazebo::WebGazebo(std::string _host, int _port) :
host(_host), port(_port)
{
+ // Set up the HTTP server
// Not sure whether it's safe to do this more that once in one process
event_init();
+ printf("[webgazebo] Starting HTTP server listening on %s:%d...",
+ this->host.c_str(), this->port);
+ fflush(stdout);
this->eh = evhttp_start(this->host.c_str(), this->port);
assert(eh);
+ evhttp_set_gencb(eh, &WebGazebo::EventCallback, (void*)this);
+ puts("Done.");
+
+ // Hook up to Gazebo
+ printf("[webgazebo] Opening Gazebo simulation interface...");
+ fflush(stdout);
+ this->client = new gazebo::Client();
+ this->simIface = new gazebo::SimulationIface();
+ this->client->ConnectWait(0, GZ_CLIENT_ID_USER_FIRST);
+ /// Open the Simulation Interface; let exceptions leak out
+ this->simIface->Open(this->client, "default");
+ puts("Done.");
+
+ puts("[webgazebo] Ready");
}
WebGazebo::~WebGazebo()
{
+ delete this->simIface;
+ delete this->client;
+
// No event_fini() to call...
}
+bool
+WebGazebo::GetPose(gazebo::Pose* pose, std::string model)
+{
+ // Discard any leftover responses;
+ this->simIface->data->responseCount = 0;
+
+ // Ask Gazebo
+ this->simIface->GetPose3d(model.c_str());
+
+ // Wait for the response
+ struct timespec sleeptime = {0, 10000000};
+ while(this->simIface->data->responseCount == 0)
+ nanosleep(&sleeptime, NULL);
+
+ assert(this->simIface->data->responseCount == 1);
+ *pose = this->simIface->data->responses[0].modelPose;
+
+ return true;
+}
+
void
-WebGazebo::GenericURICallback(evhttp_request* req, void* arg)
+WebGazebo::EventCallback(evhttp_request* req, void* arg)
{
WebGazebo* obj = (WebGazebo*)arg;
- printf("in server cb for uri:%s:\n", req->uri);
+ printf("[webgazebo] Got request:%s:\n", req->uri);
struct evbuffer* eb = evbuffer_new();
assert(eb);
- evbuffer_add_printf(eb, "response for:%s:\n", req->uri);
- evhttp_send_reply(req, 200, "foo", eb);
+
+ std::string model = "pioneer2dx_model1";
+ gazebo::Pose p;
+ assert(obj->GetPose(&p, model));
+
+ evbuffer_add_printf(eb, "<html><head><title>WebGazebo</title></head><body>");
+ evbuffer_add_printf(eb, "<h1>WebGazebo!</h1>");
+ evbuffer_add_printf(eb, "%s's pose: (%.3f,%.3f,%.3f) (%.3f,%.3f,%.3f)",
+ model.c_str(),
+ p.pos.x, p.pos.y, p.pos.z,
+ p.roll, p.pitch, p.yaw);
+ evbuffer_add_printf(eb, "</body></html>");
+
+ evhttp_send_reply(req, 200, "OK", eb);
evbuffer_free(eb);
}
+void
+WebGazebo::Spin()
+{
+ event_dispatch();
+}
Modified: code/branches/federation/gazebo/webgazebo/WebGazebo.hh
===================================================================
--- code/branches/federation/gazebo/webgazebo/WebGazebo.hh 2009-03-08
05:05:57 UTC (rev 7386)
+++ code/branches/federation/gazebo/webgazebo/WebGazebo.hh 2009-03-08
05:30:33 UTC (rev 7387)
@@ -8,19 +8,29 @@
#include <event.h>
#include <evhttp.h>
+// libgazebo; the libgazebo directory is used because we're building
+// against the source tree
+#include <libgazebo/gazebo.h>
+
class WebGazebo
{
public:
WebGazebo(std::string _host, int _port);
~WebGazebo();
+ void Spin();
+
private:
std::string host;
int port;
struct evhttp* eh;
+ gazebo::Client *client;
+ gazebo::SimulationIface *simIface;
+
// Static, so that it can be passed as a callback to libevent
- static void GenericURICallback(evhttp_request* req, void* arg);
+ static void EventCallback(evhttp_request* req, void* arg);
+
+ bool GetPose(gazebo::Pose* pose, std::string model);
};
-
Modified: code/branches/federation/gazebo/webgazebo/http.cc
===================================================================
--- code/branches/federation/gazebo/webgazebo/http.cc 2009-03-08 05:05:57 UTC
(rev 7386)
+++ code/branches/federation/gazebo/webgazebo/http.cc 2009-03-08 05:30:33 UTC
(rev 7387)
@@ -37,7 +37,7 @@
event_init();
- ec = evhttp_connection_new("localhost", 7000);
+ ec = evhttp_connection_new("localhost", 8000);
assert(ec);
er = evhttp_request_new(cb, NULL);
Modified: code/branches/federation/gazebo/webgazebo/main.cc
===================================================================
--- code/branches/federation/gazebo/webgazebo/main.cc 2009-03-08 05:05:57 UTC
(rev 7386)
+++ code/branches/federation/gazebo/webgazebo/main.cc 2009-03-08 05:30:33 UTC
(rev 7387)
@@ -2,28 +2,35 @@
#include <stdlib.h>
-#define USAGE "USAGE: webgazebo [-h <host>] [-p <port>]"
+#define USAGE "USAGE: webgazebo [-h <host>] [-p <port>]\n"
-int g_port;
-std::string g_host;
+#define DEFAULT_PORT 8000
+#define DEFAULT_HOST "localhost"
+int g_port = DEFAULT_PORT;
+std::string g_host = DEFAULT_HOST;
+
bool ParseArgs(int argc, char** argv);
int
main(int argc, char** argv)
{
- //evhttp_set_gencb(eh, cb, NULL);
- //evhttp_set_cb(eh, "/foo", cb, NULL);
-
- //event_dispatch();
-
if(!ParseArgs(argc, argv))
{
fputs(USAGE, stderr);
exit(1);
}
- WebGazebo wg(g_host, g_port);
+ try
+ {
+ WebGazebo wg(g_host, g_port);
+ wg.Spin();
+ }
+ catch(std::string e)
+ {
+ fprintf(stderr, "Gazebo exception:\n %s\n", e.c_str());
+ exit(1);
+ }
return 0;
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit