środa, 14 grudnia 2011

Turn off kde screen dimming

Even if you mess around with power manager policies, kde will turn off the screen if mouse was'nt moved nor key wasn't pressed. Apparently this little script prevents kde from turning screen off.



#!/bin/bash

for (( ; ; ))
do
dbus-send --print-reply --type=method_call --dest=org.freedesktop.ScreenSaver /ScreenSaver org.freedesktop.ScreenSaver.SimulateUserActivity
sleep 60
done

niedziela, 20 listopada 2011

Arduino Sonar Grid

Because of the small project that I did recently I had to build sonar grid on Arduino. The circuit was gathering data from five ultrasonic sensors LV MaxSonar EZ0 and was sending readings to computer via Firmata. I turns out that each sonar will interfere with every other so the signal you will get can be very noisy (depending it on sonar mutual locations and room layout). Something you can do (with this particular sonar) is to turn-off all others sonar in the time of reading data. So if you read data for sonar connected to pin 0 others should not send the ultrasonic wave.

Here goes modified minimal Firmata implementation to achieve this.


#include <Firmata.h>

int analogPin = 0; // counter for reading analog pins
int digitalPin = 0; //conuter for turning on/off digital pins (RX for sensors)
unsigned long currentMillis; // store the current value from millis()
unsigned long previousMillis; // for comparison with currentMillis

void setup()
{
Firmata.setFirmwareVersion(0, 2);

for (digitalPin=2;digitalPin<=7;digitalPin++){
pinMode(digitalPin, OUTPUT);
}
Firmata.begin(57600);
}

void loop()
{
while(Firmata.available())
Firmata.processInput();

currentMillis = millis();
if(currentMillis - previousMillis > 20) {
previousMillis += 20; // run this every 20ms

for(analogPin=0;analogPin<TOTAL_ANALOG_PINS;analogPin++) {
for (digitalPin=2;digitalPin<=7;digitalPin++){
if (digitalPin - 2 == analogPin) {
digitalWrite(digitalPin, HIGH);
}
else {
digitalWrite(digitalPin, LOW);
}
}
delay(40); //wait wait man!
Firmata.sendAnalog(analogPin, analogRead(analogPin));
}
}
}


Analog output (AN pin) from all sonar are connected to A0-A5 pins on Arduino (since we are reading from analog). RX pin (which controls measuring state of sonar) are connected to digital pins 2-5. As you probably see this will get way much lower signal resolution that we can get from one sonar. MaxSonar works in 49ms cycles and sends 42Hz waves at the begining of each cyle only if RX pin is HIGH or unconnected. After changing digital pins state you need to wait a while to seetle state on it and also you need to wait for the sonar to its cycle begining (40ms delay gives very smooth signal).

Of course this is easiest possible solution. Depeding on your need you can read from sonars in pairs on weave reading with differents operations.

wtorek, 17 maja 2011

VLC + p2p real time audio/video streaming

Recently I was coordinating this art event. My responsibility was to setup real-time a/v streams in five cities. Every city was streaming a/v from hd camera and also realy big projector was showing streams from other cities. We decided to go for p2p architecture and use some additional player which can randomly switch streams.

We decided to use VLC ...and first bummer: Vlc dosen't support grabbing video from firewire (or I wasn't able to find this option in UI). We are sure we don't want to put ieee 1394 as v4l device, because only way to do that is by vloopback - and this module... well it isn't quite stable.

This line was used to setup stream with transcoding it by h264.

dvgrab - -noavc -nostop | cvlc - -vvv --no-sub-autodetect-file :demux=rawdv
--sout'#transcode{vcodec=h264,vb=600,acodec=mp3,ab=56,scale=0,width=720,height=576,channels=2}:
duplicate{dst=std{access=http,mux=ts,dst=0.0.0.0:8085}}'

also stream tittle is a neat feature:

#transcode{vcodec=h264,vb=1500,scale=1,width=1024,height=576,
sfilter='marq{marquee=Toruń %Y/%m/%d%H:%M%S,position=10,size=14}',
acodec=mp3,ab=196,channels=2,samplerate=44100}:http{mux=ts,dst=:8081/}

stream merging was achieved by

cvlc url1:port url2:port ... --sout="#gather:http{mux=ts,dst=localhost:8079/}" --sout-keep


this will loopback merged stream to localhost on 8079, just open it in any player and switch streams by vlc ui. Depending on option http-cache (buffer size) switching will be little bit delayed (but this is what we wanted to achieve here). Also notice that --sout-keep will only work if stream config is identicall, so you have two option: transocde it on the client or make same setup on server.

Look also here: auto-reconnect, and someone advised me to take a look on twisted-based streaming software

niedziela, 24 kwietnia 2011

Augumented Reality Model Editor



Augemented Reality Model Editor.

Ogre3d + ARToolkitPlus + little bit of OpenCV

code available on github