Wednesday, December 14, 2011

Plot funny conditional stuff in gnuplot

plot "acc_len_acc_old_new11.txt" using 2:4:(+0):(-($4-$5)):((($2<=1)||($4<=1)||($4==$5))?(1/0):(($4 > $5) ? (rgb("0","255","0")): (rgb("255","0","0")))) notitle with vectors lc rgb variable,"acc_len_acc_old_new11.txt" using 2:5:(+0):(-($4-$5)):(($4!=$5)?(1/0):(($4 > $5) ? (rgb("0","255","255")):(rgb("255","0","255")))) notitle with vectors lc rgb variable, "acc_len_acc_old_new11.txt" using 2:(($4==$5 ? 5 : 1/0)) notitle with points pt 13 lc 13

Wednesday, December 7, 2011

PDFs to text to make them searchable on commandline

linse@elektrobier:~/Documents/cloned/diss/paper$ for f in *.pdf; do pdftotext $f; done

Sunday, November 13, 2011

NRG to ISO

Assuming the NRG is just a single session ISO CD image, you can just remove the first few kb with dd from Terminal.app
Code:

dd if=image.nrg of=cdrom.iso bs=512 skip=600

Friday, November 11, 2011

Game states

final int STATE_XBEE_INIT = 0;
final int STATE_PLAYER_LIST = 1;
final int STATE_LEVEL_SELECT = 2;
final int STATE_PLAY = 3;
final int STATE_HIGHSCORE = 4;

Lag test

else if (mode == 2) {
println("We can test the lag now.");
players[0].xpansProx[0].broadcastProxConfig(1500);
mode++;
}
else {// done
initLevel(players, "levels/03-nomoremosquitos.xml");
for (int s=4; s<8; s++) { // Send an arbitrary step to the patches
println("Sending step "+s+" at time "+millis());
for (int i=0; i players[i].sendStep(s);
delay(500);
}
}
}

Shut off buzzing by hand, for player 1

// shut off glove buzzer
players[0].xpansVibe[0].broadcastVibe(0);
// shut off patch buzzer
Step shutoff = new Step(false, false, false, false, false);
players[0].xpansProx[0].broadcastStep(0, shutoff, shutoff, shutoff, shutoff);

for player 2, just do it for players[1]

Tuesday, November 8, 2011

PANs

Player 1 PANs:

1001: two proximity sensors, one base -- bidirectional.
Node Identifier: P1_PROX1
base ID: 0
end device IDs: 1, 2

1002: two proximity sensors, one base -- bidirectional.
Node Identifier: P1_PROX2
base ID: 0
end device IDs: 3, 4

1003: two vibes, one base
Node Identifier: P1_VIBE
base ID: 0
end device IDs: 5, 6

1004: two accelerometers, one base -- incoming only.
Node Identifier: P1_ACCEL
base ID: 0
end device IDs: 7, 8

Player 2 PANs:

2001: two proximity sensors, one base -- bidirectional.
Node Identifier: P2_PROX1
base ID: 0
end device IDs: 9, 10

2002: two proximity sensors, one base -- bidirectional.
Node Identifier: P2_PROX2
base ID: 0
end device IDs: 11, 12

2003: two vibes, one base
Node Identifier: P2_VIBE
base ID: 0
end device IDs: 13, 14

2004: two accelerometers, one base -- incoming only.
Node Identifier: P2_ACCEL
base ID: 0
end device IDs: 15, 16

One bottleneck is the baud rate between the base Xbee and the computer. This should be cranked up to 115200. The baud rate between the arduinos and the endpoint Xbees can remain at 9600.

Data packets for xbees

Message/Packet types:
1: from base to proximity patches telling them it’s the beginning of a turn. [5 BYTES]
2: from prox. patches to base providing sensor readings. [6 BYTES]
3: from base to gloves telling them what intensity to vibrate. [2 BYTES]
4: from accelerometer anklets to base providing sensor readings. [5 BYTES]
5: Config. from base to proximity patches. [3 BYTES]
6: Ack. of configuration messages, send from prox. patches to base in response to config. [4 BYTES]
7: Messages from gloves to base, for button presses on gloves, UI control. [3 BYTES]

More Info about Packets

2fake: data simulation packet outgoing of patch:
“sent” approximately every 50 ms, with a small percentage of dropped packets:
time (ms)
player #: 0 or 1
patch #: 0-3
touched: 0-1
prox: 0-1028

4fake: data simulation packet outgoing of accelerometer:
set every 50 ms, with a small percentage of dropped packets:
player#
patch#
accel: 1-255

