33 from dbw_fca_msgs.msg
import BrakeCmd, BrakeReport, BrakeInfoReport
34 from dbw_fca_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 (%)',
'Measured (%)',
'Torque Request (Nm)',
'Torque Actual (Nm)',
'Pressure (bar)'])
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(
'')
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(
'')
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 "{:.01f}".format(self.msg_brake_info_report.brake_pc) +
', ' +
114 "{:.01f}".format(self.msg_brake_info_report.brake_torque_request) +
', ' +
115 "{:.01f}".format(self.msg_brake_info_report.brake_torque_actual) +
', ' +
116 "{:.01f}".format(self.msg_brake_info_report.brake_pressure))
117 self.csv_writer.writerow([
"{:.03f}".format(self.msg_brake_report.pedal_output),
118 "{:.01f}".format(self.msg_brake_info_report.brake_pc),
119 "{:.01f}".format(self.msg_brake_info_report.brake_torque_request),
120 "{:.01f}".format(self.msg_brake_info_report.brake_torque_actual),
121 "{:.01f}".format(self.msg_brake_info_report.brake_pressure)])
123 rospy.signal_shutdown(
'')
135 msg.pedal_cmd_type = BrakeCmd.CMD_PEDAL
137 self.pub.publish(msg)
156 rospy.loginfo(
'Saving csv file')
157 self.csv_file.close()
159 if __name__ ==
'__main__':
162 rospy.on_shutdown(node.shutdown_handler)
164 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)