tactile.cpp
Go to the documentation of this file.
1 /*
2 * Copyright 2011 Shadow Robot Company Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16 
28 #include <ros/ros.h>
29 #include <string>
30 
31 #include <boost/thread/mutex.hpp>
32 
33 // messages
34 #include <std_msgs/Float64.h>
35 
36 // a ros subscriber (will be instantiated later on)
38 std_msgs::Float64::_data_type data[5];
39 boost::mutex update_mutex;
40 
41 
42 void callback_ff(const std_msgs::Float64ConstPtr &msg)
43 {
44  update_mutex.lock();
45  data[0] = msg->data;
46  update_mutex.unlock();
47 }
48 
49 void callback_mf(const std_msgs::Float64ConstPtr &msg)
50 {
51  update_mutex.lock();
52  data[1] = msg->data;
53  update_mutex.unlock();
54 }
55 
56 void callback_rf(const std_msgs::Float64ConstPtr &msg)
57 {
58  update_mutex.lock();
59  data[2] = msg->data;
60  update_mutex.unlock();
61 }
62 
63 void callback_lf(const std_msgs::Float64ConstPtr &msg)
64 {
65  update_mutex.lock();
66  data[3] = msg->data;
67  update_mutex.unlock();
68 }
69 
70 void callback_th(const std_msgs::Float64ConstPtr &msg)
71 {
72  update_mutex.lock();
73  data[4] = msg->data;
74  update_mutex.unlock();
75 }
76 
77 
78 int main(int argc, char **argv)
79 {
80  // init the ros node
81  ros::init(argc, argv, "test_tactile");
82 
83  ros::NodeHandle node_tactile;
84 
85  sub[0] = node_tactile.subscribe("/sr_tactile/touch/ff", 2, callback_ff);
86  sub[1] = node_tactile.subscribe("/sr_tactile/touch/mf", 2, callback_mf);
87  sub[2] = node_tactile.subscribe("/sr_tactile/touch/rf", 2, callback_rf);
88  sub[3] = node_tactile.subscribe("/sr_tactile/touch/lf", 2, callback_lf);
89  sub[4] = node_tactile.subscribe("/sr_tactile/touch/th", 2, callback_th);
90 
91  ros::Rate publish_rate = ros::Rate(20.0);
92  std_msgs::Float64::_data_type cur_data[5] = {0};
93 
94  while (ros::ok())
95  {
96  update_mutex.lock();
97  for (int i = 0; i < 5; i++)
98  {
99  cur_data[i] = data[i];
100  }
101  update_mutex.unlock();
102 
103  ROS_ERROR("TACTILE SENSOR READING: %f %f %f %f %f",
104  cur_data[0],
105  cur_data[1],
106  cur_data[2],
107  cur_data[3],
108  cur_data[4]);
109 
110  publish_rate.sleep();
111  ros::spinOnce();
112  }
113 
114  return 0;
115 }
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)
void callback_mf(const std_msgs::Float64ConstPtr &msg)
Definition: tactile.cpp:49
ROSCPP_DECL bool ok()
int main(int argc, char **argv)
Definition: tactile.cpp:78
void callback_th(const std_msgs::Float64ConstPtr &msg)
Definition: tactile.cpp:70
bool sleep()
void callback_rf(const std_msgs::Float64ConstPtr &msg)
Definition: tactile.cpp:56
void callback_ff(const std_msgs::Float64ConstPtr &msg)
Definition: tactile.cpp:42
void callback_lf(const std_msgs::Float64ConstPtr &msg)
Definition: tactile.cpp:63
ros::Subscriber sub[5]
Definition: tactile.cpp:37
boost::mutex update_mutex
Definition: tactile.cpp:39
ROSCPP_DECL void spinOnce()
#define ROS_ERROR(...)
std_msgs::Float64::_data_type data[5]
Definition: tactile.cpp:38


sr_tactile_sensors
Author(s): Ugo Cupcic
autogenerated on Mon Feb 28 2022 23:52:14