process_for_sysid.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # Software License Agreement (BSD License)
00003 #
00004 #  Copyright (c) 2011, UC Regents
00005 #  All rights reserved.
00006 #
00007 #  Redistribution and use in source and binary forms, with or without
00008 #  modification, are permitted provided that the following conditions
00009 #  are met:
00010 #
00011 #   * Redistributions of source code must retain the above copyright
00012 #     notice, this list of conditions and the following disclaimer.
00013 #   * Redistributions in binary form must reproduce the above
00014 #     copyright notice, this list of conditions and the following
00015 #     disclaimer in the documentation and/or other materials provided
00016 #     with the distribution.
00017 #   * Neither the name of the University of California nor the names of its
00018 #     contributors may be used to endorse or promote products derived
00019 #     from this software without specific prior written permission.
00020 #
00021 #  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 #  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 #  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 #  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 #  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 #  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 #  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 #  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 #  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 #  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 #  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 #  POSSIBILITY OF SUCH DAMAGE.
00033 
00034 import sys
00035 from load_bag import BagLoader
00036 from timeseries import uniform_resample, quaternion_to_eulerypr
00037 import scipy.io as sio
00038 import numpy as np
00039 
00040 in_bag, out_mat = sys.argv[1:3]
00041 
00042 input_bag = BagLoader(in_bag)
00043 
00044 quats = (input_bag.estimator_output_pose_pose_orientation_w, 
00045          input_bag.estimator_output_pose_pose_orientation_x, 
00046          input_bag.estimator_output_pose_pose_orientation_y,
00047          input_bag.estimator_output_pose_pose_orientation_z)
00048 yaw, pitch, roll = [np.degrees(x) for x in quaternion_to_eulerypr(quats)]
00049 
00050 resample_inputs = (('linear',
00051                     input_bag.estimator_output___header__time[1:],
00052                     input_bag.estimator_output_pose_pose_position_x[1:],
00053                     input_bag.estimator_output_pose_pose_position_y[1:],
00054                     input_bag.estimator_output_pose_pose_position_z[1:],
00055                     input_bag.estimator_output_twist_twist_linear_x[1:],
00056                     input_bag.estimator_output_twist_twist_linear_y[1:],
00057                     input_bag.estimator_output_twist_twist_linear_z[1:],
00058                    ),
00059                    ('zero',
00060                     input_bag.estimator_output___header__time[1:],
00061                     input_bag.estimator_output_pose_pose_orientation_w[1:],
00062                     input_bag.estimator_output_pose_pose_orientation_x[1:],
00063                     input_bag.estimator_output_pose_pose_orientation_y[1:],
00064                     input_bag.estimator_output_pose_pose_orientation_z[1:],
00065                     ),
00066                    ('zero',
00067                     input_bag.estimator_output___header__time[1:],
00068                     yaw[1:],
00069                     pitch[1:],
00070                     roll[1:],
00071                     ),
00072                    ('linear',
00073                     input_bag.asctec_imu___header__time[1:],
00074                     input_bag.asctec_imu_angular__velocity_x[1:],
00075                     input_bag.asctec_imu_angular__velocity_y[1:],
00076                     input_bag.asctec_imu_angular__velocity_z[1:]
00077                     ),
00078                     ('zero',
00079                      input_bag.controller__mux_output___header__time[1:],
00080                      input_bag.controller__mux_output_yaw__cmd[1:],
00081                      input_bag.controller__mux_output_pitch__cmd[1:],
00082                      input_bag.controller__mux_output_roll__cmd[1:],
00083                      input_bag.controller__mux_output_alt__cmd[1:]
00084                      )
00085                   )
00086 
00087 t_out, resample_outputs = uniform_resample(resample_inputs, 0.02) # resample at 50 Hz
00088 
00089 mdict = {'t': t_out,
00090          
00091          # States:
00092          'x': resample_outputs[0][0],
00093          'y': resample_outputs[0][1],
00094          'z': resample_outputs[0][2],
00095          'vx': resample_outputs[0][3],
00096          'vy': resample_outputs[0][4],
00097          'vz': resample_outputs[0][5],
00098          
00099          'qw': resample_outputs[1][0],
00100          'qx': resample_outputs[1][1],
00101          'qy': resample_outputs[1][2],
00102          'qz': resample_outputs[1][3],
00103          
00104          'yaw':   resample_outputs[2][0],
00105          'pitch': resample_outputs[2][1],
00106          'roll':  resample_outputs[2][2],
00107          
00108          'wx': resample_outputs[3][0],
00109          'wy': resample_outputs[3][1],
00110          'wz': resample_outputs[3][2],
00111          
00112          # Inputs:
00113          'u_yaw':   resample_outputs[4][0],
00114          'u_pitch': resample_outputs[4][1],
00115          'u_roll':  resample_outputs[4][2],
00116          'u_alt':   resample_outputs[4][3],
00117          }
00118 
00119 print "Saving %s..." % out_mat 
00120 sio.savemat(out_mat, mdict, long_field_names=True)


starmac_tools
Author(s): bouffard
autogenerated on Sun Jan 5 2014 11:38:35