e-puck2 and Pi-puck: Difference between pages

From GCtronic wiki
(Difference between pages)
Jump to navigation Jump to search
 
 
Line 1: Line 1:
=Hardware=
=Hardware=
==Overview==
==Overview==
<span class="plainlinks">[http://www.gctronic.com/doc/images/e-puck2-overview.png <img width=500 src="http://www.gctronic.com/doc/images/e-puck2-overview_small.png">]</span>
<span class="plainlinks">[https://projects.gctronic.com/epuck2/wiki_images/pipuck-overview.jpg <img width=600 src="https://projects.gctronic.com/epuck2/wiki_images/pipuck-overview-small.jpg">]</span><br/>
<span class="plainlinks">[http://projects.gctronic.com/epuck2/wiki_images/e-puck2-features.png <img width=600 src="http://projects.gctronic.com/epuck2/wiki_images/e-puck2-features_small.png">]</span><br/>
Features:
* Raspberry Pi zero W (rPi) connected to the robot via I2C
* interface between the robot base camera and the rPi via USB, up to 15 FPS
* 1 digital microphone and 1 speaker
* USB hub connected to the rPi with 2 free ports
* uUSB cable to the rPi uart port. Also ok for charging
* 2 chargers. 1 for the robot battery and 1 for the auxiliary battery on top of the extension
* charging contact points in front for automatic charging. External docking station available
* several extension options. 6 i2C channels, 2 ADC inputs
* several LED to show the status of the rPi and the power/chargers


The following figures show the main components offered by the e-puck2 robot and where they are physically placed:<br/>
==I2C bus==
<span class="plainlinks">[http://projects.gctronic.com/epuck2/wiki_images/epuck2-components-position.png <img width=800 src="http://projects.gctronic.com/epuck2/wiki_images/epuck2-components-position_small.png">]</span><br/>
I2C is used to let communicate various elements present in the robot, Pi-puck and extensions. An overall schema is shown in the following figure:<br/>
<span class="plainlinks">[https://projects.gctronic.com/epuck2/wiki_images/i2c-buses.png <img width=600 src="https://projects.gctronic.com/epuck2/wiki_images/i2c-buses.png">]</span><br/>
An I2C switcher is included in the Pi-puck extension in order to support additional I2C buses (the RPi alone has only one usable I2C bus). These are needed to avoid conflicts between Time-of-Flight sensors that have a fixed I2C address.


==Specifications==
=Getting started=
The e-puck2 robot maintains full compatibility with its predecessor e-puck (e-puck HWRev 1.3 is considered in the following table):
This introductory section explains the minimal procedures needed to work with the Raspberry Pi Zero W mounted on the Pi-puck extension board and gives a general overview of the available basic demos and scripts shipped with the system flashed on the micro SD. More advanced demos are described in the following separate sections (e.g. ROS), but the steps documented here are fundamental, so be sure to fully understand them. <br/>
{| border="1"
|'''Feature'''
|'''e-puck1.3'''
|'''e-puck2'''
|'''Compatibility'''
|'''Additional'''
|-
|Size, weight
|70 mm diameter, 55 mm height, 150 g
|Same form factor: 70 mm diameter, 45 mm, 130 g
|style="text-align:center;" | <img width=40 src="http://www.gctronic.com/doc/images/ok.png">
|No e-jumper required
|-
|Battery, autonomy
|LiIPo rechargeable battery (external charger), 1800 mAh. <br/>About 3 hours autonomy. Recharging time about 2-3h.
|Same battery; USB charging, recharging time about 2.5h.
|style="text-align:center;" | <img width=30 src="http://www.gctronic.com/doc/images/plus.png">
|USB charging
|-
|Processor
|16-bit dsPIC30F6014A @ 60MHz (15 MIPS), DSP core for signal processing
|32-bit STM32F407 @ 168 MHz (210 DMIPS), DSP and FPU, DMA
|style="text-align:center;" | <img width=30 src="http://www.gctronic.com/doc/images/plus.png">
|~10 times faster
|-
|Memory
|RAM: 8 KB; Flash: 144 KB
|RAM: 192 KB; Flash: 1024 KB
|style="text-align:center;" | <img width=30 src="http://www.gctronic.com/doc/images/plus.png">
|RAM: 24x more capable<br/>Flash:~7x more capable
|-
|Motors
|2 stepper motors with a 50:1 reduction gear; 20 steps per revolution; about 0.13 mm resolution
|Same motors
|style="text-align:center;" | <img width=40 src="http://www.gctronic.com/doc/images/ok.png">
|
|-
|Wheels
|Wheels diamater = 41 mm <br/>Distance between wheels = 53 mm
|Same wheels
|style="text-align:center;" | <img width=40 src="http://www.gctronic.com/doc/images/ok.png">
|
|-
|Speed
|Max: 1000 steps/s (about 12.9 cm/s)
|Max: 1200 steps/s (about 15.4 cm/s)
|style="text-align:center;" | <img width=30 src="http://www.gctronic.com/doc/images/plus.png">
|20% faster
|-
|Mechanical structure
|Transparent plastic body supporting PCBs, battery and motors
|Same mechanics
|style="text-align:center;" | <img width=40 src="http://www.gctronic.com/doc/images/ok.png">
|
|-
|Distance sensor
|8 infra-red sensors measuring ambient light and proximity of objects up to 6 cm
|Same infra-red sensors <br/>Front real distance sensor, Time of fight (ToF), up to 2 meter.
|style="text-align:center;" | <img width=30 src="http://www.gctronic.com/doc/images/plus.png">
|ToF sensor
|-
|IMU
|3D accelerometer and 3D gyro
|3D accelerometer, 3D gyro, 3D magnetometer
|style="text-align:center;" | <img width=30 src="http://www.gctronic.com/doc/images/plus.png">
|3D magnetometer
|-
|Camera
|VGA color camera; typical use: 52x39 or 480x1
|Same camera; typical use: 160x120
|style="text-align:center;" | <img width=40 src="http://www.gctronic.com/doc/images/ok.png">
|Bigger images handling
|-
|Audio
|3 omni-directional microphones for sound localization<br/>speaker capable of playing WAV or tone sounds
|4 omni-directional microhpones (digital) for sound localization<br/>speaker capable of playing WAV or tone sounds
|style="text-align:center;" | <img width=30 src="http://www.gctronic.com/doc/images/plus.png">
| +1 front microphone
|-
|LEDs
|8 red LEDs around the robot, green body light, 1 strong red LED in front
|4 red LEDs and 4 RGB LEDs around the robot, green light, 1 strong red LED in front
|style="text-align:center;" | <img width=30 src="http://www.gctronic.com/doc/images/plus.png">
|4x RGB LEDs
|-
|Communication
|RS232 and Bluetooth 2.0 for connection and programming
|USB Full-speed, Bluetooth 2.0, BLE, WiFi
|style="text-align:center;" | <img width=30 src="http://www.gctronic.com/doc/images/plus.png">
|WiFi, BLE
|-
|Storage
|Not available
|Micro SD slot
|style="text-align:center;" | <img width=30 src="http://www.gctronic.com/doc/images/plus.png">
|Micro SD
|-
|Remote Control
|Infra-red receiver for standard remote control commands
|Same receiver
|style="text-align:center;" | <img width=40 src="http://www.gctronic.com/doc/images/ok.png">
|
|-
|Switch / selector
|16 position rotating switch
|Same selector
|style="text-align:center;" | <img width=40 src="http://www.gctronic.com/doc/images/ok.png">
|
|-
|Extensions
|Ground sensors, range and bearing, RGB panel, Gumstix extension, omnivision, your own
|All extension supported
|style="text-align:center;" | <img width=40 src="http://www.gctronic.com/doc/images/ok.png">
|
|-
|Programming
|Free C compiler and IDE, Webots simulator, external debugger
|Free C compiler and IDE, Webots simulator, onboard debugger (GDB)
|style="text-align:center;" | <img width=30 src="http://www.gctronic.com/doc/images/plus.png">
|Onboard debugger
|}


This is the overall communication schema:<br/>
The extension is mostly an interface between the e-puck robot and the Raspberry Pi, so you can exploit the computational power of a Linux machine to extend the robot capabilities.<br/>
<span class="plainlinks">[http://www.gctronic.com/doc/images/comm-overall-e-puck2E.jpg <img width=700 src="http://www.gctronic.com/doc/images/comm-overall-e-puck2E.jpg">]</span><br/>


==Documentation==
In most cases, the Pi-puck extension will be attached to the robot, but it's interesting to note that it can be used also alone when the interaction with the robot isn't required.<br/>
* '''Main microcontroller''': STM32F407, [http://projects.gctronic.com/epuck2/doc/STM32F407xx_datasheet.pdf datasheet], [http://projects.gctronic.com/epuck2/doc/STM32F407_reference-manual.pdf reference-manual]
The following sections assume the full configuration (robot + extension), unless otherwise stated.
* '''Programmer/debugger''': STM32F413, [http://projects.gctronic.com/epuck2/doc/STM32F413x_datasheet.pdf datasheet], [http://projects.gctronic.com/epuck2/doc/STM32F413_reference-manual.pdf reference-manual]
* '''Radio module''': Espressif ESP32, [http://projects.gctronic.com/epuck2/doc/esp32_datasheet_en.pdf datasheet], [http://projects.gctronic.com/epuck2/doc/esp32_technical_reference_manual_en.pdf reference-manual]
* '''Camera''': PixelPlus PO8030D CMOS image sensor, [http://projects.gctronic.com/E-Puck/docs/Camera/PO8030D.pdf datasheet], no IR cut filter
* '''Microphones''': STM-MP45DT02, [http://projects.gctronic.com/epuck2/doc/mp45dt02.pdf datasheet]
* '''Optical sensors''': Vishay Semiconductors Reflective Optical Sensor, [http://projects.gctronic.com/epuck2/doc/tcrt1000.pdf datasheet]
* '''ToF distance sensor''': STM-VL53L0X, [http://projects.gctronic.com/epuck2/doc/VL53L0X-Datasheet.pdf datasheet], [http://projects.gctronic.com/epuck2/doc/VL53L0X-UserManual-API.pdf user-manual]
* '''IMU''': InvenSense MPU-9250, [http://projects.gctronic.com/epuck2/doc/MPU-9250-product-specification.pdf product-specification], [http://projects.gctronic.com/epuck2/doc/MPU-9250-Register-Map.pdf register-map]
* '''Motors''': [http://www.e-puck.org/index.php?option=com_content&view=article&id=7&Itemid=9 details]
* '''Speaker''': Diameter 13mm, power 500mW, 8 Ohm, DS-1389 or PSR12N08AK or similar
* '''IR receiver''': TSOP36230


=Installation of the e-puck2 environment=
==Requirements==
Some programs are needed to program the e-puck2.
The robot must be programmed with a special firmware in order to communicate via I2C bus with the Raspberry Pi mounted on the Pi-puck extension. The same I2C bus is shared by all the devices (camera, IMU, distance sensor, others extensions), the main microcontroller and the Raspberry Pi. Since the Raspberry Pi acts as I2C master, these devices will not be anymore reachable directly from the robot main microcontroller that will act instead as I2C slave.


#Eclipse_e-puck2 is a distribution of Eclipse IDE for C/C++ Developers specially modified to edit and compile e-puck2's projects out of the box. It doesn't require to be installed and everything needed is located in the package given. The only dependency needed to be able to run Eclipse is '''Java'''.
===e-puck1===
#Drivers must also be installed for Windows older than Windows 10.
The e-puck1 robot must be programmed with the following firmware [https://raw.githubusercontent.com/yorkrobotlab/pi-puck/master/e-puck1/pi-puck-e-puck1.hex pi-puck-e-puck1.hex].


==Installation for Windows==
===e-puck2===
===Java 8 32bits===
The e-puck2 robot must be programmed with the following firmware [https://projects.gctronic.com/epuck2/gumstix/e-puck2_main-processor_extension_b346841_07.06.19.elf  e-puck2_main-processor_extension.elf (07.06.19)] and the selector must be placed in position 10.<br/>
This section can be ignored if Java version 8 32bits is already installed on your computer.<br>
The source code is available in the <code>gumstix</code> branch of the repo <code>https://github.com/e-puck2/e-puck2_main-processor</code>.
To verify, you can open the '''Programs and Features''' panel and search for a '''Java 8 Update xxx''' install.  


#Go to the [https://www.java.com/en/download/manual.jsp Java download page] and download "Windows offline" This is the 32bits version of Java.
==Turn on/off the extension==
#Run the downloaded installer and follow its instructions to proceed with the installation of Java 32bits.
To turn on the extension you need to press the <code>auxON</code> button as shown in the follwoing figure; this will turn on also the robot (if not already turned on). Similarly, if you turn on the robot then also the extension will turn on automatically.<br/>
#Close the internet browser if it opened at the end of the installation.
<span class="plainlinks">[https://projects.gctronic.com/epuck2/wiki_images/pipuck_btn_on_off.jpg <img width=250 src="https://projects.gctronic.com/epuck2/wiki_images/pipuck_btn_on_off-small.jpg">]</span><br/>


:<span class="plain links">[http://projects.gctronic.com/epuck2/wiki_images/Java_windows.png <img width=500 src="http://projects.gctronic.com/epuck2/wiki_images/Java_windows.png">]</span><br/>
To turn off the Pi-puck you need to press and hold the <code>auxON</code> button for 2 seconds; this will initiate the power down procedure.<br>
:''Java download page''


===Eclipse_e-puck2===
Beware that by turning off the robot, the extension will not be turned off automatically if it is powered from another source like the micro usb cable or a secondary battery. You need to use its power off button to switch it off. Instead if there is no other power source, then by turning off the robot also the extension will be turned off (not cleanly).
#Download the [http://projects.gctronic.com/epuck2/Eclipse_e-puck2/Eclipse_e-puck2_Win32_11_apr_2018.zip Eclipse_e-puck2 package for windows].
#Unzip the downloaded file to the location you want (can take time). It is strongly recommended for better performance and less extraction time to use 7Zip. You can download it on http://www.7-zip.org.
#You can now run the <code>Eclipse_e-puck2.exe</code> to launch Eclipse.
#You can create a shortcut to Eclipse_e-puck2.exe and place it anywhere if you want.


:<span class="plain links">[http://projects.gctronic.com/epuck2/wiki_images/Eclipse_e-puck2_Folder_Windows.png <img width=800 src="http://projects.gctronic.com/epuck2/wiki_images/Eclipse_e-puck2_Folder_Windows.png">]</span><br/>
==Console mode==
:''Eclipse_e-puck2 folder obtained after extraction''
The Pi-puck extension board comes with a pre-configured system ready to run without any additional configuration.<br/>
In order to access the system from a PC in console mode, the following steps must be performed:<br/>
1. connect a micro USB cable from the PC to the extension module. If needed, the drivers are available in the following link [https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers USB to UART bridge drivers]<br/>
<span class="plainlinks">[https://projects.gctronic.com/epuck2/wiki_images/pipuck_usb.png <img width=250 src="https://projects.gctronic.com/epuck2/wiki_images/pipuck_usb-small.png">]</span><br/>
2. execute a terminal program and configure the connection with 115200-8N1 (no flow control). The serial device is the one created when the extension is connected to the computer<br/>
3. switch on the robot (the extension will turn on automatically); now the terminal should display the Raspberry Pi booting information. If the robot isn't present, then you can directly power on the extension board with the related button<br/>
4. login with <code>user = pi</code>, <code>password = raspberry</code><br/>


'''Important things to avoid :'''
==Battery charge==
:1. The path to the Eclipse_e-puck2 folder must contain zero space.  
You can either charge the robot battery or the additional battery connected to the Pi-puck extension or both the batteries by simply plugging the micro USB cable.<br/>
::Example :
The following figure shows the connector for the additional battery.<br/>
::<code>C:\epfl_stuff\Eclipse_e-puck2</code> OK
<span class="plainlinks">[https://projects.gctronic.com/epuck2/wiki_images/pipuck_battery.jpg <img width=250 src="https://projects.gctronic.com/epuck2/wiki_images/pipuck_battery-small.jpg">]</span><br/>
::<code>C:\epfl stuff\Eclipse_e-puck2</code> NOT OK
:2. You must not put Ellipse_e-puck2 folder into '''Program Files (x86)'''. Otherwise the compilation when using Eclipse will not work.  
:3. The file’s structure in the Eclipse_e-puck2 folder must remain the same. It means no file inside this folder must be moved to another place.


===Drivers===
The robot can also autonomously charge itself if the charging wall is available. The Pi-puck extension includes two spring contacts on the front side that let the robot easily make contact with the charging wall and charge itself. The charging wall and the spring contacts are shown in the following figures:<br/>
This part concerns only the users of a Windows version older than Windows 10. The drivers are automatically installed with Windows 10.
<span class="plainlinks">[https://www.gctronic.com/img2/shop/pipuck-charger-robot.jpg <img width=250 src="https://www.gctronic.com/img2/shop/pipuck-charger-robot-small.jpg">]</span>
<span class="plainlinks">[https://projects.gctronic.com/epuck2/wiki_images/pipuck_contacts.jpg <img width=250 src="https://projects.gctronic.com/epuck2/wiki_images/pipuck_contacts-small.jpg">]</span><br/>


#Open <code>zadig-2.3.exe</code> located in the <code>Eclipse_e-puck2\Tools\</code> folder you installed before.
==Reset button==
#Connect the e-puck2 with the USB cable and turn it on. Three unknown devices appear in the device list of the program, namely '''e-puck2 STM32F407''', '''e-puck2 GDB Server (Interface 0)''' and '''e-puck2 Serial Monitor (Interface 2)'''.
A button is available to reset the robot, when pressed it will resets only the robot restarting its firmware. This is useful for instance during development or for specific demos in which a restart of the robot is needed. In these cases you don't need to turn off completely the robot (and consequently also the Pi-puck if energy is supplied by the robot) but instead you can simply reset the robot. The position of the reset button is shown in the following figure:<br/>
#For each of the three devices mentioned above, select the <code>USB Serial (CDC)</code> driver and click on the <code>Install Driver</code> button to install it. Accept the different prompts which may appear during the process. After that you can simply quit the program and the drivers are installed. These steps are illustrated on Figure 3 below.
<span class="plainlinks">[https://projects.gctronic.com/epuck2/wiki_images/pipuck_reset.png <img width=250 src="https://projects.gctronic.com/epuck2/wiki_images/pipuck_reset-small.png">]</span><br/>
::Note : The drivers installed are located in <code>C:\Users\"your_user_name"\usb_driver</code>


:<span class="plain links">[http://projects.gctronic.com/epuck2/wiki_images/Zadig_e-puck2_STM32F407.png <img width=500 src="http://projects.gctronic.com/epuck2/wiki_images/Zadig_e-puck2_STM32F407.png">]</span><br/>
=How to communicate with the robot and its sensors=
::''Example of driver installation for e-puck2 STM32F407''
==Communicate with the e-puck1==
Refer to the repo [https://github.com/yorkrobotlab/pi-puck-e-puck1 https://github.com/yorkrobotlab/pi-puck-e-puck1].


==Installation for Linux==
==Communicate with the e-puck2==
===Java 8===
An example showing how to exchange data between the robot and the Pi-puck extension is available in the Pi-puck repository; you can find it in the directory <code>/home/pi/Pi-puck/e-puck2/</code>.<br/>
This section can be ignored if Java is already installed on your computer.<br>
You can build the program with the command <code>gcc e-puck2_test.c -o e-puck2_test</code>.<br/>
To verify whether it is installed or not you can type the following command into a terminal window:
Now you can run the program by issueing <code>./e-puck2_test</code>; this demo will print the sensors data on the terminal and send some commands to the robot at 2 Hz.<br/>
<pre>update-java-alternatives -l</pre>
The same example is also available in Python, you can run it by issueing <code>python3 e-puck2_test.py</code>.
If Java is installed, you will get some information about it, otherwise the command will be unknown.<br>
You need to have Java 1.8.xxxx listed to be able to run Eclipse_e-puck2.


Type the following commands in a terminal session to install Java SDK:
===Packet format===
<pre>sudo add-apt-repository ppa:openjdk-r/ppa
Extension to robot packet format, 20 bytes payload (the number in the parenthesis represents the bytes for each field):
sudo apt-get update
{| border="1"
sudo apt-get install openjdk-8-jre </pre>
| Left speed (2)
| Right speed (2)
| Speaker (1)
| LED1, LED3, LED5, LED7 (1)
| LED2 RGB (3)
| LED4 RGB (3)
| LED6 RGB (3)
| LED8 RGB (3)
| Settings (1)
| Checksum (1)
|}
* Left, right speed: [-2000 ... 2000]
* Speaker: sound id = [0, 1, 2]
* LEDs on/off flag: bit0 for LED1, bit1 for LED3, bit2 for LED5, bit3 for LED7
* RGB LEDs: [0 (off) ... 100 (max)]
* Settings:
** bit0: 1=calibrate IR proximity sensors
** bit1: 0=disable onboard obstacle avoidance; 1=enable onboard obstacle avoidance (not implemented yet)
** bit2: 0=set motors speed; 1=set motors steps (position)
* Checksum: Longitudinal Redundancy Check (XOR of the bytes 0..18)


===Eclipse_e-puck2===
Robot to extension packet format, 47 bytes payload (the number in the parenthesis represents the bytes for each field):
#Install <code>make</code> (probably you already have it installed) by issueing the command: <code>sudo apt-get install make</code>
{| border="1"
#Download the Eclipse_e-puck2 package for Linux [http://projects.gctronic.com/epuck2/Eclipse_e-puck2/Eclipse_e-puck2_Linux_11_apr_2018_32bits.tar.gz 32bits] / [http://projects.gctronic.com/epuck2//Eclipse_e-puck2/Eclipse_e-puck2_Linux_11_apr_2018_64bits.tar.gz 64bits]. Pay attention to the 32bits or 64bits version. If unsure which Linux version you have, enter the following comand <code>uname -a</code> in the terminal window and look for i686 (32bit) or x86_64 (64 bit)
| 8 x Prox (16)
#Extract the downloaded file to the location you want (can take time).
| 8 x Ambient (16)
#You can now run the <code>Eclipse_e-puck2</code> executable to launch Eclipse.
| 4 x Mic (8)
| Selector + button (1)  
| Left steps (2)  
| Right steps (2)
| TV remote (1)
| Checksum
|}
* Selector + button: selector values represented by 4 least significant bits (bit0, bit1, bit2, bit3); button state is in bit4 (1=pressed, 0=not pressed)
* Checksum: Longitudinal Redundancy Check (XOR of the bytes 0..45)


:<span class="plain links">[http://projects.gctronic.com/epuck2/wiki_images/Eclipse_e-puck2_Folder_Linux.png <img width=800 src="http://projects.gctronic.com/epuck2/wiki_images/Eclipse_e-puck2_Folder_Linux.png">]</span><br/>
==Communicate with the IMU==
:''Eclipse_e-puck2 folder obtained after extraction''
===e-puck1===
An example written in C showing how to read data from the IMU (LSM330) mounted on e-puck 1.3 is available in the Pi-puck repository; you can find it in the directory <code>/home/pi/Pi-puck/e-puck1/</code>.<br/>
You can build the program with the command <code>gcc e-puck1_imu.c -o e-puck1_imu</code>.<br/>
Now you can run the program by issueing <code>./e-puck1_imu</code> and then choose whether to get data from the accelerometer or gyroscope; this demo will print the sensors data on the terminal.<br/>


Note : The icon of the Eclipse_e-puck2 executable will appear after the first launch of the program.
===e-puck2===
An example showing how to read data from the IMU (MPU-9250) is available in the Pi-puck repository; you can find it in the directory <code>/home/pi/Pi-puck/e-puck2/</code>.<br/>
You can build the program with the command <code>gcc e-puck2_imu.c -o e-puck2_imu</code>.<br/>
Now you can run the program by issueing <code>./e-puck2_imu</code> and then choose whether to get data from the accelerometer or gyroscope; this demo will print the sensors data on the terminal.<br/>
The same example is also available in Python, you can run it by issueing <code>python3 e-puck2_imu.py</code>.


'''Important things to avoid :'''
==Communicate with the ToF sensor==
:1. You cannot create a Link to the Eclipse_e-puck2 executable because otherwise the program will think its location is where the Link is and it will not find the resource located in the Eclipse_e-puck2 folder.
The Time of Flight sensor is available only on the e-puck2 robot.<br/>
:2. The path to the Eclipse_e-puck2 folder must contain zero space.  
::Example :
::<code>/home/student/epfl_stuff/Eclipse_e-puck2</code> OK
::<code>/home/student/epfl stuff/Eclipse_e-puck2</code> NOT OK
:3. The file’s structure in the Eclipse_e-puck2 folder must remain the same. It means no file inside this folder must be moved to another place.


===Serial Port===
First of all you need to verify that the VL53L0X Python package is installed with the following command: <code>python3 -c "import VL53L0X"</code>. If the command returns nothing you're ready to go, otherwise if you receive an <code>ImportError</code> then you need to install the package with the command: <code>pip3 install git+https://github.com/gctronic/VL53L0X_rasp_python</code>.<br/>
In order to let Eclipse (or any program ran by you) to access the serial ports, a little configuration is needed.


Type the following command in a terminal session. Once done, you need to log off to let the change take effect.
A Python example showing how to read data from the ToF sensor is available in the Pi-puck repository; you can find it in the directory <code>/home/pi/Pi-puck/e-puck2/</code>.<br/>
You can run the example by issueing <code>python3 VL53L0X_example.py</code> (this is the example that you can find in the repository [https://github.com/gctronic/VL53L0X_rasp_python/tree/master/python https://github.com/gctronic/VL53L0X_rasp_python/tree/master/python]).


<pre>sudo adduser $USER dialout</pre>
==Capture an image==
The robot camera is connected to the Pi-puck extension as a USB camera, so you can access it very easily.<br/>
An example showing how to capture an image from the robot's camera using OpenCV is available in the Pi-puck repository; you can find it in the directory <code>/home/pi/Pi-puck/snapshot/</code>.<br/>
You can build the program with the command <code>g++ $(pkg-config --libs --cflags opencv) -ljpeg -o snapshot snapshot.cpp</code>.<br/>
Now you can run the program by issueing <code>./snapshot</code>; this will save a VGA image (JPEG) named <code>image01.jpg</code> to disk.<br/>
The program can accept the following parameters:<br/>
<code>-d DEVICE_ID</code> to specify the input video device from which to capture an image, by default is <code>0</code> (<code>/dev/video0</code>). This is useful when working also with the [http://www.gctronic.com/doc/index.php?title=Omnivision_Module_V3 Omnivision V3] extension that crates another video device; in this case you need to specify <code>-d 1</code> to capture from the robot camera.<br/>
<code>-n NUM</code> to specify how many images to capture (1-99), by default is 1<br/>
<code>-v</code> to enable verbose mode (print some debug information)<br/>
Beware that in this demo the acquisition rate is fixed to 5 Hz, but the camera supports up to '''15 FPS'''.<br/>
The same example is also available in Python, you can run it by issueing <code>python snapshot.py</code>.


==Installation for Mac==
==Communicate with the ground sensors extension==
===Command Line Tools ===
Both e-puck1 and e-puck2 support the [https://www.gctronic.com/doc/index.php?title=Others_Extensions#Ground_sensors ground sensors extension].<br/>
To compile on Mac with Eclipse_e-puck2, it is necessary to have the Command Line Tools installed. It is a bundle of many commonly used tools.<br>
This extension is attached to the I2C bus and can be read directly from the Pi-puck.<br/>
You can install it by typing the following command in a terminal window. It will then open a popup asking you if you want to install this bundle. Otherwise it will tell you it is already installed.
An example written in C showing how to read data from the ground sensors extension is available in the Pi-puck repository; you can find it in the directory <code>/home/pi/Pi-puck/ground-sensor/</code>.<br/>
<pre>xcode-select --install</pre>
You can build the program with the command <code>gcc groundsensor.c -o groundsensor</code>.<br/>
Now you can run the program by issueing <code>./groundsensor</code>; this demo will print the sensors data on the terminal.<br/>
The same example is also available in Python, you can run it by issueing <code>python3 groundsensor.py</code>.


===Java 8===
==Communicate with the range and bearing extension==
This section can be ignored if Java is already installed on your computer.<br>
Both e-puck1 and e-puck2 support the [https://www.gctronic.com/doc/index.php?title=Others_Extensions#Range_and_bearing range and bearing extension].<br/>
To verify whether it is installed or not you can type the following command into a terminal window. It will list all the Java runtimes installed on your Mac.
This extension is attached to the I2C bus and can be read directly from the Pi-puck.<br/>
<pre>/usr/libexec/java_home -V</pre>
An example written in C showing how to start playing with the range and bearing extension is available in the Pi-puck repository; you can find it in the directory <code>/home/pi/Pi-puck/randb/</code>. You need two boards: one is the transmitter (run <code>randb_tx</code>) and the other is the receiver (run <code>randb_rx</code>). The receiver will print the data received from the transmitter.<br/>
You need to have <code>Java SE 8</code> listed to be able to run Eclipse_e-puck2.
You can build the programs with the command <code>gcc randb_tx.c -o randb_tx</code> and <code>gcc randb_rx.c -o randb_rx</code>.<br/>
The same example is also available in Python, you can run it by issueing <code>python3 randb_tx.py</code> and <code>python3 randb_rx.py</code>.


:1. Go to the [http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html Java download page] and download the <code>Mac OS X Java 8 SE Development Kit</code>. It is the .dmg file without the Demos and Samples.  
==Wireless remote control==
::For example: <code>jdk-8uXXX-macosx-x64.dmg</code>
If you want to control the robot from a computer, for instance when you have an algorithm that requires heavy processing not suitable for the Pi-puck or when the computer acts as a master controlling a fleet of robots that return some information to the controller, then you have 3 options:<br/>
:2. Open the .dmg file downloaded, run the installer and follow the instructions to proceed with the installation of Java SDK.
1) The computer establishes a WiFi connection with the Pi-puck to receive data processed by the Pi-puck (e.g. results of an image processing task); at the same time the computer establishes a Bluetooth connection directly with the e-puck2 robot to control it.
:''Disadvantages'':
:- the Bluetooth standard only allow up to seven simultaneous connections
:- doubled latency (Pi-puck <-> pc and pc <-> robot)
2) The computer establishes a WiFi connection with both the Pi-puck and the e-puck2 robot.
:''Advantages'':
:- only one connection type needed, easier to handle
:''Disadvantages'':
:- doubled latency (Pi-puck <-> pc and pc <-> robot)
3) The computer establishes a WiFi connection with the Pi-puck and then the Pi-puck is in charge of controlling the robot via I2C based on the data received from the computer controller.
:''Advantages'':
:- less latency involved
:- less number of connections to handle
:- depending on your algorithm, it would be possible to initially develop the controller on the computer (easier to develop and debug) and then transfer the controller directly to the Pi-puck without the need to change anything related to the control of the robot via I2C


:<span class="plain links">[http://projects.gctronic.com/epuck2/wiki_images/Java_mac.png <img width=500 src="http://projects.gctronic.com/epuck2/wiki_images/Java_mac.png">]</span><br/>
The following figure summarizes these 3 options:<br/>
:''Java download page''
<span class="plainlinks">[https://projects.gctronic.com/epuck2/wiki_images/wireless-remote-control-options.png <img width=600 src="https://projects.gctronic.com/epuck2/wiki_images/wireless-remote-control-options.png">]</span>


===Eclipse_e-puck2===
=How to work with the Pi-puck=
:1. Download the [http://projects.gctronic.com/epuck2/Eclipse_e-puck2/Eclipse_e-puck2_Mac_11_apr_2018.dmg Eclipse_e-puck2 package for Mac].
==Demos and scripts update==
:2. Open the .dmg file downloaded and DragAndDrop the Eclipse_e-puck2.app into the Applications folder
First of all you should update to the last version of the demos and scripts released with the system that you can use to start playing with the Pi-puck extension and the robot.<br/>
::Note : You can place the Eclipse_e-puck2.app anywhere, as long as the full path to it doesn’t contain any space, if you don’t want it to be in Applications.
To update the repository follow these steps:<br/>
:3. You can create an Alias to Eclipse_e-puck2.app and place it anywhere if you want.
1. go to the directory <code>/home/pi/Pi-puck</code><br/>
2. issue the command <code>git pull</code><br/>
Then to update some configurations of the system:<br/>
1. go to the directory <code>/home/pi/Pi-puck/system</code><br/>
2. issue the command <code>./update.sh</code>; the system will reboot.<br/>
You can find the Pi-puck repository here [https://github.com/gctronic/Pi-puck https://github.com/gctronic/Pi-puck].<br/>


===First launch and Gatekeeper===
==Audio recording==
It’s very likely that Gatekeeper (one of the protections of Mac OS) will prevent you to launch Eclipse_e-puck2.app because it isn’t signed from a known developer.<br>
Use the <code>arecord</code> utility to record audio from the onboard microphone. The following example shows how to record an audio of 2 seconds (<code>-d</code> parameter) and save it to a wav file (<code>test.wav</code>):<br/>
If you can’t run the program because of a warning of the system, press <code>OK</code> and try to launch it by right clicking on it and choosing <code>open</code> in the contextual menu (may be slow to open the first time).<br>
<code>arecord -Dmic_mono -c1 -r16000 -fS32_LE -twav -d2 test.wav</code><br/>
If <code>Unable to open "Eclipse_e-puck2.app" because this app comes from an unidentified developer.</code> or if <code>"Eclipse.app" is corrupted and cannot be opened. You should place this item in the Trash.</code> appears after executing the app the first time, it is needed to disable temporarily Gatekeeper.
You can also specify a rate of 48 KHz with <code>-r48000</code>


To do so :
==Audio play==
Use <code>aplay</code> to play <code>wav</code> files and <code>mplayer</code> to play <code>mp3</code> files.


:1. Go to <code>System Preferences->security and privacy->General</code> and authorize downloaded application from <code>Anywhere</code>.
==Battery reading==
An example showing how to measure both the battery of the robot and the battery of the Pi-puck extension is available in the Pi-puck repository; you can find it in the directory <code>/home/pi/Pi-puck/battery/</code>.<br/>
The first time you need to change the mode of the script in order to be executable with the command <code>sudo chmod +x read-battery.sh</code>.<br/>
Then you can start reading the batteries value by issueing <code>./read-battery.sh</code>.; this demo will print the batteries values (given in Volts) on the terminal.


::<span class="plain links">[http://projects.gctronic.com/epuck2/wiki_images/security_tab_mac.png <img width=500 src="http://projects.gctronic.com/epuck2/wiki_images/security_tab_mac.png">]</span><br/>
==WiFi configuration==
::''Security settings of Mac OS''
Specify your network configuration in the file <code>/etc/wpa_supplicant/wpa_supplicant-wlan0.conf</code>.<br/>
 
Example:<br/>
::If you are on Mac OS Sierra or greater (greater or equal to Mac OS 10.12), you must type the following command on the terminal to make the option above appear.
<pre>
::<pre>sudo spctl --master-disable</pre>
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
:2. Now you can try to run the application and it should work.
update_config=1
:3. If Eclipse opened successfully, it is time to reactivate Gatekeeper. Simply set back the setting of Gatekeeper.
country=CH
::For the ones who needed to type a command to disable Gatekeeper, here is the command to reactivate it.
network={
::<pre>sudo spctl --master-enable</pre>
        ssid="MySSID"
 
        psk="9h74as3xWfjd"
This procedure is only needed the first time. After that Gatekeeper will remember your choice to let run this application and will not bother you anymore, as long as you use this application. If you re-download it, you will have to redo the procedure for Gatekeeper.
}
</pre>
You can have more than one <code>network</code> parameter to support more networks. For more information about ''wpa_supplicant'' refer to [https://hostap.epitest.fi/wpa_supplicant/ https://hostap.epitest.fi/wpa_supplicant/].


'''Important things to avoid :'''
Once the configuration is done, you can also connect to the Pi-puck with <code>SSH</code>. If you are working in Windows you can use [https://www.putty.org/ PuTTY].
:1. The path to the Eclipse_e-puck2.app must contain zero space.
::Example :
::<code>/home/student/epfl_stuff/Eclipse_e-puck2</code> OK
::<code>/home/student/epfl stuff/Eclipse_e-puck2</code> NOT OK
:2. The file’s structure in the Eclipse_e-puck2.app must remain the same. It means no file inside this app must be moved to another place.


=Getting Started=
===How to know your IP address===
===Meaning of the LEDs===
A simple method to know your IP address is to connect the USB cable to the Pi-puck extension and issue the command <code>ip a</code>; from the command's result you will be able to get you current assigned IP address.
The e-puck2 has three groups of LEDs that are not controllable by the user.


::<span class="plain links">[http://projects.gctronic.com/epuck2/wiki_images/e-puck2_top_leds.png <img width=500 src="http://projects.gctronic.com/epuck2/wiki_images/e-puck2_top_leds.png">]</span><br/>
If you prefer to know your IP address remotely (without connecting any cable) then you can use <code>nmap</code>.<br/>
::''Top view of the e-puck2''
For example you can search all connected devices in your network with the following command: <code>nmap 192.168.1.*</code>. Beware that you need to specify the subnet based on your network configuration.<br/>
From the command's result you need to look for the hostname <code>raspberrypi</code>.<br/>
If you are working in Windows you can use the [https://nmap.org/zenmap/ Zenmap] application.


*Charger : RED if charging, GREEN if charge complete and RED and GREEN if an error occurs
==File transfer==
*USB : Turned ON if the e-puck2 detects a USB connection with a computer
===USB cable===
*STATUS : Turned ON if the robot is ON and OFF is the robot is OFF. When ON, gives an indication of the level of the battery. Also blinks GREEN if the program is running during a debug session.
You can transfer files via USB cable between the computer and the Pi-puck extension by using on of the <code>zmodem</code> protocol.<br/>
The <code>lrzsz</code> package is pre-installed in the system, thus you can use the <code>sx</code> and <code>rx</code> utilities to respectevely send files to the computer and receive files from the computer.<br/>
Example of sending a file to the computer using the <code>Minicom</code> terminal program:<br/>
1. in the Pi-puck console type <code>sx --zmodem fliename.ext</code>. The transfer should start automatically and you'll find the file in the home directory.<br/>
<!--2. to start the transfer type the sequence <code>CTRL+A+R</code>, then chose <code>xmodem</code> and finally enter the name you want to assign to the received file. You'll find the file in the home directory.<br/>-->
Example of receiving a file from the computer using the <code>Minicom</code> terminal program:<br/>
1. in the Pi-puck console type <code>rx -Z</code><br/>
2. to start the transfer type the sequence <code>CTRL+A+S</code>, then chose <code>zmodem</code> and select the file you want to send with the <code>spacebar</code>. Finally press <code>enter</code> to start the transfer.<br/>
===WiFi===
The Pi-puck extension supports <code>SSH</code> connections.<br/>
To exchange files between the Pi-puck and the computer, the <code>scp</code> tool (secure copy) can be used. An example of transferring a file from the Pi-puck to the computer is the following:<br/>
<code>scp pi@192.168.1.20:/home/pi/example.txt example.txt</code>


Battery level indications (STATUS RGB LED):
If you are working in Windows you can use [https://www.putty.org/ PuTTY].
*GREEN if the system's tension is greater than 3.5V
*ORANGE if the system's tension is between 3.5V and 3.4V
*RED if the system's tension is between 3.4V and 3.3V
*RED blinking if the system's tension is below 3.3V


The robot is automatically turned OFF if the system's tension gets below 3.2V during 10 seconds.
==Image streaming==


==Finding the USB serial ports used==
Two ports are created by the e-puck2's programmer when the USB cable is connected to the robot (even if the robot is turned off):
* '''e-puck2 GDB Server'''. The port used to program and debug the e-puck2 with Eclipse_e-puck2 (GDB).
* '''e-puck2 Serial Monitor'''. A serial monitor. [[#see dedicated chapter(not yet ready)]]


A third port could be available depending on the code inside the e-puck2's microcontroller. With the standard firmware a port named '''e-puck2 STM32F407''' is created.
==Bluetooth LE==
===Windows===
An example of a ''BLE uart service'' is available in the Pi-puck repository; you can find it in the directory <code>/home/pi/Pi-puck/ble/</code>.<br/>
#Open the Device Manager
To start the service you need to type: <code>python uart_peripheral.py</code>.<br/>
#Under '''Ports (COM & LPT)''' you can see the virtual ports connected to your computer.
Then you can use the ''e-puck2-android-ble app'' you can find in chapter [https://www.gctronic.com/doc/index.php?title=e-puck2_mobile_phone_development#Connecting_to_the_BLE Connecting to the BLE] in order to connect to the Pi-puck extension via BLE. Once connected you'll receive some dummy data for the proximity values and by clicking on the motion buttons you'll see the related action printed on the Pi-puck side. This is a starting point that you can extend based on your needs.
#Do a '''Right-click -> properties''' on the COM port you want to identify.
#Go under the '''details''' tab and select '''Bus reported device description''' in the properties list.
#The name of the port should be written in the text box below.
#Once you found the desired device, you can simply look at its port number '''(COMX)'''.


===Linux===
=Operating system=
:1. Open a terminal window (ctrl+alt+t) and enter the following command.
The system is based on Raspbian Stretch and can be downloaded from the following link [https://projects.gctronic.com/epuck2/PiPuck/pi-puck-os_16.12.19.zip pi-puck-os_16.12.19.zip].
:<pre>ls /dev/ttyACM*</pre>
:2. Look for '''ttyACM0''' and '''ttyACM1''' in the generated list, which are respectively '''e-puck2 GDB Server''' and '''e-puck2 Serial Monitor'''.
Note : Virtual serial port numbering on Linux is made by the connections order, thus it can be different if another device using virtual serial ports is already connected to your computer.


===Mac===
When booting the first time, the first thing to do is expanding the file system in order to use all the available space on the micro sd:<br/>
:1. Open a terminal window and enter the following command.
1. <code>sudo raspi-config</code><br/>
:<pre>ls /dev/cu.usbmodem*</pre>
2. Select <code>Advanced Options</code> and then <code>Expand Filesystem</code><br/>
:2. Look for two '''cu.usbmodemXXXX''', where XXXX is the number attributed by your computer. You should find two names, more or less following in the numbering, which are respectively '''e-puck2 GDB Server''' and '''e-puck2 Serial Monitor'''.
3. reboot


Note : Virtual serial port numbering on Mac depends on the physical USB port used and the device. If you want to keep the same names, you must connect to the same USB port each time.
==e-puck2 camera configuration==
The e-puck2 camera need to be configured through I2C before it can be used. For this reason a Python script is called at boot that detects and configures the camera. The script resides in the Pi-puck repository installed in the system (<code>/home/pi/Pi-puck/camera-configuration.py</code>), so beware to not remove it.


==Configuring the Debugger's settings==
If the robot is plugged after the boot process is completed, you need to call manually the Python configuration script before using the camera by issueing the command <code>python3 /home/pi/Pi-puck/camera-configuration.py</code>.
Eclipse_e-puck2 contains everything needed to compile, program and debug the e-puck2.<br>
The only settings to configure with a new project are located under the '''Debug Configurations''' tab of Eclipse (you can also find it on '''Run->Debug Configurations''').
:<span class="plain links">[http://projects.gctronic.com/epuck2/wiki_images/Debug_configuration.png <img width=231 src="http://projects.gctronic.com/epuck2/wiki_images/Debug_configuration.png">]</span><br/>
Once in the settings, select '''Generic Blackmagic Probe''' preset on the left panel. Then you need to configure two things :


#If you already have a project, under the '''main''' tab, you need to select which project to debug and the path to the compiled file. If the project has already been compiled, Eclipse must have indexed the binaries and you can list the project and the compiled files using respectively the '''Browse...''' and '''Search Project...''' buttons. If you do not already have a project, add a random name as the title which will act as a place holder, allowing you to apply the next configuration.
In order to automatically run the script at boot, the <code>/etc/rc.local</code> was modified by adding the call to the script just before the end of the file.
#Under the '''Startup''' tab, you need to replace the path to the serial port written on the first line of the text box by the one used by the GDB Server of your e-puck. [[#Finding the USB serial ports used | See how to find it]].
:* For Windows, it will be '''\\.\COMX''', X being the port number.
:* For Linux, it will be '''/dev/ttyACMX''', X being the port number
:* For Mac, it will be '''/dev/cu.usbmodemXXXXX''', XXXXX being the port number.
:* You can also type '''${COM_PORT}''' instead of the com port in order to use the variable COM_PORT for the debug configuration.<br>To change the value of this variable, go to the '''main''' tab again, click on the '''Variables...''' button and click on the '''Edit Variables...''' button. The opened window will let you edit the value of the variable.<br>Using the variable COM_PORT instead of the real com port in a debug configuration is useful if you have multiple debug configurations for example. If for one reason you need to change the com port to use, then you can simply edit the variable COM_PORT instead of editing the com port for each debug configuration


If you want to debug another project, you can change the settings of the '''Generic Blackmagic Probe''' preset or copy it into another preset and configure this one in order to have one preset by project.
==Power button handling==
Now you should be able to use the debugger with Eclipse.
The power button press is handled by a background service (<code>systemd</code>) started automatically at boot. The service description file is located in <code>/etc/systemd/system/power_handling.service</code> and it calls the <code>/home/pi/power-handling/</code> program. Beware to not remove neither of these files.<br/>
The source code of the power button handling program is available in the Pi-puck repository and is located in <code>/home/pi/Pi-puck/power-handling/power-handling.c</code>.


==Creating a project==
==Desktop mode==
===Basic standard project===
The system starts in console mode, to switch to desktop (LXDE) mode issue the command <code>startx</code>.
[https://github.com/e-puck2/e-puck2_main-processor.git e-puck2_main-processor] is the basic standard project containing all the libraries written for the e-puck2. Refer to the [http://www.gctronic.com/doc/index.php?title=e-puck2#Library Library] section to download the complete version.<br>
===Camera viewer===
The basic standard project shows how to use the libraries and can be interfaced with [[#PC interface | e-puck2 monitor]].<br/>
A camera viewer called <code>luvcview</code> is installed in the system. You can open a terminal and issue simply the command <code>luvcview</code> to see the image coming from the robot camera.
This project can be added to Eclipse_e-puck2 by following the next steps:<br>
# Run Eclipse and then select '''File->New->Makefile Project with Existing Code'''.
# Next choose the project folder and set a project name (otherwise you can keep the one created by Eclipse). Choose '''None''' for the the toolchain.
# Click on the '''Finish''' button and the project is added to Eclipse.  


===Project template===
==VNC==
The basic standard project can also be used as a library to build your own project on top of it.<br>
[https://www.realvnc.com/en/ VNC] is a remote control desktop application that lets you connect to the Pi-puck from your computer and then you will see the desktop of the Pi-puck inside a window on your computer. You'll be able to control it as though you were working on the Pi-puck itself.<br/>
VNC is installed in the system and the ''VNC server'' is automatically started at boot, thus you can connect with ''VNC Viewer'' from your computer by knowing the IP address of the Pi-puck (refer to section [https://www.gctronic.com/doc/index.php?title=Pi-puck#How_to_know_your_IP_address How to know your IP address]).<br/>
Notice that the ''VNC server'' is started also in console mode.


To accomplish that, you have to copy the folder '''Project_template''', contained in the e-puck2_main-processor project, where you want to place your project.<br>
==I2C communication==
You can of course rename the folder to the name you want.<br>
The communication between the Pi-puck extension and the robot is based on I2C. The system is configured to exploit the I2C hardware peripheral in order to save CPU usage, but if you need to use the software I2C you can enable it by modifying the <code>/boot/config.txt</code> file and removing the <code>#</code> symbol (comment) in front of the line with the text <code>dtparam=soft_i2c</code> (it is placed towards the end of the file).


The next step is to edit the makefile of your project. Set the name of your project, write the updated path to the e-puck2_main-processor folder, and also rewrite the path to the .c files. Lastly, include the path for any desired .h files from other folders.<br>
==Audio output configuration==
All the .h files located next to the makefile are automatically included in the compilation. But if you need to place them into folders, you have to specify these folders in the makefile.
You can enable or disable audio output by modifying the <code>config.txt</code> file in the <code>boot</code> partition.<br/>
This makefile uses the main makefile of the e-puck2_main-processor project. This means you can add custom commands to the makefile but it should not interfere with the main makefile.
To enable audio output insert the line: <code>gpio=22=op,dh</code><br/>
To disable audio output insert the line: <code>gpio=22=op,dl</code><br/>
If you don't need to play audio files it is suggested to disable audio output in order to save power.


The result of the compilation will appear in a build folder in your project folder.
=ROS=
ROS Kinetic is integrated in the Pi-puck system.<br/>
A ROS node developed to run in the Pi-puck is available for both <code>CPP</code> and <code>Python</code>, the communication system is based on the third architecture shown in chapter [https://www.gctronic.com/doc/index.php?title=Pi-puck#Wireless_remote_control Wireless remote control]; a more detailed schema is shown below:<br/>
<span class="plainlinks">[https://projects.gctronic.com/epuck2/wiki_images/epuck2-ros-schema.png <img width=600 src="https://projects.gctronic.com/epuck2/wiki_images/epuck2-ros-schema.png">]</span>


===Adding to Eclipse_epuck2===
==Initial configuration==
#To add the project into Eclipse, you need to select '''File->New->Makefile Project with Existing Code'''.
The ROS workspace is located in <code>~/rosbots_catkin_ws/</code><br/>
#Next choose your project folder and set a project name. Choose '''None''' for the the toolchain.
The e-puck2 ROS driver is located in <code>~/rosbots_catkin_ws/src/epuck_driver_cpp/</code><br/>
#Click on the '''Finish''' button and the project is added to Eclipse.
Remember to follow the steps in the section [http://www.gctronic.com/doc/index.php?title=Pi-puck#Requirements Requirements ] and section [https://www.gctronic.com/doc/index.php?title=Pi-puck#Demos_and_scripts_update Demos and scripts update], only once.<br/>
#Rename the file '''Debug_project_template.launch''' contained in the project folder by the name you want for the debug configuration of your project.
The PC (if used) and the Pi-puck extension are supposed to be configured in the same network.
#Go to '''Run->Debug Configurations...''' and select on the left your new debug configuration and set the project to debug and the path to the compiled file of the project ([[#Configuring the Debugger's settings |as explained in the chapter before]]). If there is nothing apering when you press '''Search Project...''' then you must enter the '''.elf''' file name by hand, which can be found in your project folder under a folder named '''build'''.
#Go to  '''Project->Properties->C/C++ General->Preprocessor Include Paths, Macros etc->Providers''' and Check '''CDT Cross GCC Built-in Compiler Settings'''.<br> Then in the textbox below, write '''arm-none-eabi-gcc ${FLAGS} -E -P -v -dD "${INPUTS}"'''.
#Create a linked folder inside your project that links to the e-puck2_main-processor library. This allows Eclipse to index the declarations and implementations of the functions and variables in the code of the library.
##Go to '''File->New->Folder'''.
##Check '''Advanced >>''' on the bottom.
##Choose '''Link to alternate location (Linked Folder)'''.
##Type '''PROJECT_LOC''' and then add to this path the path to the e-puck2_main-processor folder. For example '''PROJECT_LOC/../e-puck2_main-processor''' if the library is located as the same level as your project folder.
#Before you compile, make sure the robot is turned on, and in addition make sure that the Makefile, has a capital M in the front.  
#After you compile the project and if it succeeded, select the project root folder and go to '''Project->C/C++ Index->Rebuild''' to rebuild the index. (We need to have compiled at least one time in order to let Eclipse find all the paths to the files used.)


You should now be able to use the project with Eclipse.
==Running roscore==
<code>roscore</code> can be launched either from the PC or directly from the Pi-puck.<br/>
Before starting roscore, open a terminal and issue the following commands:
* <code>export ROS_IP=roscore-ip</code>
* <code>export ROS_MASTER_URI=http://roscore-ip:11311</code>
where <code>roscore-ip</code> is the IP of the machine that runs <code>roscore</code><br/>
Then start <code>roscore</code> by issueing <code>roscore</code>.


==Flashing the main microcontroller==
==Running the ROS node==
In order to update the firmware of the main microcontroller (STM32F407) you can either use Eclipse (as explained in section [http://www.gctronic.com/doc/index.php?title=e-puck2#Configuring_the_Debugger.27s_settings Configuring the Debugger settings]) or you can do it manually as explained in this section. The onboard programmer run a gdb server, so we can use gdb commands to upload a new firmware.<br/>
Before starting the e-puck2 ROS node on the Pi-puck, issue the following commands:
1. download the gdb init file [http://projects.gctronic.com/epuck2/mygdbinit mygdbinit] and place it in the same folder of the compiled firmware. This file has the following content:
* <code>export ROS_IP=pipuck-ip</code>
<pre>target extended-remote \\.\COM72
* <code>export ROS_MASTER_URI=http://roscore-ip:11311</code>
monitor swdp_scan
where <code>pipuck-ip</code> is the IP of the Pi-puck extension and <code>roscore-ip</code> is the IP of the machine that runs <code>roscore</code> (can be the same IP if <code>roscore</code> runs directly on the Pi-puck).
attach 1
set mem inaccessible-by-default off
load</pre>
In this file you need to change the port to reflect the one of the <code>GDB server</code> (see chapter [http://www.gctronic.com/doc/index.php?title=e-puck2#Finding_the_USB_serial_ports_used Finding the USB serial ports used]).


2. issue the following command to start the upload
To start the e-puck2 ROS node issue the command:<br/>
<pre>Windows: arm-none-eabi-gdb.exe --interpreter=mi -x mygdbinit firmware.elf
<code>roslaunch epuck_driver_cpp epuck_minimal.launch debug_en:=true ros_rate:=20</code><br/>
Linux/Mac: arm-none-eabi-gdb --interpreter=mi -x mygdbinit firmware.elf</pre>
<!--
In this command you need to change the name of the firmware with the one you have.<br/>
To start the e-puck2 ROS node issue the command:<br/>
Moreover if the <code>PATH</code> variable is not set (see chapter [http://www.gctronic.com/doc/index.php?title=e-puck2#Configuring_the_PATH_variable Configuring the PATH variable]) you need to insert the absolute path to the debugger that you can find in the Eclipse package (see chapter [http://www.gctronic.com/doc/index.php?title=e-puck2#Installation_of_the_e-puck2_environment Installation of the e-puck2 environment]) inside the directory <code>Tools\gcc-arm-none-eabi-XXX\bin</code>.
<code>roslaunch epuck_driver_cpp epuck_controller.launch epuck_id:='3000'</code><br/>
This launch file will start the e-puck2 node and the camera node.
If you are using a PC, then you can start <code>rviz</code>:
* in a terminal issue the command <code>rviz rviz</code>
* open the configuration file named <code>single_epuck_driver_rviz.rviz</code> you can find in <code>epuck_driver_cpp/config/</code> directory
-->


When the upload is complete you'll see an output like in the following figure:<br/>
The following graph shows all the topics published by the e-puck2 driver node:<br/>
<span class="plain links">[http://projects.gctronic.com/epuck2/wiki_images/f407-flashing.png <img width=400 src="http://projects.gctronic.com/epuck2/wiki_images/f407-flashing.png">]</span><br/>
<span class="plainlinks">[https://projects.gctronic.com/epuck2/wiki_images/ros-e-puck2_.jpg <img width=150 src="https://projects.gctronic.com/epuck2/wiki_images/ros-e-puck2_small.jpg">]</span>
The final line should contain <code>".data",</code> , and it should all be enclosed at the end with <code>(gdb)</code>. You can then close the terminal window.
''<font size="2">Click to enlarge</font>''


If you encounter some problem, try to unplug and plug again the USB cable and power cycle the robot, then retry.
==Test the communication==
You can test if the communication between the robot and the computer is actually working by simply display messages published by a topic, e.g.:
<code>rostopic echo /proximity0</code>
You can have the list of all the topic by issueing the command: <code>rostopic list</code>.


==Flashing the radio module==
==Get the source code==
In order to update the firmware of the ESP32 WiFi module you need to use a python script called <code>esptool</code> provided by Espressif (manufacturer of the chip). This script was modified to work with the e-puck2 robot and is available from the following link:
The last version of the e-puck2 ROS node can be downloaded from the git: <code>git clone -b pi-puck https://github.com/gctronic/epuck_driver_cpp.git</code><br/>
* Windows: [http://projects.gctronic.com/epuck2/esptool.exe esptool.exe]; Python not required on the system.
* Linux/Mac: [http://projects.gctronic.com/epuck2/esptool.py esptool.py]; Python 3.4 and pySerial 2.5 need to be installed on the system.
Place the script in the same folder as the firmware (composed by 3 bin files: <code>bootloader.bin</code>, <code>ESP32_E-Puck_2.bin</code> and <code>partitions_singleapp.bin</code>) and then issue the following command:
* Windows:
<pre>esptool.exe --chip esp32 --port COM96 --baud 230400 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 bootloader.bin 0x10000 ESP32_E-Puck_2.bin 0x8000 partitions_singleapp.bin</pre>
Alternatively you can download the following batch file [http://projects.gctronic.com/epuck2/esp32-flashing.bat esp32-flashing.bat]
*Linux/Mac:
<pre>python esptool.py --chip esp32 --port COM96 --baud 230400 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 bootloader.bin 0x10000 ESP32_E-Puck_2.bin 0x8000 partitions_singleapp.bin</pre>
In all cases you need to specify the correct port (with <code>--port</code> parameter) that is the one labeled <code>Serial monitor</code> (see chapter [http://www.gctronic.com/doc/index.php?title=e-puck2#Finding_the_USB_serial_ports_used Finding the USB serial ports used]).


The upload should last about 10-15 seconds and you'll see the progress as shown in the following figure:<br/>
To update to the last version follow these steps:
<span class="plain links">[http://projects.gctronic.com/epuck2/wiki_images/esp32-flashing1.png <img width=400 src="http://projects.gctronic.com/epuck2/wiki_images/esp32-flashing1.png">]</span><br/>
# <code>cd ~/rosbots_catkin_ws/src/</code>
When the upload is complete you'll see that all 3 bin files are uploaded correctly as shown in the following figure:<br/>
# <code>rm -R -f epuck_driver_cpp</code>
<span class="plain links">[http://projects.gctronic.com/epuck2/wiki_images/esp32-flashing2.png <img width=400 src="http://projects.gctronic.com/epuck2/wiki_images/esp32-flashing2.png">]</span><br/>
# <code>git clone -b pi-puck https://github.com/gctronic/epuck_driver_cpp.git</code>
# <code>cd ~/rosbots_catkin_ws/</code>
# <code>catkin_make --only-pkg-with-deps epuck_driver_cpp</code>


Sometime you could encounter a timeout error as shown in the following figures; in these cases you need to unplug and plug again the USB cable and power cycle the robot, then you can retry.<br/>
==Python version==
<span class="plain links">[http://projects.gctronic.com/epuck2/wiki_images/esp32-flashing3.png <img width=400 src="http://projects.gctronic.com/epuck2/wiki_images/esp32-flashing3.png">]</span>
A Python version developed by the York University can be found here [https://github.com/yorkrobotlab/pi-puck-ros https://github.com/yorkrobotlab/pi-puck-ros].
<span class="plain links">[http://projects.gctronic.com/epuck2/wiki_images/esp32-flashing4.png <img width=400 src="http://projects.gctronic.com/epuck2/wiki_images/esp32-flashing4.png">]</span><br/>


==Connecting to the Bluetooth==
=OpenCV=
OpenCV 3.4.1 is integrated in the Pi-puck system.


The default firmware in the ESP32, the module which provides Bluetooth and Wi-Fi connectivity, creates 3 Bluetooth channels using the RFcomm protocol:
=York Robotics Lab Expansion Board=
# Channel 1, GDB: port to connect with GDB if the programmer is in mode 1 or 3 (refer to chapter [http://www.gctronic.com/doc/index.php?title=e-puck2#Configuring_the_Programmer.27s_settings Configuring the Programmer's settings] for more information about these modes)
The York Robotics Lab developed an expansion board for the Pi-puck extension that includes: 9-DoF IMU, 5-input navigation switch, RGB LED, XBee socket, 24-pin Raspberry Pi compatible header. For more information have a look at [https://pi-puck.readthedocs.io/en/latest/extensions/yrl-expansion/ https://pi-puck.readthedocs.io/en/latest/extensions/yrl-expansion/].<br/>
# Channel 2, UART: port to connect to the UART port of the main processor
<span class="plainlinks">[https://projects.gctronic.com/epuck2/wiki_images/yrl-expansion-top.jpg <img width=350 src="https://projects.gctronic.com/epuck2/wiki_images/yrl-expansion-top.jpg">]</span><br/>
# Channel 3, SPI: port to connect to the SPI port of the main processor (not yet implemented. Just do an echo for now)


By default, the e-puck2 is not visible when you search for it in the Bluetooth utility of your computer.<br>
An example showing how to communicate with the YRL expansion board is available in the Pi-puck repository of the York Robotics Lab:
'''To make it visible, it is necessary to hold the USER button (also labeled "esp32" on the electronic board) while turning on the robot with the ON/OFF button.'''<br>
# <code> git clone https://github.com/yorkrobotlab/pi-puck.git pi-puck_yrl</code>
Then it will be discoverable and you will be able to pair with it.<br>
# <code>cd pi-puck_yrl/python-library</code>
Note that a prompt could ask you to confirm that the number written on the screen is the same on the e-puck. just ignore this and accept. Otherwise if you are asked for a pin insert 0000.
# <code>python3 pipuck-library-test.py -x</code> Once started, press in sequence up, down, left, right, center to continue the demo.


===Windows 7===
==Assembly==
When you pair your computer with the e-puck2, 3 COM ports will be automatically created.
The assembly is very simple: place the YRL expansion board on top of the Raspberry Pi and then connect them with the provided screws. Once they are connected, you can attach both on top of the Pi-puck extension.<br/>
To see which COM port corresponds to which channel you need to open the properties of the paired e-puck2 robot from <code>Bluetooth devices</code>. Then the ports and related channels are listed in the <code>Services</code> tab, as shown in the following figure:<br/>
<span class="plainlinks">[https://projects.gctronic.com/epuck2/wiki_images/yrl-exp1.jpg <img width=200 src="https://projects.gctronic.com/epuck2/wiki_images/yrl-exp1.jpg">]</span>
<span class="plain links">[http://projects.gctronic.com/epuck2/wiki_images/BT-connection-win7.png <img width=300 src="http://projects.gctronic.com/epuck2/wiki_images/BT-connection-win7.png">]</span>
<span class="plainlinks">[https://projects.gctronic.com/epuck2/wiki_images/yrl-exp2.jpg <img width=150 src="https://projects.gctronic.com/epuck2/wiki_images/yrl-exp2.jpg">]</span>
<span class="plainlinks">[https://projects.gctronic.com/epuck2/wiki_images/yrl-exp3.jpg <img width=200 src="https://projects.gctronic.com/epuck2/wiki_images/yrl-exp3.jpg">]</span><br/>
==XBee==
In this section it is explained how to send data from the Pi-puck to the computer using XBee modules Series 1.


===Windows 10===
The XBee module mounted on the YRL expansion must be programmed with the <code>XBEE 802.15.4-USB ADAPTER</code> firmware; this can be done with the [http://www.digi.com/products/wireless-wired-embedded-solutions/zigbee-rf-modules/xctu XTCU software]. With XTCU be sure to program also the same parameters on both modules in order to be able to communicate between each other: <code>Channel</code> (e.g. <code>C</code>), <code>PAN ID</code> (e.g. <code>3332</code>), <code>DH = 0</code>, <code>DL = 0</code>, <code>MY = 0</code>.
When you pair your computer with the e-puck2, 6 COM ports will be automatically created. The three ports you will use have <code>Outgoing</code> direction and are named <code>e_puck2_xxxxx-GDB</code>, <code>e_puck2_xxxxx-UART</code>, <code>e_puck2_xxxxx-SPI</code>. <code>xxxxx</code> is the ID number of your e-puck2.<br/>
To see which COM port corresponds to which channel you need to:
# open the Bluetooth devices manager
# pair with the robot
# click on <code>More Bluetooth options</code>
# the ports and related channels are listed in the <code>COM Ports</code> tab, as shown in the following figure:<br/>
:<span class="plain links">[http://projects.gctronic.com/epuck2/wiki_images/BT-connection-win10.png <img height=300 src="http://projects.gctronic.com/epuck2/wiki_images/BT-connection-win10.png">]</span>


===Linux===
Some Python examples ara available in the [https://github.com/yorkrobotlab/pi-puck-expansion-board YRL Expansion Board GitHub repository] that can be used to communicate with the XBee module mounted on the YRL expansion. These examples are based on the [https://github.com/digidotcom/xbee-python Digi XBee Python library] that can be installed with the command <code>pip3 install digi-xbee</code>. This library requires the XBee module to be configured in API mode; you can setup this mode following these steps:
Once paired with the Bluetooth manager, you need to create the port for communicating with the robot by issueing the command: <br/>
# <code> git clone https://github.com/yorkrobotlab/pi-puck-expansion-board.git</code>
<code>sudo rfcomm bind /dev/rfcomm0 MAC_ADDR 2</code><br/>
# <code>cd pi-puck-expansion-board/xbee</code>
The MAC address is visible from the Bluetooth manager. The parameter <code>2</code> indicates the channel, in this case a port for the <code>UART</code> channel is created. If you want to connect to another service you need to change this parameter accordingly (e.g. <code>1</code> for <code>GDB</code> and <code>3</code> for <code>SPI</code>). Now you can use <code>/dev/rfcomm0</code> to connect to the robot.
# <code>python3 xbee-enable-api-mode.py</code>


===Mac===
Now connect the second module to the computer and run XTCU, select the console view and open the serial connection. Then run the [https://projects.gctronic.com/epuck2/PiPuck/xbee-send-broadcast.py xbee-send-broadcast.py] example from the Pi-puck by issuing the command: <code>python3 xbee-send-broadcast.py</code>. From the XTCU console you should receive <code>Hello Xbee World!</code>.
When you pair your computer with the e-puck2, 3 COM ports will be automatically created: <code>/dev/cu.e-puck2_xxxxx-GDB</code>, <code>/dev/cu.e-puck2_xxxxx-UART</code> and <code>/dev/cu.e-puck2_xxxxx-SPI</code>. xxxxx is the ID number of your e-puck2.


==Connecting to the WiFi==
For more information refer to [https://pi-puck.readthedocs.io/en/latest/extensions/yrl-expansion/xbee/ https://pi-puck.readthedocs.io/en/latest/extensions/yrl-expansion/xbee/].
At the moment the WiFi channel is used to transfer the image to the computer (a QQVGA color image is transferred) together with the sensors values (magnetometer, selector and tv remote not supported at the moment). The robot is also able to receive commands from the computer (only motors and red LEDs are supported at the moment).<br/>
A dedicated configuration is needed to use the WiFi, thus the robot and WiFi module firmwares need to be updated; moreover a PC application is provided to receive the data from the robot and send commands to it:
# [http://projects.gctronic.com/epuck2/e-puck2_main-processor_wifi_97d247f.elf main processor firmware] (see chapter [http://www.gctronic.com/doc/index.php?title=e-puck2#Flashing_the_main_microcontroller Flashing the main microcontroller]to update the firmware); put the selector in position 15. If you are interested to the source code, refer to chapter [http://www.gctronic.com/doc/index.php?title=e-puck2#WiFi_support_2 Main microcontroller - WiFi support].
# [http://projects.gctronic.com/epuck2/esp32-firmware-wifi-d4ff7b4.zip WiFi module firmware] (see chapter [http://www.gctronic.com/doc/index.php?title=e-puck2#Flashing_the_radio_module Flashing the radio module] to update the firmware). If you are interested to the source code, refer to chapter [http://www.gctronic.com/doc/index.php?title=e-puck2#WiFi_support_3 Radio module - WiFi support].
# PC application: [http://projects.gctronic.com/epuck2/monitor-wifi_e9cf9f9.zip Monitor WiFi]. If you are interested to the source code, refer to chapter [http://www.gctronic.com/doc/index.php?title=e-puck2#WiFi_support PC interface - WiFi support].


The LED2 is used to indicate the state of the WiFi connection:
=Time-of-Flight Distance Sensor add-on=
* red indicates that the robot is in ''access point mode'' (waiting for configuration)
The Pi-puck extension integrates six sensor board sockets that can be used to add up to six VL53L1X-based distance sensor add-ons. The Pi-puck equipped with these add-ons is shown in the following figure:<br/>
* green indicates that the robot is connected to a network and has received an IP address
<span class="plainlinks">[https://projects.gctronic.com/epuck2/wiki_images/pi-puck-tof.jpg <img width=250 src="https://projects.gctronic.com/epuck2/wiki_images/pi-puck-tof.jpg">]</span><br/>
* blue (toggling) indicates that the robot is transferring the image to the computer
For more information have a look at [https://pi-puck.readthedocs.io/en/latest/extensions/tof-sensor/#time-of-flight-distance-sensor https://pi-puck.readthedocs.io/en/latest/extensions/tof-sensor/#time-of-flight-distance-sensor].


===Network configuration===
<font style="color:red"> Beware that once the socket for the ToF add-on sensor '''3''' is soldered on the pi-puck extension, you are no more able to connect the HDMI cable.</font>
If there is no WiFi configuration saved in flash, then the robot will be in ''access point mode'' in order to let the user connect to it and setup a WiFi connection. The LED2 is red.  


The access point SSID will be <code>e-puck2_0XXXX</code> where <code>XXXX</code> is the id of the robot; the password to connect to the access point is <code>e-puck2robot</code>.<br/>
==Communicate with the ToF sensors==
You can use a phone, a tablet or a computer to connect to the robot's WiFi and then you need to open a browser and insert the address <code>192.168.1.1</code>. The available networks are scanned automatically and listed in the browser page as shown in ''figure 1''. Choose the WiFi signal you want the robot to establish a conection with from the web generated list, and enter the related password; if the password is correct you'll get a message saying that the connection is established as shown in ''figure 2''. After pressing <code>OK</code> you will be redirected to the main page showing the network to which you're connected and the others available nearby as shown in ''figure 3''. If you press on the connected network, then you can see your IP address as shown in ''figure 4''; take note of the address since it will be needed later.<br/>
In order to communicate with the sensors you can use the <code>multiple-i2c-bus-support</code> branch of the [https://github.com/pimoroni/vl53l1x-python vl53l1x-python] library from [https://shop.pimoroni.com/ Pimoroni]. To install this library follow these steps:
# <code>git clone -b multiple-i2c-bus-support https://github.com/pimoroni/vl53l1x-python.git</code>
# <code>cd vl53l1x-python</code>
# <code>sudo python3 setup.py install</code>


<span class="plainlinks">
A Python example showing how to read data from the ToF sensors is available in the Pi-puck repository of the York Robotics Lab:
<table>
# <code> git clone https://github.com/yorkrobotlab/pi-puck.git pi-puck_yrl</code>
<tr>
# <code>cd pi-puck_yrl/python-library</code>
<td align="center">[1]</td>
# <code>python3 pipuck-library-test.py -t</code>
<td align="center">[2]</td>
<td align="center">[3]</td>
<td align="center">[4]</td>
</tr>
<tr>
<td>[http://projects.gctronic.com/epuck2/wiki_images/esp32-wifi-setup1.png <img width=150 src="http://projects.gctronic.com/epuck2/wiki_images/esp32-wifi-setup1.png">]</td>
<td>[http://projects.gctronic.com/epuck2/wiki_images/esp32-wifi-setup2.png <img width=150 src="http://projects.gctronic.com/epuck2/wiki_images/esp32-wifi-setup2.png">]</td>
<td>[http://projects.gctronic.com/epuck2/wiki_images/esp32-wifi-setup3.png <img width=150 src="http://projects.gctronic.com/epuck2/wiki_images/esp32-wifi-setup3.png">]</td>
<td>[http://projects.gctronic.com/epuck2/wiki_images/esp32-wifi-setup4.png <img width=150 src="http://projects.gctronic.com/epuck2/wiki_images/esp32-wifi-setup4.png">]</td>
</tr>
</table>
</span><br/>
Now the configuration is saved in flash, this means that when the robot is turned on it will read this configuration and try to establish a connection automatically.<br/>
Remember that you need to power cycle the robot at least once for the new configuration to be active.<br/>
 
Once the connection is established, the LED2 will be green.<br/>
 
In order to reset the current configuration you need to press the user button for 2 seconds (the LED2 red will turn on), then you need to power cycle the robot to enter ''access point mode''.
 
===Receiving the image===
Run the pc application and insert the IP address of the robot. Click on <code>Connect</code> to start receiving the image. The LED2 blue will toggle.<br/>
 
Often the IP address assigned to the robot will remain the same when connecting to the same network, so if you took note of the IP address in section [http://www.gctronic.com/doc/index.php?title=e-puck2#Network_configuration Network configuration] probably you're ready to go. <br/>
Otherwise you need to connect the robot to the computer with the USB cable and open the port labeled <code>Serial Monitor</code> (see chapter [http://www.gctronic.com/doc/index.php?title=e-puck2#Finding_the_USB_serial_ports_used Finding the USB serial ports used]). Then power cycle the robot and the IP address will be shown in the terminal (together with others informations), as illustrated in the following figure:<br/>
<span class="plain links">[http://projects.gctronic.com/epuck2/wiki_images/esp32-wifi-setup5.png <img width=500 src="http://projects.gctronic.com/epuck2/wiki_images/esp32-wifi-setup5.png">]</span>
 
==Configuring the PATH variable==
The PATH variable is a environment variable used to store a list of the paths to the folders containing the executables we can run in a terminal with Windows, Mac and Linux.
 
If you want to use the arm-none-eabi toolchain provided inside the Eclipse_e-puck2 package, you have to add it to the PATH variable to be able to call it inside a terminal window.
 
Setting the PATH variable for Windows :
<pre>set PATH=your_installation_path\Eclipse_e-puck2\Tools\gcc-arm-none-eabi-7-2017-q4-major-win32\bin;%PATH%</pre>
Setting the PATH variable for Linux :
<pre>export PATH=your_installation_path/Eclipse_e-puck2/Tools/gcc-arm-none-eabi-7-2017-q4-major/bin:$PATH</pre>
Setting the PATH variable for Mac :
<pre>export PATH=your_installation_path/Eclipse_e-puck2.app/Contents/Eclipse_e-puck2/Tools/gcc-arm-none-eabi-7-2017-q4-major/bin:$PATH</pre>
 
What is important to know is that this procedure is temporary. It applies only to the terminal window used to type it. If you open a new terminal window or close this one, you will have to set again the PATH variable.
 
Note : The arm-none-eabi version can differ from the one given in this example. It could be needed to adapt the path to the correct version.
 
=Software=
==PC interface==
<span class="plainlinks">[http://projects.gctronic.com/epuck2/wiki_images/monitor.png <img width=250 src="http://projects.gctronic.com/epuck2/wiki_images/monitor_small.png">]<br/>
An interface running on a computer and connecting to the e-puck2 either through Bluetooth (selector position 3) or via USB (selector position 8) based on the advanced sercom protocol was developed; from this interface it's possible to have information about all the sensors, receive camera images and control the leds and motors. The source code is available from the repository [https://github.com/e-puck2/monitor https://github.com/e-puck2/monitor].
Available executables:
* [http://projects.gctronic.com/epuck2/monitor_win.zip Windows executable]: tested on Windows 7 and Windows 10
* [http://projects.gctronic.com/epuck2/monitor_mac.zip Max OS X executable]
 
On Linux remember to apply the configuration explained in the chapter [http://www.gctronic.com/doc/index.php?title=e-puck2#Serial_Port Installation for Linux - Serial Port] in order to access the serial port.
 
===WiFi support===
A dedicated WiFi version of the monitor application was developed to communicate with the robot through TCP protocol.<br/>
For more information about the communication protocol, refer to section [http://www.gctronic.com/doc/index.php?title=e-puck2#WiFi_communication_protocol WiFi communication protocol].<br/>
The source code can be downloaded with the command <code>git clone -b wifi --recursive https://github.com/e-puck2/monitor.git</code><br/>
A Windows executable is available here [http://projects.gctronic.com/epuck2/monitor-wifi_e9cf9f9.zip Monitor WiFi for Windows].
 
==Main microcontroller firmware==
The robot is initially programmed with a firmware that includes many demos that could be started based on the selector position:
* Selector position 0: Aseba
* Selector position 1: Shell
* Selector position 2: Read proximity sensors
* Selector position 3: Asercom protocol v2 (BT)
* Selector positoin 4: Range and bearing extension (receiver)
* Selector position 5: Range and bearing extension (transmitter)
* Selector position 6: ESP32 UART communication test
* Selector position 7: ...
* Selector position 8: Asercom protocol v2 (USB)
* Selector position 9: Asercom protocol (BT)
* Selector position 10: This position is used to work with the gumstix extension.
* Selector position 11: Simple obstacle avoidance + some animation
* Selector position 12: Hardware test
* Selector position 13: LEDs reflect orientation of the robot
* Selector position 14: Read magnetometer sensor
* Selector position 15: ...
The source code is available in the git repo [https://github.com/e-puck2/e-puck2_main-processor https://github.com/e-puck2/e-puck2_main-processor].<br/>
The pre-built firmware is available here [http://projects.gctronic.com/epuck2/e-puck2_main-processor_23.04.18_3988f7c.elf e-puck2-firmware].
===Flashing the main microcontroller===
Refer to section [http://www.gctronic.com/doc/index.php?title=e-puck2#Flashing_the_main_microcontroller Flashing the main microcontroller].
===WiFi support===
At the moment there is a separate firmware if the user want to use the WiFi; this firmware was specifically developed to transmit the camera image and sensors to the computer and receive commands from the computer (only motors and red LEDs are supported at the moment).<br/>
In the future the WiFi support will be integrated in the standard firmware.<br/>
The source code can be downloaded with the command <code>git clone -b wifi --recursive https://github.com/e-puck2/e-puck2_main-processor.git</code><br/>
The pre-built firmware is available here [http://projects.gctronic.com/epuck2/e-puck2_main-processor_wifi_97d247f.elf e-puck2-firmware_wifi].
 
==Library==
The library contains all the functions needed to interact with the robot's sensors and actuators; the project includes also the basic standard firmware that shows how to use these functions.<br/>
A snapshot of the library can be donwloaded from [http://projects.gctronic.com/epuck2/e-puck2_main-processor_snapshot_16.02.18_13fa922.zip e-puck2_main-processor_snapshot_16.02.18.zip].<br/>
Otherwise the latest version can be downloaded with the command: <code>git clone --recursive https://github.com/e-puck2/e-puck2_main-processor.git</code><br/>
If you don't have <code>git</code>, you can issue the command: <code>sudo apt-get install git</code>.
 
==Programmer firmware==
This firmware is based on [https://github.com/blacksphere/blackmagic/wiki Black Magic Probe programmer/debugger].<br/>
The source code can be downloaded with the command <code>git clone --recursive -b e-puck-2.0_E https://github.com/e-puck2/e-puck2-programmer</code><br/>
In order to build the firmware you need to issue the following commands form the main repo directory:<br/>
<code>make clean</code><br/>
<code>make PROBE_HOST=e-puck/2.0</code><br/>
The result is a bin file named <code>blackmagic.bin</code> that you can find in the <code>src</code> directory.<br/>
The pre-built firmware is available here [http://projects.gctronic.com/epuck2/programmer-firmware_09.04.18_252d604.bin programmer-firmware.bin]; it is also available in dfu format here [http://projects.gctronic.com/epuck2/programmer-firmware_09.04.18_252d604.dfu programmer-firmware.dfu].
 
===Flashing the programmer===
First of all to update the programmer's firmware you need to enter DFU mode (device firmware upgrade). To do it refer to section [http://www.gctronic.com/doc/index.php?title=e-puck2#Using_the_DFU Using the DFU], in particular Note 2.<br/>
The programmer will be recognized as <code>STM Device in DFU Mode</code> device.
 
====Linux====
In order to update the programmer firmware you need an utility called <code>dfu-util</code>.<br/>
To install it issue the command <code>sudo apt-get install dfu-util</code>.<br/>
Then issue the following command to upload the firmware: <code>sudo dfu-util -d 0483:df11 -a 0 -s 0x08000000 -D programmer-firmware.bin</code>
 
====Windows====
For Windows users it is available an application called <code>DfuSe</code> released by STMicroelectronics. You can download it from [http://projects.gctronic.com/epuck2/en.stsw-stm32080_DfuSe_Demo_V3.0.5.zip DfuSe_V3.0.5.zip].<br/>
When the program is started, the programmer in DFU mode will be automatically detected as shown in figure 1. Then you need to open the compiled firmware by clicking on <code>choose</code> and then locating the file,  as shown in figure 2. Now click on the <code>upgrade</code> button, a warning message will be shown, confirm the action by clicking on <code>yes</code> as shown in figure 3. If all is ok you'll be prompted with a message saying that the upgrade was successfull as shown in figure 4.<br/>
<span class="plainlinks">
<table>
<tr>
<td align="center">[1]</td>
<td align="center">[2]</td>
<td align="center">[3]</td>
<td align="center">[4]</td>
</tr>
<tr>
<td>[http://projects.gctronic.com/epuck2/wiki_images/dfu1.png <img width=250 src="http://projects.gctronic.com/epuck2/wiki_images/dfu1.png">]</td>
<td>[http://projects.gctronic.com/epuck2/wiki_images/dfu2.png <img width=250 src="http://projects.gctronic.com/epuck2/wiki_images/dfu2.png">]</td>
<td>[http://projects.gctronic.com/epuck2/wiki_images/dfu3.png <img width=250 src="http://projects.gctronic.com/epuck2/wiki_images/dfu3.png">]</td>
<td>[http://projects.gctronic.com/epuck2/wiki_images/dfu4.png <img width=250 src="http://projects.gctronic.com/epuck2/wiki_images/dfu4.png">]</td>
</tr>
</table>
</span><br/>
 
==Radio module firmware==
The firmware support Bluetooth communication.<br/>
The source code can be downloaded with the command <code>git clone --recursive https://github.com/e-puck2/esp-idf.git</code><br/>
In order to build the firmware you need to install the toolchain, refer to [http://esp-idf.readthedocs.io/en/latest/get-started/#setup-toolchain http://esp-idf.readthedocs.io/en/latest/get-started/#setup-toolchain]. Once installed you can issue the command <code>make flash</code> from the directory <code>Projects\ESP32_E-Puck_2</code> to build the firmware. For more information have a look at [http://esp-idf.readthedocs.io/en/latest/get-started/#build-and-flash http://esp-idf.readthedocs.io/en/latest/get-started/#build-and-flash].<br/>
The pre-built firmware is available here [http://projects.gctronic.com/epuck2/esp32-firmware_26.01.18_37db240.zip esp32-firmware.zip].
 
===Flashing the radio module===
Refer to section [http://www.gctronic.com/doc/index.php?title=e-puck2#Flashing_the_radio_module Flashing the radio module].
 
===WiFi support===
At the moment there is a separate firmware if the user want to use the WiFi; this firmware was specifically developed to transmit the camera image and sensors to the computer and receive commands from the computer (only motors and red LEDs are supported at the moment).<br/>
In the future the WiFi support will be integrated in the standard firmware.<br/>
The source code can be downloaded with the command <code>git clone -b wifi --recursive https://github.com/e-puck2/esp-idf.git</code><br/>
The pre-built firmware is available here [http://projects.gctronic.com/epuck2/esp32-firmware-wifi-d4ff7b4.zip esp32-firmware_wifi.zip].
 
=Advanced usage=
==Configuring the Programmer's settings==
The on-board programmer of the e-puck2 is based on the [https://github.com/blacksphere/blackmagic/wiki Blackmagic probe open source project] firmware. <br>
Some functionalities has been added on top of the original project to be able to control some functions of the robot, for example the power on or power off.
 
To access to the available commands of the programmer, it is needed to connect to the programmer with a GDB console. <br>
To do so, you have to type the following command in a terminal window with the com port used by the '''e-puck2 GDB Server'' port of your e-puck2 :
<pre>
arm-none-eabi-gdb
target extended-remote your_gdb_com_port
</pre>
 
Once connected to the programmer with GDB, you can type
<pre>monitor help</pre> or <pre>mon help</pre> to print the available commands of the programmer.
 
One command in particular is useful, which is mon select_mode. It is used to select in which mode the  '''e-puck2 Serial Monitor''' com port will work.<br>
mode 1 = the serial monitor is connected to the UART port of the main processor<br>
mode 2 = the serial monitor is connected to the UART of the ESP32<br>
mode 3 = the serial monitor works as a Aseba CAN to USB translator<br>
 
The choice made for the mode is the only setting that is stored in a flash zone of the programmer, which means the choice is remembered, even if the robot is completely turned off.
 
Note : in mode 1 and 3, GDB can be used over the bluetooth connection of the e-puck2. But is is much slower than with USB and it doesn't work with Windows due to GDB limitations on this OS.
 
By being connected with GDB, you can also use the standard GDB command to program and debug the main processor of the e-puck2.
 
==Using the DFU==
To put the e-puck2 into DFU, it is needed to turn it on while keeping pressed the "407 boot" button located under the electronic card on the left side of the robot.<br>
The robot will appear as "STM32 BOOTLOADER" in the USB devices.
 
Once in DFU, you can program it with [http://dfu-util.sourceforge.net dfu-util]  using the following command :
<pre>dfu-util -d 0483:df11 -a 0 -s 0x08000000 -D your_firmware.bin</pre>
 
See the [http://dfu-util.sourceforge.net/dfu-util.1.html manual page] of dfu-util for further information on how to use it.
 
'''Note''': For windows, it is needed to install a libusbK driver for the DFU device. <br>
You can use the Zadig program located in the Eclipse_e-puck2\Tools\ (if you installed Eclipse_e-puck2 package) to install it. <br>
Follow the same procedure as explained above under the [[#Drivers | Installation drivers]] section using libusbK driver instead of USB Serial (CDC).
 
'''Note 2''': It is also possible to put the programmer in DFU by contacting two pinholes together while inserting the USB cable (no need to turn on the robot).<br>
It is used to update the firmware of the programmer.<br>
The two pin holes are located near the USB connector of the e-puck2, see the photo below.
 
::<span class="plain links">[http://projects.gctronic.com/epuck2/wiki_images/e-puck2_top_leds_DFU_413.png <img width=200 src="http://projects.gctronic.com/epuck2/wiki_images/e-puck2_top_leds_DFU_413.png">]</span><br/>
::''Location of the pin holes to put the programmer into DFU''
 
==WiFi communication protocol==
The communication is based on TCP; the robot create a TCP server and wait for a connection.<br/>
 
Each packet is identified by an ID (1 byte). The following IDs are used to send data from the robot to the computer:
* 0x00 = reserved
* 0x01 = QQVGA color image packet (only the first segment includes this id); packet size (without id) = 38400 bytes; image format = RGB565
* 0x02 = sensors packet; packet size (without id) = 104 bytes; the format of the returned values are based on the [http://www.gctronic.com/doc/index.php/Advanced_sercom_protocol asercom protocol]:
 
:<span class="plain links">[http://projects.gctronic.com/epuck2/wiki_images/packet-format-robot-to-pc.jpg <img width=1150 src="http://projects.gctronic.com/epuck2/wiki_images/packet-format-robot-to-pc.jpg">]</span><br/>
:*Acc: raw axes values, between -1500 and 1500, resolution is +-2g
:*Acceleration: acceleration magnitude <img width=70 src="http://projects.gctronic.com/epuck2/wiki_images/3dvector-magnitude.png">, between 0.0 and about 2600.0 (~3.46 g)
:*Orientation: between 0.0 and 360.0 degrees
::<table>
<tr>
<td align="center">0.0 deg</td>
<td align="center">90.0 deg</td>
<td align="center">180 deg</td>
<td align="center">270 deg</td>
</tr>
<tr>
<td><img width=80 src="http://projects.gctronic.com/epuck2/wiki_images/orientation0.png"></td>
<td><img width=80 src="http://projects.gctronic.com/epuck2/wiki_images/orientation90.png"></td>
<td><img width=80 src="http://projects.gctronic.com/epuck2/wiki_images/orientation180.png"></td>
<td><img width=80 src="http://projects.gctronic.com/epuck2/wiki_images/orientation270.png"></td>
</tr>
</table>
:*Inclination:
:*Gyro:
:*Magnetometer:
:*Temp:
:*IR proximity:
:*IR ambient:
:*ToF distance:
:*Mic volume:
:*Motors steps:
:*Battery:
:*uSD state:
:*TV remote data:
:*Selector position:
:*Ground proximity:
:*Ground ambient:
:*Button state:
* 0x03 = empty packet (only id is sent); this is used as an acknowledgment for the commands packet when no sensors and no image is requested
The following IDs are used to send data from the computer to the robot:
* 0x80 = commands packet; packet size (without id) = 20 bytes:
 
:<span class="plain links">[http://projects.gctronic.com/epuck2/wiki_images/packet-format-pc-to-robot.jpg <img width=600 src="http://projects.gctronic.com/epuck2/wiki_images/packet-format-pc-to-robot.jpg">]</span><br/>
 
:*request:
:** bit0: 0=stop image stream; 1=start image stream
:** bit1: 0=stop sensors stream; 1=start sensors stream
:*settings:
:** bit0: 1=calibrate IR proximity sensors
:** bit1: 0=disable onboard obstacle avoidance; 1=enable onboard obstacle avoidance (not implemented yet)
:** bit2: 0=set motors speed; 1=set motors steps (position)
:*left and right: when bit2 of <code>settings</code> field is <code>0</code>, then this is the desired motors speed (-1000..1000); when <code>1</code> then this is the value that will be set as motors position (steps)
:*LEDs: 0=off; 1=on; 2=toggle
:** bit0: 0=LED1 off; 1=LED1 on
:** bit1: 0=LED3 off; 1=LED3 on
:** bit2: 0=LED5 off; 1=LED5 on
:** bit3: 0=LED7 off; 1=LED7 on
:** bit4: 0=body LED off; 1=body LED on
:** bit5: 0=front LED off; 1=front LED on
:*RGB LEDs: for each LED, it is specified in sequence the value of red, green and blue (0...100)
:* sound id: 0x01=MARIO, 0x02=UNDERWOLRD, 0x04=STARWARS, 0x08=4KHz, 0x10=10KHz, 0x20=stop sound
 
For example to receive the camera image (stream) the following steps need to be followed:<br/>
1) connect to the robot through TCP<br/>
2) send the command packet:
:{| border="1"
|0x80
|0x01
|0x00
|0x00
|0x00
|0x00
|0x00
|0x00
|0x00
|0x00
|0x00
|0x00
|0x00
|0x00
|0x00
|0x00
|0x00
|0x00
|0x00
|0x00
|0x00
|}
3) read the ID (1 byte) and the QQVGA color image pakcet (38400 bytes)<br/>
4) go to step 3

Revision as of 09:44, 24 May 2022

Hardware

Overview


Features:

  • Raspberry Pi zero W (rPi) connected to the robot via I2C
  • interface between the robot base camera and the rPi via USB, up to 15 FPS
  • 1 digital microphone and 1 speaker
  • USB hub connected to the rPi with 2 free ports
  • uUSB cable to the rPi uart port. Also ok for charging
  • 2 chargers. 1 for the robot battery and 1 for the auxiliary battery on top of the extension
  • charging contact points in front for automatic charging. External docking station available
  • several extension options. 6 i2C channels, 2 ADC inputs
  • several LED to show the status of the rPi and the power/chargers

I2C bus

I2C is used to let communicate various elements present in the robot, Pi-puck and extensions. An overall schema is shown in the following figure:

An I2C switcher is included in the Pi-puck extension in order to support additional I2C buses (the RPi alone has only one usable I2C bus). These are needed to avoid conflicts between Time-of-Flight sensors that have a fixed I2C address.

Getting started

This introductory section explains the minimal procedures needed to work with the Raspberry Pi Zero W mounted on the Pi-puck extension board and gives a general overview of the available basic demos and scripts shipped with the system flashed on the micro SD. More advanced demos are described in the following separate sections (e.g. ROS), but the steps documented here are fundamental, so be sure to fully understand them.

The extension is mostly an interface between the e-puck robot and the Raspberry Pi, so you can exploit the computational power of a Linux machine to extend the robot capabilities.

In most cases, the Pi-puck extension will be attached to the robot, but it's interesting to note that it can be used also alone when the interaction with the robot isn't required.
The following sections assume the full configuration (robot + extension), unless otherwise stated.

Requirements

The robot must be programmed with a special firmware in order to communicate via I2C bus with the Raspberry Pi mounted on the Pi-puck extension. The same I2C bus is shared by all the devices (camera, IMU, distance sensor, others extensions), the main microcontroller and the Raspberry Pi. Since the Raspberry Pi acts as I2C master, these devices will not be anymore reachable directly from the robot main microcontroller that will act instead as I2C slave.

e-puck1

The e-puck1 robot must be programmed with the following firmware pi-puck-e-puck1.hex.

e-puck2

The e-puck2 robot must be programmed with the following firmware e-puck2_main-processor_extension.elf (07.06.19) and the selector must be placed in position 10.
The source code is available in the gumstix branch of the repo https://github.com/e-puck2/e-puck2_main-processor.

Turn on/off the extension

To turn on the extension you need to press the auxON button as shown in the follwoing figure; this will turn on also the robot (if not already turned on). Similarly, if you turn on the robot then also the extension will turn on automatically.

To turn off the Pi-puck you need to press and hold the auxON button for 2 seconds; this will initiate the power down procedure.

Beware that by turning off the robot, the extension will not be turned off automatically if it is powered from another source like the micro usb cable or a secondary battery. You need to use its power off button to switch it off. Instead if there is no other power source, then by turning off the robot also the extension will be turned off (not cleanly).

Console mode

The Pi-puck extension board comes with a pre-configured system ready to run without any additional configuration.
In order to access the system from a PC in console mode, the following steps must be performed:
1. connect a micro USB cable from the PC to the extension module. If needed, the drivers are available in the following link USB to UART bridge drivers

2. execute a terminal program and configure the connection with 115200-8N1 (no flow control). The serial device is the one created when the extension is connected to the computer
3. switch on the robot (the extension will turn on automatically); now the terminal should display the Raspberry Pi booting information. If the robot isn't present, then you can directly power on the extension board with the related button
4. login with user = pi, password = raspberry

Battery charge

You can either charge the robot battery or the additional battery connected to the Pi-puck extension or both the batteries by simply plugging the micro USB cable.
The following figure shows the connector for the additional battery.

The robot can also autonomously charge itself if the charging wall is available. The Pi-puck extension includes two spring contacts on the front side that let the robot easily make contact with the charging wall and charge itself. The charging wall and the spring contacts are shown in the following figures:

Reset button

A button is available to reset the robot, when pressed it will resets only the robot restarting its firmware. This is useful for instance during development or for specific demos in which a restart of the robot is needed. In these cases you don't need to turn off completely the robot (and consequently also the Pi-puck if energy is supplied by the robot) but instead you can simply reset the robot. The position of the reset button is shown in the following figure:

How to communicate with the robot and its sensors

Communicate with the e-puck1

Refer to the repo https://github.com/yorkrobotlab/pi-puck-e-puck1.

Communicate with the e-puck2

An example showing how to exchange data between the robot and the Pi-puck extension is available in the Pi-puck repository; you can find it in the directory /home/pi/Pi-puck/e-puck2/.
You can build the program with the command gcc e-puck2_test.c -o e-puck2_test.
Now you can run the program by issueing ./e-puck2_test; this demo will print the sensors data on the terminal and send some commands to the robot at 2 Hz.
The same example is also available in Python, you can run it by issueing python3 e-puck2_test.py.

Packet format

Extension to robot packet format, 20 bytes payload (the number in the parenthesis represents the bytes for each field):

Left speed (2) Right speed (2) Speaker (1) LED1, LED3, LED5, LED7 (1) LED2 RGB (3) LED4 RGB (3) LED6 RGB (3) LED8 RGB (3) Settings (1) Checksum (1)
  • Left, right speed: [-2000 ... 2000]
  • Speaker: sound id = [0, 1, 2]
  • LEDs on/off flag: bit0 for LED1, bit1 for LED3, bit2 for LED5, bit3 for LED7
  • RGB LEDs: [0 (off) ... 100 (max)]
  • Settings:
    • bit0: 1=calibrate IR proximity sensors
    • bit1: 0=disable onboard obstacle avoidance; 1=enable onboard obstacle avoidance (not implemented yet)
    • bit2: 0=set motors speed; 1=set motors steps (position)
  • Checksum: Longitudinal Redundancy Check (XOR of the bytes 0..18)

Robot to extension packet format, 47 bytes payload (the number in the parenthesis represents the bytes for each field):

8 x Prox (16) 8 x Ambient (16) 4 x Mic (8) Selector + button (1) Left steps (2) Right steps (2) TV remote (1) Checksum
  • Selector + button: selector values represented by 4 least significant bits (bit0, bit1, bit2, bit3); button state is in bit4 (1=pressed, 0=not pressed)
  • Checksum: Longitudinal Redundancy Check (XOR of the bytes 0..45)

Communicate with the IMU

e-puck1

An example written in C showing how to read data from the IMU (LSM330) mounted on e-puck 1.3 is available in the Pi-puck repository; you can find it in the directory /home/pi/Pi-puck/e-puck1/.
You can build the program with the command gcc e-puck1_imu.c -o e-puck1_imu.
Now you can run the program by issueing ./e-puck1_imu and then choose whether to get data from the accelerometer or gyroscope; this demo will print the sensors data on the terminal.

e-puck2

An example showing how to read data from the IMU (MPU-9250) is available in the Pi-puck repository; you can find it in the directory /home/pi/Pi-puck/e-puck2/.
You can build the program with the command gcc e-puck2_imu.c -o e-puck2_imu.
Now you can run the program by issueing ./e-puck2_imu and then choose whether to get data from the accelerometer or gyroscope; this demo will print the sensors data on the terminal.
The same example is also available in Python, you can run it by issueing python3 e-puck2_imu.py.

Communicate with the ToF sensor

The Time of Flight sensor is available only on the e-puck2 robot.

First of all you need to verify that the VL53L0X Python package is installed with the following command: python3 -c "import VL53L0X". If the command returns nothing you're ready to go, otherwise if you receive an ImportError then you need to install the package with the command: pip3 install git+https://github.com/gctronic/VL53L0X_rasp_python.

A Python example showing how to read data from the ToF sensor is available in the Pi-puck repository; you can find it in the directory /home/pi/Pi-puck/e-puck2/.
You can run the example by issueing python3 VL53L0X_example.py (this is the example that you can find in the repository https://github.com/gctronic/VL53L0X_rasp_python/tree/master/python).

Capture an image

The robot camera is connected to the Pi-puck extension as a USB camera, so you can access it very easily.
An example showing how to capture an image from the robot's camera using OpenCV is available in the Pi-puck repository; you can find it in the directory /home/pi/Pi-puck/snapshot/.
You can build the program with the command g++ $(pkg-config --libs --cflags opencv) -ljpeg -o snapshot snapshot.cpp.
Now you can run the program by issueing ./snapshot; this will save a VGA image (JPEG) named image01.jpg to disk.
The program can accept the following parameters:
-d DEVICE_ID to specify the input video device from which to capture an image, by default is 0 (/dev/video0). This is useful when working also with the Omnivision V3 extension that crates another video device; in this case you need to specify -d 1 to capture from the robot camera.
-n NUM to specify how many images to capture (1-99), by default is 1
-v to enable verbose mode (print some debug information)
Beware that in this demo the acquisition rate is fixed to 5 Hz, but the camera supports up to 15 FPS.
The same example is also available in Python, you can run it by issueing python snapshot.py.

Communicate with the ground sensors extension

Both e-puck1 and e-puck2 support the ground sensors extension.
This extension is attached to the I2C bus and can be read directly from the Pi-puck.
An example written in C showing how to read data from the ground sensors extension is available in the Pi-puck repository; you can find it in the directory /home/pi/Pi-puck/ground-sensor/.
You can build the program with the command gcc groundsensor.c -o groundsensor.
Now you can run the program by issueing ./groundsensor; this demo will print the sensors data on the terminal.
The same example is also available in Python, you can run it by issueing python3 groundsensor.py.

Communicate with the range and bearing extension

Both e-puck1 and e-puck2 support the range and bearing extension.
This extension is attached to the I2C bus and can be read directly from the Pi-puck.
An example written in C showing how to start playing with the range and bearing extension is available in the Pi-puck repository; you can find it in the directory /home/pi/Pi-puck/randb/. You need two boards: one is the transmitter (run randb_tx) and the other is the receiver (run randb_rx). The receiver will print the data received from the transmitter.
You can build the programs with the command gcc randb_tx.c -o randb_tx and gcc randb_rx.c -o randb_rx.
The same example is also available in Python, you can run it by issueing python3 randb_tx.py and python3 randb_rx.py.

Wireless remote control

If you want to control the robot from a computer, for instance when you have an algorithm that requires heavy processing not suitable for the Pi-puck or when the computer acts as a master controlling a fleet of robots that return some information to the controller, then you have 3 options:
1) The computer establishes a WiFi connection with the Pi-puck to receive data processed by the Pi-puck (e.g. results of an image processing task); at the same time the computer establishes a Bluetooth connection directly with the e-puck2 robot to control it.

Disadvantages:
- the Bluetooth standard only allow up to seven simultaneous connections
- doubled latency (Pi-puck <-> pc and pc <-> robot)

2) The computer establishes a WiFi connection with both the Pi-puck and the e-puck2 robot.

Advantages:
- only one connection type needed, easier to handle
Disadvantages:
- doubled latency (Pi-puck <-> pc and pc <-> robot)

3) The computer establishes a WiFi connection with the Pi-puck and then the Pi-puck is in charge of controlling the robot via I2C based on the data received from the computer controller.

Advantages:
- less latency involved
- less number of connections to handle
- depending on your algorithm, it would be possible to initially develop the controller on the computer (easier to develop and debug) and then transfer the controller directly to the Pi-puck without the need to change anything related to the control of the robot via I2C

The following figure summarizes these 3 options:

How to work with the Pi-puck

Demos and scripts update

First of all you should update to the last version of the demos and scripts released with the system that you can use to start playing with the Pi-puck extension and the robot.
To update the repository follow these steps:
1. go to the directory /home/pi/Pi-puck
2. issue the command git pull
Then to update some configurations of the system:
1. go to the directory /home/pi/Pi-puck/system
2. issue the command ./update.sh; the system will reboot.
You can find the Pi-puck repository here https://github.com/gctronic/Pi-puck.

Audio recording

Use the arecord utility to record audio from the onboard microphone. The following example shows how to record an audio of 2 seconds (-d parameter) and save it to a wav file (test.wav):
arecord -Dmic_mono -c1 -r16000 -fS32_LE -twav -d2 test.wav
You can also specify a rate of 48 KHz with -r48000

Audio play

Use aplay to play wav files and mplayer to play mp3 files.

Battery reading

An example showing how to measure both the battery of the robot and the battery of the Pi-puck extension is available in the Pi-puck repository; you can find it in the directory /home/pi/Pi-puck/battery/.
The first time you need to change the mode of the script in order to be executable with the command sudo chmod +x read-battery.sh.
Then you can start reading the batteries value by issueing ./read-battery.sh.; this demo will print the batteries values (given in Volts) on the terminal.

WiFi configuration

Specify your network configuration in the file /etc/wpa_supplicant/wpa_supplicant-wlan0.conf.
Example:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=CH
network={
        ssid="MySSID"
        psk="9h74as3xWfjd"
}

You can have more than one network parameter to support more networks. For more information about wpa_supplicant refer to https://hostap.epitest.fi/wpa_supplicant/.

Once the configuration is done, you can also connect to the Pi-puck with SSH. If you are working in Windows you can use PuTTY.

How to know your IP address

A simple method to know your IP address is to connect the USB cable to the Pi-puck extension and issue the command ip a; from the command's result you will be able to get you current assigned IP address.

If you prefer to know your IP address remotely (without connecting any cable) then you can use nmap.
For example you can search all connected devices in your network with the following command: nmap 192.168.1.*. Beware that you need to specify the subnet based on your network configuration.
From the command's result you need to look for the hostname raspberrypi.
If you are working in Windows you can use the Zenmap application.

File transfer

USB cable

You can transfer files via USB cable between the computer and the Pi-puck extension by using on of the zmodem protocol.
The lrzsz package is pre-installed in the system, thus you can use the sx and rx utilities to respectevely send files to the computer and receive files from the computer.
Example of sending a file to the computer using the Minicom terminal program:
1. in the Pi-puck console type sx --zmodem fliename.ext. The transfer should start automatically and you'll find the file in the home directory.
Example of receiving a file from the computer using the Minicom terminal program:
1. in the Pi-puck console type rx -Z
2. to start the transfer type the sequence CTRL+A+S, then chose zmodem and select the file you want to send with the spacebar. Finally press enter to start the transfer.

WiFi

The Pi-puck extension supports SSH connections.
To exchange files between the Pi-puck and the computer, the scp tool (secure copy) can be used. An example of transferring a file from the Pi-puck to the computer is the following:
scp pi@192.168.1.20:/home/pi/example.txt example.txt

If you are working in Windows you can use PuTTY.

Image streaming

Bluetooth LE

An example of a BLE uart service is available in the Pi-puck repository; you can find it in the directory /home/pi/Pi-puck/ble/.
To start the service you need to type: python uart_peripheral.py.
Then you can use the e-puck2-android-ble app you can find in chapter Connecting to the BLE in order to connect to the Pi-puck extension via BLE. Once connected you'll receive some dummy data for the proximity values and by clicking on the motion buttons you'll see the related action printed on the Pi-puck side. This is a starting point that you can extend based on your needs.

Operating system

The system is based on Raspbian Stretch and can be downloaded from the following link pi-puck-os_16.12.19.zip.

When booting the first time, the first thing to do is expanding the file system in order to use all the available space on the micro sd:
1. sudo raspi-config
2. Select Advanced Options and then Expand Filesystem
3. reboot

e-puck2 camera configuration

The e-puck2 camera need to be configured through I2C before it can be used. For this reason a Python script is called at boot that detects and configures the camera. The script resides in the Pi-puck repository installed in the system (/home/pi/Pi-puck/camera-configuration.py), so beware to not remove it.

If the robot is plugged after the boot process is completed, you need to call manually the Python configuration script before using the camera by issueing the command python3 /home/pi/Pi-puck/camera-configuration.py.

In order to automatically run the script at boot, the /etc/rc.local was modified by adding the call to the script just before the end of the file.

Power button handling

The power button press is handled by a background service (systemd) started automatically at boot. The service description file is located in /etc/systemd/system/power_handling.service and it calls the /home/pi/power-handling/ program. Beware to not remove neither of these files.
The source code of the power button handling program is available in the Pi-puck repository and is located in /home/pi/Pi-puck/power-handling/power-handling.c.

Desktop mode

The system starts in console mode, to switch to desktop (LXDE) mode issue the command startx.

Camera viewer

A camera viewer called luvcview is installed in the system. You can open a terminal and issue simply the command luvcview to see the image coming from the robot camera.

VNC

VNC is a remote control desktop application that lets you connect to the Pi-puck from your computer and then you will see the desktop of the Pi-puck inside a window on your computer. You'll be able to control it as though you were working on the Pi-puck itself.
VNC is installed in the system and the VNC server is automatically started at boot, thus you can connect with VNC Viewer from your computer by knowing the IP address of the Pi-puck (refer to section How to know your IP address).
Notice that the VNC server is started also in console mode.

I2C communication

The communication between the Pi-puck extension and the robot is based on I2C. The system is configured to exploit the I2C hardware peripheral in order to save CPU usage, but if you need to use the software I2C you can enable it by modifying the /boot/config.txt file and removing the # symbol (comment) in front of the line with the text dtparam=soft_i2c (it is placed towards the end of the file).

Audio output configuration

You can enable or disable audio output by modifying the config.txt file in the boot partition.
To enable audio output insert the line: gpio=22=op,dh
To disable audio output insert the line: gpio=22=op,dl
If you don't need to play audio files it is suggested to disable audio output in order to save power.

ROS

ROS Kinetic is integrated in the Pi-puck system.
A ROS node developed to run in the Pi-puck is available for both CPP and Python, the communication system is based on the third architecture shown in chapter Wireless remote control; a more detailed schema is shown below:

Initial configuration

The ROS workspace is located in ~/rosbots_catkin_ws/
The e-puck2 ROS driver is located in ~/rosbots_catkin_ws/src/epuck_driver_cpp/
Remember to follow the steps in the section Requirements and section Demos and scripts update, only once.
The PC (if used) and the Pi-puck extension are supposed to be configured in the same network.

Running roscore

roscore can be launched either from the PC or directly from the Pi-puck.
Before starting roscore, open a terminal and issue the following commands:

where roscore-ip is the IP of the machine that runs roscore
Then start roscore by issueing roscore.

Running the ROS node

Before starting the e-puck2 ROS node on the Pi-puck, issue the following commands:

where pipuck-ip is the IP of the Pi-puck extension and roscore-ip is the IP of the machine that runs roscore (can be the same IP if roscore runs directly on the Pi-puck).

To start the e-puck2 ROS node issue the command:
roslaunch epuck_driver_cpp epuck_minimal.launch debug_en:=true ros_rate:=20

The following graph shows all the topics published by the e-puck2 driver node:
Click to enlarge

Test the communication

You can test if the communication between the robot and the computer is actually working by simply display messages published by a topic, e.g.: rostopic echo /proximity0 You can have the list of all the topic by issueing the command: rostopic list.

Get the source code

The last version of the e-puck2 ROS node can be downloaded from the git: git clone -b pi-puck https://github.com/gctronic/epuck_driver_cpp.git

To update to the last version follow these steps:

  1. cd ~/rosbots_catkin_ws/src/
  2. rm -R -f epuck_driver_cpp
  3. git clone -b pi-puck https://github.com/gctronic/epuck_driver_cpp.git
  4. cd ~/rosbots_catkin_ws/
  5. catkin_make --only-pkg-with-deps epuck_driver_cpp

Python version

A Python version developed by the York University can be found here https://github.com/yorkrobotlab/pi-puck-ros.

OpenCV

OpenCV 3.4.1 is integrated in the Pi-puck system.

York Robotics Lab Expansion Board

The York Robotics Lab developed an expansion board for the Pi-puck extension that includes: 9-DoF IMU, 5-input navigation switch, RGB LED, XBee socket, 24-pin Raspberry Pi compatible header. For more information have a look at https://pi-puck.readthedocs.io/en/latest/extensions/yrl-expansion/.

An example showing how to communicate with the YRL expansion board is available in the Pi-puck repository of the York Robotics Lab:

  1. git clone https://github.com/yorkrobotlab/pi-puck.git pi-puck_yrl
  2. cd pi-puck_yrl/python-library
  3. python3 pipuck-library-test.py -x Once started, press in sequence up, down, left, right, center to continue the demo.

Assembly

The assembly is very simple: place the YRL expansion board on top of the Raspberry Pi and then connect them with the provided screws. Once they are connected, you can attach both on top of the Pi-puck extension.

XBee

In this section it is explained how to send data from the Pi-puck to the computer using XBee modules Series 1.

The XBee module mounted on the YRL expansion must be programmed with the XBEE 802.15.4-USB ADAPTER firmware; this can be done with the XTCU software. With XTCU be sure to program also the same parameters on both modules in order to be able to communicate between each other: Channel (e.g. C), PAN ID (e.g. 3332), DH = 0, DL = 0, MY = 0.

Some Python examples ara available in the YRL Expansion Board GitHub repository that can be used to communicate with the XBee module mounted on the YRL expansion. These examples are based on the Digi XBee Python library that can be installed with the command pip3 install digi-xbee. This library requires the XBee module to be configured in API mode; you can setup this mode following these steps:

  1. git clone https://github.com/yorkrobotlab/pi-puck-expansion-board.git
  2. cd pi-puck-expansion-board/xbee
  3. python3 xbee-enable-api-mode.py

Now connect the second module to the computer and run XTCU, select the console view and open the serial connection. Then run the xbee-send-broadcast.py example from the Pi-puck by issuing the command: python3 xbee-send-broadcast.py. From the XTCU console you should receive Hello Xbee World!.

For more information refer to https://pi-puck.readthedocs.io/en/latest/extensions/yrl-expansion/xbee/.

Time-of-Flight Distance Sensor add-on

The Pi-puck extension integrates six sensor board sockets that can be used to add up to six VL53L1X-based distance sensor add-ons. The Pi-puck equipped with these add-ons is shown in the following figure:

For more information have a look at https://pi-puck.readthedocs.io/en/latest/extensions/tof-sensor/#time-of-flight-distance-sensor.

Beware that once the socket for the ToF add-on sensor 3 is soldered on the pi-puck extension, you are no more able to connect the HDMI cable.

Communicate with the ToF sensors

In order to communicate with the sensors you can use the multiple-i2c-bus-support branch of the vl53l1x-python library from Pimoroni. To install this library follow these steps:

  1. git clone -b multiple-i2c-bus-support https://github.com/pimoroni/vl53l1x-python.git
  2. cd vl53l1x-python
  3. sudo python3 setup.py install

A Python example showing how to read data from the ToF sensors is available in the Pi-puck repository of the York Robotics Lab:

  1. git clone https://github.com/yorkrobotlab/pi-puck.git pi-puck_yrl
  2. cd pi-puck_yrl/python-library
  3. python3 pipuck-library-test.py -t