VonHippel(python)

From BUG Wiki

Jump to: navigation, search

Contents

Brief

Communication with the VonHippel module is currently being done using the standard bmi_vh_control kernel module that the java system also uses. With the current kernel and rootfs, this means that you will need to quit all running java processes before trying to open the device. However, once that is done, the VonHippel python class can be used to open the bmi_vh_control device for the given slot, and can control many aspects of the VH module. See below for what features are working and not working.

Files

  1. ioctl_wrapper.py - a python wrapper for ioctl() calls that replicates the _IOR(), _IOW() and _IO().
  2. bmi_vh_driver.py - a python "driver" for the VonHippel module. This merely provides python method access to the ioctl calls in bmi_vh.h.
  3. VonHippel.py - the VonHippel python class - an easy to use python class which does a bunch of convenient parsing and tracking of status.

Installation

In a nutshell, all you need to be able to do is copy the .py files over to the bug, open up a shell, and launch python.

  1. First make sure you have a network connection to the bug, either via ethernet or the USB network driver. See the bug start page. You will not need eclipse or dragonfly.
  2. Next you will need to copy the VonHippel_python.tar.gz archive onto the bug. This can be done by using a cardreader and writing to the MicroSD card, or the vastly easier technique of using SCP. On windows, you can use WinSCP to log into the bug (address 10.10.10.10, user root, password blank). On Mac or linux, simply use the SCP command -
scp ./VonHippel_python.tar.gz root@10.10.10.10:/home/root 

in a terminal and hit enter twice. You should put the file in an appropriate location for working with the code. I just use /home/root.

  1. Next, connect to the bug using SSH. On windows, you can use putty(windows). On mac and linux, simply type
ssh root@10.10.10.10 

into a console, and hit enter at the password prompt. Navigate over to the location where you transferred the archive, and type

tar zxvf ./VonHippel_python.tar.gz to unzip it.
  1. Finally, simply type
python 

to launch the python interpreter, and type

from VonHippel import * 

to load the module. See the examples section for how to use it!

Usage

To create a new VonHippel module, you need to initialize it with a path to the VonHippel module driver you want to use. For example: v = VonHippel('/dev/bmi_vh_control_m1') The above will create a new VonHippel object inserted into slot 1. If the command returns The device does not exist! Please try again. then you have the wrong device name. Close python by pressing 'control-D' and type 'ls -l /dev | grep bmi' to see a list of all modules in the system.

If the module still refuses to open after several attempts, try killing all instances of java on the system. you can find these instances by typing ps ax|grep java into the bash shell, and then typing kill XXXX where XXXX is the PID number on the left side of the screen.

To check if the module is working, try typing this into python: v.toggle_iox(3) This should turn on the bright blue LED on the module. Type it again to turn it off.

You are now able to use the variety of methods in VonHippel.py to control the VonHippel module. Read through VonHippel.py to discover what methods are available and how to use them.

What doesn't work

Sadly, not everything works with the VonHippel. Currently, there is no access to the i2c or i2S interfaces on the VonHippel. Also the DAC didn't seem to be responding to ioctl() calls, so it has been omitted from the code. Finally, the SPI bus hasn't yet been implemented as it hasn't been tested.

More Examples:

All examples are assuming a VonHippel module plugged into slot 1.

This will blink the blue LED indefinitely.

#*********************************
from VonHippel import *
from time import sleep
 
v = VonHippel('/dev/bmi_vh_control_m1')
while True:
    v.toggle_iox(3)
    sleep(0.5)

This will turn on the blue LED when the voltage at the ADC0 pin goes above 1.225V:

#*********************************
from VonHippel import *
from time import sleep
 
v = VonHippel('/dev/bmi_vh_control_m1')
v.set_adcgain(0,1)  #make sure that the gain for ADC channel 0 is set to 1.
while True:
    val = v.read_adc(0)  #Read the ADC
    if val > 2.45/2:
        v.iox_high(3)
    else:
        v.iox_low(3)
    sleep(0.150)

This will turn on the iox pin and LED when the corresponding button on the left of the base is held down.

#*********************************
from VonHippel import *
from time import sleep
 
v = VonHippel('/dev/bmi_vh_control_m1')
f = open('/proc/bugnav','r')
while True:
    f.seek(0,0)
    for line in f:
        if line[0] == 'M'
            v.set_iox(int(line[1]) - 1,int(line[3]))
    sleep(0.150)