2real: real packet outgoing of patch
sent by patch arduino software
every 50 ms
highest prox reading of interval

7real: real packet outgoing of patch: button press

4real: real packet outgoing of accelerometer
sent by anklet arduino software
every 50 ms
highest accel. reading of interval

Packet structure
Packet structures, by byte:

Type #1: Base to Prox
0: Packet type
1: Step number (high order bits)
2: Step number (low order bits)
3: patches active this turn (4 bits) and patches active next turn (4 bits) - patch is active or not: 1 or 0
4: patches active two turns from now (4 bits) and patches active 3 turns from now (4 bits)

Type #2: Prox to Base
0: Message Type
1: Patch Address (7 bits, expect 1-4, 9-12) | touched (1 bit)
2: Step number (high order bits)
3: Step number (low order bits)
4: Proximity reading (high order bits)
5: Proximity reading (low order bits)

Type #3: Base to Gloves
0: Message Type
1: Vibe intensity (higher -> more vibration)

Type #4: Accel to Base
0: Message type
1: Patch Address (expect 7-8, 15-16)
2: X axis reading
3: Y axis reading
4: Z axis reading

Type #5: Config, base to prox
0: Message Type
1: Length of step (high order bits) - tells the patches how long each “step” will be during this level
2: Length of step (low order bits)

Type #7: Glove to Base
0: Message Type
1: Patch address (expect 5-6, 13-14)
2: Which button was touched

Button touch data is an int encoded thus:
0: no touch, or ambiguous touch that we shouldn’t react to
1: left button ONLY was touched
2: right button ONLY was touched
3: center button ONLY was touched
4: all three buttons were touched

Wednesday, September 28, 2011

Run X-CTU with MacOS X Lion

X-CTU is the Windows software that is required to update the firmware of the XBee radios. It is not compatible with neither Linux nor Mac, but it can be used with wine - the Windows emulator.

I used Wineskin which produces standalone Mac Software packages based on wine.
First of all, get the X-CTU program from digi.com, and get wineskin for Mac.

Follow the tutorial for software with a windows installer that comes with wineskin.
Just name your wrapper X-CTU and point to the X-CTU installer from digi.com in the steps where the tutorial uses Neverball.

After clicking the advanced tab of your new wrapper, in the tools section you click "Test run application" to test your X-CTU program that you just wrapped for Mac.
You will see immediately that it complains that it cannot connect to com ports - as there are no com ports on the Mac.

We have to map the USB ports to the com ports by hand:
The port mappings for your new wrapper live under Contents/Resources/dosdevices in the wrapper we just created and should have still opened in finder (at /Users/yourusername/Applications/Wineskin/X-CTU.app).
We now create softlinks from the mac USB ports to windows com ports. Plug in your device, open terminal and go to the dosdevices folder:
cd /Users/yourusername/Applications/Wineskin/X-CTU.app/Contents/Resources/dosdevices

Look up the device location of your plugged in device, it should be /dev/tty.usbserialXXXX for an XBee on a XBee explorer connected via USB. Here, XXXX is the device ID and is different for every device.
Choose a high number for the com port, as the lower ones may be already in use by wine. I have chosen 10.
ln -s /dev/tty.usbserialXXXX com10

Kill and test run your X-CTU wrapper application again, and the complaint about the missing com ports should be gone. Add your new com port now, so that X-CTU knows it:
In the bottom panel, go to the "User Com Ports" tab. At the right, put your com port number in the box (e.g. 10) and press the "Add" button.
It now appears in the top panel, and you should be able to test/query the XBee sucessfully.

Your very own selfmade Mac version of X-CTU and your XBee should now be able to play well together.

Caveat: The com port number is forgotten by X-CTU on shutdown. So you have to go to "User Com Ports"->"Add" every time you start up your X-CTU wrapper again.

Tuesday, September 27, 2011

Serial connection from Seeduino Film via XBees to Computer

With a program that talks to Serial from the seeduino film with baud rate 19200, and two xbees on explorer boards set to baud rate 9600 and two terminal emulators set to baud rate 9600, we can establish a serial connection from the seeduino film to the computer via the xbees.

One xbee is just on the explorer shield and connected to the computer via USB, a terminal emulator attached to it (powered via USB from the explorer).
The second xbee is wired to the seeduino film's breakout board (powered via USB) like this: 5v and ground are connected, and RXD on the seeduino breakout board is connected to DOUT on the xbee explorer, and TXD on the seeduino breakout board is connected to DIN on the XBee explorer shield.

