-
Notifications
You must be signed in to change notification settings - Fork 5
/
stopmotors
109 lines (96 loc) · 3.47 KB
/
stopmotors
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash -ue
# Script_name : stopmotors
# Author : Bert Lindeman
# Description : Stop all recognized tacho motors
# Version : v1.3
# Date : 2014-11-04
# Usage : stopmotors
# Notes :
# Copyright : 2014 Bert Lindeman
# License : GPL-3.0+
#
#============================================================================
#
# Changelog
# Date By Description
# 20141104 BL prepare for release v1.3
# 20141024 BL Temporary "fix" for issue 186 (duty-cycle only if "run")
# 20141022 BL Add rxc-motor and rxc-led
# Adapt to "force motor driver"
# 20140916 BL Do not use fixed number suffix on tacho-motor#
# 20140907 BL Use centralized functions
# 40141125 BL Remove circumvention for dc-motors
#============================================================================
. /usr/local/bin/bert_ev3dev_functions
#
showmotor () {
runfilename=${1:-run}
if [ $motorpower -eq 0 ]; then motorcolor=$brgreen
else motorcolor=$brred
fi
printf "${motorcolor}%3s$brwhite" "`cat ${MOTORPATH}/$runfilename`"
}
#
# "old" directory name before kernel 3.16.1-6:
for m in /sys/class/tacho-motor/tacho-motor*
do
MOTORPATH="$m"
if [ -e $MOTORPATH ]; then
printf "%-40s %-6s " "$MOTORPATH/run" "status"
# report status before reset
motorpower=`cat $MOTORPATH/run`
printf "$brblue %-6s $brwhite%3s " "before" "`showmotor`"
# set back to zero:
echo 0 > "$MOTORPATH/run"
# report status after reset
motorpower=`cat $MOTORPATH/run`
printf "$brblue %-6s $brwhite%-3s\n" "after" "`showmotor`"
fi
done
#
# "new" directory name starting at kernel 3.16.1-6:
for m in /sys/class/tacho-motor/motor*
do
MOTORPATH="$m"
if [ -e $MOTORPATH ]; then
printf "%-40s %-6s " "$MOTORPATH/run" "status"
# report status before reset
motorpower=`cat $MOTORPATH/run`
printf "$brblue %-6s $brwhite%3s " "before" "`showmotor`"
# set back to zero:
echo 0 > "$MOTORPATH/run"
# report status after reset
motorpower=`cat $MOTORPATH/run`
printf "$brblue %-6s $brwhite%-3s\n" "after" "`showmotor`"
fi
done
# ================================
for m in /sys/class/dc-motor/motor*/
do
MOTORPATH="$m"
if [ -e $MOTORPATH ]; then
printf "%-40s %-6s " "${MOTORPATH}duty_cycle" "status"
# report status before reset
motorpower=`cat ${MOTORPATH}duty_cycle`
printf "$brblue %-6s $brwhite%3s " "before" "`showmotor duty_cycle`"
# set ramping to zero to decrease the stop duration:
#? echo 0 > "${MOTORPATH}ramp_down_ms"
#? echo 0 > "${MOTORPATH}ramp_up_ms"
# echo "DEBUG Running in dir `pwd` MOTORPATH=${MOTORPATH}"
#
# echo duty_cycle only accepted if command=run: ISSUE 186
#
# prevcommand=`cat ${MOTORPATH}command`
# echo "run" > ${MOTORPATH}command
# set back to zero:
echo 0 > "${MOTORPATH}duty_cycle_sp"
echo "brake" > ${MOTORPATH}command
# # set command back:
# echo $prevcommand > ${MOTORPATH}command
# report status after reset
# echo "DEBUG Running in dir `pwd` MOTORPATH=${MOTORPATH}"
motorpower=`cat ${MOTORPATH}duty_cycle`
printf "$brblue %-6s $brwhite%-3s\n" "after" "`showmotor duty_cycle`"
fi
# controldir=`find /sys/class/${motordir} -name "motor*"`
done