Skip to content

Commit

Permalink
Modify throttle interpolator to publish on msg receipt (f1tenth#2)
Browse files Browse the repository at this point in the history
* Modify throttle interpolator to publish on msg receipt
  • Loading branch information
tbalch-tri authored and GitHub Enterprise committed Dec 6, 2021
1 parent 193362a commit fac7b6b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ackermann_cmd_mux/src/throttle_interpolator.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def __init__(self):
# Create topic subscribers and publishers
self.rpm_output = rospy.Publisher(self.rpm_output_topic, Float64,queue_size=1)
self.servo_output = rospy.Publisher(self.servo_output_topic, Float64,queue_size=1)

# Create throttle timeout
self.throttle_timeout = rospy.get_param('throttle_timeout', default=1.0)
self.last_throttle_time = rospy.Time.now()

rospy.Subscriber(self.rpm_input_topic, Float64, self._process_throttle_command)
rospy.Subscriber(self.servo_input_topic, Float64, self._process_servo_command)
Expand All @@ -62,13 +66,15 @@ def _publish_throttle_command(self, evt):
smoothed_rpm = self.last_rpm + clipped_delta
self.last_rpm = smoothed_rpm
# print self.desired_rpm, smoothed_rpm
self.rpm_output.publish(Float64(smoothed_rpm))
if rospy.Time.now() - self.last_throttle_time < self.throttle_timeout:
self.rpm_output.publish(Float64(smoothed_rpm))

def _process_throttle_command(self,msg):
input_rpm = msg.data
# Do some sanity clipping
input_rpm = min(max(input_rpm, self.min_rpm), self.max_rpm)
self.desired_rpm = input_rpm
self.last_throttle_time = rospy.Time.now()

def _publish_servo_command(self, evt):
desired_delta = self.desired_servo_position-self.last_servo
Expand Down

0 comments on commit fac7b6b

Please sign in to comment.