From tk at edam.speech.cs.cmu.edu Thu Dec 7 14:45:00 2006 From: tk at edam.speech.cs.cmu.edu (tk@edam.speech.cs.cmu.edu) Date: Thu, 7 Dec 2006 14:45:00 -0500 Subject: [TeamTalk 9]: [546] TeamTalk/Agents: backendstub: Message-ID: <200612071945.kB7Jj0ke011908@edam.speech.cs.cmu.edu> An HTML attachment was scrubbed... URL: http://mailman.srv.cs.cmu.edu/pipermail/teamtalk-developers/attachments/20061207/e32a4c47/attachment-0001.html -------------- next part -------------- Modified: TeamTalk/Agents/Agents.sln =================================================================== --- TeamTalk/Agents/Agents.sln 2006-11-09 20:10:38 UTC (rev 545) +++ TeamTalk/Agents/Agents.sln 2006-12-07 19:44:59 UTC (rev 546) @@ -35,6 +35,41 @@ EndProjectSection EndProject Global + GlobalSection(SourceCodeControl) = preSolution + SccNumberOfProjects = 8 + SccProjectUniqueName0 = MultiDecoder\\Audio_Server\\Audio_Server.vcproj + SccProjectName0 = \u0022$/CommonAgents-2005/MultiDecoder/Audio_Server\u0022,\u0020ONACAAAA + SccLocalPath0 = MultiDecoder\\Audio_Server + SccProvider0 = MSSCCI:Microsoft\u0020Visual\u0020SourceSafe + SccProjectUniqueName1 = Helios3\\Helios3.vcproj + SccProjectName1 = \u0022$/CommonAgents-2005/Helios3\u0022,\u0020ZJACAAAA + SccLocalPath1 = Helios3 + SccProvider1 = MSSCCI:Microsoft\u0020Visual\u0020SourceSafe + SccProjectUniqueName2 = Kalliope\\Kalliope.vcproj + SccProjectName2 = \u0022$/CommonAgents-2005/Kalliope\u0022,\u0020MLACAAAA + SccLocalPath2 = Kalliope + SccProvider2 = MSSCCI:Microsoft\u0020Visual\u0020SourceSafe + SccProjectUniqueName3 = NlgServer2\\NlgServer2.vcproj + SccProjectName3 = \u0022$/CommonAgents-2005/NlgServer2\u0022,\u0020JOACAAAA + SccLocalPath3 = NlgServer2 + SccProvider3 = MSSCCI:Microsoft\u0020Visual\u0020SourceSafe + SccProjectUniqueName4 = Phoenix2\\phoenix2.vcproj + SccProjectName4 = \u0022$/CommonAgents-2005/Phoenix2\u0022,\u0020APACAAAA + SccLocalPath4 = Phoenix2 + SccProvider4 = MSSCCI:Microsoft\u0020Visual\u0020SourceSafe + SccProjectUniqueName5 = ProcessMonitor\\ProcessMonitor.vcproj + SccProjectName5 = \u0022$/CommonAgents-2005/ProcessMonitor\u0022,\u0020VPACAAAA + SccLocalPath5 = ProcessMonitor + SccProvider5 = MSSCCI:Microsoft\u0020Visual\u0020SourceSafe + SccProjectUniqueName6 = RavenClaw\\RavenClaw.vcproj + SccProjectName6 = \u0022$/CommonAgents-2005/RavenClaw\u0022,\u0020PRACAAAA + SccLocalPath6 = RavenClaw + SccProvider6 = MSSCCI:Microsoft\u0020Visual\u0020SourceSafe + SccProjectUniqueName7 = MultiDecoder\\Sphinx_Engine\\Sphinx_Engine.vcproj + SccProjectName7 = \u0022$/CommonAgents-2005/MultiDecoder/Sphinx_Engine\u0022,\u0020BOACAAAA + SccLocalPath7 = MultiDecoder\\Sphinx_Engine + SccProvider7 = MSSCCI:Microsoft\u0020Visual\u0020SourceSafe + EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 Release|Win32 = Release|Win32 @@ -42,8 +77,8 @@ GlobalSection(ProjectConfigurationPlatforms) = postSolution {C31484B0-179B-432D-AE1E-75FB90591F23}.Debug|Win32.ActiveCfg = Debug|Win32 {C31484B0-179B-432D-AE1E-75FB90591F23}.Debug|Win32.Build.0 = Debug|Win32 - {C31484B0-179B-432D-AE1E-75FB90591F23}.Release|Win32.ActiveCfg = Release|Win32 - {C31484B0-179B-432D-AE1E-75FB90591F23}.Release|Win32.Build.0 = Release|Win32 + {C31484B0-179B-432D-AE1E-75FB90591F23}.Release|Win32.ActiveCfg = Debug|Win32 + {C31484B0-179B-432D-AE1E-75FB90591F23}.Release|Win32.Build.0 = Debug|Win32 {93C8F5F8-6C43-4179-9B9F-A31AA6438513}.Debug|Win32.ActiveCfg = Debug|Win32 {93C8F5F8-6C43-4179-9B9F-A31AA6438513}.Debug|Win32.Build.0 = Debug|Win32 {93C8F5F8-6C43-4179-9B9F-A31AA6438513}.Release|Win32.ActiveCfg = Release|Win32 Modified: TeamTalk/Agents/PrimitiveComm/PrimitiveComm.vcproj =================================================================== --- TeamTalk/Agents/PrimitiveComm/PrimitiveComm.vcproj 2006-11-09 20:10:38 UTC (rev 545) +++ TeamTalk/Agents/PrimitiveComm/PrimitiveComm.vcproj 2006-12-07 19:44:59 UTC (rev 546) @@ -184,15 +184,11 @@ > - - + + + + @@ -262,11 +266,11 @@ > + + -#include - -#include "geometry.h" -#include "utils.h" - -using namespace geometry; - -Vector::Vector() {}; -Vector::Vector(double X, double Y) : x(X), y(Y) {}; -Vector Vector::rotate(double rads) { - double r = sqrt(x*x + y*y); - double theta = atan2(y, x); - x = r*cos(theta+rads); - y = r*sin(theta+rads); - return *this; -} - -double Vector::length() const { - return sqrt(x*x+y*y); -}; - -double Vector::angle() const { - return atan2(y, x); -}; - -ostream& operator<<(ostream& out, const Vector& p) { - return out << '[' << p.x << ',' << p.y << ']'; -}; - -istream& operator>>(istream& in, Vector& p) { - //expecting "\s*(\s*f\s+f\s*)" or "\s*f\s+f"; - - bool has_paren = false; - - while(!in.eof()) { - char c = in.peek(); - if (isspace(c)) { - in.ignore(); - } else if (c == '(') { - in.ignore(); - has_paren = true; - break; - } else break; - } - - in >> p.x >> p.y; - - if(has_paren) { - while(!in.eof()) { - char c = in.peek(); - if (isspace(c)) { - in.ignore(); - } else if (c == ')') { - in.ignore(); - break; - } else break; - } - } - - return in; -}; - -istream& operator>>(istream& in, geometry::Polygon& l) { - l.clear(); - geometry::Point p; - while(in >> p) { - l.push_back(p); - } - return in; -}; - -Quadrilateral::Quadrilateral(Vector lower_left, Vector upper_right) : Polygon(4) { - // axis-aligned quadrilateral - at(0) = Point(lower_left.x, lower_left.y); - at(1) = Point(lower_left.x, upper_right.y); - at(2) = Point(upper_right.x, upper_right.y); - at(3) = Point(upper_right.x, lower_left.y); -}; - -Quadrilateral::Quadrilateral(double x1, double y1, double x2, double y2) : Polygon(4) { - at(0) = Point(MIN(x1, x2), MIN(y1, y2)); - at(1) = Point(MIN(x1, x2), MAX(y1, y2)); - at(2) = Point(MAX(x1, x2), MAX(y1, y2)); - at(3) = Point(MAX(x1, x2), MIN(y1, y2)); -}; - -Quadrilateral::Quadrilateral(Vector p1, Vector p2, Vector p3, Vector p4) : Polygon(4) { - at(0) = Point(p1.x, p1.y); - at(1) = Point(p2.x, p2.y); - at(2) = Point(p3.x, p3.y); - at(3) = Point(p4.x, p4.y); -}; - -Quadrilateral::operator geometry::Polygon() const { - return *this; -}; - -Point Quadrilateral::ll() const { - Point retval = at(0); - for(int i=1; i<4; i++) { - if(at(i).x < retval.x || at(i).y < retval.y) retval = at(i); - } - return retval; -}; - -Point Quadrilateral::ul() const { - Point retval = at(0); - for(int i=1; i<4; i++) { - if(at(i).x > retval.x || at(i).y < retval.y) retval = at(i); - } - return retval; -}; - -Point Quadrilateral::ur() const { - Point retval = at(0); - for(int i=1; i<4; i++) { - if(at(i).x > retval.x || at(i).y > retval.y) retval = at(i); - } - return retval; -}; - -Point Quadrilateral::lr() const { - Point retval = at(0); - for(int i=1; i<4; i++) { - if(at(i).x < retval.x || at(i).y > retval.y) retval = at(i); - } - return retval; -}; - Modified: TeamTalk/Agents/PrimitiveComm/geometry.h =================================================================== --- TeamTalk/Agents/PrimitiveComm/geometry.h 2006-11-09 20:10:38 UTC (rev 545) +++ TeamTalk/Agents/PrimitiveComm/geometry.h 2006-12-07 19:44:59 UTC (rev 546) @@ -3,45 +3,122 @@ #include +#include "utils.h" + using namespace std; namespace geometry { -struct Vector { - double x, y; - Vector(); - Vector(double x, double y); - Vector rotate(double rads); - double length() const; - double angle() const; +template struct Point { + T x, y; + Point() : x(0), y(0) {}; + Point(T X, T Y) : x(X), y(Y) {}; + template static Point Polar(L length, double angle) { + return Point((T)(cos(angle)*length), (T)(sin(angle)*length)); + } + Point rotate(double rads) { + double r = sqrt(x*x + y*y); + double theta = atan2(y, x); + x = (T) (r*cos(theta+rads)); + y = (T) (r*sin(theta+rads)); + return *this; + } + double length() const {return sqrt(x*x+y*y);}; + double angle() const {return atan2(y, x);}; + Point operator-(const Point& rhs) const { + return Point(x-rhs.x, y-rhs.y); + } + Point& operator-=(const Point& rhs) { + x -= rhs.x; + y -= rhs.y; + return *this; + } + Point operator+(const Point& rhs) const { + return Point(x+rhs.x, y+rhs.y); + } + Point operator+=(const Point& rhs) { + x += rhs.x; + y += rhs.y; + return *this; + } }; -typedef Vector Point; +template struct Polygon : public vector< Point > { + Polygon() : vector< Point >() {}; + Polygon (int n) : vector< Point >(n) {}; + Polygon(const Polygon& p) : vector< Point >(p) {}; +}; -struct Polygon : public vector { - Polygon() : vector() {}; - Polygon(int n) : vector(n) {}; - Polygon(const Polygon& p) : vector(p) {}; +template struct Quadrilateral : public Polygon { + Quadrilateral() : Polygon(4) {}; + Quadrilateral(const Quadrilateral& q) : Polygon(q) {}; + Quadrilateral(Point lower_left, Point upper_right) : Polygon(4) { + // axis-aligned quadrilateral + at(0) = Point(lower_left.x, lower_left.y); + at(1) = Point(lower_left.x, upper_right.y); + at(2) = Point(upper_right.x, upper_right.y); + at(3) = Point(upper_right.x, lower_left.y); + }; + Quadrilateral(T x1, T x2, T y1, T y2) : Polygon(4) { + at(0) = Point(MIN(x1, x2), MIN(y1, y2)); + at(1) = Point(MIN(x1, x2), MAX(y1, y2)); + at(2) = Point(MAX(x1, x2), MAX(y1, y2)); + at(3) = Point(MAX(x1, x2), MIN(y1, y2)); + }; + Quadrilateral(Point p1, Point p2, Point p3, Point p4): Polygon(4) { + at(0) = p1; at(1) = p2; at(2) = p3; at(3) = p4; + }; + operator Polygon() const {return *this;} + Point ll() const { + Point retval = at(0); + for(int i=1; i<4; i++) { + if(at(i).x < retval.x || at(i).y < retval.y) retval = at(i); + } + return retval; + }; + Point ul() const { + Point retval = at(0); + for(int i=1; i<4; i++) { + if(at(i).x > retval.x || at(i).y < retval.y) retval = at(i); + } + return retval; + }; + Point ur() const { + Point retval = at(0); + for(int i=1; i<4; i++) { + if(at(i).x > retval.x || at(i).y > retval.y) retval = at(i); + } + return retval; + }; + Point lr() const { + Point retval = at(0); + for(int i=1; i<4; i++) { + if(at(i).x < retval.x || at(i).y > retval.y) retval = at(i); + } + return retval; + }; }; -struct Quadrilateral : public Polygon { - Quadrilateral() : Polygon(4) {}; - Quadrilateral(const Quadrilateral& q) : Polygon(q) {}; - Quadrilateral(Point lower_left, Point upper_right); // axis-aligned - Quadrilateral(double x1, double x2, double y1, double y2); //another axis-aligned - Quadrilateral(Point p1, Point p2, Point p3, Point p4); //generic - - operator Polygon () const; - Point ll() const; - Point ul() const; - Point ur() const; - Point lr() const; +template struct Pose { + Point loc; + T yaw; + Pose() : loc(), yaw(0) {} + Pose(const Point& _loc, T _yaw) : loc(_loc), yaw(_yaw) {} + Pose(T _x, T _y, T _yaw) : loc(_x, _y), yaw(_yaw) {} }; +} //end namespace geometry + +template +ostream& operator<<(ostream& out, const geometry::Point& p) { + return out << '(' << p.x << ' ' << p.y << ')'; } +template +istream& operator>>(istream& in, geometry::Point& p) { + if(istreamLookFor(in, '(').fail()) return in; + if((in >> p.x).fail()) return in; + if((in >> p.y).fail()) return in; + return istreamLookFor(in, ')'); +} -ostream& operator<<(ostream& out, const geometry::Vector& p); -istream& operator>>(istream& in, geometry::Vector& p); -istream& operator>>(istream& in, geometry::Polygon& l); - #endif //GEOMETRY Modified: TeamTalk/Agents/PrimitiveComm/robot_client.cpp =================================================================== --- TeamTalk/Agents/PrimitiveComm/robot_client.cpp 2006-11-09 20:10:38 UTC (rev 545) +++ TeamTalk/Agents/PrimitiveComm/robot_client.cpp 2006-12-07 19:44:59 UTC (rev 546) @@ -6,6 +6,7 @@ #include "robot_client.hpp" #include "utils.h" +#include "win_netutils.h" #include #include #include @@ -27,45 +28,48 @@ using namespace std; using namespace TeamTalk; -int inet_pton(int family, const char *strptr, void *addrptr) { - if(family == AF_INET) { - struct in_addr in_val; -#ifdef WIN32 - in_val.S_un.S_addr = inet_addr(strptr); -#else - in_val.s_addr = inet_addr(strptr); -#endif - memcpy(addrptr, &in_val, sizeof(struct in_addr)); - return 1; - } - return -1; +void RobotClient::connect(const string &loc, const string &voice, + const string &safeness, unsigned short port) { + voice_ = voice; + debug << "opening " << loc << ':' << port << endl; + open(loc.c_str(), port); + if(spawnback) (*spawnback)(name_, safeness); } -const unsigned short RobotClient::PORT = 32788; +void (*RobotClient::spawnback)(const string&, const string&) = NULL; + +RobotClient::RobotClient(const string& name) : name_(name) {} + +RobotClient::RobotClient(const std::string& name, const std::string& loc, + const std::string& voice, const std::string& safeness, unsigned short port) + : name_(name) { + connect(loc, voice, safeness, port); +} + +string RobotClient::getName() const {return name_;} +string RobotClient::getVoice() const {return voice_;} + +bool RobotClient::operator<(const RobotClient& rhs) const { + return name_ < rhs.name_; +} + +//const unsigned short RobotsClient::PORT = 32788; //const unsigned int RobotClient::MAXLINE = 0xfff; //maximum size of received message <4k //unsigned int RobotClient::KEEPALIVEPERIOD = 900; //time between pings 15min //char* RobotClient::BROADCASTADDR = "192.168.1.255"; -RobotClient::RobotClient(const string& handle, void (*c)(const Msg*), void (*n)(const string&, const string&)) - : handle_(handle), callback_(c), spawnback_(n), callbackClass_(NULL) +RobotsClient::RobotsClient(const string& handle, RobotCallback* robotCallback) + : handle_(handle), robotCallback_(robotCallback) { + srand ((unsigned int)time(NULL)); + Msg::taskIDCounter = rand(); initializeSocketLayer(); getMyAddress(); - //connectOpTrader(); serverThread_ = spawnServer(); } -RobotClient::RobotClient(const string& handle, CallBackClass* c) - : handle_(handle), callback_(NULL), callbackClass_(c) +RobotsClient::~RobotsClient() { - initializeSocketLayer(); - getMyAddress(); - //connectOpTrader(); - serverThread_ = spawnServer(); -} - -RobotClient::~RobotClient() -{ // issue: close recieve thread somehow? #ifdef WIN32 @@ -73,47 +77,13 @@ #endif } -void RobotClient::initializeSocketLayer() { +void RobotsClient::initializeSocketLayer() { #ifdef WIN32 - { - WORD wVersionRequested; - WSADATA wsaData; - int err; - wVersionRequested = MAKEWORD( 2, 2 ); - err = WSAStartup( wVersionRequested, &wsaData ); - switch(err) { - case 0: break; //successful - case WSASYSNOTREADY: - throw RobotClientException("Indicates that the underlying network subsystem is not ready for network communication."); - case WSAVERNOTSUPPORTED: - throw RobotClientException("The version of Windows Sockets support requested is not provided by this particular Windows Sockets implementation."); - case WSAEINPROGRESS: - throw RobotClientException("A blocking Windows Sockets 1.1 operation is in progress."); - case WSAEPROCLIM: - throw RobotClientException("Limit on the number of tasks supported by the Windows Sockets implementation has been reached."); - case WSAEFAULT: - throw RobotClientException("The lpWSAData is not a valid pointer."); - default: - throw RobotClientException("unknown error starting Windows sockets."); - } - } + initializeSockets(); #endif } -Boeing::RobotClient* RobotClient::find(const string& s) { - map::iterator i = robotAddress.find(s); - if(i == robotAddress.end()) { - cerr << "didn't find '" << s << "' in "; - for(map::iterator i = robotAddress.begin(); i != robotAddress.end(); i++) { - cerr << "--" << i->first << "-- "; - } - cerr << endl; - return NULL; - } - return i->second; -} - -void RobotClient::getMyAddress() { +void RobotsClient::getMyAddress() { gethostname(hostname, Boeing::SADDR_LENGTH); struct hostent *Host = gethostbyname(hostname); in_addr me; @@ -122,14 +92,12 @@ } #ifdef WIN32 -HANDLE RobotClient::spawnServer() { +HANDLE RobotsClient::spawnServer() { #else -pthread_t RobotClient::spawnServer() { +pthread_t RobotsClient::spawnServer() { #endif //spawn server - //cerr << "about to spawn server" << endl; #ifdef WIN32 - //_beginthread(keepalive, 0, (void *) this); return (HANDLE)_beginthread(readMessages, 0, (void *) this); #else pthread_t readingThread, keepaliveThread; @@ -139,101 +107,45 @@ readMessages, (void *) this ); - pthread_create( - &keepaliveThread, - pthread_attr_default, - keepalive, - (void *) this - ); return readingThread; #endif } -bool RobotClient::addRobot(const string& name, - const string& loc, - const string& voice, - const string& safeness, - unsigned short port) { - - if(!port) port = PORT; - robotAddress[name] = new Boeing::RobotClient(); - robotAddress[name]->open(loc.c_str(), port); - robotVoice_[name] = voice; - if(spawnback_) (*spawnback_)(name, safeness); - //fixme +//returns false if a robot by that name already exists +//else it creates that robot client and inserts it +bool RobotsClient::addRobot(const string& name, const string& loc, + const string& voice, const string& safeness, + unsigned short port) +{ + if(find(name)) return false; + insert(RobotClient(name, loc, voice, safeness, port)); return true; } -//adds undiscoverable robots from a file -void RobotClient::addRobotsFile(const string& name, - Boeing::TraderClient *tclient, - Boeing::MapClient *mclient) { - cerr << "about to add robots" << endl; - ifstream Frobotips(name.c_str()); - if(!Frobotips) cerr << "problem opening " << name << endl; - string rname; - while(Frobotips >> rname) { - if(rname.at(0) == '#') { - ignoreToEndOfLine(Frobotips); - continue; - } - toupper(rname); - string rip; - Frobotips >> rip; - string::size_type i = rip.find(':'); - try { - int port = 0; - if(i != string::npos) { - port = atoi(string(rip, i+1, rip.size()-i-1).c_str()); - rip.resize(i); - } - if(rname == "OPTRADER") { - ignoreToEndOfLine(Frobotips); - cerr << "adding optrader@" << rip << ':' << port << endl; - tclient->open(rip.c_str(), port); - } else if(rname == "MAPSERVER") { - ignoreToEndOfLine(Frobotips); - cerr << "adding mapserver@" << rip << ':' << port << endl; - if(port) mclient->open(rip.c_str(), port); - else mclient->open(rip.c_str()); - } else { - string voice, safeness; - Frobotips >> voice >> safeness; - ignoreToEndOfLine(Frobotips); - cerr << "adding robot@" << rip << ':' << port << ' ' << voice << ' ' << safeness << endl; - addRobot(rname, rip, voice, safeness, port); - } - } catch(RobotClientException e) { - cerr << "unable to add robot " << rname << '(' << rip << ')' << endl; - cerr << e.what() << endl; - } - } -} - //--------------------------- // receiving messages #ifdef WIN32 -void RobotClient::readMessages(void *thisp) +void RobotsClient::readMessages(void *thisp) #else -void* RobotClient::readMessages(void *thisp) +void* RobotsClient::readMessages(void *thisp) #endif { - RobotClient* me = (RobotClient *) thisp; - cerr << "About to start reading thread" << endl; + RobotsClient* me = (RobotsClient *) thisp; + debug("client") << "About to start reading thread" << endl; for(;;) { bool gotAMessage = false; - for(map::iterator i = me->robotAddress.begin(); - i != me->robotAddress.end(); i++) { - const Boeing::MsgRobot* mesg = i->second->getNextMessage(); + for(iterator i = me->begin(); i != me->end(); i++) { + const Boeing::MsgRobot* mesg = i->getNextMessage(); if(mesg == NULL) continue; gotAMessage = true; - Msg* m = Msg::interpret(mesg->buff, i->first); + Msg* m = Msg::interpretBoeingPacket(string(mesg->buff, sizeof(Boeing::MsgRobot)), i->getName()); if(m == NULL) continue; - //if(!dynamic_cast(m)) { - //report unless you get a monotonous location message - cerr << "robot " << i->first << ": " << *m << endl; - //} + //report unless you get a monotonous location message + if(dynamic_cast(m)) + debug("client") << "robot " << i->getName() << ": " << m << endl; + else + info("client") << "robot " << i->getName() << ": " << m << endl; { //[2005-09-22] (tk): don't worry about pings for now //MsgPingPP* ping = dynamic_cast(m); @@ -245,108 +157,36 @@ // me->sendPacket(ping->handle(), MsgPingPP(me->handle_)); //} } - //cerr << "bout to call back" << endl; - if (me->callback_ != NULL) { - (*me->callback_)(m); - } else { - me->callbackClass_->callback(m); - } + me->robotCallback_->processRobotMessage(m); delete m; } if(!gotAMessage) Sleep(500); } } -/* -void RobotClient::broadcast() { - //form broadcast addr - sockaddr_in st_broadcast_addr; - { - memset(&st_broadcast_addr, 0, sizeof(struct sockaddr_in)); - st_broadcast_addr.sin_family = AF_INET; - inet_pton(AF_INET, BROADCASTADDR, &st_broadcast_addr.sin_addr); - st_broadcast_addr.sin_port = htons(PORT); - } +vector RobotsClient::getClientList() const { + vector ret; + for(const_iterator i = begin(); i != end(); i++) { + ret.push_back(i->getName()); + } + return ret; } -*/ -vector RobotClient::getClientList() const { - vector ret; - for(map::const_iterator i = robotAddress.begin(); - i != robotAddress.end(); - i++) { - ret.push_back(i->first); - } - return ret; +RobotClient* RobotsClient::find(const string& name) { + iterator i = set::find(RobotClient(name)); + if (i == end()) { + warn << "didn;t find robotclient for " << name << endl; + return NULL; + } else { + warn << "found robotclient " << ((void*)&*i) << " for " << name << endl; + } + return &*i; } -string RobotClient::find(const string& host, int port) const { - for(map::const_iterator i = robotAddress.begin(); - i != robotAddress.end(); - i++) { - if(i->second->getHost() == host && (port == 0 || i->second->getPort() == port)) return i->first; - } - return string(); -} - -string RobotClient::robotVoice(const string& robot_name) const { - map::const_iterator i = robotVoice_.find(robot_name); - if(i != robotVoice_.end()) return i->second; - return string(); -} - -void RobotClient::wait() const { +void RobotsClient::wait() const { #ifdef WIN32 WaitForSingleObject(serverThread_, INFINITE); #else pthread_join(serverThread_, NULL); #endif } - - /* - //here's some stuff that I might want to incorporate into udpsocket - if (nready == SOCKET_ERROR) { - select_error = WSAGetLastError(); - switch(select_error) { - case WSANOTINITIALISED: - throw RobotClientException("A successful WSAStartup call must occur before using this function."); - case WSAEFAULT: - throw RobotClientException("The name parameter is not a valid part of the user address space."); - case WSAENETDOWN: - throw RobotClientException("The network subsystem has failed."); - case WSAEINVAL: - throw RobotClientException("Invalid"); - case WSAEINTR: - throw RobotClientException("A blocking Windows Socket 1.1 call was canceled through WSACancelBlockingCall."); - case WSAEINPROGRESS: - throw RobotClientException("A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function."); - case WSAENOTSOCK: - throw RobotClientException("Not a socket"); - default: - throw RobotClientException("unknown select exception"); - } - } - } - if (rv == SOCKET_ERROR) { - socket_error = WSAGetLastError(); - switch (socket_error) { - case WSANOTINITIALISED: throw RobotClientException("A successful WSAStartup call must occur before using this function."); - case WSAENETDOWN: throw RobotClientException(" The network subsystem has failed."); - case WSAEFAULT: throw RobotClientException(" The buf parameter is not completely contained in a valid part of the user address space."); - case WSAENOTCONN: throw RobotClientException(" The socket is not connected."); - case WSAEINTR: throw RobotClientException(" The (blocking) call was canceled through WSACancelBlockingCall."); - case WSAEINPROGRESS: throw RobotClientException(" A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function."); - case WSAENETRESET: throw RobotClientException(" The connection has been broken due to the keep-alive activity detecting a failure while the operation was in progress."); - case WSAENOTSOCK: throw RobotClientException(" The descriptor is not a socket."); - case WSAEOPNOTSUPP: throw RobotClientException(" MSG_OOB was specified, but the socket is not stream-style such as type SOCK_STREAM, OOB data is not supported in the communication domain associated with this socket, or the socket is unidirectional and supports only send operations."); - case WSAESHUTDOWN: throw RobotClientException(" The socket has been shut down; it is not possible to receive on a socket after shutdown has been invoked with how set to SD_RECEIVE or SD_BOTH."); - case WSAEWOULDBLOCK: throw RobotClientException(" The socket is marked as nonblocking and the receive operation would block."); - case WSAEMSGSIZE: throw RobotClientException(" The message was too large to fit into the specified buffer and was truncated."); - case WSAEINVAL: throw RobotClientException(" The socket has not been bound with bind, or an unknown flag was specified, or MSG_OOB was specified for a socket with SO_OOBINLINE enabled or (for byte stream sockets only) len was zero or negative."); - case WSAECONNABORTED: throw RobotClientException(" The virtual circuit was terminated due to a time-out or other failure. The application should close the socket as it is no longer usable."); - case WSAETIMEDOUT: throw RobotClientException(" The connection has been dropped because of a network failure or because the peer system failed to respond."); - case WSAECONNRESET: throw RobotClientException(" The virtual circuit was reset by the remote side executing a hard or abortive close. The application should close the socket as it is no longer usable. On a UPD-datagram socket this error would indicate that a previous send operation resulted in an ICMP \"Port Unreachable\" message."); - default: throw RobotClientException("unknown recv error"); - } - } - */ Modified: TeamTalk/Agents/PrimitiveComm/robot_client.hpp =================================================================== --- TeamTalk/Agents/PrimitiveComm/robot_client.hpp 2006-11-09 20:10:38 UTC (rev 545) +++ TeamTalk/Agents/PrimitiveComm/robot_client.hpp 2006-12-07 19:44:59 UTC (rev 546) @@ -1,8 +1,6 @@ #ifndef __ROBOT_CLIENT_H__ #define __ROBOT_CLIENT_H__ -// client class to manage UDP connections to robots - #ifdef WIN32 #include #else @@ -20,23 +18,13 @@ #include #include #include -#include "robot_packet.hpp" +#include "robot_packet2.h" #include "udpsocket.h" #include #include #include -#ifdef WIN32 -#define sleep(x) Sleep((x)*1000) -#endif - -//[2005-09-29] (tk): hack - please repair -//#define OPTRADER_IP "192.168.99.210" -//#define OPTRADER_IP "128.2.179.53" (gs219) -//#define OPTRADER_PORT 32790 -//#define OPTRADER_PORT 5001 - using namespace std; namespace TeamTalk { @@ -49,41 +37,63 @@ const char* what() throw() {return error.c_str();} }; -class CallBackClass { +/** + * RobotCallback is an abstract interface class for the processMessage method. + * Whatever class you wish to use to process messages needs to inherit this + * class and implement processMessage. + */ +class RobotCallback { public: - virtual ~CallBackClass(){}; - virtual void callback(const Msg* msg)=0; + virtual void processRobotMessage(const Msg* m)=0; }; -class RobotClient { +/** + * The RobotClient class encapsulates everything we need to know to talk to a + * robot. + */ +class RobotClient : public Boeing::RobotClient { private: - static const unsigned short PORT; - map robotAddress; //for mapping names to robot clients - map robotVoice_; //for mapping robot names to voice names - //map addressRobot; //for mapping robot clients to names - + string name_; //the robot's name + string voice_; //the name of the robot's voice + +protected: + void connect(const string& loc, const string& voice, const string& safeness, + unsigned short port); + +public: + //spawnback is a hook for robot instantiation + //This is useful because the primitivecomm library handles robot instantiation + //and descruction, but may not know everything that needs to be done. By + //default it is set to do nothing. + static void (*spawnback)(const string& name, const string& safeness); + RobotClient(const string& name); + RobotClient(const string& name, const string& loc, const string& voice, + const string& safeness, unsigned short port=0); + + string getName() const; + string getVoice() const; + + bool operator<(const RobotClient& rhs) const; +}; + +class RobotsClient : public set { +private: char hostname[Boeing::SADDR_LENGTH]; // our host name char ip[16]; // our ip address in presentation format string handle_; //our handle #ifdef WIN32 static void readMessages(void *thisp); - //static void keepalive(void *thisp); HANDLE serverThread_; #else static void* readMessages(void *thisp); - //static void* keepalive(void *thisp); pthread_t serverThread_; #endif - void (*callback_)(const Msg*); - CallBackClass *callbackClass_; + RobotCallback* robotCallback_; - void (*spawnback_)(const string& name, const string& safeness); - protected: void initializeSocketLayer(); - //void connectOpTrader(); void getMyAddress(); #ifdef WIN32 HANDLE spawnServer(); @@ -93,81 +103,15 @@ public: // fill out any constructor/destructor info you need - RobotClient(const string& handle, void (*c)(const Msg*), void (*n)(const string&, const string&)=NULL); - RobotClient(const string& handle, CallBackClass* c); - ~RobotClient(); + RobotsClient(const string& handle, RobotCallback* robotCallback); + ~RobotsClient(); // returns true if robot wasn't already added - bool addRobot(const string& name, const string& loc, const string& voice, const string& safeness, unsigned short port=0); - bool addRobot(const string& name, in_addr addr); - bool addRobot(const string& name, sockaddr_in addr); - //adds undiscoverable robots from a file - void addRobotsFile(const string& name, - Boeing::TraderClient* tclient, Boeing::MapClient* mclient); + bool addRobot(const string& name, const string& loc, const string& voice, + const string& safeness, unsigned short port=0); - // -------------------------- - // send commands - /* - template bool sendPacketToOptrader(const M& msg) const { - cerr << "sending packet to optrader" << endl; - M message(msg); - Msg::stamp(message, hostname, "OpTrader"); - cerr << "to optrader: " << message << endl; - cerr << "size is " << sizeof(*message.content()) << endl; - cerr << hex; - for(int i=0; isend((const char*)message.content(), sizeof(*message.content())); - cerr << "sent " << nbytes << " bytes" << endl; - return (nbytes == sizeof(*message.content())); - } - */ - - Boeing::RobotClient* find(const string& s); - string find(const string& host, int port=0) const; //get the name of a robot from the ip or port - - /* - template - bool sendPacket(const string& robot, const M& msg) const { - M message(msg); - Msg::stamp(message, hostname, robot); - - return sendBuf(robot, (const char*)message.content(), sizeof(*message.content())); - } - */ - - /* - bool sendBuf(const string& robot, const char* msg, int size) { - map::iterator i = robotAddress.find(robot); - if(i == robotAddress.end()) { - cerr << "problem sending to unknown bot: " << robot << endl; - return 0; - } - Boeing::MsgCmd msgcmd; - memcpy(msgcmd.buff, msg, size); - return (i->second.sendPacket((Boeing::MsgHeader*)&msgcmd)) - } -*/ - - // send to all robots -/* - template bool sendAll(const M& msg) const { - bool retval = true; - for(map::iterator i=robotAddress.begin(); - i!=robotAddress.end(); i++) - retval &= sendPacket(i->first, msg); - return retval; - } -*/ - - void broadcast(); - - //getters vector getClientList() const; - string robotVoice(const string& robot_name) const; + RobotClient* find(const string& name); //wait for thread void wait() const; Deleted: TeamTalk/Agents/PrimitiveComm/robot_packet.h =================================================================== --- TeamTalk/Agents/PrimitiveComm/robot_packet.h 2006-11-09 20:10:38 UTC (rev 545) +++ TeamTalk/Agents/PrimitiveComm/robot_packet.h 2006-12-07 19:44:59 UTC (rev 546) @@ -1,203 +0,0 @@ -#ifndef __ROBOT_PACKET_H__ -#define __ROBOT_PACKET_H__ - -#ifdef WIN32 -//msvc doesn't seem to have stdint.h -typedef unsigned short uint16_t; -typedef short int16_t; -#else -#include -#endif - -#include - -// Packet structures for sending translated commands -// between human operators and robots - -//---------------------------------------------------- -// header packet for all messages - -// number of bytes defining a senders hostname -#define SADDR_LENGTH 32 - -// len - length in bytes of whole packet (including header) -// type - msg id -// tstamp - time of transmission in secs since Jan 1, 1970 -// sender - senders hostname -struct MsgHeader { - uint16_t type; - uint16_t len; - double tstamp; -}; - -// task id types -typedef uint16_t TaskID; - -//---------------------------------------------------- -// Message ID's - -// Task Requests -static const uint16_t MsgIdCmdHalt = 0x0000; -static const uint16_t MsgIdCmdGoTo = 0x0001; -static const uint16_t MsgIdCmdHome = 0x0002; -static const uint16_t MsgIdCmdPause = 0x0003; -static const uint16_t MsgIdCmdResume = 0x0004; -static const uint16_t MsgIdCmdFollow = 0x0005; -static const uint16_t MsgIdCmdCover = 0x0006; -static const uint16_t MsgIdCmdLoad = 0x0007; -static const uint16_t MsgIdCmdUnload = 0x0008; - -static const uint16_t MsgIdCmdPlayAction = 0x0010; - -// Information Requests -static const uint16_t MsgIdReqLocation = 0x2000; - -// Robot to Human status messages -static const uint16_t MsgIdRobAck = 0x8000; -static const uint16_t MsgIdRobDone = 0x4000; -static const uint16_t MsgIdRobLocation = 0x4001; - -static const uint16_t MsgIdPlayActionAck = 0x0010; - -// Handshaking -static const uint16_t MsgIdPing = 0x4002; - -//---------------------------------------------------- -// Task Requests - -struct MsgCmdTask : public MsgHeader { - TaskID taskid; -}; - -// message packets -// Halt message -> for stopping robots _now_ -typedef MsgCmdTask MsgCmdHalt; - -// Go to an x,y location in absolute/relative coord frame -// default is in global frame -// (x,y) - point in meters -// angle - orientation in radians -// attr - attributes, default - no angle, global frame -struct MsgCmdGoTo : public MsgCmdTask { - static const uint16_t UseAngle = 0x0100; - static const uint16_t Relative = 0x0001; - - uint16_t attr; - float x, y; - float angle; - - bool useAngle() { return (attr & UseAngle); } - bool useRelative() { return (attr & Relative); } - bool useGlobal() { return (!useRelative()); } -}; - - -typedef MsgCmdTask MsgCmdHome; -typedef MsgCmdTask MsgCmdPause; -typedef MsgCmdTask MsgCmdResume; - -struct MsgCmdFollow : public MsgCmdTask { - char leader[SADDR_LENGTH]; -}; - -struct RP_Polygon { - static const int MAX_POLYGON=10; - - //up to 10-sided - int n; //number of vertices - float xpoint[MAX_POLYGON+1], ypoint[MAX_POLYGON+1]; -}; - -struct MsgCmdCover : public MsgCmdTask { - //only axis-aligned rectangles -a type of polygon- are currently supported - RP_Polygon cover_shape; -}; - -typedef MsgCmdTask MsgCmdLoad; -typedef MsgCmdTask MsgCmdUnload; - -// Request robot location in absolute absolute frame -typedef MsgCmdTask MsgReqLocation; - -// play manager messages. Note these are variable length -// action will be a null terminated string -struct MsgCmdAction : public MsgCmdTask { - char action[1]; -}; - -//---------------------------------------------------- -// Robot to Human messages - -// acknowledgement messages -struct MsgRobAck : public MsgHeader { - TaskID taskid; // responding task id -}; - -// acknowledgement message for play manager -struct MsgPlayActionAck : public MsgHeader { - TaskID taskid; - int16_t status; - - static const int16_t FAILED=-1; - static const int16_t INPROGRESS=0; - static const int16_t COMPLETED=1; - - int isCompleted() { return status==COMPLETED; } - int isFailed() { return status<=FAILED; } - int isInProgress() { return status==INPROGRESS; } -}; - - -// robot done status message -// status - task status [Succeeded,Failed] -struct MsgRobDone : public MsgHeader { - static const int16_t Succeeded = 0x0001; - static const int16_t Failed = 0x0002; - - TaskID taskid; //task that has been completed - int16_t status; - - bool isSuccess() { return (status == Succeeded); } - bool isFailure() { return (!isSuccess()); } -}; - -// robot location status message -// (x,y) - location in global frame in meters -// angle - angle in global frame in radians -// moving - flag to indicate robot is in motion -struct MsgRobLocation : public MsgHeader { - float x, y; - float angle; - int16_t moving; - bool operator!=(const MsgRobLocation& rhs) const { - return rhs.x != x || - rhs.y != y || - rhs.angle != angle || - rhs.moving != moving; - }; -}; - -// Handshaking -struct MsgPing : public MsgHeader { - char handle[0xff]; -}; - -/* -union MsgUnion { - MsgCmdHalt halt; - MsgCmdGoTo go; - MsgCmdHome home; - MsgCmdPause pause; - MsgCmdResume resume; - MsgCmdFollow follow; - MsgCmdCover cover; - MsgCmdLoad load; - MsgCmdUnload unload; - MsgReqLocation loc; - MsgRobAck ack; - MsgRobDone done; - MsgRobLocation location; -}; -*/ - -#endif Modified: TeamTalk/Agents/PrimitiveComm/robot_packet.hpp =================================================================== --- TeamTalk/Agents/PrimitiveComm/robot_packet.hpp 2006-11-09 20:10:38 UTC (rev 545) +++ TeamTalk/Agents/PrimitiveComm/robot_packet.hpp 2006-12-07 19:44:59 UTC (rev 546) @@ -83,19 +83,21 @@ const Boeing::MsgCmdAction* content() const; }; -class MsgCmdSetPos : public MsgCmdActionPP { -private: - double x_, y_, angle_; +class MsgCmdSetPosPP : public Msg { + friend class Msg; protected: - static const char *const scan_template; - bool parse(); + Boeing::MsgCmdAction content_; + Boeing::MsgHeader* header(); public: - MsgCmdSetPos(const Boeing::MsgCmdAction& c); - MsgCmdSetPos(double x, double y, double a); - double getX() const; - double getY() const; - double getAngle() const; + MsgCmdSetPosPP(const Boeing::MsgCmdAction& c); + MsgCmdSetPosPP(double x, double y, double a); + //double getX() const; + //double getY() const; + //double getAngle() const; + MsgCmdSetPosPP* clone() const; + const Boeing::MsgCmdAction* content() const; string action_string() const; + string render() const; }; class MsgCmdHaltPP : public Msg { Added: TeamTalk/Agents/PrimitiveComm/robot_packet2.cpp =================================================================== --- TeamTalk/Agents/PrimitiveComm/robot_packet2.cpp (rev 0) +++ TeamTalk/Agents/PrimitiveComm/robot_packet2.cpp 2006-12-07 19:44:59 UTC (rev 546) @@ -0,0 +1,592 @@ +#include "robot_packet2.h" +#include "utils.h" +#include "win_netutils.h" + +//these are for Msg::stamp +#include +#include + +#include + +using namespace std; +using namespace geometry; + +// MalformedPacketException ******************************************* + +MalformedPacketException::MalformedPacketException(const string& context, const string& rep) throw() { + ostringstream e; + e << context << ": " << rep; + error = e.str(); +} + +MalformedPacketException::~MalformedPacketException() throw() {} + +const char* MalformedPacketException::what() throw() {return error.c_str();} + +// Msg **************************************************************** + +int Msg::taskIDCounter = 0; +const int Msg::defaultPriority = 1; + +//normal instantiation +Msg::Msg(string sender) : sender_(sender) {} +//instantiation from Boeing packet +Msg::Msg(string sender, double tstamp) : sender_(sender), tstamp_(tstamp) {} + +Msg::~Msg() {} + +Msg* Msg::interpretBoeingPacket(const string& m, const string& sender) +{ + const Boeing::MsgHeader *h = + reinterpret_cast(m.c_str()); + double tstamp = h->tstamp; + int type = h->type; + //messages to robots + if(type == Boeing::ROB_ACTION_ECHO || type == Boeing::CMD_ACTION) { + debug("packet") << "got: CMD_ACTION or ROB_ACTION_ECHO" << endl; + return MsgCmd::interpretBoeingPlayAction( + reinterpret_cast(m.c_str()), sender, tstamp); + } + if(type == Boeing::CMD_COVER) { + warn("packet") << "unhandled type: CMD_COVER " << endl; + return NULL; + } + if(type == Boeing::CMD_FOLLOW) { + warn("packet") << "unhandled type: CMD_FOLLOW " << endl; + return NULL; + } + if(type == Boeing::CMD_GOTO) { + warn("packet") << "unhandled type: CMD_GOTO " << endl; + return NULL; + } + if(type == Boeing::CMD_HALT) { + warn("packet") << "unhandled type: CMD_HALT " << endl; + return NULL; + } + if(type == Boeing::CMD_HOME) { + warn("packet") << "unhandled type: CMD_HOME " << endl; + return NULL; + } + if(type == Boeing::CMD_PAUSE) { + warn("packet") << "unhandled type: CMD_PAUSE " << endl; + return NULL; + } + if(type == Boeing::CMD_RESUME) { + warn("packet") << "unhandled type: CMD_RESUME " << endl; + return NULL; + } + if(type == Boeing::CMD_SETPOS) { + warn("packet") << "unhandled type: CMD_SETPOS " << endl; + return NULL; + } + if(type == Boeing::REQ_LOCATION) { + debug("packet") << "got: REQ_LOCATION" << endl; + return new MsgReqLocation(sender, tstamp); + } + if(type == Boeing::REQ_IMAGE) { + debug("packet") << "got: REQ_IMAGE" << endl; + return new MsgMapReq(sender, tstamp, + reinterpret_cast(m.c_str())->invoice); + } + //messages from robots + if(type == Boeing::ROB_LOCATION) { + debug("packet") << "got ROB_LOCATION" << endl; + const Boeing::MsgRobLocation* brl = + reinterpret_cast(m.c_str()); + return new MsgRobLocation(sender, brl->tstamp, + geometry::Point(brl->x, brl->y), brl->angle, (brl->moving != 0)); + } + if(type == Boeing::ROB_ACK) { + debug("packet") << "got: ROB_ACK" << endl; + return new MsgRobAck(sender, tstamp, + reinterpret_cast(m.c_str())->taskid); + } +// case Boeing::ROB_ACTION_ACK: +// warn("packet") << "unhandled type: ROB_ACTION_ACK " << h->type << endl; +// break; + if(type == Boeing::ROB_DONE) { + debug("packet") << "got: ROB_DONE" << endl; + const Boeing::MsgRobDone* bp = reinterpret_cast(m.c_str()); + return new MsgRobDone(sender, tstamp, + bp->taskid, (bp->status == Boeing::SUCCEEDED)); + } + if(type == Boeing::ROB_PLAY_HALT) { + warn("packet") << "unhandled type: ROB_PLAY_HALT " << endl; + return NULL; + } + if(type == Boeing::ROB_IMAGE) { + debug("packet") << "got: ROB_IMAGE" << endl; + const Boeing::MsgMap* bp = reinterpret_cast(m.c_str()); + return new MsgMap(sender, tstamp, bp->invoice, bp->seq, bp->x, bp->y, + string((const char *)bp->map, bp->array_length), MsgMap::JPEG); + } + //messages to trader +// case Boeing::TASK_CANCEL: +// warn("packet") << "unhandled type: TASK_CANCEL " << endl; +// break; + //messages from trader + if(type == Boeing::INFO) { + warn("packet") << "unhandled type: INFO " << endl; + return NULL; + } +// case Boeing::TASK_ACK: +// warn("packet") << "unhandled type: TASK_ACK " << endl; +// break; +// case Boeing::TASK_DONE: +// warn("packet") << "unhandled type: TASK_DONE " << endl; +// break; + //messages to mapserver/imageserver +// case Boeing::MAP_ACK: +// warn("packet") << "unhandled type: MAP_ACK " << endl; +// break; +// case Boeing::MAP_KEEPALIVE: +// warn("packet") << "unhandled type: MAP_KEEPALIVE " << endl; +// break; + //messages from mapserver/imageserver +// case Boeing::MAP_DIFF: +// warn("packet") << "unhandled type: MAP_DIFF " << endl; +// break; +// case Boeing::MAP_FULL: +// warn("packet") << "unhandled type: MAP_FULL " << endl; +// break; + warn("packet") << "unknown type: " << h->type << endl; + return NULL; +} + +void Msg::stamp(Boeing::MsgHeader& h) +{ +#ifdef WIN32 + struct __timeb64 timebuffer; + _ftime64(&timebuffer); +#else + struct timeb timebuffer; + ftime(&timebuffer); +#endif + h.tstamp = timebuffer.time + (float)timebuffer.millitm/1000; +} + +string Msg::getSender() const {return sender_;} + +// MsgCmd ************************************************************* + +//normal instantiation +MsgCmd::MsgCmd() : Msg(), taskID_(taskIDCounter++), priority_(defaultPriority) {} +MsgCmd::MsgCmd(int priority, string sender) +: Msg(sender), taskID_(taskIDCounter++), priority_(priority) {} +//instantiation from Boeing packet +MsgCmd::MsgCmd(string sender, double tstamp, int priority, int taskID) +: Msg(sender, tstamp) {} + +int MsgCmd::getTaskID() const {return taskID_;} +int MsgCmd::getPriority() const {return priority_;} + +MsgCmd* MsgCmd::interpretBoeingPlayAction(const Boeing::MsgCmdAction* m, + const string& sender, double tstamp) +{ + istringstream iaction(m->action); + string action_head; + iaction >> action_head; + if(action_head == "halt") + return new MsgCmdHalt(sender, tstamp, m->priority, m->taskid, m->action); + if(action_head == "goto" || action_head == "home") + return new MsgCmdGoTo(sender, tstamp, m->priority, m->taskid, m->action); + if(action_head == "pause") + return new MsgCmdPause(sender, tstamp, m->priority, m->taskid, m->action); + if(action_head == "resume") + return new MsgCmdPause(sender, tstamp, m->priority, m->taskid, m->action); + if(action_head == "follow") + return new MsgCmdFollow(sender, tstamp, m->priority, m->taskid, m->action); + if(action_head == "cover") + return new MsgCmdCover(sender, tstamp, m->priority, m->taskid, m->action); + if(action_head == "setpos") + return new MsgCmdSetPos(sender, tstamp, m->priority, m->taskid, m->action); + warn("packet") << "unknown action head: " << action_head << endl; + return NULL; +} + +string MsgCmd::renderBoeingPacket() const +{ + string retval; + Boeing::MsgCmdAction bPacket = + Boeing::MsgCmdAction::factory(render().c_str(), priority_, taskID_); + retval.assign(reinterpret_cast(&bPacket), bPacket.len); + return retval; +} + +string MsgCmd::render() const +{ + ostringstream out; + out << "MsgCmd: "; + out << "sender " << sender_; + out << " priority " << priority_; + out << " tstamp " << tstamp_ << ' '; + out << renderBoeingPlayAction(); + return out.str(); +} + +// MsgCmdHalt ********************************************************* + +//normal instantiation +MsgCmdHalt::MsgCmdHalt(): MsgCmd() {} +MsgCmdHalt::MsgCmdHalt(int priority): MsgCmd(priority) {} + +//instantiation from Boeing packet +MsgCmdHalt::MsgCmdHalt(string sender, double tstamp, int priority, int taskID, + string action) +: MsgCmd(sender, tstamp, priority, taskID) {} + +string MsgCmdHalt::renderBoeingPlayAction() const {return "halt";} + +// MsgCmdGoTo ********************************************************* + +//normal instantiation +//turn radians +MsgCmdGoTo::MsgCmdGoTo(float rad) +: MsgCmd(), angle_(rad), useAngle_(true), absolute_(false) {} +//move along a relative vector +MsgCmdGoTo::MsgCmdGoTo(Point loc, bool absolute) +: MsgCmd(), loc_(loc), angle_(0), useAngle_(false), absolute_(absolute) {} +MsgCmdGoTo::MsgCmdGoTo(Point loc, float angle, bool useAngle, bool absolute, int priority, string sender) +: MsgCmd(priority, sender), loc_(loc), angle_(angle), useAngle_(useAngle), absolute_(absolute) {} + +//instantiation from a Boeing packet +MsgCmdGoTo::MsgCmdGoTo(string sender, double tstamp, int priority, int taskID, string action) +: MsgCmd(sender, tstamp, priority, taskID) { + MalformedPacketException e("MsgCmdGoTo", action); + istringstream in(action); + string token; + if((in >> token).fail() || token != "goto") throw e; + if((in >> token).fail()) throw e; + if(token == "abs") absolute_ = true; + else if(token == "rel") absolute_ = false; + else throw e; + if((in >> loc_).fail()) throw e; + useAngle_ = !(in >> angle_).fail(); +} + +string MsgCmdGoTo::renderBoeingPlayAction() const { + ostringstream out; + out << "goto "; + if(absolute_) out << "abs "; + else out << "rel "; + out << loc_; + if(useAngle_) out << ' ' << angle_; + return out.str(); +} + +float MsgCmdGoTo::getX() const {return loc_.x;} +float MsgCmdGoTo::getY() const {return loc_.y;} +float MsgCmdGoTo::getAngle() const {return angle_;} +bool MsgCmdGoTo::useAngle() const {return useAngle_;} +bool MsgCmdGoTo::isAbsolute() const {return absolute_;} +bool MsgCmdGoTo::isRelative() const {return !absolute_;} + +// MsgCmdHome ********************************************************* + +//normal instantiation +MsgCmdHome::MsgCmdHome() : MsgCmd() {} +MsgCmdHome::MsgCmdHome(int priority, string sender) : MsgCmd(priority, sender) {} + +//instantiation from a Boeing packet +MsgCmdHome::MsgCmdHome(string sender, double tstamp, int priority, int taskID, string action) +: MsgCmd(sender, tstamp, priority, taskID) {} + +string MsgCmdHome::renderBoeingPlayAction() const {return "home";} + +// MsgCmdPause ******************************************************** + +//normal instantiation +MsgCmdPause::MsgCmdPause(int priority, string sender) : MsgCmd(priority, sender) {} + +//instantiation from a Boeing packet +MsgCmdPause::MsgCmdPause(string sender, double tstamp, int priority, int taskID, string action) +: MsgCmd(sender, tstamp, priority, taskID) {} + +string MsgCmdPause::renderBoeingPlayAction() const {return "pause";} + +// MsgCmdResume ******************************************************* + +//normal instantiation +MsgCmdResume::MsgCmdResume(int priority, string sender) : MsgCmd(priority, sender) {} + +//instantiation from a Boeing packet +MsgCmdResume::MsgCmdResume(string sender, double tstamp, int priority, int taskID, string action) +: MsgCmd(sender, tstamp, priority, taskID) {} + +string MsgCmdResume::renderBoeingPlayAction() const {return "resum,e";} + +// MsgCmdFollow ******************************************************* + +//normal instantiation +MsgCmdFollow::MsgCmdFollow() : MsgCmd() {} +MsgCmdFollow::MsgCmdFollow(int priority, string sender) : MsgCmd(priority, sender) {} + +//instantiation from a Boeing packet +MsgCmdFollow::MsgCmdFollow(string sender, double tstamp, int priority, int taskID, string action) +: MsgCmd(sender, tstamp, priority, taskID) {} + +string MsgCmdFollow::renderBoeingPlayAction() const {return "follow";} + +// MsgCmdCover ******************************************************** + +//normal instantiations +MsgCmdCover::MsgCmdCover(const Point& lower_left, const Point& upper_right, int priority, string sender) +: MsgCmd(priority, sender), polygon_(4) { + polygon_[0] = lower_left; + polygon_[1] = Point(lower_left.x, upper_right.y); + polygon_[2] = upper_right; + polygon_[3] = Point(upper_right.x, lower_left.y); +} + +MsgCmdCover::MsgCmdCover(float x1, float x2, float y1, float y2, int priority, string sender) +: MsgCmd(priority, sender), polygon_(4) { + polygon_[0] = Point(x1, y1); + polygon_[1] = Point(x1, y2); + polygon_[2] = Point(x2, y2); + polygon_[3] = Point(x2, y1); +} + +MsgCmdCover::MsgCmdCover(const geometry::Polygon& polygon, int priority, string sender) +: MsgCmd(priority, sender), polygon_(polygon) {} + +//instantiation from a Boeing packet +MsgCmdCover::MsgCmdCover(string sender, double tstamp, int priority, int taskID, string action) +: MsgCmd(sender, tstamp, priority, taskID) { + MalformedPacketException e("MsgCmdCover", action); + istringstream in(action); + string token; + if((in >> token).fail() || token != "cover") throw e; + Point p; + if((in >> p).fail()) throw e; //there should be at least one cover point + do { + polygon_.push_back(p); + in >> p; + } while(!in.fail()); +} + +geometry::Polygon MsgCmdCover::getPolygon() const {return polygon_;} + +string MsgCmdCover::renderBoeingPlayAction() const { + ostringstream out; + out << "cover "; + for(geometry::Polygon::const_iterator i = polygon_.begin(); i != polygon_.end(); i++) { + if(i != polygon_.begin()) out << ' '; + out << *i; + } + return out.str(); +} + +// MsgCmdSetPos ******************************************************* + +//normal instantiation +MsgCmdSetPos::MsgCmdSetPos(const Point& loc, float angle, int priority, string sender) +: MsgCmd(priority, sender), loc_(loc), angle_(angle) {} +MsgCmdSetPos::MsgCmdSetPos(float x, float y, float angle, int priority, string sender) +: MsgCmd(priority, sender), loc_(x, y), angle_(angle) {} + +//instantiation from a Boeing Packet +MsgCmdSetPos::MsgCmdSetPos(string sender, double tstamp, int priority, int taskID, string action) +: MsgCmd(sender, tstamp, priority, taskID) { + MalformedPacketException e("MsgCmdSetPos", action); + istringstream in(action); + string token; + if((in >> token).fail() || token != "setpos") throw e; + if((in >> loc_).fail()) throw e; + if((in >> angle_).fail()) throw e; +} + +Point MsgCmdSetPos::getLocation() const {return loc_;} +float MsgCmdSetPos::getX() const {return loc_.x;} +float MsgCmdSetPos::getY() const {return loc_.y;} +float MsgCmdSetPos::getAngle() const {return angle_;} + +string MsgCmdSetPos::renderBoeingPlayAction() const { + ostringstream out; + out << "setpos " << loc_ << ' ' << angle_; + return out.str(); +} + +// MsgReqLocation ***************************************************** + +//normal instantiation +MsgReqLocation::MsgReqLocation(string sender) : Msg(sender) {} + +//instatiation from a Boeing packet +MsgReqLocation::MsgReqLocation(string sender, double tstamp) : Msg(sender, tstamp) {} + +string MsgReqLocation::render() const {return "reqlocation";} + +string MsgReqLocation::renderBoeingPacket() const { + Boeing::MsgReqLocation packet = + Boeing::MsgReqLocation::factory(1, taskIDCounter++); + return string(reinterpret_cast(&packet), packet.len); +} + +// MsgRobAck ********************************************************** + +//normal instantiation +MsgRobAck::MsgRobAck(int taskID, string sender) : Msg(sender), taskID_(taskID) {} + +//instatiation from a Boeing packet +MsgRobAck::MsgRobAck(string sender, double tstamp, int taskID) +: Msg(sender, tstamp), taskID_(taskID) {} + +string MsgRobAck::render() const {return "roback";} + +string MsgRobAck::renderBoeingPacket() const { + Boeing::MsgRobAck packet = Boeing::MsgRobAck::factory(taskID_); + return string(reinterpret_cast(&packet), packet.len); +} + +// MsgRobDone ********************************************************* + +//normal instantiation +MsgRobDone::MsgRobDone(int taskID, bool success, string sender) +: Msg(sender), taskID_(taskID), success_(success) {} + +//instantiation from a Boeing packet +MsgRobDone::MsgRobDone(string sender, double tstamp, int taskID, bool success) +: Msg(sender, tstamp), taskID_(taskID), success_(success) {} + +int MsgRobDone::getTaskID() const {return taskID_;} + +bool MsgRobDone::isSuccess() const {return success_;} + +string MsgRobDone::render() const { + ostringstream out; + out << "robdone: " << taskID_ << (success_? "SUCCEEDED": "FAILED"); + return out.str(); +} + +string MsgRobDone::renderBoeingPacket() const { + Boeing::MsgRobDone packet = Boeing::MsgRobDone::factory(taskID_, success_); + return string(reinterpret_cast(&packet), packet.len); +} + +// MsgRobLocation ***************************************************** + +const float MsgRobLocation::tolerance = 0.05F; //5 cm tolerance to change-in position +const float MsgRobLocation::angularTolerance = 0.03F; // ~2 deg tolerance + +//normal instantiation +MsgRobLocation::MsgRobLocation() +: Msg(), angle_(0), moving_(false) {} +MsgRobLocation::MsgRobLocation(Point loc, float angle, bool moving, string sender) +: Msg(sender), loc_(loc), angle_(angle), moving_(moving) {} + +MsgRobLocation::MsgRobLocation(string sender, double tstamp, Point loc, float angle, bool moving) +: Msg(sender, tstamp), loc_(loc), angle_(angle), moving_(moving) {} + +Point MsgRobLocation::getLocation() const {return loc_;} +float MsgRobLocation::getX() const {return loc_.x;} +float MsgRobLocation::getY() const {return loc_.y;} +float MsgRobLocation::getAngle() const {return angle_;} +bool MsgRobLocation::isMoving() const {return moving_;} + +bool MsgRobLocation::operator==(const MsgRobLocation& x) const { + return (loc_-x.loc_).length() <= tolerance && + abs(angle_ - x.angle_) <= angularTolerance; +} + +bool MsgRobLocation::operator!=(const MsgRobLocation& x) const { + return (loc_-x.loc_).length() > tolerance || + abs(angle_ - x.angle_) <= angularTolerance; +} + +string MsgRobLocation::render() const { + ostringstream out; + out << "roblocation: " << loc_ << angle_ << "rad " + << (moving_? "MOVING": "STILL"); + return out.str(); +} + +string MsgRobLocation::renderBoeingPacket() const { + Boeing::MsgRobLocation packet = + Boeing::MsgRobLocation::factory(loc_.x, loc_.y, angle_, moving_); + return string(reinterpret_cast(&packet), packet.len); +} + +// MsgMapReq ********************************************************** + +int MsgMapReq::invoiceCounter_ = 0; + +//normal instantiation +MsgMapReq::MsgMapReq(string sender) : Msg(sender), invoice_(invoiceCounter_++) {} + +//instantiation from a Boeing packet +MsgMapReq::MsgMapReq(string sender, double tstamp, int invoice) +: Msg(sender, tstamp), invoice_(invoice) {} + +int MsgMapReq::getInvoice() const {return invoice_;} + +string MsgMapReq::render() const { + ostringstream out; + out << "mapreq: " << invoice_; + return out.str(); +} + +string MsgMapReq::renderBoeingPacket() const { + Boeing::MsgMapReq packet = Boeing::MsgMapReq::factory(); + return string(reinterpret_cast(&packet), packet.len); +} + +// MsgMap ************************************************************* + +//normal instantiation +MsgMap::MsgMap(short invoice, int sequence, int width, int height, const string& imageData, MsgMap::Encoding encoding, string sender) @@ Diff output truncated at 60000 characters. @@ From tk at edam.speech.cs.cmu.edu Thu Dec 7 16:45:42 2006 From: tk at edam.speech.cs.cmu.edu (tk@edam.speech.cs.cmu.edu) Date: Thu, 7 Dec 2006 16:45:42 -0500 Subject: [TeamTalk 10]: [547] TeamTalk/Configurations/DesktopConfiguration/startlist-desktop.txt: Reduced verbosity for PenDecoder and TeamTalkBackend. Message-ID: <200612072145.kB7LjgdK012234@edam.speech.cs.cmu.edu> An HTML attachment was scrubbed... URL: http://mailman.srv.cs.cmu.edu/pipermail/teamtalk-developers/attachments/20061207/dcff5253/attachment.html -------------- next part -------------- Modified: TeamTalk/Configurations/DesktopConfiguration/startlist-desktop.txt =================================================================== --- TeamTalk/Configurations/DesktopConfiguration/startlist-desktop.txt 2006-12-07 19:44:59 UTC (rev 546) +++ TeamTalk/Configurations/DesktopConfiguration/startlist-desktop.txt 2006-12-07 21:45:42 UTC (rev 547) @@ -4,7 +4,7 @@ { title PenDecoder dir ..\..\Agents\PenDecoder - path java -classpath bsh-core-2.0b4.jar;bsh-util-2.0b4.jar;jiu.jar;dist/PenDecoder.jar;../../ExternalLibraries/galaxy/contrib/MITRE/bindings/java/lib/galaxy.jar edu.cmu.ravenclaw.pendecoder.PenDecoderServer -port 11002 -peerfile ..\..\Configurations\DesktopConfiguration\peerfile.txt + path java -classpath bsh-core-2.0b4.jar;bsh-util-2.0b4.jar;jiu.jar;dist/PenDecoder.jar;../../ExternalLibraries/galaxy/contrib/MITRE/bindings/java/lib/galaxy.jar edu.cmu.ravenclaw.pendecoder.PenDecoderServer -port 11002 -verbosity 1 -peerfile ..\..\Configurations\DesktopConfiguration\peerfile.txt server_name PenDecoder } @@ -18,7 +18,7 @@ { title TeamTalkBackend dir . - path ..\..\Bin\x86-nt\TeamTalkBackend.exe -verbosity 5 -maxconns 6 + path ..\..\Bin\x86-nt\TeamTalkBackend.exe -verbosity 1 -maxconns 6 server_name TeamTalkBackend } @@ -45,7 +45,7 @@ { title SPHINX_AUDIO dir . - path ..\..\Bin\x86-nt\Audio_Server.exe -maxconns 6 -sps 16000 -engine_list sphinx_engines.txt + path ..\..\Bin\x86-nt\Audio_Server-DEBUG.exe -maxconns 6 -sps 16000 -engine_list sphinx_engines.txt server_name sphinx } @@ -62,4 +62,4 @@ path ..\..\ExternalLibraries\Galaxy\bin\x86-nt\HUB.exe -verbosity 3 -pgm_file TeamTalk-hub-desktop-skeleton.pgm } -} \ No newline at end of file +} From tk at edam.speech.cs.cmu.edu Thu Dec 7 16:47:21 2006 From: tk at edam.speech.cs.cmu.edu (tk@edam.speech.cs.cmu.edu) Date: Thu, 7 Dec 2006 16:47:21 -0500 Subject: [TeamTalk 11]: [548] TeamTalk/Agents/boeingLib: Imported changes. Message-ID: <200612072147.kB7LlLBu012244@edam.speech.cs.cmu.edu> An HTML attachment was scrubbed... URL: http://mailman.srv.cs.cmu.edu/pipermail/teamtalk-developers/attachments/20061207/ca2dd95b/attachment.html -------------- next part -------------- Modified: TeamTalk/Agents/boeingLib/boeing/boeing_converter.cc =================================================================== --- TeamTalk/Agents/boeingLib/boeing/boeing_converter.cc 2006-12-07 21:45:42 UTC (rev 547) +++ TeamTalk/Agents/boeingLib/boeing/boeing_converter.cc 2006-12-07 21:47:20 UTC (rev 548) @@ -86,6 +86,13 @@ if(strncasecmp(temp,"rel",64) == 0) { result.msg_goto.attr |= MsgCmdGoTo::Relative; } + } else if (name == "setpos") { + if (debug) + printf(" Got setpos message\n"); + result.hdr.type = CMD_SETPOS; + rv = sscanf(params,"%f %f %f", + &result.msg_setpos.x, &result.msg_setpos.y, + &result.msg_setpos.angle); } else if (name == "home") { if (debug) printf(" Got home message\n"); Modified: TeamTalk/Agents/boeingLib/coralshared/netbase.h =================================================================== --- TeamTalk/Agents/boeingLib/coralshared/netbase.h 2006-12-07 21:45:42 UTC (rev 547) +++ TeamTalk/Agents/boeingLib/coralshared/netbase.h 2006-12-07 21:47:20 UTC (rev 548) @@ -7,6 +7,15 @@ #include #include "util.h" +#ifndef PACKED +#ifdef WIN32 +#pragma pack(1) +#define PACKED +#else +#define PACKED __attribute__((packed)) +#endif +#endif + // Base type for TLV (type,length,value) messages struct NetMsg{ uint16_t msg_type; From tk at edam.speech.cs.cmu.edu Thu Dec 7 16:49:06 2006 From: tk at edam.speech.cs.cmu.edu (tk@edam.speech.cs.cmu.edu) Date: Thu, 7 Dec 2006 16:49:06 -0500 Subject: [TeamTalk 12]: [549] TeamTalk/Agents/PrimitiveComm: The call to interpretBoeingPacket is now surrounded by a try block. Message-ID: <200612072149.kB7Ln6F6012254@edam.speech.cs.cmu.edu> An HTML attachment was scrubbed... URL: http://mailman.srv.cs.cmu.edu/pipermail/teamtalk-developers/attachments/20061207/3a7f2a18/attachment-0001.html -------------- next part -------------- Modified: TeamTalk/Agents/PrimitiveComm/robot_client.cpp =================================================================== --- TeamTalk/Agents/PrimitiveComm/robot_client.cpp 2006-12-07 21:47:20 UTC (rev 548) +++ TeamTalk/Agents/PrimitiveComm/robot_client.cpp 2006-12-07 21:49:06 UTC (rev 549) @@ -139,26 +139,33 @@ const Boeing::MsgRobot* mesg = i->getNextMessage(); if(mesg == NULL) continue; gotAMessage = true; - Msg* m = Msg::interpretBoeingPacket(string(mesg->buff, sizeof(Boeing::MsgRobot)), i->getName()); - if(m == NULL) continue; - //report unless you get a monotonous location message - if(dynamic_cast(m)) - debug("client") << "robot " << i->getName() << ": " << m << endl; - else - info("client") << "robot " << i->getName() << ": " << m << endl; - { - //[2005-09-22] (tk): don't worry about pings for now - //MsgPingPP* ping = dynamic_cast(m); - //if(ping != NULL) { - // if(me->addRobot(ping->handle(), - // ping->content()->header.sender)) { - // if(me->addRobot(ping->handle(), st_remote_addr)) - // //if this robot is new to us, reply to the ping - // me->sendPacket(ping->handle(), MsgPingPP(me->handle_)); - //} - } - me->robotCallback_->processRobotMessage(m); - delete m; + try { + Msg* m = Msg::interpretBoeingPacket(string(mesg->buff, sizeof(Boeing::MsgRobot)), i->getName()); + if(m == NULL) { + error << "interpretation of message returned NULL" << endl; + continue; + } + //report unless you get a monotonous location message + if(dynamic_cast(m)) + debug("client") << "robot " << i->getName() << ": " << m << endl; + else + info("client") << "robot " << i->getName() << ": " << m << endl; + { + //[2005-09-22] (tk): don't worry about pings for now + //MsgPingPP* ping = dynamic_cast(m); + //if(ping != NULL) { + // if(me->addRobot(ping->handle(), + // ping->content()->header.sender)) { + // if(me->addRobot(ping->handle(), st_remote_addr)) + // //if this robot is new to us, reply to the ping + // me->sendPacket(ping->handle(), MsgPingPP(me->handle_)); + //} + } + me->robotCallback_->processRobotMessage(m); + delete m; + } catch(MalformedPacketException e) { + error << e.what(); + } } if(!gotAMessage) Sleep(500); } Deleted: TeamTalk/Agents/PrimitiveComm/robot_packet.cpp =================================================================== --- TeamTalk/Agents/PrimitiveComm/robot_packet.cpp 2006-12-07 21:47:20 UTC (rev 548) +++ TeamTalk/Agents/PrimitiveComm/robot_packet.cpp 2006-12-07 21:49:06 UTC (rev 549) @@ -1,589 +0,0 @@ -#include "robot_packet.hpp" - -#include -#include -#include - -using namespace std; -using namespace Boeing; - -ostream& operator<<(ostream& out, const RP_Polygon& p) { - out << '{'; - for(int i=0; i> w1; - if(w1 == "halt") retval = new MsgCmdHaltPP(); - else if(w1 == "goto") { - string w2; - i >> w2; - if (w2 == "home") { - retval = new MsgCmdHomePP(); - } else { - geometry::Point p; - i >> p; - if (w2 == "abs") { - retval = new MsgCmdGoToGlobalPP(p); - } else if (w2 == "rel") { - if(p.x == 0 && p.y == 0) { - double a = 0; - i >> a; - retval = new MsgCmdTurnRelativePP(a); - } else retval = new MsgCmdGoToRelativePP(p); - } - } - } else if (w1 == "pause") retval = new MsgCmdPausePP(); - else if (w1 == "resume") retval = new MsgCmdResumePP(); - else if (w1 == "setpos") retval = new MsgCmdSetPos(playaction); - return retval; -} - -Msg* Msg::interpret(const char* c, string s) { - Msg* retval = NULL; - if(c == NULL) { - cerr << "Msg::interpret: null string" << endl; - return retval; - } - const MsgHeader* h = (const MsgHeader*)c; - cerr << "got message type: " << h->type << endl; - switch(h->type) { - case CMD_HALT: retval = new MsgCmdHaltPP(*(const MsgCmdHalt*)c); break; - case CMD_GOTO: - switch(((const MsgCmdGoTo*)c)->attr) { - case 0x0000: retval = new MsgCmdGoToGlobalPP(*(const MsgCmdGoTo*)c); break; - case (MsgCmdGoTo::Relative): - retval = new MsgCmdGoToRelativePP(*(const MsgCmdGoTo*)c); break; - case (MsgCmdGoTo::Relative | MsgCmdGoTo::UseAngle): - retval = new MsgCmdTurnRelativePP(*(const MsgCmdGoTo*)c); break; - default: - cerr << "got unexpected attr: " << hex << ((const MsgCmdGoTo*)c)->attr << endl; - throw exception(); - } - break; - case CMD_HOME: retval = new MsgCmdHomePP(*(const MsgCmdHome*)c); break; - case CMD_PAUSE: retval = new MsgCmdPausePP(*(const MsgCmdPause*)c); break; - case CMD_RESUME: retval = new MsgCmdResumePP(*(const MsgCmdResume*)c); break; - case CMD_FOLLOW: retval = new MsgCmdFollowPP(*(const MsgCmdFollow*)c); break; - case REQ_LOCATION: retval = new MsgReqLocationPP(*(const MsgReqLocation*)c); break; - case ROB_ACK: retval = new MsgRobAckPP(*(const MsgRobAck*)c); break; - case ROB_DONE: retval = new MsgRobDonePP(*(const MsgRobDone*)c); break; - case ROB_LOCATION: retval = new MsgRobLocationPP(*(const MsgRobLocation*)c); break; - //case MsgIdPing: retval = new MsgPingPP(*(const MsgPing*)c); break; - case ROB_ACTION_ACK: retval = new MsgActionAckPP(*(const MsgActionAck*)c); break; - case ROB_ACTION_ECHO: - case CMD_ACTION: - retval = interpretPlayAction(*(const MsgCmdAction*)c); - if (retval == NULL) { - cerr << "didn't understand command action message" << endl; - return NULL; - } - break; - case REQ_IMAGE: retval = new MsgMapReqPP(*(const MsgMapReq*)c); break; - case ROB_IMAGE: retval = new MsgMapPP(*(const MsgMap*)c); break; - default: cerr << "unhandled type: " << h->type << endl; return NULL; - } - if (retval == NULL) { - //shouldn't happen - cerr << "weird error here" << endl; - return NULL; - } - retval->sender = s; - return retval; -}; - -Msg* Msg::clone() const { - const MsgCmdHaltPP *halt = dynamic_cast(this); - if(halt != NULL) return halt->clone(); - const MsgCmdGoToGlobalPP *gtg = dynamic_cast(this); - if(gtg != NULL) return gtg->clone(); - const MsgCmdGoToRelativePP *gtr = dynamic_cast(this); - if(gtr != NULL) return gtr->clone(); - const MsgCmdTurnRelativePP *turn = dynamic_cast(this); - if(turn != NULL) return turn->clone(); - const MsgCmdPausePP *pause = dynamic_cast(this); - if(pause != NULL) return pause->clone(); - const MsgCmdResumePP *resume = dynamic_cast(this); - if(resume != NULL) return resume->clone(); - const MsgCmdFollowPP *follow = dynamic_cast(this); - if(follow != NULL) return follow->clone(); - const MsgReqLocationPP *rloc = dynamic_cast(this); - if(rloc != NULL) return rloc->clone(); - const MsgRobAckPP *ack = dynamic_cast(this); - if(ack != NULL) return ack->clone(); - const MsgRobDonePP *done = dynamic_cast(this); - if(done != NULL) return done->clone(); - const MsgRobLocationPP *loc = dynamic_cast(this); - if(loc != NULL) return loc->clone(); - //const MsgPingPP *ping = dynamic_cast(this); - //if(ping != NULL) return ping->clone(); - const MsgMapReqPP *req_map = dynamic_cast(this); - if(req_map != NULL) return req_map->clone(); - const MsgMapPP *map = dynamic_cast(this); - if(map != NULL) return map->clone(); - return NULL; -}; - -Msg::~Msg() {} - -uint16_t Msg::getType() const { - if(dynamic_cast(this) != NULL) return CMD_HALT; - if(dynamic_cast(this) != NULL) return CMD_GOTO; - if(dynamic_cast(this) != NULL) return CMD_HOME; - if(dynamic_cast(this) != NULL) return CMD_PAUSE; - if(dynamic_cast(this) != NULL) return CMD_RESUME; - if(dynamic_cast(this) != NULL) return CMD_FOLLOW; - if(dynamic_cast(this) != NULL) return CMD_COVER; - if(dynamic_cast(this) != NULL) return REQ_LOCATION; - if(dynamic_cast(this) != NULL) return ROB_ACK; - if(dynamic_cast(this) != NULL) return ROB_DONE; - if(dynamic_cast(this) != NULL) return ROB_LOCATION; - //if(dynamic_cast(this) != NULL) return MsgIdPing; - if(dynamic_cast(this) != NULL) return REQ_IMAGE; - if(dynamic_cast(this) != NULL) return ROB_IMAGE; - return 0; -} - -string Msg::getSender() const { - return sender; -} - -MsgCmdActionPP::MsgCmdActionPP() {} -MsgCmdActionPP::MsgCmdActionPP(const MsgCmdAction& c) : content_(c) {} -MsgHeader* MsgCmdActionPP::header() {return (MsgHeader*)&content_;}; -string MsgCmdActionPP::render() const { - return content_.action; -} -const MsgCmdAction* MsgCmdActionPP::content() const { - return &content_; -} - -MsgCmdHaltPP::MsgCmdHaltPP() { - content_.type = CMD_HALT; - content_.len = sizeof(content_); - content_.taskid = iTaskCounter++; - content_.priority = 1; -}; -MsgCmdHaltPP::MsgCmdHaltPP(const MsgCmdHalt& x) : content_(x) {}; -MsgCmdHaltPP* MsgCmdHaltPP::clone() const {return new MsgCmdHaltPP(*this);}; -MsgHeader* MsgCmdHaltPP::header() {return (MsgHeader*)&content_;}; -const MsgCmdHalt* MsgCmdHaltPP::content() const {return &content_;} -string MsgCmdHaltPP::action_string() const {return "halt";} -string MsgCmdHaltPP::render() const {return "Halt";} - -MsgCmdGoToPP::MsgCmdGoToPP() { - content_.type = CMD_GOTO; - content_.len = sizeof(content_); - content_.taskid = iTaskCounter++; - content_.priority = 1; -}; -MsgCmdGoToPP::MsgCmdGoToPP(const MsgCmdGoTo& x) : content_(x) {}; -MsgHeader* MsgCmdGoToPP::header() {return (MsgHeader*)&content_;}; -const MsgCmdGoTo* MsgCmdGoToPP::content() const {return &content_;} - -MsgCmdGoToGlobalPP::MsgCmdGoToGlobalPP(Point loc) { - content_.x = (float) loc.x; content_.y = (float) loc.y; content_.attr = 0x0000; -}; -MsgCmdGoToGlobalPP::MsgCmdGoToGlobalPP(const MsgCmdGoTo& x) : - MsgCmdGoToPP(x) {}; -MsgCmdGoToGlobalPP* MsgCmdGoToGlobalPP::clone() const {return new MsgCmdGoToGlobalPP(*this);}; -string MsgCmdGoToGlobalPP::action_string() const { - ostringstream s; - s << "goto abs (" << content_.x << ' ' << content_.y << ')'; - return s.str(); -}; -string MsgCmdGoToGlobalPP::render() const { - ostringstream out; - out << "GoToGlobal: " << Point(content_.x, content_.y); - return out.str(); -}; - -MsgCmdGoToRelativePP::MsgCmdGoToRelativePP(Point vec) { - content_.x = (float) vec.x; content_.y = (float) vec.y; content_.attr = 0x0001; -}; -MsgCmdGoToRelativePP::MsgCmdGoToRelativePP(const MsgCmdGoTo& x) : - MsgCmdGoToPP(x) {}; -MsgCmdGoToRelativePP* MsgCmdGoToRelativePP::clone() const {return new MsgCmdGoToRelativePP(*this);}; -string MsgCmdGoToRelativePP::action_string() const { - ostringstream s; - s << "goto rel (" << content_.x << ' ' << content_.y << ')'; - return s.str(); -}; -string MsgCmdGoToRelativePP::render() const { - ostringstream out; - out << "GoToRelative: " << Point(content_.x, content_.y); - return out.str(); -}; - -MsgCmdTurnRelativePP::MsgCmdTurnRelativePP(double a) { - content_.x = 0; content_.y = 0; - content_.angle = (float) a; - content_.attr = 0x0101; -}; -MsgCmdTurnRelativePP::MsgCmdTurnRelativePP(const MsgCmdGoTo& x) : - MsgCmdGoToPP(x) {}; -MsgCmdTurnRelativePP* MsgCmdTurnRelativePP::clone() const {return new MsgCmdTurnRelativePP(*this);}; -string MsgCmdTurnRelativePP::action_string() const { - ostringstream s; - s << "goto rel (0 0) " << content_.angle; - return s.str(); -}; -string MsgCmdTurnRelativePP::render() const { - ostringstream out; - out << "TurnRelative: " << content_.angle << " radians"; - return out.str(); -}; - -MsgCmdHomePP::MsgCmdHomePP() { - content_.type = CMD_HOME; - content_.len = sizeof(content_); - content_.taskid = iTaskCounter++; - content_.priority = 1; -}; -MsgCmdHomePP::MsgCmdHomePP(const MsgCmdHome& x) : content_(x) {} -MsgCmdHomePP* MsgCmdHomePP::clone() const {return new MsgCmdHomePP(*this);} -MsgHeader* MsgCmdHomePP::header() {return (MsgHeader*)&content_;} -const MsgCmdHome* MsgCmdHomePP::content() const {return &content_;} -string MsgCmdHomePP::action_string() const {return "goto home";} -string MsgCmdHomePP::render() const {return "Home";} - -MsgCmdPausePP::MsgCmdPausePP() { - content_.type = CMD_PAUSE; - content_.len = sizeof(content_); - content_.taskid = iTaskCounter++; - content_.priority = 1; -}; -MsgCmdPausePP::MsgCmdPausePP(const MsgCmdPause& x) : content_(x) {}; -MsgCmdPausePP* MsgCmdPausePP::clone() const {return new MsgCmdPausePP(*this);}; -MsgHeader* MsgCmdPausePP::header() {return (MsgHeader*)&content_;}; -const MsgCmdPause* MsgCmdPausePP::content() const {return &content_;} -string MsgCmdPausePP::action_string() const {return "pause";} -string MsgCmdPausePP::render() const {return "Pause";}; - -MsgCmdResumePP::MsgCmdResumePP() { - content_.type = CMD_RESUME; - content_.len = sizeof(content_); - content_.taskid = iTaskCounter++; - content_.priority = 1; -}; -MsgCmdResumePP::MsgCmdResumePP(const MsgCmdResume& x) : content_(x) {}; -MsgCmdResumePP* MsgCmdResumePP::clone() const {return new MsgCmdResumePP(*this);}; -MsgHeader* MsgCmdResumePP::header() {return (MsgHeader*)&content_;}; -const MsgCmdResume* MsgCmdResumePP::content() const {return &content_;} -string MsgCmdResumePP::action_string() const {return "resume";} -string MsgCmdResumePP::render() const {return "Resume";}; - -MsgCmdFollowPP::MsgCmdFollowPP(const string& l) { - content_.type = CMD_FOLLOW; - content_.len = sizeof(content_); - content_.taskid = iTaskCounter++; - //strncpy(content_.leader, l.c_str(), SADDR_LENGTH); - content_.priority = 1; -}; -MsgCmdFollowPP::MsgCmdFollowPP(const MsgCmdFollow& x) : content_(x) {}; -MsgCmdFollowPP* MsgCmdFollowPP::clone() const {return new MsgCmdFollowPP(*this);}; -MsgHeader* MsgCmdFollowPP::header() {return (MsgHeader*)&content_;}; -const MsgCmdFollow* MsgCmdFollowPP::content() const {return &content_;} -string MsgCmdFollowPP::action_string() const { - ostringstream s; - //s << "follow " << content_.leader; - return s.str(); -} -string MsgCmdFollowPP::render() const { - ostringstream out; - //out << "Follow: " << content_.leader; - return out.str(); -}; - -MsgCmdCoverPP::MsgCmdCoverPP(const Point& lower_left, - const Point& upper_right) { - content_.type = CMD_COVER; - content_.len = sizeof(content_); - content_.taskid = iTaskCounter++; - content_.priority = 1; - content_.cover_shape = makeRP((geometry::Polygon)Quadrilateral(lower_left, upper_right)); -}; -MsgCmdCoverPP::MsgCmdCoverPP(float x1, float x2, float y1, float y2) { - content_.type = CMD_COVER; - content_.len = sizeof(content_); - content_.taskid = iTaskCounter++; - content_.priority = 1; - content_.cover_shape = makeRP((geometry::Polygon)Quadrilateral(x1, x2, y1, y2)); -}; -MsgCmdCoverPP::MsgCmdCoverPP(const geometry::Polygon& polygon) { - content_.type = CMD_COVER; - content_.len = sizeof(content_); - content_.taskid = iTaskCounter++; - content_.priority = 1; - content_.cover_shape = makeRP(polygon); -}; -MsgCmdCoverPP::MsgCmdCoverPP(const MsgCmdCover& x) : content_(x) {}; -MsgCmdCoverPP* MsgCmdCoverPP::clone() const {return new MsgCmdCoverPP(*this);}; -MsgHeader* MsgCmdCoverPP::header() {return (MsgHeader*)&content_;}; -const MsgCmdCover* MsgCmdCoverPP::content() const {return &content_;} -string MsgCmdCoverPP::action_string() const { - ostringstream s; - s << "cover"; - for(int i=0; i < content_.cover_shape.n; i++) { - s << " " << content_.cover_shape.xpoint[i] << ' ' << content_.cover_shape.ypoint[i] << ')'; - } - return s.str(); -} -string MsgCmdCoverPP::render() const { - ostringstream out; - out << "Cover: " << content_.cover_shape; - return out.str(); -}; - -MsgReqLocationPP::MsgReqLocationPP() { - content_.type = REQ_LOCATION; - content_.len = sizeof(content_); - content_.priority = 1; -}; -MsgReqLocationPP::MsgReqLocationPP(const MsgReqLocation& x) : content_(x) {}; -MsgReqLocationPP* MsgReqLocationPP::clone() const {return new MsgReqLocationPP(*this);}; -MsgHeader* MsgReqLocationPP::header() {return (MsgHeader*)&content_;}; -const MsgReqLocation* MsgReqLocationPP::content() const { - return &content_; -} -string MsgReqLocationPP::render() const {return "ReqLocation";}; - -MsgRobAckPP::MsgRobAckPP(uint16_t id) { - content_.type = ROB_ACK; - content_.len = sizeof(content_); - content_.taskid = id; -}; -MsgRobAckPP::MsgRobAckPP(const MsgRobAck& x) : content_(x) {}; -MsgRobAckPP* MsgRobAckPP::clone() const {return new MsgRobAckPP(*this);}; -MsgHeader* MsgRobAckPP::header() {return (MsgHeader*)&content_;}; -const MsgRobAck* MsgRobAckPP::content() const { - return &content_; -} -string MsgRobAckPP::render() const {return "RobAck";}; - -MsgRobDonePP::MsgRobDonePP(uint16_t id, bool success) { - content_.type = ROB_DONE; - content_.len = sizeof(content_); - content_.taskid = id; - content_.status = (success? 0x0001: 0x0002); -}; -MsgRobDonePP::MsgRobDonePP(const MsgRobDone& x) : content_(x) {}; -MsgRobDonePP* MsgRobDonePP::clone() const {return new MsgRobDonePP(*this);}; -MsgHeader* MsgRobDonePP::header() {return (MsgHeader*)&content_;}; -const MsgRobDone* MsgRobDonePP::content() const { - return &content_; -} -bool MsgRobDonePP::isSuccess() const { - return content_.status == 0x0001; -}; -string MsgRobDonePP::render() const { - ostringstream out; - out << "RobDone: " - << (isSuccess()? "successful": "unsuccessful"); - return out.str(); -}; - -MsgRobLocationPP::MsgRobLocationPP(Point loc, double a, bool m) { - content_.type = ROB_LOCATION; - content_.len = sizeof(content_); - content_.x = (float) loc.x; content_.y = (float) loc.y; - content_.angle = (float) a; - content_.moving = (m? 1: 0); -}; -MsgRobLocationPP::MsgRobLocationPP(const MsgRobLocation& x) : content_(x) {}; -MsgRobLocationPP* MsgRobLocationPP::clone() const {return new MsgRobLocationPP(*this);}; -MsgHeader* MsgRobLocationPP::header() {return (MsgHeader*)&content_;}; -const MsgRobLocation* MsgRobLocationPP::content() const { - return &content_; -} -bool MsgRobLocationPP::isMoving() const {return content_.moving==1;}; -string MsgRobLocationPP::render() const { - ostringstream out; - out << "RobLocation: " - << Point(content_.x, content_.y) << ' ' - << content_.angle << " radians " - << (isMoving()? "Moving": "Not moving"); - return out.str(); -}; - -/* -MsgPingPP::MsgPingPP(const string& handle) { - content_.type = MsgIdPing; - content_.len = sizeof(content_); - handle.copy(content_.handle, 0xff); - content_.handle[handle.size()] = '\0'; -}; -MsgPingPP::MsgPingPP(const MsgPing& x) : content_(x) {}; -MsgPingPP* MsgPingPP::clone() const {return new MsgPingPP(*this);}; -MsgHeader* MsgPingPP::header() {return (MsgHeader*)&content_;}; -const MsgPing* MsgPingPP::content() const {return &content_;}; -string MsgPingPP::handle() const {return content_.handle;}; -string MsgPingPP::render() const { - ostringstream out; - out << "Ping: " << content_.handle; - return out.str(); -}; -*/ - -MsgActionAckPP::MsgActionAckPP() { - content_.type = ROB_ACTION_ACK; - content_.len = sizeof(content_); -}; -MsgActionAckPP::MsgActionAckPP(const MsgActionAck& x) : content_(x) {}; -MsgActionAckPP* MsgActionAckPP::clone() const {return new MsgActionAckPP(*this);}; -MsgHeader* MsgActionAckPP::header() {return (MsgHeader*)&content_;}; -const MsgActionAck* MsgActionAckPP::content() const {return &content_;}; -string MsgActionAckPP::render() const { - ostringstream out; - out << "PlayActionAck: "; - return out.str(); -}; - -MsgMapReqPP::MsgMapReqPP() { - content_.type = REQ_IMAGE; - content_.len = sizeof(content_); -}; -MsgMapReqPP::MsgMapReqPP(const MsgMapReq& x) : content_(x) {}; -MsgMapReqPP* MsgMapReqPP::clone() const {return new MsgMapReqPP(*this);}; -MsgHeader* MsgMapReqPP::header() {return (MsgHeader*)&content_;}; -const MsgMapReq* MsgMapReqPP::content() const {return &content_;}; -string MsgMapReqPP::render() const { - ostringstream out; - out << "MapReq: "; - return out.str(); -}; -int MsgMapReqPP::getInvoice() const { - return content_.invoice; -} - -MsgMapPP::MsgMapPP() { - content_ = (MsgMap *)malloc(sizeof(MsgMap)); - content_->type = ROB_IMAGE; - content_->len = sizeof(content_); - content_->array_length = 0; -} -MsgMapPP::MsgMapPP(const MsgMap& x) { - content_ = (MsgMap *)malloc(x.getSize()); - memcpy(content_, &x, x.getSize()); -} -MsgMapPP::~MsgMapPP() {free(content_);} -MsgMapPP* MsgMapPP::clone() const {return new MsgMapPP(*(this->content_));} -MsgHeader* MsgMapPP::header() {return (MsgHeader*)content_;} -const MsgMap* MsgMapPP::content() const {return content_;} -int MsgMapPP::getWidth() const {return content_->x;} -int MsgMapPP::getHeight() const {return content_->y;} -int MsgMapPP::getInvoice() const {return content_->invoice;} -const char* MsgMapPP::getImageData() const {return (const char*)content_->map;} -int MsgMapPP::getImageDataSize() const {return content_->array_length;} -string MsgMapPP::render() const { - ostringstream out; - out << "Map: "; - return out.str(); -} - -MsgHeader Msg::construct_MsgHeader(uint16_t _type) { - MsgHeader retval; - retval.type = _type; -#ifdef WIN32 - struct __timeb64 timebuffer; - _ftime64(&timebuffer); -#else - struct timeb timebuffer; - ftime(&timebuffer); -#endif - retval.tstamp = timebuffer.time + (float)timebuffer.millitm/1000; - return retval; -} - -MsgCmdTask Msg::construct_MsgCmdTask(uint16_t _type) { - MsgCmdTask retval; - retval.type = _type; -#ifdef WIN32 - struct __timeb64 timebuffer; - _ftime64(&timebuffer); -#else - struct timeb timebuffer; - ftime(&timebuffer); -#endif - retval.tstamp = timebuffer.time + (float)timebuffer.millitm/1000; - retval.priority = 1; - retval.taskid = iTaskCounter++; - return retval; -} - -MsgCmdAction Msg::construct_MsgCmdAction(const string& _action) { - MsgCmdAction retval; - retval.type = CMD_ACTION; -#ifdef WIN32 - struct __timeb64 timebuffer; - _ftime64(&timebuffer); -#else - struct timeb timebuffer; - ftime(&timebuffer); -#endif - retval.tstamp = timebuffer.time + (float)timebuffer.millitm/1000; - retval.priority = 1; - retval.taskid = iTaskCounter++; - _action.copy(retval.action, _action.size()); - retval.len = retval.getSize(); - return retval; -} - -// **************** SetPos **************************************************** - -const char *const MsgCmdSetPos::scan_template = "setpos (%d %d) %d"; - -bool MsgCmdSetPos::parse() { - int numscanned = sscanf(content_.action, scan_template, x_, y_, angle_); - if(numscanned != 3) { - cerr << "problem parsing setpos: \"" << content_.action - << "\" with scan template: " << scan_template << endl; - cerr << "got only " << numscanned << " tokens" << endl; - return false; - } - return true; -} - -MsgCmdSetPos::MsgCmdSetPos(const Boeing::MsgCmdAction& x) : MsgCmdActionPP(x) { - parse(); -} - -MsgCmdSetPos::MsgCmdSetPos(double x, double y, double a) : x_(x), y_(y), angle_(a) { - ostringstream cmd_string; - cmd_string << "setpos (" << x << ' ' << y << ") " << a; - content_ = construct_MsgCmdAction(cmd_string.str()); -} - -double MsgCmdSetPos::getX() const {return x_;} -double MsgCmdSetPos::getY() const {return y_;} -double MsgCmdSetPos::getAngle() const {return angle_;} - -string MsgCmdSetPos::action_string() const { - ostringstream out; - out << "setpos (" << x_ << ' ' << y_ << ") " << angle_; - return out.str(); -} From tk at edam.speech.cs.cmu.edu Thu Dec 7 16:55:59 2006 From: tk at edam.speech.cs.cmu.edu (tk@edam.speech.cs.cmu.edu) Date: Thu, 7 Dec 2006 16:55:59 -0500 Subject: [TeamTalk 13]: [550] TeamTalk/Agents/PenDecoder: Added code to process task status updates . Message-ID: <200612072155.kB7Ltx5Q012267@edam.speech.cs.cmu.edu> An HTML attachment was scrubbed... URL: http://mailman.srv.cs.cmu.edu/pipermail/teamtalk-developers/attachments/20061207/c3807f25/attachment.html -------------- next part -------------- Modified: TeamTalk/Agents/PenDecoder/.nbintdb =================================================================== (Binary files differ) Modified: TeamTalk/Agents/PenDecoder/src/edu/cmu/ravenclaw/pendecoder/DrawingPad.java =================================================================== --- TeamTalk/Agents/PenDecoder/src/edu/cmu/ravenclaw/pendecoder/DrawingPad.java 2006-12-07 21:49:06 UTC (rev 549) +++ TeamTalk/Agents/PenDecoder/src/edu/cmu/ravenclaw/pendecoder/DrawingPad.java 2006-12-07 21:55:59 UTC (rev 550) @@ -19,6 +19,8 @@ protected java.util.List servers = new java.util.Vector(); protected Imager imager; + public TaskKeeper taskKeeper = new TaskKeeper(); + public DrawingPad(String title) { super(title); @@ -35,6 +37,10 @@ try { if(tool.getName() == "Zoom Out") { drawingCanvas.zoomOut(); + } else if(tool.getName() == "Cancel Task") { + Integer lastAdded = taskKeeper.getLastAdded(); + if(lastAdded == null) System.err.println("There are no tasks."); + else cancelTask(lastAdded); } else if(tool.getName() == "Start Session") { startSession(); ToggleButtonTool bt = (ToggleButtonTool)tool; @@ -122,6 +128,7 @@ "Click to zoom into a point on the map.", PointTool.ZOOMIN)); t.addTool(new ButtonTool(drawingCanvas, "Zoom Out", "Zoom out to see the entire map.")); + t.addTool(new ButtonTool(drawingCanvas, "Cancel Task", "Cancel the last task.")); t.addTool(new NPointTool(drawingCanvas, "Search", "Select waypoints along which to search.", @@ -177,6 +184,10 @@ } } + public void cancelTask(Integer taskid) { + for(PenDecoderServer server : servers) server.cancelTask(taskid); + } + public void startSession() { ListIterator i = servers.listIterator(); while(i.hasNext()) { Modified: TeamTalk/Agents/PenDecoder/src/edu/cmu/ravenclaw/pendecoder/Imager.java =================================================================== --- TeamTalk/Agents/PenDecoder/src/edu/cmu/ravenclaw/pendecoder/Imager.java 2006-12-07 21:49:06 UTC (rev 549) +++ TeamTalk/Agents/PenDecoder/src/edu/cmu/ravenclaw/pendecoder/Imager.java 2006-12-07 21:55:59 UTC (rev 550) @@ -3,9 +3,6 @@ * * Created on September 25, 2006, 3:23 PM * - * To change this template, choose Tools | Options and locate the template under - * the Source Creation and Management node. Right-click the template and choose - * Open. You can then make changes to the template in the Source Editor. */ package edu.cmu.ravenclaw.pendecoder; @@ -23,6 +20,7 @@ */ public class Imager extends Canvas { + static final long serialVersionUID = -2498616324568959806L; BufferedImage image; /** Creates a new instance of Imager */ Modified: TeamTalk/Agents/PenDecoder/src/edu/cmu/ravenclaw/pendecoder/PenDecoderServer.java =================================================================== --- TeamTalk/Agents/PenDecoder/src/edu/cmu/ravenclaw/pendecoder/PenDecoderServer.java 2006-12-07 21:49:06 UTC (rev 549) +++ TeamTalk/Agents/PenDecoder/src/edu/cmu/ravenclaw/pendecoder/PenDecoderServer.java 2006-12-07 21:55:59 UTC (rev 550) @@ -73,6 +73,44 @@ return (GFrame) null; } + public GFrame serverOpTaskUpdate(GFrame f) { + System.err.println("got task update"); + String type = (String)f.getProperty(":type"); + Integer taskid = (Integer)f.getProperty(":taskid"); + if(taskid == null) { + System.err.println("task update with no taskid!"); + return (GFrame)null; + } + if(type == null) { + System.err.println("task update with no type"); + return (GFrame)null; + } + if(type.equalsIgnoreCase("done")) { + Integer status = (Integer)f.getProperty(":status"); + if(status == null) { + System.err.println("task done update with no status!"); + return (GFrame)null; + } + boolean bstatus = (status != 0); + if(bstatus) frame.taskKeeper.succeedtask(taskid); + else frame.taskKeeper.failtask(taskid); + } else if(type.equalsIgnoreCase("ack")) { + frame.taskKeeper.addTask(taskid); + } else { + System.err.println("unhandled trader message type: " + type); + return (GFrame)null; + } + //String active_rendering = null; + String active_rendering = tk.utils.Utils.join(frame.taskKeeper.getActive(), " "); + //for(Integer i : frame.taskKeeper.getActive()) active_rendering += i.toString() + ' '; + //String succeeded_rendering = null; + String succeeded_rendering = tk.utils.Utils.join(frame.taskKeeper.getSucceeded(), " "); + //for(Integer i : frame.taskKeeper.getSucceeded()) succeeded_rendering += i.toString() + ' '; + frame.getInterpreter().print_bot("active tasks", active_rendering); + frame.getInterpreter().print_bot("succeeded tasks", succeeded_rendering); + return (GFrame) null; + } + public GFrame serverOpSetGoal(GFrame f) { String name = (String)f.getProperty(":robot_name"); boolean relative = (((Integer)f.getProperty(":relative")).intValue() == 1); @@ -195,12 +233,12 @@ } public void placeBot(String name, float x, float y, float theta) { - System.err.println("placing bot " + name + ": (" + x + " " + y + ") " + theta); + System.err.println("placing bot " + name + ": (" + x/100 + " " + y/100 + ") " + theta); Map pose = new HashMap(); - pose.put("[x]", Double.toString(x)); - pose.put("[y]", Double.toString(y)); + pose.put("[x]", Double.toString(x/100)); + pose.put("[y]", Double.toString(y/100)); pose.put("[angle]", Double.toString(theta)); - sayToBot("Commands", "[SetPoseCommand]", pose); + sayToBot("Commands", "[HumanSetPoseCommand]", pose); } public void search(RectangleShape shape) { @@ -226,6 +264,13 @@ sayToBot("Commands", "[HumanExploreCommand]", loc); } + public void cancelTask(Integer taskid) { + System.err.println("Cancelling " + taskid); + Map task = new HashMap(); + task.put("[taskid]", taskid.toString()); + sayToBot("Commands", "[HumanCancelTaskCommand]", task); + } + public void search(PolyLineShape shape) { System.err.println("Searching..."); Map loc = new HashMap(); Added: TeamTalk/Agents/PenDecoder/src/edu/cmu/ravenclaw/pendecoder/TaskKeeper.java =================================================================== --- TeamTalk/Agents/PenDecoder/src/edu/cmu/ravenclaw/pendecoder/TaskKeeper.java (rev 0) +++ TeamTalk/Agents/PenDecoder/src/edu/cmu/ravenclaw/pendecoder/TaskKeeper.java 2006-12-07 21:55:59 UTC (rev 550) @@ -0,0 +1,69 @@ +/* + * TaskKeeper.java + * + * Created on December 4, 2006, 4:02 PM + * + * To change this template, choose Tools | Options and locate the template under + * the Source Creation and Management node. Right-click the template and choose + * Open. You can then make changes to the template in the Source Editor. + */ + +package edu.cmu.ravenclaw.pendecoder; + +import java.util.LinkedList; +import java.util.List; + +/** + * + * @author tkharris + */ +public class TaskKeeper { + private List activetasks = new LinkedList(); + private List failedtasks = new LinkedList(); + private List succeededtasks = new LinkedList(); + private List cancelledtasks = new LinkedList(); + + /** Creates a new instance of TaskKeeper */ + public TaskKeeper() {} + + public void addTask(Integer taskid) { + activetasks.add(taskid); + } + + public void succeedtask(Integer taskid) { + activetasks.remove(taskid); + succeededtasks.add(taskid); + } + + public void failtask(Integer taskid) { + activetasks.remove(taskid); + failedtasks.add(taskid); + } + + //boolean cancelLastTask() { + // if(activetasks.isEmpty()) return false; + // cancelledtasks.add(activetasks.remove(0)); + // return true; + //} + + public List getActive() { + return activetasks; + } + + public List getSucceeded() { + return succeededtasks; + } + + public List getFailed() { + return failedtasks; + } + + public List getCancelled() { + return cancelledtasks; + } + + public Integer getLastAdded() { + if(activetasks.isEmpty()) return (Integer)null; + return activetasks.get(activetasks.size()-1); + } +} Added: TeamTalk/Agents/PenDecoder/src/tk/utils/Utils.java =================================================================== --- TeamTalk/Agents/PenDecoder/src/tk/utils/Utils.java (rev 0) +++ TeamTalk/Agents/PenDecoder/src/tk/utils/Utils.java 2006-12-07 21:55:59 UTC (rev 550) @@ -0,0 +1,38 @@ +/* + * Utils.java + * + * Created on December 6, 2006, 2:11 PM + * + * To change this template, choose Tools | Options and locate the template under + * the Source Creation and Management node. Right-click the template and choose + * Open. You can then make changes to the template in the Source Editor. + */ + +package tk.utils; + +import java.util.Collection; +import java.util.Iterator; + +/** + * + * @author tkharris + */ +public class Utils { + + /** Creates a new instance of Utils */ + public Utils() { + } + + public static String join(Collection s, String delimiter) { + StringBuffer buf = new StringBuffer(); + Iterator i = s.iterator(); + if(i.hasNext()) { + buf.append(i.next()); + while(i.hasNext()) { + buf.append(delimiter); + buf.append(i.next()); + } + } + return buf.toString(); + } +} From tk at edam.speech.cs.cmu.edu Thu Dec 7 16:58:41 2006 From: tk at edam.speech.cs.cmu.edu (tk@edam.speech.cs.cmu.edu) Date: Thu, 7 Dec 2006 16:58:41 -0500 Subject: [TeamTalk 14]: [551] TeamTalk/Configurations/DesktopConfiguration: Added task update messages to skeleton hub. Message-ID: <200612072158.kB7LwfHJ012277@edam.speech.cs.cmu.edu> An HTML attachment was scrubbed... URL: http://mailman.srv.cs.cmu.edu/pipermail/teamtalk-developers/attachments/20061207/9f82ec9b/attachment.html -------------- next part -------------- Modified: TeamTalk/Configurations/DesktopConfiguration/TeamTalk-hub-desktop-skeleton.pgm =================================================================== --- TeamTalk/Configurations/DesktopConfiguration/TeamTalk-hub-desktop-skeleton.pgm 2006-12-07 21:55:59 UTC (rev 550) +++ TeamTalk/Configurations/DesktopConfiguration/TeamTalk-hub-desktop-skeleton.pgm 2006-12-07 21:58:41 UTC (rev 551) @@ -33,7 +33,7 @@ ;; ------------------------------------------------- SERVER: PenDecoder at localhost:11002 -OPERATIONS: set_bot set_goal set_halt set_follow set_cover speak map_update image info_update +OPERATIONS: set_bot set_goal set_halt set_follow set_cover speak map_update image info_update task_update INIT: :greeting "Welcome to the CMU zap 2.0 PenDecoder!" ;; ------------------------------------------------- @@ -174,6 +174,10 @@ OUT: PROGRAM: trader_message -RULE: --> PenDecoder.info_update -IN: :type :ip :object :x :y +RULE: :type = "info" --> PenDecoder.info_update +IN: :type :ip :object :x :y :taskid :status OUT: + +RULE: :type = "ack" | :type = "done" --> PenDecoder.task_update +IN: :type :taskid :status +OUT: Modified: TeamTalk/Configurations/DesktopConfiguration/TeamTalk-hub-desktop-template.pgm =================================================================== --- TeamTalk/Configurations/DesktopConfiguration/TeamTalk-hub-desktop-template.pgm 2006-12-07 21:55:59 UTC (rev 550) +++ TeamTalk/Configurations/DesktopConfiguration/TeamTalk-hub-desktop-template.pgm 2006-12-07 21:58:41 UTC (rev 551) @@ -43,7 +43,7 @@ ;; ------------------------------------------------- SERVER: kalliope at localhost:12001 -OPERATIONS: speak reset +OPERATIONS: speak reset add_voice INIT: :greeting "Welcome to the %%DialogManager%%!" ;; ------------------------------------------------- @@ -228,3 +228,44 @@ RULE: --> phoenix.restart_decoder IN: OUT: + +PROGRAM: robot_message + +;;RULE: :goal | --> PenDecoder.speak +;;IN: :robot_name :speaktext +;;OUT: + +RULE: :type = "location" --> PenDecoder.set_bot +IN: :robot_name :x :y :r +OUT: + +RULE: :type = "goal" --> PenDecoder.set_goal +IN: :robot_name :relative :x :y +OUT: + +RULE: :type = "halt" --> PenDecoder.set_halt +IN: :robot_name +OUT: + +RULE: :type = "follow" --> PenDecoder.set_follow +IN: :robot_name :followee +OUT: + +RULE: :type = "cover" --> PenDecoder.set_cover +IN: :robot_name :x :y +OUT: + +RULE: :type = "image" --> PenDecoder.image +IN: :robot_name :width :height :invoice :jpeg +OUT: + +PROGRAM: robot_config +LOG_IN: :name :voice +RULE: :voice --> kalliope.add_voice +IN: :name :voice +OUT: + +PROGRAM: map_message +RULE: --> PenDecoder.map_update +IN: :type :x_size :y_size :resolution :encoded_map +OUT: From tk at edam.speech.cs.cmu.edu Fri Dec 8 13:00:29 2006 From: tk at edam.speech.cs.cmu.edu (tk@edam.speech.cs.cmu.edu) Date: Fri, 8 Dec 2006 13:00:29 -0500 Subject: [TeamTalk 15]: [552] TeamTalk/Configurations/DesktopConfiguration/startlist-desktop.config : Added configuration for python process manager. Message-ID: <200612081800.kB8I0TAI003752@edam.speech.cs.cmu.edu> An HTML attachment was scrubbed... URL: http://mailman.srv.cs.cmu.edu/pipermail/teamtalk-developers/attachments/20061208/5cb88013/attachment.html -------------- next part -------------- Added: TeamTalk/Configurations/DesktopConfiguration/startlist-desktop.config =================================================================== --- TeamTalk/Configurations/DesktopConfiguration/startlist-desktop.config (rev 0) +++ TeamTalk/Configurations/DesktopConfiguration/startlist-desktop.config 2006-12-08 18:00:28 UTC (rev 552) @@ -0,0 +1,42 @@ +EXPAND: $MITRE_ROOT $GC_HOME\contrib\MITRE +EXPAND: $TEAMTALK ..\.. +EXPAND: $AGENTS $TEAMTALK\Agents +EXPAND: $PENDECODER $AGENTS\PenDecoder +EXPAND: $BIN $TEAMTALK\Bin\x86-nt +EXPAND: $NLG $AGENTS\TeamTalkNLG +EXPAND: $RESOURCES $TEAMTALK\Resources +EXPAND: $GRAMMAR $RESOURCES\Grammar +EXPAND: $DECODER $RESOURCES\DecoderConfig +EXPAND: $GALAXY ..\..\ExternalLibraries\Galaxy\bin\x86-nt + +EXPAND: $JAVAEXE java +EXPAND: $PERL perl + +TITLE: TeamTalk + +PROCESS: $JAVAEXE -classpath $PENDECODER/bsh-core-2.0b4.jar;$PENDECODER/bsh-util-2.0b4.jar;$PENDECODER/jiu.jar;$PENDECODER/dist/PenDecoder.jar;$MITRE_ROOT/bindings/java/lib/galaxy.jar edu.cmu.ravenclaw.pendecoder.PenDecoderServer -port 11002 -peerfile peerfile.txt +PROCESS_TITLE: PenDecoder + +PROCESS: $BIN\KalliopeSwift.exe -maxconns 6 -config swift.cfg +PROCESS_TITLE: Kalliope + +PROCESS: $BIN\TeamTalkBackend.exe -verbosity 1 -maxconns 6 +PROCESS_TITLE: TeamTalkBackend + +PROCESS: $PERL -I$NLG_ROOT/../Rosetta $NLG_ROOT/bin/TeamTalk +PROCESS_TITLE: Rosetta + +PROCESS: $BIN\NlgServer2.exe -maxconns 6 -nlghost localhost +PROCESS_TITLE: NLGServer + +PROCESS: $BIN\phoenix2.exe -maxconns 6 -grammardir $GRAMMAR -grammarfn $GRAMMAR\zap2.net +PROCESS_TITLE: Phoenix + +PROCESS: $BIN\Audio_Server-DEBUG.exe -maxconns 6 -sps 16000 -engine_list sphinx_engines.txt +PROCESS_TITLE: Audio_Server + +PROCESS: $BIN\Sphinx_Engine -name male -argfn $DECODER\male-16khz.arg -port 9990 +PROCESS_TITLE: Sphinx_Male + +PROCESS: $GALAXY\HUB.exe -verbosity 3 -pgm_file TeamTalk-hub-desktop-skeleton.pgm +PROCESS_TITLE: Hub From tk at edam.speech.cs.cmu.edu Sun Dec 10 22:21:43 2006 From: tk at edam.speech.cs.cmu.edu (tk@edam.speech.cs.cmu.edu) Date: Sun, 10 Dec 2006 22:21:43 -0500 Subject: [TeamTalk 16]: [553] TeamTalk/Agents: compartmentalized per-robot information into a TeamTalk::robot class Message-ID: <200612110321.kBB3LhsO004256@edam.speech.cs.cmu.edu> An HTML attachment was scrubbed... URL: http://mailman.srv.cs.cmu.edu/pipermail/teamtalk-developers/attachments/20061210/a01c8f2e/attachment-0001.html -------------- next part -------------- Modified: TeamTalk/Agents/PrimitiveComm/PrimitiveComm.vcproj =================================================================== --- TeamTalk/Agents/PrimitiveComm/PrimitiveComm.vcproj 2006-12-08 18:00:28 UTC (rev 552) +++ TeamTalk/Agents/PrimitiveComm/PrimitiveComm.vcproj 2006-12-11 03:21:42 UTC (rev 553) @@ -184,6 +184,10 @@ > + + @@ -262,6 +266,10 @@ > + + Added: TeamTalk/Agents/PrimitiveComm/robot_class.cpp =================================================================== --- TeamTalk/Agents/PrimitiveComm/robot_class.cpp (rev 0) +++ TeamTalk/Agents/PrimitiveComm/robot_class.cpp 2006-12-11 03:21:42 UTC (rev 553) @@ -0,0 +1,42 @@ +#include "robot_class.h" +#include "utils.h" +#include "boeing_net.h" + +using namespace std; +using namespace TeamTalk; + +Robot::Robot(const std::string &_name, Robot::RobotClass _robotClass, const std::string &_loc, + unsigned short _port, const std::string &_voice) + : name(_name), robotClass(_robotClass), loc(_loc), port(_port), voice(_voice) {} + +Robot::Robot(const std::string &_name, Robot::RobotClass _robotClass, const std::string &_loc, + const std::string &_voice) + : name(_name), robotClass(_robotClass), loc(_loc), port(Boeing::ROBOT_PORT), voice(_voice) {} + +Robot::Robot(const Robot& x) : name(x.name), robotClass(x.robotClass), loc(x.loc), port(x.port), voice(x.voice) {} + +Robot::~Robot() {} + +istream& operator>>(istream& in, Robot::RobotClass& robotClass) { + string s; + if((in >> s).fail()) return in; + if(s == "safe" || s == "SAFE") robotClass = Robot::SAFE; + else if(s == "dangerous" || s == "DANGEROUS") robotClass = Robot::DANGEROUS; + else in.setf(ios::failbit); + return in; +} + +ostream& operator<<(ostream& out, const Robot::RobotClass& robotClass) { + switch(robotClass) { + case Robot::SAFE: + out << "safe"; + break; + case Robot::DANGEROUS: + out << "dangerous"; + break; + default: + error << "unknown robot class: " << (int)robotClass << endl; + out << (int)robotClass; + } + return out; +} \ No newline at end of file Added: TeamTalk/Agents/PrimitiveComm/robot_class.h =================================================================== --- TeamTalk/Agents/PrimitiveComm/robot_class.h (rev 0) +++ TeamTalk/Agents/PrimitiveComm/robot_class.h 2006-12-11 03:21:42 UTC (rev 553) @@ -0,0 +1,28 @@ +#ifndef ROBOT_CLASS_H +#define ROBOT_CLASS_H + +#include + +using namespace std; + +namespace TeamTalk { + class Robot { + public: + string name; + enum RobotClass {SAFE, DANGEROUS} robotClass; + string loc; + unsigned short port; + string voice; + + Robot(const string& _name, RobotClass _robotClass, const string& _loc, unsigned short port, + const string& voice); + Robot(const string& _name, RobotClass _robotClass, const string& _loc, const string& _voice); + Robot(const Robot& robot); + ~Robot(); + }; +}; + +istream& operator>>(istream& in, TeamTalk::Robot::RobotClass& robotClass); +ostream& operator<<(ostream& out, const TeamTalk::Robot::RobotClass& robotClass); + +#endif \ No newline at end of file Modified: TeamTalk/Agents/PrimitiveComm/robot_client.cpp =================================================================== --- TeamTalk/Agents/PrimitiveComm/robot_client.cpp 2006-12-08 18:00:28 UTC (rev 552) +++ TeamTalk/Agents/PrimitiveComm/robot_client.cpp 2006-12-11 03:21:42 UTC (rev 553) @@ -28,44 +28,139 @@ using namespace std; using namespace TeamTalk; -void RobotClient::connect(const string &loc, const string &voice, - const string &safeness, unsigned short port) { - voice_ = voice; - debug << "opening " << loc << ':' << port << endl; - open(loc.c_str(), port); - if(spawnback) (*spawnback)(name_, safeness); +bool RobotClient::connect() +{ + debug << "opening " << robot_.loc << ':' << robot_.port << endl; + return open(robot_.loc.c_str(), robot_.port) != 0; } +void RobotClient::spawnServer() +{ + //spawn server +#ifdef WIN32 + serverThread_ = (HANDLE)_beginthread(readMessages, 0, (void*)this); + _beginthread(trackbots, 0, (void*)this); +#else + pthread_t trackThread; + pthread_create(&serverThread_, pthread_attr_default, readMessages, (void *)this); + pthread_create(&trackThread_, pthread_attr_default, trackbots, (void*)this); +#endif +} + +#ifdef WIN32 +void RobotClient::trackbots(void* thisp) +#else +void* RobotClient::trackbots(void* thisp) +#endif +{ + RobotClient* me = (RobotClient*)thisp; + debug << "starting trackbots thread" << endl; + for(int t=0; true; t++) { + Sleep(1000); + debug << "sending location request" << endl; + if(!me->sendReqLocation()) { + //maybe we're not connected anymore, try to connect + warn << "we appear to be disconnected...trying to reconnect" << endl; + if(me->reopen()) { + warn << "ok, reconnected to " << me->getHost() << ':' << me->getPort() << endl; + me->sendReqLocation(); + } else { + warn << "couldn't reconnect to " << me->getHost() << ':' << me->getPort() << endl; + } + } + if(!(t%40) && me->hasCamera()) { //send image request every 40 seconds + me->sendReqImage(); + } + } +} + +//--------------------------- +// receiving messages + +#ifdef WIN32 +void RobotClient::readMessages(void *thisp) +#else +void* RobotClient::readMessages(void *thisp) +#endif +{ + RobotClient* me = (RobotClient *)thisp; + debug("client") << "About to start reading thread" << endl; + for(;;) { + bool gotAMessage = false; + const Boeing::MsgRobot* mesg = me->getNextMessage(); + if(mesg == NULL) continue; + try { + Msg* m = Msg::interpretBoeingPacket(string(mesg->buff, sizeof(Boeing::MsgRobot)), me->getName()); + if(!m) throw MalformedPacketException("RobotClient::readMessages", + "interpretation of message returned NULL"); + gotAMessage = true; + + //report unless you get a monotonous location message + if(dynamic_cast(m)) + debug("client") << "robot " << me->getName() << ": " << m << endl; + else + info("client") << "robot " << me->getName() << ": " << m << endl; + { + //[2005-09-22] (tk): don't worry about pings for now + //MsgPingPP* ping = dynamic_cast(m); + //if(ping != NULL) { + // if(me->addRobot(ping->handle(), + // ping->content()->header.sender)) { + // if(me->addRobot(ping->handle(), st_remote_addr)) + // //if this robot is new to us, reply to the ping + // me->sendPacket(ping->handle(), MsgPingPP(me->handle_)); + //} + } + me->robotCallback_->processRobotMessage(m); + delete m; + } catch(MalformedPacketException e) { + error << e.what(); + } + if(!gotAMessage) Sleep(500); + } +} + void (*RobotClient::spawnback)(const string&, const string&) = NULL; -RobotClient::RobotClient(const string& name) : name_(name) {} - RobotClient::RobotClient(const std::string& name, const std::string& loc, - const std::string& voice, const std::string& safeness, unsigned short port) - : name_(name) { - connect(loc, voice, safeness, port); + const std::string& voice, const std::string& safeness, unsigned short port, RobotCallback* robotCallback) + : robot_(name, Robot::SAFE, loc, port, voice), robotCallback_(robotCallback) +{ + if(safeness == "SAFE" || safeness == "safe") robot_.robotClass = Robot::SAFE; + else if(safeness == "DANGEROUS" || safeness == "dangerous") robot_.robotClass = Robot::DANGEROUS; + else { + error << "RobotClient::RobotClient: unknown robot class: " << safeness << endl; + return; + } + if(spawnback) (*spawnback)(name, safeness); + connect(); + spawnServer(); } -string RobotClient::getName() const {return name_;} -string RobotClient::getVoice() const {return voice_;} +string RobotClient::getName() const {return robot_.name;} +string RobotClient::getVoice() const {return robot_.voice;} +bool RobotClient::hasCamera() const {return robot_.robotClass == Robot::DANGEROUS;} -bool RobotClient::operator<(const RobotClient& rhs) const { - return name_ < rhs.name_; +void RobotClient::wait() const +{ +#ifdef WIN32 + WaitForSingleObject(serverThread_, INFINITE); +#else + pthread_join(serverThread_, NULL); +#endif } - //const unsigned short RobotsClient::PORT = 32788; //const unsigned int RobotClient::MAXLINE = 0xfff; //maximum size of received message <4k //unsigned int RobotClient::KEEPALIVEPERIOD = 900; //time between pings 15min //char* RobotClient::BROADCASTADDR = "192.168.1.255"; -RobotsClient::RobotsClient(const string& handle, RobotCallback* robotCallback) - : handle_(handle), robotCallback_(robotCallback) +RobotsClient::RobotsClient(const string& handle) + : handle_(handle) { srand ((unsigned int)time(NULL)); Msg::taskIDCounter = rand(); initializeSocketLayer(); getMyAddress(); - serverThread_ = spawnServer(); } RobotsClient::~RobotsClient() @@ -77,13 +172,15 @@ #endif } -void RobotsClient::initializeSocketLayer() { +void RobotsClient::initializeSocketLayer() +{ #ifdef WIN32 initializeSockets(); #endif } -void RobotsClient::getMyAddress() { +void RobotsClient::getMyAddress() +{ gethostname(hostname, Boeing::SADDR_LENGTH); struct hostent *Host = gethostbyname(hostname); in_addr me; @@ -91,109 +188,30 @@ strncpy(hostname, inet_ntoa(me), Boeing::SADDR_LENGTH); } -#ifdef WIN32 -HANDLE RobotsClient::spawnServer() { -#else -pthread_t RobotsClient::spawnServer() { -#endif - //spawn server -#ifdef WIN32 - return (HANDLE)_beginthread(readMessages, 0, (void *) this); -#else - pthread_t readingThread, keepaliveThread; - pthread_create( - &readingThread, - pthread_attr_default, - readMessages, - (void *) this - ); - return readingThread; -#endif -} - //returns false if a robot by that name already exists //else it creates that robot client and inserts it bool RobotsClient::addRobot(const string& name, const string& loc, const string& voice, const string& safeness, - unsigned short port) + unsigned short port, RobotCallback *robotCallback) { if(find(name)) return false; - insert(RobotClient(name, loc, voice, safeness, port)); + push_back(new RobotClient(name, loc, voice, safeness, port, robotCallback)); return true; } -//--------------------------- -// receiving messages - -#ifdef WIN32 -void RobotsClient::readMessages(void *thisp) -#else -void* RobotsClient::readMessages(void *thisp) -#endif +vector RobotsClient::getClientList() const { - RobotsClient* me = (RobotsClient *) thisp; - debug("client") << "About to start reading thread" << endl; - for(;;) { - bool gotAMessage = false; - for(iterator i = me->begin(); i != me->end(); i++) { - const Boeing::MsgRobot* mesg = i->getNextMessage(); - if(mesg == NULL) continue; - gotAMessage = true; - try { - Msg* m = Msg::interpretBoeingPacket(string(mesg->buff, sizeof(Boeing::MsgRobot)), i->getName()); - if(m == NULL) { - error << "interpretation of message returned NULL" << endl; - continue; - } - //report unless you get a monotonous location message - if(dynamic_cast(m)) - debug("client") << "robot " << i->getName() << ": " << m << endl; - else - info("client") << "robot " << i->getName() << ": " << m << endl; - { - //[2005-09-22] (tk): don't worry about pings for now - //MsgPingPP* ping = dynamic_cast(m); - //if(ping != NULL) { - // if(me->addRobot(ping->handle(), - // ping->content()->header.sender)) { - // if(me->addRobot(ping->handle(), st_remote_addr)) - // //if this robot is new to us, reply to the ping - // me->sendPacket(ping->handle(), MsgPingPP(me->handle_)); - //} - } - me->robotCallback_->processRobotMessage(m); - delete m; - } catch(MalformedPacketException e) { - error << e.what(); - } - } - if(!gotAMessage) Sleep(500); - } -} - -vector RobotsClient::getClientList() const { vector ret; for(const_iterator i = begin(); i != end(); i++) { - ret.push_back(i->getName()); + ret.push_back((*i)->getName()); } return ret; } -RobotClient* RobotsClient::find(const string& name) { - iterator i = set::find(RobotClient(name)); - if (i == end()) { - warn << "didn;t find robotclient for " << name << endl; - return NULL; - } else { - warn << "found robotclient " << ((void*)&*i) << " for " << name << endl; +RobotClient* RobotsClient::find(const string& name) +{ + for(const_iterator i = begin(); i != end(); i++) { + if((*i)->getName() == name) return *i; } - return &*i; + return NULL; } - -void RobotsClient::wait() const { -#ifdef WIN32 - WaitForSingleObject(serverThread_, INFINITE); -#else - pthread_join(serverThread_, NULL); -#endif -} Modified: TeamTalk/Agents/PrimitiveComm/robot_client.hpp =================================================================== --- TeamTalk/Agents/PrimitiveComm/robot_client.hpp 2006-12-08 18:00:28 UTC (rev 552) +++ TeamTalk/Agents/PrimitiveComm/robot_client.hpp 2006-12-11 03:21:42 UTC (rev 553) @@ -15,8 +15,7 @@ #endif #include -#include -#include +#include #include #include "robot_packet2.h" #include "udpsocket.h" @@ -24,6 +23,7 @@ #include #include #include +#include using namespace std; @@ -53,12 +53,21 @@ */ class RobotClient : public Boeing::RobotClient { private: - string name_; //the robot's name - string voice_; //the name of the robot's voice + Robot robot_; //the type of robot + RobotCallback* robotCallback_; protected: - void connect(const string& loc, const string& voice, const string& safeness, - unsigned short port); + bool connect(); //returns true if connection succeeded + void spawnServer(); +#ifdef WIN32 + static void trackbots(void *thisp); + static void readMessages(void *thisp); + HANDLE serverThread_; +#else + static void* trackbots(void *thisp); + static void* readMessages(void *thisp); + pthread_t serverThread_; +#endif public: //spawnback is a hook for robot instantiation @@ -66,55 +75,38 @@ //and descruction, but may not know everything that needs to be done. By //default it is set to do nothing. static void (*spawnback)(const string& name, const string& safeness); - RobotClient(const string& name); + RobotClient(const string& name, const string& loc, const string& voice, - const string& safeness, unsigned short port=0); + const string& safeness, unsigned short port, RobotCallback* robotCallback); string getName() const; string getVoice() const; + bool hasCamera() const; - bool operator<(const RobotClient& rhs) const; + void wait() const; }; -class RobotsClient : public set { +class RobotsClient : public list { private: char hostname[Boeing::SADDR_LENGTH]; // our host name char ip[16]; // our ip address in presentation format string handle_; //our handle -#ifdef WIN32 - static void readMessages(void *thisp); - HANDLE serverThread_; -#else - static void* readMessages(void *thisp); - pthread_t serverThread_; -#endif - - RobotCallback* robotCallback_; - protected: void initializeSocketLayer(); void getMyAddress(); -#ifdef WIN32 - HANDLE spawnServer(); -#else - pthread_t spawnServer(); -#endif public: // fill out any constructor/destructor info you need - RobotsClient(const string& handle, RobotCallback* robotCallback); + RobotsClient(const string& handle); ~RobotsClient(); // returns true if robot wasn't already added bool addRobot(const string& name, const string& loc, const string& voice, - const string& safeness, unsigned short port=0); + const string& safeness, unsigned short port, RobotCallback* robotCallback); vector getClientList() const; RobotClient* find(const string& name); - - //wait for thread - void wait() const; }; } //namespace TEAMTALK #endif Modified: TeamTalk/Agents/PrimitiveComm/robot_packet2.cpp =================================================================== --- TeamTalk/Agents/PrimitiveComm/robot_packet2.cpp 2006-12-08 18:00:28 UTC (rev 552) +++ TeamTalk/Agents/PrimitiveComm/robot_packet2.cpp 2006-12-11 03:21:42 UTC (rev 553) @@ -33,6 +33,8 @@ //instantiation from Boeing packet Msg::Msg(string sender, double tstamp) : sender_(sender), tstamp_(tstamp) {} +Msg::Msg(const Msg& m) : sender_(m.sender_), tstamp_(m.tstamp_) {} + Msg::~Msg() {} Msg* Msg::interpretBoeingPacket(const string& m, const string& sender) Modified: TeamTalk/Agents/PrimitiveComm/robot_packet2.h =================================================================== --- TeamTalk/Agents/PrimitiveComm/robot_packet2.h 2006-12-08 18:00:28 UTC (rev 552) +++ TeamTalk/Agents/PrimitiveComm/robot_packet2.h 2006-12-11 03:21:42 UTC (rev 553) @@ -54,6 +54,7 @@ Msg(string sender=string()); //instantiation from Boeing packet Msg(string sender, double tstamp); + Msg(const Msg& m); public: virtual ~Msg(); Modified: TeamTalk/Agents/TeamTalkBackend/TeamTalkBackend.vcproj =================================================================== --- TeamTalk/Agents/TeamTalkBackend/TeamTalkBackend.vcproj 2006-12-08 18:00:28 UTC (rev 552) +++ TeamTalk/Agents/TeamTalkBackend/TeamTalkBackend.vcproj 2006-12-11 03:21:42 UTC (rev 553) @@ -144,7 +144,7 @@ /> > token; if(token == "search") { - Robot *dangerousRobot = robots.findFirst(Robot::DANGEROUS); + Robot *dangerousRobot = robots.findFirst(TeamTalk::Robot::DANGEROUS); if(!dangerousRobot) { warn << "couldn't find a dangerous robot" << endl; continue; } - Robot *safeRobot = robots.findFirst(Robot::SAFE); + Robot *safeRobot = robots.findFirst(TeamTalk::Robot::SAFE); if(!safeRobot) { warn << "couldn't find a safe robot" << endl; continue; @@ -134,7 +134,7 @@ safeRobot->enqueueGoal(trail[i]); safeRobot->enqueueGoal(Goal(trail[i], msg->msg_task.taskid)); } else if(token == "explore") { - Robot *safeRobot = robots.findFirst(Robot::SAFE); + Robot *safeRobot = robots.findFirst(TeamTalk::Robot::SAFE); if(!safeRobot) { warn << "couldn't find a safe robot" << endl; continue; @@ -212,8 +212,8 @@ else if(!strcmp(argv[i], "--peerfile")) peerfile = argv[++i]; else { - //start a robot, put it on the stack - robots.push_back(Robot(argv[i], Robot::SAFE, &tserver, atoi(argv[i]))); + fatal << "main: no robots specified" << endl; + exit(1); } } @@ -238,23 +238,24 @@ string voice; Frobotips >> voice; debug << "voice is " << voice << endl; - Robot::RobotClass robotClass; + TeamTalk::Robot::RobotClass robotClass; if((Frobotips >> robotClass).fail()) error << "couldn't get robot class for " << rname << endl; string::size_type i = rip.find(':'); debug << "bout to add..." << endl; if(i != string::npos) { unsigned short port = atoi(string(rip, i+1, rip.size()-i-1).c_str()); - robots.push_back(Robot(rname, robotClass, &tserver, port)); + robots.push_back(new Robot(TeamTalk::Robot(rname, robotClass, "localhost", port, voice), &tserver)); info << "added " << rname << '@' << port << " class:" << robotClass << endl; } else { - robots.push_back(Robot(rname, robotClass, &tserver)); + robots.push_back(new Robot(TeamTalk::Robot(rname, robotClass, "localhost", voice), &tserver)); info << "added " << rname << " class:" << robotClass << endl; } ignoreToEndOfLine(Frobotips); } } - if(robots.empty()) robots.push_back(Robot(name, Robot::SAFE, &tserver)); + if(robots.empty()) + robots.push_back(new Robot(TeamTalk::Robot(name, TeamTalk::Robot::SAFE, "localhost", ""), &tserver)); Boeing::MapServer *mserver; if(need_mapserver) { @@ -271,7 +272,7 @@ HANDLE* handles = new HANDLE[robots.size()]; int i=0; for(Robots::const_iterator iter = robots.begin(); iter != robots.end(); i++, iter++) { - handles[i] = iter->getSimulationHandle(); + handles[i] = (*iter)->getSimulationHandle(); } WaitForMultipleObjects((DWORD) robots.size(), handles, true, INFINITE); return 0; Modified: TeamTalk/Agents/TeamTalkBackend/backendstub/robot.cpp =================================================================== --- TeamTalk/Agents/TeamTalkBackend/backendstub/robot.cpp 2006-12-08 18:00:28 UTC (rev 552) +++ TeamTalk/Agents/TeamTalkBackend/backendstub/robot.cpp 2006-12-11 03:21:42 UTC (rev 553) @@ -181,22 +181,19 @@ _endthread(); } -Robot::Robot(const string& name, RobotClass robotClass, - Boeing::TraderServer* tserver, unsigned short port) -: followee(NULL), action(WAITING), name_(name), robotClass_(robotClass), -tserver_(tserver) { +Robot::Robot(const TeamTalk::Robot& robot, Boeing::TraderServer* tserver) +: followee(NULL), action(WAITING), robot_(robot), tserver_(tserver) +{ InitializeCriticalSection(&CriticalSection); if(!image) readImage("pic.jpg"); server_ = new Boeing::RobotServer(); - if(port) server_->open(port); - else server_->open(); + server_->open(robot.port); simulationThread_ = (HANDLE)_beginthread(simulate, 0, (void *) this); } -Robot::Robot(const Robot& x) +Robot::Robot(const ::Robot& x) : pose(x.pose), action(x.action), followee(x.followee), goal(x.goal), -goals(x.goals), name_(x.name_), robotClass_(x.robotClass_), tserver_(x.tserver_), -server_(x.server_) +goals(x.goals), robot_(x.robot_), tserver_(x.tserver_), server_(x.server_) { InitializeCriticalSection(&CriticalSection); simulationThread_ = (HANDLE)_beginthread(simulate, 0, (void *) this); @@ -300,34 +297,11 @@ tserver_ = tserver; } -string Robot::getName() const {return name_;} +string Robot::getName() const {return robot_.name;} -Robot::RobotClass Robot::getClass() const {return robotClass_;} +TeamTalk::Robot::RobotClass Robot::getClass() const {return robot_.robotClass;} const Pose& Robot::getPose() const {return pose;} const Point& Robot::getLocation() const {return pose.loc;} float Robot::getYaw() const {return pose.yaw;} -istream& operator>>(istream& in, Robot::RobotClass& robotClass) { - string s; - if((in >> s).fail()) return in; - if(s == "safe" || s == "SAFE") robotClass = Robot::SAFE; - else if(s == "dangerous" || s == "DANGEROUS") robotClass = Robot::DANGEROUS; - else in.setf(ios::failbit); - return in; -} - -ostream& operator<<(ostream& out, const Robot::RobotClass& robotClass) { - switch(robotClass) { - case Robot::SAFE: - out << "safe"; - break; - case Robot::DANGEROUS: - out << "dangerous"; - break; - default: - error << "unknown robot class: " << (int)robotClass << endl; - out << (int)robotClass; - } - return out; -} Modified: TeamTalk/Agents/TeamTalkBackend/backendstub/robot.h =================================================================== --- TeamTalk/Agents/TeamTalkBackend/backendstub/robot.h 2006-12-08 18:00:28 UTC (rev 552) +++ TeamTalk/Agents/TeamTalkBackend/backendstub/robot.h 2006-12-11 03:21:42 UTC (rev 553) @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -35,9 +36,6 @@ }; class Robot { -public: - enum RobotClass {SAFE, DANGEROUS}; - protected: //current orientation and state Pose pose; @@ -53,8 +51,7 @@ queue goals; //queue of goals //robot characteristics - string name_; - RobotClass robotClass_; + TeamTalk::Robot robot_; //parameters common to all robots static const float velocity; //bots have const velocity when moving @@ -78,8 +75,7 @@ static void simulate_wander(void *thisp); public: - Robot(const string& name, RobotClass robotClass, Boeing::TraderServer* tserver, - unsigned short port=0); + Robot(const TeamTalk::Robot& robot, Boeing::TraderServer* tserver); Robot(const Robot& robot); ~Robot(); void callback(const Msg* msgp, const sockaddr* st_remote); @@ -94,13 +90,10 @@ //getters string getName() const; - RobotClass getClass() const; + TeamTalk::Robot::RobotClass getClass() const; const Pose& getPose() const; const Point& getLocation() const; float getYaw() const; }; -istream& operator>>(istream& in, Robot::RobotClass& robotClass); -ostream& operator<<(ostream& out, const Robot::RobotClass& robotClass); - #endif \ No newline at end of file Modified: TeamTalk/Agents/TeamTalkBackend/backendstub/robots.cpp =================================================================== --- TeamTalk/Agents/TeamTalkBackend/backendstub/robots.cpp 2006-12-08 18:00:28 UTC (rev 552) +++ TeamTalk/Agents/TeamTalkBackend/backendstub/robots.cpp 2006-12-11 03:21:42 UTC (rev 553) @@ -2,12 +2,12 @@ using namespace std; -Robots::Robots() : vector() {} +Robots::Robots() : list() {} const Robot* Robots::find(const string& name) const { for(const_iterator i = begin(); i != end(); i++) { - if(i->getName() == name) return &*i; + if((*i)->getName() == name) return *i; } return NULL; } @@ -15,32 +15,32 @@ Robot* Robots::find(const string& name) { for(iterator i = begin(); i != end(); i++) { - if(i->getName() == name) return &*i; + if((*i)->getName() == name) return *i; } return NULL; } -Robots Robots::find(Robot::RobotClass robotClass) const +Robots Robots::find(TeamTalk::Robot::RobotClass robotClass) const { Robots classRobots; for(const_iterator i = begin(); i != end(); i++) { - if(i->getClass() == robotClass) classRobots.push_back(*i); + if((*i)->getClass() == robotClass) classRobots.push_back(*i); } return classRobots; } -const Robot* Robots::findFirst(Robot::RobotClass robotClass) const +const Robot* Robots::findFirst(TeamTalk::Robot::RobotClass robotClass) const { for(const_iterator i = begin(); i != end(); i++) { - if(i->getClass() == robotClass) return &*i; + if((*i)->getClass() == robotClass) return *i; } return NULL; } -Robot* Robots::findFirst(Robot::RobotClass robotClass) +Robot* Robots::findFirst(TeamTalk::Robot::RobotClass robotClass) { for(iterator i = begin(); i != end(); i++) { - if(i->getClass() == robotClass) return &*i; + if((*i)->getClass() == robotClass) return *i; } return NULL; } Modified: TeamTalk/Agents/TeamTalkBackend/backendstub/robots.h =================================================================== --- TeamTalk/Agents/TeamTalkBackend/backendstub/robots.h 2006-12-08 18:00:28 UTC (rev 552) +++ TeamTalk/Agents/TeamTalkBackend/backendstub/robots.h 2006-12-11 03:21:42 UTC (rev 553) @@ -7,17 +7,19 @@ #include "robot.h" +#include + using namespace std; -class Robots : public vector { +class Robots : public list { public: Robots(); const Robot* find(const string& name) const; Robot* find(const string& name); - Robots find(Robot::RobotClass robotClass) const; - const Robot* findFirst(Robot::RobotClass robotClass) const; - Robot* findFirst(Robot::RobotClass robotClass); + Robots find(TeamTalk::Robot::RobotClass robotClass) const; + const Robot* findFirst(TeamTalk::Robot::RobotClass robotClass) const; + Robot* findFirst(TeamTalk::Robot::RobotClass robotClass); }; #endif \ No newline at end of file Modified: TeamTalk/Agents/TeamTalkBackend/robot-galaxy_adapter.cpp =================================================================== --- TeamTalk/Agents/TeamTalkBackend/robot-galaxy_adapter.cpp 2006-12-08 18:00:28 UTC (rev 552) +++ TeamTalk/Agents/TeamTalkBackend/robot-galaxy_adapter.cpp 2006-12-11 03:21:42 UTC (rev 553) @@ -38,7 +38,7 @@ Frobotips >> voice >> safeness; ignoreToEndOfLine(Frobotips); info << "adding robot@" << rip << ':' << port << ' ' << voice << ' ' << safeness << endl; - if(!r_client->addRobot(rname, rip, voice, safeness, port)) { + if(!r_client->addRobot(rname, rip, voice, safeness, port, this)) { error << "couldn't add " << rname << endl; } } @@ -154,10 +154,9 @@ { GalaxyRobots* me = (GalaxyRobots*)p; Boeing::MapClient* m_client = me->m_client; - for(;;) { + for(int t=0;;) { const Boeing::MsgMapClient* msg = m_client->getNextMessage(); if(!msg) { - debug << "msgmapclient is null" << endl; Sleep(1000); continue; } @@ -189,37 +188,16 @@ } } -void GalaxyRobots::trackbots(void *p) +void GalaxyRobots::trackmap(void *thisp) { - GalaxyRobots* me = (GalaxyRobots*)p; - TeamTalk::RobotsClient* r_client = me->r_client; + GalaxyRobots* me = (GalaxyRobots*)thisp; Boeing::MapClient* m_client = me->m_client; - debug << "starting trackbots thread" << endl; + debug << "starting trackmap thread" << endl; for(int t=0; true; t++) { Sleep(1000); - for(TeamTalk::RobotsClient::iterator i = r_client->begin(); - i != r_client->end(); i++) { - debug << "sending location request" << endl; - if(!i->sendReqLocation()) { - //maybe we're not connected anymore, try to connect - warn << "we appear to be disconnected...trying to reconnect" << endl; - if(i->reopen()) { - warn << "ok, reconnected to " - << i->getHost() << ':' << i->getPort() << endl; - i->sendReqLocation(); - } else { - warn << "couldn't reconnect to " - << i->getHost() << ':' << i->getPort() << endl; - } - } - } if(!(t%3)) { //send map keepalive every 3 seconds m_client->sendKeepAlive(0); } - if(!(t%40) && !r_client->empty()) { //send image request every 40 seconds - r_client->begin()->sendReqImage(); - //p_client->find("FESTO")->sendReqImage(); - } } } @@ -247,50 +225,42 @@ { skeleton_comm_ = NULL; - { - static char* *const OAS = {NULL}; - int i; - //if (!GalUtil_OACheckUsage(argc, argv, OAS, &i)) exit(1); - } - iTraderTaskId = rand(); - debug << "about to get the p_client" << endl; - try { + debug << "about to get the p_client" << endl; + try { //startup trader client t_client = new Boeing::TraderClient(); - if(!t_client->isConnected()) { - fatal << "optraderserver not found" << endl; - } else { - debug << "connected to trader" << endl; - } //startup map client - m_client = new Boeing::MapClient(); + m_client = new Boeing::MapClient(); //startup robot client TeamTalk::RobotClient::spawnback = &Agent::spawnMinorGalaxy; - r_client = new TeamTalk::RobotsClient("tester", this); + r_client = new TeamTalk::RobotsClient("tester"); processPeerfile("peerfile.txt"); - if(!testLastConfig("peerfile.txt", + if(!testLastConfig("peerfile.txt", "..\\..\\Resources\\DecoderConfig\\LanguageModel\\zap2LM.arpa")) - addRobotNamesToGrammar(); - if(!m_client->isConnected()) { - fatal << "mapserver not found" << endl; + addRobotNamesToGrammar(); + if(!m_client->isConnected()) { + fatal << "mapserver not found" << endl; } else if(!m_client->sendSubscribe(0)) { - fatal << "couldn't send subscribe message to map server" << endl; - } - - //start listening threads - _beginthread(traderlistener, 0, (void*) this); - _beginthread(maplistener, 0, (void*) this); - - //start thread to track bots - _beginthread(trackbots, 0, (void*) this); + fatal << "couldn't send subscribe message to map server" << endl; + } else { + _beginthread(maplistener, 0, (void*) this); + _beginthread(trackmap, 0, (void*) this); + } + if(!t_client->isConnected()) { + fatal << "optraderserver not found" << endl; + } else { + debug << "connected to trader" << endl; + //start listening threads + _beginthread(traderlistener, 0, (void*) this); + } } catch(exception e) { - fatal << "couldn't start GalaxyRobots: " << e.what() << ": " << endl; + fatal << "couldn't start GalaxyRobots: " << e.what() << ": " << endl; throw e; - } + } } GalaxyRobots::~GalaxyRobots() { Modified: TeamTalk/Agents/TeamTalkBackend/robot-galaxy_adapter.h =================================================================== --- TeamTalk/Agents/TeamTalkBackend/robot-galaxy_adapter.h 2006-12-08 18:00:28 UTC (rev 552) +++ TeamTalk/Agents/TeamTalkBackend/robot-galaxy_adapter.h 2006-12-11 03:21:42 UTC (rev 553) @@ -21,9 +21,9 @@ //static bool testLastConfig(const string& source, const string& target); - static void traderlistener(void *p); - static void maplistener(void *p); - static void trackbots(void *p); + static void traderlistener(void *thisp); + static void maplistener(void *thisp); + static void trackmap(void *thisp); public: GalaxyRobots(Gal_Server *s, int argc, char **argv); Modified: TeamTalk/Agents/boeingLib/boeing/boeing_map_client.cc =================================================================== --- TeamTalk/Agents/boeingLib/boeing/boeing_map_client.cc 2006-12-08 18:00:28 UTC (rev 552) +++ TeamTalk/Agents/boeingLib/boeing/boeing_map_client.cc 2006-12-11 03:21:42 UTC (rev 553) @@ -151,7 +151,7 @@ debug("Got message rv %i, type %x len %u\n",rv, rxdata.hdr.type,rxdata.hdr.len); - if (rv!=rxdata.hdr.len) { + if (rv>0 && rv!=rxdata.hdr.len) { printf("WARNING: size mismatch! %i, but packet says %i\n", rv,rxdata.hdr.len); } else { Modified: TeamTalk/Agents/boeingLib/boeing/boeing_map_server.cc =================================================================== --- TeamTalk/Agents/boeingLib/boeing/boeing_map_server.cc 2006-12-08 18:00:28 UTC (rev 552) +++ TeamTalk/Agents/boeingLib/boeing/boeing_map_server.cc 2006-12-11 03:21:42 UTC (rev 553) @@ -76,7 +76,7 @@ int rv = sock->recv(rxdata.buff,sizeof(rxdata)); //printf("mapserver got %d bytes\n", rv); - if (rv!=rxdata.hdr.len) { + if (rv>0 && rv!=rxdata.hdr.len) { printf("WARNING: size mismatch! %i, but packet says %i\n", rv,rxdata.hdr.len); } Modified: TeamTalk/Agents/boeingLib/boeing/boeing_robot_client.cc =================================================================== --- TeamTalk/Agents/boeingLib/boeing/boeing_robot_client.cc 2006-12-08 18:00:28 UTC (rev 552) +++ TeamTalk/Agents/boeingLib/boeing/boeing_robot_client.cc 2006-12-11 03:21:42 UTC (rev 553) @@ -274,7 +274,7 @@ const MsgRobot* RobotClient::getNextMessage() { // read your socket if there is something available - // process it + // process it *NON-BLOCKING* if (!isConnected()) { printf("WARNING: Not connected\n"); @@ -292,7 +292,7 @@ printf("MEssage was too long!!! Playing it safe and ignoring it\n"); return NULL; } - if (rv!=rxdata.hdr.len) { + if (rv>0 && rv!=rxdata.hdr.len) { printf("WARNING: size mismatch! %i, but packet says %i\n", rv,rxdata.hdr.len); } Modified: TeamTalk/Agents/boeingLib/boeing/boeing_trader_client.cc =================================================================== --- TeamTalk/Agents/boeingLib/boeing/boeing_trader_client.cc 2006-12-08 18:00:28 UTC (rev 552) +++ TeamTalk/Agents/boeingLib/boeing/boeing_trader_client.cc 2006-12-11 03:21:42 UTC (rev 553) @@ -134,7 +134,7 @@ debug("Got message rv %i, type %x len %u\n",rv, rxdata.hdr.type,rxdata.hdr.len); - if (rv!=rxdata.hdr.len) { + if (rv>0 && rv!=rxdata.hdr.len) { printf("WARNING: size mismatch! %i, but packet says %i\n", rv,rxdata.hdr.len); } Modified: TeamTalk/Agents/boeingLib/boeing/boeing_trader_server.cc =================================================================== --- TeamTalk/Agents/boeingLib/boeing/boeing_trader_server.cc 2006-12-08 18:00:28 UTC (rev 552) +++ TeamTalk/Agents/boeingLib/boeing/boeing_trader_server.cc 2006-12-11 03:21:42 UTC (rev 553) @@ -76,7 +76,7 @@ int rv = sock->recv(rxdata.buff,sizeof(rxdata)); //printf("traderserver got %d bytes\n", rv); - if (rv!=rxdata.hdr.len) { + if (rv > 0 && rv!=rxdata.hdr.len) { printf("WARNING: size mismatch! %i, but packet says %i\n", rv,rxdata.hdr.len); } From tk at edam.speech.cs.cmu.edu Sun Dec 10 22:25:22 2006 From: tk at edam.speech.cs.cmu.edu (tk@edam.speech.cs.cmu.edu) Date: Sun, 10 Dec 2006 22:25:22 -0500 Subject: [TeamTalk 17]: [554] TeamTalk/Configurations/DesktopConfiguration/startlist-desktop.config : Added working directory information into the Pythia configuration. Message-ID: <200612110325.kBB3PM1W004266@edam.speech.cs.cmu.edu> An HTML attachment was scrubbed... URL: http://mailman.srv.cs.cmu.edu/pipermail/teamtalk-developers/attachments/20061210/5635cdd3/attachment.html -------------- next part -------------- Modified: TeamTalk/Configurations/DesktopConfiguration/startlist-desktop.config =================================================================== --- TeamTalk/Configurations/DesktopConfiguration/startlist-desktop.config 2006-12-11 03:21:42 UTC (rev 553) +++ TeamTalk/Configurations/DesktopConfiguration/startlist-desktop.config 2006-12-11 03:25:21 UTC (rev 554) @@ -1,5 +1,8 @@ +NUM_DIVISIONS: 2 + EXPAND: $MITRE_ROOT $GC_HOME\contrib\MITRE EXPAND: $TEAMTALK ..\.. +EXPAND: $CONFIGURATION $TEAMTALK\Configuration\DesktopConfiguration EXPAND: $AGENTS $TEAMTALK\Agents EXPAND: $PENDECODER $AGENTS\PenDecoder EXPAND: $BIN $TEAMTALK\Bin\x86-nt @@ -7,23 +10,24 @@ EXPAND: $RESOURCES $TEAMTALK\Resources EXPAND: $GRAMMAR $RESOURCES\Grammar EXPAND: $DECODER $RESOURCES\DecoderConfig -EXPAND: $GALAXY ..\..\ExternalLibraries\Galaxy\bin\x86-nt EXPAND: $JAVAEXE java EXPAND: $PERL perl TITLE: TeamTalk -PROCESS: $JAVAEXE -classpath $PENDECODER/bsh-core-2.0b4.jar;$PENDECODER/bsh-util-2.0b4.jar;$PENDECODER/jiu.jar;$PENDECODER/dist/PenDecoder.jar;$MITRE_ROOT/bindings/java/lib/galaxy.jar edu.cmu.ravenclaw.pendecoder.PenDecoderServer -port 11002 -peerfile peerfile.txt +PROCESS: $JAVAEXE -classpath bsh-core-2.0b4.jar;bsh-util-2.0b4.jar;jiu.jar;dist/PenDecoder.jar;$MITRE_ROOT/bindings/java/lib/galaxy.jar edu.cmu.ravenclaw.pendecoder.PenDecoderServer -port 11002 -peerfile $CONFIGURATION\peerfile.txt +PROCESS_WORKDIR: $PENDECODER PROCESS_TITLE: PenDecoder PROCESS: $BIN\KalliopeSwift.exe -maxconns 6 -config swift.cfg PROCESS_TITLE: Kalliope -PROCESS: $BIN\TeamTalkBackend.exe -verbosity 1 -maxconns 6 +PROCESS: $BIN\TeamTalkBackend-DEBUG.exe -verbosity 1 -maxconns 6 PROCESS_TITLE: TeamTalkBackend -PROCESS: $PERL -I$NLG_ROOT/../Rosetta $NLG_ROOT/bin/TeamTalk +PROCESS: $PERL -I../Rosetta bin/TeamTalk +PROCESS_WORKDIR: $NLG PROCESS_TITLE: Rosetta PROCESS: $BIN\NlgServer2.exe -maxconns 6 -nlghost localhost @@ -35,8 +39,9 @@ PROCESS: $BIN\Audio_Server-DEBUG.exe -maxconns 6 -sps 16000 -engine_list sphinx_engines.txt PROCESS_TITLE: Audio_Server -PROCESS: $BIN\Sphinx_Engine -name male -argfn $DECODER\male-16khz.arg -port 9990 +PROCESS: $BIN\Sphinx_Engine -name male -argfn male-16khz.arg -port 9990 +PROCESS_WORKDIR: $DECODER PROCESS_TITLE: Sphinx_Male -PROCESS: $GALAXY\HUB.exe -verbosity 3 -pgm_file TeamTalk-hub-desktop-skeleton.pgm +PROCESS: $GC_HOME\bin\x86-nt\HUB.exe -verbosity 3 -pgm_file TeamTalk-hub-desktop-skeleton.pgm PROCESS_TITLE: Hub From tk at edam.speech.cs.cmu.edu Sun Dec 10 22:46:03 2006 From: tk at edam.speech.cs.cmu.edu (tk@edam.speech.cs.cmu.edu) Date: Sun, 10 Dec 2006 22:46:03 -0500 Subject: [TeamTalk 18]: [555] TeamTalk/Agents: Adding the TeamTalkSimulator, a high-fidelity robot simulator that uses MOAST. Message-ID: <200612110346.kBB3k38I004284@edam.speech.cs.cmu.edu> An HTML attachment was scrubbed... URL: http://mailman.srv.cs.cmu.edu/pipermail/teamtalk-developers/attachments/20061210/b712de04/attachment-0001.html -------------- next part -------------- Added: TeamTalk/Agents/TeamTalkSimulator/Makefile =================================================================== --- TeamTalk/Agents/TeamTalkSimulator/Makefile (rev 0) +++ TeamTalk/Agents/TeamTalkSimulator/Makefile 2006-12-11 03:46:02 UTC (rev 555) @@ -0,0 +1,43 @@ +MOASTLIB_DIR = /net/eucalyptus/usr0/tkharris/moast-1.2 +RCSLIB_DIR = /net/eucalyptus/usr0/tkharris/lib/rcslib +BOEINGLIB_DIR = ../boeingLib +PRIMITIVECOMM_DIR = ../PrimitiveComm + +DEFS = -DDEFAULT_NML_FILE=\"$(MOASTLIB_DIR)/etc/moast.nml\" \ + -DDEFAULT_INI_FILE=\"$(MOASTLIB_DIR)/etc/moast.nml\" +INCLUDES = -I. -I$(MOASTLIB_DIR)/include -I$(RCSLIB_DIR)/include \ + -I$(PRIMITIVECOMM_DIR) -I$(BOEINGLIB_DIR)/boeing +LDFLAGS = -L$(MOASTLIB_DIR)/lib -L$(RCSLIB_DIR)/lib +LDLIBS = -lmoast -lrcs -lposemath -lm #-lwsock32 + +CPPFLAGS = $(DEFS) $(INCLUDES) +CXXFLAGS = -g -Wall -O0 +CXXCOMPILE = $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) +CXXLINK = $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ + +OBJECTS = TeamTalkSimulator.o robot.o imageClient.o \ + $(PRIMITIVECOMM_DIR)/libboeingrobotserver.a + +EXECUTABLES = TeamTalkSimulator + +all: $(EXECUTABLES) + +TeamTalkSimulator: primitivecomm $(OBJECTS) + @rm -f TeamTalkSimulatedBot + $(CXXLINK) $(OBJECTS) $(LDLIBS) + +primitivecomm: + $(MAKE) -C $(PRIMITIVECOMM_DIR) + +TeamTalkSimulator.o: TeamTalkSimulator.cc robot.h imageClient.h $(PRIMITIVECOMM_DIR)/utils.h + $(CXXCOMPILE) -o $@ $< + +robot.o: robot.cc robot.h imageClient.h $(PRIMITIVECOMM_DIR)/utils.h + $(CXXCOMPILE) -o $@ $< + +imageClient.o: imageClient.cc imageClient.h $(PRIMITIVECOMM_DIR)/utils.h + $(CXXCOMPILE) -o $@ $< + +clean: + $(MAKE) -C $(PRIMITIVECOMM_DIR) clean + rm -f *.o $(EXECUTABLES) Property changes on: TeamTalk/Agents/TeamTalkSimulator/Makefile ___________________________________________________________________ Name: svn:executable + Added: TeamTalk/Agents/TeamTalkSimulator/TeamTalkSimulator.cc =================================================================== --- TeamTalk/Agents/TeamTalkSimulator/TeamTalkSimulator.cc (rev 0) +++ TeamTalk/Agents/TeamTalkSimulator/TeamTalkSimulator.cc 2006-12-11 03:46:02 UTC (rev 555) @@ -0,0 +1,414 @@ +/** TeamTalkSimulatedBot + * Author: TK Harris + * + * Simulated Boeing robots in the usarsim environment. + * + * Created: 2006/9/11 + **/ + +#include +#include +#include //for initial map kludge + +#include +#include +#include + +using namespace std; + +#define DEBUG 1 + +#include "robot.h" +#include +#include +#include +#include + +#include +#include "moastTypes.hh" // MOAST_NML_BUFFER_NAME_LEN +#include "moastNmlOffsets.hh" // NAV_DATA_BASE, etc. +#include "sectMobPL.hh" // secMobPL_format() + +static RCS_CMD_CHANNEL *sectMobPLCmdBuf = NULL; +static RCS_STAT_CHANNEL *sectMobPLStatBuf = NULL; +static RCS_CMD_CHANNEL *sectMobPLCfgBuf = NULL; +static RCS_STAT_CHANNEL *sectMobPLSetBuf = NULL; +static SectMobPLStat *sectMobPLStatPtr; +static SectMobPLSet *sectMobPLSetPtr; + +map robots; + +#define MOAST_DIR "/net/eucalyptus/usr0/tkharris/moast-1.2/" +#define MOAST_BIN "/net/eucalyptus/usr0/tkharris/moast-1.2/bin" +#ifndef DEFAULT_NML_FILE +#define DEFAULT_NML_FILE "/net/eucalyptus/usr0/tkharris/moast-1.2/etc/moast.nml" +#endif +#ifndef DEFAULT_INI_FILE +#define DEFAULT_INI_FILE "/net/eucalyptus/usr0/tkharris/moast-1.2/etc/moast.ini" +#endif + +#define THIS_PROCESS "sectShell" + +char nml_file_default[] = DEFAULT_NML_FILE; +char *nml_file_env; +char *NML_FILE = NULL; +char ini_file_default[] = DEFAULT_INI_FILE; +char *ini_file_env; +char *INI_FILE = NULL; +int bufnum = 1; + +/****************** MAP STUFF *********************/ + +static unsigned char* conveyedMap; +static unsigned char* currentMap; +static unsigned char* diffMap; +static int mapWidth, mapHeight; +static int mapXOffset, mapYOffset; + + +void readMapFile() { + //we're going to do this a lot, so just open once + +} + +void sendFullMap(Boeing::MapServer *m) { + readMapFile(); + Boeing::MsgMap::MsgMapFactory(Boeing::MAP_RLE, + msgMap, mapData, mapWidth*mapHeight, + 0, 0, mapWidth, mapHeight); + cerr << "raw: " << msgMap->map[0] + << " rl: " << ((msgMap->map[0]&0xFFFFFF00)>>8) + << " rv: " << (msgMap->map[0]&0x000000FF) << endl; + mserver->sendFullMap(msgMap); +} + +void sendDiffMap(Boeing::MapServer *m) { + readMapFile(); + Boeing::MsgMap::MsgMapFactory(Boeing::MAP_RLE, + msgMap, diff_map, + 0, 0, mapWidth, mapHeight); + cerr << "raw: " << msgMap->map[0] + << " rl: " << ((msgMap->map[0]&0xFFFFFF00)>>8) + << " rv: " << (msgMap->map[0]&0x000000FF) << endl; + mserver->sendDiffMap(msgMap); +} + +void* readMapRequests(void *m) { + bool subscribed = false; + int updatePeriod = 1; + + Boeing::MapServer *mserver = (Boeing::MapServer *) m; + for(;;) { + const Boeing::MsgMapServer *msg = mserver->getNextMessage(); + if(msg) { + switch(msg->hdr.type) { + case Boeing::MAP_SUBSCRIBE: + sendFullMap(m); + subscribed = true; + break; + case Boeing::MAP_KEEPALIVE: + break; + case Boeing::MAP_ACK: + break; + case Boeing::MAP_UNSUBSCRIBE: + subscribed = false; + break; + default: + cerr << "unknown or unhandled msgtype: " << msg->hdr.type << endl; + } + } else { + if(subscribed) sendDiffMap(m); + sleep(updatePeriod); + } + } +} + +/*************************** END MAP STUFF ****************************/ + +void* readTrades(void *t) { + Boeing::TraderServer *tserver = (Boeing::TraderServer *) t; + for(;;) { + const Boeing::MsgTraderServer *msg = tserver->getNextMessage(); + if(!msg) { + //cerr << "getNextMessage is NULL" << endl; + sleep(1000); + continue; + } + + sectMobPLStatBuf->read(); + sectMobPLSetBuf->read(); + + if(msg->hdr.type != Boeing::TRADER_TASK) { + cerr << "don't know what to do with header type " << msg->hdr.type << endl; + continue; + } + cerr << "got: " << msg->msg_task.task << endl; + istringstream task(msg->msg_task.task); + string token; + task >> token; + if(token != "search") { + cerr << "don't know how to deal with command " << token << endl; + continue; + } + float x, y; + while(task >> x) { + if(!(task >> y)) break; + for(map::iterator i = robots.begin(); i != robots.end(); i++) { + if(i->first == "bashful") i->second->setFollow("clyde"); + else if(i->first == "clyde") i->second->stackGoal(x, y); + } + } + } +} + +void readMapData() { + ifstream f("stubdb.txt"); + f >> mapWidth >> mapHeight; + mapData = new unsigned char[mapWidth*mapHeight]; + for(int j=0; j> n; + mapData[j*mapWidth+i] = (unsigned char)n; + } + } +} + +static int NmlSvrPid = 0; +static int SectMobPLPid = 0; +static void sigint_handler(int sig) { + for(map::const_iterator i=robots.begin(); i!=robots.end(); i++) { + delete i->second; //deleting the robot kills the asociated moast procs + } + if(SectMobPLPid) kill(SectMobPLPid, SIGINT); + if(NmlSvrPid) kill(NmlSvrPid, SIGINT); + signal(SIGINT, SIG_DFL); //reset sigint handler + kill(getpid(), SIGINT); //kill yourself +} + +static int cleanupSectMobPLNmlBuffers(void) +{ + if (NULL != sectMobPLCmdBuf) + delete sectMobPLCmdBuf; + if (NULL != sectMobPLStatBuf) + delete sectMobPLStatBuf; + if (NULL != sectMobPLSetBuf) + delete sectMobPLSetBuf; + if (NULL != sectMobPLCfgBuf) + delete sectMobPLCfgBuf; + + sectMobPLStatBuf = NULL; + sectMobPLSetBuf = NULL; + sectMobPLCmdBuf = NULL; + sectMobPLCfgBuf = NULL; + + return 0; +} + +static void mapDump() { + sectMobPLStatBuf->read(); + sectMobPLSetBuf->read(); + + SectMobPLCfgDumpWM dump = SectMobPLCfgDumpWM(); + dump.turnOn = 1; + dump.serial_number = sectMobPLSetPtr->echo_serial_number + 1; + dump.skip = 5; + dump.dumpContinuous = true; + strcpy(dump.fileName, "/tmp/SectMobPLDispOutput.ppm"); + sectMobPLCfgBuf->write(&dump); +} + +static int initSectMobPLNmlBuffers(char *config_file, int bufnum) { + cleanupSectMobPLNmlBuffers(); + + { + ostringstream chanName; + chanName << SECT_MOB_PL_CMD_NAME << bufnum; + sectMobPLCmdBuf = + new RCS_CMD_CHANNEL(sectMobPL_format, chanName.str().c_str(), + THIS_PROCESS, config_file); + if (!sectMobPLCmdBuf->valid()) { + delete sectMobPLCmdBuf; + sectMobPLCmdBuf = 0; + return 1; + } + } + + { + ostringstream chanName; + chanName << SECT_MOB_PL_STAT_NAME << bufnum; + sectMobPLStatBuf = + new RCS_STAT_CHANNEL(sectMobPL_format, chanName.str().c_str(), + THIS_PROCESS, config_file); + if (!sectMobPLStatBuf->valid()) { + delete sectMobPLStatBuf; + sectMobPLStatBuf = 0; + return 1; + } + } + + { + ostringstream chanName; + chanName << SECT_MOB_PL_CFG_NAME << bufnum; + sectMobPLCfgBuf = + new RCS_CMD_CHANNEL(sectMobPL_format, chanName.str().c_str(), + THIS_PROCESS, config_file); + if (!sectMobPLCfgBuf->valid()) { + delete sectMobPLCfgBuf; + sectMobPLCfgBuf = 0; + return 1; + } + } + + { + ostringstream chanName; + chanName << SECT_MOB_PL_CMD_NAME << bufnum; + sectMobPLSetBuf = + new RCS_STAT_CHANNEL(sectMobPL_format, chanName.str().c_str(), + THIS_PROCESS, config_file); + if (!sectMobPLSetBuf->valid()) { + delete sectMobPLSetBuf; + sectMobPLSetBuf = 0; + return 1; + } + } + + return 0; +} + +int initSectionControl() { + if (NULL == NML_FILE) { + nml_file_env = getenv("CONFIG_NML"); + if (NULL != nml_file_env) { + NML_FILE = nml_file_env; + } else { + NML_FILE = nml_file_default; + } + } + + // ditto for the .ini file + if (NULL == INI_FILE) { + ini_file_env = getenv("CONFIG_INI"); + if (NULL != ini_file_env) { + INI_FILE = ini_file_env; + } else { + INI_FILE = ini_file_default; + } + } + + // initial allocate all the buffers + int retval = initSectMobPLNmlBuffers(NML_FILE, bufnum); + + if (retval) { + cerr << "TeamTalkSimulator: Can't allocate NML buffers" << endl; + return 1; + } + + // set up our convenient pointer to status and settings + sectMobPLStatPtr = (SectMobPLStat *) sectMobPLStatBuf->get_address(); + sectMobPLSetPtr = (SectMobPLSet *) sectMobPLSetBuf->get_address(); + + sectMobPLStatBuf->read(); + sectMobPLSetBuf->read(); + + // set up init command + SectMobPLCmdInit sectInit = SectMobPLCmdInit(); + sectInit.serial_number = sectMobPLStatPtr->echo_serial_number + 1; + sectInit.vehList_length = robots.size(); + for(int i=0; iwrite(§Init); + + return 0; +} + +int main(int argc, char *argv[]) +{ + //register sigint handler + signal(SIGINT, sigint_handler); + + //clear ipc and start the moast nml server + spawn(true, MOAST_BIN, "ipc-clear"); + NmlSvrPid = spawn(false, MOAST_BIN, "moastNmlSvr"); + sleep(3); + SectMobPLPid = spawn(false, MOAST_BIN, "sectMobPL"); + + string name = "tester"; + string peerfile; + for(int i=1; i> rname) { + if(rname.at(0) == '#') { + ignoreToEndOfLine(Frobotips); + continue; + } + toupper(rname); + if(rname == "MAPSERVER" || rname == "OPTRADER") { + ignoreToEndOfLine(Frobotips); + continue; + } + string rip; + Frobotips >> rip; + string::size_type i = rip.find(':'); + if(i != string::npos) { + unsigned short port = atoi(string(rip, i+1, rip.size()-i-1).c_str()); + robots[rname] = new Robot(&robots, rname, robot_count++, port); + cerr << "added " << rname << '@' << port << endl; + } else { + robots[rname] = new Robot(&robots, rname, robot_count++); + cerr << "added " << rname << endl; + } + ignoreToEndOfLine(Frobotips); + } + } + if(robots.empty()) robots[name] = new Robot(&robots, name, 1); + + //initialize section control + initSectionControl(); + //start dumping map + mapDump(); + + //start the trader + Boeing::TraderServer tserver; + tserver.open(); + //handle trading messages + pthread_t tradeThread_; + pthread_create(&tradeThread_, NULL, readTrades, (void *) &tserver); + + readMapData(); + //start the map server + Boeing::MapServer mserver; + mserver.open(); + //handle trading messages + pthread_t mapThread_; + pthread_create(&mapThread_, NULL, readMapRequests, (void *) &mserver); + + //wait for all of the threads to terminate + cerr << "wait for thread termination...\n" << endl; + pthread_join(tradeThread_, NULL); + pthread_join(mapThread_, NULL); + //should probably also be waiting for robot server handles here + return 0; + +} Property changes on: TeamTalk/Agents/TeamTalkSimulator/TeamTalkSimulator.cc ___________________________________________________________________ Name: svn:executable + Added: TeamTalk/Agents/TeamTalkSimulator/imageClient.cc =================================================================== --- TeamTalk/Agents/TeamTalkSimulator/imageClient.cc (rev 0) +++ TeamTalk/Agents/TeamTalkSimulator/imageClient.cc 2006-12-11 03:46:02 UTC (rev 555) @@ -0,0 +1,139 @@ +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include "imageClient.h" + +using namespace std; + +ImageClient::ImageClient(const string& host, unsigned short port) + : sockfd(0), image_(NULL), image_size_(0) +{ + struct sockaddr_in serv_addr; + struct hostent *hostptr; + + if(!(hostptr = gethostbyname(host.c_str()))) { + cerr << "socket error: cannot find host " << host << endl; + return; + } + + memset((char *) &serv_addr, 0, sizeof(serv_addr)); + serv_addr.sin_family = AF_INET; + memcpy((char *) &serv_addr.sin_addr, + hostptr->h_addr_list[0], + hostptr->h_length); + serv_addr.sin_port = htons(port); + + if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { + perror("socket"); + return; + } + + if (connect(sockfd, (struct sockaddr*) &serv_addr, sizeof(serv_addr)) < 0) { + perror("connect"); + return; + } + + //getImage_(); +} + +ImageClient::ImageClient(const string& host, unsigned short port, + int* image_size, const unsigned char*& image) + : sockfd(0), image_(NULL), image_size_(0) +{ + struct sockaddr_in serv_addr; + struct hostent *hostptr; + + if(!(hostptr = gethostbyname(host.c_str()))) { + cerr << "socket error: cannot find host " << host << endl; + return; + } + + memset((char *) &serv_addr, 0, sizeof(serv_addr)); + serv_addr.sin_family = AF_INET; + memcpy((char *) &serv_addr.sin_addr, + hostptr->h_addr_list[0], + hostptr->h_length); + serv_addr.sin_port = htons(port); + + if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { + perror("socket"); + return; + } + + //cerr << "about to connect" << endl; + if (connect(sockfd, (struct sockaddr*) &serv_addr, sizeof(serv_addr)) < 0) { + perror("connect"); + return; + } + //cerr << "connected" << endl; + + //if((*image_size = getImage_()) > 0) image = image_; +} + +ImageClient::~ImageClient() { + delete image_; + close(sockfd); +} + +int ImageClient::getImage_() { + char iType; + if(!readn(&iType)) { + cerr << "problem getting image type" << endl; + return -1; + } + //cerr << "Imgage Type is " << (int)iType << endl; + if((int)iType < 1 || (int)iType > 5) { + cerr << "can't deal with image of type " << (int)iType << endl; + return -1; + } + char iName[16]; + if(!readn(&iName)) { + cerr << "problem reading image name" << endl; + return -1; + } + //cerr << "image name is " << iName << endl; + if(!readn(&image_size_)) { + cerr << "problem getting image type" << endl; + return -1; + } + image_size_ = ntohl(image_size_); + //cerr << "image size is " << image_size_ << endl; + if(image_size_ <= 0) { + cerr << "bad image size: " << image_size_ << endl; + return -1; + } + + if(image_ == NULL) { + image_ = (unsigned char*)malloc(max_image_size_ = image_size_); + } + else if(image_size_ > max_image_size_) { + image_ = (unsigned char*)realloc(image_, max_image_size_ = image_size_); + } + if(!readn(image_, image_size_)) { + cerr << "problem getting image" << endl; + return -1; + } + return image_size_; +} + +int ImageClient::getImage(const unsigned char*& imagePtr) { + char ack[] = {'O', 'k', '\n', '\r'}; + //cerr << "sending" << endl; + send(sockfd, ack, 4, 0); + + if(getImage_() <= 0) { + cerr << "cannot get image" << endl; + return -1; + } + imagePtr = image_; + return image_size_; +} + Property changes on: TeamTalk/Agents/TeamTalkSimulator/imageClient.cc ___________________________________________________________________ Name: svn:executable + Added: TeamTalk/Agents/TeamTalkSimulator/imageClient.h =================================================================== --- TeamTalk/Agents/TeamTalkSimulator/imageClient.h (rev 0) +++ TeamTalk/Agents/TeamTalkSimulator/imageClient.h 2006-12-11 03:46:02 UTC (rev 555) @@ -0,0 +1,41 @@ +#ifndef IMAGE_CLIENT_H +#define IMAGE_CLIENT_H + +#include + +#include + +class ImageClient { + protected: + int sockfd; + unsigned char* image_; + int image_size_; + int max_image_size_; + + template bool readn(C* datum, int n=1) const { + if(n <= 0) return true; + int s = n*sizeof(C); + int i = 0; + int rv; + do { + i += rv = recv(sockfd, ((char*)datum)+i, s-i, 0); + //cerr << "read: " << rv << " bytes" << endl; + if(rv < 0) { + perror("recv"); + return false; + } + } while(i +//#include + +#include +#include +#include + +#include + +#define DEBUG 1 +#include "robot.h" + +#include + +#define MOAST_DIR "/net/eucalyptus/usr0/tkharris/moast-1.2" +#define MOAST_BIN "/net/eucalyptus/usr0/tkharris/moast-1.2/bin" +#ifndef DEFAULT_NML_FILE +#define DEFAULT_NML_FILE "/net/eucalyptus/usr0/tkharris/moast-1.2/etc/moast.nml" +#endif +#ifndef DEFAULT_INI_FILE +#define DEFAULT_INI_FILE "/net/eucalyptus/usr0/tkharris/moast-1.2/etc/moast.ini" +#endif + +#define THIS_PROCESS "vehShell" + +using namespace std; + +#ifndef PI +const double PI(4.0 * atan2(1.0, 1.0)); +#endif + +const unsigned int shift = 6; +const unsigned int mask = ~0U << (sizeof(unsigned int)*8 - shift); + +int Robot::cleanupVehMobPLNmlBuffers(void) +{ + if (NULL != vehMobPLCmdBuf) + delete vehMobPLCmdBuf; + if (NULL != vehMobPLStatBuf) + delete vehMobPLStatBuf; + if (NULL != vehMobPLSetBuf) + delete vehMobPLSetBuf; + if (NULL != vehMobPLCfgBuf) + delete vehMobPLCfgBuf; + + vehMobPLStatBuf = NULL; + vehMobPLSetBuf = NULL; + vehMobPLCmdBuf = NULL; + vehMobPLCfgBuf = NULL; + + return 0; +} + +int Robot::initVehMobPLNmlBuffers(char *config_file, int bufnum) +{ + print_debugln("cleaning up nmlbuffers"); + cleanupVehMobPLNmlBuffers(); + + { + ostringstream chanName; + chanName << VEH_MOB_PL_CMD_NAME << bufnum; + vehMobPLCmdBuf = + new RCS_CMD_CHANNEL(vehMobPL_format, chanName.str().c_str(), + THIS_PROCESS, config_file); + } + if (!vehMobPLCmdBuf->valid()) { + delete vehMobPLCmdBuf; + vehMobPLCmdBuf = 0; + return 1; + } + + { + ostringstream chanName; + chanName << PRIM_MOB_JA_CMD_NAME << bufnum; + primMobJACmdBuf = + new RCS_CMD_CHANNEL(primMobJA_format, chanName.str().c_str(), + THIS_PROCESS, config_file); + } + if (!primMobJACmdBuf->valid()) { + delete primMobJACmdBuf; + primMobJACmdBuf = 0; + return 1; + } + + { + ostringstream chanName; + chanName << VEH_MOB_PL_STAT_NAME << bufnum; + vehMobPLStatBuf = + new RCS_STAT_CHANNEL(vehMobPL_format, chanName.str().c_str(), + THIS_PROCESS, config_file); + } + if (!vehMobPLStatBuf->valid()) { + delete vehMobPLStatBuf; + vehMobPLStatBuf = 0; + return 1; + } + + { + ostringstream chanName; + chanName << PRIM_MOB_JA_STAT_NAME << bufnum; + primMobJAStatBuf = + new RCS_STAT_CHANNEL(primMobJA_format, chanName.str().c_str(), + THIS_PROCESS, config_file); + } + if (!primMobJAStatBuf->valid()) { + delete primMobJAStatBuf; + primMobJAStatBuf = 0; + return 1; + } + + { + ostringstream chanName; + chanName << VEH_MOB_PL_CFG_NAME << bufnum; + vehMobPLCfgBuf = + new RCS_CMD_CHANNEL(vehMobPL_format, chanName.str().c_str(), + THIS_PROCESS, config_file); + } + if (!vehMobPLCfgBuf->valid()) { + delete vehMobPLCfgBuf; + vehMobPLCfgBuf = 0; + return 1; + } + + { + ostringstream chanName; + chanName << VEH_MOB_PL_SET_NAME << bufnum; + vehMobPLSetBuf = + new RCS_STAT_CHANNEL(vehMobPL_format, chanName.str().c_str(), + THIS_PROCESS, config_file); + } + if (!vehMobPLSetBuf->valid()) { + delete vehMobPLSetBuf; + vehMobPLSetBuf = 0; + return 1; + } + + return 0; +} + +template static inline char* rcs_stat_to_string(const C& s) { + switch(s) { + case RCS_DONE: return "RCS_DONE"; + case RCS_EXEC: return "RCS_EXEC"; + case RCS_ERROR: return "RCS_ERROR"; + case UNINITIALIZED_STATUS: return "UNINITIALIZED_STATUS"; + } + return "?"; +} + +ostream& operator<<(ostream& out, const PM_CARTESIAN& tran) { + return out << "[x=" << tran.x << " y=" << tran.y << " z=" << tran.z << ']'; +} + +ostream& operator<<(ostream& out, const PM_ROTATION_MATRIX& rot) { + PM_RPY rpy(rot); + return out << "[r=" << rpy.r << " p=" << rpy.p << " y=" << rpy.y << ']'; +} + +ostream& operator<<(ostream& out, const PM_HOMOGENEOUS& pose) { + return out << "[tran=" << pose.tran << " rot=" << pose.rot << ']'; +} + +ostream& Robot::printStat(ostream& out) const { + return out << "command_type: " + << vehMobPL_symbol_lookup(statP->command_type) << endl + << "echo_serial_number: " << statP->echo_serial_number << endl + << "prim serial number: " << primStatP->echo_serial_number << endl + << "status: " + << rcs_stat_to_string(statP->status) << endl + << "state: " << statP->state << endl + << "line: " << statP->line << endl + << "source_line: " << statP->source_line << endl + << "source_file: " << statP->source_file << endl + << "heartbeat: " << statP->heartbeat << endl + << "set cycleTime: " << setP->cycleTime << endl + << "actual cycleTime: " << statP->cycleTime << endl + << "plan cost: " << statP->planCost << endl + << "debug: " << setP->debug << endl + << "pose: " << statP->pose << endl + << "message: " << statP->message << endl; +} + +/* +void readImage(const char* file) { + ifstream i(file, ios::in|ios::binary|ios::ate); + if(!i.is_open()) { + cerr << "file: " << file << " not found" << endl; + return; + } + image_size = i.tellg(); + char *memblock = new char[image_size]; + i.seekg(0, ios::beg); + i.read(memblock, image_size); + image = (unsigned char*) memblock; +} +*/ + +float mod(const float& a, const float& b) { + int whole_divisions = (int)(a/b); + return a - whole_divisions*b; +} + +static float canonical_angle(const float& f) { + float retval = mod(f,(2*(float)PI)); + return retval<0? retval+2*(float)PI: retval; +} + +unsigned int Hash (string const& s) +{ + unsigned int result = 0; + for (unsigned int i = 0; s [i] != 0; ++i) + result = (result & mask) ^ (result << shift) ^ s [i]; + return result; +} + +float Robot::turn(float goal_r, float r) { + float diff = mod((goal_r-r), (2*(float)PI)); + if(diff > PI) return diff-2*(float)PI; + if(diff < -PI) return diff+2*(float)PI; + return diff; +} + +void* Robot::simulate(void *thisp) { + Robot* me = (Robot*) thisp; + + sleep(5); + + me->vehMobPLStatBuf->read(); + me->vehMobPLSetBuf->read(); + me->primMobJAStatBuf->read(); + + print_debugln("command initialization"); + VehMobPLCmdInit init = VehMobPLCmdInit(); + init.serial_number = me->statP->echo_serial_number+1; + me->vehMobPLCmdBuf->write(&init); + //i think primMobJA is initted by vehMobPL + + sleep(5); + me->vehMobPLStatBuf->read(); + me->vehMobPLSetBuf->read(); + me->primMobJAStatBuf->read(); + + me->printStat(cerr); + /* + print_debugln("try to get image"); + const unsigned char* image; + int image_size; + ImageClient *ic = new ImageClient("192.168.1.100", + (unsigned short)5003, &image_size, image); + cerr << "got some kind of image, size: " << image_size << endl; + */ + /* + sleep(5); + + me->vehMobPLStatBuf->read(); + me->vehMobPLSetBuf->read(); + + me->printStat(cerr); + print_debugln("try to move"); + VehMobPLCmdMoveWaypoint move = VehMobPLCmdMoveWaypoint(); + move.p.x = 4; + move.p.y = 0; + move.serial_number = me->statP->echo_serial_number+1; + move.isGlobal = false; + move.neighborhood = 1; + move.startTime = 0; + me->vehMobPLCmdBuf->write(&move); + + sleep(5); + me->vehMobPLStatBuf->read(); + me->vehMobPLSetBuf->read(); + me->printStat(cerr); + */ + + //start dumping the pic + //VehMobPLCfgDumpWM dump = VehMobPLCfgDumpWM(); + //dump.serial_number = me->setP->echo_serial_number + 1; + //dump.skip = 5; + //dump.dumpContinuous = true; + //strcpy(dump.fileName, "../../Agents/PenDecoder/VehMobPLDispOutput.ppm"); + //strcpy(dump.fileName, "/tmp/VehMobPLDispOutput.ppm"); + //me->vehMobPLCfgBuf->write(&dump); + + print_debugln("entering for loop"); + //EnterCriticalSection(&me->CriticalSection); + for(int i;;i++) { + //LeaveCriticalSection(&me->CriticalSection); + do { + const Boeing::MsgCmd *bmsg; + //if(me->server_->isConnected()) print_debug('.'); + while(me->server_->isConnected() && + (bmsg = me->server_->getNextMessage())) { + Msg* msg = Msg::interpret(bmsg->buff); + //if(!dynamic_cast(msg)) { + // print_debug("got message: "); print_debugln(msg->render()); + //} + me->callback(msg, NULL); + } + sleep(updatePeriod); + //} while(!TryEnterCriticalSection(&me->CriticalSection)); + } while(true); + /* + if(me->action == SHUTDOWN) break; + if(me->action == PAUSED) continue; + if(me->action == WAITING) { + if(me->goals.empty()) continue; + me->setGoal(me->goals.top().first, me->goals.top().second); + } + if(me->action == GO_TO_GOAL || me->action == FOLLOWING) { + //goal is revisited each step when following + if(me->action == FOLLOWING) { + map::const_iterator i = me->robots->find(me->followee); + if(i == me->robots->end()) throw exception(); + me->goal_x = i->second->x; + me->goal_y = i->second->y; + } + + //calculate difference between cur_pos and goal + float x_vec = me->goal_x-me->x; + float y_vec = me->goal_y-me->y; + float distance_to_goal = sqrt(x_vec*x_vec+y_vec*y_vec); + if(distance_to_goal <= personal_space) { + if(me->action == GO_TO_GOAL) { + me->action = WAITING; + cerr << "done" << endl; + } + continue; + } + //are we facing the right direction to translate? + float mini_goal_r = canonical_angle(atan2(y_vec, x_vec)); + float r_vec = turn(mini_goal_r, me->r); + if(r_vec) { + //turn to face the right direction + float period_turn = updatePeriod*max_r_velocity; + if(abs(r_vec) <= period_turn) me->r = mini_goal_r; + else if(r_vec > 0) { + me->r = canonical_angle(me->r + period_turn); + continue; + } else { + me->r = canonical_angle(me->r - period_turn); + continue; + } + } + //move at speed + float period_movement = updatePeriod*velocity; + me->x += cos(mini_goal_r)*period_movement; + me->y += sin(mini_goal_r)*period_movement; + } else if(me->action == GO_TO_ANGLE) { + float r_vec = turn(me->goal_r, me->r); + float period_turn = updatePeriod*max_r_velocity; + if(abs(r_vec) <= period_turn) { + me->r = me->goal_r; + cerr << "done turning" << endl; + me->action = WAITING; + } else if(r_vec > 0) me->r = canonical_angle(me->r + period_turn); + else me->r = canonical_angle(me->r - period_turn); + } + */ + } +} + +float Robot::getX() const {return statP->pose.tran.x;} +float Robot::getY() const {return statP->pose.tran.y;} +float Robot::getYaw() const {return PM_RPY(statP->pose.rot).y;} + +Robot::Robot(const map *robs, + string name, int simulator_index, unsigned int port) + : action(WAITING), sim_index(simulator_index), robots(robs), + imageClient(NULL), vehMobPLCmdBuf(NULL), vehMobPLStatBuf(NULL), + vehMobPLCfgBuf(NULL), vehMobPLSetBuf(NULL) +{ + //InitializeCriticalSection(&CriticalSection); + sim_init(); + char nml_file_default[] = DEFAULT_NML_FILE; + char *nml_file_env; + char *NML_FILE = NULL; + char ini_file_default[] = DEFAULT_INI_FILE; + char *ini_file_env; + char *INI_FILE = NULL; + + // get the config file name from arg, if provided, next environment, + // if there, else default + if (NULL == NML_FILE) { + nml_file_env = getenv("CONFIG_NML"); + if (NULL != nml_file_env) { + NML_FILE = nml_file_env; + } else { + NML_FILE = nml_file_default; + } + } + + // ditto for the .ini file + if (NULL == INI_FILE) { + ini_file_env = getenv("CONFIG_INI"); + if (NULL != ini_file_env) { + INI_FILE = ini_file_env; + } else { + INI_FILE = ini_file_default; + } + } + + // initial allocate all the buffers + print_debugln("initial allocation of the buffers"); + if(initVehMobPLNmlBuffers(NML_FILE, sim_index)) { + cerr << "can't allocate NML buffers" << endl; + } + + // set up our convenient pointer to status and settings + print_debugln("set up convenient pointers"); + statP = (VehMobPLStat *) vehMobPLStatBuf->get_address(); + primStatP = (PrimMobJAStat *) primMobJAStatBuf->get_address(); + setP = (VehMobPLSet *) vehMobPLSetBuf->get_address(); + + print_debugln("new robotserver"); + server_ = new Boeing::RobotServer(); + print_debugln("opening port"); + if (port) server_->open(port); + else server_->open(); + print_debugln("starting reading thread"); + pthread_t simulation_thread; + pthread_create(&simulation_thread, NULL, simulate, (void *)this); + print_debugln("done with robot constructor"); +} + +Robot::~Robot() { + cleanupVehMobPLNmlBuffers(); + for(vector::const_iterator i=pids.begin(); i!=pids.end(); i++) { + cerr << "killing " << *i << endl; + kill(*i, SIGQUIT); + } + delete server_; +} + +void Robot::callback(const Msg* msgp, const sockaddr* st_remote) { + //print_debugln("got a message"); + vehMobPLStatBuf->read(); + vehMobPLSetBuf->read(); + primMobJAStatBuf->read(); + + Msg* temp_message; + if(const MsgCmdActionPP* action = dynamic_cast(msgp)) { + //print_debugln("got an action"); + //need to translate txt-based message into typed message + temp_message = Msg::interpretPlayAction(*action->content()); + } else { + temp_message = msgp->clone(); + } + if(const MsgMapReqPP* req_image = dynamic_cast(temp_message)) { + //print_debugln("got an req image"); + //get the jpeg from the usarsim video socket + const unsigned char* image; + int image_size = 0; + if(imageClient == NULL) { + imageClient = new ImageClient("sylvester.speech.cs.cmu.edu", + (unsigned short)5333); + } + //print_debugln("getting the image"); + image_size = imageClient->getImage(image); + //print_debugln("got the image"); + + if(image_size > 0) { + //send the image to the robot client + server_->sendJPEGImage(image, image_size, 320, 240, req_image->getInvoice()); + } else { + cerr << "Image size is 0" << endl; + } + delete temp_message; + //print_debugln("done with req image"); + return; + } + if(dynamic_cast(temp_message)) { + //print_debugln("got an req location"); + server_->sendLocation(getX(), -getY(), canonical_angle(-getYaw()), true); + delete temp_message; + return; + } + //EnterCriticalSection(&CriticalSection); + if(const MsgCmdGoToRelativePP* goto_relative = dynamic_cast(temp_message)) { + cout << "got: " << *goto_relative << endl; + float m_x = goto_relative->content()->x; + float m_y = -goto_relative->content()->y; + float dir = getYaw()+atan2(m_y, m_x); + float len = sqrt(m_x*m_x+m_y*m_y); + VehMobPLCmdMoveWaypoint move = VehMobPLCmdMoveWaypoint(); + move.p.x = getX()+cos(dir)*len; + move.p.y = getY()+sin(dir)*len; + //cerr << "m_x: " << m_x << " m_y: " << m_y << " yaw: " << getYaw() + // << " curdir: " << atan2(m_y, m_x) << " dir: " << dir + // << " len: " << len << " c_x: " << getX() << " c_y: " << getY() + // << " movex: " << move.p.x << " movey: " << move.p.y << endl; + move.serial_number = statP->echo_serial_number+1; + move.isGlobal = true; + move.neighborhood = 1; + move.startTime = 0; + vehMobPLCmdBuf->write(&move); + delete temp_message; + return; + } else if(const MsgCmdHaltPP* halt = dynamic_cast(temp_message)) { + cout << "got: " << *halt << endl; + action = WAITING; + delete temp_message; + return; + } else if(const MsgCmdGoToGlobalPP* goto_global = dynamic_cast(temp_message)) { + cout << "got: " << *goto_global << endl; + //setGoal(goto_global->content()->x, goto_global->content()->y); + VehMobPLCmdMoveWaypoint move = VehMobPLCmdMoveWaypoint(); + move.p.x = goto_global->content()->x; + move.p.y = -goto_global->content()->y; + move.serial_number = statP->echo_serial_number+1; + move.isGlobal = true; + move.neighborhood = 1; + move.startTime = 0; + vehMobPLCmdBuf->write(&move); + delete temp_message; + return; + } else if(const MsgCmdTurnRelativePP* turn = dynamic_cast(temp_message)) { + cout << "got: " << *turn << endl; + PrimMobJACmdRotate rotate = PrimMobJACmdRotate(); + float r = -getYaw(); + rotate.theta = canonical_angle(-(r+turn->content()->angle)); + rotate.thetaTol = PI/20; //9 degrees tolerance + // always make it a new command + rotate.serial_number = primStatP->echo_serial_number + 1; + primMobJACmdBuf->write(&rotate); + //goal_r = canonical_angle(r+turn->content()->angle); + //action = GO_TO_ANGLE; //will report done when complete + delete temp_message; + return; + } else if(const MsgCmdHomePP* home = dynamic_cast(temp_message)) { + cout << "got: " << *home << endl; + VehMobPLCmdMoveWaypoint move = VehMobPLCmdMoveWaypoint(); + move.p.x = 0; + move.p.y = 0; + move.serial_number = statP->echo_serial_number+1; + move.isGlobal = true; + move.neighborhood = 1; + move.startTime = 0; + vehMobPLCmdBuf->write(&move); + delete temp_message; + return; + } else if(const MsgCmdPausePP* pause = dynamic_cast(temp_message)) { + cout << "got: " << *pause << endl; + if(action != PAUSED) { + paused_action = action; + action = PAUSED; + } + } else if(const MsgCmdResumePP* resume = dynamic_cast(temp_message)) { + cout << "got: " << *resume << endl; + if(action == PAUSED) { + action = paused_action; + } + } else if(const MsgCmdFollowPP* follow = dynamic_cast(temp_message)) { + cout << "got: " << *follow << endl; + //setFollow(follow->content()->leader); + } + //LeaveCriticalSection(&CriticalSection); + delete temp_message; +} + +/** + * Startup the moast porcesses that this robot requires + */ +void Robot::sim_init() { + vector args; + { + ostringstream arg; + arg << "-i" << sim_index; + args.push_back(arg.str()); + } + if(sim_index != 1) { + ostringstream arg; + arg << "-s" << sim_index; + args.push_back(arg.str()); + } + //args.push_back("-v"); + spawn(false, MOAST_BIN, "usarSim", args); + sleep(60); + + args.clear(); + { + ostringstream arg; + arg << "-d" << sim_index; + args.push_back(arg.str()); + } + if(sim_index==1) sleep(2); + pids.push_back(spawn(false, MOAST_BIN, "primMobMain", args)); + pids.push_back(spawn(false, MOAST_BIN, "primSPMain", args)); + if(sim_index==1) pids.push_back(spawn(false, MOAST_BIN, "primMisMain", args)); + sleep(2); + pids.push_back(spawn(false, MOAST_BIN, "amMobMain", args)); + + args.clear(); + args.push_back("-z.1"); + { + ostringstream arg; + arg << "-d" << sim_index; + args.push_back(arg.str()); + } + pids.push_back(spawn(false, MOAST_BIN, "amSPMain", args)); + + args.clear(); + args.push_back("-i"); + args.push_back("-g3"); + args.push_back("-r.2"); + { + ostringstream arg; + arg << "-d" << sim_index; + args.push_back(arg.str()); + } + pids.push_back(spawn(false, MOAST_BIN, "vehMobPLMain", args)); + sleep(6); +} + +//HANDLE Robot::getSimulationHandle() const {return simulationThread_;} + +//void Robot::wait() const {WaitForSingleObject(simulationThread_, INFINITE);} + +//some actual actions +void Robot::setGoal(float x, float y) { + //goal_x = x; + //goal_y = y; + //action = GO_TO_GOAL; +} + +void Robot::stackGoal(float x, float y) { + //goals.push(pair(x, y)); +} + +void Robot::setFollow(const string& rname) { + followee = rname; + action = FOLLOWING; //follow is never complete +} Property changes on: TeamTalk/Agents/TeamTalkSimulator/robot.cc ___________________________________________________________________ Name: svn:executable + Added: TeamTalk/Agents/TeamTalkSimulator/robot.h =================================================================== --- TeamTalk/Agents/TeamTalkSimulator/robot.h (rev 0) +++ TeamTalk/Agents/TeamTalkSimulator/robot.h 2006-12-11 03:46:02 UTC (rev 555) @@ -0,0 +1,78 @@ +#ifndef ROBOT_H +#define ROBOT_H + +#include +#include + +#include +#include + +#include +#include // MOAST_NML_BUFFER_NAME_LEN +#include // NAV_DATA_BASE, etc. +#include // vehMobPL_format() +#include // primMobJA_format() + +#include "imageClient.h" + +using namespace std; + +//class Robot : public CallBackClass { +class Robot { +protected: + //CRITICAL_SECTION CriticalSection; + typedef enum {WAITING=0, ACTING, PAUSED, FOLLOWING, SHUTDOWN} action_t; + action_t action, paused_action; + int sim_index; + string followee; + const map *robots; + vector pids; //keep pids for later destruction + + //HANDLE simulationThread_; + Boeing::RobotServer *server_; + ImageClient *imageClient; + + static float turn(float goal_r, float r); + + //moast/rcs structures + RCS_CMD_CHANNEL *vehMobPLCmdBuf; + RCS_STAT_CHANNEL *vehMobPLStatBuf; + RCS_CMD_CHANNEL *primMobJACmdBuf; + RCS_STAT_CHANNEL *primMobJAStatBuf; + RCS_CMD_CHANNEL *vehMobPLCfgBuf; + RCS_STAT_CHANNEL *vehMobPLSetBuf; + VehMobPLStat *statP; + VehMobPLSet *setP; + PrimMobJAStat *primStatP; + + int cleanupVehMobPLNmlBuffers(); + int initVehMobPLNmlBuffers(char *config, int bufnum); + static const int updatePeriod = 1; + static void* simulate(void *thisp); + + //these are protected because the mechanism requires synchrnization + //with an nml buffer read + float getX() const; //current X-coord in globalpos frame in meters + float getY() const; //current Y-ccord in globalpos frame in meters + float getYaw() const; //current yaw in globalpos frame in radians + + public: + Robot(const map* robots, + string name, int simulator_index, unsigned int port=0); + ~Robot(); + void callback(const Msg* msgp, const sockaddr* st_remote); + //HANDLE getSimulationHandle() const; + //void wait() const; + void sim_init(); + + //getters + Boeing::RobotServer *getServer(); + ostream& printStat(ostream& out) const; + + //some actual commands + void setGoal(float x, float y); + void stackGoal(float x, float y); + void setFollow(const string& rname); +}; + +#endif Property changes on: TeamTalk/Agents/TeamTalkSimulator/robot.h ___________________________________________________________________ Name: svn:executable + Added: TeamTalk/Agents/TeamTalkSimulator/runSimulator.sh =================================================================== --- TeamTalk/Agents/TeamTalkSimulator/runSimulator.sh (rev 0) +++ TeamTalk/Agents/TeamTalkSimulator/runSimulator.sh 2006-12-11 03:46:02 UTC (rev 555) @@ -0,0 +1,130 @@ +#!/bin/bash + +echo "This job was submitted by user: $PBS_O_LOGNAME" +echo "This job was submitted to host: $PBS_O_HOST" +echo "This job was submitted to queue: $PBS_O_QUEUE" +echo "PBS working directory: $PBS_O_WORKDIR" +echo "PBS job id: $PBS_JOBID" +echo "PBS job name: $PBS_JOBNAME" +echo "PBS environment: $PBS_ENVIRONMENT" +echo " " +echo "This script is running on `hostname` " + +export CONFIG_NML=/net/eucalyptus/usr0/tkharris/moast-1.2/etc/moast.nml +export CONFIG_INI=/net/eucalyptus/usr0/tkharris/moast-1.2/etc/moast.ini +./TeamTalkSimulator --peerfile peerfile.txt --mapserver + +# cd ../../../moast-1.2/bin +# HOME=/net/eucalyptus/usr0/tkharris +# MOAST=$HOME/moast-1.2 +# export RCSLIB_DIR=$HOME/lib/rcslib + +# echo `dirname $0`/.. + +# #set SECT=yes to run section, VEH, AM, prim, and servo, else SECT=no +# SECT=no + +# # if SECT=no, set VEH=yes to run vehicle, AM, prim, and servo, else VEH=no +# VEH=yes + +# # if VEH=no, set AM=yes to run AM, prim, and servo, else AM=no +# AM=yes + +# # if AM=no, set PRIM=yes to run prim, and servo, else PRIM=no +# PRIM=yes + +# # set USARSIM=yes to run usarSim, else USARSIM=no to run simpleSim +# USARSIM=yes + +# CONFIG_NML=$MOAST/etc/moast.nml ; export CONFIG_NML +# CONFIG_INI=$MOAST/etc/moast.ini ; export CONFIG_INI + +# TOP=servoShell +# if [ x$PRIM = xyes ] ; then TOP=primShell ; fi +# if [ x$AM = xyes ] ; then PRIM=yes; TOP=amShell ; fi +# if [ x$VEH = xyes ] ; then AM=yes; PRIM=yes; TOP=vehShell ; fi +# if [ x$SECT = xyes ] ; then VEH=yes; AM=yes; PRIM=yes; TOP=sectShell ; fi +# pid1=0 +# pid2=0 +# pid3=0 +# pid4=0 +# pid5=0 +# pid6=0 +# pid7=0 +# pid8=0 +# pid9=0 + +# kill1=9 +# kill2=9 +# kill3=9 +# kill4=9 +# kill5=9 +# kill6=INT +# kill7=9 +# kill8=9 +# kill9=9 + +# ./ipc-clear + +# #./splash $CONFIG_INI & + +# echo "Starting server..." +# ./moastNmlSvr & +# sleep 2 +# pid1=$! + +# if [ x$USARSIM = xyes ] ; then +# echo "Starting usarsim..." +# ./usarSim -i1 & +# sleep 30 +# kill2=HUP +# else +# ./simpleSim & +# fi +# pid2=$! + +# if [ x$PRIM = xyes ] ; then +# echo "Starting prim..." +# sleep 2 +# ./primMobMain & +# pid3=$! +# ./primSPMain & +# pid4=$! +# ./primMisMain & +# pid5=$! +# fi + +# if [ x$AM = xyes ] ; then +# echo "Starting am..." +# ./amMobMain & +# pid6=$! +# ./amSPMain -z.1& +# pid7=$! +# fi + +# if [ x$VEH = xyes ] ; then +# echo "Starting vehicle..." +# ./vehMobPLMain -i -g3 -r.2& +# pid8=$! +# fi + +# if [ x$SECT = xyes ] ; then +# echo "Starting section..." +# ./sectMobPL & +# pid9=$! +# fi + +# #./$TOP +# sleep 60 + +# if [ ! $pid9 = 0 ] ; then kill -$kill9 $pid9 ; fi +# if [ ! $pid8 = 0 ] ; then kill -$kill8 $pid8 ; fi +# if [ ! $pid7 = 0 ] ; then kill -$kill7 $pid7 ; fi +# if [ ! $pid6 = 0 ] ; then kill -$kill6 $pid6 ; fi +# if [ ! $pid5 = 0 ] ; then kill -$kill5 $pid5 ; fi +# if [ ! $pid4 = 0 ] ; then kill -$kill4 $pid4 ; fi +# if [ ! $pid3 = 0 ] ; then kill -$kill3 $pid3 ; fi +# if [ ! $pid2 = 0 ] ; then kill -$kill2 $pid2 ; fi +# if [ ! $pid1 = 0 ] ; then kill -$kill1 $pid1 ; fi + +# exit 0 Property changes on: TeamTalk/Agents/TeamTalkSimulator/runSimulator.sh ___________________________________________________________________ Name: svn:executable + From tk at edam.speech.cs.cmu.edu Mon Dec 11 03:01:47 2006 From: tk at edam.speech.cs.cmu.edu (tk@edam.speech.cs.cmu.edu) Date: Mon, 11 Dec 2006 03:01:47 -0500 Subject: [TeamTalk 19]: [556] TeamTalk/Agents/PrimitiveComm: Fixed gcc/linux compilation issues. Message-ID: <200612110801.kBB81l5V004743@edam.speech.cs.cmu.edu> An HTML attachment was scrubbed... URL: http://mailman.srv.cs.cmu.edu/pipermail/teamtalk-developers/attachments/20061211/d1e0a00f/attachment.html -------------- next part -------------- Modified: TeamTalk/Agents/PrimitiveComm/geometry.h =================================================================== --- TeamTalk/Agents/PrimitiveComm/geometry.h 2006-12-11 03:46:02 UTC (rev 555) +++ TeamTalk/Agents/PrimitiveComm/geometry.h 2006-12-11 08:01:47 UTC (rev 556) @@ -10,18 +10,18 @@ namespace geometry { template struct Point { - T x, y; - Point() : x(0), y(0) {}; - Point(T X, T Y) : x(X), y(Y) {}; + T x, y; + Point() : x(0), y(0) {}; + Point(T X, T Y) : x(X), y(Y) {}; template static Point Polar(L length, double angle) { return Point((T)(cos(angle)*length), (T)(sin(angle)*length)); } - Point rotate(double rads) { - double r = sqrt(x*x + y*y); - double theta = atan2(y, x); - x = (T) (r*cos(theta+rads)); - y = (T) (r*sin(theta+rads)); - return *this; + Point rotate(double rads) { + double r = sqrt(x*x + y*y); + double theta = atan2(y, x); + x = (T) (r*cos(theta+rads)); + y = (T) (r*sin(theta+rads)); + return *this; } double length() const {return sqrt(x*x+y*y);}; double angle() const {return atan2(y, x);}; @@ -41,6 +41,7 @@ y += rhs.y; return *this; } + bool operator!() {return x != 0 || y != 0;} }; template struct Polygon : public vector< Point > { @@ -49,53 +50,54 @@ Polygon(const Polygon& p) : vector< Point >(p) {}; }; -template struct Quadrilateral : public Polygon { - Quadrilateral() : Polygon(4) {}; - Quadrilateral(const Quadrilateral& q) : Polygon(q) {}; +template struct Quadrilateral : public Polygon +{ + Quadrilateral() : Polygon(4) {}; + Quadrilateral(const Quadrilateral& q) : Polygon(q) {}; Quadrilateral(Point lower_left, Point upper_right) : Polygon(4) { - // axis-aligned quadrilateral - at(0) = Point(lower_left.x, lower_left.y); - at(1) = Point(lower_left.x, upper_right.y); - at(2) = Point(upper_right.x, upper_right.y); - at(3) = Point(upper_right.x, lower_left.y); + // axis-aligned quadrilateral + push_back(Point(lower_left.x, lower_left.y)); + push_back(Point(lower_left.x, upper_right.y)); + push_back(Point(upper_right.x, upper_right.y)); + push_back(Point(upper_right.x, lower_left.y)); }; - Quadrilateral(T x1, T x2, T y1, T y2) : Polygon(4) { - at(0) = Point(MIN(x1, x2), MIN(y1, y2)); - at(1) = Point(MIN(x1, x2), MAX(y1, y2)); - at(2) = Point(MAX(x1, x2), MAX(y1, y2)); - at(3) = Point(MAX(x1, x2), MIN(y1, y2)); + Quadrilateral(T x1, T x2, T y1, T y2) : Polygon(4) { + push_back(Point(MIN(x1, x2), MIN(y1, y2))); + push_back(Point(MIN(x1, x2), MAX(y1, y2))); + push_back(Point(MAX(x1, x2), MAX(y1, y2))); + push_back(Point(MAX(x1, x2), MIN(y1, y2))); }; - Quadrilateral(Point p1, Point p2, Point p3, Point p4): Polygon(4) { - at(0) = p1; at(1) = p2; at(2) = p3; at(3) = p4; + Quadrilateral(Point p1, Point p2, Point p3, Point p4): Polygon(4) { + push_back(p1); push_back(p2); push_back(p3); push_back(p4); }; operator Polygon() const {return *this;} - Point ll() const { - Point retval = at(0); - for(int i=1; i<4; i++) { - if(at(i).x < retval.x || at(i).y < retval.y) retval = at(i); - } - return retval; + Point ll() const { + Point retval = this->at(0); + for(int i=1; i<4; i++) { + if(this->at(i).x < retval.x || this->at(i).y < retval.y) retval = this->at(i); + } + return retval; }; - Point ul() const { - Point retval = at(0); - for(int i=1; i<4; i++) { - if(at(i).x > retval.x || at(i).y < retval.y) retval = at(i); - } - return retval; + Point ul() const { + Point retval = this->at(0); + for(int i=1; i<4; i++) { + if(this->at(i).x > retval.x || this->at(i).y < retval.y) retval = this->at(i); + } + return retval; }; - Point ur() const { - Point retval = at(0); - for(int i=1; i<4; i++) { - if(at(i).x > retval.x || at(i).y > retval.y) retval = at(i); - } - return retval; + Point ur() const { + Point retval = this->at(0); + for(int i=1; i<4; i++) { + if(this->at(i).x > retval.x || this->at(i).y > retval.y) retval = this->at(i); + } + return retval; }; - Point lr() const { - Point retval = at(0); - for(int i=1; i<4; i++) { - if(at(i).x < retval.x || at(i).y > retval.y) retval = at(i); - } - return retval; + Point lr() const { + Point retval = this->at(0); + for(int i=1; i<4; i++) { + if(this->at(i).x < retval.x || this->at(i).y > retval.y) retval = this->at(i); + } + return retval; }; }; Modified: TeamTalk/Agents/PrimitiveComm/robot_class.cpp =================================================================== --- TeamTalk/Agents/PrimitiveComm/robot_class.cpp 2006-12-11 03:46:02 UTC (rev 555) +++ TeamTalk/Agents/PrimitiveComm/robot_class.cpp 2006-12-11 08:01:47 UTC (rev 556) @@ -22,7 +22,7 @@ if((in >> s).fail()) return in; if(s == "safe" || s == "SAFE") robotClass = Robot::SAFE; else if(s == "dangerous" || s == "DANGEROUS") robotClass = Robot::DANGEROUS; - else in.setf(ios::failbit); + else in.setstate(ios_base::failbit); return in; } @@ -39,4 +39,4 @@ out << (int)robotClass; } return out; -} \ No newline at end of file +} Modified: TeamTalk/Agents/PrimitiveComm/robot_class.h =================================================================== --- TeamTalk/Agents/PrimitiveComm/robot_class.h 2006-12-11 03:46:02 UTC (rev 555) +++ TeamTalk/Agents/PrimitiveComm/robot_class.h 2006-12-11 08:01:47 UTC (rev 556) @@ -25,4 +25,4 @@ istream& operator>>(istream& in, TeamTalk::Robot::RobotClass& robotClass); ostream& operator<<(ostream& out, const TeamTalk::Robot::RobotClass& robotClass); -#endif \ No newline at end of file +#endif Modified: TeamTalk/Agents/PrimitiveComm/robot_packet2.cpp =================================================================== --- TeamTalk/Agents/PrimitiveComm/robot_packet2.cpp 2006-12-11 03:46:02 UTC (rev 555) +++ TeamTalk/Agents/PrimitiveComm/robot_packet2.cpp 2006-12-11 08:01:47 UTC (rev 556) @@ -1,6 +1,6 @@ #include "robot_packet2.h" #include "utils.h" -#include "win_netutils.h" +#include "netutils.h" //these are for Msg::stamp #include @@ -536,17 +536,17 @@ //normal instantiation MsgMap::MsgMap(short invoice, int sequence, int width, int height, const string& imageData, MsgMap::Encoding encoding, string sender) -: Msg(sender), invoice_(invoice), sequence_(sequence), width_(width), height_(height), imageData_(imageData.begin(), imageData.end()), encoding_(encoding) {} + : Msg(sender), invoice_(invoice), width_(width), height_(height), sequence_(sequence), encoding_(encoding), imageData_(imageData.begin(), imageData.end()) {} //instatiation from a Boeing packet MsgMap::MsgMap(string sender, double tstamp, short invoice, int sequence, int width, int height, const string& imageData, MsgMap::Encoding encoding) -: Msg(sender, tstamp), invoice_(invoice), sequence_(sequence), width_(width), height_(height), imageData_(imageData.begin(), imageData.end()), encoding_(encoding) {} + : Msg(sender, tstamp), invoice_(invoice), width_(width), height_(height), sequence_(sequence), encoding_(encoding), imageData_(imageData) {} int MsgMap::getWidth() const {return width_;} int MsgMap::getHeight() const {return height_;} short MsgMap::getInvoice() const {return invoice_;} int MsgMap::getSequence() const {return sequence_;} -basic_string MsgMap::getImageData() const {return imageData_;} +string MsgMap::getImageData() const {return imageData_;} size_t MsgMap::getImageDataSize() const {return imageData_.size();} MsgMap::Encoding MsgMap::getEncoding() const {return encoding_;} @@ -581,7 +581,7 @@ break; default: throw MalformedPacketException("MsgMap::renderBoeingPacket()", ""); } - Boeing::MsgMap::MsgMapFactory(e, packet, imageData_.c_str(), (int)imageData_.size(), invoice_, sequence_, width_, height_); + Boeing::MsgMap::MsgMapFactory(e, packet, (const unsigned char*)imageData_.c_str(), (int)imageData_.size(), invoice_, sequence_, width_, height_); string spacket(reinterpret_cast(packet), packet->getSize()); free(packet); return spacket; @@ -591,4 +591,5 @@ ostream& operator<<(ostream& out, const Msg* m) { return out << m->render(); -} \ No newline at end of file +} + Modified: TeamTalk/Agents/PrimitiveComm/robot_packet2.h =================================================================== --- TeamTalk/Agents/PrimitiveComm/robot_packet2.h 2006-12-11 03:46:02 UTC (rev 555) +++ TeamTalk/Agents/PrimitiveComm/robot_packet2.h 2006-12-11 08:01:47 UTC (rev 556) @@ -271,7 +271,7 @@ short invoice_; int width_, height_, sequence_; Encoding encoding_; - basic_string imageData_; + string imageData_; public: //normal instantiation MsgMap(short invoice, int sequence, int width, int height, const string& imageData, Encoding encoding, string sender=string()); @@ -281,7 +281,7 @@ int getHeight() const; short getInvoice() const; int getSequence() const; - basic_string getImageData() const; + string getImageData() const; size_t getImageDataSize() const; Encoding getEncoding() const; string render() const; Modified: TeamTalk/Agents/PrimitiveComm/stdint.h =================================================================== --- TeamTalk/Agents/PrimitiveComm/stdint.h 2006-12-11 03:46:02 UTC (rev 555) +++ TeamTalk/Agents/PrimitiveComm/stdint.h 2006-12-11 08:01:47 UTC (rev 556) @@ -30,7 +30,7 @@ typedef unsigned short uint16_t; typedef int int32_t; typedef unsigned uint32_t; -typedef long long int64_t; +typedef long long int64_t; typedef unsigned long long uint64_t; /* 7.18.1.2 Minimum-width integer types */ Modified: TeamTalk/Agents/PrimitiveComm/udpsocket.cc =================================================================== --- TeamTalk/Agents/PrimitiveComm/udpsocket.cc 2006-12-11 03:46:02 UTC (rev 555) +++ TeamTalk/Agents/PrimitiveComm/udpsocket.cc 2006-12-11 08:01:47 UTC (rev 556) @@ -18,7 +18,6 @@ #include #include -//#include #include #include #include @@ -26,9 +25,13 @@ #include +#ifndef WIN32 +#include +#include +#endif + //#include -//#include #include //#include #include @@ -97,8 +100,8 @@ return timebuffer.time + (float)timebuffer.millitm/1000; #else struct timeval curr; - gettimeofday(&curr, NULL); - return (curr.tv_sec + curr.tv_usec / 1000000.0); + gettimeofday(&curr, NULL); + return (curr.tv_sec + curr.tv_usec / 1000000.0); #endif } @@ -176,7 +179,7 @@ #ifdef WIN32 closesocket(fd); #else - close(fd); + close(fd); #endif return status = NotConnected; } Modified: TeamTalk/Agents/PrimitiveComm/utils.cpp =================================================================== --- TeamTalk/Agents/PrimitiveComm/utils.cpp 2006-12-11 03:46:02 UTC (rev 555) +++ TeamTalk/Agents/PrimitiveComm/utils.cpp 2006-12-11 08:01:47 UTC (rev 556) @@ -1,5 +1,9 @@ #ifdef WIN32 #include +#else +#include +#include +#include #endif #include "utils.h" @@ -7,70 +11,70 @@ //parses an english number from zero to nine hundred ninety nine int GetNumber999(const string& x) { - istringstream issX(x); - int retval = 0; - for(string token; issX >> token;) { - if(token == "ZERO") { - // do nothing - } else if(token == "ONE" || token == "A") { - retval += 1; - } else if(token == "TWO") { - retval += 2; - } else if(token == "THREE") { - retval += 3; - } else if(token == "FOUR") { - retval += 4; - } else if(token == "FIVE") { - retval += 5; - } else if(token == "SIX") { - retval += 6; - } else if(token == "SEVEN") { - retval += 7; - } else if(token == "EIGHT") { - retval += 8; - } else if(token == "NINE") { - retval += 9; - } else if(token == "TEN") { - retval += 10; - } else if(token == "ELEVEN") { - retval += 11; - } else if(token == "TWELVE") { - retval += 12; - } else if(token == "THIRTEEN") { - retval += 13; - } else if(token == "FOURTEEN") { - retval += 14; - } else if(token == "FIFTEEN") { - retval += 15; - } else if(token == "SIXTEEN") { - retval += 16; - } else if(token == "SEVENTEEN") { - retval += 17; - } else if(token == "EIGHTEEN") { - retval += 18; - } else if(token == "NINETEEN") { - retval += 19; - } else if(token == "TWENTY") { - retval += 20; - } else if(token == "THIRTY") { - retval += 30; - } else if(token == "FORTY") { - retval += 40; - } else if(token == "FIFTY") { - retval += 50; - } else if(token == "SIXTY") { - retval += 60; - } else if(token == "SEVENTY") { - retval += 70; - } else if(token == "EIGHTY") { - retval += 80; - } else if(token == "NINETY") { - retval += 90; - } else if(token == "HUNDRED") { - retval *= 100; - } - } - return retval; + istringstream issX(x); + int retval = 0; + for(string token; issX >> token;) { + if(token == "ZERO") { + // do nothing + } else if(token == "ONE" || token == "A") { + retval += 1; + } else if(token == "TWO") { + retval += 2; + } else if(token == "THREE") { + retval += 3; + } else if(token == "FOUR") { + retval += 4; + } else if(token == "FIVE") { + retval += 5; + } else if(token == "SIX") { + retval += 6; + } else if(token == "SEVEN") { + retval += 7; + } else if(token == "EIGHT") { + retval += 8; + } else if(token == "NINE") { + retval += 9; + } else if(token == "TEN") { + retval += 10; + } else if(token == "ELEVEN") { + retval += 11; + } else if(token == "TWELVE") { + retval += 12; + } else if(token == "THIRTEEN") { + retval += 13; + } else if(token == "FOURTEEN") { + retval += 14; + } else if(token == "FIFTEEN") { + retval += 15; + } else if(token == "SIXTEEN") { + retval += 16; + } else if(token == "SEVENTEEN") { + retval += 17; + } else if(token == "EIGHTEEN") { + retval += 18; + } else if(token == "NINETEEN") { + retval += 19; + } else if(token == "TWENTY") { + retval += 20; + } else if(token == "THIRTY") { + retval += 30; + } else if(token == "FORTY") { + retval += 40; + } else if(token == "FIFTY") { + retval += 50; + } else if(token == "SIXTY") { + retval += 60; + } else if(token == "SEVENTY") { + retval += 70; + } else if(token == "EIGHTY") { + retval += 80; + } else if(token == "NINETY") { + retval += 90; + } else if(token == "HUNDRED") { + retval *= 100; + } + } + return retval; } DebugStream::Level DebugStream::threashold_ = DebugStream::F; @@ -82,27 +86,27 @@ DebugStream fatal = DebugStream(DebugStream::F); string& tolower(string& x) { - for(string::iterator i=x.begin(); i!=x.end(); i++) *i = tolower(*i); - return x; + for(string::iterator i=x.begin(); i!=x.end(); i++) *i = tolower(*i); + return x; } string tolower(const string& x) { - string retval(x); - return tolower(retval); + string retval(x); + return tolower(retval); } string& toupper(string& x) { - for(string::iterator i=x.begin(); i!=x.end(); i++) *i = toupper(*i); - return x; + for(string::iterator i=x.begin(); i!=x.end(); i++) *i = toupper(*i); + return x; } string toupper(const string& x) { - string retval(x); - return toupper(retval); + string retval(x); + return toupper(retval); } istream& ignoreToEndOfLine(istream& x) { - return x.ignore(numeric_limits::max(), '\n'); + return x.ignore(numeric_limits::max(), '\n'); } istream& istreamLookFor(istream& in, char c) { @@ -121,20 +125,21 @@ void substitute(string& temp, const string& var, const string& val) { - for(string::size_type j = temp.find(var); j != string::npos; j = temp.find(var)) { - temp.replace(j, var.size(), val); - } + for(string::size_type j = temp.find(var); j != string::npos; j = temp.find(var)) { + temp.replace(j, var.size(), val); + } } void substitute(string& temp, const map& subs) { - for(map::const_iterator i = subs.begin(); i != subs.end(); i++) { - substitute(temp, i->first, i->second); - } + for(map::const_iterator i = subs.begin(); i != subs.end(); i++) { + substitute(temp, i->first, i->second); + } } #ifndef WIN32 -int spawn(string working_dir, string cmd, vector args) { +int spawn(bool wait, const string& working_dir, const string& cmd, vector args) +{ char** argv = new char*[args.size()+2]; argv[0] = new char[cmd.size()+1]; strcpy(argv[0], cmd.c_str()); @@ -144,10 +149,10 @@ strcpy(argv[i+1], args[i].c_str()); } argv[i+1] = NULL; - cerr << "spawn: working dir: " << working_dir << " cmd: " << cmd; + debug << "spawn: working dir: " << working_dir << " cmd: " << cmd; for(vector::const_iterator i=args.begin(); i!=args.end(); i++) - cerr << ' ' << *i; - cerr << endl; + debug << ' ' << *i; + debug << endl; int pid; if(!(pid = fork())) { if(chdir(working_dir.c_str()) < 0) { @@ -159,10 +164,15 @@ exit(1); } else if(pid < 0) { perror("fork"); - exit(1); + return -1; } + if(wait) waitpid(pid, NULL, 0); return pid; } +int spawn(bool wait, const string& title, const string& working_dir, const string& cmd, vector args) +{ + return spawn(wait, working_dir, cmd, args); +} #else PROCESS_INFORMATION spawn(const string& title, const string& wdir, const string& cmd, @@ -179,57 +189,66 @@ PROCESS_INFORMATION spawn(const string& title, const string& wdir, const string& exe, string args) { - //CreateProcess wants a writable char* for some stupid reason - ostringstream cmdline; - cmdline << exe << ' ' << args; - char* temppath = new char[cmdline.str().length()+1]; - cmdline.str().copy(temppath, cmdline.str().length()); - temppath[cmdline.str().length()] = '\0'; + //CreateProcess wants a writable char* for some stupid reason + ostringstream cmdline; + cmdline << exe << ' ' << args; + char* temppath = new char[cmdline.str().length()+1]; + cmdline.str().copy(temppath, cmdline.str().length()); + temppath[cmdline.str().length()] = '\0'; debug << "fixin' to spawn: " << temppath << endl; - - STARTUPINFO si; - PROCESS_INFORMATION pi; - ZeroMemory(&si, sizeof(si)); - si.cb = sizeof(si); - si.lpTitle = (LPSTR) title.c_str(); - ZeroMemory(&pi, sizeof(pi)); - if (!CreateProcess(NULL, - temppath, - NULL, - NULL, - FALSE, - CREATE_NEW_CONSOLE, - NULL, - wdir.c_str(), - &si, - &pi)) { - switch(errno) { - case E2BIG: error << "Argument list exceeds 1024 bytes"; break; - case EINVAL: error << "mode argument is invalid"; break; - case ENOENT: error << "File or path is not found"; break; - case ENOEXEC: error << "Specified file is not executable or has invalid executable-file format"; break; - case ENOMEM: error << "Not enough memory is available to execute new process"; break; - default: error << "Some unknown spawn error"; - } - error << endl; - } - delete temppath; - return pi; + + STARTUPINFO si; + PROCESS_INFORMATION pi; + ZeroMemory(&si, sizeof(si)); + si.cb = sizeof(si); + si.lpTitle = (LPSTR) title.c_str(); + ZeroMemory(&pi, sizeof(pi)); + if (!CreateProcess(NULL, + temppath, + NULL, + NULL, + FALSE, + CREATE_NEW_CONSOLE, + NULL, + wdir.c_str(), + &si, + &pi)) { + switch(errno) { + case E2BIG: error << "Argument list exceeds 1024 bytes"; break; + case EINVAL: error << "mode argument is invalid"; break; + case ENOENT: error << "File or path is not found"; break; + case ENOEXEC: error << "Specified file is not executable or has invalid executable-file format"; break; + case ENOMEM: error << "Not enough memory is available to execute new process"; break; + default: error << "Some unknown spawn error"; + } + error << endl; + } + delete temppath; + return pi; } #endif bool testLastConfig(const string& source, const string& target) { - //return true if target is newer than source - struct _stat source_stat, target_stat; - if(_stat(source.c_str(), &source_stat)) { - error << "problem stating source: " << source << endl; - return false; - } - if(_stat(target.c_str(), &target_stat)) { - error << "problem stating target: " << target << endl; - return false; - } - return target_stat.st_mtime > source_stat.st_mtime; -} + //return true if target is newer than source +#ifdef WIN32 + struct _stat source_stat, target_stat; + if(_stat(source.c_str(), &source_stat)) { +#else + struct stat source_stat, target_stat; + if(stat(source.c_str(), &source_stat)) { +#endif + error << "problem stating source: " << source << endl; + return false; + } +#ifdef WIN32 + if(_stat(target.c_str(), &target_stat)) { +#else + if(stat(target.c_str(), &target_stat)) { +#endif + error << "problem stating target: " << target << endl; + return false; + } + return target_stat.st_mtime > source_stat.st_mtime; + } Modified: TeamTalk/Agents/PrimitiveComm/utils.h =================================================================== --- TeamTalk/Agents/PrimitiveComm/utils.h 2006-12-11 03:46:02 UTC (rev 555) +++ TeamTalk/Agents/PrimitiveComm/utils.h 2006-12-11 08:01:47 UTC (rev 556) @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -49,8 +50,8 @@ enum Level {D, I, W, E, F}; protected: static set types_; + Level level_; string type_; - Level level_; public: static Level threashold_; DebugStream(Level level=D, const string s=string()) : level_(level), type_(s) {}; @@ -121,14 +122,14 @@ // ** Process ********************************************************* #ifndef WIN32 -int spawn(const string& wdir, const string& cmd, +int spawn(bool wait, const string& wdir, const string& cmd, vector args=vector()); -int spawn(const string& wdir, const string& cmd, const string& exe, - string args=string()); +int spawn(bool wait, const string& title, const string& wdir, + const string& cmd, string args=string()); #else -PROCESS_INFORMATION spawn(string wd, string cmd, +PROCESS_INFORMATION spawn(bool wait, const string& wd, const string& cmd, vector args=vector()); -PROCESS_INFORMATION spawn(const string& title, const string& wdir, +PROCESS_INFORMATION spawn(bool wait, const string& title, const string& wdir, const string& exe, string args=string()); #endif From tk at edam.speech.cs.cmu.edu Mon Dec 11 03:04:39 2006 From: tk at edam.speech.cs.cmu.edu (tk@edam.speech.cs.cmu.edu) Date: Mon, 11 Dec 2006 03:04:39 -0500 Subject: [TeamTalk 20]: [557] TeamTalk/Agents/PrimitiveComm: Message-ID: <200612110804.kBB84dMW004753@edam.speech.cs.cmu.edu> An HTML attachment was scrubbed... URL: http://mailman.srv.cs.cmu.edu/pipermail/teamtalk-developers/attachments/20061211/571e7a00/attachment-0001.html -------------- next part -------------- Added: TeamTalk/Agents/PrimitiveComm/Makefile =================================================================== --- TeamTalk/Agents/PrimitiveComm/Makefile (rev 0) +++ TeamTalk/Agents/PrimitiveComm/Makefile 2006-12-11 08:04:39 UTC (rev 557) @@ -0,0 +1,66 @@ +BOEINGLIB_DIR = ../boeingLib + +INCLUDES = -I. -I$(BOEINGLIB_DIR)/boeing -I$(BOEINGLIB_DIR)/coralshared + +CPPFLAGS = $(DEFS) $(INCLUDES) +CXXFLAGS = -g -Wall -O0 +CXXCOMPILE = $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) +CXXLINK = $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ + +OBJECTS = robot_class.o robot_packet2.o udpsocket.o utils.o \ + boeing_robot_server.o boeing_trader_server.o boeing_map_packet.o \ + boeing_map_server.o + +LIBRARIES = libboeingrobotserver.a + +all: $(LIBRARIES) + +libboeingrobotserver.a: $(OBJECTS) + ar cru $@ $(OBJECTS) + ranlib $@ + +geometry.o: geometry.cpp geometry.h + $(CXXCOMPILE) -o $@ $< + +robot_packet2.o: robot_packet2.cpp robot_packet2.h geometry.h \ + $(BOEINGLIB_DIR)/boeing/boeing_robot_packet.h \ + $(BOEINGLIB_DIR)/boeing/boeing_net.h \ + $(BOEINGLIB_DIR)/boeing/boeing_trader_packet.h \ + $(BOEINGLIB_DIR)/boeing/boeing_map_packet.h + $(CXXCOMPILE) -o $@ $< + +udpsocket.o: udpsocket.cc udpsocket.h + $(CXXCOMPILE) -o $@ $< + +utils.o: utils.cpp utils.h + $(CXXCOMPILE) -o $@ $< + +boeing_robot_server.o: $(BOEINGLIB_DIR)/boeing/boeing_robot_server.cc \ + $(BOEINGLIB_DIR)/boeing/boeing_robot_server.h udpsocket.h \ + $(BOEINGLIB_DIR)/boeing/boeing_robot_packet.h \ + $(BOEINGLIB_DIR)/boeing/boeing_net.h \ + $(BOEINGLIB_DIR)/boeing/boeing_map_packet.h $(BOEINGLIB_DIR)/coralshared/timer.h \ + $(BOEINGLIB_DIR)/coralshared/error_check.h $(BOEINGLIB_DIR)/coralshared/util.h + $(CXXCOMPILE) -o $@ $< + +boeing_trader_server.o: $(BOEINGLIB_DIR)/boeing/boeing_trader_server.cc \ + $(BOEINGLIB_DIR)/boeing/boeing_trader_server.h udpsocket.h \ + $(BOEINGLIB_DIR)/boeing/boeing_trader_packet.h \ + $(BOEINGLIB_DIR)/boeing/boeing_net.h $(BOEINGLIB_DIR)/coralshared/timer.h \ + $(BOEINGLIB_DIR)/coralshared/error_check.h $(BOEINGLIB_DIR)/coralshared/util.h + $(CXXCOMPILE) -o $@ $< + +boeing_map_server.o: $(BOEINGLIB_DIR)/boeing/boeing_map_server.cc \ + $(BOEINGLIB_DIR)/boeing/boeing_map_server.h udpsocket.h \ + $(BOEINGLIB_DIR)/boeing/boeing_map_packet.h \ + $(BOEINGLIB_DIR)/boeing/boeing_net.h $(BOEINGLIB_DIR)/coralshared/timer.h \ + $(BOEINGLIB_DIR)/coralshared/error_check.h $(BOEINGLIB_DIR)/coralshared/util.h + $(CXXCOMPILE) -o $@ $< + +boeing_map_packet.o: $(BOEINGLIB_DIR)/boeing/boeing_map_packet.cc \ + $(BOEINGLIB_DIR)/boeing/boeing_map_packet.h \ + $(BOEINGLIB_DIR)/boeing/boeing_net.h + $(CXXCOMPILE) -o $@ $< + +clean: + rm -f *.o $(LIBRARIES) Property changes on: TeamTalk/Agents/PrimitiveComm/Makefile ___________________________________________________________________ Name: svn:executable + * Added: TeamTalk/Agents/PrimitiveComm/netutils.cpp =================================================================== --- TeamTalk/Agents/PrimitiveComm/netutils.cpp (rev 0) +++ TeamTalk/Agents/PrimitiveComm/netutils.cpp 2006-12-11 08:04:39 UTC (rev 557) @@ -0,0 +1,192 @@ +#include "netutils.h" + +using namespace std; + +void diag(const string& x) +{ //return a hex rep of the string + for(unsigned int i = 0; i < x.length(); i++) { + printf("%02x ", (unsigned char) x[i]); + if(i%16 == 15) printf("\n"); + } +} + +NetUtilsException::NetUtilsException(const string& e) throw() +{ + lpMsgBuf = (char*)malloc(e.size()+1); + e.copy(lpMsgBuf, e.size()); + lpMsgBuf[e.size()] = '\0'; +} + +#ifdef WIN32 +NetUtilsException::NetUtilsException(DWORD errorCode) throw() +#else +NetUtilsException::NetUtilsException() throw() +#endif +{ +#ifdef WIN32 + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + errorCode, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR) &lpMsgBuf, + 0, NULL); +#else + int errorCode = errno; + lpMsgBuf = (char*)malloc(100); + if(errorCode >= sys_nerr) { + snprintf(lpMsgBuf, 99, "unknown error %d", errorCode); + } else { + strncpy(lpMsgBuf, 99, sys_errlist[errorCode]); + } +#endif +} + +NetUtilsException::~NetUtilsException() throw() { + free(lpMsgBuf); +} + +string NetUtilsException::what() throw() {return lpMsgBuf;} + +void initializeSockets(struct fd_set* sockets) { +#ifdef WIN32 + WORD wVersionRequested; + WSADATA wsaData; + int err; + wVersionRequested = MAKEWORD( 2, 2 ); + if((err = WSAStartup(wVersionRequested, &wsaData)) != 0) + throw NetUtilsException(err); +#endif + if (sockets != NULL) FD_ZERO(sockets); +} + +void Bind_in(SOCKET socket, const sockaddr_in* socketAddress) { + if(bind(socket, (struct sockaddr*)socketAddress, sizeof(struct sockaddr_in)) == -1 ) + throw NetUtilsException(); +} + +void Bind_in(SOCKET socket, short port) { + sockaddr_in st_local_addr; + memset(&st_local_addr, 0, sizeof(st_local_addr)); + st_local_addr.sin_family = AF_INET; + st_local_addr.sin_addr.s_addr = htonl(INADDR_ANY); + st_local_addr.sin_port = htons(port); + Bind_in(socket, &st_local_addr); +} + +SOCKET Socket_udp() { + SOCKET s; + if((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1) throw NetUtilsException(); + return s; +} + +string Recv(SOCKET socket, sockaddr_in* from) { + const int BUFSIZE = 0xfff; + char buf[BUFSIZE]; + int addr_size = sizeof(sockaddr_in); + int rv = recvfrom(socket, (char *)buf, BUFSIZE, 0, (sockaddr*)from, &addr_size); + if(rv == SOCKET_ERROR) throw NetUtilsException(); + return string(buf, rv); +} + +string Recv(SOCKET socket, unsigned long* from) { + sockaddr_in s_from; + string retval = Recv(socket, &s_from); + *from = s_from.sin_addr.S_un.S_addr; + return retval; +} + +string Recv(SOCKET socket) { + const int BUFSIZE = 0xfff; + char buf[BUFSIZE]; + int rv = recv(socket, buf, BUFSIZE, 0); + if(rv == SOCKET_ERROR) throw NetUtilsException(); + return string(buf, rv); +} + +/* + switch (socket_error) { + case WSANOTINITIALISED: + throw RobotServerException("A successful WSAStartup call must occur before using this function."); + case WSAENETDOWN: + throw RobotServerException(" The network subsystem has failed."); + case WSAEFAULT: + throw RobotServerException(" The buf parameter is not completely contained in a valid part of the user address space."); + case WSAENOTCONN: + throw RobotServerException(" The socket is not connected."); + case WSAEINTR: + throw RobotServerException(" The (blocking) call was canceled through WSACancelBlockingCall."); + case WSAEINPROGRESS: + throw RobotServerException(" A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function."); + case WSAENETRESET: + throw RobotServerException(" The connection has been broken due to the keep-alive activity detecting a failure while the operation was in progress."); + case WSAENOTSOCK: + throw RobotServerException(" The descriptor is not a socket."); + case WSAEOPNOTSUPP: + throw RobotServerException(" MSG_OOB was specified, but the socket is not stream-style such as type SOCK_STREAM, OOB data is not supported in the communication domain associated with this socket, or the socket is unidirectional and supports only send operations."); + case WSAESHUTDOWN: + throw RobotServerException(" The socket has been shut down; it is not possible to receive on a socket after shutdown has been invoked with how set to SD_RECEIVE or SD_BOTH."); + case WSAEWOULDBLOCK: + throw RobotServerException(" The socket is marked as nonblocking and the receive operation would block."); + case WSAEMSGSIZE: + throw RobotServerException(" The message was too large to fit into the specified buffer and was truncated."); + case WSAEINVAL: + throw RobotServerException(" The socket has not been bound with bind, or an unknown flag was specified, or MSG_OOB was specified for a socket with SO_OOBINLINE enabled or (for byte stream sockets only) len was zero or negative."); + case WSAECONNABORTED: + throw RobotServerException(" The virtual circuit was terminated due to a time-out or other failure. The application should close the socket as it is no longer usable."); + case WSAETIMEDOUT: + throw RobotServerException(" The connection has been dropped because of a network failure or because the peer system failed to respond."); + case WSAECONNRESET: + throw RobotServerException(" The virtual circuit was reset by the remote side executing a hard or abortive close. The application should close the socket as it is no longer usable. On a UPD-datagram socket this error would indicate that a previous send operation resulted in an ICMP \"Port Unreachable\" message."); + default: throw RobotServerException("unknown recv error"); + } + case WSASYSNOTREADY: + throw "something" + case WSAVERNOTSUPPORTED: + throw NetUtilsException("The version of Windows Sockets support requested is not provided by this particular Windows Sockets implementation."); + case WSAEINPROGRESS: + throw NetUtilsException("A blocking Windows Sockets 1.1 operation is in progress."); + case WSAEPROCLIM: + throw NetUtilsException("Limit on the number of tasks supported by the Windows Sockets implementation has been reached."); + case WSAEFAULT: + throw NetUtilsException("The lpWSAData is not a valid pointer."); + default: + throw NetUtilsException("unknown error starting Windows sockets."); + + + switch(WSAGetLastError()) { + case WSANOTINITIALISED: + cerr << "A successful WSAStartup call must occur before using this function." << endl; + break; + case WSAENETDOWN: + cerr << "The network subsystem has failed." << endl; + break; + case WSAEACCES: + cerr << "Attempt to connect datagram socket to broadcast address failed because setsockopt option SO_BROADCAST is not enabled." << endl; + break; + case WSAEADDRINUSE: + cerr << "A process on the computer is already bound to the same fully-qualified address and the socket has not been marked to allow address reuse with SO_REUSEADDR. For example, the IP address and port are bound in the af_inet case). (See the SO_REUSEADDR socket option under setsockopt.)" << endl; + break; + case WSAEADDRNOTAVAIL: + cerr << "The specified address is not a valid address for this computer." << endl; + break; + case WSAEFAULT: + cerr << "The name or namelen parameter is not a valid part of the user address space, the namelen parameter is too small, the name parameter contains an incorrect address format for the associated address family, or the first two bytes of the memory block specified by name does not match the address family associated with the socket descriptor s." << endl; + break; + case WSAEINPROGRESS: + cerr << "A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function." << endl; + break; + case WSAEINVAL: + cerr << "The socket is already bound to an address." << endl; + break; + case WSAENOBUFS: + cerr << "Not enough buffers available, too many connections." << endl; + break; + case WSAENOTSOCK: + cerr << "The descriptor is not a socket." << endl; + break; + default: + cerr << "unknown bind error" << endl; + } + throw exception(); + } +*/ Added: TeamTalk/Agents/PrimitiveComm/netutils.h =================================================================== --- TeamTalk/Agents/PrimitiveComm/netutils.h (rev 0) +++ TeamTalk/Agents/PrimitiveComm/netutils.h 2006-12-11 08:04:39 UTC (rev 557) @@ -0,0 +1,43 @@ +#ifndef NETUTILS_H +#define NETUTILS_H + +#ifdef WIN32 +#include +#else +#include +#include +#include +//typedef int SOCKET +#endif + +#include + +using namespace std; + +void diag(const string& x); //return a hex rep of the string + +class NetUtilsException : public exception { + char* lpMsgBuf; +public: + NetUtilsException(const string& e) throw(); +#ifdef WIN32 + NetUtilsException(DWORD errorCode=WSAGetLastError()) throw(); +#else + NetUtilsException() throw(); +#endif + ~NetUtilsException() throw(); + string what() throw(); +}; + +void initializeSockets(fd_set* sockets=NULL); + +void Bind_in(SOCKET socket, const sockaddr_in* socketAddress); +void Bind_in(SOCKET socket, short port); + +SOCKET Socket_udp(); + +string Recv(SOCKET socket, sockaddr_in* from); +string Recv(SOCKET socket, unsigned long* from); +string Recv(SOCKET socket); + +#endif Deleted: TeamTalk/Agents/PrimitiveComm/win_netutils.cpp =================================================================== --- TeamTalk/Agents/PrimitiveComm/win_netutils.cpp 2006-12-11 08:01:47 UTC (rev 556) +++ TeamTalk/Agents/PrimitiveComm/win_netutils.cpp 2006-12-11 08:04:39 UTC (rev 557) @@ -1,173 +0,0 @@ -#include "win_netutils.h" - -using namespace std; - -void diag(const string& x) { //return a hex rep of the string - for(unsigned int i = 0; i < x.length(); i++) { - printf("%02x ", (unsigned char) x[i]); - if(i%16 == 15) printf("\n"); - } -} - -NetUtilsException::NetUtilsException(const string& e) throw() { - lpMsgBuf = (char *) malloc(e.size()+1); - e.copy(lpMsgBuf, e.size()); - lpMsgBuf[e.size()] = '\0'; -} - -NetUtilsException::NetUtilsException(DWORD errorCode) throw() { - FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - errorCode, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR) &lpMsgBuf, - 0, NULL); -} - -NetUtilsException::~NetUtilsException() throw() { - free(lpMsgBuf); -} - -string NetUtilsException::what() throw() {return lpMsgBuf;} - -void initializeSockets(struct fd_set* sockets) { - WORD wVersionRequested; - WSADATA wsaData; - int err; - wVersionRequested = MAKEWORD( 2, 2 ); - if((err = WSAStartup(wVersionRequested, &wsaData)) != 0) - throw NetUtilsException(err); - if (sockets != NULL) FD_ZERO(sockets); -} - -void Bind_in(SOCKET socket, const sockaddr_in* socketAddress) { - if(bind(socket, (struct sockaddr*)socketAddress, sizeof(struct sockaddr_in)) == -1 ) - throw NetUtilsException(); -} - -void Bind_in(SOCKET socket, short port) { - sockaddr_in st_local_addr; - memset(&st_local_addr, 0, sizeof(st_local_addr)); - st_local_addr.sin_family = AF_INET; - st_local_addr.sin_addr.s_addr = htonl(INADDR_ANY); - st_local_addr.sin_port = htons(port); - Bind_in(socket, &st_local_addr); -} - -SOCKET Socket_udp() { - SOCKET s; - if((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1) throw NetUtilsException(); - return s; -} - -string Recv(SOCKET socket, sockaddr_in* from) { - const int BUFSIZE = 0xfff; - char buf[BUFSIZE]; - int addr_size = sizeof(sockaddr_in); - int rv = recvfrom(socket, (char *)buf, BUFSIZE, 0, (sockaddr*)from, &addr_size); - if(rv == SOCKET_ERROR) throw NetUtilsException(); - return string(buf, rv); -} - -string Recv(SOCKET socket, unsigned long* from) { - sockaddr_in s_from; - string retval = Recv(socket, &s_from); - *from = s_from.sin_addr.S_un.S_addr; - return retval; -} - -string Recv(SOCKET socket) { - const int BUFSIZE = 0xfff; - char buf[BUFSIZE]; - int rv = recv(socket, buf, BUFSIZE, 0); - if(rv == SOCKET_ERROR) throw NetUtilsException(); - return string(buf, rv); -} - -/* - switch (socket_error) { - case WSANOTINITIALISED: - throw RobotServerException("A successful WSAStartup call must occur before using this function."); - case WSAENETDOWN: - throw RobotServerException(" The network subsystem has failed."); - case WSAEFAULT: - throw RobotServerException(" The buf parameter is not completely contained in a valid part of the user address space."); - case WSAENOTCONN: - throw RobotServerException(" The socket is not connected."); - case WSAEINTR: - throw RobotServerException(" The (blocking) call was canceled through WSACancelBlockingCall."); - case WSAEINPROGRESS: - throw RobotServerException(" A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function."); - case WSAENETRESET: - throw RobotServerException(" The connection has been broken due to the keep-alive activity detecting a failure while the operation was in progress."); - case WSAENOTSOCK: - throw RobotServerException(" The descriptor is not a socket."); - case WSAEOPNOTSUPP: - throw RobotServerException(" MSG_OOB was specified, but the socket is not stream-style such as type SOCK_STREAM, OOB data is not supported in the communication domain associated with this socket, or the socket is unidirectional and supports only send operations."); - case WSAESHUTDOWN: - throw RobotServerException(" The socket has been shut down; it is not possible to receive on a socket after shutdown has been invoked with how set to SD_RECEIVE or SD_BOTH."); - case WSAEWOULDBLOCK: - throw RobotServerException(" The socket is marked as nonblocking and the receive operation would block."); - case WSAEMSGSIZE: - throw RobotServerException(" The message was too large to fit into the specified buffer and was truncated."); - case WSAEINVAL: - throw RobotServerException(" The socket has not been bound with bind, or an unknown flag was specified, or MSG_OOB was specified for a socket with SO_OOBINLINE enabled or (for byte stream sockets only) len was zero or negative."); - case WSAECONNABORTED: - throw RobotServerException(" The virtual circuit was terminated due to a time-out or other failure. The application should close the socket as it is no longer usable."); - case WSAETIMEDOUT: - throw RobotServerException(" The connection has been dropped because of a network failure or because the peer system failed to respond."); - case WSAECONNRESET: - throw RobotServerException(" The virtual circuit was reset by the remote side executing a hard or abortive close. The application should close the socket as it is no longer usable. On a UPD-datagram socket this error would indicate that a previous send operation resulted in an ICMP \"Port Unreachable\" message."); - default: throw RobotServerException("unknown recv error"); - } - case WSASYSNOTREADY: - throw "something" - case WSAVERNOTSUPPORTED: - throw NetUtilsException("The version of Windows Sockets support requested is not provided by this particular Windows Sockets implementation."); - case WSAEINPROGRESS: - throw NetUtilsException("A blocking Windows Sockets 1.1 operation is in progress."); - case WSAEPROCLIM: - throw NetUtilsException("Limit on the number of tasks supported by the Windows Sockets implementation has been reached."); - case WSAEFAULT: - throw NetUtilsException("The lpWSAData is not a valid pointer."); - default: - throw NetUtilsException("unknown error starting Windows sockets."); - - - switch(WSAGetLastError()) { - case WSANOTINITIALISED: - cerr << "A successful WSAStartup call must occur before using this function." << endl; - break; - case WSAENETDOWN: - cerr << "The network subsystem has failed." << endl; - break; - case WSAEACCES: - cerr << "Attempt to connect datagram socket to broadcast address failed because setsockopt option SO_BROADCAST is not enabled." << endl; - break; - case WSAEADDRINUSE: - cerr << "A process on the computer is already bound to the same fully-qualified address and the socket has not been marked to allow address reuse with SO_REUSEADDR. For example, the IP address and port are bound in the af_inet case). (See the SO_REUSEADDR socket option under setsockopt.)" << endl; - break; - case WSAEADDRNOTAVAIL: - cerr << "The specified address is not a valid address for this computer." << endl; - break; - case WSAEFAULT: - cerr << "The name or namelen parameter is not a valid part of the user address space, the namelen parameter is too small, the name parameter contains an incorrect address format for the associated address family, or the first two bytes of the memory block specified by name does not match the address family associated with the socket descriptor s." << endl; - break; - case WSAEINPROGRESS: - cerr << "A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function." << endl; - break; - case WSAEINVAL: - cerr << "The socket is already bound to an address." << endl; - break; - case WSAENOBUFS: - cerr << "Not enough buffers available, too many connections." << endl; - break; - case WSAENOTSOCK: - cerr << "The descriptor is not a socket." << endl; - break; - default: - cerr << "unknown bind error" << endl; - } - throw exception(); - } -*/ \ No newline at end of file Deleted: TeamTalk/Agents/PrimitiveComm/win_netutils.h =================================================================== --- TeamTalk/Agents/PrimitiveComm/win_netutils.h 2006-12-11 08:01:47 UTC (rev 556) +++ TeamTalk/Agents/PrimitiveComm/win_netutils.h 2006-12-11 08:04:39 UTC (rev 557) @@ -1,31 +0,0 @@ -#ifndef WIN_NETUTILS_H -#define WIN_NETUTILS_H - -#include -#include - -using namespace std; - -void diag(const string& x); //return a hex rep of the string - -class NetUtilsException : public exception { - char* lpMsgBuf; -public: - NetUtilsException(const string& e) throw(); - NetUtilsException(DWORD errorCode=WSAGetLastError()) throw(); - ~NetUtilsException() throw(); - string what() throw(); -}; - -void initializeSockets(struct fd_set* sockets=NULL); - -void Bind_in(SOCKET socket, const sockaddr_in* socketAddress); -void Bind_in(SOCKET socket, short port); - -SOCKET Socket_udp(); - -string Recv(SOCKET socket, sockaddr_in* from); -string Recv(SOCKET socket, unsigned long* from); -string Recv(SOCKET socket); - -#endif \ No newline at end of file From tk at edam.speech.cs.cmu.edu Mon Dec 11 03:10:22 2006 From: tk at edam.speech.cs.cmu.edu (tk@edam.speech.cs.cmu.edu) Date: Mon, 11 Dec 2006 03:10:22 -0500 Subject: [TeamTalk 21]: [558] TeamTalk/Agents/TeamTalkSimulator: Changes to support latest version of PrimitiveComm. Message-ID: <200612110810.kBB8AM21004767@edam.speech.cs.cmu.edu> An HTML attachment was scrubbed... URL: http://mailman.srv.cs.cmu.edu/pipermail/teamtalk-developers/attachments/20061211/35fa865a/attachment.html -------------- next part -------------- Modified: TeamTalk/Agents/TeamTalkSimulator/TeamTalkSimulator.cc =================================================================== --- TeamTalk/Agents/TeamTalkSimulator/TeamTalkSimulator.cc 2006-12-11 08:04:39 UTC (rev 557) +++ TeamTalk/Agents/TeamTalkSimulator/TeamTalkSimulator.cc 2006-12-11 08:10:22 UTC (rev 558) @@ -13,6 +13,7 @@ #include #include #include +#include using namespace std; @@ -60,21 +61,21 @@ /****************** MAP STUFF *********************/ static unsigned char* conveyedMap; -static unsigned char* currentMap; +static unsigned char* currentMap = (unsigned char*)malloc(500000); static unsigned char* diffMap; static int mapWidth, mapHeight; static int mapXOffset, mapYOffset; +static Boeing::MsgMap* msgMap = (Boeing::MsgMap*)malloc(500000); - void readMapFile() { //we're going to do this a lot, so just open once } -void sendFullMap(Boeing::MapServer *m) { +void sendFullMap(Boeing::MapServer *mserver) { readMapFile(); Boeing::MsgMap::MsgMapFactory(Boeing::MAP_RLE, - msgMap, mapData, mapWidth*mapHeight, + msgMap, currentMap, mapWidth*mapHeight, 0, 0, mapWidth, mapHeight); cerr << "raw: " << msgMap->map[0] << " rl: " << ((msgMap->map[0]&0xFFFFFF00)>>8) @@ -82,10 +83,10 @@ mserver->sendFullMap(msgMap); } -void sendDiffMap(Boeing::MapServer *m) { +void sendDiffMap(Boeing::MapServer *mserver) { readMapFile(); Boeing::MsgMap::MsgMapFactory(Boeing::MAP_RLE, - msgMap, diff_map, + msgMap, diffMap, mapWidth*mapHeight, 0, 0, mapWidth, mapHeight); cerr << "raw: " << msgMap->map[0] << " rl: " << ((msgMap->map[0]&0xFFFFFF00)>>8) @@ -97,13 +98,13 @@ bool subscribed = false; int updatePeriod = 1; - Boeing::MapServer *mserver = (Boeing::MapServer *) m; + Boeing::MapServer *mserver = (Boeing::MapServer*)m; for(;;) { const Boeing::MsgMapServer *msg = mserver->getNextMessage(); if(msg) { switch(msg->hdr.type) { case Boeing::MAP_SUBSCRIBE: - sendFullMap(m); + sendFullMap(mserver); subscribed = true; break; case Boeing::MAP_KEEPALIVE: @@ -117,7 +118,7 @@ cerr << "unknown or unhandled msgtype: " << msg->hdr.type << endl; } } else { - if(subscribed) sendDiffMap(m); + if(subscribed) sendDiffMap(mserver); sleep(updatePeriod); } } @@ -164,12 +165,11 @@ void readMapData() { ifstream f("stubdb.txt"); f >> mapWidth >> mapHeight; - mapData = new unsigned char[mapWidth*mapHeight]; for(int j=0; j> n; - mapData[j*mapWidth+i] = (unsigned char)n; + currentMap[j*mapWidth+i] = (unsigned char)n; } } } Modified: TeamTalk/Agents/TeamTalkSimulator/imageClient.h =================================================================== --- TeamTalk/Agents/TeamTalkSimulator/imageClient.h 2006-12-11 08:04:39 UTC (rev 557) +++ TeamTalk/Agents/TeamTalkSimulator/imageClient.h 2006-12-11 08:10:22 UTC (rev 558) @@ -5,6 +5,12 @@ #include +#ifndef WIN32 +#include +#include +#include +#endif + class ImageClient { protected: int sockfd; Modified: TeamTalk/Agents/TeamTalkSimulator/robot.cc =================================================================== --- TeamTalk/Agents/TeamTalkSimulator/robot.cc 2006-12-11 08:04:39 UTC (rev 557) +++ TeamTalk/Agents/TeamTalkSimulator/robot.cc 2006-12-11 08:10:22 UTC (rev 558) @@ -6,6 +6,7 @@ #include #include +#include #define DEBUG 1 #include "robot.h" @@ -25,10 +26,6 @@ using namespace std; -#ifndef PI -const double PI(4.0 * atan2(1.0, 1.0)); -#endif - const unsigned int shift = 6; const unsigned int mask = ~0U << (sizeof(unsigned int)*8 - shift); @@ -53,7 +50,7 @@ int Robot::initVehMobPLNmlBuffers(char *config_file, int bufnum) { - print_debugln("cleaning up nmlbuffers"); + debug << "cleaning up nmlbuffers" << endl; cleanupVehMobPLNmlBuffers(); { @@ -229,7 +226,7 @@ me->vehMobPLSetBuf->read(); me->primMobJAStatBuf->read(); - print_debugln("command initialization"); + debug << "command initialization" << endl; VehMobPLCmdInit init = VehMobPLCmdInit(); init.serial_number = me->statP->echo_serial_number+1; me->vehMobPLCmdBuf->write(&init); @@ -281,16 +278,20 @@ //strcpy(dump.fileName, "/tmp/VehMobPLDispOutput.ppm"); //me->vehMobPLCfgBuf->write(&dump); - print_debugln("entering for loop"); + debug << "entering for loop" << endl; //EnterCriticalSection(&me->CriticalSection); for(int i;;i++) { //LeaveCriticalSection(&me->CriticalSection); do { const Boeing::MsgCmd *bmsg; - //if(me->server_->isConnected()) print_debug('.'); while(me->server_->isConnected() && (bmsg = me->server_->getNextMessage())) { - Msg* msg = Msg::interpret(bmsg->buff); + Msg* msg = Msg::interpretBoeingPacket(string(bmsg->buff, 1000)); + if(!msg) { + warn << "got NULL message" << endl; + break; + } + debug << "got message: " << msg->render() << endl; //if(!dynamic_cast(msg)) { // print_debug("got message: "); print_debugln(msg->render()); //} @@ -400,26 +401,26 @@ } // initial allocate all the buffers - print_debugln("initial allocation of the buffers"); + debug << "initial allocation of the buffers" << endl; if(initVehMobPLNmlBuffers(NML_FILE, sim_index)) { cerr << "can't allocate NML buffers" << endl; } // set up our convenient pointer to status and settings - print_debugln("set up convenient pointers"); + debug << "set up convenient pointers" << endl; statP = (VehMobPLStat *) vehMobPLStatBuf->get_address(); primStatP = (PrimMobJAStat *) primMobJAStatBuf->get_address(); setP = (VehMobPLSet *) vehMobPLSetBuf->get_address(); - print_debugln("new robotserver"); + debug << "new robotserver" << endl; server_ = new Boeing::RobotServer(); - print_debugln("opening port"); + debug << "opening port" << endl; if (port) server_->open(port); else server_->open(); - print_debugln("starting reading thread"); + debug << "starting reading thread" << endl; pthread_t simulation_thread; pthread_create(&simulation_thread, NULL, simulate, (void *)this); - print_debugln("done with robot constructor"); + debug << "done with robot constructor" << endl; } Robot::~Robot() { @@ -438,14 +439,14 @@ primMobJAStatBuf->read(); Msg* temp_message; - if(const MsgCmdActionPP* action = dynamic_cast(msgp)) { - //print_debugln("got an action"); - //need to translate txt-based message into typed message - temp_message = Msg::interpretPlayAction(*action->content()); - } else { - temp_message = msgp->clone(); - } - if(const MsgMapReqPP* req_image = dynamic_cast(temp_message)) { + //if(const MsgCmdActionPP* action = dynamic_cast(msgp)) { + // //print_debugln("got an action"); + // //need to translate txt-based message into typed message + // temp_message = Msg::interpretPlayAction(*action->content()); + //} else { + // temp_message = msgp->clone(); + //} + if(const MsgMapReq* req_image = dynamic_cast(temp_message)) { //print_debugln("got an req image"); //get the jpeg from the usarsim video socket const unsigned char* image; @@ -468,67 +469,52 @@ //print_debugln("done with req image"); return; } - if(dynamic_cast(temp_message)) { + if(dynamic_cast(temp_message)) { //print_debugln("got an req location"); server_->sendLocation(getX(), -getY(), canonical_angle(-getYaw()), true); delete temp_message; return; } //EnterCriticalSection(&CriticalSection); - if(const MsgCmdGoToRelativePP* goto_relative = dynamic_cast(temp_message)) { - cout << "got: " << *goto_relative << endl; - float m_x = goto_relative->content()->x; - float m_y = -goto_relative->content()->y; - float dir = getYaw()+atan2(m_y, m_x); - float len = sqrt(m_x*m_x+m_y*m_y); - VehMobPLCmdMoveWaypoint move = VehMobPLCmdMoveWaypoint(); - move.p.x = getX()+cos(dir)*len; - move.p.y = getY()+sin(dir)*len; - //cerr << "m_x: " << m_x << " m_y: " << m_y << " yaw: " << getYaw() - // << " curdir: " << atan2(m_y, m_x) << " dir: " << dir - // << " len: " << len << " c_x: " << getX() << " c_y: " << getY() - // << " movex: " << move.p.x << " movey: " << move.p.y << endl; - move.serial_number = statP->echo_serial_number+1; - move.isGlobal = true; - move.neighborhood = 1; - move.startTime = 0; - vehMobPLCmdBuf->write(&move); + if(const MsgCmdGoTo* goTo = dynamic_cast(temp_message)) { + cout << "got: " << goTo << endl; + Point vec(goTo->getX(), goTo->getY()); + if(goTo->useAngle() && !vec) { + PrimMobJACmdRotate rotate = PrimMobJACmdRotate(); + float r = -getYaw(); + rotate.theta = canonical_angle(-(r+goTo->getAngle())); + rotate.thetaTol = PI/20; //9 degrees tolerance + // always make it a new command + rotate.serial_number = primStatP->echo_serial_number + 1; + primMobJACmdBuf->write(&rotate); + } else { + Point loc(getX(), getY()); + Point destination; + if(goTo->isAbsolute()) { + destination = vec; + } else { + destination = + loc + Point::Polar(vec.length(), getYaw()+vec.angle()); + } + VehMobPLCmdMoveWaypoint move = VehMobPLCmdMoveWaypoint(); + move.p.x = destination.x; + move.p.y = destination.y; + move.serial_number = statP->echo_serial_number+1; + move.isGlobal = true; + move.neighborhood = 1; + move.startTime = 0; + vehMobPLCmdBuf->write(&move); + } delete temp_message; return; - } else if(const MsgCmdHaltPP* halt = dynamic_cast(temp_message)) { - cout << "got: " << *halt << endl; + } else if(const MsgCmdHalt* halt = dynamic_cast(temp_message)) { + cout << "got: " << halt << endl; action = WAITING; delete temp_message; return; - } else if(const MsgCmdGoToGlobalPP* goto_global = dynamic_cast(temp_message)) { - cout << "got: " << *goto_global << endl; - //setGoal(goto_global->content()->x, goto_global->content()->y); + } else if(const MsgCmdHome* home = dynamic_cast(temp_message)) { + cout << "got: " << home << endl; VehMobPLCmdMoveWaypoint move = VehMobPLCmdMoveWaypoint(); - move.p.x = goto_global->content()->x; - move.p.y = -goto_global->content()->y; - move.serial_number = statP->echo_serial_number+1; - move.isGlobal = true; - move.neighborhood = 1; - move.startTime = 0; - vehMobPLCmdBuf->write(&move); - delete temp_message; - return; - } else if(const MsgCmdTurnRelativePP* turn = dynamic_cast(temp_message)) { - cout << "got: " << *turn << endl; - PrimMobJACmdRotate rotate = PrimMobJACmdRotate(); - float r = -getYaw(); - rotate.theta = canonical_angle(-(r+turn->content()->angle)); - rotate.thetaTol = PI/20; //9 degrees tolerance - // always make it a new command - rotate.serial_number = primStatP->echo_serial_number + 1; - primMobJACmdBuf->write(&rotate); - //goal_r = canonical_angle(r+turn->content()->angle); - //action = GO_TO_ANGLE; //will report done when complete - delete temp_message; - return; - } else if(const MsgCmdHomePP* home = dynamic_cast(temp_message)) { - cout << "got: " << *home << endl; - VehMobPLCmdMoveWaypoint move = VehMobPLCmdMoveWaypoint(); move.p.x = 0; move.p.y = 0; move.serial_number = statP->echo_serial_number+1; @@ -538,19 +524,19 @@ vehMobPLCmdBuf->write(&move); delete temp_message; return; - } else if(const MsgCmdPausePP* pause = dynamic_cast(temp_message)) { - cout << "got: " << *pause << endl; + } else if(const MsgCmdPause* pause = dynamic_cast(temp_message)) { + cout << "got: " << pause << endl; if(action != PAUSED) { paused_action = action; action = PAUSED; } - } else if(const MsgCmdResumePP* resume = dynamic_cast(temp_message)) { - cout << "got: " << *resume << endl; + } else if(const MsgCmdResume* resume = dynamic_cast(temp_message)) { + cout << "got: " << resume << endl; if(action == PAUSED) { action = paused_action; } - } else if(const MsgCmdFollowPP* follow = dynamic_cast(temp_message)) { - cout << "got: " << *follow << endl; + } else if(const MsgCmdFollow* follow = dynamic_cast(temp_message)) { + cout << "got: " << follow << endl; //setFollow(follow->content()->leader); } //LeaveCriticalSection(&CriticalSection); Modified: TeamTalk/Agents/TeamTalkSimulator/robot.h =================================================================== --- TeamTalk/Agents/TeamTalkSimulator/robot.h 2006-12-11 08:04:39 UTC (rev 557) +++ TeamTalk/Agents/TeamTalkSimulator/robot.h 2006-12-11 08:10:22 UTC (rev 558) @@ -2,7 +2,7 @@ #define ROBOT_H #include -#include +#include #include #include From tk at edam.speech.cs.cmu.edu Mon Dec 11 03:18:26 2006 From: tk at edam.speech.cs.cmu.edu (tk@edam.speech.cs.cmu.edu) Date: Mon, 11 Dec 2006 03:18:26 -0500 Subject: [TeamTalk 22]: [559] TeamTalk/Agents/PrimitiveComm/robot_packet.hpp: Message-ID: <200612110818.kBB8IQ9g004780@edam.speech.cs.cmu.edu> An HTML attachment was scrubbed... URL: http://mailman.srv.cs.cmu.edu/pipermail/teamtalk-developers/attachments/20061211/9ed4e1c7/attachment-0001.html -------------- next part -------------- Deleted: TeamTalk/Agents/PrimitiveComm/robot_packet.hpp =================================================================== --- TeamTalk/Agents/PrimitiveComm/robot_packet.hpp 2006-12-11 08:10:22 UTC (rev 558) +++ TeamTalk/Agents/PrimitiveComm/robot_packet.hpp 2006-12-11 08:18:25 UTC (rev 559) @@ -1,379 +0,0 @@ -#ifndef ROBOT_PACKET_H -#define ROBOT_PACKET_H - -//all these includes are just for the "sender" a bit cludgy -#ifdef WIN32 -#include -#else -#include -#include -#include -#include -#include -#include -#include -#ifndef SOCKET -#define SOCKET long -#endif -#endif - -#include -#include - -#include -#include - -#include -#include -#include -#include "geometry.h" - -using namespace std; -using namespace geometry; - -ostream& operator<<(ostream& out, const Boeing::RP_Polygon& p); - -Boeing::RP_Polygon makeRP(const geometry::Polygon& p); - -class Msg { -protected: - static int iTaskCounter; - virtual Boeing::MsgHeader* header() =0; - string sender; -public: - static Boeing::MsgHeader construct_MsgHeader(uint16_t _type); - static Boeing::MsgCmdTask construct_MsgCmdTask(uint16_t _type); - static Boeing::MsgCmdAction construct_MsgCmdAction(const string& play); - static Msg* interpretPlayAction(const Boeing::MsgCmdAction& playaction); - -public: - string getSender() const; - static Msg* interpret(const char* m, string s=string()); - virtual ~Msg(); - Msg* clone() const; - uint16_t getType() const; -//void stamp(const string& hostname, const string& recipient); - virtual string render() const =0; - template - static void stamp(M& msg, const string& hostname, const string& recipient) { - //hostname.copy(h->sender, SADDR_LENGTH); - //recipient.copy(h->recipient, SADDR_LENGTH); - //msg.content_.priority = 1; -#ifdef WIN32 - struct __timeb64 timebuffer; - _ftime64(&timebuffer); -#else - struct timeb timebuffer; - ftime(&timebuffer); -#endif - msg.content_.tstamp = timebuffer.time + (float)timebuffer.millitm/1000; - }; -}; - -class MsgCmdActionPP : public Msg { - friend class Msg; -protected: - Boeing::MsgCmdAction content_; - Boeing::MsgHeader* header(); - MsgCmdActionPP(); -public: - MsgCmdActionPP(const Boeing::MsgCmdAction& c); - MsgCmdActionPP(const string& play, int _taskid); - string render() const; - const Boeing::MsgCmdAction* content() const; -}; - -class MsgCmdSetPosPP : public Msg { - friend class Msg; -protected: - Boeing::MsgCmdAction content_; - Boeing::MsgHeader* header(); -public: - MsgCmdSetPosPP(const Boeing::MsgCmdAction& c); - MsgCmdSetPosPP(double x, double y, double a); - //double getX() const; - //double getY() const; - //double getAngle() const; - MsgCmdSetPosPP* clone() const; - const Boeing::MsgCmdAction* content() const; - string action_string() const; - string render() const; -}; - -class MsgCmdHaltPP : public Msg { - friend class Msg; -protected: - Boeing::MsgCmdHalt content_; - Boeing::MsgHeader* header(); -public: - MsgCmdHaltPP(); - MsgCmdHaltPP(const Boeing::MsgCmdHalt& x); - MsgCmdHaltPP* clone() const; - const Boeing::MsgCmdHalt* content() const; - string action_string() const; - string render() const; -}; - -class MsgCmdGoToPP : public Msg { - friend class Msg; -protected: - Boeing::MsgCmdGoTo content_; - Boeing::MsgHeader* header(); -public: - MsgCmdGoToPP(); - MsgCmdGoToPP(const Boeing::MsgCmdGoTo& x); - const Boeing::MsgCmdGoTo* content() const; - string render() const =0; -}; - -class MsgCmdGoToGlobalPP : public MsgCmdGoToPP { - friend class Msg; -public: - MsgCmdGoToGlobalPP(Point loc); - MsgCmdGoToGlobalPP(const Boeing::MsgCmdGoTo& x); - MsgCmdGoToGlobalPP* clone() const; - string action_string() const; - string render() const; -}; - -class MsgCmdGoToRelativePP : public MsgCmdGoToPP { - friend class Msg; -public: - MsgCmdGoToRelativePP(Point vec); - MsgCmdGoToRelativePP(const Boeing::MsgCmdGoTo& x); - MsgCmdGoToRelativePP* clone() const; - string action_string() const; - string render() const; -}; - -class MsgCmdTurnRelativePP : public MsgCmdGoToPP { - friend class Msg; -public: - MsgCmdTurnRelativePP(double a); - MsgCmdTurnRelativePP(const Boeing::MsgCmdGoTo& x); - MsgCmdTurnRelativePP* clone() const; - string action_string() const; - string render() const; -}; - -class MsgCmdHomePP : public Msg { - friend class Msg; - Boeing::MsgCmdHome content_; -protected: - Boeing::MsgHeader* header(); -public: - MsgCmdHomePP(); - MsgCmdHomePP(const Boeing::MsgCmdHome& x); - MsgCmdHomePP* clone() const; - const Boeing::MsgCmdHome* content() const; - string action_string() const; - string render() const; -}; - -class MsgCmdPausePP : public Msg { - friend class Msg; - Boeing::MsgCmdPause content_; -protected: - Boeing::MsgHeader* header(); -public: - MsgCmdPausePP(); - MsgCmdPausePP(const Boeing::MsgCmdPause& x); - MsgCmdPausePP* clone() const; - const Boeing::MsgCmdPause* content() const; - string action_string() const; - string render() const; -}; - -class MsgCmdResumePP : public Msg { - friend class Msg; - Boeing::MsgCmdResume content_; -protected: - Boeing::MsgHeader* header(); -public: - MsgCmdResumePP(); - MsgCmdResumePP(const Boeing::MsgCmdResume& x); - MsgCmdResumePP* clone() const; - const Boeing::MsgCmdResume* content() const; - string action_string() const; - string render() const; -}; - -class MsgCmdFollowPP : public Msg { - friend class Msg; - Boeing::MsgCmdFollow content_; -protected: - Boeing::MsgHeader* header(); -public: - MsgCmdFollowPP(const string& l); - MsgCmdFollowPP(const Boeing::MsgCmdFollow& x); - MsgCmdFollowPP* clone() const; - const Boeing::MsgCmdFollow* content() const; - string action_string() const; - string render() const; -}; - -class MsgCmdCoverPP : public Msg { - friend class Msg; - Boeing::MsgCmdCover content_; -protected: - Boeing::MsgHeader* header(); -public: - MsgCmdCoverPP(const Point& lower_left, const Point& upper_right); - MsgCmdCoverPP(float x1, float x2, float y1, float y2); - MsgCmdCoverPP(const geometry::Polygon& polygon); - MsgCmdCoverPP(const Boeing::MsgCmdCover& x); - MsgCmdCoverPP* clone() const; - const Boeing::MsgCmdCover* content() const; - string action_string() const; - string render() const; -}; - -/* -class MsgCmdLoadPP : public Msg { - friend class Msg; - Boeing::MsgCmdLoad content_; -protected: - Boeing::MsgHeader* header(); -public: - MsgCmdLoadPP(); - MsgCmdLoadPP(const Boeing::MsgCmdLoad& x); - MsgCmdLoadPP* clone() const; - const Boeing::MsgCmdLoad* content() const; - string action_string() const; - string render() const; -}; - -class MsgCmdUnloadPP : public Msg { - friend class Msg; - Boeing::MsgCmdUnload content_; -protected: - Boeing::MsgHeader* header(); -public: - MsgCmdUnloadPP(); - MsgCmdUnloadPP(const Boeing::MsgCmdUnload& x); - MsgCmdUnloadPP* clone() const; - const Boeing::MsgCmdUnload* content() const; - string action_string() const; - string render() const; -}; -*/ - -class MsgReqLocationPP : public Msg { - friend class Msg; - Boeing::MsgReqLocation content_; -protected: - Boeing::MsgHeader* header(); -public: - MsgReqLocationPP(); - MsgReqLocationPP(const Boeing::MsgReqLocation& x); - MsgReqLocationPP* clone() const; - const Boeing::MsgReqLocation* content() const; - string render() const; -}; - -class MsgRobAckPP : public Msg { - friend class Msg; - Boeing::MsgRobAck content_; -protected: - Boeing::MsgHeader* header(); -public: - MsgRobAckPP(uint16_t id); - MsgRobAckPP(const Boeing::MsgRobAck& x); - MsgRobAckPP* clone() const; - const Boeing::MsgRobAck* content() const; - string render() const; -}; - -class MsgRobDonePP : public Msg { - friend class Msg; - Boeing::MsgRobDone content_; -protected: - Boeing::MsgHeader* header(); -public: - MsgRobDonePP(uint16_t id, bool success=true); - MsgRobDonePP(const Boeing::MsgRobDone& x); - MsgRobDonePP* clone() const; - bool isSuccess() const; - const Boeing::MsgRobDone* content() const; - string render() const; -}; - -class MsgRobLocationPP : public Msg { - friend class Msg; - Boeing::MsgRobLocation content_; -protected: - Boeing::MsgHeader* header(); -public: - MsgRobLocationPP(Point loc, double a, bool m); - MsgRobLocationPP(const Boeing::MsgRobLocation& x); - MsgRobLocationPP* clone() const; - bool isMoving() const; - const Boeing::MsgRobLocation* content() const; - string render() const; -}; - -/* -class MsgPingPP : public Msg { - friend class Msg; - MsgPing content_; -protected: - MsgHeader* header(); -public: - MsgPingPP(const string& handle); - MsgPingPP(const MsgPing& x); - MsgPingPP* clone() const; - string handle() const; - const MsgPing* content() const; - string render() const; -}; -*/ - -class MsgActionAckPP : public Msg { - friend class Msg; - Boeing::MsgActionAck content_; -protected: - Boeing::MsgHeader* header(); -public: - MsgActionAckPP(); - MsgActionAckPP(const Boeing::MsgActionAck& x); - MsgActionAckPP* clone() const; - const Boeing::MsgActionAck* content() const; - string render() const; -}; - -class MsgMapReqPP : public Msg { - friend class Msg; - Boeing::MsgMapReq content_; -protected: - Boeing::MsgHeader* header(); -public: - MsgMapReqPP(); - MsgMapReqPP(const Boeing::MsgMapReq& x); - MsgMapReqPP* clone() const; - const Boeing::MsgMapReq* content() const; - int getInvoice() const; - string render() const; -}; - -class MsgMapPP : public Msg { - friend class Msg; - Boeing::MsgMap* content_; -protected: - Boeing::MsgHeader* header(); -public: - MsgMapPP(); - MsgMapPP(const Boeing::MsgMap& x); - ~MsgMapPP(); - MsgMapPP* clone() const; - const Boeing::MsgMap* content() const; - int getWidth() const; - int getHeight() const; - int getInvoice() const; - const char* getImageData() const; - int getImageDataSize() const; - string render() const; -}; - -ostream& operator<<(ostream& out, const Msg& m); - -#endif From tk at edam.speech.cs.cmu.edu Wed Dec 13 14:04:18 2006 From: tk at edam.speech.cs.cmu.edu (tk@edam.speech.cs.cmu.edu) Date: Wed, 13 Dec 2006 14:04:18 -0500 Subject: [TeamTalk 23]: [560] TeamTalk/Agents: fixed references from win_netutils to the now generic netutils Message-ID: <200612131904.kBDJ4ITZ009800@edam.speech.cs.cmu.edu> An HTML attachment was scrubbed... URL: http://mailman.srv.cs.cmu.edu/pipermail/teamtalk-developers/attachments/20061213/1501480c/attachment.html -------------- next part -------------- Modified: TeamTalk/Agents/PrimitiveComm/robot_client.cpp =================================================================== --- TeamTalk/Agents/PrimitiveComm/robot_client.cpp 2006-12-11 08:18:25 UTC (rev 559) +++ TeamTalk/Agents/PrimitiveComm/robot_client.cpp 2006-12-13 19:04:17 UTC (rev 560) @@ -6,7 +6,7 @@ #include "robot_client.hpp" #include "utils.h" -#include "win_netutils.h" +#include "netutils.h" #include #include #include Modified: TeamTalk/Agents/PrimitiveComm/robot_server.hpp =================================================================== --- TeamTalk/Agents/PrimitiveComm/robot_server.hpp 2006-12-11 08:18:25 UTC (rev 559) +++ TeamTalk/Agents/PrimitiveComm/robot_server.hpp 2006-12-13 19:04:17 UTC (rev 560) @@ -5,7 +5,6 @@ #ifdef WIN32 #include -#include "win_netutils.h" #include "win32dep.h" #else #include @@ -24,6 +23,7 @@ #include #include "robot_packet2.h" #include "udpsocket.h" +#include "netutils.h" using namespace std; Modified: TeamTalk/Agents/PrimitiveComm/utils.cpp =================================================================== --- TeamTalk/Agents/PrimitiveComm/utils.cpp 2006-12-11 08:18:25 UTC (rev 559) +++ TeamTalk/Agents/PrimitiveComm/utils.cpp 2006-12-13 19:04:17 UTC (rev 560) @@ -174,7 +174,7 @@ return spawn(wait, working_dir, cmd, args); } #else -PROCESS_INFORMATION spawn(const string& title, const string& wdir, +PROCESS_INFORMATION spawn(bool wait, const string& title, const string& wdir, const string& cmd, vector args=vector()) { @@ -183,10 +183,10 @@ if(i != args.begin()) argstring << ' '; argstring << *i; } - return spawn(title, wdir, cmd, argstring.str()); + return spawn(wait, title, wdir, cmd, argstring.str()); } -PROCESS_INFORMATION spawn(const string& title, const string& wdir, +PROCESS_INFORMATION spawn(bool wait, const string& title, const string& wdir, const string& exe, string args) { //CreateProcess wants a writable char* for some stupid reason @@ -223,6 +223,7 @@ } error << endl; } + if(wait) WaitForSingleObject(pi.hProcess, INFINITE); delete temppath; return pi; } Modified: TeamTalk/Agents/TeamTalkBackend/agent.cpp =================================================================== --- TeamTalk/Agents/TeamTalkBackend/agent.cpp 2006-12-11 08:18:25 UTC (rev 559) +++ TeamTalk/Agents/TeamTalkBackend/agent.cpp 2006-12-13 19:04:17 UTC (rev 560) @@ -28,7 +28,7 @@ ostringstream args; args << "-verbosity 3 -pgm_file " << cfilename; - serverChildren_.push(spawn(cfilename, ".", HUB, args.str()).hProcess); + serverChildren_.push(spawn(false, cfilename, ".", HUB, args.str()).hProcess); } void Agent::spawnHelios(const string& uppername) @@ -42,7 +42,7 @@ ostringstream args; args << "-port " << iHeliosPort << " -config " << cfilename; - serverChildren_.push(spawn(cfilename, ".", HELIOS, args.str()).hProcess); + serverChildren_.push(spawn(false, cfilename, ".", HELIOS, args.str()).hProcess); } void Agent::spawnDM(const string& uppername, const string& safeness) @@ -70,7 +70,7 @@ ostringstream args; args << "-maxconns 6 -config " << cfilename; - serverChildren_.push(spawn(cfilename, ".", DM, args.str()).hProcess); + serverChildren_.push(spawn(false, cfilename, ".", DM, args.str()).hProcess); } string Agent::writeSpecializedConfig(const string temp, const string ext, Modified: TeamTalk/Agents/TeamTalkBackend/backendstub/robot.cpp =================================================================== --- TeamTalk/Agents/TeamTalkBackend/backendstub/robot.cpp 2006-12-11 08:18:25 UTC (rev 559) +++ TeamTalk/Agents/TeamTalkBackend/backendstub/robot.cpp 2006-12-13 19:04:17 UTC (rev 560) @@ -230,17 +230,13 @@ EnterCriticalSection(&CriticalSection); if(const MsgCmdGoTo* goTo = dynamic_cast(temp_message)) { info << "got: " << goTo << endl; - Point gotoVec(goTo->getX(), goTo->getY()); - float m_x = goTo->getX(); - float m_y = goTo->getY(); - if(goTo->isAbsolute()) setGoal(gotoVec); //will report done when complete - else if(goTo->useAngle() && m_x == 0 && m_y == 0) { + Point vec(goTo->getX(), goTo->getY()); + if(goTo->isAbsolute()) setGoal(vec); //will report done when complete + else if(goTo->useAngle() && !vec) { setGoal(canonical_angle(pose.yaw+goTo->getAngle())); action = GO_TO_ANGLE; //will report done when complete } else { - float dir = pose.yaw+atan2(m_y, m_x); - float len = sqrt(m_x*m_x+m_y*m_y); - setGoal(Point::Polar(len, dir)); + setGoal(pose.loc+Point::Polar(vec.length(), pose.yaw+vec.angle())); } } else if(const MsgCmdHalt* halt = dynamic_cast(temp_message)) { info << "got: " << halt << endl; From tk at edam.speech.cs.cmu.edu Thu Dec 14 12:49:22 2006 From: tk at edam.speech.cs.cmu.edu (tk@edam.speech.cs.cmu.edu) Date: Thu, 14 Dec 2006 12:49:22 -0500 Subject: [TeamTalk 24]: [561] TeamTalk/Agents: more interesting fake treasure location Message-ID: <200612141749.kBEHnMrV012079@edam.speech.cs.cmu.edu> An HTML attachment was scrubbed... URL: http://mailman.srv.cs.cmu.edu/pipermail/teamtalk-developers/attachments/20061214/ae4ae744/attachment.html -------------- next part -------------- Modified: TeamTalk/Agents/PrimitiveComm/PrimitiveComm.vcproj =================================================================== --- TeamTalk/Agents/PrimitiveComm/PrimitiveComm.vcproj 2006-12-13 19:04:17 UTC (rev 560) +++ TeamTalk/Agents/PrimitiveComm/PrimitiveComm.vcproj 2006-12-14 17:49:21 UTC (rev 561) @@ -274,10 +274,6 @@ > - - Modified: TeamTalk/Agents/PrimitiveComm/robot_client.cpp =================================================================== --- TeamTalk/Agents/PrimitiveComm/robot_client.cpp 2006-12-13 19:04:17 UTC (rev 560) +++ TeamTalk/Agents/PrimitiveComm/robot_client.cpp 2006-12-14 17:49:21 UTC (rev 561) @@ -88,7 +88,10 @@ for(;;) { bool gotAMessage = false; const Boeing::MsgRobot* mesg = me->getNextMessage(); - if(mesg == NULL) continue; + if(mesg == NULL) { + Sleep(500); + continue; + } try { Msg* m = Msg::interpretBoeingPacket(string(mesg->buff, sizeof(Boeing::MsgRobot)), me->getName()); if(!m) throw MalformedPacketException("RobotClient::readMessages", Modified: TeamTalk/Agents/PrimitiveComm/robot_packet2.cpp =================================================================== --- TeamTalk/Agents/PrimitiveComm/robot_packet2.cpp 2006-12-13 19:04:17 UTC (rev 560) +++ TeamTalk/Agents/PrimitiveComm/robot_packet2.cpp 2006-12-14 17:49:21 UTC (rev 561) @@ -25,6 +25,24 @@ // Msg **************************************************************** +int Msg::boeingStatus(Msg::Status x) +{ + switch(x) { + case FAILED: return Boeing::FAILED; + case IN_PROGRESS: return Boeing::INPROGRESS; + case SUCCEEDED: return Boeing::SUCCEEDED; + default: error << "unknown status " << (int)x; + } + return 0; +} + +Msg::Status Msg::statusOfBoeing(int x) +{ + if(x <= Boeing::FAILED) return FAILED; + if(x >= Boeing::SUCCEEDED) return SUCCEEDED; + return IN_PROGRESS; +} + int Msg::taskIDCounter = 0; const int Msg::defaultPriority = 1; @@ -103,9 +121,12 @@ return new MsgRobAck(sender, tstamp, reinterpret_cast(m.c_str())->taskid); } -// case Boeing::ROB_ACTION_ACK: -// warn("packet") << "unhandled type: ROB_ACTION_ACK " << h->type << endl; -// break; + if(type == Boeing::ROB_ACTION_ACK) { + warn("packet") << "unhandled type: ROB_ACTION_ACK " << h->type << endl; + debug("packet") << "got: ROB_ACTION_ACK" << endl; + const Boeing::MsgActionAck* bp = reinterpret_cast(m.c_str()); + return new MsgRobActionAck(sender, tstamp, bp->taskid, (bp->status == Boeing::SUCCEEDED)); + } if(type == Boeing::ROB_DONE) { debug("packet") << "got: ROB_DONE" << endl; const Boeing::MsgRobDone* bp = reinterpret_cast(m.c_str()); @@ -127,10 +148,10 @@ // warn("packet") << "unhandled type: TASK_CANCEL " << endl; // break; //messages from trader - if(type == Boeing::INFO) { - warn("packet") << "unhandled type: INFO " << endl; - return NULL; - } +// if(type == Boeing::INFO) { +// warn("packet") << "unhandled type: INFO " << endl; +// return NULL; +// } // case Boeing::TASK_ACK: // warn("packet") << "unhandled type: TASK_ACK " << endl; // break; @@ -440,6 +461,39 @@ return string(reinterpret_cast(&packet), packet.len); } +// MsgRobActionAck **************************************************** + +//normal instantiation +MsgRobActionAck::MsgRobActionAck(int taskID, Status status, string sender) +: Msg(sender), taskID_(taskID), status_(status) {} + +//instantiation from a Boeing packet +MsgRobActionAck::MsgRobActionAck(string sender, double tstamp, int taskID, int status) +: Msg(sender, tstamp), taskID_(taskID) { + if(status <= Boeing::FAILED) status_ = FAILED; + else if(status = Boeing::INPROGRESS) status_ = IN_PROGRESS; + else status = SUCCEEDED; +} + +int MsgRobActionAck::getTaskID() const {return taskID_;} + +Msg::Status MsgRobActionAck::getStatus() const {return status_;} + +bool MsgRobActionAck::isSuccess() const {return status_ == SUCCEEDED;} +bool MsgRobActionAck::isInprogress() const {return status_ == IN_PROGRESS;} +bool MsgRobActionAck::isFailure() const {return status_ == FAILED;} + +string MsgRobActionAck::render() const { + ostringstream out; + out << "robactionack: " << taskID_ << status_; + return out.str(); +} + +string MsgRobActionAck::renderBoeingPacket() const { + Boeing::MsgActionAck packet = Boeing::MsgActionAck::factory(taskID_, statusOfBoeing(status_)); + return string(reinterpret_cast(&packet), packet.len); +} + // MsgRobDone ********************************************************* //normal instantiation @@ -589,7 +643,26 @@ // Stream Operators *************************************************** -ostream& operator<<(ostream& out, const Msg* m) { +ostream& operator<<(ostream& out, const Msg* m) +{ return out << m->render(); } +ostream& operator<<(ostream& out, const Msg::Status& x) +{ + switch(x) + { + case Msg::FAILED: + out << "FAILED"; + break; + case Msg::IN_PROGRESS: + out << "IN PROGRESS"; + break; + case Msg::SUCCEEDED: + out << "SUCCEEDED"; + break; + default: + error << "unknown status: " << (int)x << endl; + } + return out; +} Modified: TeamTalk/Agents/PrimitiveComm/robot_packet2.h =================================================================== --- TeamTalk/Agents/PrimitiveComm/robot_packet2.h 2006-12-13 19:04:17 UTC (rev 560) +++ TeamTalk/Agents/PrimitiveComm/robot_packet2.h 2006-12-14 17:49:21 UTC (rev 561) @@ -45,6 +45,11 @@ class Msg { +public: + enum Status {FAILED, IN_PROGRESS, SUCCEEDED}; + static int boeingStatus(Status x); + static Status statusOfBoeing(int x); + protected: static const int defaultPriority; string sender_; @@ -211,6 +216,24 @@ string renderBoeingPacket() const; }; +class MsgRobActionAck : public Msg { +protected: + int taskID_; + Status status_; +public: + //normal instantiation + MsgRobActionAck(int taskID, Status status, string sender=string()); + //instantiation from a Boeing packet + MsgRobActionAck(string sender, double tstamp, int taskID, int status); + int getTaskID() const; + Status getStatus() const; + bool isSuccess() const; + bool isFailure() const; + bool isInprogress() const; + string render() const; + string renderBoeingPacket() const; +}; + class MsgRobDone : public Msg { protected: int taskID_; @@ -289,5 +312,6 @@ }; ostream& operator<<(ostream& out, const Msg* m); +ostream& operator<<(ostream& out, const Msg::Status& x); #endif Modified: TeamTalk/Agents/PrimitiveComm/utils.cpp =================================================================== --- TeamTalk/Agents/PrimitiveComm/utils.cpp 2006-12-13 19:04:17 UTC (rev 560) +++ TeamTalk/Agents/PrimitiveComm/utils.cpp 2006-12-14 17:49:21 UTC (rev 561) @@ -195,7 +195,7 @@ char* temppath = new char[cmdline.str().length()+1]; cmdline.str().copy(temppath, cmdline.str().length()); temppath[cmdline.str().length()] = '\0'; - debug << "fixin' to spawn: " << temppath << endl; + debug << "fixin' to spawn: " << temppath << " from dir: " << wdir << endl; STARTUPINFO si; PROCESS_INFORMATION pi; Modified: TeamTalk/Agents/TeamTalkBackend/backendstub/backendstub.cpp =================================================================== --- TeamTalk/Agents/TeamTalkBackend/backendstub/backendstub.cpp 2006-12-13 19:04:17 UTC (rev 560) +++ TeamTalk/Agents/TeamTalkBackend/backendstub/backendstub.cpp 2006-12-14 17:49:21 UTC (rev 561) @@ -94,7 +94,7 @@ for(int c=1;;c++) { if(!(c%500)) { //find treasure every 50 seconds ostringstream info_string; - info_string << "object unknown at (0, 0)"; + info_string << "object unknown at (10, -5)"; debug << "sending: " << info_string.str() << endl; tserver->sendInfo(c/10, info_string.str().c_str()); } Modified: TeamTalk/Agents/TeamTalkBackend/gal_be.cpp =================================================================== --- TeamTalk/Agents/TeamTalkBackend/gal_be.cpp 2006-12-13 19:04:17 UTC (rev 560) +++ TeamTalk/Agents/TeamTalkBackend/gal_be.cpp 2006-12-14 17:49:21 UTC (rev 561) @@ -38,7 +38,7 @@ { debug << "sending restart_decoder" << endl; Gal_Frame gfInput = Gal_MakeFrame("restart_decoder", GAL_CLAUSE); - galaxyRobots->writeFrameAllHubs(gfInput); + galaxyRobots->writeFrameSkeletonHub(gfInput); }; BOOL WINAPI ConsoleHandler(DWORD CEvent) Modified: TeamTalk/Agents/TeamTalkBackend/robot-galaxy_adapter.cpp =================================================================== --- TeamTalk/Agents/TeamTalkBackend/robot-galaxy_adapter.cpp 2006-12-13 19:04:17 UTC (rev 560) +++ TeamTalk/Agents/TeamTalkBackend/robot-galaxy_adapter.cpp 2006-12-14 17:49:21 UTC (rev 561) @@ -63,14 +63,17 @@ subs); PROCESS_INFORMATION lm_build_proc = - spawn("Language Build", "..\\..\\Resources\\MakeLM", "perl", "makelm.pl"); - WaitForSingleObject(lm_build_proc.hProcess, INFINITE); + spawn(true, "Language Build", "..\\..\\Resources\\MakeLM", "perl", "makelm.pl"); } void GalaxyRobots::traderlistener(void *p) { GalaxyRobots* me = (GalaxyRobots *)p; Boeing::TraderClient* t_client = me->t_client; + + //this is bogus, but need to ping trader to get on its client list + t_client->sendCancel(0); + for(;;) { const Boeing::MsgTraderClient* msg = t_client->getNextMessage(); if(!msg) { @@ -203,10 +206,11 @@ void GalaxyRobots::writeFrameAllHubs(Gal_Frame f) { - debug << "writing to all hubs"; + debug << "writing to all hubs" << endl; for(set::iterator i = agents_.begin(); i != agents_.end(); i++) { i->writeFrame(f); } + writeFrameSkeletonHub(f); }; void GalaxyRobots::writeFrameSkeletonHub(Gal_Frame f) @@ -229,10 +233,7 @@ debug << "about to get the p_client" << endl; try { - //startup trader client t_client = new Boeing::TraderClient(); - - //startup map client m_client = new Boeing::MapClient(); //startup robot client @@ -278,11 +279,13 @@ void GalaxyRobots::setRobotVoices() { - for(set::const_iterator i = agents_.begin(); i != agents_.end(); i++) { - string name(toupper(i->getName())); - string voice(tolower(i->getRobotClient()->getVoice())); - debug << "adding voice " << voice << " to name " << name << endl; - SendRobotConfigMessage(name, voice); + debug << "attempting to set robot voices" << endl; + for(TeamTalk::RobotsClient::const_iterator i = r_client->begin(); + i != r_client->end(); i++) { + string name(toupper((*i)->getName())); + string voice(toupper((*i)->getVoice())); + debug << "adding voice " << voice << " to name " << name << endl; + SendRobotConfigMessage(name, voice); } } Modified: TeamTalk/Agents/boeingLib/boeing/boeing_robot_packet.h =================================================================== --- TeamTalk/Agents/boeingLib/boeing/boeing_robot_packet.h 2006-12-13 19:04:17 UTC (rev 560) +++ TeamTalk/Agents/boeingLib/boeing/boeing_robot_packet.h 2006-12-14 17:49:21 UTC (rev 561) @@ -214,6 +214,12 @@ struct MsgActionAck : public MsgHeader { TaskID taskid; int16_t status; + static MsgActionAck factory(TaskID taskID, int16_t status) { + MsgActionAck m; + m.MsgHeaderFill(ROB_ACTION_ACK, sizeof(MsgActionAck)); + m.taskid = taskID; m.status = status; + return m; + }; } PACKED; /** robot done status message From tk at edam.speech.cs.cmu.edu Thu Dec 14 12:53:31 2006 From: tk at edam.speech.cs.cmu.edu (tk@edam.speech.cs.cmu.edu) Date: Thu, 14 Dec 2006 12:53:31 -0500 Subject: [TeamTalk 25]: [562] TeamTalk/Configurations/DesktopConfiguration: Launchall batch now uses Pythia. Message-ID: <200612141753.kBEHrV9u012093@edam.speech.cs.cmu.edu> An HTML attachment was scrubbed... URL: http://mailman.srv.cs.cmu.edu/pipermail/teamtalk-developers/attachments/20061214/cc88918e/attachment-0001.html -------------- next part -------------- Modified: TeamTalk/Configurations/DesktopConfiguration/TeamTalk_LaunchAll-desktop.bat =================================================================== --- TeamTalk/Configurations/DesktopConfiguration/TeamTalk_LaunchAll-desktop.bat 2006-12-14 17:49:21 UTC (rev 561) +++ TeamTalk/Configurations/DesktopConfiguration/TeamTalk_LaunchAll-desktop.bat 2006-12-14 17:53:31 UTC (rev 562) @@ -1,3 +1,5 @@ -set GAL_VERBOSE=1 -set SLS_VERBOSE=1 -..\..\Bin\x86-nt\processmonitor.exe -list startlist-desktop.txt -crashlog crash.log -restart_delay 100 -remedy nothing +rem set GAL_VERBOSE=1 +rem set SLS_VERBOSE=1 +set GC_HOME=..\..\ExternalLibraries\Galaxy +rem ..\..\Bin\x86-nt\processmonitor.exe -list startlist-desktop.txt -crashlog crash.log -restart_delay 100 -remedy nothing +python ..\..\Pythia\src\process_monitor.py startlist-desktop.config Modified: TeamTalk/Configurations/DesktopConfiguration/startlist-desktop.config =================================================================== --- TeamTalk/Configurations/DesktopConfiguration/startlist-desktop.config 2006-12-14 17:49:21 UTC (rev 561) +++ TeamTalk/Configurations/DesktopConfiguration/startlist-desktop.config 2006-12-14 17:53:31 UTC (rev 562) @@ -2,7 +2,7 @@ EXPAND: $MITRE_ROOT $GC_HOME\contrib\MITRE EXPAND: $TEAMTALK ..\.. -EXPAND: $CONFIGURATION $TEAMTALK\Configuration\DesktopConfiguration +EXPAND: $CONFIGURATION $TEAMTALK\Configurations\DesktopConfiguration EXPAND: $AGENTS $TEAMTALK\Agents EXPAND: $PENDECODER $AGENTS\PenDecoder EXPAND: $BIN $TEAMTALK\Bin\x86-nt @@ -23,7 +23,7 @@ PROCESS: $BIN\KalliopeSwift.exe -maxconns 6 -config swift.cfg PROCESS_TITLE: Kalliope -PROCESS: $BIN\TeamTalkBackend-DEBUG.exe -verbosity 1 -maxconns 6 +PROCESS: $BIN\TeamTalkBackend.exe -verbosity 1 -maxconns 6 PROCESS_TITLE: TeamTalkBackend PROCESS: $PERL -I../Rosetta bin/TeamTalk From tk at edam.speech.cs.cmu.edu Thu Dec 21 00:49:59 2006 From: tk at edam.speech.cs.cmu.edu (tk@edam.speech.cs.cmu.edu) Date: Thu, 21 Dec 2006 00:49:59 -0500 Subject: [TeamTalk 26]: [563] TeamTalk/Agents/fixdepend: Fixup dependency files for linux compilations. Message-ID: <200612210549.kBL5nxi1005566@edam.speech.cs.cmu.edu> An HTML attachment was scrubbed... URL: http://mailman.srv.cs.cmu.edu/pipermail/teamtalk-developers/attachments/20061221/b11aaff1/attachment.html -------------- next part -------------- Added: TeamTalk/Agents/fixdepend =================================================================== --- TeamTalk/Agents/fixdepend (rev 0) +++ TeamTalk/Agents/fixdepend 2006-12-21 05:49:58 UTC (rev 563) @@ -0,0 +1,45 @@ +#!/usr/bin/ruby + +# /* LICENSE: */ + +dir = ARGV.shift.chomp("/") +#dir.chomp!("/"); + +obj_name = nil +if(!ARGV[0].nil? && ARGV[0]=~/\.o$/) + obj_name = ARGV.shift +end + +generated_h_files = ARGV + +line = $stdin.gets() +parts = line.split(/:/) +if(parts.size < 2) + exit 2 +end + +if(obj_name.nil?) + obj_name = File.join(dir,parts[0].strip()) +end +dep_name = obj_name.clone() +dep_name[-1,1] = "d" + +deps = parts[1] +rest_of_file = $stdin.gets(nil) +if(!rest_of_file.nil?) + deps += rest_of_file +end + +print "#{obj_name} : #{deps}" + +deps.gsub!(%r%([^[:blank:]\\]\S+)%) {|filename| + if(generated_h_files.index(filename).nil?) + "$(wildcard #{filename})" + else + filename + end +} + +print "\n#{dep_name} : #{deps}" + +exit 0 From tk at edam.speech.cs.cmu.edu Thu Dec 21 01:00:03 2006 From: tk at edam.speech.cs.cmu.edu (tk@edam.speech.cs.cmu.edu) Date: Thu, 21 Dec 2006 01:00:03 -0500 Subject: [TeamTalk 27]: [564] TeamTalk/Agents/PrimitiveComm: linux builds automatically handle dependencies Message-ID: <200612210600.kBL603xa005675@edam.speech.cs.cmu.edu> An HTML attachment was scrubbed... URL: http://mailman.srv.cs.cmu.edu/pipermail/teamtalk-developers/attachments/20061221/1875af09/attachment.html -------------- next part -------------- Modified: TeamTalk/Agents/PrimitiveComm/Makefile =================================================================== --- TeamTalk/Agents/PrimitiveComm/Makefile 2006-12-21 05:49:58 UTC (rev 563) +++ TeamTalk/Agents/PrimitiveComm/Makefile 2006-12-21 06:00:03 UTC (rev 564) @@ -2,6 +2,17 @@ INCLUDES = -I. -I$(BOEINGLIB_DIR)/boeing -I$(BOEINGLIB_DIR)/coralshared +VERBOSE = 1 + +DEP_ECHO = @echo Dependency: $@ +CC_ECHO = @echo Compiling: $@ +LINK_ECHO = @echo Linking: $@ +CLEAN_ECHO = @echo Cleaning. + +ifneq ($(VERBOSE), 1) + Q := @ +endif + CPPFLAGS = $(DEFS) $(INCLUDES) CXXFLAGS = -g -Wall -O0 CXXCOMPILE = $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) @@ -13,54 +24,51 @@ LIBRARIES = libboeingrobotserver.a +# Include the dependencies +-include $(OBJECTS:.o=.d) + all: $(LIBRARIES) libboeingrobotserver.a: $(OBJECTS) - ar cru $@ $(OBJECTS) - ranlib $@ + $(LINK_ECHO) + $(Q)ar cru $@ $(OBJECTS) + $(Q)ranlib $@ -geometry.o: geometry.cpp geometry.h - $(CXXCOMPILE) -o $@ $< +boeing_robot_server.o: $(BOEINGLIB_DIR)/boeing/boeing_robot_server.cc + $(CC_ECHO) + $(Q)$(CXXCOMPILE) -o $@ $< -robot_packet2.o: robot_packet2.cpp robot_packet2.h geometry.h \ - $(BOEINGLIB_DIR)/boeing/boeing_robot_packet.h \ - $(BOEINGLIB_DIR)/boeing/boeing_net.h \ - $(BOEINGLIB_DIR)/boeing/boeing_trader_packet.h \ - $(BOEINGLIB_DIR)/boeing/boeing_map_packet.h - $(CXXCOMPILE) -o $@ $< +boeing_trader_server.o: $(BOEINGLIB_DIR)/boeing/boeing_trader_server.cc + $(CC_ECHO) + $(Q)$(CXXCOMPILE) -o $@ $< -udpsocket.o: udpsocket.cc udpsocket.h - $(CXXCOMPILE) -o $@ $< +boeing_map_server.o: $(BOEINGLIB_DIR)/boeing/boeing_map_server.cc + $(CC_ECHO) + $(Q)$(CXXCOMPILE) -o $@ $< -utils.o: utils.cpp utils.h - $(CXXCOMPILE) -o $@ $< +boeing_map_packet.o: $(BOEINGLIB_DIR)/boeing/boeing_map_packet.cc + $(CC_ECHO) + $(Q)$(CXXCOMPILE) -o $@ $< -boeing_robot_server.o: $(BOEINGLIB_DIR)/boeing/boeing_robot_server.cc \ - $(BOEINGLIB_DIR)/boeing/boeing_robot_server.h udpsocket.h \ - $(BOEINGLIB_DIR)/boeing/boeing_robot_packet.h \ - $(BOEINGLIB_DIR)/boeing/boeing_net.h \ - $(BOEINGLIB_DIR)/boeing/boeing_map_packet.h $(BOEINGLIB_DIR)/coralshared/timer.h \ - $(BOEINGLIB_DIR)/coralshared/error_check.h $(BOEINGLIB_DIR)/coralshared/util.h - $(CXXCOMPILE) -o $@ $< +# Compilation rule +%.o: %.cc + $(CC_ECHO) + $(Q)$(CXXCOMPILE) -o $@ $< -boeing_trader_server.o: $(BOEINGLIB_DIR)/boeing/boeing_trader_server.cc \ - $(BOEINGLIB_DIR)/boeing/boeing_trader_server.h udpsocket.h \ - $(BOEINGLIB_DIR)/boeing/boeing_trader_packet.h \ - $(BOEINGLIB_DIR)/boeing/boeing_net.h $(BOEINGLIB_DIR)/coralshared/timer.h \ - $(BOEINGLIB_DIR)/coralshared/error_check.h $(BOEINGLIB_DIR)/coralshared/util.h - $(CXXCOMPILE) -o $@ $< +%.o: %.cpp + $(CC_ECHO) + $(Q)$(CXXCOMPILE) -o $@ $< -boeing_map_server.o: $(BOEINGLIB_DIR)/boeing/boeing_map_server.cc \ - $(BOEINGLIB_DIR)/boeing/boeing_map_server.h udpsocket.h \ - $(BOEINGLIB_DIR)/boeing/boeing_map_packet.h \ - $(BOEINGLIB_DIR)/boeing/boeing_net.h $(BOEINGLIB_DIR)/coralshared/timer.h \ - $(BOEINGLIB_DIR)/coralshared/error_check.h $(BOEINGLIB_DIR)/coralshared/util.h - $(CXXCOMPILE) -o $@ $< +# Dependency generation rule +%.d: %.cc + $(DEP_ECHO) + $(Q)$(CXX) -c $(CPPFLAGS) -MM $< | ../fixdepend $(dir $<) > $@ -boeing_map_packet.o: $(BOEINGLIB_DIR)/boeing/boeing_map_packet.cc \ - $(BOEINGLIB_DIR)/boeing/boeing_map_packet.h \ - $(BOEINGLIB_DIR)/boeing/boeing_net.h - $(CXXCOMPILE) -o $@ $< +%.d: %.cpp + $(DEP_ECHO) + $(Q)$(CXX) -c $(CPPFLAGS) -MM $< | ../fixdepend $(dir $<) > $@ +# Clean rule clean: - rm -f *.o $(LIBRARIES) + $(CLEAN_ECHO) + $(Q)rm -f *.o $(LIBRARIES) Modified: TeamTalk/Agents/PrimitiveComm/geometry.h =================================================================== --- TeamTalk/Agents/PrimitiveComm/geometry.h 2006-12-21 05:49:58 UTC (rev 563) +++ TeamTalk/Agents/PrimitiveComm/geometry.h 2006-12-21 06:00:03 UTC (rev 564) @@ -9,7 +9,8 @@ namespace geometry { -template struct Point { +template struct Point +{ T x, y; Point() : x(0), y(0) {}; Point(T X, T Y) : x(X), y(Y) {}; @@ -41,10 +42,11 @@ y += rhs.y; return *this; } - bool operator!() {return x != 0 || y != 0;} + bool operator!() {return x == 0 && y == 0;} }; -template struct Polygon : public vector< Point > { +template struct Polygon : public vector< Point > +{ Polygon() : vector< Point >() {}; Polygon (int n) : vector< Point >(n) {}; Polygon(const Polygon& p) : vector< Point >(p) {}; @@ -70,7 +72,7 @@ Quadrilateral(Point p1, Point p2, Point p3, Point p4): Polygon(4) { push_back(p1); push_back(p2); push_back(p3); push_back(p4); }; - operator Polygon() const {return *this;} + //operator Polygon() const {return *this;} Point ll() const { Point retval = this->at(0); for(int i=1; i<4; i++) { @@ -101,7 +103,8 @@ }; }; -template struct Pose { +template struct Pose +{ Point loc; T yaw; Pose() : loc(), yaw(0) {} @@ -112,15 +115,23 @@ } //end namespace geometry template -ostream& operator<<(ostream& out, const geometry::Point& p) { +ostream& operator<<(ostream& out, const geometry::Point& p) +{ return out << '(' << p.x << ' ' << p.y << ')'; } template -istream& operator>>(istream& in, geometry::Point& p) { +istream& operator>>(istream& in, geometry::Point& p) +{ if(istreamLookFor(in, '(').fail()) return in; if((in >> p.x).fail()) return in; if((in >> p.y).fail()) return in; return istreamLookFor(in, ')'); } +template +ostream& operator<<(ostream& out, const geometry::Pose& pose) +{ + return out << pose.loc << ' ' << pose.yaw << " rad"; +} + #endif //GEOMETRY Modified: TeamTalk/Agents/PrimitiveComm/robot_packet2.cpp =================================================================== --- TeamTalk/Agents/PrimitiveComm/robot_packet2.cpp 2006-12-21 05:49:58 UTC (rev 563) +++ TeamTalk/Agents/PrimitiveComm/robot_packet2.cpp 2006-12-21 06:00:03 UTC (rev 564) @@ -469,11 +469,7 @@ //instantiation from a Boeing packet MsgRobActionAck::MsgRobActionAck(string sender, double tstamp, int taskID, int status) -: Msg(sender, tstamp), taskID_(taskID) { - if(status <= Boeing::FAILED) status_ = FAILED; - else if(status = Boeing::INPROGRESS) status_ = IN_PROGRESS; - else status = SUCCEEDED; -} +: Msg(sender, tstamp), taskID_(taskID), status_(statusOfBoeing(status)) {} int MsgRobActionAck::getTaskID() const {return taskID_;} From tk at edam.speech.cs.cmu.edu Thu Dec 21 01:16:02 2006 From: tk at edam.speech.cs.cmu.edu (tk@edam.speech.cs.cmu.edu) Date: Thu, 21 Dec 2006 01:16:02 -0500 Subject: [TeamTalk 28]: [565] TeamTalk/Agents/TeamTalkSimulator: linux builds automatically handle depenencies Message-ID: <200612210616.kBL6G2X0005766@edam.speech.cs.cmu.edu> An HTML attachment was scrubbed... URL: http://mailman.srv.cs.cmu.edu/pipermail/teamtalk-developers/attachments/20061221/ddb21569/attachment-0001.html -------------- next part -------------- Modified: TeamTalk/Agents/TeamTalkSimulator/Makefile =================================================================== --- TeamTalk/Agents/TeamTalkSimulator/Makefile 2006-12-21 06:00:03 UTC (rev 564) +++ TeamTalk/Agents/TeamTalkSimulator/Makefile 2006-12-21 06:16:02 UTC (rev 565) @@ -1,5 +1,5 @@ -MOASTLIB_DIR = /net/eucalyptus/usr0/tkharris/moast-1.2 -RCSLIB_DIR = /net/eucalyptus/usr0/tkharris/lib/rcslib +MOASTLIB_DIR = $(CARTOON_HOME)/moast/devel +RCSLIB_DIR = $(CARTOON_HOME)/lib/rcslib BOEINGLIB_DIR = ../boeingLib PRIMITIVECOMM_DIR = ../PrimitiveComm @@ -10,34 +10,57 @@ LDFLAGS = -L$(MOASTLIB_DIR)/lib -L$(RCSLIB_DIR)/lib LDLIBS = -lmoast -lrcs -lposemath -lm #-lwsock32 +VERBOSE = 1 + +DEP_ECHO = @echo Dependency: $@ +CC_ECHO = @echo Compiling: $@ +LINK_ECHO = @echo Linking: $@ +CLEAN_ECHO = @echo Cleaning. + +ifneq ($(VERBOSE), 1) + Q := @ +endif + CPPFLAGS = $(DEFS) $(INCLUDES) CXXFLAGS = -g -Wall -O0 CXXCOMPILE = $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) CXXLINK = $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ -OBJECTS = TeamTalkSimulator.o robot.o imageClient.o \ - $(PRIMITIVECOMM_DIR)/libboeingrobotserver.a +OBJECTS = TeamTalkSimulator.o robot.o imageClient.o EXECUTABLES = TeamTalkSimulator +# Include the dependencies +-include $(OBJECTS:.o=.d) + all: $(EXECUTABLES) TeamTalkSimulator: primitivecomm $(OBJECTS) @rm -f TeamTalkSimulatedBot - $(CXXLINK) $(OBJECTS) $(LDLIBS) + $(CXXLINK) $(OBJECTS) $(PRIMITIVECOMM_DIR)/libboeingrobotserver.a $(LDLIBS) primitivecomm: - $(MAKE) -C $(PRIMITIVECOMM_DIR) + $(MAKE) -C $(PRIMITIVECOMM_DIR) all -TeamTalkSimulator.o: TeamTalkSimulator.cc robot.h imageClient.h $(PRIMITIVECOMM_DIR)/utils.h - $(CXXCOMPILE) -o $@ $< +# Compilation rule +%.o: %.cc + $(CC_ECHO) + $(Q)$(CXXCOMPILE) -o $@ $< -robot.o: robot.cc robot.h imageClient.h $(PRIMITIVECOMM_DIR)/utils.h - $(CXXCOMPILE) -o $@ $< +%.o: %.cpp + $(CC_ECHO) + $(Q)$(CXXCOMPILE) -o $@ $< -imageClient.o: imageClient.cc imageClient.h $(PRIMITIVECOMM_DIR)/utils.h - $(CXXCOMPILE) -o $@ $< +# Dependency generation rule +%.d: %.cc + $(DEP_ECHO) + $(Q)$(CXX) -c $(CPPFLAGS) -MM $< | ../fixdepend $(dir $<) > $@ +%.d: %.cpp + $(DEP_ECHO) + $(Q)$(CXX) -c $(CPPFLAGS) -MM $< | ../fixdepend $(dir $<) > $@ + +# Clean rule clean: $(MAKE) -C $(PRIMITIVECOMM_DIR) clean rm -f *.o $(EXECUTABLES) Modified: TeamTalk/Agents/TeamTalkSimulator/TeamTalkSimulator.cc =================================================================== --- TeamTalk/Agents/TeamTalkSimulator/TeamTalkSimulator.cc 2006-12-21 06:00:03 UTC (rev 564) +++ TeamTalk/Agents/TeamTalkSimulator/TeamTalkSimulator.cc 2006-12-21 06:16:02 UTC (rev 565) @@ -39,16 +39,15 @@ map robots; -#define MOAST_DIR "/net/eucalyptus/usr0/tkharris/moast-1.2/" -#define MOAST_BIN "/net/eucalyptus/usr0/tkharris/moast-1.2/bin" #ifndef DEFAULT_NML_FILE -#define DEFAULT_NML_FILE "/net/eucalyptus/usr0/tkharris/moast-1.2/etc/moast.nml" +#define DEFAULT_NML_FILE "moast.nml" #endif #ifndef DEFAULT_INI_FILE -#define DEFAULT_INI_FILE "/net/eucalyptus/usr0/tkharris/moast-1.2/etc/moast.ini" +#define DEFAULT_INI_FILE "moast.ini" #endif #define THIS_PROCESS "sectShell" +static const char* MAP_DUMP = "/tmp/SectMobPLDispOutput.ppm"; char nml_file_default[] = DEFAULT_NML_FILE; char *nml_file_env; @@ -58,6 +57,8 @@ char *INI_FILE = NULL; int bufnum = 1; +string moast_bin; + /****************** MAP STUFF *********************/ static unsigned char* conveyedMap; @@ -77,9 +78,9 @@ Boeing::MsgMap::MsgMapFactory(Boeing::MAP_RLE, msgMap, currentMap, mapWidth*mapHeight, 0, 0, mapWidth, mapHeight); - cerr << "raw: " << msgMap->map[0] - << " rl: " << ((msgMap->map[0]&0xFFFFFF00)>>8) - << " rv: " << (msgMap->map[0]&0x000000FF) << endl; + //debug << "raw: " << msgMap->map[0] + // << " rl: " << ((msgMap->map[0]&0xFFFFFF00)>>8) + // << " rv: " << (msgMap->map[0]&0x000000FF) << endl; mserver->sendFullMap(msgMap); } @@ -88,9 +89,9 @@ Boeing::MsgMap::MsgMapFactory(Boeing::MAP_RLE, msgMap, diffMap, mapWidth*mapHeight, 0, 0, mapWidth, mapHeight); - cerr << "raw: " << msgMap->map[0] - << " rl: " << ((msgMap->map[0]&0xFFFFFF00)>>8) - << " rv: " << (msgMap->map[0]&0x000000FF) << endl; + //debug << "raw: " << msgMap->map[0] + // << " rl: " << ((msgMap->map[0]&0xFFFFFF00)>>8) + // << " rv: " << (msgMap->map[0]&0x000000FF) << endl; mserver->sendDiffMap(msgMap); } @@ -115,12 +116,14 @@ subscribed = false; break; default: - cerr << "unknown or unhandled msgtype: " << msg->hdr.type << endl; + error << "unknown or unhandled msgtype: " << msg->hdr.type << endl; } } else { - if(subscribed) sendDiffMap(mserver); - sleep(updatePeriod); + if(subscribed) + //sendDiffMap(mserver); + sendFullMap(mserver); } + sleep(updatePeriod); } } @@ -131,7 +134,7 @@ for(;;) { const Boeing::MsgTraderServer *msg = tserver->getNextMessage(); if(!msg) { - //cerr << "getNextMessage is NULL" << endl; + //debug << "getNextMessage is NULL" << endl; sleep(1000); continue; } @@ -140,15 +143,15 @@ sectMobPLSetBuf->read(); if(msg->hdr.type != Boeing::TRADER_TASK) { - cerr << "don't know what to do with header type " << msg->hdr.type << endl; + error << "don't know what to do with header type " << msg->hdr.type << endl; continue; } - cerr << "got: " << msg->msg_task.task << endl; + debug << "got: " << msg->msg_task.task << endl; istringstream task(msg->msg_task.task); string token; task >> token; if(token != "search") { - cerr << "don't know how to deal with command " << token << endl; + error << "don't know how to deal with command " << token << endl; continue; } float x, y; @@ -163,13 +166,51 @@ } void readMapData() { - ifstream f("stubdb.txt"); - f >> mapWidth >> mapHeight; + ifstream f(MAP_DUMP); + if(!f) { + error << " can't open map" << endl; + return; + } + string token; + if((f >> token).fail() || token != "P6") { + error << " expected P6: " << token << endl; + return; + } + //int oldMapWidth = mapWidth; + //int oldMapHeight = mapHeight; + if((f >> mapWidth >> mapHeight).fail() || mapWidth <= 0 || mapHeight <= 0) { + error << " expected mapWidth: " + << mapWidth << " mapHeight: " << mapHeight << endl; + return; + } + if((f >> token).fail() || token != "255") { + error << " expected 255: " << token << endl; + return; + } + ignoreToEndOfLine(f); for(int j=0; j> n; - currentMap[j*mapWidth+i] = (unsigned char)n; + char r, g, b; + r = f.get(); + g = f.get(); + b = f.get(); + if(f.fail()) { + error << " failed to read at (" << i << ' ' << j << ')' << endl; + return; + } + if(r == '\0' && g == '\0' && b == '\0') { + //unknown + currentMap[j*mapWidth+i] = 0x40; + } else if(r == '\255' && g == '\0' && b == '\0') { + //obstacle + currentMap[j*mapWidth+i] = 0xff; + } else if(r == '\255' && g == '\255' && b == '\255') { + //unknown + currentMap[j*mapWidth+i] = 0x00; + } else { + error << " unknown encoding at (" << i << ' ' << j << "): (" << (unsigned int)r << ' ' << (unsigned int)g << ' ' << (unsigned int)b << ')' << endl; + return; + } } } } @@ -214,7 +255,7 @@ dump.serial_number = sectMobPLSetPtr->echo_serial_number + 1; dump.skip = 5; dump.dumpContinuous = true; - strcpy(dump.fileName, "/tmp/SectMobPLDispOutput.ppm"); + strcpy(dump.fileName, MAP_DUMP); sectMobPLCfgBuf->write(&dump); } @@ -300,7 +341,7 @@ int retval = initSectMobPLNmlBuffers(NML_FILE, bufnum); if (retval) { - cerr << "TeamTalkSimulator: Can't allocate NML buffers" << endl; + fatal << "TeamTalkSimulator: Can't allocate NML buffers" << endl; return 1; } @@ -315,6 +356,7 @@ SectMobPLCmdInit sectInit = SectMobPLCmdInit(); sectInit.serial_number = sectMobPLStatPtr->echo_serial_number + 1; sectInit.vehList_length = robots.size(); + sectInit.subordinate = VEHICLE; for(int i=0; i about to init Section Control" << endl; initSectionControl(); //start dumping map + debug << " about to mapDump" << endl; mapDump(); //start the trader @@ -405,7 +458,7 @@ pthread_create(&mapThread_, NULL, readMapRequests, (void *) &mserver); //wait for all of the threads to terminate - cerr << "wait for thread termination...\n" << endl; + info << "wait for thread termination...\n" << endl; pthread_join(tradeThread_, NULL); pthread_join(mapThread_, NULL); //should probably also be waiting for robot server handles here Modified: TeamTalk/Agents/TeamTalkSimulator/imageClient.cc =================================================================== --- TeamTalk/Agents/TeamTalkSimulator/imageClient.cc 2006-12-21 06:00:03 UTC (rev 564) +++ TeamTalk/Agents/TeamTalkSimulator/imageClient.cc 2006-12-21 06:16:02 UTC (rev 565) @@ -20,7 +20,7 @@ struct hostent *hostptr; if(!(hostptr = gethostbyname(host.c_str()))) { - cerr << "socket error: cannot find host " << host << endl; + error << "socket error: cannot find host " << host << endl; return; } @@ -52,7 +52,7 @@ struct hostent *hostptr; if(!(hostptr = gethostbyname(host.c_str()))) { - cerr << "socket error: cannot find host " << host << endl; + error << "socket error: cannot find host " << host << endl; return; } @@ -68,12 +68,12 @@ return; } - //cerr << "about to connect" << endl; + //debug << "about to connect" << endl; if (connect(sockfd, (struct sockaddr*) &serv_addr, sizeof(serv_addr)) < 0) { perror("connect"); return; } - //cerr << "connected" << endl; + //debug << "connected" << endl; //if((*image_size = getImage_()) > 0) image = image_; } @@ -86,28 +86,28 @@ int ImageClient::getImage_() { char iType; if(!readn(&iType)) { - cerr << "problem getting image type" << endl; + error << "problem getting image type" << endl; return -1; } - //cerr << "Imgage Type is " << (int)iType << endl; + //debug << "Imgage Type is " << (int)iType << endl; if((int)iType < 1 || (int)iType > 5) { - cerr << "can't deal with image of type " << (int)iType << endl; + error << "can't deal with image of type " << (int)iType << endl; return -1; } char iName[16]; if(!readn(&iName)) { - cerr << "problem reading image name" << endl; + error << "problem reading image name" << endl; return -1; } //cerr << "image name is " << iName << endl; if(!readn(&image_size_)) { - cerr << "problem getting image type" << endl; + error << "problem getting image type" << endl; return -1; } image_size_ = ntohl(image_size_); //cerr << "image size is " << image_size_ << endl; if(image_size_ <= 0) { - cerr << "bad image size: " << image_size_ << endl; + error << "bad image size: " << image_size_ << endl; return -1; } @@ -118,7 +118,7 @@ image_ = (unsigned char*)realloc(image_, max_image_size_ = image_size_); } if(!readn(image_, image_size_)) { - cerr << "problem getting image" << endl; + error << "problem getting image" << endl; return -1; } return image_size_; @@ -126,7 +126,7 @@ int ImageClient::getImage(const unsigned char*& imagePtr) { char ack[] = {'O', 'k', '\n', '\r'}; - //cerr << "sending" << endl; + //debug << "sending" << endl; send(sockfd, ack, 4, 0); if(getImage_() <= 0) { Modified: TeamTalk/Agents/TeamTalkSimulator/robot.cc =================================================================== --- TeamTalk/Agents/TeamTalkSimulator/robot.cc 2006-12-21 06:00:03 UTC (rev 564) +++ TeamTalk/Agents/TeamTalkSimulator/robot.cc 2006-12-21 06:16:02 UTC (rev 565) @@ -8,26 +8,24 @@ #include #include -#define DEBUG 1 #include "robot.h" #include -#define MOAST_DIR "/net/eucalyptus/usr0/tkharris/moast-1.2" -#define MOAST_BIN "/net/eucalyptus/usr0/tkharris/moast-1.2/bin" #ifndef DEFAULT_NML_FILE -#define DEFAULT_NML_FILE "/net/eucalyptus/usr0/tkharris/moast-1.2/etc/moast.nml" +#define DEFAULT_NML_FILE "moast.nml" #endif #ifndef DEFAULT_INI_FILE -#define DEFAULT_INI_FILE "/net/eucalyptus/usr0/tkharris/moast-1.2/etc/moast.ini" +#define DEFAULT_INI_FILE "moast.ini" #endif -#define THIS_PROCESS "vehShell" +#define THIS_PROCESS "TeamTalkSimulator" using namespace std; const unsigned int shift = 6; const unsigned int mask = ~0U << (sizeof(unsigned int)*8 - shift); +extern string moast_bin; int Robot::cleanupVehMobPLNmlBuffers(void) { @@ -39,11 +37,14 @@ delete vehMobPLSetBuf; if (NULL != vehMobPLCfgBuf) delete vehMobPLCfgBuf; + if (NULL != navDataExtBuf) + delete navDataExtBuf; vehMobPLStatBuf = NULL; vehMobPLSetBuf = NULL; vehMobPLCmdBuf = NULL; vehMobPLCfgBuf = NULL; + navDataExtBuf = NULL; return 0; } @@ -130,7 +131,20 @@ vehMobPLSetBuf = 0; return 1; } - + + { + ostringstream chanName; + chanName << NAV_DATA_EXT_NAME << bufnum; + navDataExtBuf = + new NML(navDataExt_format, chanName.str().c_str(), + THIS_PROCESS, config_file); + } + if (!navDataExtBuf->valid()) { + delete navDataExtBuf; + navDataExtBuf = 0; + return 1; + } + return 0; } @@ -173,7 +187,7 @@ << "actual cycleTime: " << statP->cycleTime << endl << "plan cost: " << statP->planCost << endl << "debug: " << setP->debug << endl - << "pose: " << statP->pose << endl + << "pose: " << pose << endl << "message: " << statP->message << endl; } @@ -291,10 +305,11 @@ warn << "got NULL message" << endl; break; } - debug << "got message: " << msg->render() << endl; - //if(!dynamic_cast(msg)) { - // print_debug("got message: "); print_debugln(msg->render()); - //} + if(dynamic_cast(msg)) { + //debug << "got message: " << msg->render() << endl; + } else { + info << "got message: " << msg->render() << endl; + } me->callback(msg, NULL); } sleep(updatePeriod); @@ -360,9 +375,17 @@ } } -float Robot::getX() const {return statP->pose.tran.x;} -float Robot::getY() const {return statP->pose.tran.y;} -float Robot::getYaw() const {return PM_RPY(statP->pose.rot).y;} +float Robot::getX() const {return pose.loc.x;} +float Robot::getY() const {return pose.loc.y;} +//float Robot::getYaw() const {return PM_RPY(statP->pose.rot).y;} +float Robot::getYaw() const {return pose.yaw;} +Pose Robot::getPose() const {return pose;} +void Robot::updatePose() +{ + pose.loc.x = navP->tranAbs.x; + pose.loc.y = navP->tranAbs.y; + pose.yaw = navP->rpyAbs.y; +} Robot::Robot(const map *robs, string name, int simulator_index, unsigned int port) @@ -411,6 +434,7 @@ statP = (VehMobPLStat *) vehMobPLStatBuf->get_address(); primStatP = (PrimMobJAStat *) primMobJAStatBuf->get_address(); setP = (VehMobPLSet *) vehMobPLSetBuf->get_address(); + navP = (NavDataExt *) navDataExtBuf->get_address(); debug << "new robotserver" << endl; server_ = new Boeing::RobotServer(); @@ -437,8 +461,10 @@ vehMobPLStatBuf->read(); vehMobPLSetBuf->read(); primMobJAStatBuf->read(); + navDataExtBuf->read(); + updatePose(); - Msg* temp_message; + //Msg* temp_message; //if(const MsgCmdActionPP* action = dynamic_cast(msgp)) { // //print_debugln("got an action"); // //need to translate txt-based message into typed message @@ -446,7 +472,7 @@ //} else { // temp_message = msgp->clone(); //} - if(const MsgMapReq* req_image = dynamic_cast(temp_message)) { + if(const MsgMapReq* req_image = dynamic_cast(msgp)) { //print_debugln("got an req image"); //get the jpeg from the usarsim video socket const unsigned char* image; @@ -465,21 +491,26 @@ } else { cerr << "Image size is 0" << endl; } - delete temp_message; + //delete temp_message; //print_debugln("done with req image"); return; } - if(dynamic_cast(temp_message)) { + if(dynamic_cast(msgp)) { //print_debugln("got an req location"); server_->sendLocation(getX(), -getY(), canonical_angle(-getYaw()), true); - delete temp_message; + //delete temp_message; return; } //EnterCriticalSection(&CriticalSection); - if(const MsgCmdGoTo* goTo = dynamic_cast(temp_message)) { - cout << "got: " << goTo << endl; + if(const MsgCmdGoTo* goTo = dynamic_cast(msgp)) { + debug << "got: " << goTo << endl; Point vec(goTo->getX(), goTo->getY()); + if(goTo->useAngle()) debug << "useAngle" << endl; + else debug << "!useAngle" << endl; + if(!vec) debug << "!vec" << endl; + else debug << "vec" << endl; if(goTo->useAngle() && !vec) { + debug << "interpreting as turn relative" << endl; PrimMobJACmdRotate rotate = PrimMobJACmdRotate(); float r = -getYaw(); rotate.theta = canonical_angle(-(r+goTo->getAngle())); @@ -491,8 +522,10 @@ Point loc(getX(), getY()); Point destination; if(goTo->isAbsolute()) { + debug << "interpreting as goto absolute" << endl; destination = vec; } else { + debug << "interpreting as goto relative" << endl; destination = loc + Point::Polar(vec.length(), getYaw()+vec.angle()); } @@ -505,15 +538,15 @@ move.startTime = 0; vehMobPLCmdBuf->write(&move); } - delete temp_message; + //delete temp_message; return; - } else if(const MsgCmdHalt* halt = dynamic_cast(temp_message)) { - cout << "got: " << halt << endl; + } else if(const MsgCmdHalt* halt = dynamic_cast(msgp)) { + debug << "got: " << halt << endl; action = WAITING; - delete temp_message; + //delete temp_message; return; - } else if(const MsgCmdHome* home = dynamic_cast(temp_message)) { - cout << "got: " << home << endl; + } else if(const MsgCmdHome* home = dynamic_cast(msgp)) { + debug << "got: " << home << endl; VehMobPLCmdMoveWaypoint move = VehMobPLCmdMoveWaypoint(); move.p.x = 0; move.p.y = 0; @@ -522,25 +555,25 @@ move.neighborhood = 1; move.startTime = 0; vehMobPLCmdBuf->write(&move); - delete temp_message; + //delete temp_message; return; - } else if(const MsgCmdPause* pause = dynamic_cast(temp_message)) { - cout << "got: " << pause << endl; + } else if(const MsgCmdPause* pause = dynamic_cast(msgp)) { + debug << "got: " << pause << endl; if(action != PAUSED) { paused_action = action; action = PAUSED; } - } else if(const MsgCmdResume* resume = dynamic_cast(temp_message)) { - cout << "got: " << resume << endl; + } else if(const MsgCmdResume* resume = dynamic_cast(msgp)) { + debug << "got: " << resume << endl; if(action == PAUSED) { action = paused_action; } - } else if(const MsgCmdFollow* follow = dynamic_cast(temp_message)) { - cout << "got: " << follow << endl; + } else if(const MsgCmdFollow* follow = dynamic_cast(msgp)) { + debug << "got: " << follow << endl; //setFollow(follow->content()->leader); } //LeaveCriticalSection(&CriticalSection); - delete temp_message; + //delete temp_message; } /** @@ -553,27 +586,37 @@ arg << "-i" << sim_index; args.push_back(arg.str()); } - if(sim_index != 1) { + { ostringstream arg; arg << "-s" << sim_index; args.push_back(arg.str()); } + args.push_back("-p2"); //args.push_back("-v"); - spawn(false, MOAST_BIN, "usarSim", args); - sleep(60); + spawn(false, moast_bin, "simWare", args); + sleep(20); args.clear(); { ostringstream arg; + arg << "-i" << sim_index; + args.push_back(arg.str()); + } + pids.push_back(spawn(false, moast_bin, "slamStub", args)); + sleep(2); + + args.clear(); + { + ostringstream arg; arg << "-d" << sim_index; args.push_back(arg.str()); } - if(sim_index==1) sleep(2); - pids.push_back(spawn(false, MOAST_BIN, "primMobMain", args)); - pids.push_back(spawn(false, MOAST_BIN, "primSPMain", args)); - if(sim_index==1) pids.push_back(spawn(false, MOAST_BIN, "primMisMain", args)); + //if(sim_index==1) sleep(2); + pids.push_back(spawn(false, moast_bin, "primMobMain", args)); + pids.push_back(spawn(false, moast_bin, "primSPMain", args)); + //if(sim_index==1) pids.push_back(spawn(false, moast_bin, "primMisMain", args)); sleep(2); - pids.push_back(spawn(false, MOAST_BIN, "amMobMain", args)); + pids.push_back(spawn(false, moast_bin, "amMobMain", args)); args.clear(); args.push_back("-z.1"); @@ -582,7 +625,7 @@ arg << "-d" << sim_index; args.push_back(arg.str()); } - pids.push_back(spawn(false, MOAST_BIN, "amSPMain", args)); + pids.push_back(spawn(false, moast_bin, "amSPMain", args)); args.clear(); args.push_back("-i"); @@ -593,7 +636,7 @@ arg << "-d" << sim_index; args.push_back(arg.str()); } - pids.push_back(spawn(false, MOAST_BIN, "vehMobPLMain", args)); + pids.push_back(spawn(false, moast_bin, "vehMobPLMain", args)); sleep(6); } Modified: TeamTalk/Agents/TeamTalkSimulator/robot.h =================================================================== --- TeamTalk/Agents/TeamTalkSimulator/robot.h 2006-12-21 06:00:03 UTC (rev 564) +++ TeamTalk/Agents/TeamTalkSimulator/robot.h 2006-12-21 06:16:02 UTC (rev 565) @@ -12,10 +12,12 @@ #include // NAV_DATA_BASE, etc. #include // vehMobPL_format() #include // primMobJA_format() +#include // navigation data #include "imageClient.h" using namespace std; +using namespace geometry; //class Robot : public CallBackClass { class Robot { @@ -41,9 +43,12 @@ RCS_STAT_CHANNEL *primMobJAStatBuf; RCS_CMD_CHANNEL *vehMobPLCfgBuf; RCS_STAT_CHANNEL *vehMobPLSetBuf; + NML *navDataExtBuf; VehMobPLStat *statP; VehMobPLSet *setP; PrimMobJAStat *primStatP; + NavDataExt *navP; + Pose pose; int cleanupVehMobPLNmlBuffers(); int initVehMobPLNmlBuffers(char *config, int bufnum); @@ -55,6 +60,8 @@ float getX() const; //current X-coord in globalpos frame in meters float getY() const; //current Y-ccord in globalpos frame in meters float getYaw() const; //current yaw in globalpos frame in radians + Pose getPose() const; + void updatePose(); public: Robot(const map* robots, Modified: TeamTalk/Agents/TeamTalkSimulator/runSimulator.sh =================================================================== --- TeamTalk/Agents/TeamTalkSimulator/runSimulator.sh 2006-12-21 06:00:03 UTC (rev 564) +++ TeamTalk/Agents/TeamTalkSimulator/runSimulator.sh 2006-12-21 06:16:02 UTC (rev 565) @@ -10,9 +10,10 @@ echo " " echo "This script is running on `hostname` " -export CONFIG_NML=/net/eucalyptus/usr0/tkharris/moast-1.2/etc/moast.nml -export CONFIG_INI=/net/eucalyptus/usr0/tkharris/moast-1.2/etc/moast.ini -./TeamTalkSimulator --peerfile peerfile.txt --mapserver +MOAST=${CARTOON_HOME}/moast/devel +export CONFIG_NML=${MOAST}/etc/moast.nml +export CONFIG_INI=${MOAST}/etc/moast.ini +./TeamTalkSimulator --moast $MOAST --peerfile peerfile.txt --mapserver # cd ../../../moast-1.2/bin # HOME=/net/eucalyptus/usr0/tkharris