RaspberryPi

From Asociación de Robótica UC3M
Jump to navigation Jump to search
Logo concursos.png

Diseños

Todos los diseños disponibles se encuentran en el siguiente enlace.

Proyectos interesantes


Operative Systems

Configurations

Remote access

La raspberry pi debe estar conectada por ethernet al router de ASROB. El ordenador de trabajo debe estar conectado a la misma red mediante wifi o ethernet.

Method #3: X11 Forwarding for Desktop over SSH

With X11+SSH forwarding, you can actually run the entire desktop of Raspberry Pi remotely, not just standalone GUI applications.

Here I will show how to run the remote RPi desktop in the second virtual terminal (i.e., virtual terminal 8) via X11 forwarding. Your Linux desktop is running by default on the first virtual terminal, which is virtual terminal #7. Follow instructions below to get your RPi desktop to show up in your second virtual terminal.

Open your console or terminal, and change to root user. [Important you must be superuser if not, this will not work]

$ sudo su

Type the command below, which will activate xinit in virtual terminal 8. Note that you will be automatically switched to virtual terminal 8. You can switch back to the original virtual terminal 7 by pressing CTRL+ALT+F7.

# xinit -- :1 &

After switching to virtual terminal 8, execute the following command to launch the RPi desktop remotely. Type pi user password when asked (see picture below).

# DISPLAY=:1 ssh -X pi@192.168.2.5 lxsession 

or if ASROB wifi connected:

# DISPLAY=:1 ssh -X pi@222.1.1.3 lxsession

You will bring to your new virtual terminal 8 the remote RPi desktop, as well as a small terminal launched from your active virtual terminal 7 (see picture below).

Remember, do NOT close that terminal. Otherwise, your RPi desktop will close immediately.

You can move between first and second virtual terminals by pressing CTRL+ALT+F7 or CTRL+ALT+F8.

To close your remote RPi desktop over X11+SSH, you can either close a small terminal seen in your active virtual terminal 8 (see picture above), or kill su session running in your virtual terminal 7.

More info.

Camera

Open the raspi-config tool from the Terminal:

sudo raspi-config

Select Enable camera and hit Enter, then go to Finish and you'll be prompted to reboot.

The python-picamera library is available in the Raspbian archives. Install with apt:

sudo apt-get update
sudo apt-get install python-picamera*

More info:

Hardware

GPIO

El puerto GPIO tiene las siguientes características:

The GPIO connector actually has a number of different types of connection on them. There are:

  • True GPIO (General Purpose Input Output) pins that you can use to turn LEDs on and off etc.
  • I2C interface pins that allow you to connect hardware modules with just two control pins
  • SPI interface with SPI devices, a similar concept to I2C but a different standard
  • Serial Rx and Tx pins for communication with serial peripherals

In addition, some of the pins can be used for PWM (pulse Width Modulation) for power control and another type of pulse generation for controlling servo motors called PPM (Pulse Position Modulation). In this tutorial, you are not actually build anything, but you will learn how to configure your Raspberry Pi and install useful libraries ready to start attaching some external electronics to it.

En la página aparece un overview y los primeros pasos para configurar el puerto.

Raspberry-Pi-GPIO-Layout-Revision-2.png Gpio-srm.png

Software

GPIO libreries

C/C++

Configuración puerto GPIO Buen tutorial en C/C++ para controlar el GPIO

Python

Existen dos librerías para poder controlar el GPIO de la Raspberry Pi:

Adafruit
$ sudo apt-get install git
$ git clone http://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code.git
$ cd Adafruit-Raspberry-Pi-Python-Code

Es un repositorio de proyectos-ejempos en Python para gobernar el puerto GPIO. Para poder usarlos es necesario tener estas librerías instaladas

rpi.gpio

En el siguiente link están los pasos a seguir. Se reducen a instalar las librerías de GPIO para la Raspberry:

$sudo apt-get update
$sudo apt-get install python-dev
$sudo apt-get install python-rpi.gpio

