Skip to content

Instantly share code, notes, and snippets.

@jadonk
Last active October 10, 2019 19:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jadonk/8ece4ad83ac67e5215af6a3d686d0ae2 to your computer and use it in GitHub Desktop.
Save jadonk/8ece4ad83ac67e5215af6a3d686d0ae2 to your computer and use it in GitHub Desktop.
git clone https://gist.github.com/jadonk/8ece4ad83ac67e5215af6a3d686d0ae2
cd 8ece4ad83ac67e5215af6a3d686d0ae2
sudo ./thrash_motors.sh
sudo ./pwmcleaner.sh
#!/bin/bash
cd /sys/class/pwm
set -x
set -e
FILES=$(ls -d pwm-*)
for file in $FILES; do
echo Found $file
PWM=$(echo $file | cut -d'-' -f 2)
PWMCHIP=pwmchip$(echo $PWM | cut -d':' -f 1)
CHANNEL=$(echo $PWM | cut -d':' -f 2)
echo Disabling $PWMCHIP channel $CHANNEL...
echo 0 > ${file}/enable
echo $CHANNEL > ${PWMCHIP}/unexport
done
#!/bin/bash
set -x
set -e
while true; do
rc_test_motors -d 0.2 -m 1 &
RC=$!
sleep 1
kill -15 \$RC
sleep 1
done
@dmalawey
Copy link

What does this line do?
RC=$?

@jadonk
Copy link
Author

jadonk commented Mar 26, 2019

It was supposed to be RC=$! and it saves the process ID of the last invocation. This is done so we can kill the process after waiting a bit.

@rg-28
Copy link

rg-28 commented Oct 10, 2019

I was trying to use the above given procedure to solve my similar problem on BeagleBoneBlue but while running the script files I got the following errors:
In pwmcleaner.sh file the error was:
./pwmcleaner.sh: line 12: echo: write error: Invalid argument
and while trying to resolve this I changed echo 0 > ${file}/enable to echo 0 > ${file/enable}
and the output was:
./pwmcleaner.sh: line 12: pwm-0:0: Is a directory

And in thrash_motors.sh, the error was:
./thrash_motors.sh: line 8: kill: $RC: arguments must be process or job IDs
and to resolve this I changed kill -15 $RC to kill -15 $RC
and the output was:
./thrash_motors.sh: line 8: kill: (1668) - No such process

So I wanted to know whether I have done it right or not?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment