[TeamTalk 6]: [543] TeamTalk/Agents/PrimitiveComm: Added MsgCmdSetPos class.

tk@edam.speech.cs.cmu.edu tk at edam.speech.cs.cmu.edu
Wed Nov 8 15:05:26 EST 2006


An HTML attachment was scrubbed...
URL: http://mailman.srv.cs.cmu.edu/pipermail/teamtalk-developers/attachments/20061108/8fab39ae/attachment.html
-------------- next part --------------
Modified: TeamTalk/Agents/PrimitiveComm/robot_packet.cpp
===================================================================
--- TeamTalk/Agents/PrimitiveComm/robot_packet.cpp	2006-11-08 16:59:50 UTC (rev 542)
+++ TeamTalk/Agents/PrimitiveComm/robot_packet.cpp	2006-11-08 20:05:26 UTC (rev 543)
@@ -195,7 +195,8 @@
 };
 */
 
-MsgCmdActionPP::MsgCmdActionPP(MsgCmdAction c) : content_(c) {}
+MsgCmdActionPP::MsgCmdActionPP() {}
+MsgCmdActionPP::MsgCmdActionPP(const MsgCmdAction& c) : content_(c) {}
 MsgHeader* MsgCmdActionPP::header() {return (MsgHeader*)&content_;};
 string MsgCmdActionPP::render() const {
 	return content_.action;
@@ -607,3 +608,30 @@
 	retval.len = retval.getSize();
 	return retval;
 }
+
+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_;}
\ No newline at end of file

Modified: TeamTalk/Agents/PrimitiveComm/robot_packet.hpp
===================================================================
--- TeamTalk/Agents/PrimitiveComm/robot_packet.hpp	2006-11-08 16:59:50 UTC (rev 542)
+++ TeamTalk/Agents/PrimitiveComm/robot_packet.hpp	2006-11-08 20:05:26 UTC (rev 543)
@@ -73,15 +73,30 @@
 class MsgCmdActionPP : public Msg {
 	friend class Msg;
 protected:
-  Boeing::MsgCmdAction content_;
+	Boeing::MsgCmdAction content_;
 	Boeing::MsgHeader* header();
+	MsgCmdActionPP();
 public:
-	MsgCmdActionPP(Boeing::MsgCmdAction c);
+	MsgCmdActionPP(const Boeing::MsgCmdAction& c);
 	MsgCmdActionPP(const string& play, int _taskid);
 	string render() const;
 	const Boeing::MsgCmdAction* content() const;
 };
 
+class MsgCmdSetPos : public MsgCmdActionPP {
+private:
+	double x_, y_, angle_;
+protected:
+	static const char *const scan_template;
+	bool parse();
+public:
+	MsgCmdSetPos(const Boeing::MsgCmdAction& c);
+	MsgCmdSetPos(double x, double y, double a);
+	double getX() const;
+	double getY() const;
+	double getAngle() const;
+};
+
 class MsgCmdHaltPP : public Msg {
 	friend class Msg;
 protected:


More information about the TeamTalk-developers mailing list