Advertisement
DrAungWinHtut

solar_sat.py

Jan 10th, 2025
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.10 KB | None | 0 0
  1. import datetime
  2. import math
  3.  
  4. # Constants
  5. SOLAR_CONSTANT = 1361  # Solar irradiance in W/m^2
  6. BATTERY_CAPACITY = 10000  # Battery capacity in Watt-hours (Wh)
  7. SOLAR_ARRAY_EFFICIENCY = 0.3  # Efficiency of solar panels
  8. TRANSMISSION_EFFICIENCY = 0.9  # Efficiency of power transmission
  9.  
  10. # Global state
  11. battery_charge = 4000  # Initial battery charge in Wh
  12. consumption_log = []  # Log of power consumption (Wh)
  13.  
  14. def calculate_solar_power(solar_array_area, sunlight_hours, angle_to_sun):
  15.     """Calculate solar power generated, accounting for angle to the sun."""
  16.     effective_irradiance = SOLAR_CONSTANT * math.cos(math.radians(angle_to_sun))
  17.     effective_irradiance = max(effective_irradiance, 0)  # No negative irradiance
  18.     generated_power = (
  19.         effective_irradiance * solar_array_area *
  20.         SOLAR_ARRAY_EFFICIENCY * sunlight_hours * TRANSMISSION_EFFICIENCY
  21.     )
  22.     return generated_power  # Wh
  23.  
  24. def log_consumption(subsystem, power, duration):
  25.     """Log power consumption for a subsystem."""
  26.     global battery_charge
  27.     consumed_energy = power * duration  # Wh
  28.     consumption_log.append({
  29.         'subsystem': subsystem,
  30.         'power': power,  # W
  31.         'duration': duration,  # hours
  32.         'energy': consumed_energy,  # Wh
  33.         'timestamp': datetime.datetime.now()
  34.     })
  35.     battery_charge -= consumed_energy
  36.  
  37. def balance_energy(solar_array_area, sunlight_hours, angle_to_sun):
  38.     """Balance energy generated and consumed."""
  39.     global battery_charge
  40.     generated_power = calculate_solar_power(solar_array_area, sunlight_hours, angle_to_sun)
  41.     battery_charge += generated_power
  42.  
  43.     # Ensure battery charge stays within valid range
  44.     battery_charge = max(0, min(battery_charge, BATTERY_CAPACITY))
  45.  
  46.     return generated_power
  47.  
  48. def report_status():
  49.     """Report current power system status."""
  50.     print(f"Battery charge: {battery_charge:.2f} Wh")
  51.     print("Recent Consumption Log:")
  52.     for log in consumption_log[-5:]:  # Last 5 logs
  53.         print(f"- {log['subsystem']} consumed {log['energy']:.2f} Wh ({log['duration']} hours)")
  54.  
  55. # Example Usage
  56. if __name__ == "__main__":
  57.     solar_array_area = 2  # m^2 for CubeSat
  58.     sunlight_hours = 5  # Example: 5 hours of sunlight
  59.     angle_to_sun = 30  # Angle between solar panel normal and sunlight in degrees
  60.  
  61.     # Calculate energy generation
  62.     generated_power = balance_energy(solar_array_area, sunlight_hours, angle_to_sun)
  63.     print(f"Solar power generated: {generated_power:.2f} Wh")
  64.  
  65.     # Log power consumption
  66.     log_consumption("Communications", power=150, duration=3)  # 150 W for 3 hours
  67.     log_consumption("Payload Operations", power=200, duration=2)  # 200 W for 2 hours
  68.     log_consumption("Thermal Control", power=50, duration=5)  # 50 W for 5 hours
  69.  
  70.     # Report current status
  71.     report_status()
  72.  
  73.     # Simulate eclipse period (no sunlight)
  74.     eclipse_hours = 2
  75.     generated_power = balance_energy(solar_array_area, eclipse_hours, angle_to_sun=90)  # Sun blocked
  76.     print(f"Solar power generated during eclipse: {generated_power:.2f} Wh")
  77.  
  78.     # Report final status
  79.     report_status()
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement