Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import datetime
- import math
- # Constants
- SOLAR_CONSTANT = 1361 # Solar irradiance in W/m^2
- BATTERY_CAPACITY = 10000 # Battery capacity in Watt-hours (Wh)
- SOLAR_ARRAY_EFFICIENCY = 0.3 # Efficiency of solar panels
- TRANSMISSION_EFFICIENCY = 0.9 # Efficiency of power transmission
- # Global state
- battery_charge = 4000 # Initial battery charge in Wh
- consumption_log = [] # Log of power consumption (Wh)
- def calculate_solar_power(solar_array_area, sunlight_hours, angle_to_sun):
- """Calculate solar power generated, accounting for angle to the sun."""
- effective_irradiance = SOLAR_CONSTANT * math.cos(math.radians(angle_to_sun))
- effective_irradiance = max(effective_irradiance, 0) # No negative irradiance
- generated_power = (
- effective_irradiance * solar_array_area *
- SOLAR_ARRAY_EFFICIENCY * sunlight_hours * TRANSMISSION_EFFICIENCY
- )
- return generated_power # Wh
- def log_consumption(subsystem, power, duration):
- """Log power consumption for a subsystem."""
- global battery_charge
- consumed_energy = power * duration # Wh
- consumption_log.append({
- 'subsystem': subsystem,
- 'power': power, # W
- 'duration': duration, # hours
- 'energy': consumed_energy, # Wh
- 'timestamp': datetime.datetime.now()
- })
- battery_charge -= consumed_energy
- def balance_energy(solar_array_area, sunlight_hours, angle_to_sun):
- """Balance energy generated and consumed."""
- global battery_charge
- generated_power = calculate_solar_power(solar_array_area, sunlight_hours, angle_to_sun)
- battery_charge += generated_power
- # Ensure battery charge stays within valid range
- battery_charge = max(0, min(battery_charge, BATTERY_CAPACITY))
- return generated_power
- def report_status():
- """Report current power system status."""
- print(f"Battery charge: {battery_charge:.2f} Wh")
- print("Recent Consumption Log:")
- for log in consumption_log[-5:]: # Last 5 logs
- print(f"- {log['subsystem']} consumed {log['energy']:.2f} Wh ({log['duration']} hours)")
- # Example Usage
- if __name__ == "__main__":
- solar_array_area = 2 # m^2 for CubeSat
- sunlight_hours = 5 # Example: 5 hours of sunlight
- angle_to_sun = 30 # Angle between solar panel normal and sunlight in degrees
- # Calculate energy generation
- generated_power = balance_energy(solar_array_area, sunlight_hours, angle_to_sun)
- print(f"Solar power generated: {generated_power:.2f} Wh")
- # Log power consumption
- log_consumption("Communications", power=150, duration=3) # 150 W for 3 hours
- log_consumption("Payload Operations", power=200, duration=2) # 200 W for 2 hours
- log_consumption("Thermal Control", power=50, duration=5) # 50 W for 5 hours
- # Report current status
- report_status()
- # Simulate eclipse period (no sunlight)
- eclipse_hours = 2
- generated_power = balance_energy(solar_array_area, eclipse_hours, angle_to_sun=90) # Sun blocked
- print(f"Solar power generated during eclipse: {generated_power:.2f} Wh")
- # Report final status
- report_status()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement