commit d483a77903fffcaae62b8443a0d8888905c9e4be Author: Fisch Date: Sat Dec 7 13:36:16 2019 +0100 add program to approximate cell configuration diff --git a/akkuconfig/12S_LiIon_Akkupack.csv b/akkuconfig/12S_LiIon_Akkupack.csv new file mode 100644 index 0000000..e269671 --- /dev/null +++ b/akkuconfig/12S_LiIon_Akkupack.csv @@ -0,0 +1,28 @@ +Label;Capacity @ 2A;+Capacity @ .5A;Capacity;Resistance [mOhm] +1 Gruen;1338;582;1920;170 +2 Gruen;1228;702;1930;150 +3 dunkelblau;1033;469;1502;140 +4 dunkelblau;438;395;833;212 +5 dunkelblau;777;411;1188;196 +6 dunkelblau;1201;382;1583;140 +7 dunkelblau;964;493;1457;200 +8 dunkelblau;955;543;1498;208 +9 dunkelblau;806;402;1208;174 +10 dunkelblau;1010;426;1436;166 +11 hellblau;1308;254;1562;118 +12 hellblau;1440;172;1612;118 +13 hellblau;1393;178;1571;114 +14 hellblau;1131;590;1721;286 +15 hellblau;1415;225;1640;110 +16 hellblau;1454;261;1715;110 +17 hellblau;1454;211;1665;108 +18 hellblau;1565;184;1749;100 +19 hellblau;1591;221;1812;110 +20 hellblau;1538;180;1718;118 +21 hellblau;1525;183;1708;108 +22 hellblau;1435;213;1648;126 +23 hellblau;1450;169;1619;122 +24 hellblau;1503;196;1699;112 +25 hellblau;1510;188;1698;130 +26 hellblau;1462;230;1692;130 +27 hellblau;1484;182;1666;112 diff --git a/akkuconfig/12S_LiIon_Akkupack_selected.csv b/akkuconfig/12S_LiIon_Akkupack_selected.csv new file mode 100644 index 0000000..77ab619 --- /dev/null +++ b/akkuconfig/12S_LiIon_Akkupack_selected.csv @@ -0,0 +1,25 @@ +Label;Capacity @ 2A;+Capacity @ .5A;Capacity;Resistance [mOhm] +1 Gruen;1338;582;1920;170 +2 Gruen;1228;702;1930;150 +3 dunkelblau;1033;469;1502;140 +5 dunkelblau;777;411;1188;196 +6 dunkelblau;1201;382;1583;140 +7 dunkelblau;964;493;1457;200 +9 dunkelblau;806;402;1208;174 +10 dunkelblau;1010;426;1436;166 +11 hellblau;1308;254;1562;118 +12 hellblau;1440;172;1612;118 +13 hellblau;1393;178;1571;114 +15 hellblau;1415;225;1640;110 +16 hellblau;1454;261;1715;110 +17 hellblau;1454;211;1665;108 +18 hellblau;1565;184;1749;100 +19 hellblau;1591;221;1812;110 +20 hellblau;1538;180;1718;118 +21 hellblau;1525;183;1708;108 +22 hellblau;1435;213;1648;126 +23 hellblau;1450;169;1619;122 +24 hellblau;1503;196;1699;112 +25 hellblau;1510;188;1698;130 +26 hellblau;1462;230;1692;130 +27 hellblau;1484;182;1666;112 diff --git a/akkuconfig/akkupack_config (Kopie 1).py b/akkuconfig/akkupack_config (Kopie 1).py new file mode 100644 index 0000000..cf51d3f --- /dev/null +++ b/akkuconfig/akkupack_config (Kopie 1).py @@ -0,0 +1,109 @@ +#!/usr/bin/env python3 +import numpy as np +import csv +import itertools +import math + +column_label=0 +column_capacity=3 +column_resistance=4 + + +config_parallel=2 +config_cells=12 + +#config_parallel*config_cells*config_packs needed +batteriesneeded=config_parallel*config_cells + + +batteries=[] +batterylabels=[] + +with open('12S_LiIon_Akkupack_selected.csv', 'r') as csvfile: + csvreader = csv.reader(csvfile, delimiter=';') + firstrow=True + for row in csvreader: + label=row[column_label] + capacity=row[column_capacity] + resistance=row[column_resistance] + if not firstrow: + capacity=float(capacity) + resistance=float(resistance) + + batteries.append([label,capacity,resistance]) + batterylabels.append(label) + firstrow=False + +print(str(len(batteries))+" Batteries found") +if len(batteries)==batteriesneeded: + print("You have just enough batteries") +elif len(batteries)>batteriesneeded: + print("You have "+str(len(batteries)-batteriesneeded)+" batteries spare") +elif len(batteries)batteriesneeded: + print("You have "+str(len(batteries)-batteriesneeded)+" batteries spare") +elif len(batteries)batteriesneeded: + print("You have "+str(len(batteries)-batteriesneeded)+" batteries in spare") +elif len(batteries)=config_cells : #nothing left + + currentSelectionDistance=getDistanceFromSelection(currentSelection) + if currentSelectionDistance < bestSelectionDistance: #new best found + bestSelectionDistance=currentSelectionDistance + bestSelection=currentSelection + print("") + print("New best found "+str(currentSelection)) + _print_deviationFromMean=[round(deviationFromMean[a],1) for a in currentSelection] + print("Dev. from mean "+str(_print_deviationFromMean)) + print("Distance="+str(currentSelectionDistance)) + for i in bestSelection: + print(str(comb_parallel_all[i])+" mc="+str(comb_parallel_all_meancapacities[i])) + + + return #backtrack + + if len(currentSelection)>0 and getDistanceFromSelection(currentSelection)>bestSelectionDistance: #distance is already too high + return #backtrack early + + for i in remainingSortedIndices: #try all in sorted order + newremainingSortedIndices=[x for x in remainingSortedIndices] #copy list, should be the same for every i + + _selectedIndex=i #greedy take element i + + + #remove elements with one of the used batteries + for used in parallelCombinations[_selectedIndex]: + #print(used) + for rsi in newremainingSortedIndices: #check all remaining indices + containesBattery=False + for pcb in parallelCombinations[rsi]: + if pcb==used: + containesBattery=True + + if containesBattery: + newremainingSortedIndices=[x for x in newremainingSortedIndices if x is not rsi] #remove current index rsi from remainingSortedIndices + + #repeat until empty + greedy(parallelCombinations,newremainingSortedIndices,currentSelection+[_selectedIndex]) + + + + +greedy(comb_parallel_all,sortedIndices, []) +print(bestSelection) + +print("###") +for i in bestSelection: + print(str(comb_parallel_all[i])+" mc="+str(comb_parallel_all_meancapacities[i])) diff --git a/akkuconfig/combinationstest.py b/akkuconfig/combinationstest.py new file mode 100644 index 0000000..d761d5d --- /dev/null +++ b/akkuconfig/combinationstest.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 +import numpy as np +import csv +import itertools +import math + +import scipy.special + +#o(n) = (n-1) * o(n-2) <- pairs +def number_pairs(size): + if size<2: + return 1 + n=size-1 + return n*number_pairs(size-2) + + +#https://stackoverflow.com/questions/5360220/how-to-split-a-list-into-pairs-in-all-possible-ways +def all_pairs(lst): + if len(lst) < 2: + yield lst + return + a = lst[0] + for i in range(1,len(lst)): + pair = (a,lst[i]) + for rest in all_pairs(lst[1:i]+lst[i+1:]): + yield [pair] + rest + +def all_triples(lst): + if len(lst) < 3: + yield lst + return + a = lst[0] + for i in range(1,len(lst)): + for j in range(i+1,len(lst)): + pair = (a,lst[i],lst[j]) + for rest in all_triples(lst[1:i]+lst[i+1:j]+lst[j+1:]): + yield [pair] + rest + +def all_quadruples(lst): + if len(lst) < 4: + yield lst + return + a = lst[0] + for i in range(1,len(lst)): + for j in range(i+1,len(lst)): + for k in range(j+1,len(lst)): + pair = (a,lst[i],lst[j],lst[k]) + for rest in all_quadruples(lst[1:i]+lst[i+1:j]+lst[j+1:k]+lst[k+1:]): + yield [pair] + rest + + + + + + +#a=[1,2,3,4] +a=[1,2,3,4,5,6] + +print(number_pairs(24)) + + +count=0 +for i in all_pairs(a): + count+=1 + #print(i) + +print(count) diff --git a/akkuconfig/hoverboard_serial_test (von lucas).pde b/akkuconfig/hoverboard_serial_test (von lucas).pde new file mode 100644 index 0000000..0541b6b --- /dev/null +++ b/akkuconfig/hoverboard_serial_test (von lucas).pde @@ -0,0 +1,71 @@ +import controlP5.*; +import processing.serial.*; + +ControlP5 cp5; + +Serial myPort; // Create object from Serial class +int val; // Data received from the serial port + +float links; +float rechts; +Slider slLinks; +Slider slRechts; + +void setup() { + size(450, 300); + frameRate(100); + background(0); + + cp5 = new ControlP5(this); + + slLinks = cp5.addSlider("links") + .setRange((float)-1, (float)1) + .setValue(0) + .setPosition(10,10) + .setSize(400,20) + ; + + + slRechts = cp5.addSlider("rechts") + .setRange((float)-1,(float)1) + .setValue(0) + .setPosition(10,40) + .setSize(400,20); + + cp5.addButton("stop") + .setPosition(10, 80) + .setSize(150, 150); + + + myPort = new Serial(this, "/dev/ttyUSB0", 115200); +} + +void stop() { + slLinks.setValue(0); + slRechts.setValue(0); +} + +void draw() { + + int bits = Float.floatToIntBits(rechts); + byte[] bytes = new byte[8]; + bytes[0] = (byte)(bits & 0xff); + bytes[1] = (byte)((bits >> 8) & 0xff); + bytes[2] = (byte)((bits >> 16) & 0xff); + bytes[3] = (byte)((bits >> 24) & 0xff); + + bits = Float.floatToIntBits(links); + bytes[4] = (byte)(bits & 0xff); + bytes[5] = (byte)((bits >> 8) & 0xff); + bytes[6] = (byte)((bits >> 16) & 0xff); + bytes[7] = (byte)((bits >> 24) & 0xff); + + myPort.write(bytes); // send an H to indicate mouse is over square + + + String inBuffer = myPort.readString(); + if (inBuffer != null) { + println(inBuffer); + } + +} \ No newline at end of file