# Arduino Alvik API

<p class="callout warning">Estas instrucciones son específicas del ARDUINO ALVIK </p>

Para acceder a las funciones de Arduino Alvik API tenemos que ejecutar las instrucciones:

```python
alvik = ArduinoAlvik()
alvik.begin()
```

Entonces ya podemos usar las siguientes: (extraido de [https://docs.arduino.cc/tutorials/alvik/api-overview/](https://docs.arduino.cc/tutorials/alvik/api-overview/) )

<p class="callout success">Luego veremos en el apartado de programación del Arduino Alvik con código Arduino IDE que utilizaremos una biblioteca #include "Arduino\_Alvik.h" que importa prácticamente las mismas funciones, ver [https://libros.catedu.es/books/arduino-alvik/page/programas-arduino-ide-sin-iot](https://libros.catedu.es/books/arduino-alvik/page/arduino-ide-sin-iot-un-pequena-danza) </p>

<table border="1" id="bkmrk-funcion-salida-stop%28" style="border-collapse: collapse; width: 100%; height: 313.598px;"><colgroup><col style="width: 53.8625%;"></col><col style="width: 46.2434%;"></col></colgroup><tbody><tr><td>**FUNCION con sus Inputs**</td><td>**Outputs**</td></tr><tr><td style="height: 29.6806px;">stop()</td><td style="height: 29.6806px;">para todas las funciones Alvik</td></tr><tr style="height: 46.4722px;"><td style="height: 46.4722px;">is\_on()</td><td style="height: 46.4722px;">true si esta encendido  
false si esta apagado</td></tr><tr style="height: 29.6806px;"><td style="height: 29.6806px;">is\_target\_reached()</td><td style="height: 29.6806px;">true si ha enviado M o R en el mensaje</td></tr><tr><td>get\_ack()</td><td>last\_ack: el valor del último mensaje</td></tr><tr style="height: 29.6806px;"><td style="height: 29.6806px;">stop()</td><td style="height: 29.6806px;">para todas las funciones Alvik</td></tr><tr style="height: 29.6806px;"><td style="height: 29.6806px;">get\_orientation()</td><td style="height: 29.6806px;">r: valor de balanceo p: valor de cabeceo y: valor de guiñada</td></tr><tr style="height: 29.6806px;"><td style="height: 29.6806px;">get\_accelerations()

ver uso en   
[https://libros.catedu.es/books/arduino-alvik/page/programas-de-ejemplo](https://libros.catedu.es/books/arduino-alvik/page/programas-de-test)

</td><td style="height: 29.6806px;">ax  
ay  
az</td></tr><tr style="height: 29.6806px;"><td style="height: 29.6806px;">get\_gyros()  
  
ver uso en   
[https://libros.catedu.es/books/arduino-alvik/page/programas-de-ejemplo](https://libros.catedu.es/books/arduino-alvik/page/programas-de-test)

</td><td style="height: 29.6806px;">gx  
by  
gz</td></tr><tr style="height: 29.6806px;"><td style="height: 29.6806px;">get\_imu()</td><td style="height: 29.6806px;">las 6 anteriores</td></tr><tr style="height: 29.6806px;"><td style="height: 29.6806px;">get\_line\_sensors()</td><td style="height: 29.6806px;">left  
center

right

</td></tr><tr style="height: 29.6806px;"><td style="height: 29.6806px;">brake()</td><td style="height: 29.6806px;">Frena el robot</td></tr><tr><td>get\_battery\_charge()</td><td>battery\_soc: el % de la batería</td></tr><tr><td>get\_touch\_any()</td><td>touch\_any es true si se ha apretado cualquier botón</td></tr><tr><td>get\_touch\_ok()   
get\_touch\_cancel()   
get\_touch\_center()  
get\_touch\_up()  
get\_touch\_left()  
get\_touch\_down()  
get\_touch\_right()  
</td><td>touch\_ok es true si se ha apretado ok etc...

ver ejemplos en

[https://libros.catedu.es/books/arduino-alvik/page/robotica-para-infantil](https://libros.catedu.es/books/arduino-alvik/page/robotica-para-infantil)

y en

[https://libros.catedu.es/books/arduino-alvik/page/mensajes-a-telegram](https://libros.catedu.es/books/arduino-alvik/page/mensajes-a-telegram)

</td></tr><tr><td>get\_color\_raw()  
get\_color\_label()  
</td><td>color</td></tr><tr><td>get\_version()  
print\_status()  
</td><td>versión del firmware  
para actualizarlo ver [https://docs.arduino.cc/tutorials/alvik/user-manual/#how-to-upload-firmware](https://docs.arduino.cc/tutorials/alvik/user-manual/#how-to-upload-firmware)

</td></tr><tr><td>set\_behaviour(behaviour: int)</td><td>  
</td></tr><tr><td>rotate(angle: float, unit: str = 'deg', blocking: bool = True)</td><td>  
</td></tr><tr><td>move(distance: float, unit: str = 'cm', blocking: bool = True)</td><td>  
</td></tr><tr><td>get\_wheels\_speed(unit: str = 'rpm')</td><td>left\_wheel\_speed: the speed value  
right\_wheel\_speed: the speed value</td></tr><tr><td>set\_wheels\_speed(left\_speed: float, right\_speed: float, unit: str = 'rpm')</td><td>  
</td></tr><tr><td>set\_wheels\_position(left\_angle: float, right\_angle: float, unit: str = 'deg')</td><td>  
</td></tr><tr><td>get\_wheels\_position(unit: str = 'deg')</td><td>angular\_velocity</td></tr><tr><td>drive(linear\_velocity: float, angular\_velocity: float, linear\_unit: str = 'cm/s',angular\_unit: str = 'deg/s')</td><td>  
</td></tr><tr><td>get\_drive\_speed(linear\_unit: str = 'cm/s', angular\_unit: str = 'deg/s')</td><td>linear\_velocity: speed of the robot.  
angular\_velocity: speed of the wheels.</td></tr><tr><td>reset\_pose(x: float, y: float, theta: float, distance\_unit: str = 'cm', angle\_unit: str = 'deg')</td><td>  
</td></tr><tr><td>get\_pose(distance\_unit: str = 'cm', angle\_unit: str = 'deg')</td><td>x  
y  
theta</td></tr><tr><td>set\_servo\_positions(a\_position: int, b\_position: int)</td><td>  
</td></tr><tr><td>set\_builtin\_led(value: bool)</td><td>  
</td></tr><tr><td>set\_illuminator(value: bool)</td><td>  
</td></tr><tr><td>color\_calibration(background: str = 'white')</td><td>  
</td></tr><tr><td>rgb2hsv(r: float, g: float, b: float)

</td><td>h: hue value  
s: saturation value  
v: brightness value</td></tr><tr><td>get\_color(color\_format: str = 'rgb')

</td><td>r or h  
g or s  
b or v</td></tr><tr><td>hsv2label(h, s, v)

</td><td>color label: like "BLACK" or "GREEN", if possible, otherwise return "UNDEFINED"  
</td></tr><tr><td>get\_distance(unit: str = 'cm')

</td><td>lee la distancia del sensor TOF:  
ver ejemplo en [https://libros.catedu.es/books/arduino-alvik/page/evita-obstaculos](https://libros.catedu.es/books/arduino-alvik/page/evita-obstaculos)  
  
left\_tof: 45° to the left object distance  
center\_left\_tof: 22° to the left object distance  
center\_tof: center object distance  
center\_right\_tof: 22° to the right object distance  
right\_tof: 45° to the right object distance  
</td></tr><tr><td>get\_distance\_top(unit: str = 'cm')

</td><td>top\_tof: 45° to the top object distance  
</td></tr><tr><td>get\_distance\_bottom(unit: str = 'cm')

</td><td>bottom\_tof: 45° to the bottom object distance  
</td></tr><tr><td>on\_touch\_ok\_pressed(callback: callable, args: tuple = ())

on\_touch\_cancel\_pressed(callback: callable, args: tuple = ())

on\_touch\_center\_pressed(callback: callable, args: tuple = ())

on\_touch\_up\_pressed(callback: callable, args: tuple = ())

on\_touch\_left\_pressed(callback: callable, args: tuple = ())

on\_touch\_down\_pressed(callback: callable, args: tuple = ())

on\_touch\_right\_pressed(callback: callable, args: tuple = ())

</td><td>He intentado hacer programas con estas instrucciones, pero una vez pulsado la tecla, sigue llamando a callback continuamente

No veo su utilidad teniendo get\_touch

</td></tr></tbody></table>

##### <span style="color: rgb(22, 145, 121);">**Unidades**</span>

- m: centimeters  
    mm: millimeters  
    m: meters  
    inch: inch, 2.54 cm  
    in: inch, 2.54 cm
- deg: degrees, example: 1.0 as reference for the other unit. 1 degree is 1/360 of a circle.  
    rad: radiant, example: 1 radiant is 180/pi deg.  
    rev: revolution, example: 1 rev is 360 deg.  
    revolution: same as rev  
    perc: percentage, example 1 perc is 3.6 deg.  
    %: same as perc
- 'cm/s': centimeters per second  
    'mm/s': millimeters per second  
    'm/s': meters per second  
    'inch/s': inch per second  
    'in/s': inch per second
- 'rpm': revolutions per minute, example: 1.0 as reference for the other unit.  
    'deg/s': degrees per second, example: 1.0 deg/s is 60.0 deg/min that is 1/6 rpm.  
    'rad/s': radiant per second, example: 1.0 rad/s is 60.0 rad/min that is 9.55 rpm.  
    'rev/s': revolution per second, example: 1.0 rev/s is 60.0 rev/min that is 60.0 rpm.

<p class="callout info">¿Qué es eso de **bloking**?  
Por ejemplo en rotate(angle: float, unit: str = 'deg', blocking: bool = True)  
  
Si es true, todos los eventos no influyen, es decir el microprocesador esta centrado en esa instrucción  
Si es falso, el microprocesador es libre de hacer otra cosa a la vez  
  
Utiliza true si quieres precisión o no quieres que nada interaccione con la acción que estas ejecutando</p>