-
Notifications
You must be signed in to change notification settings - Fork 5
/
testmotor
95 lines (92 loc) · 2.99 KB
/
testmotor
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
#!/bin/bash -u
# Script_name : testmotor
# Author : Bert Lindeman
# Description : Fiddle a bit with a connected motor
# Version : v1.3
# Date : 2014-11-04
# Usage : testmotor
# Notes : One parameter (optional): the number of the tacho-motor
# to be exercised.
# Copyright : 2014 Bert Lindeman
# License : GPL-3.0+
#
#============================================================================
#
# Changelog
# Date By Description
# 20141104 BL prepare for release v1.3
# 20140914 BL o Add new attribute (3.16.1) encoder_mode
# o small cleanup
# 20140826 BL o add script header
# o check for missing or too many argument(s)
#
#============================================================================
if [ "$#" -gt 1 ]; then
echo "$0 ERROR: Too many parameters"
exit
fi
if [ "$#" == "0" ]; then
MOTORPATH=/sys/class/tacho-motor/motor0
else
MOTORPATH=/sys/class/tacho-motor/motor$1
fi
#
showStateS () {
for (( i=1; i<=5; i++ ))
do
printf "%14s: %5d " "duty_cycle_sp" "`cat $MOTORPATH/duty_cycle_sp`"
printf "%8s: %10s " "state" "`cat $MOTORPATH/state`"
printf "%12s: %9s " "encoder_mode" "`cat $MOTORPATH/encoder_mode`"
printf "%18s: %6d " "position" "`cat $MOTORPATH/position`"
printf "%16s: %6d\n" "pulses_per_second" "`cat $MOTORPATH/pulses_per_second`"
sleep 0.2
done
}
echo "Working with motorpath: $MOTORPATH"
if [ -e $MOTORPATH/ ]; then
echo 1 > $MOTORPATH/reset
## DUTY_SP_VAR=duty_cycle_sp
echo -e "\t\t==== regulation_mode OFF"
echo off > $MOTORPATH/regulation_mode
echo 0 > $MOTORPATH/duty_cycle_sp
echo 1 > $MOTORPATH/run
showStateS
sleep 0.1
echo 25 > $MOTORPATH/duty_cycle_sp
showStateS
sleep 0.7
echo -e "\t\t==== encoder_mode inverted "
echo inverted > $MOTORPATH/encoder_mode
showStateS
sleep 0.7
echo 50 > $MOTORPATH/duty_cycle_sp
showStateS
sleep 0.7
echo -e "\t\t==== duty_cycle_sp to negative "
echo -50 > $MOTORPATH/duty_cycle_sp
showStateS
echo -e "\t\t==== regulation_mode ON || duty_cycle_sp to zero encoder_mode normal "
echo normal > $MOTORPATH/encoder_mode
echo on > $MOTORPATH/regulation_mode
echo 0 > $MOTORPATH/duty_cycle_sp
sleep 0.2
showStateS
echo 500 > $MOTORPATH/pulses_per_second_sp
sleep 0.2
showStateS
echo 300 > $MOTORPATH/pulses_per_second_sp
sleep 0.2
showStateS
echo 100 > $MOTORPATH/pulses_per_second_sp
sleep 0.2
showStateS
echo -300 > $MOTORPATH/pulses_per_second_sp
sleep 0.2
showStateS
sleep 0.7
echo 0 > $MOTORPATH/run
sleep 0.2
showStateS
else
echo -e "Path for motor does not exist: $MOTORPATH"
fi