speed_square_wave.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 import rospy
3 from dataspeed_ulc_can import Speed
4 
5 
6 class SpeedSquareWave(Speed):
7 
8  def __init__(self):
9  rospy.init_node('speed_square_wave')
10  super(SpeedSquareWave, self).__init__()
11 
12  def timer_callback(self, event):
13  if self.enabled:
14  if self.v1 == 0 and self.v2 == 0:
15  rospy.logwarn_throttle(1.0, 'both speed targets are zero')
16 
17  if self.t >= self.period:
18  # Reset time when period is reached and switch back to initial speed
19  self.t = 0
20  self.ulc_cmd.linear_velocity = self.v1
21  elif self.t >= 0.5 * self.period:
22  # During second half of period, switch to other speed
23  self.t += 0.02
24  self.ulc_cmd.linear_velocity = self.v2
25  else:
26  # During first half of period, use initial speed
27  self.t += 0.02
28  self.ulc_cmd.linear_velocity = self.v1
29 
30  self.pub_ulc_cmd.publish(self.ulc_cmd)
31 
32 
33 if __name__ == '__main__':
34  try:
35  node_instance = SpeedSquareWave()
36  rospy.spin()
37  except rospy.ROSInterruptException:
38  pass


dataspeed_ulc_can
Author(s): Micho Radovnikovich
autogenerated on Thu Jul 9 2020 03:45:43