Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * talkerpub_thread.cpp - Publish talker messages via ROS 00004 * 00005 * Created: Thu May 05 18:50:04 2011 00006 * Copyright 2006-2011 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU Library General Public License for more details. 00019 * 00020 * Read the full text in the LICENSE.GPL file in the doc directory. 00021 */ 00022 00023 #include "talkerpub_thread.h" 00024 00025 #include <ros/ros.h> 00026 #include <std_msgs/String.h> 00027 00028 using namespace fawkes; 00029 00030 /** @class ROSTalkerPubThread "talkerpub_thread.h" 00031 * Thread to publish messages via ROS. 00032 * 00033 * @author Tim Niemueller 00034 */ 00035 00036 /** Constructor. */ 00037 ROSTalkerPubThread::ROSTalkerPubThread() 00038 : Thread("ROSTalkerPubThread", Thread::OPMODE_WAITFORWAKEUP), 00039 BlockedTimingAspect(BlockedTimingAspect::WAKEUP_HOOK_ACT) 00040 { 00041 } 00042 00043 00044 /** Destructor. */ 00045 ROSTalkerPubThread::~ROSTalkerPubThread() 00046 { 00047 } 00048 00049 00050 void 00051 ROSTalkerPubThread::init() 00052 { 00053 __pub = rosnode->advertise<std_msgs::String>("/chatter", 10); 00054 } 00055 00056 00057 void 00058 ROSTalkerPubThread::finalize() 00059 { 00060 __pub.shutdown(); 00061 } 00062 00063 00064 void 00065 ROSTalkerPubThread::loop() 00066 { 00067 Time t; 00068 00069 std_msgs::String msg; 00070 msg.data = std::string("Hello world ") + t.str(); 00071 00072 __pub.publish(msg); 00073 }