00001 /********************************************************************* 00002 * 00003 * Software License Agreement (BSD License) 00004 * 00005 * Copyright (c) 2011, Robert Bosch LLC. 00006 * All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 00012 * * Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * * Redistributions in binary form must reproduce the above 00015 * copyright notice, this list of conditions and the following 00016 * disclaimer in the documentation and/or other materials provided 00017 * with the distribution. 00018 * * Neither the name of the Robert Bosch nor the names of its 00019 * contributors may be used to endorse or promote products derived 00020 * from this software without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00023 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00024 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00025 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00026 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00027 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00028 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00029 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00030 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00032 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00033 * POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 *********************************************************************/ 00036 00037 //\Author Adrian Funk, Bosch LLC 00038 00039 // This node fakes data of the proximity sensor 00040 // This might be useful for debugging reasons with the skin 00041 00042 #include <ros/ros.h> 00043 #include <proximity_sensor_driver/prox_sensor_measurement.h> 00044 #include <proximity_sensor_driver/reinitialize_proximity_sensor.h> 00045 #include <time.h> 00046 00047 // Fake the maximum amount of possible patches 00048 const int INT_FAKED_PATCHES = 192; 00049 00050 // Fake callback for the reinit service 00051 bool reinitialize_callback( proximity_sensor_driver::reinitialize_proximity_sensor::Request &req, 00052 proximity_sensor_driver::reinitialize_proximity_sensor::Response &res) 00053 { 00054 ROS_INFO("Reconfigure callback executed!"); 00055 return(true); 00056 } 00057 00058 int main(int argc, char **argv) 00059 { 00060 srand(time(NULL)); 00061 ros::init(argc, argv, "fake_skin_data"); 00062 ros::NodeHandle nh; 00063 00064 ros::Publisher prox_data_pub = nh.advertise<proximity_sensor_driver::prox_sensor_measurement>("prox_sensor_data", 100); 00065 ros::ServiceServer prox_serv = nh.advertiseService("reinitialize_proximity_sensor", reinitialize_callback); 00066 00067 // Fake data in an endless loop at 15hz 00068 ros::Rate loop_rate(15); 00069 int int_count = 1; 00070 while(ros::ok()) 00071 { 00072 // Execute Callback from reconfigure 00073 ros::spinOnce(); 00074 // Build the message 00075 proximity_sensor_driver::prox_sensor_measurement prox_data; 00076 prox_data.header.stamp = ros::Time::now(); 00077 prox_data.header.seq = int_count; 00078 prox_data.cell_count = INT_FAKED_PATCHES; 00079 prox_data.is_connected = true; 00080 prox_data.status_err = false; 00081 prox_data.status_go = true; 00082 00083 for(int a = 0; a < INT_FAKED_PATCHES; a++) 00084 { 00085 prox_data.value[a] = rand() % 255; // Create some random readings 00086 prox_data.offset[a] = 120; // But keep a constant offset 00087 prox_data.limit[a] = 8; 00088 } 00089 00090 prox_data_pub.publish(prox_data); 00091 00092 loop_rate.sleep(); 00093 int_count++; 00094 } 00095 00096 return(0); 00097 }