publishers.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 """
4  diagnostics.py - diagnostic output code
5  Copyright (c) 2011 Vanadium Labs LLC. All right reserved.
6 
7  Redistribution and use in source and binary forms, with or without
8  modification, are permitted provided that the following conditions are met:
9  * Redistributions of source code must retain the above copyright
10  notice, this list of conditions and the following disclaimer.
11  * Redistributions in binary form must reproduce the above copyright
12  notice, this list of conditions and the following disclaimer in the
13  documentation and/or other materials provided with the distribution.
14  * Neither the name of Vanadium Labs LLC nor the names of its
15  contributors may be used to endorse or promote products derived
16  from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  DISCLAIMED. IN NO EVENT SHALL VANADIUM LABS BE LIABLE FOR ANY DIRECT, INDIRECT,
22  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 """
29 
30 import rospy
31 from diagnostic_msgs.msg import DiagnosticArray
32 from sensor_msgs.msg import JointState
33 
35  """ Class to handle publications of joint_states message. """
36 
37  def __init__(self):
38  self.t_delta = rospy.Duration(1.0/rospy.get_param("~diagnostic_rate", 1.0))
39  self.t_next = rospy.Time.now() + self.t_delta
40  self.pub = rospy.Publisher('diagnostics', DiagnosticArray, queue_size=5)
41 
42  def update(self, joints, controllers):
43  """ Publish diagnostics. """
44  now = rospy.Time.now()
45  if now > self.t_next:
46  # create message
47  msg = DiagnosticArray()
48  msg.header.stamp = now
49  for controller in controllers:
50  d = controller.getDiagnostics()
51  if d:
52  msg.status.append(d)
53  for joint in joints:
54  d = joint.getDiagnostics()
55  if d:
56  msg.status.append(d)
57  # publish and update stats
58  self.pub.publish(msg)
59  self.t_next = now + self.t_delta
60 
61 
63  """ Class to handle publications of joint_states message. """
64 
65  def __init__(self):
66  # parameters: throttle rate and geometry
67  self.rate = rospy.get_param("~read_rate", 10.0)
68  self.t_delta = rospy.Duration(1.0/self.rate)
69  self.t_next = rospy.Time.now() + self.t_delta
70 
71  # subscriber
72  self.pub = rospy.Publisher('joint_states', JointState, queue_size=5)
73 
74  def update(self, joints, controllers):
75  """ publish joint states. """
76  if rospy.Time.now() > self.t_next:
77  msg = JointState()
78  msg.header.stamp = rospy.Time.now()
79  msg.name = list()
80  msg.position = list()
81  msg.velocity = list()
82  for joint in joints:
83  msg.name.append(joint.name)
84  msg.position.append(joint.position)
85  msg.velocity.append(joint.velocity)
86  for controller in controllers:
87  msg.name += controller.joint_names
88  msg.position += controller.joint_positions
89  msg.velocity += controller.joint_velocities
90  self.pub.publish(msg)
91  self.t_next = rospy.Time.now() + self.t_delta
92 
def update(self, joints, controllers)
Definition: publishers.py:74
def update(self, joints, controllers)
Definition: publishers.py:42


arbotix_python
Author(s): Michael Ferguson
autogenerated on Mon Feb 28 2022 21:37:42