Arduino Nano vs Seeduino Film

When compiling code for Arduino Nano, choose Arduino Duemilanove, when compiling for the Seeduino Film, choose Arduino Diecimila. So far, so good.

Uploading Arduino code that establishes a serial connection like this

void setup()
{
Serial.begin(9600);
}

void loop()
{
Serial.print("arduino greets");
delay(2000);
echo();
}

works fine on the Arduino Nano via USB to a serial terminal emulator (baud rate 9600) on the computer.

With seeduino film and the UartSBFrame programming adapter via USB to a serial terminal emulator, however, the terminal receives only garbage from the seeduino film.

Remedy: Set the baud rate to 4800.
Why??

If changing the baud rate to the next higher one, to be 19200 in the arduino code, one can then connect the terminal emulator with 9600. It seems to be always off by one - is this a known bug?

Wednesday, September 14, 2011

Old subversion link

https://www.assembla.com/code/tag/subversion/nodes?rev=24

Load arduino wirelessly via xbees

http://www.ladyada.net/make/xbee/arduino.html
RTS and DI03 are connected in the explorer board - to transmit the RTS signal wirelessly via the DI03 pin. The xbees have to be configured to transmit the DI03 signal.

Serial connection between two XBEEs

- plug in two xbees with USB explorer boards

- connect to the xbees via serial terminal emulator
screen /dev/tty.usbserial-A8004xAX 9600
screen /dev/tty.usbserial-A8004YWG 9600

- access xbee configuration via AT commands:
+++ -> should return OK, makes the xbee listen to commands
AT -> should return OK, now we are really sure that the xbee understands commands
ATID -> PAN id, 3332 per default, (xbees send/recieve within same PAN id)
ATBD -> baud rate for wireless transfer, 3 per default, number codes mean:
0 = 1200
1 = 2400
2 = 4800
3 = 9600
4 = 19200
5 = 38400
6 = 57600
7 = 115200

-> AT (check if xbee modem is responding)
<- OK -> ATBD (get current baud rate as above)
<- 3 (9600) -> ATBD 4 (set baud rate to 19200)
<- OK -> ATBD (check again)
<- 4 -> ATWR (write the baud rate change to flash)
<- OK





http://www.ladyada.net/make/xbee/ref.html

Screen as a serial terminal emulator in MacOS X

screen /dev/tty.usbserial-XXXXXXXXX 9600

More comfortable: Apple script

tell application "Terminal"
do script with command "screen /dev/tty.KeySerial1"
set number of rows of window 1 to 100
set number of columns of window 1 to 80
set background color of window 1 to "black"
set normal text color of window 1 to "green"
set custom title of window 1 to "SerialOut"
end tell

Control-A followed by Control-\ to exit your screen

Thursday, July 14, 2011

Print TiKz figures from matlab

Go to

http://win.ua.ac.be/~nschloe/content/matlab2tikz

download the zipfile, place .m-scripts in matlab working directory.
Print to TiKz figure from matlab with

matlab2tikz( 'myfile.tikz' );

correct the plot labels (escape %, remove or add $ for math mode), embed into
LaTeX file by

\newlength\fheight \newlength\fwidth \setlength\fheight{4cm} \setlength\fwidth{6cm} \input{myfile.tikz}

Wednesday, July 13, 2011

Print last rows of some result files

