domingo, 4 de junio de 2017

Octave: Fit Gaussian to data



% Adjust a gaussian
% Define the gaussian function
gausFun = @(hms,x) hms(1) .* exp (-(x-hms(2)).^2 ./ (2*hms(3)^2)) ;
init=[100;0;20]; % Hmax, mean, sigma
[P, FY, CVG, OUTP] = nonlin_curvefit (gausFun , init', XX, NN);
%Print estimated sigma
sigma_est=P(3)

viernes, 28 de abril de 2017

Raspberry pi zero W

Enable headless operation

  1. Download raspbian and write to micro-SD card
  2. Mount on PC and, on the boot partition:
  3. Create an (empty) file called ssh (this enable SSH on startup)
  4. Create a wpa_supplicant.conf file with the following content
network={
    ssid="YOUR_WIFI_SSID"
    psk="YOUR_WIFI_PASSWORD"
    key_mgmt=WPA-PSK
}
 

On Off button

Poweroff


To poweroff, follow these instructions:

Essentially:
Connect button between GPIO18 and GND
Write this python script


    1. #!/bin/python  
    2. # Simple script for shutting down the raspberry Pi at the press of a button.  
    3. # by Inderpreet Singh  
    4.   
    5. import RPi.GPIO as GPIO  
    6. import time  
    7. import os  
    8.  
    9. # Use the Broadcom SOC Pin numbers  
    10. # Setup the Pin with Internal pullups enabled and PIN in reading mode.  
    11. GPIO.setmode(GPIO.BCM)  
    12. GPIO.setup(18, GPIO.IN, pull_up_down = GPIO.PUD_UP)  
    13.  
    14. # Our function on what to do when the button is pressed  
    15. def Shutdown(channel):  
    16.     os.system("sudo shutdown -h now")  
    17.  
    18. # Add our function to execute when the button pressed event happens  
    19. GPIO.add_event_detect(18, GPIO.FALLING, callback = Shutdown, bouncetime = 2000)  
    20.  
    21. # Now wait!  
    22. while 1:  
    23.     time.sleep(1)  



We need our python script to run automatically every time the RPi starts. For this we need to do a little manual editing of the RPI generated files. Run the following command
  1. sudo nano /etc/rc.local 
This file is what gets executed everytime your RPi boots up. We need to add our python command before the last line which closes the if loop. Therefore, add the following line before the #fi at the end of the file.
  1. sudo python /home/pi/Scripts/shutdown_pi.py & 
Please note that everything is case sensitive so Scripts is not the same as scripts. The & at the end of the command tells it to run the process in the background. If you omit it, then your login prompt probably will not appear.

Poweron


To poweron, place a button across the RUN header of the RPI zero. This is actually a reset button but when halted can bring the Pi on again.


Power Consumption


During boot, I have seen peaks of 240 mA.
After shutdown, power consumption is 30 mA.




 

sábado, 25 de marzo de 2017

SPICE with Python

PySpice seems to be a great tool!
Just do
git clone https://github.com/FabriceSalvaire/PySpice
and install everything that it needs:
PySpice requires the following dependencies:

The way to organize a project is to have the file.py, a folder called libraries and inside put folders with the element.lib files. These can also be put into folders to easily organize things. Then, call this

libraries_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'libraries')
spice_library = SpiceLibrary(libraries_path)
circuit.include(spice_library['2n2222a'])
circuit.BJT(1, 'collector', 'base', circuit.gnd, '2n2222a')

Resistor
circuit.R( name, +node, -node, value) 
circuit.R(1, 'out', circuit.gnd, kilo(5))

Capacitor
circuit.C(1, +node, -node, value)
circuit.C(1, +node, -node, value, initial_condition=5)

BJT
circuit.BJT(1, 'collector', 'base', circuit.gnd, '2n2222a')


Results
analysis.base : the voltage of node named 'base'





Interesting features
https://github.com/FabriceSalvaire/PySpice/blob/gh-pages/downloads/voltage-divider.py
Shows how to put a voltage source defined in Python into Spice. This probably means that you can have an arbitrary function generator in Python!!!

domingo, 5 de febrero de 2017

Coses sobre l'esquena i els isquiotibials


https://breakingmuscle.com/learn/2-overlooked-reasons-your-hamstrings-are-tight

https://breakingmuscle.com/learn/cant-touch-your-toes-find-and-fix-the-root-of-the-problem

https://breakingmuscle.com/learn/are-your-weak-neck-muscles-making-your-hamstrings-tight


viernes, 3 de febrero de 2017

Arduino. On és el main?


Exactament què fa un programa en Arduino?

Executa un loop com aquest: https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/main.cpp

int main(void) {
    init();
    initVariant();
   
    setup();
   
    for (;;) {
        loop();
        if (serialEventRun) serialEventRun();
    }  
    return 0;
}


Executa una vegada el setup de client i crida repetidament loop() més serialEventRun.

Tot el codi principal està aquí https://github.com/arduino/Arduino/tree/master/hardware/arduino/avr/cores/arduino

Un element important és Arduino.h (en les versions "modernes" de Arduino).

jueves, 2 de febrero de 2017

Flight Controller

One of the best tutorials I have found on flight controllers

http://blog.owenson.me/build-your-own-quadcopter-flight-controller/

sábado, 7 de enero de 2017

Python debugging

Install interactive debugging

sudo -H pip install ipdb

To debug a script in ipython
that uses parameters in its call:

ipython -m ipdb './xvalues.py' -- -d TUB

The parameters for the script are passed after "--"

Once you have the shell, the useful commands are:
  • n "next"
  • <ENTER> repeats the last command
  • p "print" p variable
  • s "step into"
  • b "breakpoint" b. This can be interesting: break at line 25: b 25. Break when method x of object y is called b y.x
  • r "continue to end of subroutine"
  • c "continue till the end"

Useful link
https://pythonconquerstheuniverse.wordpress.com/2009/09/10/debugging-in-python/

viernes, 6 de enero de 2017

domingo, 4 de diciembre de 2016

What to do after installing a new Ubuntu system

To be able to keep a list of all packages that we install next, edit /etc/logrotate.d/{apt,dpkg}


List of packages that have been installed in Ubuntu


From http://unix.stackexchange.com/questions/288024/how-can-i-get-a-list-of-packages-that-i-have-installed-using-apt-get

This will give you a list of packages that have been installed, in the order that they were installed:

zgrep -h ' install ' /var/log/dpkg.log* | sort | awk '{print $4}'

However, only the last 12 months of/var/log/dpkg.log* files are kept by default. To change this, edit /etc/logrotate.d/{apt,dpkg}. For example, change rotate 12 to rotate 1200 to keep the last 1200 months (100 years) worth - effectively forever, never delete the old logs.

Use dpkg to list all packages installed on a system: dpkg --get-selections



balllalalala