1- from typing import Optional
1+ from typing import Optional , Union
22
33from ..abstract_parts import *
44
@@ -57,8 +57,8 @@ def contents(self):
5757class AaBattery (Battery , FootprintBlock ):
5858 """AA battery holder supporting alkaline and rechargeable chemistries."""
5959 @init_in_parent
60- def __init__ (self , voltage : RangeLike = (0.9 , 1.6 )* Volt , * args ,
61- actual_voltage : RangeLike = (0.9 , 1.6 )* Volt , ** kwargs ):
60+ def __init__ (self , voltage : RangeLike = (1.0 , 1.6 )* Volt , * args ,
61+ actual_voltage : RangeLike = (1.0 , 1.6 )* Volt , ** kwargs ):
6262 super ().__init__ (voltage , * args , ** kwargs )
6363 self .gnd .init_from (Ground ())
6464 self .pwr .init_from (VoltageSource (
@@ -84,22 +84,28 @@ def contents(self):
8484class AaBatteryStack (Battery , GeneratorBlock ):
8585 """AA Alkaline battery stack that generates batteries in series"""
8686 @init_in_parent
87- def __init__ (self , count : IntLike = 1 , * , cell_actual_voltage : RangeLike = (0.9 , 1.6 )* Volt ):
88- super ().__init__ ()
87+ def __init__ (self , count : IntLike = 1 , * , cell_actual_voltage : RangeLike = (1.0 , 1.6 )* Volt ):
88+ super ().__init__ (voltage = Range . all ()) # no voltage spec passed in
8989 self .count = self .ArgParameter (count )
9090 self .cell_actual_voltage = self .ArgParameter (cell_actual_voltage )
9191 self .generator_param (self .count )
9292
9393 def generate (self ):
9494 super ().generate ()
9595 prev_cell : Optional [AaBattery ] = None
96+ prev_capacity_min : Union [FloatExpr , float ] = float ('inf' )
97+ prev_capacity_max : Union [FloatExpr , float ] = float ('inf' )
9698 self .cell = ElementDict [AaBattery ]()
9799 for i in range (self .get (self .count )):
98100 self .cell [i ] = cell = self .Block (AaBattery (actual_voltage = self .cell_actual_voltage ))
99- if prev_cell is None : # direct connect to gnd
101+ if prev_cell is None : # first cell, direct connect to gnd
100102 self .connect (self .gnd , cell .gnd )
101103 else :
102- self .connect (prev_cell .pwr .as_ground (), cell .gnd )
104+ self .connect (prev_cell .pwr .as_ground (self .pwr .link ().current_drawn ), cell .gnd )
105+ prev_capacity_min = cell .actual_capacity .lower ().min (prev_capacity_min )
106+ prev_capacity_max = cell .actual_capacity .upper ().min (prev_capacity_max )
107+ prev_cell = cell
103108
104109 assert prev_cell is not None , "must generate >=1 cell"
105110 self .connect (self .pwr , prev_cell .pwr )
111+ self .assign (self .actual_capacity , (prev_capacity_min , prev_capacity_max ))
0 commit comments