testbb.cpp
Go to the documentation of this file.
1 
23 #include "testbb/testbb.h"
24 
25 // Register the application
27 
28 namespace testbb{
29 
30  TestBb::TestBb() {}
31 
32  TestBb::~TestBb() {}
33 
34  void TestBb::init() {}
35 
36  void TestBb::stop() {}
37 
38  void TestBb::baseCallback(const nav_msgs::Odometry& lmsg)
39  {
40  static int msg_count = 0;
41  float x=lmsg.pose.pose.position.x;
42  float y=lmsg.pose.pose.position.y;
43 
44  float vx=lmsg.twist.twist.linear.x;
45  float vy=lmsg.twist.twist.linear.y;
46 
47  micros_swarm::Base l(x, y, 0, vx, vy, 0, 1);
48  set_base(l);
49 
50  msg_count++;
51  if(msg_count >= 5) {
52  std::cout<<"shutdown sub"<<std::endl;
53  sub.shutdown();
54  }
55  //std::cout<<"<<<"<<x<<", "<<y<<">>>"<<std::endl;
56  }
57 
58  void TestBb::loop_put(const ros::TimerEvent&)
59  {
60  static int count=0;
61  std::string robot_id_string="robot_"+boost::lexical_cast<std::string>(get_id());
62  std_msgs::Int32 val;
63  val.data = get_id()+count;
64  bb.put(robot_id_string, val);
65  count++;
66  }
67 
68  void TestBb::loop_get(const ros::TimerEvent&)
69  {
70  std::string robot_id_string="robot_"+boost::lexical_cast<std::string>(get_id());
71  std_msgs::Int32 val = bb.get(robot_id_string);
72  std::cout<<robot_id_string<<": "<<val.data<<std::endl;
73  }
74 
75  void TestBb::start()
76  {
77  ros::NodeHandle nh;
78  sub = nh.subscribe("base_pose_ground_truth", 1000, &TestBb::baseCallback, this, ros::TransportHints().udp());
79  ros::Duration(1).sleep();
81 
82  //test put
83  //timer = nh.createTimer(ros::Duration(0.1), &TestBb::loop_put, this);
84 
85  //test get
86  std::string robot_id_string="robot_" + boost::lexical_cast<std::string>(get_id());
87  std_msgs::Int32 val;
88  val.data = get_id();
89  bb.put(robot_id_string, val);
90  timer = nh.createTimer(ros::Duration(0.1), &TestBb::loop_get, this);
91  }
92 };
93 
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
bool sleep() const
Definition: testbb.h:33
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)


testbb
Author(s):
autogenerated on Mon Jun 10 2019 14:02:31