misc_hvac_cmd.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Software License Agreement (Proprietary and Confidential)
4 #
5 # Copyright (c) 2019, Dataspeed Inc.
6 # All rights reserved.
7 #
8 # NOTICE: All information contained herein is, and remains the property of
9 # Dataspeed Inc. The intellectual and technical concepts contained herein are
10 # proprietary to Dataspeed Inc. and may be covered by U.S. and Foreign Patents,
11 # patents in process, and are protected by trade secret or copyright law.
12 # Dissemination of this information or reproduction of this material is strictly
13 # forbidden unless prior written permission is obtained from Dataspeed Inc.
14 
15 import rospy
16 
17 from dbw_fca_msgs.msg import Misc2Report, MiscCmd
18 from std_msgs.msg import Bool, Empty
19 
21 
22  def __init__(self):
23  rospy.init_node('vent')
24 
25  self.initializing = True
26 
27  self.i = 0
28  self.start = 0
29  self.end = 100000
30 
31  # resolution is 20ms
32  self.duration = rospy.Duration(0.01)
33 
34  self.dbw_enabled = False
35  self.msg_misc2_report = Misc2Report()
36 
37  rospy.loginfo('Sending vent command every ' + str(self.duration.to_sec()) + ' seconds from ' + str(self.start) + ' to ' + str(self.end) )
38 
39  # Publishers
40  global enable_pub, vent_pub, misc_pub
41  enable_pub = rospy.Publisher('/vehicle/enable', Empty, queue_size=1)
42  misc_pub = rospy.Publisher('/vehicle/misc_cmd', MiscCmd, queue_size=1)
43 
44  # Subscribers
45  # DBW should be enabled
46  rospy.Subscriber('/vehicle/dbw_enabled', Bool, self.recv_dbw_enabled)
47  rospy.Subscriber('/vehicle/misc_2_report', Misc2Report, self.recv_misc2_report)
48 
49  # To publish /vehicle/enable message to enable dbw system
50  rospy.Timer(rospy.Duration(0.5), self.initialize, oneshot=True)
51 
52 
53  def initialize(self, event):
54  rospy.loginfo('Initialize: Start to enable DBW.')
55  timeout = 10.0
56  wait_time = 0.0
57 
58  # For test
59  self.dbw_enabled = True
60 
61  while not self.dbw_enabled and wait_time < timeout:
62  enable_pub.publish()
63  rospy.sleep(0.01)
64  wait_time += 0.01
65 
66  while True:
67  if self.dbw_enabled == True:
68  rospy.loginfo('Initialize: DBW is enabled. Start timer_process')
69  self.initializing = False
70  rospy.Timer(rospy.Duration(0.02), self.timer_process)
71  break
72 
73  rospy.Timer(rospy.Duration(0.02), self.timer_process)
74 
75  def timer_process(self, event):
76 
77  if self.initializing:
78  rospy.signal_shutdown('')
79  return
80 
81  if not self.dbw_enabled:
82  rospy.logerr("No new messages on topic '/vehicle/enable'. Enable DBW first.")
83  else:
84  self.i += 1
85  msg = MiscCmd()
86  msg.ft_drv_temp.value = 70
87  msg.ft_psg_temp.value = 67
88  msg.ft_fan_speed.value = 5
89  msg.vent_mode.value = msg.vent_mode.FLOOR
90  msg.sync.cmd = msg.sync.cmd.OFF
91  msg.hsw.cmd = msg.hsw.cmd.ON
92  msg.fl_heated_seat.cmd = msg.fl_heated_seat.cmd.HI
93  misc_pub.publish(msg)
94  rospy.loginfo('hvac commands were sent.')
95 
96  def recv_misc2_report(self, msg):
97  self.msg_misc2_report = msg
99 
100  def recv_dbw_enabled(self, msg):
101  rospy.loginfo('DBW is enabled')
102  self.dbw_enabled = msg.data
103 
104  def shutdown_handler(self):
105  rospy.loginfo('shutdown_handler')
106 
107 if __name__ == '__main__':
108  try:
110  rospy.on_shutdown(node.shutdown_handler)
111  rospy.spin()
112  except rospy.ROSInterruptException:
113  pass
def timer_process(self, event)
def recv_misc2_report(self, msg)


dbw_fca_can
Author(s): Kevin Hallenbeck
autogenerated on Wed May 12 2021 02:14:05