Main Page
Classes
Class List
Class Members
All
Functions
Variables
Files
File List
File Members
All
a
c
d
g
m
o
Functions
a
c
m
Variables
Typedefs
talker
talker.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2008, Morgan Quigley and Willow Garage, Inc.
3
*
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
6
* * Redistributions of source code must retain the above copyright notice,
7
* this list of conditions and the following disclaimer.
8
* * Redistributions in binary form must reproduce the above copyright
9
* notice, this list of conditions and the following disclaimer in the
10
* documentation and/or other materials provided with the distribution.
11
* * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its
12
* contributors may be used to endorse or promote products derived from
13
* this software without specific prior written permission.
14
*
15
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25
* POSSIBILITY OF SUCH DAMAGE.
26
*/
27
// %Tag(FULLTEXT)%
28
// %Tag(ROS_HEADER)%
29
#include "
ros/ros.h
"
30
// %EndTag(ROS_HEADER)%
31
// %Tag(MSG_HEADER)%
32
#include "std_msgs/String.h"
33
// %EndTag(MSG_HEADER)%
34
35
#include <sstream>
36
40
int
main
(
int
argc,
char
**argv)
41
{
52
// %Tag(INIT)%
53
ros::init
(argc, argv,
"talker"
);
54
// %EndTag(INIT)%
55
61
// %Tag(NODEHANDLE)%
62
ros::NodeHandle
n;
63
// %EndTag(NODEHANDLE)%
64
82
// %Tag(PUBLISHER)%
83
ros::Publisher
chatter_pub = n.
advertise
<std_msgs::String>(
"chatter"
, 1000);
84
// %EndTag(PUBLISHER)%
85
86
// %Tag(LOOP_RATE)%
87
ros::Rate
loop_rate(10);
88
// %EndTag(LOOP_RATE)%
89
94
// %Tag(ROS_OK)%
95
int
count = 0;
96
while
(
ros::ok
())
97
{
98
// %EndTag(ROS_OK)%
102
// %Tag(FILL_MESSAGE)%
103
std_msgs::String msg;
104
105
std::stringstream ss;
106
ss <<
"hello world "
<< count;
107
msg.data = ss.str();
108
// %EndTag(FILL_MESSAGE)%
109
110
// %Tag(ROSCONSOLE)%
111
ROS_INFO
(
"%s"
, msg.data.c_str());
112
// %EndTag(ROSCONSOLE)%
113
120
// %Tag(PUBLISH)%
121
chatter_pub.
publish
(msg);
122
// %EndTag(PUBLISH)%
123
124
// %Tag(SPINONCE)%
125
ros::spinOnce
();
126
// %EndTag(SPINONCE)%
127
128
// %Tag(RATE_SLEEP)%
129
loop_rate.sleep();
130
// %EndTag(RATE_SLEEP)%
131
++count;
132
}
133
134
135
return
0;
136
}
137
// %EndTag(FULLTEXT)%
ros::Publisher
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
ros.h
ros::spinOnce
ROSCPP_DECL void spinOnce()
ros::Publisher::publish
void publish(const boost::shared_ptr< M > &message) const
ros::NodeHandle::advertise
Publisher advertise(AdvertiseOptions &ops)
ros::ok
ROSCPP_DECL bool ok()
main
int main(int argc, char **argv)
Definition:
talker.cpp:40
ros::Rate
ROS_INFO
#define ROS_INFO(...)
ros::NodeHandle
roscpp_tutorials
Author(s): Morgan Quigley, Dirk Thomas
autogenerated on Fri Jun 24 2022 02:27:48