Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include <ros/ros.h>
00040 #include <visualization_msgs/Marker.h>
00041 #include <visualization_msgs/MarkerArray.h>
00042 #include <vector>
00043 #include <math.h>
00044 #include <proximity_sensor_driver/prox_sensor_measurement.h>
00045
00046 using namespace std;
00047
00048
00049 int sensor_count = 0;
00050 vector<int> sensor_measurements;
00051
00052
00053 void proxSensorDataCallback( const boost::shared_ptr<proximity_sensor_driver::prox_sensor_measurement const> &msg )
00054 {
00055 for( int int_current_patch = 0; int_current_patch < sensor_count; int_current_patch++ )
00056 {
00057 sensor_measurements[int_current_patch] = abs( msg->value[int_current_patch] - msg->offset[int_current_patch] );
00058 }
00059 return;
00060 }
00061
00062
00063 template <class T>
00064 inline void readParam( const ros::NodeHandle &nh, const std::string &str_name, T &rhs )
00065 {
00066 if( !nh.getParam(str_name, rhs) )
00067 {
00068 ROS_ERROR("Could not find parameter %s", str_name.c_str());
00069 exit(1);
00070 }
00071 return;
00072 }
00073
00074
00075 int main( int argc, char** argv )
00076 {
00077 ros::init( argc, argv, "visualize_patches" );
00078 ros::NodeHandle nh;
00079
00080
00081 int int_noise;
00082 int int_min_intensity;
00083 readParam( nh, "/prox_sensor_driver/sensor_count", sensor_count );
00084 readParam( nh, "/prox_sensor_driver/noise_threshold", int_noise );
00085 readParam( nh, "/prox_sensor_driver/static_threshold", int_min_intensity );
00086 sensor_measurements.resize( sensor_count );
00087
00088
00089 ros::Subscriber prox_sensor_sub = nh.subscribe( "/prox_sensor_data", 100, proxSensorDataCallback );
00090 ros::Publisher marker_pub = nh.advertise<visualization_msgs::MarkerArray>( "proximity_sensor_marker_array", 20 );
00091 ros::Publisher fake_pub = nh.advertise<visualization_msgs::Marker>( "proximity_sensor_marker", 20 );
00092
00093 visualization_msgs::Marker patch;
00094 visualization_msgs::Marker arrow;
00095
00096
00097 patch.ns = "patches";
00098 patch.type = visualization_msgs::Marker::CYLINDER;
00099 patch.action = visualization_msgs::Marker::ADD;
00100 patch.pose.position.x = 0;
00101 patch.pose.position.y = 0;
00102 patch.pose.position.z = 0;
00103 patch.pose.orientation.x = 0;
00104 patch.pose.orientation.y = sqrt(0.5);
00105 patch.pose.orientation.z = 0;
00106 patch.pose.orientation.w = sqrt(0.5);
00107 patch.scale.x = 0.06;
00108 patch.scale.y = 0.06;
00109 patch.scale.z = 0.005;
00110 patch.color.b = 0.0;
00111 patch.color.a = 0.6;
00112 patch.lifetime = ros::Duration();
00113
00114
00115 arrow.ns = "arrows";
00116
00117 arrow.type = visualization_msgs::Marker::TEXT_VIEW_FACING;
00118 arrow.action = visualization_msgs::Marker::ADD;
00119 arrow.pose.position.x = 0.01;
00120 arrow.pose.position.y = 0;
00121 arrow.pose.position.z = 0;
00122 arrow.pose.orientation.x = 0;
00123 arrow.pose.orientation.y = 0;
00124 arrow.pose.orientation.z = 0;
00125 arrow.pose.orientation.w = 1;
00126 arrow.scale.x = 0.075;
00127 arrow.scale.y = 0.075;
00128 arrow.scale.z = 0.025;
00129 arrow.color.g = 1.0;
00130 arrow.color.b = 1.0;
00131 arrow.color.a = 0.6;
00132 arrow.lifetime = ros::Duration();
00133
00134
00135
00136
00137 ros::Rate r(5);
00138
00139 while( ros::ok() )
00140 {
00141 visualization_msgs::MarkerArray marker_array;
00142 ros::spinOnce();
00143
00144
00145 for( int int_current_patch = 0; int_current_patch < sensor_count; int_current_patch++ )
00146 {
00147
00148 patch.header.frame_id = "/patch_" + boost::lexical_cast<string>( int_current_patch );
00149 patch.header.stamp = ros::Time(0);
00150 patch.id = int_current_patch;
00151
00152
00153 if( sensor_measurements[int_current_patch] >= int_min_intensity + int_noise )
00154 {
00155 patch.color.r = 1.0;
00156 patch.color.g = 0.0;
00157 }
00158 else
00159 {
00160 patch.color.r = 0.0;
00161 patch.color.g = 1.0;
00162 }
00163
00164 marker_array.markers.push_back( patch );
00165
00166
00167
00168 arrow.header.frame_id = "/patch_" + boost::lexical_cast<string>( int_current_patch );
00169 arrow.header.stamp = ros::Time(0);
00170 arrow.id = int_current_patch;
00171
00172
00173 if( sensor_measurements[int_current_patch] >= int_min_intensity + int_noise )
00174 {
00175 arrow.color.r = 1.0;
00176 arrow.text = boost::lexical_cast<string>( int_current_patch );
00177 }
00178 else
00179 {
00180 arrow.color.r = (double)(sensor_measurements[int_current_patch] - int_noise) / (double)int_min_intensity;
00181 arrow.text = boost::lexical_cast<string>( int_current_patch );
00182 }
00183
00184 marker_array.markers.push_back( arrow );
00185 }
00186 marker_pub.publish( marker_array );
00187 r.sleep();
00188 }
00189
00190 return 0;
00191 }
00192