Pi Scratch new for free download now


42 posts   Page 2 of 2   1, 2
by ghp » Tue Jun 13, 2017 2:50 am
Hello,
please provide the config file in order to verify that the software works. You have hit some problems where I changed something recently and I would like to avoid that you run into additional trouble.

Regards,
Gerhard
Posts: 1135
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
by kaszpirowski » Thu Jun 15, 2017 6:32 am
Hello,
Here is a configuration file that I tried to run:


<?xml version='1.0' encoding='utf-8' ?>
<config version='1.0'
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="config.xsd" >
<description>
Servo control.
Input values are servo_A.
Values 0..100.
</description>


<adapter class='adapter.gpio.GpioOutputPWMServo' name='servo_pwm'>
<description>Sample GPIO PWM</description>

<gpio port='GPIO23'> <!-- use names precisely from GPIO00 to GPIO31 -->
<default dir='OUT' pull='PUD_OFF' default='low' />
<active dir='RESERVED' />
</gpio>
<input_value name='rate'> <!-- leave this name as is -->
<variable name='servo_A'/> <!-- modify this name according to your needs; this is the name used in scratch -->
</input_value>

<parameter name='frequency' value='50' />
<parameter name='rate' value='50' />
</adapter>
</config>

And the result of the launch:

root@raspberrypi:/home/pi/scratchClient# python3 src/scratchClient.py -c config/config_gpio_servo1.xml -v
2017-06-15 08:25:39,216 - gpio.RPi_GPIO_GPIOManager - INFO - GPIOManager setActive, True
2017-06-15 08:25:39,217 - gpio.RPi_GPIO_GPIOManager - INFO - 0.6.3
2017-06-15 08:25:39,219 - __main__ - INFO - event_connect
2017-06-15 08:25:39,220 - __main__ - INFO - Trying to connect to scratch.
2017-06-15 08:25:39,221 - __main__ - INFO - Connected to Scratch !
2017-06-15 08:25:39,222 - adapter.gpio - INFO - Adapter, setActive servo_pwm True
2017-06-15 08:25:39,222 - gpio.RPi_GPIO_GPIOManager - INFO - activeSetting
Exception in thread scratchClient:
Traceback (most recent call last):
File "/usr/lib/python3.4/threading.py", line 920, in _bootstrap_inner
self.run()
File "src/scratchClient.py", line 918, in run
self._connect()
File "src/scratchClient.py", line 970, in _connect
module.setActive(True)
File "/home/pi/scratchClient/src/adapter/gpio.py", line 454, in setActive
adapter.adapters.GPIOAdapter.setActive(self, state);
File "/home/pi/scratchClient/src/adapter/adapters.py", line 410, in setActive
self.gpioManager.setGPIOActive(gpio, active)
File "/home/pi/scratchClient/src/configuration.py", line 168, in setGPIOActive
self.delegateGPIOManager.setGPIOActive(gpioConfiguration, state)
File "/home/pi/scratchClient/src/gpio/RPi_GPIO_GPIOManager.py", line 138, in setGPIOActive
self.setGpioState(gpioConfiguration, gpioConfiguration.active_setting)
File "/home/pi/scratchClient/src/gpio/RPi_GPIO_GPIOManager.py", line 144, in setGpioState
logger.debug("setGpioState %s", str(setting))
File "/home/pi/scratchClient/src/configuration.py", line 118, in __str__
return "GpioSetting[dir={dir:s}, pull={pull:s}, default={default:s}]".format(dir=self.dir, pull=self.pull, default=self.default)
TypeError: non-empty format string passed to object.__format__
Posts: 23
Joined: Fri May 12, 2017 10:47 pm
by ghp » Thu Jun 15, 2017 7:01 am
Hello,
please download latest scratchClient from http://heppg.de/ikg/wordpress/?page_id=6
This version has the problems fixed.
Regards,
Gerhard
Posts: 1135
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
by kaszpirowski » Thu Jun 15, 2017 9:29 am
answer like this..... :
root@raspberrypi:/home/pi/scratchClient# python3 src/scratchClient.py -c config/config_gpio_servo.xml -v
2017-06-15 11:21:12,982 - gpio.RPi_GPIO_GPIOManager - INFO - GPIOManager setActive, True
2017-06-15 11:21:12,982 - gpio.RPi_GPIO_GPIOManager - INFO - 0.6.3
2017-06-15 11:21:12,985 - __main__ - INFO - event_connect
2017-06-15 11:21:12,985 - __main__ - INFO - Trying to connect to scratch.
2017-06-15 11:21:12,986 - __main__ - INFO - Connected to Scratch !
2017-06-15 11:21:12,987 - adapter.gpio - INFO - Adapter, setActive servo_pwm True
2017-06-15 11:21:12,988 - gpio.RPi_GPIO_GPIOManager - INFO - activeSetting
Exception in thread scratchClient:
Traceback (most recent call last):
File "/usr/lib/python3.4/threading.py", line 920, in _bootstrap_inner
self.run()
File "src/scratchClient.py", line 918, in run
self._connect()
File "src/scratchClient.py", line 970, in _connect
module.setActive(True)
File "/home/pi/scratchClient/src/adapter/gpio.py", line 454, in setActive
adapter.adapters.GPIOAdapter.setActive(self, state);
File "/home/pi/scratchClient/src/adapter/adapters.py", line 410, in setActive
self.gpioManager.setGPIOActive(gpio, active)
File "/home/pi/scratchClient/src/configuration.py", line 168, in setGPIOActive
self.delegateGPIOManager.setGPIOActive(gpioConfiguration, state)
File "/home/pi/scratchClient/src/gpio/RPi_GPIO_GPIOManager.py", line 138, in setGPIOActive
self.setGpioState(gpioConfiguration, gpioConfiguration.active_setting)
File "/home/pi/scratchClient/src/gpio/RPi_GPIO_GPIOManager.py", line 144, in setGpioState
logger.debug("setGpioState %s", str(setting))
File "/home/pi/scratchClient/src/configuration.py", line 118, in __str__
return "GpioSetting[dir={dir:s}, pull={pull:s}, default={default:s}]".format(dir=self.dir, pull=self.pull, default=self.default)
TypeError: non-empty format string passed to object.__format__
Posts: 23
Joined: Fri May 12, 2017 10:47 pm
by ghp » Thu Jun 15, 2017 11:10 am
Hello,
possibly there is a problem with your download.
I added version info to the first log messages. On my test system, output is now:
Code: Select all
root@raspberrypi:/home/pi/scratchClient#  python3 src/scratchClient.py -c config/config_gpio_servo.xml -v
2017-06-15 10:56:44,655 - root - INFO - create ScratchClient 2017-06-15
2017-06-15 10:56:44,857 - gpio.RPi_GPIO_GPIOManager - INFO - GPIOManager setActive, True
2017-06-15 10:56:44,858 - gpio.RPi_GPIO_GPIOManager - INFO - 0.6.3
2017-06-15 10:56:44,860 - __main__ - INFO - event_connect
2017-06-15 10:56:44,861 - __main__ - INFO - Trying to connect to scratch.
2017-06-15 10:56:44,862 - __main__ - INFO - Connected to Scratch !
2017-06-15 10:56:44,863 - adapter.gpio - INFO - Adapter, setActive servo_pwm True
2017-06-15 10:56:44,864 - gpio.RPi_GPIO_GPIOManager - INFO - activeSetting
2017-06-15 10:56:44,866 - __main__ - INFO - Running....

