Tuesday, December 31, 2013

Starting to work at GII

That's it. I've finished my  2 years Post-Doc adventure at TAU.
I'm now starting to work on the Israel national Earthquake Early Warning System (EEWS).
As of tomorrow, I'm going to work at the Seismology Division of the Geophysical Institute of Israel (GII).

Tuesday, November 26, 2013

Real-Time Kernel for RaspberryPi (Take II)

After unsuccessful attempt to compile Archlinux-rt kernel,
I encountered a very good guide describing how to compile a Debian Linux-rt kernel with Xenomai for the RaspberryPi. and a completing page for creating the RPI image.
I can't say I understand it completely, but I managed to combine to two guides and compile my own RaspberryPi Linux-rt kernel.

I'm sure some of the steps are missing and things change very quickly (e.g. links, kernel versions and patches) so anyone following my steps should take that into consideration and adapt to changes.

I started by installing a fresh Debian 32bit x86 on a virtual box.
Follow the picnc guides but remember to adapt the patches and kernel version differences.

I'll try to redo the process and give here a complete guide at a later stage.

Thursday, August 29, 2013

EQMet TSA-SMA setup for SeisComp3

The following post will describe how to install EQMet INTERNET-READY STRONG MOTION ACCELEROGRAPH (TSA-SMA) and set it up for SeisComp3.