Para ejemplos visitar esta página

  • Ejemplo
#!/usr/bin/python
import RPi.GPIO as GPIO
import time

channel = 15
GPIO.setmode(GPIO.BOARD)

GPIO.setup(channel, GPIO.OUT)

for i in range (10):
	GPIO.output(channel, GPIO.LOW)
	time.sleep(3)
	GPIO.output(channel, GPIO.HIGH)
	time.sleep(3)

GPIO.cleanup(channel)
PWM
#!/usr/bin/python
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BOARD) # pin GPIO
GPIO.setup(12, GPIO.OUT) # salida

p = GPIO.PWM(12, 0.5) # channel=12 frequency=0.5Hz
p.start(1) # duty cycle (en este caso 1%)
input('Press return to stop:')   # use raw_input for Python 2
p.stop()
GPIO.cleanup()

Este programa configura el pin 12 como salida pwm de 0.5 HZ. 1 vez cada 2 seg hace parpadear el led)

Servo

Instalar las librerías de RPIO localizadas en esta página siguiendo las instrucciones:

$ sudo apt-get install python-setuptools
$ sudo easy_install -U RPIO

Para poder controlar un servo, no es posible alimentarlo directamente desde la raspberry pi. En vez de eso, es necesaria una fuerte externa de alimentación ya sea una pila o un transformador. El control del servo se realiza mediante el ancho de pulso PWM. Para más info

El ancho de puslo determina el ángulo del servo: - 300us de 20ms serán 0 grados - 2500us de 20ms será el tope 180 grados

Existe una librería llamada RPIO que se utiliza para controlar los motores:

from RPIO import PWM

servo = PW:.Servo()

r=1460

while r is not "q":
  r = imput("ancho de pulso en microsegundos:")
  servo.set_servo(18,r)

servo.stop_servo(18)
I2C

En esta página se recogen los pasos para la correcta configuración.


Camera libraries

Instalación y configuración de las librerías necesarias para controlar la Raspi Cam en C++ y utilizar openCv. Pasos extraídos del tutorial

C/C++
OpenCV

Las librerías de openCV se instalan mediante un script autoejecutable.

$ wget https://raw.github.com/jayrambhia/Install-OpenCV/master/Ubuntu/2.4/opencv2_4_5.sh
$ chmod +x opencv2_4_5.sh
$ ./opencv2_4_5.sh

Common Problem Solution

No se pudieron obtener algunos archivos, ¿Quizá deba ejecutar <<apt-get update>> o deba intentarlo de nuevo con --fix-missing?

Para resolver, dejar instalar y cuando acabe, hacer:

$ sudo apt-get update

Y volver a ejecutar

$./opencv2_4_5.sh

Una vez compilado despues de unas cuatro horas y media:

$ cd programs/OpenCv/opencv-2.4.5/build
$ sudo make install

A partir de aquí es necesario seguir el tutorial del la siguiente página.

El paso 2 trata sobre instalar userland que es un programa llamado rapistill que usa el acceso a la cámara de la raspberry y demás.

El paso 3 es para crear el primer programa y poner a prueba los pasos anteriores.

A la hora de compilar con make (una vez modificado el CMakeLists.txt)

fatal error EGL/egl.h: no such file or directory

Se soluciona instalando las librerías legl de synaptic que son las genéricas. Se han instalado las siguientes:

eglibc-source
libegl-0.2-0
libegl-dev

Se instalarán algunas dependencias más pero con estas valen. El último paso es modificar el CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
project(camcv)
SET(COMPILE_DEFINITIONS -Werror)
include_directories(/opt/vc/host_applications/linux/libs/bcm_host/include)
include_directories(/opt/vc/interface/vcos)
include_directories(/opt/vc/)
include_directories(/opt/vc/interface/vcos/pthreads)
include_directories(/opt/vc/interface/vmcs_host/linux)
include_directories(/opt/vc/interface/khronos/include)
include_directories(/opt/vc/interface/khronos/common)