timestamps are in utc, so log is from a few minutes ago.
What needs to change is the setup procedure. Found on my system when I repeatedly download the tar file, wget does not overwrite existing tar file but adds a number.
I also see that you run the code as 'root'. When you follow the download script as root, this might change the base directory.

Installation should be done by:
log in as pi user
Code: Select all
cd ~
wget -p http://heppg.de/ikg/administration/pi/scratchClient/download/scratchClient.tar.gz
tar xzf scratchClient.tar.gz
Posts: 1135
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
by kaszpirowski » Fri Jun 16, 2017 6:46 am
Hello,
I used the file which you loaded in the penultimate post and underdeveloped the error ... but there is a problem running the servo. When using a simple program in scretch, the volume changes in the console while the servo is standing in place ....
(info from the scratch client console)
2017-06-16 08:29:08,771 - __main__ - INFO - sensor-update: servo_A, 0
2017-06-16 08:29:08,799 - __main__ - INFO - sensor-update: servo_A, 50
2017-06-16 08:29:09,815 - __main__ - INFO - sensor-update: servo_A, 0
2017-06-16 08:29:09,836 - __main__ - INFO - sensor-update: servo_A, 50
2017-06-16 08:29:10,845 - __main__ - INFO - sensor-update: servo_A, 0
2017-06-16 08:29:10,866 - __main__ - INFO - sensor-update: servo_A, 50
2017-06-16 08:29:11,882 - __main__ - INFO - sensor-update: servo_A, 0
2017-06-16 08:29:11,904 - __main__ - INFO - sensor-update: servo_A, 50
2017-06-16 08:29:12,925 - __main__ - INFO - sensor-update: servo_A, 0
2017-06-16 08:29:12,946 - __main__ - INFO - sensor-update: servo_A, 50
2017-06-16 08:29:13,962 - __main__ - INFO - sensor-update: servo_A, 0
2017-06-16 08:29:13,986 - __main__ - INFO - sensor-update: servo_A, 50
2017-06-16 08:29:15,005 - __main__ - INFO - sensor-update: servo_A, 0
2017-06-16 08:29:15,026 - __main__ - INFO - sensor-update: servo_A, 50
2017-06-16 08:29:16,026 - __main__ - INFO - sensor-update: servo_A, 0
2017-06-16 08:29:16,049 - __main__ - INFO - sensor-update: servo_A, 50
2017-06-16 08:29:17,068 - __main__ - INFO - sensor-update: servo_A, 0
2017-06-16 08:29:17,091 - __main__ - INFO - sensor-update: servo_A, 50
2017-06-16 08:29:18,095 - __main__ - INFO - sensor-update: servo_A, 0
2017-06-16 08:29:18,122 - __main__ - INFO - sensor-update: servo_A, 50
2017-06-16 08:29:19,131 - __main__ - INFO - sensor-update: servo_A, 0
2017-06-16 08:29:19,152 - __main__ - INFO - sensor-update: servo_A, 50

I also noticed a message after restart scratchclient and scratch:

root@raspberrypi:/home/pi/scratchClient# python3 src/scratchClient.py -c config/config_gpio_servo.xml -v
2017-06-16 08:26:52,735 - root - INFO - create ScratchClient 2017-06-15
2017-06-16 08:26:52,737 - root - INFO - start scratch client 2017-06-15
2017-06-16 08:26:52,953 - gpio.RPi_GPIO_GPIOManager - INFO - GPIOManager setActive, True
2017-06-16 08:26:52,953 - gpio.RPi_GPIO_GPIOManager - INFO - 0.6.3
2017-06-16 08:26:52,956 - __main__ - INFO - event_connect
2017-06-16 08:26:52,956 - __main__ - INFO - Trying to connect to scratch.
2017-06-16 08:26:52,957 - __main__ - WARNING - There was an error connecting to Scratch!
2017-06-16 08:26:52,958 - __main__ - WARNING - Unterstuetzung fuer Netzwerksensoren einschalten!
2017-06-16 08:26:52,958 - __main__ - WARNING - Activate remote sensor connections!
2017-06-16 08:26:52,958 - __main__ - INFO - No Mesh session at host: 127.0.0.1, port: 42001
2017-06-16 08:27:13,011 - __main__ - INFO - Connected to Scratch !
2017-06-16 08:27:13,012 - adapter.gpio - INFO - Adapter, setActive servo_pwm True
2017-06-16 08:27:13,013 - gpio.RPi_GPIO_GPIOManager - INFO - activeSetting
/home/pi/scratchClient/src/gpio/RPi_GPIO_GPIOManager.py:111: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(gpio.getPort(), GPIO.OUT)
2017-06-16 08:27:13,016 - __main__ - INFO - Running....


And one more thing .... how to get ctrl + c restart (in the process i do not have a normal python process) and again scratch the client this servo is starting to work on the nweet no procedure in scratch is running (sscratch is running). Even though I change the position to another, the servo returns to position 0 ..... it stops after the scratch and scratch client is restarted ... .
Posts: 23
Joined: Fri May 12, 2017 10:47 pm
by ghp » Fri Jun 16, 2017 1:34 pm
Hello,
reason for not working was my test setup here for servo: I use a transistor to extend the pi output voltage to the servo voltage level which inverts the signal. So the signals have been low/high exchanged on pi output.

So it took some time to run some tests on the various servo driving scenario
- rpi.gpio pwm (jitter, but no external dependencies)
- RPIO2, a dma based driver based on RPIO.PWM, adjusted for pi2, pi3
- servoblaster (needs adjustments in servod.c in order to run on pi3)
And each one in python2, python3.

Download latest scratchClient again and run a test please.

The 'RuntimeWarning:' just indicates that the GPIO have been used earlier and not perfectly cleaned up. Not a problem.

Your last paragraph is difficult to understand. Usually scratchClient runs in a terminal window and is stopped by ctrl-c or sending a signal by using "kill" from another session.
Posts: 1135
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
by kaszpirowski » Fri Jun 16, 2017 4:44 pm
After downloading a new configuration is unchanged ... servwo not start ... in the python console shows the changes of the site, www also shows the change of location ...

As for the last paragraph it is that after removing the process responsible for the scratch client (htop does not find any process for python and gpio) and restarting the scratch client the servo starts to shake and is standing still. It even starts as if there was no running program in the scratch. I also noticed that closing the scratch causes a temporary servo start and a slight change in position
Posts: 23
Joined: Fri May 12, 2017 10:47 pm
by ghp » Fri Jun 16, 2017 8:26 pm
Hello,
in case scratchClient is connecting to scratch, but no script running there: the 'for all sprites' variables are sent out to scratchClient with their current values and as the servo adapter start the pwm signals when connected these values setting the servo.