Following the instruction in the manual:
The initial steps are to connect the TSA-SMA to electricity, GPS and a computer via the USB device connection.
Then, connect to the device via serial connection.
On windows: read the manual and follow the orders using putty. Don’t forget to download the driver for the device from EQMet site (http://www.eqmet.com/eng/Linux-cdc-acm.zip)

On Linux:
install cu:
# sudo yum install uucp
get the tty of the connection:
# dmesg | grep 'tty'
on my system it was: ttyACM0 but it can be ttyS[1234] or serial.
next I connect to the device:
# cu -l /dev/ttyACM0 -s 115200
it takes a while to prompt for user and password (root,kmi) press enter if does not prompt.
I need to assign an IP based on the mac address so I check the mac:
# ifconfig
after I got the IP, it is easy to connect via http sftp and ssh.

for static IP, edit /etc/network/interfaces:
replace:
iface eth0 inet dhcp
with:
iface eth0 inet static
address <IP>
netmask <MASK>
gateway <GATEWAY>
dns-nameservers <DNS-SERVER>

connect to the device via http.
Next go to Parameters:hardware menu option.
update to your preferable network-station-location-channel ID in:
- Network ID
- Unit ID and Site ID
- dig1 ChX ID
- dig1 ChX Location code
where X in channel 1, 2 or 3.

press OK.

Next, following the response mail I got for EQmet support regarding seedlink connection:
Sir,

The limited version of Rockhound in the TSA-SMA does not support continuous recording. However, you can approximate continuous recording by adding the SEEDLink mirror module and configuring it to accept data from the RockToSlink module at address 127.0.0.1, port 18000 (or as configured). You should add this module after installing and adding in the RockToSlink module.

This module writes the received MiniSEED packets out to storage and breaks the files at approximately the specified duration (depending on MiniSEED packet contents). If you add this module, you should also consider adding an auto file delete module to avoid filling the storage. A file sender module may also be useful (SSH, FTP, or email).

The RockToSlink module for Rockhound is provided by ISTI, New York. The module and documentation is available from ISTI at http://www.isti2.com/RockToSLink/

Technical support for RockToSLink is available from ISTI at isti-info@isti.com. SEEDlink is a public domain program and protocols. Support for these programs including detailed protocol descriptions or installation and setup of the programs is not provided by Kinemetrics.

Regards,
EQMet, Technical Support
support@eqmet.com
installe the RockToSlink module and add it to the workflow:

1. Download the rocktoslik module from http://www.isti2.com/RockToSLink/dist_pub/:
> wget -v http://www.isti2.com/RockToSLink/dist_pub/RockToSLink_v1.0_dist.zip
2. Unzip it:
> unzip RockToSLink_v1.0_dist.zip
following the instractions in http://www.isti2.com/RockToSLink/current_dist/docs/RockToSLink_ovr.html:
3. sftp to the device:
> sftp root@<IP>
4. Change directory to module location:
> cd  /usr/rock/SMARTSDist/injar
5 Upload the module-update jar file:
> put RockToSLink_update.jar
6. connect via ssh:
> ssh root@<IP>
7. Change directory to module location:
> cd  /usr/rock/SMARTSDist/injar
8. Rename "RockToSLink_update.jar" to "update.jar"
> mv RockToSLink_update.jar update.jar
9. Reboot the instrument:
> reboot
Now add the RockToLink module to device layout:
10. In the device http menue Parameters: Advanced features, add options for Add/Remove Modules, Replace Modules and Advanced Modules.
11. In Module Add, add the RockToLink module.
12. Press apply changes now.

Now go to system operation and make sure all settings are correct.

enjoy.


Thursday, August 1, 2013

Machinoid Real-Time Linux for RaspberryPi

Download and install Machinoid following: http://www.machinoid.com/?p=10
apt-get install libtool gfortran
apt-get install libusb-1.0
install xenomai following the instructions in the link above.
sysctl vm.min_free_kbytes=8192
vi /etc/ld.so.conf.d/xenomai.conf
add 2 lines:
  # xenomai default configuration
  /usr/xenomai/lib
ldconfig
install wifi drivers (after I got problems with rt2800usb driver):
apt-get install firmware-ralink

create new file /etc/modprobe.d/8192cu.conf
add:
# Disable power saving
options 8192cu rtw_power_mgnt=0 rtw_enusbss=1 rtw_ips_mode=1

in /etc/dhcp/dhcp.conf
uncomment the timeout line and edit:
timeout 100;


Sunday, July 7, 2013

LSM303 accelerometer on RaspberryPi

After getting my new LSM303 accelerometer, I got my great electronics tec. Daviv Shtibelman to wire it up for RPI.
Connecting LSM303 pins 1 (SCL), 2 (SDA), 6 (GND) and 8 (V3V) to pins 5 (SCL), 3 (SDA), 6 (GND) and 1 (V3V) on the Pi board.
On my ArchlinuxARM OS I had to install i2c-tools:
> pacman -S i2c-tools
And add i2c modules:
> echo i2c-dev > /etc/modules-load.d/ i2c.conf
> echo i2c-bcm2708 >> /etc/modules-load.d/ i2c.conf
> reboot

now to check it works:
> i2cdetect -y 1
got a message like this:
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- 19 -- -- -- -- 1e --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

Now, following this, I test it and it works. Now I'm up for creating my own code.

Made some changes to the code:

main.cpp
#include"LSM303DLHC.h"
#include<stdio.h>
#include <unistd.h>


/*
   getHeading() calculates a tilt-compensated heading.
   A float between 0 and 360 degrees is returned. You need
   to pass this function both a magneto and acceleration array.
 
   Headings are calculated as specified in AN3192:
   http://www.sparkfun.com/datasheets/Sensors/Magneto/Tilt%20Compensated%20Compass.pdf
 
*/

float getHeading(LSM303& lsm303dlhc);

#define PI 3.141592654


int main(void)
{
    uint8_t bajt;
    const char *fileN = "/dev/i2c-1";
    LSM303 lsm303dlhc(fileN);

    lsm303dlhc.enalbe();

    while(1)
    {
        lsm303dlhc.readAccelerationRaw();
        lsm303dlhc.readMagnetometerRaw();
        printf("acc [m/s^2]: \e[27;1;31m %f \e[m \e[27;1;32m %f \e[m \e[27;1;34m %f \e[m mag:  \e[27;1;31m %d \e[m  \e[27;1;32m %d \e[m \e[27;1;34m %d\e[m %fdeg\n",
               (int16_t)lsm303dlhc.acc_x_raw*0.00957,(int16_t)lsm303dlhc.acc_y_raw*0.00957,-(int16_t)lsm303dlhc.acc_z_raw*0.00957,
               (int16_t)lsm303dlhc.mag_x_raw, (int16_t)lsm303dlhc.mag_y_raw, (int16_t)lsm303dlhc.mag_z_raw,getHeading(lsm303dlhc));
        usleep(10);
       }

    }


float getHeading(LSM303& lsm303dlhc)
{
  float heading,pitch,roll,xh,yh,zh;
  // see section 1.2 in app note AN3192
  int magValue[3];
  float accelValue[3];
  magValue[0] = (int16_t)lsm303dlhc.mag_x_raw;
  magValue[1] = (int16_t)lsm303dlhc.mag_y_raw;
  magValue[2] = (int16_t)lsm303dlhc.mag_z_raw;
  accelValue[0] = (int16_t)lsm303dlhc.acc_x_raw*0.000976531;
  accelValue[1] = (int16_t)lsm303dlhc.acc_y_raw*0.000976531;
  accelValue[2] = -(int16_t)lsm303dlhc.acc_z_raw*0.000976531;

    // see appendix A in app note AN3192
  pitch = asin(-accelValue[0]);
  roll = asin(accelValue[1]/cos(pitch));

  xh = magValue[0] * cos(pitch) + magValue[2] * sin(pitch);
  yh = magValue[0] * sin(roll) * sin(pitch) + magValue[1] * cos(roll) - magValue[2] * sin(roll) * cos(pitch);
  zh = -magValue[0] * cos(roll) * sin(pitch) + magValue[1] * sin(roll) + magValue[2] * cos(roll) * cos(pitch);

  heading = 180*atan2(yh,xh)/PI;

  if (heading <0)
    heading += 360;

  return heading;
}

LSM303DLHC.cpp:
#include"LSM303DLHC.h"
#include<math.h>
#include<stdio.h>

/*Conection to Raspberry PI:
 LSM303     Raspberry PI
 VDD    ->  3V3(PIN 1)
 SDA    ->  SDA(PIN 3)
 SCL    ->  SCL(PIN 5)
 GND    ->  GND(PIN 6)
*/

#define LSM303DLHC_MAG_ADDRESS            (0x3C >> 1)
#define LSM303DLHC_ACC_ADDRESS            (0x32 >> 1)

LSM303::LSM303(const char * i2cDeviceName) : i2c_lsm303(i2cDeviceName)
{

}

uint8_t LSM303::readAccRegister(uint8_t regAddr)
{
    i2c_lsm303.addrSet(LSM303DLHC_ACC_ADDRESS);
    return i2c_lsm303.readByte(regAddr);
}

uint8_t LSM303::readMagRegister(uint8_t regAddr)
{
    i2c_lsm303.addrSet(LSM303DLHC_MAG_ADDRESS);
    return i2c_lsm303.readByte(regAddr);
}

void LSM303::writeAccRegister(uint8_t regAddr,uint8_t byte)
{
    i2c_lsm303.addrSet(LSM303DLHC_ACC_ADDRESS);
    i2c_lsm303.writeByte(regAddr, byte);

}

void LSM303::writeMagRegister(uint8_t regAddr, uint8_t byte)
{
    i2c_lsm303.addrSet(LSM303DLHC_MAG_ADDRESS);
    i2c_lsm303.writeByte(regAddr, byte);

}

void LSM303::enalbe(void)
{
   writeAccRegister(LSM303_CTRL_REG1, 0b10010111);
   writeAccRegister(LSM303_CTRL_REG4, 0b00001000);

   writeMagRegister(LSM303_MR_REG, 0x00);
}

void LSM303::readAccelerationRaw(void)
{
    uint8_t block[6];

    i2c_lsm303.addrSet(LSM303DLHC_ACC_ADDRESS);

    i2c_lsm303.readBlock(0x80 | LSM303_OUT_X_L_A, sizeof(block), block);
    acc_x_raw = (int16_t)(block[0] | (block[1] << 8)) >> 4;
    acc_y_raw = (int16_t)(block[2] | block[3] << 8) >> 4;
    acc_z_raw = (int16_t)(block[4] | block[5] << 8) >> 4;

}

void LSM303::readMagnetometerRaw(void)
{
    uint8_t block[6];

    i2c_lsm303.addrSet(LSM303DLHC_MAG_ADDRESS);
    i2c_lsm303.readBlock(0x80 | LSM303_OUT_X_H_M, sizeof(block), block);

    mag_x_raw = (int16_t)(block[1] | block[0] << 8);
    mag_y_raw = (int16_t)(block[5] | block[4] << 8);
    mag_z_raw = (int16_t)(block[3] | block[2] << 8);

}

void LSM303::readAcceleration(void)
{
    readAccelerationRaw();
}

Sunday, June 30, 2013

Real-Time Kernel for RaspberryPi

After installing and running ArchLinuxARM on my RaspberryPi, I tried to compile a real-time kernel.
With the help of moonman, following this ArchLinuxARM forum thread, I downloaded the RT patch:
https://www.kernel.org/pub/linux/kernel/projects/rt/3.6/patch-3.6.11.4-rt36.patch.gz
and the PKGBUILD:
# git clone https://github.com/archlinuxarm/PKGBUILDs.git
following this, I updated pacman:
# pacman -Syy
and installed some packages:
# pacman -S kernel26-headers file base-devel abs
next
# cd PKGBUILDs/core/linux-raspberrypi
and edit the PKGBUILD file to include the patch in the source array:

source=('config'
        'change-default-console-loglevel.patch'
        'usb-add-reset-resume-quirk-for-several-webcams.patch'
        'args-uncompressed.txt'
        'boot-uncompressed.txt'
        'imagetool-uncompressed.py'
        'https://raspy-juice.googlecode.com/svn/trunk/linux-rtc/0001-rtc-pcf8523.patch'
        'https://raspy-juice.googlecode.com/svn/trunk/linux-rtc/0002-pcf8523-i2c-register-dt.patch'
        'patch-3.6.11.4-rt36.patch')

add a patch line:
patch -Np1 -i "${srcdir}/patch-3.6.11.4-rt36.patch"

and add md5sums at the end of the PKGBUILD file. to get the correct number run:
# md5sum patch-3.6.11.4-rt36.patch

next for the build:
# makepkg --asroot -Acs

The process has failed with some rejections of patches. So we need to manually apply the patches:
first look for rejections:
# find . -name "*.rej"
then edit the file and the .rej file:
# vim XXX.c XXX.c.rej
replacing XXX with the file path and name.
Then use :split to split the screen :next to change one screen to .rej file and ctrl+ww to switch between files.
add the lines marked by + and remove lines marked by - (lines with no +- sign are used for orientation.

after manually patching all files, edit the PKGBUILD file to ignore the kernel git and the patches (adding # at the start of the line)
add a line to src/linux/security/apparmor/sid.c:
"#include <linux/cache.h>"

re-run:
# makepkg --asroot

Now for the installation part:
# pacman -U linux-headers-raspberrypi-3.6.11-11-armv6h.pkg.tar.xz linux-raspberrypi-3.6.11-11-armv6h.pkg.tar.xz

And reboot.

Well, it didn't work.

Saturday, June 1, 2013

RaspberryPi initial steps

I initiated a new project involving low-cost micro-computer RaspberryPi.
In order to begin I ordered some basic parts (costs are in USD for Israeli market, should be cheaper elsewhere):
a RaspberryPi (55$)
5v charger with microusb adapter (10$)
8GB SD card (12$)
HDMI cable (8$)

and some extra parts:
3.5" LCD screen (45$)
micro-keyboard (62$)
micro-sd low profile adapter (11.9$)
wifi dongle (18.6$)

Not so cheap but might be worth it.

after I got a couple of RaspberryPi (model B rev2 512MB RAM) devices for a project I'm working on (details about the project will come later if it will work).
I bought a SD 8GB card and hooked it to the my desktop computer.
I downloaded the ARCLinux image unzipped it and followed the instructions:
Replacing sdX with the location of the SD card, run:
dd bs=1M if=/path/to/archlinux-hf-2013-06-15.img of=/dev/sdX
In order to increase the SD space to it's full 8GB I used gparted.

upgrade system:
> pacman -Sy pacman
> pacman-key --init
> pacman -Syu
sync (3 times):
# sync
reboot:
# reboot
Now I can add packages using pacman. to look for a package use:
> pacman -Ss <package name>
then select the one you need and install by:
> pacman -S <package name>

I am currently testing the Pi with the screen and 8 AA batteries to see how long it can work. I plan to build a case with a built-in 3.5" screen and a miniature keyboard so I can have a control unit for other RaspberryPi devices. My initial thoughts of using an old Gamboy case are now switched (with the encouragement of my electronic tec. guy David Shtibelman) to build a costume made case. Of course, David is the one to build it, since I have no skills to do that.



Wednesday, January 16, 2013

Fedora 17 Linux packges

These are MY needed packages, feel free to follow my steps or ignore this.
1. Add rpmfusion to yum repo list:
 > sudo yum localinstall --nogpgcheck http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm
2.
sudo yum install -y yumex tcsh gmt ImageMagick ipython scipy scitools spyder gthumb nautilus-open-terminal bluecurve-icon-theme gnome-applets gnome-themes bluecurve-gnome-theme filezilla gimp swig lshw lshw-gui gnome-tweak-tool libreoffice gv gcc gcc-gfortran gcc-c++ dconf-editor tigervnc-server
install chrome from google
install virtualbox from oracle site.
copy panels:
on old machine: dconf dump /org/gnome/gnome-panel/ > panels
on new machine: dconf load /org/gnome/gnome-panel/ < panels
change with dconf-editor:
/org/gnome/desktop/interface/icon-theme to Bluecurve
/org/gnome/desktop/wm/preferences/theme Clearlooks
/org/gnome/desktop/background/show-desktop-icons True
change user shell to tcsh: sudo usermod -s /bin/tcsh USERNAME
install microsoft fonts:
wget http://www.my-guides.net/en/images/stories/fedora12/msttcore-fonts-2.0-3.noarch.rpm
sudo rpm -ivh msttcore-fonts-2.0-3.noarch.rpm

6.Install obspy as root:
sudo easy_install -N obspy.core obspy.mseed obspy.sac obspy.gse2 obspy.imaging obspy.signal obspy.arclink obspy.datamark obspy.db obspy.earthworm obspy.fissures obspy.iris obspy.neries obspy.realtime obspy.segy obspy.seg2 obspy.seisan obspy.seishub obspy.sh obspy.taup obspy.wav obspy.xseed

Tuesday, January 1, 2013

Done with the PhD., Moving forward

Finally, I finished my PhD. and now it time to move forward.
Taking my Professors advice, I'm making the first steps in the world of seismology and I'm going to spend the next few years in Tel-Aviv University, working with Dr. Alon Ziv and Dr. Hillel Wust-Bloch.
The main work is building and maintain a local mini seismic-array network. I am going to actually place the seismometers, connect the dataloggers and build the server to collect the data. We are going to use different devices - Lennartz LE-3Dlite1DV MkII seismometers, Trillium broadband seismometers, TSA-SMA accelerometers and Summit M Hydra dataloggers. On the server side, We are going to use Seiscomp3 as our main framework, but we probably research for new algorithms and Seiscomp3 modules to better suit it to our needs.
Me getting the PhD. diploma from Prof. Rivka Carmi, presedent of BGU