add_executable(camcv RaspiCamControl.c RaspiCLI.c RaspiPreview.c camcv.c RaspiTex.c RaspiTexUtil.c teapot.c models.c square.c mirror.c)

target_link_libraries(camcv /opt/vc/lib/libmmal_core.so /opt/vc/lib/libmmal_util.so /opt/vc/lib/libmmal_vc_client.so /opt/vc/lib/libvcos.so /opt/vc/lib/libbcm_host.so /opt/vc/lib/libGLESv2.so /opt/vc/lib/libEGL.so)

Ahora sí se puede compilar con make y no da problemas.

Finalmente para añadir opencv al programa seguir el paso 4 del tutorial

Para esta parte es necesario haber instalado el lilbfacerec (reconocimiento facial) <c lang="make"> projects $ git clone https://github.com/bytefish/libfacerec.git $ cd libfacerec $ mkdir build $ cd build $ cmake .. $ make </syntaxhighlight lang="make"> Ya se puede modificar el CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
project(camcv)
SET(COMPILE_DEFINITIONS -Werror)
#OPENCV
find_package( OpenCV REQUIRED )

link_directories( /home/pi/projects/libfacerec )

include_directories(/opt/vc/host_applications/linux/libs/bcm_host/include)
include_directories(/opt/vc/interface/vcos)
include_directories(/opt/vc)
include_directories(/opt/vc/interface/vcos/pthreads)
include_directories(/opt/vc/interface/vmcs_host/linux)
include_directories(/opt/vc/interface/khronos/include)
include_directories(/opt/vc/interface/khronos/common)
add_executable(camcv RaspiCamControl.c RaspiCLI.c RaspiPreview.c camcv.c RaspiTex.c RaspiTexUtil.c teapot.c models.c square.c mirror.c)
target_link_libraries(camcv /opt/vc/lib/libmmal_core.so /opt/vc/lib/libmmal_util.so /opt/vc/lib/libmmal_vc_client.so /opt/vc/lib/libvcos.so /opt/vc/lib/libbcm_host.so /opt/vc/lib/libGLESv2.so /opt/vc/lib/libEGL.so /home/pi/projects/libfacerec/build/libopencv_facerec.a ${OpenCV_LIBS})

En el archivo camcv.c a partir de la línea 232 está el código preparado para procesar la imagen con OpenCV.

Python
Raspi Cam

En este link están los primeros pasos y toda la documentación de la librería picamera en python.

OpenCv

Leer estos tutoriales de opencv en python.

Other raspicam libraries

Nueva librería del profe de Raúl. Habrá que probarla: aqui

Otra librerías para utilizar la raspicam

ROS Install

Follow the next tutorial tutorial Don't care about the python-catkink-pkg and other similar errors. They have been installed by pip.

Wait until catkin_make_isolated ends and make an export like:

$ export LC_ALL=C

If you want to make permanent --> to .bashrc

Proyecto rastreador mediante procesamiento de imagen

Este proyecto se basa en un rastreador con un chasis de protobot al cual se le ha incorporado una raspberry Pi. Esta raspberry Pi es capaz de controlar dos servos que actuan de sistema motriz del protobot. La forma de seguir las líneas es mediante visión por computador. La cámara de raspberry está colocada en la parte frontal del vehículo ajustando la información visual entre 10 y 20 cm. Mediante librerías de OpenCv se pretende procesar la imagen y sacar la desviación del robot con respecto a la linea y realizar un control acorde a ese error.

Repositorio

En el siguiente enlace podréis ver de manera online el REPOSITORIO.

Para poder trabajar con el repositorio, en la ubicación deseada abrir una terminal y poner lo siguiente:

git clone https://github.com/asrob-uc3m/rpc_rpi.git asrob_rpc_rpi

Para más información sobre el uso de Git seguir este TUTORIAL.



By-sa.png Este obra está bajo una licencia de Creative Commons Reconocimiento-CompartirIgual 3.0 Unported.