00001
00002
00003 from __future__ import division
00004
00005 import roslib
00006 roslib.load_manifest('rotors_evaluation')
00007
00008 from rosbag_tools import analyze_bag, helpers
00009
00010
00011 __author__ = "Fadri Furrer, Michael Burri, Markus Achtelik"
00012 __copyright__ = ("Copyright 2015, Fadri Furrer & Michael Burri & "
00013 "Markus Achtelik, ASL, ETH Zurich, Switzerland")
00014 __credits__ = ["Fadri Furrer", "Michael Burri", "Markus Achtelik"]
00015 __license__ = "ASL 2.0"
00016 __version__ = "0.1"
00017 __maintainer__ = "Fadri Furrer"
00018 __email__ = "fadri.furrer@mavt.ethz.ch"
00019 __status__ = "Development"
00020
00021
00022 def main():
00023 [ab, plot, begin_time, total_end_time, rms_calc_time, settling_radius,
00024 min_settled_time, first_waypoint_evaluation_delay] = helpers.initialize()
00025
00026 settling_time_max = 10.0
00027 position_error_max = 0.2
00028 angular_velocity_error_max = 0.2
00029
00030
00031 waypoints = ab.waypoint[0]
00032 bag_time_start = ab.bag_time_start.to_sec()
00033 bag_time_end = ab.bag_time_end.to_sec()
00034 list_settling_time = []
00035 list_pos_rms = []
00036 list_pqr_rms = []
00037
00038
00039 for index in range(len(waypoints.x)):
00040 settling_time = None
00041 print("\n")
00042 [begin_time, end_time] = helpers.get_evaluation_period(
00043 waypoints, index, bag_time_start, bag_time_end, total_end_time)
00044 print("[Waypoint %d]: [%.3f, %.3f, %.3f, %.3f] at time %.3f s" % (
00045 index, waypoints.x[index], waypoints.y[index], waypoints.z[index],
00046 waypoints.yaw[index], begin_time))
00047
00048
00049 positions = ab.pos[0].slice(begin_time, end_time)
00050
00051 set_point_pos = analyze_bag.create_set_point(
00052 waypoints.x[index], waypoints.y[index], waypoints.z[index])
00053 set_point_pqr = analyze_bag.create_set_point(0, 0, 0)
00054
00055
00056
00057
00058
00059 if index == 0:
00060 begin_time += first_waypoint_evaluation_delay
00061 print("Setting the first evaluation start time %f s after the "
00062 "first waypoint was published.\n"
00063 % first_waypoint_evaluation_delay)
00064 print("[Waypoint %d]: Settling time for this waypoint not\n"
00065 " considered." % index)
00066
00067 rms_evaluation_start_time = begin_time
00068 rms_evaluation_end_time = min(begin_time + rms_calc_time, end_time)
00069
00070 rms_positions = ab.pos[0].slice(rms_evaluation_start_time,
00071 rms_evaluation_end_time)
00072 pos_rms_error = helpers.get_rms_position_error(
00073 rms_positions, set_point_pos, index)
00074
00075
00076 angular_velocities = ab.pqr[0].slice(rms_evaluation_start_time,
00077 rms_evaluation_end_time)
00078 pqr_rms_error = helpers.get_rms_angular_velocity_error(
00079 angular_velocities, set_point_pqr, index)
00080 else:
00081
00082
00083
00084 settling_time = helpers.get_settling_time(
00085 positions, set_point_pos, settling_radius, min_settled_time,
00086 index)
00087 if settling_time is not None and settling_time < settling_time_max:
00088 rms_evaluation_start_time = begin_time + settling_time
00089 rms_evaluation_end_time = min(begin_time + settling_time +
00090 rms_calc_time, end_time)
00091
00092 rms_positions = ab.pos[0].slice(
00093 rms_evaluation_start_time, rms_evaluation_end_time)
00094 pos_rms_error = helpers.get_rms_position_error(
00095 rms_positions, set_point_pos, index)
00096
00097
00098 angular_velocities = ab.pqr[0].slice(
00099 rms_evaluation_start_time, rms_evaluation_end_time)
00100 pqr_rms_error = helpers.get_rms_angular_velocity_error(
00101 angular_velocities, set_point_pqr, index)
00102
00103 list_settling_time.append(settling_time)
00104 list_pos_rms.append(pos_rms_error)
00105 list_pqr_rms.append(pqr_rms_error)
00106 else:
00107 print("[Waypoint %d]: System didn't settle in %f seconds -- "
00108 "inserting 101 % of defined maximum values."
00109 % (index, settling_time_max))
00110 list_settling_time.append(settling_time_max * 1.01)
00111 list_pos_rms.append(position_error_max * 1.01)
00112 list_pqr_rms.append(angular_velocity_error_max * 1.01)
00113
00114
00115 if plot and len(ab.pose_topics) > 0:
00116 x_range = [begin_time - 2, rms_evaluation_end_time + 2]
00117
00118 helpers.plot_positions(
00119 ab, begin_time, rms_evaluation_end_time, settling_time,
00120 settling_radius, set_point_pos, x_range, str(index))
00121 helpers.plot_angular_velocities(
00122 ab, begin_time, rms_evaluation_end_time, settling_time,
00123 x_range, str(index))
00124
00125 average_settling_time = helpers.calculate_average(list_settling_time)
00126 average_pos_rms = helpers.calculate_average(list_pos_rms)
00127 average_pqr_rms = helpers.calculate_average(list_pqr_rms)
00128
00129 start_collision_time = (waypoints.bag_time[0].to_sec() +
00130 first_waypoint_evaluation_delay)
00131 if (helpers.no_collisions_occured(ab, start_collision_time,
00132 rms_evaluation_end_time)):
00133 print("\n")
00134 helpers.print_scoring(average_settling_time, settling_time_max,
00135 "settling time", "s", [0.0, 1.5, 3.5, 5.0])
00136 helpers.print_scoring(average_pos_rms, position_error_max,
00137 "position RMS error", "m", [0.0, 1.5, 3.5, 5.0])
00138 helpers.print_scoring(average_pqr_rms, angular_velocity_error_max,
00139 "angular velocity RMS error", "rad/s",
00140 [0.0, 1.0, 2.0, 3.0])
00141
00142
00143 if __name__ == "__main__":
00144 main()