33 from dbw_mkz_msgs.msg
import BrakeCmd, BrakeReport, BrakeInfoReport
34 from dbw_mkz_msgs.msg
import GearReport, SteeringReport
39 rospy.init_node(
'brake_sweep')
60 rospy.loginfo(
'Recording brake pedal data every ' + str(self.duration.to_sec()) +
' seconds from ' + str(self.
start) +
' to ' + str(self.
end) +
' with ' + str(self.
resolution) +
' increments.')
61 rospy.loginfo(
'This will take ' + str((self.
end - self.
start) / self.
resolution * self.duration.to_sec() / 60.0) +
' minutes.')
64 self.
csv_file = open(
'brake_sweep_data.csv',
'w')
66 self.csv_writer.writerow([
'Brake (%)',
'Torque Request (Nm)',
'Torque Actual (Nm)'])
69 self.
pub = rospy.Publisher(
'/vehicle/brake_cmd', BrakeCmd, queue_size=1)
70 rospy.Subscriber(
'/vehicle/brake_report', BrakeReport, self.
recv_brake)
71 rospy.Subscriber(
'/vehicle/brake_info_report', BrakeInfoReport, self.
recv_brake_info)
72 rospy.Subscriber(
'/vehicle/gear_report', GearReport, self.
recv_gear)
73 rospy.Subscriber(
'/vehicle/steering_report', SteeringReport, self.
recv_steering)
74 rospy.Timer(rospy.Duration(0.02), self.
timer_cmd)
81 rospy.logerr(
'Speed check failed. No messages on topic \'/vehicle/steering_report\'')
82 rospy.signal_shutdown(
'')
83 if self.msg_steering_report.speed > 1.0:
84 rospy.logerr(
'Speed check failed. Vehicle speed is greater than 1 m/s.')
85 rospy.signal_shutdown(
'')
87 rospy.logerr(
'Gear check failed. No messages on topic \'/vehicle/gear_report\'')
88 rospy.signal_shutdown(
'')
89 if not self.msg_gear_report.state.gear == self.msg_gear_report.state.PARK:
90 rospy.logerr(
'Gear check failed. Vehicle not in park.')
91 rospy.signal_shutdown(
'')
95 rospy.logerr(
'No new messages on topic \'/vehicle/brake_report\'')
96 rospy.signal_shutdown(
'')
98 rospy.logerr(
'No new messages on topic \'/vehicle/brake_info_report\'')
99 rospy.signal_shutdown(
'')
100 if not self.msg_brake_report.enabled:
101 rospy.logerr(
'Brake module not enabled!')
102 rospy.signal_shutdown(
'')
103 if self.msg_brake_report.pedal_input > 0.19:
104 rospy.logwarn(
'Take your foot off the brake pedal! This will corrupt the measurement.')
107 diff = self.
brake_cmd - self.msg_brake_report.pedal_output
108 if (fabs(diff) > 0.01):
109 rospy.logwarn(
'Not saving data point. Large disparity between pedal request and actual: ' + str(diff))
112 rospy.loginfo(
'Data point: ' +
"{:.03f}".format(self.msg_brake_report.pedal_output) +
', ' +
113 str(self.msg_brake_info_report.brake_torque_request) +
', ' +
114 str(self.msg_brake_info_report.brake_torque_actual))
115 self.csv_writer.writerow([
"{:.03f}".format(self.msg_brake_report.pedal_output),
116 "{:.01f}".format(self.msg_brake_info_report.brake_torque_request),
117 "{:.01f}".format(self.msg_brake_info_report.brake_torque_actual)])
119 rospy.signal_shutdown(
'')
131 msg.pedal_cmd_type = BrakeCmd.CMD_PEDAL
133 if msg.pedal_cmd > 0.2:
135 self.pub.publish(msg)
154 rospy.loginfo(
'Saving csv file')
155 self.csv_file.close()
157 if __name__ ==
'__main__':
160 rospy.on_shutdown(node.shutdown_handler)
162 except rospy.ROSInterruptException:
def recv_brake(self, msg)
msg_steering_report_ready
def recv_brake_info(self, msg)
msg_brake_info_report_ready
def recv_steering(self, msg)
def shutdown_handler(self)
def timer_process(self, event)
def timer_cmd(self, event)