00001 /********************************************************************* 00002 * 00003 * Software License Agreement (BSD License) 00004 * 00005 * Copyright (c) 2012, University of Pennsylvania 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 University of Pennsylvania 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 * Author: Ian McMahon (imcmahon@grasp.upenn.edu) 00036 *********************************************************************/ 00037 00038 #include <ros/ros.h> 00039 #include <biotac_sensors/biotac_hand_class.h> 00040 #include <biotac_sensors/BioTacHand.h> 00041 00042 using namespace std; 00043 using namespace biotac; 00044 00045 00046 int main(int argc, char** argv) 00047 { 00048 //Initialize ROS node 00049 ros::init(argc, argv, "biotac_sensors_pub", ros::init_options::AnonymousName); 00050 ros::NodeHandle n; 00051 //Loop at 100Hz 00052 ros::Rate loop_rate(100); 00053 //Advertise on "biotac_pub" topic 00054 ros::Publisher biotac_pub = n.advertise<biotac_sensors::BioTacHand>("biotac_pub", 1000); 00055 //Create a blank message to publish 00056 biotac_sensors::BioTacHand bt_hand_msg; 00057 //Check if a null_message parameter was set & publish zero data if so 00058 if(n.hasParam(ros::this_node::getName() + "/null_msg")) 00059 { 00060 biotac_sensors::BioTacData biotac_finger; 00061 bt_hand_msg.bt_data.push_back(biotac_finger); 00062 bt_hand_msg.bt_data[0].bt_serial = "Foo"; 00063 bt_hand_msg.bt_data.push_back(biotac_finger); 00064 bt_hand_msg.bt_data[1].bt_serial = "Bar"; 00065 bt_hand_msg.hand_id = "Null_Data"; 00066 while(ros::ok()) 00067 { 00068 biotac_pub.publish(bt_hand_msg); 00069 loop_rate.sleep(); 00070 } 00071 } 00072 else //Start the node normally 00073 { 00074 //Name the BioTac hand that will be published 00075 BioTacHandClass left_hand("left_hand"); 00076 //Connect to and configure the sensors 00077 left_hand.initBioTacSensors(); 00078 00079 while(ros::ok()) 00080 { //Collect a batch of data 00081 bt_hand_msg = left_hand.collectBatch(); 00082 biotac_pub.publish(bt_hand_msg); 00083 loop_rate.sleep(); 00084 } 00085 } 00086 return 0; 00087 }