Skip to content

Commit 8596b55

Browse files
committed
Updated the ev3dev_port_logger application
- Deleted template - Deleted old example files - Added fully worked example
1 parent c3c4536 commit 8596b55

File tree

10 files changed

+3212
-3050
lines changed

10 files changed

+3212
-3050
lines changed
Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env python
2+
13
import json
24
import argparse
35
import time
@@ -42,9 +44,21 @@ def join(self, timeout=None):
4244

4345
test = json.loads( open( args.infile ).read() )
4446

47+
def execute_actions(actions):
48+
for p,c in actions['ports'].items():
49+
for b in c:
50+
for k,v in b.items():
51+
setattr( device[p], k, v )
52+
4553
device = {}
4654
logs = {}
4755

56+
for p,v in test['meta']['ports'].items():
57+
device[p] = getattr( ev3, v['device_class'] )( p )
58+
59+
if test['actions'][0]['time'] < 0:
60+
execute_actions(test['actions'][0])
61+
4862
for p,v in test['meta']['ports'].items():
4963
device[p] = getattr( ev3, v['device_class'] )( p )
5064

@@ -57,13 +71,10 @@ def join(self, timeout=None):
5771
end = start + test['meta']['max_time'] * 1e-3
5872

5973
for a in test['actions']:
60-
then = start + a['time'] * 1e-3
61-
while time.time() < then: pass
62-
63-
for p,c in a['ports'].items():
64-
for b in c:
65-
for k,v in b.items():
66-
setattr( device[p], k, v )
74+
if a['time'] >= 0:
75+
then = start + a['time'] * 1e-3
76+
while time.time() < then: pass
77+
execute_actions(a)
6778

6879
while time.time() < end:
6980
pass

tests/motor/motor_ramps.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"meta": {
3+
"title": "Test Large EV3 Motor Operation",
4+
"subtitle": "Positive and Negative Ramps",
5+
"notes": "ramp_up_sp:1000\nramp_down_sp:2000\ntime_sp: 2000\nspeed_sp: +/- 900\nstop_command: coast",
6+
"interval": 10,
7+
"name": "run-direct-test",
8+
"max_time": 8000,
9+
"ports": { "outA": { "log_attributes": [ "speed",
10+
"position",
11+
"duty_cycle" ],
12+
"device_class": "Motor" } }
13+
},
14+
"actions": [
15+
{ "time": -1, "ports": { "outA": [ { "command": "reset" },
16+
{ "position": 0 },
17+
{ "ramp_up_sp": 1000 },
18+
{ "ramp_down_sp": 2000 },
19+
{ "time_sp": 2000 },
20+
{ "speed_sp": 900 } ] } },
21+
{ "time": 0, "ports": { "outA": [ { "command": "run-timed" } ] } },
22+
{ "time": 4000, "ports": { "outA": [ { "speed_sp": -900 },
23+
{ "command": "run-timed" } ] } }
24+
]
25+
}

0 commit comments

Comments
 (0)