Main Page
Related Pages
Modules
Data Structures
Files
Examples
tacho.py
1
# -*- coding: utf-8 -*-
2
3
from
time
import
sleep
4
import
sys
5
from
ev3dev
import
*
6
7
if
__name__ ==
'__main__'
:
8
if
not
EV3_BRICK:
9
# Disable auto-detection of the brick (you have to set the correct address below)
10
ev3.brick_addr =
'192.168.0.204'
11
12
if
ev3_init
() == -1: sys.exit( 1 )
13
14
if
not
EV3_BRICK:
15
print
'The EV3 brick auto-detection is DISABLED,'
16
print
'waiting %s online with plugged tacho...'
% ( ev3.brick_addr )
17
else
:
18
print
'Waiting tacho is plugged...'
19
20
while
ev3_tacho_init
() < 1: sleep( 1.0 )
21
22
print
'*** ( EV3 ) Hello! ***'
23
24
print
'Found tacho motors:'
25
for
i
in
range( DESC_LIMIT ):
26
type_inx =
ev3_tacho_desc_type_inx
( i )
27
if
type_inx != TACHO_TYPE__NONE_:
28
print
' type ='
,
ev3_tacho_type
( type_inx )
29
print
' port ='
,
ev3_tacho_port_name
( i )
30
31
ok, sn =
ev3_search_tacho
( LEGO_EV3_M_MOTOR )
32
if
ok:
33
print
'LEGO_EV3_M_MOTOR is found, run for 5 sec...'
34
max_speed =
get_tacho_max_speed
( sn )
35
print
' max_speed ='
, max_speed
36
set_tacho_stop_action_inx
( sn, TACHO_COAST )
37
set_tacho_speed_sp
( sn, max_speed * 2 / 3 )
38
set_tacho_time_sp
( sn, 5000 )
39
set_tacho_ramp_up_sp
( sn, 2000 )
40
set_tacho_ramp_down_sp
( sn, 2000 )
41
set_tacho_command_inx
( sn, TACHO_RUN_TIMED )
42
# Wait tacho stop
43
sleep( 0.1 )
44
ok, flags =
get_tacho_state_flags
( sn )
45
while
ok
and
flags:
46
ok, flags =
get_tacho_state_flags
( sn )
47
48
print
'run to relative position...'
49
set_tacho_speed_sp
( sn, max_speed / 2 )
50
set_tacho_ramp_up_sp
( sn, 0 )
51
set_tacho_ramp_down_sp
( sn, 0 )
52
set_tacho_position_sp
( sn, 90 )
53
for
i
in
range( 8 ):
54
set_tacho_command_inx
( sn, TACHO_RUN_TO_REL_POS )
55
sleep( 0.5 )
56
else
:
57
print
'LEGO_EV3_M_MOTOR is NOT found'
58
59
ev3_uninit
()
60
print
'*** ( EV3 ) Bye! ***'
Generated on Fri Oct 20 2017 17:49:28 by
1.8.11