tilt_driver.hpp
Go to the documentation of this file.
1 #ifndef TILTDRIVER_H
2 #define TILTDRIVER_H
3 
4 // freenect wrapper
5 
7 #include <ros/ros.h>
8 #include "std_msgs/Int16.h"
9 #include "std_msgs/Float64.h"
10 
12 {
13 
15 {
16 public:
18  cmd_topic_ = "set_tilt_degree";
19  device_ready_ = false;
20  set_degree_ = 0.0;
21  current_degree_ = 0.0;
22  device_ =NULL;
23  }
24 
25  TiltDriver(boost::shared_ptr<FreenectDevice> device,bool * close_tiltThread){
26  close_tiltThread_=close_tiltThread;
27  if(device)
28  {
29  device_=device->device_;
30  device_ready_=true;
31  //ROS_INFO("get you!\n");
32  }
33  else
34  {
35  device_ =NULL;
36  }
37  cmd_topic_ = "set_tilt_degree";
38  set_degree_ = 0.0;
39  current_degree_ = 0.0;
40  //ROS_INFO("get you!\n");
41  }
42 
43  void run(){
44 
45  ros::NodeHandle nodeHandler("tilt");
46  //ROS_INFO("get you6!\n");
47 
48  mTiltPub_=nodeHandler.advertise<std_msgs::Float64>("/current_tilt_degree",1,true);
49  //ROS_INFO("get you2!\n");
50  ros::Subscriber sub = nodeHandler.subscribe(cmd_topic_, 10, &TiltDriver::sendcmd, this);
51  //ROS_INFO("get you7!\n");
52 
53  ros::Rate r(1);//发布周期为1hz
54  //ROS_INFO("get you3!\n");
55  while (!(*close_tiltThread_))
56  {
57  if(device_ready_)
58  {
59  publishState();
60  }
61  r.sleep();
62  }
63 
64  }
65 
66  void sendcmd(const std_msgs::Int16 &set_degree){
67  set_degree_=set_degree.data;
68  if(device_ready_)
69  {
71  {
72  device_ready_=false;
73  }
74  }
75  }
76 
77  void publishState(){
79  {
80  device_ready_=false;
81  ROS_INFO("ERROR: CANNOT UPDATE TILT STATE!\n");
82  return;
83  }
85  std_msgs::Float64 status;
86  status.data=current_degree_;
87  mTiltPub_.publish(status);
88  }
89 private:
93  double set_degree_;
94  std::string cmd_topic_;
98 };
99 
100 
101 }
102 #endif // TILTDRIVER_H
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
freenect_device * device_
the actual openni device
Definition: tilt_driver.hpp:91
int freenect_set_tilt_degs(freenect_device *dev, double angle)
double freenect_get_tilt_degs(freenect_raw_tilt_state *state)
#define ROS_INFO(...)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
freenect_raw_tilt_state * freenect_get_tilt_state(freenect_device *dev)
bool sleep()
int freenect_update_tilt_state(freenect_device *dev)
void sendcmd(const std_msgs::Int16 &set_degree)
Definition: tilt_driver.hpp:66
TiltDriver(boost::shared_ptr< FreenectDevice > device, bool *close_tiltThread)
Definition: tilt_driver.hpp:25


xiaoqiang_freenect_camera
Author(s): Patrick Mihelich, Suat Gedikli, Radu Bogdan Rusu (original openni_camera driver)., Piyush Khandelwal (libfreenect port).
autogenerated on Mon Jun 10 2019 15:53:18