sim_sensor.py
Go to the documentation of this file.
1 #! /usr/bin/python
2 
3 #***********************************************************
4 #* Software License Agreement (BSD License)
5 #*
6 #* Copyright (c) 2009, Willow Garage, Inc.
7 #* All rights reserved.
8 #*
9 #* Redistribution and use in source and binary forms, with or without
10 #* modification, are permitted provided that the following conditions
11 #* are met:
12 #*
13 #* * Redistributions of source code must retain the above copyright
14 #* notice, this list of conditions and the following disclaimer.
15 #* * Redistributions in binary form must reproduce the above
16 #* copyright notice, this list of conditions and the following
17 #* disclaimer in the documentation and/or other materials provided
18 #* with the distribution.
19 #* * Neither the name of the Willow Garage nor the names of its
20 #* contributors may be used to endorse or promote products derived
21 #* from this software without specific prior written permission.
22 #*
23 #* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 #* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 #* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 #* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 #* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 #* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 #* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 #* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 #* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 #* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 #* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 #* POSSIBILITY OF SUCH DAMAGE.
35 #***********************************************************
36 
37 # Author: Blaise Gassend
38 
39 # Simulates the presence of a fingertip sensor
40 
41 import roslib
42 roslib.load_manifest('fingertip_pressure')
43 import rospy
44 from math import sin, cos
45 import threading
46 
47 from pr2_msgs.msg import PressureState
48 
50  def callback(self, pressurestate):
51  #print "callback"
52  self.l_finger_tip = pressurestate.l_finger_tip
53  self.r_finger_tip = pressurestate.r_finger_tip
54  self.datatimestamp = pressurestate.header.stamp
55  self.dataready = True
56 
57  def publish(self):
58  ps = PressureState()
59  ps.header.stamp = rospy.get_rostime();
60  ps.l_finger_tip = []
61  ps.r_finger_tip = []
62  t = rospy.get_time()
63  for i in range(0,22):
64  ph = .1 * t * (i / 22. + 1)
65  ps.l_finger_tip.append(4000*(1+sin(ph)))
66  ps.r_finger_tip.append(4000*(1+cos(ph)))
67  self.pub.publish(ps)
68 
69  def __init__(self, dest):
70  rospy.init_node('sim_sensor', anonymous=True)
71  rospy.sleep(.2)
72 
73  self.pub = rospy.Publisher(dest, PressureState)
74 
75 
76 if __name__ == '__main__':
77  #@todo it would be nice to read an xml configuration file to get these parameters.
78  s1 = pressureSimulator('pressure/r_gripper_motor')
79  s2 = pressureSimulator('pressure/l_gripper_motor')
80 
81  while not rospy.is_shutdown():
82  rospy.sleep(0.1)
83  s1.publish()
84  s2.publish()
def __init__(self, dest)
Definition: sim_sensor.py:69
def callback(self, pressurestate)
Definition: sim_sensor.py:50


fingertip_pressure
Author(s): Blaise Gassend
autogenerated on Fri Mar 15 2019 02:53:38