waypoints_eval.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # This is needed such that int / int gives a float instead of an int
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  # [s]
00027     position_error_max = 0.2  # [m]
00028     angular_velocity_error_max = 0.2  # [rad/s]
00029 
00030     # Get the begin and end times, and the set point from the waypoints.
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     # Iterate over waypoints, and create evaluations for each waypoint.
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         # Get all positions for the evaluation period.
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         # Treat the first waypoint specially, as the MAV will most likely still
00056         # be in collision (with the ground), as the first waypoint gets
00057         # published. You can specify the delay of the evaluation with the
00058         # first_waypoint_evaluation_delay option.
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             # Get the position RMS errors.
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             # Get the angular velocity RMS errors.
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             # Get the time at which the MAV stayed for at least
00082             # min_settled_time seconds within a ball of settling_radius meters
00083             # around set_point_pos.
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                 # Get the position RMS errors
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                 # Get the angular velocity RMS errors
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         # Plot pose msg content if there are any pose topics.
00115         if plot and len(ab.pose_topics) > 0:
00116             x_range = [begin_time - 2, rms_evaluation_end_time + 2]
00117             # ab.plot_3d_trajectories()
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()


rotors_evaluation
Author(s): Fadri Furrer, Michael Burri, Mina Kamel, Janosch Nikolic, Markus Achtelik
autogenerated on Thu Apr 18 2019 02:43:40