#NAME:
#  TestAeroTorque.py
#PURPOSE
#  To test the calculation of aerodynamic torque on the satellite as 
#  a function of input angle of the velocity vector
#
##############################################################

import os
execfile(os.path.expanduser('~')+'/Desktop/Software/Python/CZTCubeSat/CZTCubeSatSetup.py')

import ephem
from datetime import *
from CXBN_Utilities import *

# Main routine if we are called as a script
if __name__ == "__main__":

  #Create a satellite object
  cxbn = CubeSat()

  #Create an instance of the constant object
  c = c()

  #Set the time increment for the propogation
  d_phi     = double(0.01)       #Angular interval (radians)
  phi_final = 2*pi               #Final angle (radians)
  NumAngles = floor(phi_final/d_phi)
  Angles    = arange(NumAngles)
  t_x_Arr  = zeros(NumAngles, dtype=float32)
  t_y_Arr  = zeros(NumAngles, dtype=float32)
  t_z_Arr  = zeros(NumAngles, dtype=float32)

  #Rotation matrix is identity
  e_2_b = mat3(eye(3))

  #Radius is dummy at 700 km
  r_eci = vec3(0,0,7000000.)

  #Loop over the angles
  for PhiInd in Angles:

    #Form the velocity vector
    #v_eci=vec3(700000*cos(PhiInd*d_phi),100,1000)
    v_eci=vec3(0, 3000000, 700000*cos(PhiInd*d_phi))
    #v_eci=vec3(700000*cos(PhiInd*d_phi),100,1000)

    #Calculate the aerodynamic torque
    aero_torque = getAerodynamicTorque(v_eci, r_eci, e_2_b, cxbn, c)
    t_x_Arr[PhiInd] = aero_torque.x
    t_y_Arr[PhiInd] = aero_torque.y
    t_z_Arr[PhiInd] = aero_torque.z
 
