-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathshowmotor
317 lines (277 loc) · 10.4 KB
/
showmotor
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/bin/bash -u
# Script_name : showmotor
# Author : Bert Lindeman
# Description : Show status of connected motors
# Version : v1.3
# Date : 2014-11-04
# Usage : showmotor
# Notes : Only tested with LEGO EV3 and NXT motors
# Copyright : 2014 Bert Lindeman
# License : GPL-3.0+
#
#============================================================================
#
# Changelog
# Date By Description
# 20141104 BL prepare for release v1.3
# 20141023 BL adapt to changes at kernel 3.16.1-6
# 20140911 BL adapt to changes at kernel 3.16.1-2
# 20140826 BL Add script header
# 20150105 BL Add servo-motor
# 20150115 BL Simplify search for the motorpath
# 20150430 BL adapt to changes at kernel 3.16.7-ckt9-ev3dev1
# 20160103 BL adapt to image 20151230 (change file names)
#============================================================================
#
#
# show motor status
. /usr/local/bin/bert_ev3dev_functions
#
# determine which motor(port) is connected to what tacho-motor-number
# /sys/class/tacho-motor/motor*/address is the link between motor# and port
#
#
# IFS=$' \n' read -a tachoPath <<< "`echo /sys/class/tacho-motor/motor*/ /sys/class/dc-motor/motor*/ /sys/class/servo-motor/motor*/`"
IFS=$' \n' read -a tachoPath <<< "`echo /sys/class/*motor/motor*/`"
#
for i in ${!tachoPath[@]} # ! walk the index
do
echo -e "process $i ${tachoPath[$i]}"
if [ -e ${tachoPath[$i]} ]; then
cd ${tachoPath[$i]}
# determine motortype
p=`pwd`
basename="`basename $p`"
dirname="`dirname $p`"
dir3="`basename ${dirname}`" # third node in path
#ls -l driver_name
if [ $? -eq 0 ] ; then
type="."
if [ -r driver_name ]; then
type="`cat driver_name`"
attribute="driver"
elif [ -r type ]; then
type="`cat type`"
attribute="tacho"
else
type=$dir3
attribute="dc"
fi
printf "${brblue}Motor on port $brwhite%s$brblue as type=$brwhite%-10s$brblue at $brwhite%s$white\n" \
"`cat address`" "$type" "${tachoPath[$i]} "
curval="."; title="_"
if [ -e duty_cycle_sp ] ; then
curval=`cat duty_cycle_sp`
title="duty_cycle_sp:"
fi
line1_1=`printf "%-21s %12s\n" "${title}" "$curval"`
curval="."; title="_"
if [ -e pulses_per_second_sp ] ; then
curval=`cat pulses_per_second_sp`
title="pulses_per_second_sp:"
fi
line2_1=`printf "%-21s %12s\n" "${title}" "$curval"`
curval="."; title="_"
if [ -e encoder_mode ] ; then
curval=`cat encoder_mode`
title="encoder_mode:"
fi
encval=$curval # use later..
line3_1=`printf "%-21s %12s\n" "${title}" "$curval"`
curval="."; title="_"
if [ -e position_sp ] ; then
curval=`cat position_sp`
title="position_sp:"
fi
line4_1=`printf "%-21s %12s\n" "${title}" "$curval"`
curval="."; title="_"
if [ -e time_sp ] ; then
curval=`cat time_sp`
title="time_sp:"
fi
line5_1=`printf "%-21s %12s\n" "${title}" "$curval"`
curval="."; title="_"
if [ -e ramp_down_sp ] ; then
curval=`cat ramp_down_sp`
title="ramp_down_sp:"
elif [ -e ramp_down_ms ] ; then
curval=`cat ramp_down_ms`
title="ramp_down_ms:"
fi
line6_1=`printf "%-21s %12s\n" "${title}" "$curval"`
curval="."; title="_"
if [ -e ramp_up_sp ] ; then
curval=`cat ramp_up_sp`
title="ramp_up_sp:"
elif [ -e ramp_up_ms ] ; then
curval=`cat ramp_up_ms`
title="ramp_up_ms:"
fi
line7_1=`printf "%-21s %12s\n" "${title}" "$curval"`
line8_1="_ ."
line9_1="_ ."
line10_1=" "
curval="."; title="_"
if [ -e pulses_per_second_sp ]; then
curval=`cat pulses_per_second`
title="pulses_per_second:"
fi
line2_2=`printf "%-21s %12s\n" "${title}" "$curval"`
curval="."; title="_"
if [ -e polarity_mode ] ; then
curval=`cat polarity_mode`
title="polarity_mode:"
elif [ -e polarity ] ; then
curval=`cat polarity`
title="polarity:"
fi
polval=$curval
line3_2=`printf "%-21s %12s\n" "${title}" "$curval"`
curval="."; title="_"
if [ -e position ] ; then
curval=`cat position`
title="position:"
fi
line4_2=`printf "%-21s %12s\n" "${title}" "$curval"`
curval="."; title="_"
if [ -e position_mode ] ; then
curval=`cat position_mode`
title="position_mode:"
fi
line5_2=`printf "%-21s %-50s\n" "${title}" "$curval"`
curval="."; title="_"
if [ -e regulation_mode ] ; then
curval=`cat regulation_mode`
title="regulation_mode:"
fi
line6_2=`printf "%-21s %12s\n" "${title}" "$curval"`
curval="."; title="_"
if [ -e run_mode ] ; then
curval=`cat run_mode`
title="run_mode:"
elif [ -r command ]; then # does exist but is write only NOW
# command is write-only but still bash reports it is readile???
curval=`cat command 2>/dev/null` && title="command:"
fi
line7_2=`printf "%-21s %12s\n" "${title}" "$curval"`
curval="-"; title="_"
if [ -e state ] ; then
curval=`cat state`
title="state:"
fi
state=$curval
line8_2=`printf "%-21s %s\n" "${title}" "$curval"`
curval="-"; title="_"
if [ -e stop_mode ] ; then
curval=`cat stop_mode`
title="stop_mode:"
fi
line9_2=`printf "%-21s %12s\n" "${title}" "$curval"`
line10_2="_ ."
# If duty_cycle on dc-motor present as speed
curval="."; title="_"; duty_cycle=0
if [ -e duty_cycle ]; then
curval=`cat duty_cycle`
title="duty_cycle:"
duty_cycle=$curval
fi
line1_2=`printf "%-21s %12s\n" "${title}" "$curval"`
curval="-"; title="_"; runval=0
if [ -e run ] ; then
curval=`cat run`
runval=$curval
title="run"
fi
line1_3=`printf "%-21s %8s\n" "${title}" "$curval"`
if [ $runval == 0 ]; then
runval=$duty_cycle
fi
set +x
curval="-"; title="_"
if [ -e estop ] ; then
curval=`cat estop`
title="estop:"
fi
line2_3=`printf "%-21s %8s\n" "${title}" "$curval"`
curval="-"; title="_"
if [ -e speed_regulation_D ] ; then
curval=`cat speed_regulation_D`
title="speed_regulation_D:"
fi
line3_3=`printf "%-21s %8s\n" "${title}" "$curval"`
curval="-"; title="_"
if [ -e speed_regulation_I ] ; then
curval=`cat speed_regulation_I`
title="speed_regulation_I:"
fi
line4_3=`printf "%-21s %8s\n" "${title}" "$curval"`
curval="-"; title="_"
if [ -e speed_regulation_K ] ; then
curval=`cat speed_regulation_K`
title="speed_regulation_K:"
fi
line5_3=`printf "%-21s %8s\n" "${title}" "$curval"`
curval="-"; title="_"
if [ -e speed_regulation_P ] ; then
curval=`cat speed_regulation_P`
title="speed_regulation_P:"
fi
line6_3=`printf "%-21s %8s\n" "${title}" "$curval"`
# type already in top of the display
#
line7_3=""
## uevent >> Line 11 as it's too long...
#
line8_3="_ ."
line9_3="_ ."
tabc=$brblue
# Long string....
curval="."; title="_"
if [ -e stop_modes ]; then
curval=`cat stop_modes`
title="stop_modes:"
elif [ -e commands ]; then
curval=`cat commands`
title="commands: "
fi
line10_1=`printf "$tabc%-10s $white%s\n" "${title}" "$curval"`
# There is a newline in uevent, I do not want to see it....
curval=`cat uevent` ; title="uevent: " ; curval=`echo ${curval} | tr '\n' ' '`
line11_1=`printf "$tabc%-10s $white%s\n" "${title}" "$curval"`
# echo -e "1" ${line11_1}
# echo -e "2" "${line11_1}"
printf "\n$brwhite%32s %32s %32s$white\n" " == setpoints == " " == state == " " == switches =="
#
if [ attribute == "dc" ] ; then
echo "set duty_cycle as speed"
fi
if [ "$runval" == 0 ] ; then runcol=${red}
else runcol=${brgreen}
fi
if [ "$encval" == "normal" ] ; then enccol=${brgreen}
elif [ "$encval" == "." ] ; then enccol=${blue}
else enccol=${red}
fi
if [ "$polval" == "normal" ] ; then polcol=${brgreen}
elif [ "$polval" == "." ] ; then polcol=${blue}
else polcol=${red}
fi
printf "$tabc%-21s $white%08s $brwhite|$white $tabc%-18s $runcol%11s $brwhite|$white $tabc%-21s $runcol%10s\n" $line1_1 $line1_2 $line1_3
printf "$tabc%-21s $white%08s $brwhite|$white $tabc%-18s $white%11s $brwhite|$white $tabc%-21s $white%10s\n" $line2_1 $line2_2 $line2_3
printf "$tabc%-21s $enccol%8s $brwhite|$white $tabc%-18s $polcol%11s $brwhite|$white $tabc%-21s $white%10s\n" $line3_1 $line3_2 $line3_3
printf "$tabc%-21s $white%08s $brwhite|$white $tabc%-18s $white%11s $brwhite|$white $tabc%-21s $white%10s\n" $line4_1 $line4_2 $line4_3
printf "$tabc%-21s $white%08s $brwhite|$white $tabc%-18s $white%11s $brwhite|$white $tabc%-21s $white%10s\n" $line5_1 $line5_2 $line5_3
printf "$tabc%-21s $white%08s $brwhite|$white $tabc%-18s $white%11s $brwhite|$white $tabc%-21s $white%10s\n" $line6_1 $line6_2 $line6_3
printf "$tabc%-21s $white%08s $brwhite|$white $tabc%-18s $white%11s $brwhite|$white $tabc%-21s $white%10s\n" $line7_1 $line7_2 "`echo -n $line7_3`"
printf "$tabc%-21s %00000008s $brwhite|$white $tabc%-18s $runcol%11s $brwhite|$white $tabc%-21s %10s\n" $line8_1 $line8_2 $line8_3
printf "$tabc%-21s %00000008s $brwhite|$white $tabc%-18s $white%11s $brwhite|$white $tabc%-21s %10s\n" $line9_1 $line9_2 $line9_3
#
echo "$line10_1" # 10_2 and 10_3 not used.
# no need to show uevent (line11) as info is already shown above
# echo "$line11_1" # 11_2 and 11_3 not used.
echo ""
else
echo "does not exist entry $i ${tachoPath[$i]} "
fi
fi
done