if sim_params['save_every'] == 1: for i in range(le - 1): mag_angles[i] = np.arccos(dcm_bn[i] @ mag[i] / np.linalg.norm(mag[i])) mag_angles[-1] = mag_angles[-2] else: for i in range(le): mag_angles[i] = np.arccos(dcm_bn[i] @ mag[i] / np.linalg.norm(mag[i])) _plot(mag_angles, 'angles between magnetic field and body frame', 'rad') # The Animation if display_animation: num = animation_speed start = 0 end = -1 vec2 = DrawingVectors(data.sun.values[start:end:num], 'single', color='y', label='sun', length=0.5) vec1 = DrawingVectors(data.nadir.values[start:end:num], 'single', color='b', label='nadir', length=0.5) vec3 = DrawingVectors(data.velocities.values[start:end:num], 'single', color='g', label='velocity', length=0.5) vec4 = DrawingVectors(data.mag.values[start:end:num], 'single', color='r', label='magnetic field', length=0.5) ref1 = DrawingVectors(data.dcm_bn.values[start:end:num], 'axes', color=['C0', 'C1', 'C2'], label=['Body x', 'Body y', 'Body z'], length=0.2) ref2 = DrawingVectors(data.dcm_bo.values[start:end:num], 'axes', color=['C0', 'C1', 'C2'], label=['Body x', 'Body y', 'Body z'], length=0.2) plot1 = AdditionalPlots(time[start:end:num], data.controls.values[start:end:num], labels=['X', 'Y', 'Z']) plot2 = AdditionalPlots(data.lons.values[start:end:num], data.lats.values[start:end:num], groundtrack=True) plot3 = AdditionalPlots(data.hyst_rod_external_field.values[:, 1][start:end:num], data.hyst_rod_magnetization.values[:, 1][start:end:num], hyst_curve=rods[1]) a = AnimateAttitude(data.dcm_bn.values[start:end:num], draw_vector=[ref1, vec4, vec1], additional_plots=[plot2, plot3], cubesat_model=cubesat) a.animate_and_plot() plt.show()
sigmas[0] = np.array([0.60, -0.4, 0.2]) omegas[0] = np.array([0.1, 0.01, -0.05]) for i in range(len(time) - 1): omegas[i + 1] = omegas[i] + time_step * omega_dot(omegas[i]) sigmas[i + 1] = sigmas[i] + time_step * sigma_dot(sigmas[i], omegas[i]) # 3.0 plot angular velocites plt.figure() plt.plot(time, omegas) plt.title('angular velocity components') # 3.1 plot attitude representation components plt.figure() plt.plot(time, sigmas) plt.title('attitude representation components') # 4.0 Animate this result so we can actually see what is going on cubesat = CubeSatAerodynamicEx1() # need the 3x3 matrix representation of attitude (Directional Cosine Matrix (DCM)) for the animation routine. dcm = np.zeros((len(time), 3, 3)) for i in range(len(time)): dcm[i] = tr.mrp_to_dcm(sigmas[i]) ref = DrawingVectors(dcm[::100], 'axes', color=['C0', 'C1', 'C2'], label=['Body x', 'Body y', 'Body z'], length=0.2) a = AnimateAttitude(dcm[::100], draw_vector=ref, cubesat_model=cubesat) a.animate()
def _plot(data, title, ylabel): plt.figure() plt.plot(time, data) plt.title(title) plt.xlabel('Time (s)') plt.ylabel(ylabel) # _plot(omegas, 'angular velocity components', 'angular velocity (rad/s)') # _plot(sigmas, 'mrp components', 'mrp component values') # _plot(controls, 'control torque components', 'Torque (Nm)') # _plot(m, 'coil magnetic moments', '(A*m^2)') from adcsim.animation import AnimateAttitude, DrawingVectors, AdditionalPlots num = 200 vec = DrawingVectors(mag_vec_def, 'double', 'r', 'B-field', 6) body = DrawingVectors(dcm[::num], 'axes', ['C0', 'C1', 'C2'], ['Body x', 'Body y', 'Body z'], 4) plot1 = AdditionalPlots(time[::num], m[::num], title='Magnetic moment', ylabel='A*m^2') plot2 = AdditionalPlots(time[::num], mag[::num], title='body frame B-field', ylabel='T') a = AnimateAttitude(dcm[::num], draw_vector=[vec, body], additional_plots=[plot1, plot2]) a.animate_and_plot()
_plot(np.linalg.norm(sigmas, axis=1), 'mrp magnitude', '') # plot wheel speed and accelerations _plot(wheel_angular_vel * 9.5493, 'reaction wheel angular velocities', 'rpm') _plot(wheel_angular_accel, 'reaction wheel angular accelerations', 'rad/s/s') _plot(m, 'coil magnetic moments', '(A*m^2)') from adcsim.animation import AnimateAttitude, DrawingVectors, AdditionalPlots num = 200 plot1 = AdditionalPlots(time[::num], wheel_angular_vel[::num] * 9.5493, title='Reaction Wheel Angular Velocities', ylabel='rpm') plot2 = AdditionalPlots(time[::num], m[::num], title='Magnetic moment', ylabel='A*m^2') ref1 = DrawingVectors(dcm[::num], 'axes', color=['C0', 'C1', 'C2'], label=['Body x', 'Body y', 'Body z'], length=4) a = AnimateAttitude(dcm[::num], draw_vector=ref1, additional_plots=[plot1, plot2]) a.animate_and_plot() plt.show()
# The prv's are obtained and plotted here because they are an intuitive attitude coordinate system # and the prv angle as a function of time is the best way to visualize your attitude error. _plot(angle, 'prv angle reference', 'prv angle (rad)') # plot the control torque _plot(controls, 'control torque components', 'Torque (Nm)') # plot the mrp magnitude _plot(np.linalg.norm(sigmas, axis=1), 'mrp magnitude', '') from adcsim.animation import AnimateAttitude, DrawingVectors from adcsim.CubeSat_model_examples import CubeSatEx1 num = 100 ref1 = DrawingVectors(dcm[::num], 'axes', color=['C0', 'C1', 'C2'], label=['Body x', 'Body y', 'Body z'], length=4) ref2 = DrawingVectors(dcm_rn, 'axes', color=['r', 'y', 'b'], label=['Ref x', 'Ref y', 'Ref z'], length=4) cubesat = CubeSatEx1() a = AnimateAttitude(dcm[::num], draw_vector=[ref1, ref2], cubesat_model=cubesat) a.animate() plt.show()
for i in range(len(time)): mag_angles[i] = np.arccos(dcm_bn[i] @ mag_field[i] / np.linalg.norm(mag_field[i])) cubesat.hyst_rods[0].plot_limiting_cycle(-150, 150) plt.plot(cubesat.hyst_rods[0].h, cubesat.hyst_rods[0].b, color='red', linestyle='--') plt.show() #_plot(aerod, 'aerodynamic disturbance') #_plot(gravityd, 'gravity gradient disturbance') #_plot(solard, 'solar radiation pressure disturbance') #_plot(magneticd, 'residual magnetic disturbance') from adcsim.animation import AnimateAttitude, DrawingVectors, AdditionalPlots num = 1000 vec1 = DrawingVectors(nadir[::num], 'single', color='b', label='nadir', length=0.5) vec2 = DrawingVectors(sun_vec[::num], 'single', color='y', label='sun', length=0.5) vec3 = DrawingVectors(velocities[::num], 'single', color='g', label='velocity', length=0.5) vec4 = DrawingVectors(mag_field[::num], 'single', color='r', label='magnetic field', length=0.5) ref1 = DrawingVectors(dcm_bn[::num], 'axes', color=['C0', 'C1', 'C2'], label=['Body x', 'Body y', 'Body z'], length=0.2) reforbit = DrawingVectors(dcm_on[::num], 'axes', color=['C0', 'C1', 'C2'], label=['Orbit x', 'Orbit y', 'Orbit z'], length=0.2) ref2 = DrawingVectors(dcm_bo[::num], 'axes', color=['C0', 'C1', 'C2'], label=['Body x', 'Body y', 'Body z'], length=0.2) plot1 = AdditionalPlots(time[::num], controls[::num], labels=['X', 'Y', 'Z']) plot2 = AdditionalPlots(lons[::num], lats[::num], groundtrack=True) plot3 = AdditionalPlots(time[::num], is_eclipse[::num]) # a = AnimateAttitude(dcm_bo[::num], draw_vector=ref2, additional_plots=plot2, cubesat_model=cubesat) a = AnimateAttitude(dcm_bn[::num], draw_vector=[ref1, vec1, vec4], additional_plots=plot2, cubesat_model=cubesat) a.animate_and_plot() plt.show()
# Calculate angles between body axis and magnetic field mag_angles = np.zeros((le, 3)) for i in range(le): mag_angles[i] = np.arccos(dcm_bn[i] @ mag_field[i] / np.linalg.norm(mag_field[i])) _plot(mag_angles, 'angles between magnetic field and body frame', 'rad') # The Animation num = 10 start = 0 end = -1 vec2 = DrawingVectors(sun_vec[start:end:num], 'single', color='y', label='sun', length=0.5) vec3 = DrawingVectors(velocities[start:end:num], 'single', color='g', label='velocity', length=0.5) vec4 = DrawingVectors(mag_field[start:end:num], 'single', color='r', label='magnetic field', length=0.5) ref1 = DrawingVectors(dcm_bn[start:end:num], 'axes', color=['C0', 'C1', 'C2'],