tail -n 1 -q ../../data/bralibase/unaligned/*/*.res

Loop over multiple files

Loop over multiple input files and do something, beep when done.
 
for i in `ls ../../data/bralibase/unaligned/*/*.fa`; do perl planACstar.pl -p=9 -q=9 $i >> $i.res; done; beep

Friday, July 8, 2011

Wednesday, June 15, 2011

Split PDF into single pages

pdftk p_node_edit_operations.pdf burst output p_node_edit_operations_%02d.pdf

Monday, June 6, 2011

Colour a vector depending on a condition in gnuplot

plot "data.txt" using 1:2:(+0):(-($2-$3)):(($2 > $3) ? (rgb("0","255","0")):(rgb("255","0","0"))) notitle with vectors lc rgb variable

plot arrows between values in gnuplot

plot "data.txt" using 1:2 title "orig" lt 2 pt 2, \
 "data.txt" using 1:3 title "step 1 1" lt 1 pt 3, \
 "data.txt" using 1:2:(+0):(-($2-$3)) notitle with vectors arrowstyle 1

Friday, June 3, 2011

Crop a PDF with Latex

\documentclass{article}
\usepackage{graphicx}
\usepackage[active,tightpage]{preview}
\PreviewMacro[{*[][]{}}]{\includegraphics}
\begin{document}
\pagestyle {empty}

\includegraphics[viewport=0 270 420 570]{NawrockiFig-crop.pdf}

\end{document}

Tuesday, May 31, 2011

Find empty results of a cluster job

 find dir/ -type f -size 0 -name *.o*

Sunday, May 22, 2011

was macht eigentlich der cluster fuer mich?

qstat|grep  "username     r"|wc -l

Thursday, May 19, 2011

Transparent Points using Gnuplot and Tikz terminal

Insert this in your tikz drawing generated by gnuplot:

\tikzstyle{every path} = [opacity=.5]
\tikzstyle{every node} = [opacity=1]

Saturday, May 7, 2011

Draw nice RNA 2d structures in PGF/TikZ

Vienna package - RNAplot:
RNAplot -o svg

change colours in inkscape if desired

transform inkscape svg to pgf/tikz code:
inkscape2tikz -o output.tex input.svg

change tikz code, e.g. add
\tikzstyle{every node} = [fill=white]
for better readability, and delete
line width = XXX
for standard line width

Remove background rectangle
 \path[draw=white,fill=white,rounded corners=0.0000cm] (0.0000,0.0000) rectangle  (452.0000,452.0000);

Tuesday, April 19, 2011

Delete empty lines from file

perl -pi -e 's/^\n$//' file.txt

Friday, April 15, 2011

AG PI BibTeX key scheme for JabRef

Key pattern -> default pattern
[auth3_1:upper:]:[auth3_2:upper:]:[auth3_3:upper:]:[auth3_4:upper:]:[auth3_5:upper:]:[auth3_6:upper:]:[auth3_7:upper:]:[auth3_8:upper:]:[auth3_9:upper:]:[auth3_10:upper:]:[year]

Regular Expression
replace 
:+
with
:

Wednesday, April 13, 2011

Cross out terms or text in LaTeX

Required package: cancel
\usepackage{cancel}

You can make the following
with the following LaTeX source code:
\[ a + b + \cancel{c} = \cancel{c} + d + e \]

You can also zero out a term in an equation looking like
with the following LaTeX source code:
\[ a + b + \cancelto{0}{c} = d + e \]

Monday, April 11, 2011

Find out whether sparc machine is 32 or 64 bit

If you want to find out if your machine is 32 or 64 bit, simply type in the following:

isainfo -v

Finding out about the type of machine (sparc vs x86) is

uname -a

Monday, April 4, 2011

Check whether binary was compiled for 64 bit

linse@zebrano ~/release/RNAforester-1.5 $ file /vol/rnaforester2/bin/RNAforester
/vol/rnaforester2/bin/RNAforester: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), not stripped, uses CMOV SSE SSE2

Wednesday, March 23, 2011

Redirect only stderr to file

./4a_eval_affine.pl 4a_structure_test_sets/ 1 2> 4_result/4a_vienna_for_file_1.txt

Friday, March 18, 2011

Thursday, March 10, 2011

Open and jump to line in vi

$ vi +99 some-file

The above opens some-file and go immediately to line 99.

Thursday, January 27, 2011

Perl: replace string over multiple files

perl -pi -w -e 's/search/replace/g;' *.cpp

Tuesday, January 25, 2011

Profiling C++

Use gprof:
Add -pg to compiler and linker flags and rebuild.
Call the program to collect profiling info.
Call the program with gprof yourprogram to see profiling info.

Use valgrind with the following options
valgrind --tool=callgrind ./(Your binary)
It will generate a file called callgrind.out.x. You can then use kcachegrind tool to read this file. It will give you a graphical analysis of things with results like which lines cost how much.

Thursday, January 20, 2011

Latex: Cropped PDFs from TikZ

Using the preview package. The package provides several ways of previewing parts of your document. For example, adding this to your document preamble:
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
will extract every tikzpicture environment. If you use pdflatex, every tikzpicture will be put on a separate page in the resulting pdf document. See the documentation for more details. To add a margin around the figure add:

Thursday, January 13, 2011

Doxygen code documentation tool

doxygen -g <config-file>
install doxygen-gui
doxywizard 

C++ code beautifier

linse@elektrobier:~/Documents/cloned/RNAforester2_refac_tmp$ astyle  --style=java --recursive  src/*.cpp  src/*.h
linse@elektrobier:~/Documents/cloned/RNAforester2_refac_tmp$ astyle  --style=java --recursive  src/*/*.cpp  src/*/*.h