mvsim-subscriber-example.cpp
Go to the documentation of this file.
1 
2 #include <mvsim/Comms/Client.h>
3 #include <mvsim/mvsim-msgs/GenericObservation.pb.h>
4 #include <mvsim/mvsim-msgs/TimeStampedPose.pb.h>
5 
6 #include <mrpt/obs/CObservation2DRangeScan.h>
7 
8 #include <chrono>
9 #include <iostream>
10 #include <thread>
11 
12 void myPoseCallback(const mvsim_msgs::TimeStampedPose& p)
13 {
14  std::cout << "topic callback: " << p.DebugString() << std::endl;
15 }
16 
17 void mySensorCallback(const mvsim_msgs::GenericObservation& o)
18 {
19  const std::vector<uint8_t> data(
20  o.mrptserializedobservation().begin(),
21  o.mrptserializedobservation().end());
22 
23  mrpt::serialization::CSerializable::Ptr obj;
25 
26  mrpt::obs::CObservation::Ptr obs =
27  std::dynamic_pointer_cast<mrpt::obs::CObservation>(obj);
28  ASSERT_(obs);
29 
30  std::cout << "sensor callback: " << obs->getDescriptionAsTextValue()
31  << "\n";
32 }
33 
34 int main(int argc, char** argv)
35 {
36  try
37  {
38  mvsim::Client client("mvsim-subscriber-example");
39  client.setVerbosityLevel(mrpt::system::LVL_DEBUG);
40 
41  client.connect();
42 
43  client.subscribeTopic<mvsim_msgs::TimeStampedPose>(
44  "/r1/pose", myPoseCallback);
45 
46  client.subscribeTopic<mvsim_msgs::GenericObservation>(
47  "/r1/laser1", mySensorCallback);
48 
49  std::this_thread::sleep_for(std::chrono::seconds(5));
50 
51  return 0;
52  }
53  catch (const std::exception& e)
54  {
55  std::cerr << mrpt::exception_to_str(e);
56  return 1;
57  }
58 }
void BASE_IMPEXP OctetVectorToObject(const vector_byte &in_data, CSerializablePtr &obj)
void subscribeTopic(const std::string &topicName, const std::function< void(const MSG_T &)> &callback)
Definition: Client.h:178
int main(int argc, char **argv)
void mySensorCallback(const mvsim_msgs::GenericObservation &o)
obs
GLhandleARB obj
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
GLfloat GLfloat p
void myPoseCallback(const mvsim_msgs::TimeStampedPose &p)
#define ASSERT_(f)


mvsim
Author(s):
autogenerated on Fri May 7 2021 03:05:51