Ergebnis 31 bis 45 von 114
Thema: Python to Javascript
-
04-05-2017, 21:10 #31
Eroberer
- registriert
- 03-05-2017
- Beiträge
- 59
AW: Python to Javascript
Code:pi@carcam:~/ant-cycling-power $ sudo npm install python-shell ant-cycling-power@0.1.0 /home/pi/ant-cycling-power └── python-shell@0.4.0 pi@carcam:~/ant-cycling-power $
klappt aber leider nicht
Code:Cpi@carcam:~/ant-cycling-power $ sudo node test.js startup Max channels: 8 cycling power meter initialized
Bei dem test klappt es wie beschrieben:
Code:pi@carcam:~/testx $ node test.js test finished pi@carcam:~/testx $
denn das Orginal macht ja an Ausgabe:
Code:Max channels: 8 cycling power meter initialized Event: 3 Power: 0w Cadence: undefinedrpm Event: 4 Power: 0w Cadence: undefinedrpm Event: 5 Power: 145w Cadence: undefinedrpm Event: 6 Power: 117w Cadence: undefinedrpm
-
05-05-2017, 07:39 #32
Foren-Gott
- registriert
- 19-05-2008
- Beiträge
- 5.667
AW: Python to Javascript
glaube ich nicht, aber schließen wir das mal als erstes aus.
ersetze dein python script mal durch
Code:for x in range(1, 11): print x*100
hoffen wir es mal.
wie rufst du das python script (ohne js) denn auf(mit sudo?)? brauchst du root-rechte für die gpios?
-
05-05-2017, 15:35 #33
Eroberer
- registriert
- 03-05-2017
- Beiträge
- 59
AW: Python to Javascript
Für die GPIOS brauche ich keine root Rechte, das funktioniert so.
Code:./7powerTX.py
Ergebnis kann ich erst wieder nach der Arbeit liefern, aber dann ist ja WE!
- - - Aktualisiert - - -
Hier mein Output:
Code:pi@carcam:~/ant-cycling-power $ node test.js 100 100 undefined 200 200 undefined 300 300 undefined 400 400 undefined 500 500 undefined 600 600 undefined 700 700 undefined 800 800 undefined 900 900 undefined 1000 1000 undefined finished cycling power meter initialized
Aber Zahlen sind ja da!? Was nun?
-
05-05-2017, 16:06 #34
Foren-Gott
- registriert
- 19-05-2008
- Beiträge
- 5.667
AW: Python to Javascript
dann nimm wieder dein richtiges python script und streue dort solang prints rein, bis du die stelle gefunden hast, bei der es hängt.
so in etwa wird es ja noch das aus post 1 sein. dort würde ich
bei
Code:GPIO.setmode(GPIO.BCM) GPIO.setup(20, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP)
Code:print 1 GPIO.setmode(GPIO.BCM) print 2 GPIO.setup(20, GPIO.IN, pull_up_down=GPIO.PUD_UP) print 3 GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP) print 4
dann erst mal sehen wie weit es geht.
-
05-05-2017, 17:22 #35
Eroberer
- registriert
- 03-05-2017
- Beiträge
- 59
AW: Python to Javascript
das script alleine macht
1
2
3
4
Code:if __name__ == "__main__": import time import pigpio import readRPM import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(20, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP) print 1 GPIO.setmode(GPIO.BCM) print 2 GPIO.setup(20, GPIO.IN, pull_up_down=GPIO.PUD_UP) print 3 GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP) print 4 count = 5 RPM_GPIO = 4 RUN_TIME = 9600.0 SAMPLE_TIME = 1.0 RPM_LOWER_LIMIT = 20 RPM_HIGHER_LIMIT = 120 LEVEL_TO_POWER = { 1: [6,12,20,29,40,53,69,79,92,106,121],
Code:Max channels: 8 cycling power meter initialized
Geändert von Landix (05-05-2017 um 17:54 Uhr) Grund: Kopf Tisch
-
05-05-2017, 18:21 #36
Foren-Gott
- registriert
- 19-05-2008
- Beiträge
- 5.667
-
05-05-2017, 18:34 #37
Eroberer
- registriert
- 03-05-2017
- Beiträge
- 59
AW: Python to Javascript
hab ich, mein output beim script alleine:
1
2
3
4
0
0
0
0
175
117
^^ power Werte
mit node test.js
wieder nix
- - - Aktualisiert - - -
Warte! Nach einer gewissen Zeit!!
Code:Max channels: 8 cycling power meter initialized 1 Event: 1 Power: 1w Cadence: undefinedrpm 2 Event: 2 Power: 2w Cadence: undefinedrpm 3 Event: 3 Power: 3w Cadence: undefinedrpm 4 Event: 4 Power: 4w Cadence: undefinedrpm 0 Event: 5 Power: 0w Cadence: undefinedrpm 0 Event: 6 Power: 0w Cadence: undefinedrpm
dann :
Code:/home/pi/ant-cycling-power/test.js:16 if (err) throw err; ^ Error: IndexError: list index out of range at PythonShell.parseError (/home/pi/ant-cycling-power/node_modules/python-shell/index.js:183:17) at terminateIfNeeded (/home/pi/ant-cycling-power/node_modules/python-shell/index.js:98:28) at ChildProcess.<anonymous> (/home/pi/ant-cycling-power/node_modules/python-shell/index.js:88:9) at emitTwo (events.js:106:13) at ChildProcess.emit (events.js:191:7) at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12) ----- Python Traceback ----- File "7powerx.py", line 194, in <module> print(calculate_power(LEVEL, RPM)) File "7powerx.py", line 154, in calculate_power return LEVEL_TO_POWER[LEVEL][(RPM) //10] # //10 pi@carcam:~/ant-cycling-power $
Wenn ich dann wieder neu starte mit sudo node test.js, wieder nix, ist auch bei ps aux keine Leiche noch offen. *kopfkratz
-
05-05-2017, 19:07 #38
Foren-Gott
- registriert
- 19-05-2008
- Beiträge
- 5.667
-
05-05-2017, 23:13 #39
Eroberer
- registriert
- 03-05-2017
- Beiträge
- 59
AW: Python to Javascript
Mein Python script:
Code:#!/usr/bin/env python import time import pigpio import json import require class reader: """ A class to read speedometer pulses and calculate the RPM. """ def __init__(self, pi, gpio, pulses_per_rev=1.0, weighting=0, min_RPM=5): """ Instantiate with the Pi and gpio of the RPM signal to monitor. Optionally the number of pulses for a complete revolution may be specified. It defaults to 1. Optionally a weighting may be specified. This is a number between 0 and 1 and indicates how much the old reading affects the new reading. It defaults to 0 which means the old reading has no effect. This may be used to smooth the data. Optionally the minimum RPM may be specified. This is a number between 1 and 1000. It defaults to 5. An RPM less than the minimum RPM returns 0.0. """ self.pi = pi self.gpio = gpio self.pulses_per_rev = pulses_per_rev if min_RPM > 1000: min_RPM = 1000 elif min_RPM < 1: min_RPM = 1 self.min_RPM = min_RPM self._watchdog = 200 # Milliseconds. if weighting < 0: weighting = 0 elif weighting > 0: weighting = 0 self._new = 1 - weighting # Weighting for new reading. self._old = weighting # Weighting for old reading. self._high_tick = None self._period = None pi.set_mode(gpio, pigpio.INPUT) self._cb = pi.callback(gpio, pigpio.RISING_EDGE, self._cbf) pi.set_watchdog(gpio, self._watchdog) def _cbf(self, gpio, level, tick): if level == 1: # Rising edge. if self._high_tick is not None: t = pigpio.tickDiff(self._high_tick, tick) if self._period is not None: self._period = (self._old * self._period) + (self._new * t) else: self._period = t self._high_tick = tick elif level == 2: # Watchdog timeout. if self._period is not None: if self._period < 2000000000: self._period += (self._watchdog * 1000) def RPM(self): """ Returns the RPM. """ RPM = 0 if self._period is not None: RPM = 60000000 / (self._period * self.pulses_per_rev) if RPM < self.min_RPM: RPM = 0 return RPM def cancel(self): """ Cancels the reader and releases resources. """ self.pi.set_watchdog(self.gpio, 0) # cancel watchdog self._cb.cancel() if __name__ == "__main__": import time import pigpio import readRPM import RPi.GPIO as GPIO #GPIO.setmode(GPIO.BCM) #GPIO.setup(20, GPIO.IN, pull_up_down=GPIO.PUD_UP) #GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP) print 1 GPIO.setmode(GPIO.BCM) print 2 GPIO.setup(20, GPIO.IN, pull_up_down=GPIO.PUD_UP) print 3 GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP) print 4 count = 5 RPM_GPIO = 4 RUN_TIME = 9600.0 SAMPLE_TIME = 0.15 RPM_LOWER_LIMIT = 20 RPM_HIGHER_LIMIT = 120 LEVEL_TO_POWER = { 1: [6,12,20,29,40,53,69,79,92,106,121], 2: [8,16,26,38,53,68,88,103,120,138,152], 3: [9,20,32,47,66,84,107,125,148,172,186], 4: [11,23,39,56,79,101,126,150,173,206,219], 5: [13,27,45,65,92,117,145,175,202,238,254], 6: [15,31,52,75,105,135,166,202,231,275,289], 7: [16,35,58,85,118,152,185,226,260,305,332], 8: [18,39,65,96,131,169,208,249,289,333,375], 9: [19,42,71,104,144,184,227,272,318,361,408], 10:[21,46,77,113,157,199,245,295,345,386,442], 11:[23,50,84,123,170,216,262,318,372,413,480], 12:[24,53,89,131,183,230,279,342,398,441,512], 13:[26,56,94,139,196,245,296,365,424,468,548], 14:[28,60,101,148,209,261,318,389,449,494,585], 15:[30,64,108,158,222,277,337,415,476,518,620], 16:[32,68,115,168,235,296,355,439,503,548,658], 17:[33,72,122,177,248,312,373,463,530,576,694], 18:[35,76,129,187,261,328,390,484,556,606,727], 19:[37,79,134,195,274,342,407,507,572,632,763], 20:[39,83,140,204,287,354,424,528,598,659,790], 21:[40,87,146,213,300,368,442,551,616,689,812], 22:[42,91,153,223,313,385,461,574,645,720,840], 23:[44,95,160,234,326,401,479,598,673,752,872], 24:[47,101,171,246,340,418,501,625,706,788,908], } def calculate_power(LEVEL, RPM): if RPM <= RPM_LOWER_LIMIT: return 0 if RPM >= RPM_HIGHER_LIMIT: return 0 return LEVEL_TO_POWER[LEVEL][(RPM) //10] # //10 def main(): for LEVEL, RPM in [(1, 6), (2, 8), (3, 9)]: print(calculate_power(LEVEL, RPM)) pi = pigpio.pi() p = readRPM.reader(pi, RPM_GPIO) start = time.time() while (time.time() - start) < RUN_TIME: input_state = GPIO.input(20) if input_state == False: if count < 24: count = count + 1 RPM = (int(RPM+1)) LEVEL = count # print('Power',calculate_power(LEVEL, RPM),'Level', count, 'RPM={}'.format(int(RPM+1))) print(calculate_power(LEVEL, RPM)) time.sleep(SAMPLE_TIME) input_state = GPIO.input(21) if input_state == False: if count > 1: count = count - 1 RPM = (int(RPM+1)) LEVEL = count print(calculate_power(LEVEL, RPM)) time.sleep(SAMPLE_TIME) LEVEL = count RPM = p.RPM() RPM = (int(RPM+1)) time.sleep(SAMPLE_TIME) print(calculate_power(LEVEL, RPM)) # print('Power',calculate_power(LEVEL, RPM),'Level', count, "RPM={}".format(int(RPM+1))) GPIO.setup(20, GPIO.IN, pull_up_down=GPIO.PUD_UP) print 7 GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP) print 8 p.cancel() pi.stop() if __name__ == '__main__': main()
Code:Event: 247 Power: 0w Cadence: undefinedrpm 0 Event: 248 Power: 0w Cadence: undefinedrpm 0 Event: 249 Power: 0w Cadence: undefinedrpm 0 Event: 250 Power: 0w Cadence: undefinedrpm 0 Event: 251 Power: 0w Cadence: undefinedrpm 0 Event: 252 Power: 0w Cadence: undefinedrpm 0 Event: 253 Power: 0w Cadence: undefinedrpm 0 Event: 254 Power: 0w Cadence: undefinedrpm 0 Event: 0 Power: 0w Cadence: undefinedrpm 0 Event: 1 Power: 0w Cadence: undefinedrpm 0 Event: 2 Power: 0w Cadence: undefinedrpm 0 Event: 3 Power: 0w Cadence: undefinedrpm 0 Event: 4 Power: 0w Cadence: undefinedrpm 0 Event: 5 Power: 0w Cadence: undefinedrpm 0 Event: 6 Power: 0w Cadence: undefinedrpm 0 Event: 7 Power: 0w Cadence: undefinedrpm 0 Event: 8 Power: 0w Cadence: undefinedrpm 0 Event: 9 Power: 0w Cadence: undefinedrpm 0 Event: 10 Power: 0w Cadence: undefinedrpm 0 Event: 11 Power: 0w Cadence: undefinedrpm 0 Event: 12 Power: 0w Cadence: undefinedrpm 0 Event: 13 Power: 0w Cadence: undefinedrpm 0 Event: 14 Power: 0w Cadence: undefinedrpm 0 Event: 15 Power: 0w Cadence: undefinedrpm 0 Event: 16 Power: 0w Cadence: undefinedrpm 0 Event: 17 Power: 0w Cadence: undefinedrpm 0 Event: 18 Power: 0w Cadence: undefinedrpm 0 Event: 19 Power: 0w Cadence: undefinedrpm 0 Event: 20 Power: 0w Cadence: undefinedrpm 0 Event: 21 Power: 0w Cadence: undefinedrpm 0 Event: 22 Power: 0w Cadence: undefinedrpm 0 Event: 23 Power: 0w Cadence: undefinedrpm 0 Event: 24 Power: 0w Cadence: undefinedrpm 0 Event: 25 Power: 0w Cadence: undefinedrpm 0 Event: 26 Power: 0w Cadence: undefinedrpm 0 Event: 27 Power: 0w Cadence: undefinedrpm 0 Event: 28 Power: 0w Cadence: undefinedrpm 0 Event: 29 Power: 0w Cadence: undefinedrpm 0 Event: 30 Power: 0w Cadence: undefinedrpm
- - - Aktualisiert - - -
Jetzt lief er gerade wieder los(von 31 bis 9)
Neu gestartet....
nach ca. 5-8 Minuten
Event 1 bis 231
dann steht es wieder
cpu und memory Auslastung ist nicht erwähnenswert, also resource Problem kanns nicht sein
- - - Aktualisiert - - -
Also wenn ich aus dem Orginal test.js das setTimeout(a, 249); entferne bleibt das script auch bei
startup
Max channels: 8
cycling power meter initialized
stehen.
muss da was mit zu tun haben?Geändert von Landix (05-05-2017 um 19:30 Uhr)
-
06-05-2017, 00:09 #40
Foren-Gott
- registriert
- 19-05-2008
- Beiträge
- 5.667
-
06-05-2017, 00:37 #41
Eroberer
- registriert
- 03-05-2017
- Beiträge
- 59
AW: Python to Javascript
Welches von dir?
das von dir weiter oben funktioniert, habe ich doch probiert
die 249 ist aber auch die Datenrate wie das ant+ übermittelt, meine Ausgabe macht das auch bei sampletime 0.249 also a 0.249 kommt auch eine Ausgabe.
-
06-05-2017, 01:10 #42
Foren-Gott
- registriert
- 19-05-2008
- Beiträge
- 5.667
AW: Python to Javascript
http://forum.jswelt.de/node-js/63342...tml#post404777 (Python to Javascript)
du hast dein js mit meinem python getestet, jetzt sollst du mein js mit deinem python testen
wenn die fest sein muss, musst du noch was zusätzlich einbauen, aber dazu muss die übermittlung der daten von python zu js erst mal laufen
die vorgegebene zeit 249 ist bei js aber sowieso mehr ein wunsch als wirklichkeit, das dürfte unter node besser funktionieren als im browser, aber verlassen kannst du dich da nicht drauf
-
06-05-2017, 10:55 #43
Eroberer
- registriert
- 03-05-2017
- Beiträge
- 59
AW: Python to Javascript
Ach so.... na ja ist ja auch schon spät.
nein es kommt keine Ausgabe.
das meinst du:
Code:var PythonShell = require('python-shell'); var pyshell = new PythonShell('7powerx.py'); pyshell.on('message', function (message) { console.log(message); }); pyshell.end(function (err) { if (err) throw err; console.log('finished'); });
Wenn ich die sample time auf 0.0 setzt in meinem python script rennt es durch, allerdings bricht dann der raspberry zusammen und ich muss den neu starten
Aber somit wissen wir, ich habe ein time Problem!
- - - Aktualisiert - - -
Wenn ich auf 0.001 setzte stottert das script.
Kann ich hiermit was anfangen?
Code:function sleep(time, callback) { var stop = new Date().getTime(); while(new Date().getTime() < stop + time) { ; } callback(); } to be used as sleep(1000, function() { // executes after one second, and blocks the thread });
Geändert von Landix (06-05-2017 um 01:21 Uhr)
-
06-05-2017, 11:28 #44
Foren-Gott
- registriert
- 19-05-2008
- Beiträge
- 5.667
-
06-05-2017, 12:30 #45
Eroberer
- registriert
- 03-05-2017
- Beiträge
- 59
AW: Python to Javascript
In meinem py Script ist eine (Ich glaube es heisst GLOBALE]
Code:SAMPLE_TIME = 0.249
Code:LEVEL = count RPM = p.RPM() RPM = (int(RPM+1)) time.sleep(SAMPLE_TIME) print(calculate_power(LEVEL, RPM))
GPIO 4 = RPM
GPIO 20,21 = die LEVEL
wenn ich das time.sleep weg lasse geht cpu und memory auf 100% dann *tod
- - - Aktualisiert - - -
ich glaub ich habs!
Code:var pyshell = new PythonShell('7powerx.py',{scriptPath:"./", pythonOptions: ['-u']});
Läuft! Jetzt muss ich noch mein py script so bauen das es interpoliertdann fertig und dann wird Zwift gerockt.
Ich poste das Ergebnis mit etwas Anleitung auf Github. Ich denke das andere das auch machen wollen!
Und vielen Dank für deine Hilfe tsseh. Das hat mich sehr viel weiter gebracht.Geändert von Landix (06-05-2017 um 12:48 Uhr)
Ähnliche Themen
-
(Junior) Backend Developer: Ruby / Python / PHP / JavaScript
Von campusjaeger im Forum JobsAntworten: 0Letzter Beitrag: 10-12-2016, 09:56 -
(Junior) Backend Developer: Ruby / Python / PHP / JavaScript
Von campusjaeger im Forum JobsAntworten: 0Letzter Beitrag: 07-09-2016, 12:38 -
Python-Variable in Javascript verwenden
Von siggi1147 im Forum JavaScriptAntworten: 2Letzter Beitrag: 24-04-2008, 18:34 -
[Python]Was ist das?
Von Kriegr im Forum Serverseitige ProgrammierungAntworten: 2Letzter Beitrag: 20-05-2003, 16:11 -
python website
Von python im Forum Site-CheckAntworten: 7Letzter Beitrag: 14-02-2003, 16:30
Lesezeichen