1
+ /* *
2
+ * custom_msg_simple_node.cpp
3
+ *
4
+ * Created on: September 08, 2014
5
+ * Author: Shehzad Ahmed
6
+ **/
7
+
8
+ #include < ros/ros.h>
9
+ #include < custom_msg_example1/NodeInfo.h>
10
+ #include < custom_msg_example1/NodesInfo.h>
11
+
12
+
13
+
14
+ int main (int argc, char *argv[])
15
+ {
16
+ /* *
17
+ * Initilization of ROS
18
+ **/
19
+ ros::init (argc, argv, " custom_msg_simple_node" );
20
+
21
+ /* *
22
+ * Initilization of node by using node handle
23
+ **/
24
+ ros::NodeHandle nh (" ~" );
25
+
26
+ /* *
27
+ * Printing Information message on the console.
28
+ **/
29
+ ROS_INFO (" custom_msg_cpp_simple_node is now running" );
30
+
31
+ /*
32
+ * Filling a simple custom message
33
+ */
34
+ custom_msg_example1::NodeInfo node_info_msg;
35
+
36
+ node_info_msg.node_name .data = " custom_msg_cpp_simple_node" ;
37
+ node_info_msg.node_status .data = false ;
38
+ node_info_msg.node_id .data = 1 ;
39
+
40
+ /*
41
+ * Filling a an array custom message
42
+ */
43
+ int number_of_nodes = 5 ;
44
+ custom_msg_example1::NodesInfo nodes_info_msg;
45
+ nodes_info_msg.node_name .resize (number_of_nodes);
46
+ nodes_info_msg.node_status .resize (number_of_nodes);
47
+ nodes_info_msg.node_id .resize (number_of_nodes);
48
+
49
+ for (int i=0 ;i < number_of_nodes; i++) {
50
+ nodes_info_msg.node_name .at (i).data = " custom_msg_cpp_simple_node " ;
51
+ nodes_info_msg.node_status .at (i).data = false ;
52
+ nodes_info_msg.node_id .at (i).data = i;
53
+ }
54
+
55
+ /* *
56
+ * Running a thread to keep spinning untill the user kills the node.
57
+ **/
58
+ ros::spin ();
59
+
60
+ return 0 ;
61
+ }
0 commit comments