Skip to content

Commit de4be32

Browse files
committed
introduce sample_rate_hz parameter
1 parent 931d96a commit de4be32

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

cob_hardware_emulation/scripts/emulation_follow_joint_trajectory.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ def __init__(self):
1515

1616
params = rospy.get_param('~')
1717
self.joint_names = params['joint_names']
18+
# fixed frequency to control the granularity of the sampling resolution
19+
self.sample_rate_hz = rospy.get_param("~sample_rate_hz", 10)
20+
# duration from one sample to the next
21+
self.sample_rate_dur_secs = (1.0 / float(self.sample_rate_hz))
22+
# rospy loop rate
23+
self.sample_rate = rospy.Rate(self.sample_rate_hz)
1824

1925
action_name = "joint_trajectory_controller/follow_joint_trajectory"
2026

@@ -83,12 +89,6 @@ def fjta_cb(self, goal):
8389
# linear interpolation of the given trajectory samples is used
8490
# to compute smooth intermediate joints positions at a fixed resolution
8591

86-
# fixed frequency to control the granularity of the sampling resolution
87-
sample_rate_hz = 10
88-
# duration from one sample to the next
89-
sample_rate_dur_secs = (1.0 / float(sample_rate_hz))
90-
# rospy loop rate
91-
sample_rate = rospy.Rate(sample_rate_hz) # 10Hz for now
9292
# upper bound of local duration segment
9393
t1 = point.time_from_start - time_since_start_of_previous_point
9494
# compute velocity as the fraction of distance from prev point to next point in trajectory
@@ -124,9 +124,9 @@ def fjta_cb(self, goal):
124124
self.joint_states.position = interpolated_positions
125125

126126
# sleep until next sample update
127-
sample_rate.sleep()
127+
self.sample_rate.sleep()
128128
# increment passed time
129-
latest_time_from_start += rospy.Duration(sample_rate_dur_secs)
129+
latest_time_from_start += rospy.Duration(self.sample_rate_dur_secs)
130130

131131
# ensure that the goal and time point is always exactly reached
132132
latest_time_from_start = point.time_from_start

0 commit comments

Comments
 (0)