When scratchClient is disconnected (either scratch stopped or connection closed) then the pwm generation is stopped. Then for a short time the servo will possibly see wrong signals, causing jitter. Driving servo is not precise science.

Difficult to assist when not having access to the system.
Perhaps one note: your delay times seem to be very fast:
2017-06-16 08:29:10,845 - __main__ - INFO - sensor-update: servo_A, 0
2017-06-16 08:29:10,866 - __main__ - INFO - sensor-update: servo_A, 50
2017-06-16 08:29:11,882 - __main__ - INFO - sensor-update: servo_A, 0
2017-06-16 08:29:11,904 - __main__ - INFO - sensor-update: servo_A, 50

From 50 -> 0, there is prox 1 sec, but from 0-->50 there is only prox 20 ms. Perhaps you add another delay there to give the servo time to run ?
Posts: 1135
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
by kaszpirowski » Fri Jun 16, 2017 8:54 pm
The command in scratch looks like this ...
http://fotozrzut.pl/8yl

screnn from console :
http://fotozrzut.pl/8y3

Still servo not run ....
Posts: 23
Joined: Fri May 12, 2017 10:47 pm
by ghp » Fri Jun 16, 2017 10:04 pm
To sum up, what is known:
- there have been some bugs in scratchClient, when you have loaded todays version this is corrected.
- when I run the code here (scratchClient + scratch) I get the pwm pulses as needed
- I connect the servo to GPIO23, which is pin 16 on the header.

You say that with python code the servo is working. Post this code here to see what the differences are.
Posts: 1135
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
by kaszpirowski » Sat Jun 17, 2017 7:53 am
Code that I once downloaded for testing purposes to see if the servo is working:

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)

GPIO.setup(16, GPIO.OUT)

p = GPIO.PWM(16, 50)

p.start(7.5)

try:
while True:
p.ChangeDutyCycle(7.5) # turn towards 90 degree
time.sleep(1) # sleep 1 second
p.ChangeDutyCycle(2.5) # turn towards 0 degree
time.sleep(1) # sleep 1 second
p.ChangeDutyCycle(12.5) # turn towards 180 degree
time.sleep(1) # sleep 1 second
except KeyboardInterrupt:
p.stop(1)
GPIO.cleanup(2)
Posts: 23
Joined: Fri May 12, 2017 10:47 pm
by ghp » Sun Jun 18, 2017 7:03 pm
Hello,
took the time to burn a fresh sd card, reinstall needed software and to run scratchClient. Worked as expected with the steps demonstrated.
A video is in http://heppg.de/ikg/wordpress/?p=1011 (no sound...)
Regards,
Gerhard
Posts: 1135
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
by kaszpirowski » Sun Jun 18, 2017 10:11 pm
It executes exactly like in the movie .... everything in the logs is ok (log and www) ... servo still does not start ,,, I stop everything and run the test script and it starts working
Posts: 23
Joined: Fri May 12, 2017 10:47 pm
by ghp » Mon Jun 19, 2017 4:30 am
Hello,
the configuration you use in scratchClient config_gpio_servo.xml uses basically the same rpi.gpio pwm commands as your python program.
I'd recommend to delete the ~/scratchClient folder from your sd card. Also delete files like scratchClient.tar.gz from ~/ folder. Then download from web site and unpack.
Posts: 1135
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
by kaszpirowski » Mon Jun 19, 2017 6:58 am
I managed to run :D .... but there were more problems .... :shock:
While scratchclient is running and scratch runs servically uncontrollably and executes operations that are not in the command ... even if no command is run ... these moves fail in the scratchclient log. I noticed that the range of moves is much smaller than in the python startup script ... it seems that the whole range is 90 degrees and the test script is 180 degrees ...
Posts: 23
Joined: Fri May 12, 2017 10:47 pm
by ghp » Mon Jun 19, 2017 5:27 pm
Hello,
these small moves are 'jitter', caused by not perfect timing in the python code. You notice this too in the video.
Current support for dma based adapters are by a RPIO2 library, config file is config_dma_servo.xml Look in the doc, as this needs an additional install step.
Or choose servoblaster, see config_servoblaster.xml. This needs external program 'servod' to run which you find on the net. Needs possibly some tweaks in the code to run on a PI3.

The range of movement is usually given by the timing of the pwm signal from 1 to 2 ms which is 5% to 10% duty cycle.
Your python sample code exceeds this range from 2.5% to 12.5%. Depends on the servo if this works. Look into the config file config_gpio_servo.xml and change the millisecond.max and millisecond.min parameter if needed. Extending range is not the primary reason to have these parameters, limiting range to limits in real live are also important. Think I have these two parameters for all my servo implementations available (except arduino as a slave board).
Posts: 1135
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany