subscriber.cpp
Go to the documentation of this file.
1 // Test subscriber
2 // Author: Max Schwarz <max.schwarz@uni-bonn.de>
3 
4 #include <ros/publisher.h>
5 #include <ros/init.h>
6 #include <ros/node_handle.h>
7 
8 #include <std_msgs/Int8MultiArray.h>
9 
10 #include <stdio.h>
11 
12 void handleMsg(const std_msgs::Int8MultiArray& msg)
13 {
14  static uint8_t previous = 0;
15  uint8_t current = msg.data[0];
16  uint8_t diff = current - previous;
17  if (diff != 1)
18  {
19  ROS_WARN("Missing %u message(s)", diff - 1);
20  }
21  ROS_INFO("Got message %u", current);
22  previous = msg.data[0];
23 }
24 
25 int main(int argc, char** argv)
26 {
27  ros::init(argc, argv, "subscriber");
29  ros::Subscriber sub = n.subscribe("data", 1, &handleMsg, ros::TransportHints().udp());
30  ros::spin();
31  return 0;
32 }
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
#define ROS_WARN(...)
void handleMsg(const std_msgs::Int8MultiArray &msg)
Definition: subscriber.cpp:12
#define ROS_INFO(...)
ROSCPP_DECL void spin()
int main(int argc, char **argv)
Definition: subscriber.cpp:25


test_roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim, Dirk Thomas
autogenerated on Mon Nov 2 2020 03:52:46