e-puck2 and e-puck2 robot side development: Difference between pages

From GCtronic wiki
(Difference between pages)
Jump to navigation Jump to search
 
 
Line 1: Line 1:
=Hardware=
[{{fullurl:e-puck2}} e-puck2 main wiki]<br/>
==Overview==
=Introduction=
<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>
The <code>C programming</code> language is used to develop code for the main microcontroller of the e-puck2 robot. The [http://www.chibios.org ChibiOS] embedded real-time OS was chosen to be integrated in the firmware, since it support the STM32F4 family of microprocessors, it includes an HAL (Hardware Abstraction Layer), it's well documented and finally it's free.<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/>
Before starting to code, you need to install the developing environment and its dependencies, all the steps are documented afterwards.<br>
 
The factory firmware integrates both the e-puck2 library used to handle all the sensors and actuators together with a series of demos that use this library. Thus you can either take the factory firmware and directly modify its main, otherwise you can start a fresh new project by linking the factory firmware project as an external library.<br>
==Specifications==
You can also modify the library itself, but before digging into the details, try to contact us, maybe we're already working on that subject or we can help you.
The e-puck2 robot maintains full compatibility with its predecessor e-puck (e-puck HWRev 1.3 is considered in the following table):
{| 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/>
<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/>


=Installation of the e-puck2 environment=
=Installation of the e-puck2 environment=
Some programs are needed to program the e-puck2.
<code>Eclipse_e-puck2</code> 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'''.
 
#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'''.
#Drivers must also be installed for Windows older than Windows 10.


==Installation for Windows==
==Installation for Windows==
===Java 8 32bits===
===Java 8 32bits===
This section can be ignored if Java version 8 32bits is already installed on your computer.<br>
This section can be ignored if Java version >= 8 32bits is already installed on your computer.<br>
To verify, you can open the '''Programs and Features''' panel and search for a '''Java 8 Update xxx''' install.
To verify you already installed Java, you can open <code>Programs and Features</code> from the <code>control panel</code> and search for a <code>AdoptOpenJDK JDK with Hotspot xxx</code> install. If this entry isn't present, then you need to install it:
 
# Go to [https://adoptopenjdk.net/releases.html OpenJDK download page] and download the <code>OpenJDK 8 (LTS) HotSpot for Windows x86 JDK</code> (take the installer, aka. <code>.msi</code> file).
#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.
# Run the downloaded installer and follow its instructions to proceed with the installation of OpenJDK 32bits.
#Run the downloaded installer and follow its instructions to proceed with the installation of Java 32bits.
:<span class="plain links">[https://projects.gctronic.com/epuck2/wiki_images/openjdk-windows.png <img width=700 src="https://projects.gctronic.com/epuck2/wiki_images/openjdk-windows.png">]</span><br/>
#Close the internet browser if it opened at the end of the installation.
:''OpenJDK download page''
 
:<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/>
:''Java download page''


===Eclipse_e-puck2===
===Eclipse_e-puck2===
#Download the [http://projects.gctronic.com/epuck2/Eclipse_e-puck2/Eclipse_e-puck2_Win32_11_apr_2018.zip Eclipse_e-puck2 package for windows].
#Download the [https://github.com/e-puck2/Create_Eclipse_e-puck2/releases/download/29_jan_2020/Eclipse_e-puck2_Win32_29_jan_2020.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.
#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 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.
#You can create a shortcut to <code>Eclipse_e-puck2.exe</code> 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/>
:<span class="plain links">[https://projects.gctronic.com/epuck2/wiki_images/Eclipse_e-puck2_Folder_Windows.png <img width=800 src="https://projects.gctronic.com/epuck2/wiki_images/Eclipse_e-puck2_Folder_Windows.png">]</span><br/>
:''Eclipse_e-puck2 folder obtained after extraction''
:''Eclipse_e-puck2 folder obtained after extraction''


'''Important things to avoid :'''
'''Important things to avoid :'''
:1. The path to the Eclipse_e-puck2 folder must contain zero space.  
:1. The path to the <code>Eclipse_e-puck2</code> folder must contain zero space.  
::Example :
::Example :
::<code>C:\epfl_stuff\Eclipse_e-puck2</code> OK  
::<code>C:\epfl_stuff\Eclipse_e-puck2</code> OK  
::<code>C:\epfl stuff\Eclipse_e-puck2</code> NOT OK
::<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.  
:2. You must not put <code>Eclipse_e-puck2</code> folder into <code>Program Files (x86)</code>. 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.
:3. The file’s structure in the <code>Eclipse_e-puck2</code> folder must remain the same. It means no file inside this folder must be moved to another place.


===Drivers===
===Configuring the PATH variable===
This part concerns only the users of a Windows version older than Windows 10. The drivers are automatically installed with Windows 10.
The <code>PATH</code> variable is an environment variable used to store a list of the paths to the folders containing the executables we can then run in a terminal from any path.


#Open <code>zadig-2.3.exe</code> located in the <code>Eclipse_e-puck2\Tools\</code> folder you installed before.
If you want to use the <code>arm-none-eabi</code> toolchain provided inside the <code>Eclipse_e-puck2</code> package, you have to add it to the <code>PATH</code> variable to be able to call it inside a terminal window. To set the <code>PATH</code> variable you need to issue the following command:
#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)'''.
#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.
::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/>
<code>set PATH=your_installation_path\Eclipse_e-puck2\Tools\gcc-arm-none-eabi-7-2017-q4-major-win32\bin;%PATH%</code>
::''Example of driver installation for e-puck2 STM32F407''
 
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 <code>PATH</code> variable.
 
If you want to set the <code>PATH</code> variable permanently, then go to <code>Control panel</code> => <code>System</code> => <code>Advanced system settings</code> => <code>Environment variables</code>. A list of variables defined for the user is shown, double click on the <code>PATH</code> variable (from the user variables list) and add at the end <code>;your_installation_path\Eclipse_e-puck2\Tools\gcc-arm-none-eabi-7-2017-q4-major-win32\bin</code>, then click <code>OK</code> three times.
 
Note : The <code>arm-none-eabi</code> version can differ from the one given in this example. It could be needed to adapt the path to the correct version.


==Installation for Linux==
==Installation for Linux==
===Java 8===
===Java 8===
This section can be ignored if Java is already installed on your computer.<br>
This section can be ignored if Java is already installed on your computer.<br>
To verify whether it is installed or not you can type the following command into a terminal window:
To verify whether it is installed or not you can type the following command into a terminal window: <code>update-java-alternatives -l</code>. If Java is installed, you will get some information about it, otherwise the command will be unknown.<br>
<pre>update-java-alternatives -l</pre>
You need to have <code>Java 1.8.xxxx</code> listed to be able to run <code>Eclipse_e-puck2</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:
Type the following commands in a terminal session to install Java SDK:
Line 191: Line 60:


===Eclipse_e-puck2===
===Eclipse_e-puck2===
#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.
#Install <code>make</code> (probably you already have it installed) by issueing the command: <code>sudo apt-get install make</code>
#Extract the downloaded file to the location you want (can take time).
#Download the Eclipse_e-puck2 package for Linux [https://projects.gctronic.com/epuck2/Eclipse_e-puck2/Eclipse_e-puck2_Linux_11_apr_2018_32bits.tar.gz 32bits] / [https://github.com/e-puck2/Create_Eclipse_e-puck2/releases/download/14_aug_2020/Eclipse_e-puck2_Linux64_14_aug_2020.tar.xz 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 <code>i686</code> (32bit) or <code>x86_64</code> (64 bit). 
#Extract the downloaded file to the location you want (can take time): <code>tar -zxvf package_name.tar.gz</code>
#You can now run the <code>Eclipse_e-puck2</code> executable to launch Eclipse.
#You can now run the <code>Eclipse_e-puck2</code> executable to launch Eclipse.


:<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/>
:<span class="plain links">[https://projects.gctronic.com/epuck2/wiki_images/Eclipse_e-puck2_Folder_Linux.png <img width=800 src="https://projects.gctronic.com/epuck2/wiki_images/Eclipse_e-puck2_Folder_Linux.png">]</span><br/>
:''Eclipse_e-puck2 folder obtained after extraction''
:''Eclipse_e-puck2 folder obtained after extraction''


Note : The icon of the Eclipse_e-puck2 executable will appear after the first launch of the program.
Note : The icon of the <code>Eclipse_e-puck2</code> executable will appear after the first launch of the program.


'''Important things to avoid :'''
'''Important things to avoid :'''
: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.
:1. You cannot create a Link to the <code>Eclipse_e-puck2</code> executable because otherwise the program will think its location is where the Link is and it will not find the resources located in the <code>Eclipse_e-puck2</code> folder.
:2. The path to the Eclipse_e-puck2 folder must contain zero space.  
:2. The path to the <code>Eclipse_e-puck2</code> folder must contain zero space.  
::Example :
::Example :
::<code>/home/student/epfl_stuff/Eclipse_e-puck2</code> OK  
::<code>/home/student/epfl_stuff/Eclipse_e-puck2</code> OK  
::<code>/home/student/epfl stuff/Eclipse_e-puck2</code> NOT 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.
:3. The file’s structure in the <code>Eclipse_e-puck2</code> folder must remain the same. It means no file inside this folder must be moved to another place.
 
===Configuring the PATH variable===
The <code>PATH</code> variable is an environment variable used to store a list of the paths to the folders containing the executables we can then run in a terminal from any path.
 
If you want to use the <code>arm-none-eabi</code> toolchain provided inside the <code>Eclipse_e-puck2</code> package, you have to add it to the <code>PATH</code> variable to be able to call it inside a terminal window. To set the <code>PATH</code> variable you need to issue the following command:
 
<code>export PATH=your_installation_path/Eclipse_e-puck2/Tools/gcc-arm-none-eabi-7-2017-q4-major/bin:$PATH</code>


===Serial Port===
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 <code>PATH</code> variable.
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.
If you want to set the <code>PATH</code> variable permanently, then you need to set it in the <code>.profile</code> file by issuing the command:<br>
<code>echo 'export PATH=your_installation_path/Eclipse_e-puck2/Tools/gcc-arm-none-eabi-7-2017-q4-major/bin:$PATH' >> ~/.profile</code><br>
Close and reopen the terminal before using your newly set environment variable.


<pre>sudo adduser $USER dialout</pre>
Note : The <code>arm-none-eabi</code> version can differ from the one given in this example. It could be needed to adapt the path to the correct version.


==Installation for Mac==
==Installation for Mac==
===Command Line Tools ===
===Command Line Tools ===
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>
To compile on Mac with <code>Eclipse_e-puck2</code>, it is necessary to have the <code>Command Line Tools</code> installed. It is a bundle of many commonly used tools.<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.
You can install it by typing the following command in a terminal window: <code>xcode-select --install</code>. It will then open a popup asking you if you want to install this bundle. Otherwise it will tell you it is already installed.
<pre>xcode-select --install</pre>


===Java 8===
===Java 8===
This section can be ignored if Java is already installed on your computer.<br>
This section can be ignored if Java is already installed on your computer.<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.
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: <code>/usr/libexec/java_home -V</code><br>
<pre>/usr/libexec/java_home -V</pre>
You need to have <code>AdoptOpenJDK 8</code> listed to be able to run <code>Eclipse_e-puck2</code>.
You need to have <code>Java SE 8</code> listed to be able to run Eclipse_e-puck2.


: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.
# Go to [https://adoptopenjdk.net/releases.html OpenJDK download page] and download the <code>OpenJDK 8 (LTS) HotSpot for MacOS x64 JDK</code> (take the installer, aka. <code>.pkg</code> file).
::For example: <code>jdk-8uXXX-macosx-x64.dmg</code>
# Open the <code>.pkg</code> file downloaded and follow the instructions to proceed with the installation of OpenJDK.
:2. Open the .dmg file downloaded, run the installer and follow the instructions to proceed with the installation of Java SDK.
:<span class="plain links">[https://projects.gctronic.com/epuck2/wiki_images/openjdk-mac.png <img width=700 src="https://projects.gctronic.com/epuck2/wiki_images/openjdk-mac.png">]</span><br/>
 
:''OpenJDK download page''
:<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/>
:''Java download page''


===Eclipse_e-puck2===
===Eclipse_e-puck2===
: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].
:1. Download the [https://projects.gctronic.com/epuck2/Eclipse_e-puck2/Eclipse_e-puck2_Mac_03.21.dmg Eclipse_e-puck2 package for Mac].
:2. Open the .dmg file downloaded and DragAndDrop the Eclipse_e-puck2.app into the Applications folder
:2. Open the <code>.dmg</code> file downloaded (confirm opening if a warning message appear) and ''drag and drop'' the <code>Eclipse_e-puck2.app</code> into the <code>Applications</code> folder
::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.
::Note: you can place the <code>Eclipse_e-puck2.app</code> anywhere, as long as the full path to it doesn’t contain any space, if you don’t want it to be in <code>Applications</code>.
:3. You can create an Alias to Eclipse_e-puck2.app and place it anywhere if you want.
:3. You can create an Alias to <code>Eclipse_e-puck2.app</code> and place it anywhere if you want.


===First launch and Gatekeeper===
===First launch and Gatekeeper===
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>
It’s very likely that <code>Gatekeeper</code> (one of the protections of Mac OS) will prevent you to launch <code>Eclipse_e-puck2.app</code> because it isn’t signed from a known developer.<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>
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>
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.
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 <code>Gatekeeper</code>.


To do so :
To do so :
Line 249: Line 123:
:1. Go to <code>System Preferences->security and privacy->General</code> and authorize downloaded application from <code>Anywhere</code>.
:1. Go to <code>System Preferences->security and privacy->General</code> and authorize downloaded application from <code>Anywhere</code>.


::<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/>
::<span class="plain links">[https://projects.gctronic.com/epuck2/wiki_images/security_tab_mac.png <img width=500 src="https://projects.gctronic.com/epuck2/wiki_images/security_tab_mac.png">]</span><br/>
::''Security settings of Mac OS''
::''Security settings of Mac OS''


::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.
::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>sudo spctl --master-disable</pre>
::<code>sudo spctl --master-disable</code>
:2. Now you can try to run the application and it should work.
:2. Now you can try to run the application and it should work.
:3. If Eclipse opened successfully, it is time to reactivate Gatekeeper. Simply set back the setting of Gatekeeper.
:3. If Eclipse opened successfully, it is time to reactivate <code>Gatekeeper</code>. Simply set back the setting of <code>Gatekeeper</code>.
::For the ones who needed to type a command to disable Gatekeeper, here is the command to reactivate it.
::For the ones who needed to type a command to disable <code>Gatekeeper</code>, here is the command to reactivate it.
::<pre>sudo spctl --master-enable</pre>
::<code>sudo spctl --master-enable</code>


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.
This procedure is only needed the first time. After that <code>Gatekeeper</code> 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 <code>Gatekeeper</code>.


'''Important things to avoid :'''
'''Important things to avoid :'''
:1. The path to the Eclipse_e-puck2.app must contain zero space.  
:1. The path to the <code>Eclipse_e-puck2.app</code> must contain zero space.  
::Example :
::Example :
::<code>/home/student/epfl_stuff/Eclipse_e-puck2</code> OK  
::<code>/home/student/epfl_stuff/Eclipse_e-puck2</code> OK  
::<code>/home/student/epfl stuff/Eclipse_e-puck2</code> NOT 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.
:2. The file’s structure in the <code>Eclipse_e-puck2.app</code> must remain the same. It means no file inside this app must be moved to another place.
 
===Configuring the PATH variable===
The <code>PATH</code> variable is an environment variable used to store a list of the paths to the folders containing the executables we can then run in a terminal from any path.
 
If you want to use the <code>arm-none-eabi</code> toolchain provided inside the <code>Eclipse_e-puck2</code> package, you have to add it to the <code>PATH</code> variable to be able to call it inside a terminal window. To set the <code>PATH</code> variable you need to issue the following command:
 
<code>export PATH=your_installation_path/Eclipse_e-puck2.app/Contents/Eclipse_e-puck2/Tools/gcc-arm-none-eabi-7-2017-q4-major/bin:$PATH</code>
 
If you put the <code>Eclipse_e-puck2.app</code> into the <code>Applications</code> folder then the exact command would be:


=Getting Started=
<code>export PATH=/Applications/Eclipse_e-puck2.app/Contents/Eclipse_e-puck2/Tools/gcc-arm-none-eabi-7-2017-q4-major/bin:$PATH</code>
===Meaning of the LEDs===
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/>
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 <code>PATH</code> variable.
::''Top view of the e-puck2''


*Charger : RED if charging, GREEN if charge complete and RED and GREEN if an error occurs
If you want to set the <code>PATH</code> variable permanently, then you need to set it in the <code>.bash_profile</code> file by issuing the command:<br>
*USB : Turned ON if the e-puck2 detects a USB connection with a computer
<code>echo 'export PATH=your_installation_path/Eclipse_e-puck2.app/Contents/Eclipse_e-puck2/Tools/gcc-arm-none-eabi-7-2017-q4-major/bin:$PATH' >> ~/.bash_profile</code><br>
*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.
Close and reopen the terminal before using your newly set environment variable.


Battery level indications (STATUS RGB LED):
Note : The <code>arm-none-eabi</code> version can differ from the one given in this example. It could be needed to adapt the path to the correct version.
*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.
=Get the source code=
The code of the e-puck2 is open source and is available as a git repository. To download the source code you need to install git on your system:
* Windows: downlaod git from [https://gitforwindows.org/ https://gitforwindows.org/] and follow the installation instructions (default configuration is ok)
* Linux: issue the command <code>sudo apt-get install git</code>
* Mac: issue the command <code>brew install git</code>


==Finding the USB serial ports used==
The source code can downloaded with the command:  <code>git clone --recursive https://github.com/e-puck2/e-puck2_main-processor.git</code><br/>
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):
The command must be issued in <code>Git bash</code> on Windows, or in a terminal on Linux / Mac.
* '''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.
This repository contains the main microcontroller factory firmware together with the e-puck2 library. This library includes all the functions needed to interact with the robot's sensors and actuators; the factory firmware shows how to use these functions.<br/>
===Windows===
 
#Open the Device Manager
A snapshot of the repository can be downloaded from [https://projects.gctronic.com/epuck2/e-puck2_main-processor_snapshot_17.03.20_1f56587.zip e-puck2_main-processor_snapshot_17.03.20.zip].<br/>
#Under '''Ports (COM & LPT)''' you can see the virtual ports connected to your computer.
 
#Do a '''Right-click -> properties''' on the COM port you want to identify.
=Creating a project=
#Go under the '''details''' tab and select '''Bus reported device description''' in the properties list.
==Main microcontroller factory firmware project==
#The name of the port should be written in the text box below.
If you want to modify the code of the factory firmware running on the main microcontroller, or if you want to have a look at the implementation details, then you can add this project in Eclipse by following the next steps:<br/>
#Once you found the desired device, you can simply look at its port number '''(COMX)'''.
:1 Run Eclipse and then select <code>File->New->Makefile Project with Existing Code</code>.
::<span class="plain links">[https://projects.gctronic.com/epuck2/wiki_images/e-puck2-dev3-1.png <img width=500 src="https://projects.gctronic.com/epuck2/wiki_images/e-puck2-dev3-1_small.png">]</span><br/>
:2 Next click on the <code>Browse</code> button and choose the project folder of the git repository downloaded previously (should be named <code>e-puck2_main-processor</code>) and set a project name (otherwise you can keep the one created by Eclipse). Choose <code>None</code> for the the toolchain.
:3 Click on the <code>Finish</code> button and the project is added to Eclipse.
::<span class="plain links">[https://projects.gctronic.com/epuck2/wiki_images/e-puck2-dev3-2.png <img width=500 src="https://projects.gctronic.com/epuck2/wiki_images/e-puck2-dev3-2_small.png">]</span><br/>
:4 Build the project by selecting one directory of the project from the left panel and then <code>Project->Build Project</code>.
 
==Project template==
The main microcontroller factory firmware project can also be used as a library to build your own project on top of it.<br>
 
To accomplish that, you have to copy the folder <code>Project_template</code>, contained in the <code>e-puck2_main-processor</code> project, and place it in the same directory of the <code>e-puck2_main-processor</code> project; you can of course rename the folder to the name you want (e.g. <code>myproject</code>). You must end up with the following directory tree:<br>
* e-puck2
** e-puck2_main-processor
** myproject


===Linux===
Then you can add this project in Eclipse by following the next steps:
:1. Open a terminal window (ctrl+alt+t) and enter the following command.
# Run Eclipse and then select <code>File->New->Makefile Project with Existing Code</code>.
:<pre>ls /dev/ttyACM*</pre>
# Next click on the <code>Browse</code> button and choose the project folder of your project (e.g. <code>myproject</code>) and set a project name (otherwise you can keep the one created by Eclipse). Choose <code>None</code> for the the toolchain.
:2. Look for '''ttyACM0''' and '''ttyACM1''' in the generated list, which are respectively '''e-puck2 GDB Server''' and '''e-puck2 Serial Monitor'''.
# Click on the <code>Finish</code> button and the project is added to Eclipse.
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.
# Select the project root folder and go to  <code>Project->Properties->C/C++ General->Preprocessor Include Paths, Macros etc->Providers</code> and check <code>CDT Cross GCC Built-in Compiler Settings</code>.<br> Then in the textbox below, write <code>arm-none-eabi-gcc ${FLAGS} -E -P -v -dD "${INPUTS}"</code>.
# Create a linked folder inside your project that links to the <code>e-puck2_main-processor</code> library. This allows Eclipse to index the declarations and implementations of the functions and variables in the code of the library.
##Select the project root folder and go to <code>File->New->Folder</code>.
##Check <code>Advanced >></code> on the bottom.
##Choose <code>Link to alternate location (Linked Folder)</code>.
##Type <code>PROJECT_LOC/../e-puck2_main-processor</code> and click the <code>Finish</code> button.
# Build the project by selecting one file of the project from the left panel and then <code>Project->Build Project</code>. The result of the compilation will appear in the <code>build</code> folder in your project folder.
# After you compile the project, select the project root folder and go to <code>Project->C/C++ Index->Rebuild</code> 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).


===Mac===
Now you can write your own program. If you want to add source files (<code>.c</code>) to the project you need to add them also in the <code>makefile</code>, in the <code>CSRC</code> definition. All the headers files (<code>.h</code>) located next to the <code>makefile</code> are automatically included in the compilation, but if you need to place them into folders, you have to specify these folders in the <code>makefile</code>, in the <code>INCDIR</code> definition. The same is needed for any desired <code>.h</code> files from other external folders.<br/>
:1. Open a terminal window and enter the following command.
In the <code>makefile</code> you can also set the name of your project.<br/>
:<pre>ls /dev/cu.usbmodem*</pre>
This <code>makefile</code> uses the main makefile of the <code>e-puck2_main-processor</code> project. This means you can add custom commands to the <code>makefile</code> but it should not interfere with the main makefile.
: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'''.


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.
=Configuring the Debugger's settings=
<code>Eclipse_e-puck2</code> 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 <code>Debug Configurations</code> icon of Eclipse (you can also find it on <code>Run->Debug Configurations</code>).
:<span class="plain links">[https://projects.gctronic.com/epuck2/wiki_images/Debug_configuration.png <img width=231 src="https://projects.gctronic.com/epuck2/wiki_images/Debug_configuration.png">]</span><br/>
Once in the settings, select <code>Generic Blackmagic Probe</code> preset on the left panel. Then you need to configure two things :


==Configuring the Debugger's settings==
# In the <code>main</code> tab, select which project to debug and the path to the compiled file. If the project has already been compiled, Eclipse should have indexed the binaries and you can list the project and the compiled files using respectively the <code>Browse...</code> and <code>Search Project...</code> buttons.<br/> If nothing is appearing when you press <code>Search Project...</code> then you must enter the <code>.elf</code> file name by hand, which can be found in your project <code>build</code> folder (e.g. <code>build/e-puck2_main-processor.elf</code>).
Eclipse_e-puck2 contains everything needed to compile, program and debug the e-puck2.<br>
# In the <code>Startup</code> tab, you need to replace the serial port name written on the first line of the text box by the one used by the GDB Server of your robot. [http://www.gctronic.com/doc/index.php?title=e-puck2#Finding_the_USB_serial_ports_used See how to find it].
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''').  
:* For Windows, it will be <code>\\.\COMX</code>, <code>X</code> being the port number.
:<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/>
:* For Linux, it will be <code>/dev/ttyACMX</code>, <code>X</code> being the port number
Once in the settings, select '''Generic Blackmagic Probe''' preset on the left panel. Then you need to configure two things :
:* For Mac, it will be <code>/dev/cu.usbmodemXXXXX</code>, <code>XXXXX</code> being the port number.
:* You can also type <code>${COM_PORT}</code> instead of the com port in order to use the variable <code>COM_PORT</code> for the debug configuration.<br>To change the value of this variable, go to the <code>main</code> tab again, click on the <code>Variables...</code> button and click on the <code>Edit Variables...</code> button. The opened window will let you edit the value of the variable.<br>Using the variable <code>COM_PORT</code> instead of the real com port in a debug configuration is useful if for example you have multiple debug configurations. If for some reason you need to change the serial port to use, then you can simply edit the variable <code>COM_PORT</code> instead of editing the serial port for each debug configuration.


#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 want to debug another project, you can duplicate this settings and change the relevant parts (project name and path to compiled file) in order to have one launch configuration for each project.<br/>
#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]].
:<span class="plain links">[https://projects.gctronic.com/epuck2/wiki_images/e-puck2-debug.jpg <img width=400 src="https://projects.gctronic.com/epuck2/wiki_images/e-puck2-debug-small.jpg">]</span><br/>
:* 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.
Now you should be able to use the debugger with Eclipse.
Now you should be able to use the debugger with Eclipse.


==Creating a project==
Notice that the settings are saved in the project folder in a file with extension <code>.launch</code>. If you want, you can rename this file (e.g. <code>Debug_project_template.launch</code>) with the name you want for the debug configuration of your project.
===Project template===
 
[https://github.com/e-puck2/e-puck2_main-processor.git e-puck2_main-processor] is a demo project containing all the libraries written for the e-puck2. <br>
=Running a debugging session=
It shows how to use them and can be interfaced with [[#PC interface | e-puck2 monitor]].<br>  
Once the debugger is configured, you can start a debugging session. When starting a session, the robot is programmed with the current developed program, thus starting a debugging session means also updating the main microcontroller firmware. This is in fact the way to update the firwmare via Eclipse; to do it manually refer to the section [http://www.gctronic.com/doc/index.php?title=e-puck2#Firmware_update Main microcontroller: firmware update].
But this project can also be used as a library to build your own project on top of it.<br>
 
To start a session follow the next steps:
# Connect the robot to the computer and turn it on
# From Eclipse, launch the debug configuration previously set: from the menu <code>Run->Debug configurations...</code>, select the configuration and click on the <code>Debug</code> button.<br>Alternatively you can directly select your configuration from the debugger drop-down menu.<br><span class="plain links">[https://projects.gctronic.com/epuck2/wiki_images/e-puck2-debug2.png <img width=350 src="https://projects.gctronic.com/epuck2/wiki_images/e-puck2-debug2.png">]</span><br/>
# When the debugging session is started, Eclipse will change the view to the <code>Debug perspective</code>. Right-click on the main process and select <code>Restart</code> to restart the program from the beginning<br><span class="plain links">[https://projects.gctronic.com/epuck2/wiki_images/e-puck2-debug3.png <img width=500 src="https://projects.gctronic.com/epuck2/wiki_images/e-puck2-debug3-small.png">]</span>
# Click on the <code>Resume</code> button on top of the window to start your program. Now you can suspend and resume whenever you want, then when you want to modify your code again you click on the <code>Terminate</code> button and click on the <code>C/C++ perspective</code> button.<br><span class="plain links">[https://projects.gctronic.com/epuck2/wiki_images/e-puck2-debug4.png <img width=500 src="https://projects.gctronic.com/epuck2/wiki_images/e-puck2-debug4-small.png">]</span>
 
==Adding breakpoints==


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>
==Watch variables==
You can of course rename the folder to the name you want.<br>


Then all you need to do is to edit the makefile to set the name of your project, the path to the e-puck2_main-processor folder, the .c files to include and the folder(s) to the .h files to include.<br>
==Analyze microcontroller registers content==
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.
When a debugging session is started, the microcontroller's registers state can be inspected by clicking on the <code>EmbSys Registers</code> tab on the top right side of the <code>Debug perspective</code>.
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.
<br><span class="plain links">[https://projects.gctronic.com/epuck2/wiki_images/e-puck2-debug5.png <img width=500 src="https://projects.gctronic.com/epuck2/wiki_images/e-puck2-debug5-small.png">]</span>


The result of the compilation will appear in a build folder in your project folder.
==Bluetooth debugging session==
It is possible to run a debugging session remotely thorugh Bluetooth following these steps:
# change the programmer's mode to <code>mode 1</code> with the command <code>monitor select_mode 1</code>, for more informations refer to [https://www.gctronic.com/doc/index.php?title=e-puck2_programmer_development e-puck2 programmer development], chapter <code>Configuring the Programmer's settings</code>
# pair the robot with the computer
# in the debugger's settings, setup the port with the <code>Bluetooth channel 1, GDB port</code> name, for more informations refer to [https://www.gctronic.com/doc/index.php?title=e-puck2_PC_side_development#Connecting_to_the_Bluetooth Connecting to the Bluetooth]
# start the debugging session and the Bluetooth connection will be established automatically; now you can program/debug the robot remotely


===Adding to Eclipse_epuck2===
Beware that GDB over the Bluetooth connection of the e-puck2 is much slower than with USB and it doesn't work with Windows due to GDB limitations on this OS.
#To add the project into Eclipse, you need to select '''File->New->Makefile Project with Existing Code'''.
#Next choose your project folder and set a project name. Choose '''None''' for the the toolchain.
#Click on the '''Finish''' button and the project is added to Eclipse.
#Rename the file '''Debug_project_template.launch''' contained in the project folder by the name you want for the debug configuration of your project.
#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]]).
#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.
#Compile the project and if it succeeded, 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.
=Local communication=
Local range infrared communication between e-puck2 robots can be achieved using the infrared sensors of the robots to transmit and receive information. The communication system is multiplexed with the proximity sensing system commonly used on the robots, thus it is possible to both communicate and avoid obstacles.<br/>


==Flashing the main microcontroller==
The implementation is based on the [http://www.e-puck.org/index.php?option=com_content&view=article&id=32&Itemid=28 libIrcom] library developed for the e-puck version 1 robots and it keeps retro-compatibility. This means that an e-puck version 1 is able to communicate with an e-puck version 2, so you can still use your e-puck version 1 robots together with e-puck version 2 to form a bigger fleet of robots for your experiments. Moreover the API is the same, thus the code developed for the e-puck version 1 can be used easily also with the e-puck version 2.<br/>
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/>
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:
<pre>target extended-remote \\.\COM72
monitor swdp_scan
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
Here are some details about the current implementation of the local communication module:
<pre>Windows: arm-none-eabi-gdb.exe --interpreter=mi -x mygdbinit firmware.elf
* messages are encoded using a frequency modulation that permits usage in a wide range of light conditions
Linux/Mac: arm-none-eabi-gdb --interpreter=mi -x mygdbinit firmware.elf</pre>
* the module allows communications at a rate of up to 30 bytes per seconds (maximum theoretical throughput)
In this command you need to change the name of the firmware with the one you have.<br/>
* support half-duplex communication
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>.
* use the infrared sensors to exchange data, thus during reception/transmission the proximity sensors cannot be used to avoid obstacles; the sensors update frequency is at most 5 Hz
* messages can be detected at a distance of about 7 cm (good reception), and even up to 12-13 cm (sparse reception)
* messages are stored in a queue (up to 20 messages) and can be retrieved at any time, unless they are overwritten when the queue is full


When the upload is complete you'll see an output like in the following figure:<br/>
The local communication module is integrated in the factory firmware, so if you want to have a look at the code refer to section [https://www.gctronic.com/doc/index.php?title=e-puck2_robot_side_development#Get_the_source_code Get the source code].<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/>
A simple exmaple exploiting the local communication can be found in the factory firmware. Put the selector in position 9 and connect the USB cable to the robot: the messages received will be printed in the terminal while the robot continuously send messages to other robots (transceiver behavior). The body led is toggled at each message reception.


If you encounter some problem, try to unplug and plug again the USB cable and power cycle the robot, then retry.
If an higher throughput and a longer communication distance are required, there is the [http://www.gctronic.com/doc/index.php/Others_Extensions#Range_and_bearing range and bearing extension] designed for this purpose.


==Flashing the WiFi module==
==Synchronize example==
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. This script was modified to work with the e-puck2 and is available from the following link:
This is a more advanced example exploiting the local communication. Basically the robots programmed with this demo will eventually orient themselves in the same direction, this is accomplished by exchanging data locally between them.
* 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 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/>
The same example is also available for e-puck version 1 robots (see [http://www.e-puck.org/index.php?option=com_content&view=article&id=32&Itemid=28 libIrcom]), so you can test it with a mix of robots.
<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/>
When the upload is complete you'll see that all 3 bin files are uploaded correctly as shown in the following figure:<br/>
<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/>


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/>
The pre-built firmware is available here [https://projects.gctronic.com/epuck2/e-puck2_example_synchronize_10.12.19_734d1f7.elf e-puck2_example_synchronize.elf (10.12.19)].
<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>
<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==
===Usage===
When the robot is turned on, it starts exchanging information with other robots and try to align with them.<br/>
Beware that the selector position is taken as the id of the robot, so you need to place the selector in a different position for each robot.<br/>
Basically you need to put the selector in an unused position, turn on the robot and place it near the others. The robots will eventually align in the same direction.


The default firmware in the ESP32, the module which provides Bluetooth and Wi-Fi connectivity, creates 3 Bluetooth channels using the RFcomm protocol:
===Building===
# 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)
First of all download the source code with the command: <code>git clone https://github.com/e-puck2/e-puck2_example_synchronize.git</code><br/>
# Channel 2, UART: port to connect to the UART port of the main processor
The command must be issued in <code>Git bash</code> on Windows, or in a terminal on Linux / Mac.<br/>
# Channel 3, SPI: port to connect to the SPI port of the main processor (not yet implemented. Just do an echo for now)
Place the cloned repo folder <code>e-puck2_example_synchronize</code> in the same directory of the <code>e-puck2_main-processor</code> project; you must end up with the following directory tree:<br>
* e-puck2
** e-puck2_main-processor
** e-puck2_example_synchronize


By default, the e-puck2 is not visible when you search for it in the Bluetooth utility of your computer.<br>
Then you can add this project in Eclipse by following the next steps:
'''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>
# Run Eclipse and then select <code>File->New->Makefile Project with Existing Code</code>.
Then it will be discoverable and you will be able to pair with it.<br>
# Next click on the <code>Browse</code> button and choose the project folder <code>e-puck2_example_synchronize</code>. Choose <code>None</code> for the the toolchain.
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.
# Click on the <code>Finish</code> button and the project is added to Eclipse.
# Select the project root folder and go to  <code>Project->Properties->C/C++ General->Preprocessor Include Paths, Macros etc->Providers</code> and check <code>CDT Cross GCC Built-in Compiler Settings</code>.<br> Then in the textbox below, write <code>arm-none-eabi-gcc ${FLAGS} -E -P -v -dD "${INPUTS}"</code>.
# Create a linked folder inside your project that links to the <code>e-puck2_main-processor</code> library. This allows Eclipse to index the declarations and implementations of the functions and variables in the code of the library.
##Select the project root folder and go to <code>File->New->Folder</code>.
##Check <code>Advanced >></code> on the bottom.
##Choose <code>Link to alternate location (Linked Folder)</code>.
##Type <code>PROJECT_LOC/../e-puck2_main-processor</code> and click the <code>Finish</code> button.
# Build the project by selecting one file of the project from the left panel and then <code>Project->Build Project</code>. The result of the compilation will appear in the <code>build</code> folder in your project folder.
# After you compile the project, select the project root folder and go to <code>Project->C/C++ Index->Rebuild</code> 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).


===Windows 7===
==Master-slave example==
When you pair your computer with the e-puck2, 3 COM ports will be automatically created.
For this example two robots equipped with the [https://www.gctronic.com/doc/index.php?title=Others_Extensions#Ground_sensors ground sensors extension] are needed: one acts as a master (transmitter) and the other as a slave (receiver). The master send a command (1 byte) to the slave indicating the current color of its RGB LEDs and the slave when receives the command, interpret it and set its RGB LEDs color to the same color of the master. The ground sensors extension is used to move the robots along a black line in order to follow a desired path.
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="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>


===Windows 10===
The pre-built firmware is available here [https://projects.gctronic.com/epuck2/e-puck2_example_master_slave_03.03.20_00311f3.elf e-puck2_example_master_slave.elf (03.03.20)].
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===
===Usage===
Once paired with the Bluetooth manager, you need to create the port for communicating with the robot by issueing the command: <br/>
Program the two robots with this demo and set the selector to position 0 for one robot (master) and position 1 (any position but zero would be ok) for the other (slave).<br/>
<code>sudo rfcomm bind /dev/rfcomm0 MAC_ADDR 2</code><br/>
Print this [https://projects.gctronic.com/epuck2/master-slave-path.pdf master-slave-path.pdf] and place the master on one side and the slave in the other side.<br/>
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.
Both robots will move back and forth and when they encounter each other, the master will send its RGB LEDs state to the slave that will reflect the same state on its own RGB LEDs.<br/>
You can try different paths and also add more robots with slighly modifications to the code, this is only a starting point.<br/>
Beware that the robots will detect each other thanks to the proximity sensors values and they start to exchange data only when they're facing each other. This behavior can be changed by continuously exchanging data, in this way you can play also with different distances between the robot's path.


===Mac===
===Building===
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.
First of all download the source code with the command: <code>git clone https://github.com/e-puck2/e-puck2_example_master_slave.git</code><br/>
The command must be issued in <code>Git bash</code> on Windows, or in a terminal on Linux / Mac.<br/>
Place the cloned repo folder <code>e-puck2_example_master_slave</code> in the same directory of the <code>e-puck2_main-processor</code> project; you must end up with the following directory tree:<br>
* e-puck2
** e-puck2_main-processor
** e-puck2_example_master_slave


==Connecting to the WiFi==
Then you can add this project in Eclipse by following the next steps:
At the moment the WiFi channel is used to transfer the image to the computer. A QQVGA color image is transfered.<br/>
# Run Eclipse and then select <code>File->New->Makefile Project with Existing Code</code>.
A dedicated configuration is needed to use the WiFi:
# Next click on the <code>Browse</code> button and choose the project folder <code>e-puck2_example_master_slave</code>. Choose <code>None</code> for the the toolchain.
# [http://projects.gctronic.com/epuck2/e-puck2_main-processor_wifi.elf main microcontroller 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
# Click on the <code>Finish</code> button and the project is added to Eclipse.
# [http://projects.gctronic.com/epuck2/esp32-firmware-wifi.zip WiFi module firmware] (see chapter [http://www.gctronic.com/doc/index.php?title=e-puck2#Flashing_the_WiFi_module Flashing the WiFi module] to update the firmware)
# Select the project root folder and go to  <code>Project->Properties->C/C++ General->Preprocessor Include Paths, Macros etc->Providers</code> and check <code>CDT Cross GCC Built-in Compiler Settings</code>.<br> Then in the textbox below, write <code>arm-none-eabi-gcc ${FLAGS} -E -P -v -dD "${INPUTS}"</code>.
# PC application: [http://projects.gctronic.com/epuck2/esp32-wifi-pc.zip Windows executable]
# Create a linked folder inside your project that links to the <code>e-puck2_main-processor</code> library. This allows Eclipse to index the declarations and implementations of the functions and variables in the code of the library.
##Select the project root folder and go to <code>File->New->Folder</code>.
##Check <code>Advanced >></code> on the bottom.
##Choose <code>Link to alternate location (Linked Folder)</code>.
##Type <code>PROJECT_LOC/../e-puck2_main-processor</code> and click the <code>Finish</code> button.
# Build the project by selecting one file of the project from the left panel and then <code>Project->Build Project</code>. The result of the compilation will appear in the <code>build</code> folder in your project folder.
# After you compile the project, select the project root folder and go to <code>Project->C/C++ Index->Rebuild</code> 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).


The LED2 is used to indicate the state of the WiFi connection:
=Example projects=
* red indicate that the robot is in Access Point mode
==Digital Signal Processing (DSP) and wav playback==
* green indicate that the robot is connected to a network and has received an IP
In this example the [http://www.keil.com/pack/doc/CMSIS/DSP/html/index.html CMSIS-DSP] library is used to compute the Fast Fourier Transform of the signal coming from the microphones. The processing power of the main microntroller let the signal to be processed continuously. Moreover this example shows how to play wav files stored in the micro sd.<br/>
* blue (toggling) indicate that the robot is transferring the image to the computer


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 pre-built firmware is available here [https://projects.gctronic.com/epuck2/e-puck2_example_dsp_05.10.18_3aa8b81.elf e-puck2_example_dsp.elf (05.10.18)].


The AP SSID will be <code>e-puck2_0XXXX</code> where <code>XXXX</code> is the id of the robot; no password needed to connect to the AP.<br/>
===Usage===
Then from the device that is connected to the robot (e.g. a phone), open a browser and insert the address <code>192.168.1.1</code>. In this page will be visualized the available networks that we can connect to as shown in figure 1. Select one from the list and enter the password; if the password is correct you'll get a message saying that the connection was sucessfull as shown in figure 2. After pressing <code>OK</code> you will be redirected to main page that shows the network to which you're connected and the others available nearby as shown in figure 3. Select the one you're connected to see your IP address as shown in figure 4; take note of the address since it will be needed later.<br/>
There are basically two demos in this example, one run on selector position 0 and the other in selector position 1.<br/>


<span class="plainlinks">
When the selector is in position 0, then the resulting frequency (max amplitude bin) of the computed FFT is mapped to the RGB LEDs: LEDs will be blue when frequency detected is around 250..900 Hz, green when frequency is around 900..1500 Hz and red with 1500..2200 Hz. The brightness of the LEDs is also changed with the frequency.<br/>
<table>
The distance sensor (ToF) is also used to detect people in front of the robot. When someone is detected within 50 cm, then the measured distance is mapped to a frequency emitted through the speaker; the generated tone is between 260 Hz (far) and 2240 Hz (near). You can use your hand to play some melody, the robot in the meantime will detect the frequency and show it through the RGB.<br/>
<tr>
 
<td align="center">[1]</td>
When the selector is in position 1, the robot will play a wav file stored in the micro sd when one of the proximity sensors is "touched" (with your finger you go near the proximity and then you go away, like pressing a button). For each proximity there is a different wav file that will be played: for proximity 0 it will be played <code>0.wav</code>, for proximity 1 it will be played <code>1.wav</code> and so on till proximity 7 with <code>7.wav</code>.<br/>
<td align="center">[2]</td>
 
<td align="center">[3]</td>
All the wav files you need are stored in the <code>wav</code> directory within the project, put all of them in a micro sd partitioned in FAT32 and you're ready to go. Alternatively you can play your own wav files, beware to name them from <code>0.wav</code> to <code>7.wav</code> and they must be 16 KHz, mono.
<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.<br/>


Turn off the robot and turn it on again, the robot will try to connect to the previously saved configuration. Once connected the LED2 will be green.
===Building===
First of all download the source code with the command:  <code>git clone https://github.com/e-puck2/e-puck2_example_dsp.git</code><br/>
The command must be issued in <code>Git bash</code> on Windows, or in a terminal on Linux / Mac.<br/>
Place the cloned repo folder <code>e-puck2_example_dsp</code> in the same directory of the <code>e-puck2_main-processor</code> project; you must end up with the following directory tree:<br>
* e-puck2
** e-puck2_main-processor
** e-puck2_example_dsp


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.
Then you can add this project in Eclipse by following the next steps:
# Run Eclipse and then select <code>File->New->Makefile Project with Existing Code</code>.
# Next click on the <code>Browse</code> button and choose the project folder <code>e-puck2_example_dsp</code>. Choose <code>None</code> for the the toolchain.
# Click on the <code>Finish</code> button and the project is added to Eclipse.
# Select the project root folder and go to  <code>Project->Properties->C/C++ General->Preprocessor Include Paths, Macros etc->Providers</code> and check <code>CDT Cross GCC Built-in Compiler Settings</code>.<br> Then in the textbox below, write <code>arm-none-eabi-gcc ${FLAGS} -E -P -v -dD "${INPUTS}"</code>.
# Create a linked folder inside your project that links to the <code>e-puck2_main-processor</code> library. This allows Eclipse to index the declarations and implementations of the functions and variables in the code of the library.
##Select the project root folder and go to <code>File->New->Folder</code>.
##Check <code>Advanced >></code> on the bottom.
##Choose <code>Link to alternate location (Linked Folder)</code>.
##Type <code>PROJECT_LOC/../e-puck2_main-processor</code> and click the <code>Finish</code> button.
# Build the project by selecting one file of the project from the left panel and then <code>Project->Build Project</code>. The result of the compilation will appear in the <code>build</code> folder in your project folder.
# After you compile the project, select the project root folder and go to <code>Project->C/C++ Index->Rebuild</code> 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).


==Configuring the PATH variable==
==Microphones recording and pitch scaling==
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.
This example shows how to record the audio (voice) from the onboard microphones and save it in the micro SD.<br/>
Moreover it applies a pitch scaling algorithm to the data before playing it from the micro SD.<br/>
The pitch scale processing is based on the SOLA algorithm and a simple implementation is available from the following link [https://www.surina.net/article/time-and-pitch-scaling.html https://www.surina.net/article/time-and-pitch-scaling.html]. Have a look at this site bacause it has a good explanation of the algorithm.<br/>


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.
The pre-built firmware is available here [https://projects.gctronic.com/epuck2/e-puck2_example_pitch_scale_07.11.18_26d16f0.elf e-puck2_example_pitch_scale.elf (07.11.18)].


Setting the PATH variable for Windows :
===Usage===
<pre>set PATH=your_installation_path\Eclipse_e-puck2\Tools\gcc-arm-none-eabi-7-2017-q4-major-win32\bin;%PATH%</pre>
The example requires a micro SD (FAT32) inserted in the robot.<br/>
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.
When the robot is turned on, it waits for the button press that triggers the recording. The voice is recorded for about 2 seconds and saved into the micro SD as wav
file. Once the recording is finished, the pitch scale is applied and then the modified voice is played.<br/>


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.
You can choose whether to get an higher or lower pitch by changing the <code>TIME_SCALE</code> parameter in <code>sola.c</code>:
* if you want to get an higher pitch, then change <code>TIME_SCALE</code> to a value > 1.0
* if you want to get a lower pitch, then change the <code>TIME_SCALE</code> to a value < 1.0
Of course, if the parameter is changed, you need to rebuild the project and reflash the robot.


=Software=
===Building===
==PC interface==
First of all download the source code with the command:  <code>git clone https://github.com/e-puck2/e-puck2_example_pitch_scale.git</code><br/>
<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/>
The command must be issued in <code>Git bash</code> on Windows, or in a terminal on Linux / Mac.<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].
Place the cloned repo folder <code>e-puck2_example_pitch_scale</code> in the same directory of the <code>e-puck2_main-processor</code> project; you must end up with the following directory tree:<br>
Available executables:
* e-puck2
* [http://projects.gctronic.com/epuck2/monitor_win.zip Windows executable]: tested on Windows 7 and Windows 10
** e-puck2_main-processor
* [http://projects.gctronic.com/epuck2/monitor_mac.zip Max OS X executable]
** e-puck2_example_pitch_scale


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.
Then you can add this project in Eclipse by following the next steps:
# Run Eclipse and then select <code>File->New->Makefile Project with Existing Code</code>.
# Next click on the <code>Browse</code> button and choose the project folder <code>e-puck2_example_pitch_scale</code>. Choose <code>None</code> for the the toolchain.
# Click on the <code>Finish</code> button and the project is added to Eclipse.
# Select the project root folder and go to  <code>Project->Properties->C/C++ General->Preprocessor Include Paths, Macros etc->Providers</code> and check <code>CDT Cross GCC Built-in Compiler Settings</code>.<br> Then in the textbox below, write <code>arm-none-eabi-gcc ${FLAGS} -E -P -v -dD "${INPUTS}"</code>.
# Create a linked folder inside your project that links to the <code>e-puck2_main-processor</code> library. This allows Eclipse to index the declarations and implementations of the functions and variables in the code of the library.
##Select the project root folder and go to <code>File->New->Folder</code>.
##Check <code>Advanced >></code> on the bottom.
##Choose <code>Link to alternate location (Linked Folder)</code>.
##Type <code>PROJECT_LOC/../e-puck2_main-processor</code> and click the <code>Finish</code> button.
# Build the project by selecting one file of the project from the left panel and then <code>Project->Build Project</code>. The result of the compilation will appear in the <code>build</code> folder in your project folder.
# After you compile the project, select the project root folder and go to <code>Project->C/C++ Index->Rebuild</code> 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).


==Standard firmware==
==C++==
The robot is initially programmed with a firmware that includes many demos that could be started based on the selector position:
A basic example showing how to integrate C++ code in your project is available in the following repository: [https://github.com/e-puck2/e-puck2_cpp https://github.com/e-puck2/e-puck2_cpp].<br/>
* Selector position 0: Aseba
The example demonstrates simple usage of a class and for range loops.
* Selector position 1: Shell
* Selector position 2: Read proximity sensors
* Selector position 3: Asercom protocol v2 (BT)
* Selector positoin 4: Read IMU raw sensors values
* Selector position 5: Distance sensor reading
* 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: ...
* Selector position 15: ...
The full 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_16.02.18_13fa922.elf e-puck2 firmware].


==Library==
===Building===
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.zip].<br/>
First of all download the source code with the command:  <code>git clone https://github.com/e-puck2/e-puck2_cpp.git</code><br/>  
The latest version can be downloaded with the command: <code>git clone --recursive https://github.com/e-puck2/e-puck2_main-processor.git</code>
The command must be issued in <code>Git bash</code> on Windows, or in a terminal on Linux / Mac.<br/>
Place the cloned repo folder <code>e-puck2_cpp</code> in the same directory of the <code>e-puck2_main-processor</code> project; you must end up with the following directory tree:<br>
* e-puck2
** e-puck2_main-processor
** e-puck2_cpp


=Advanced usage=
Then you can add this project in Eclipse by following the next steps:
==Flashing the programmer==
# Run Eclipse and then select <code>File->New->Makefile Project with Existing Code</code>.
==Configuring the Programmer's settings==
# Next click on the <code>Browse</code> button and choose the project folder <code>e-puck2_cpp</code>. Choose <code>None</code> for the the toolchain.
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>
# Click on the <code>Finish</code> button and the project is added to Eclipse.
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.  
# Select the project root folder and go to  <code>Project->Properties->C/C++ General->Preprocessor Include Paths, Macros etc->Providers</code> and check <code>CDT Cross GCC Built-in Compiler Settings</code>.<br> Then in the textbox below, write <code>arm-none-eabi-gcc ${FLAGS} -E -P -v -dD "${INPUTS}"</code>.
# Create a linked folder inside your project that links to the <code>e-puck2_main-processor</code> library. This allows Eclipse to index the declarations and implementations of the functions and variables in the code of the library.
##Select the project root folder and go to <code>File->New->Folder</code>.
##Check <code>Advanced >></code> on the bottom.
##Choose <code>Link to alternate location (Linked Folder)</code>.
##Type <code>PROJECT_LOC/../e-puck2_main-processor</code> and click the <code>Finish</code> button.
# Build the project by selecting one file of the project from the left panel and then <code>Project->Build Project</code>. The result of the compilation will appear in the <code>build</code> folder in your project folder.
# After you compile the project, select the project root folder and go to <code>Project->C/C++ Index->Rebuild</code> 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).


To access to the available commands of the programmer, it is needed to connect to the programmer with a GDB console. <br>
==Bluetooth echo==
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 :
The aim of this example is to show how to exchange data between the robot and the computer through a Bluetooth connection. The project implements a simple echo behavior, that is what is received by the robot is sent back to the computer.
<pre>
arm-none-eabi-gdb
target extended-remote your_gdb_com_port
</pre>


Once connected to the programmer with GDB, you can type
===Building===
<pre>monitor help</pre> or <pre>mon help</pre> to print the available commands of the programmer.
First of all download the source code with the command:  <code>git clone https://github.com/e-puck2/e-puck2_example_bluetooth_echo.git</code><br/>
The command must be issued in <code>Git bash</code> on Windows, or in a terminal on Linux / Mac.<br/>
Place the cloned repo folder <code>e-puck2_example_bluetooth_echo</code> in the same directory of the <code>e-puck2_main-processor</code> project; you must end up with the following directory tree:<br>
* e-puck2
** e-puck2_main-processor
** e-puck2_example_bluetooth_echo


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>
Then you can add this project in Eclipse by following the next steps:
mode 1 = the serial monitor is connected to the UART port of the main processor<br>
# Run Eclipse and then select <code>File->New->Makefile Project with Existing Code</code>.
mode 2 = the serial monitor is connected to the UART of the ESP32<br>
# Next click on the <code>Browse</code> button and choose the project folder <code>e-puck2_example_bluetooth_echo</code>. Choose <code>None</code> for the the toolchain.
mode 3 = the serial monitor works as a Aseba CAN to USB translator<br>
# Click on the <code>Finish</code> button and the project is added to Eclipse.
# Select the project root folder and go to <code>Project->Properties->C/C++ General->Preprocessor Include Paths, Macros etc->Providers</code> and check <code>CDT Cross GCC Built-in Compiler Settings</code>.<br> Then in the textbox below, write <code>arm-none-eabi-gcc ${FLAGS} -E -P -v -dD "${INPUTS}"</code>.
# Create a linked folder inside your project that links to the <code>e-puck2_main-processor</code> library. This allows Eclipse to index the declarations and implementations of the functions and variables in the code of the library.
##Select the project root folder and go to <code>File->New->Folder</code>.
##Check <code>Advanced >></code> on the bottom.
##Choose <code>Link to alternate location (Linked Folder)</code>.
##Type <code>PROJECT_LOC/../e-puck2_main-processor</code> and click the <code>Finish</code> button.
# Build the project by selecting one file of the project from the left panel and then <code>Project->Build Project</code>. The result of the compilation will appear in the <code>build</code> folder in your project folder.
# After you compile the project, select the project root folder and go to <code>Project->C/C++ Index->Rebuild</code> 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).


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.
==Ball detection==
Pierre Oppliger and WIlliam Galand, during their semester project at EPFL, were able to let the e-puck2 robot reliably recognize a ball independently of light conditions. This is a step towards an e-puck2 football soccer player. For more information about the project (French) and source code, have a look at the repository [https://github.com/e-puck2/e-puck-2-footy https://github.com/e-puck2/e-puck-2-footy].


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.
=Firmware update using factory bootloader=
==Factory firmware==
The pre-built firmware is available here [https://projects.gctronic.com/epuck2/e-puck2_main-processor_29.03.23_6363512.bin  main microcontroller factory firmware.bin (29.03.23)]; it is also available in dfu format here [https://projects.gctronic.com/epuck2/e-puck2_main-processor_29.03.23_6363512.dfu main microcontroller factory firmware.dfu (29.03.23)].


By being connected with GDB, you can also use the standard GDB command to program and debug the main processor of the e-puck2.
==Firmware update==
This procedure should be used only if the normal firmware update steps described in the section [http://www.gctronic.com/doc/index.php?title=e-puck2#Firmware_update Main microcontroller: firmware update] don't work. This is a recovery procedure.<br/>


==Using the DFU==
The main microcontroller features a factory bootloader that can be entered by acting on some special pins, the bootloader mode is called DFU (device firmware upgrade). You can enter DFU mode by first connecting the USB cable, then pressing the button called <code>407 boot</code> while turning on the robot. The button is located near the left wheel, on the bottom side of the electronic board, see the photo below.
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 :
::<span class="plain links">[https://projects.gctronic.com/epuck2/wiki_images/F407-dfu.jpg <img width=200 src="https://projects.gctronic.com/epuck2/wiki_images/F407-dfu-small.jpg">]</span><br/>
<pre>dfu-util -d 0483:df11 -a 0 -s 0x08000000 -D your_firmware.bin</pre>
::''Location of the button to put the main microcontroller into DFU''


See the [http://dfu-util.sourceforge.net/dfu-util.1.html manual page] of dfu-util for further information on how to use it.
The main microcontroller will be recognized as <code>STM Device in DFU Mode</code> device.


Note : For windows, it is needed to install a libusbK driver for the DFU device. <br>
'''Note for Windows users''': the device should be recognized automatically (in all Windows versions), but in case it won't be detected then you need to install a <code>libusbK</code> 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 in section [http://www.gctronic.com/doc/index.php?title=e-puck2#Installing_the_USB_drivers Installing the USB drivers] using <code>libusbK</code> driver instead of <code>USB Serial (CDC)</code>.<br/>
Follow the same procedure as explained above under the [[#Drivers | Installation drivers]] section using libusbK driver instead of USB Serial (CDC).
If you still have problems, try to install the drivers you can find in <code>C:\Program Files (x86)\STMicroelectronics\Software\DfuSe v3.0.6\Bin\Driver</code>.


Note 2 : It is also possible to put the programmer in DFU by contacting two pinholes together while turning ON the robot.<br>
===Linux/Mac===
It is used to update the firmware of the programmer.<br>
In order to update the main microcontroller firmware you need an utility called <code>dfu-util</code>, it should be already installed from section [http://www.gctronic.com/doc/index.php?title=e-puck2#Installing_the_dependencies_for_firmwares_updates Installing the dependencies for firmwares updates].<br/>
The two pin holes are located near the USB connector of the e-puck2, see the photo below.
To uplaod the firmware, issue the following command: <code>sudo dfu-util -d 0483:df11 -a 0 -s 0x08000000 -D your_firmware.bin</code> (the name of the bin file must be changed accordingly).


::<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/>
===Windows===
::''Location of the pin holes to put the programmer into DFU''
Start the <code>DfuSe</code> application (previously installed from section [http://www.gctronic.com/doc/index.php?title=e-puck2#Installing_the_dependencies_for_firmwares_updates Installing the dependencies for firmwares updates]). 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 with <code>dfu</code> extension,  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>[https://projects.gctronic.com/epuck2/wiki_images/dfu1.png <img width=250 src="https://projects.gctronic.com/epuck2/wiki_images/dfu1.png">]</td>
<td>[https://projects.gctronic.com/epuck2/wiki_images/dfu2_f407.png <img width=250 src="https://projects.gctronic.com/epuck2/wiki_images/dfu2_f407.png">]</td>
<td>[https://projects.gctronic.com/epuck2/wiki_images/dfu3.png <img width=250 src="https://projects.gctronic.com/epuck2/wiki_images/dfu3.png">]</td>
<td>[https://projects.gctronic.com/epuck2/wiki_images/dfu4.png <img width=250 src="https://projects.gctronic.com/epuck2/wiki_images/dfu4.png">]</td>
</tr>
</table>
</span><br/>

Revision as of 13:59, 29 March 2023

e-puck2 main wiki

Introduction

The C programming language is used to develop code for the main microcontroller of the e-puck2 robot. The ChibiOS embedded real-time OS was chosen to be integrated in the firmware, since it support the STM32F4 family of microprocessors, it includes an HAL (Hardware Abstraction Layer), it's well documented and finally it's free.
Before starting to code, you need to install the developing environment and its dependencies, all the steps are documented afterwards.
The factory firmware integrates both the e-puck2 library used to handle all the sensors and actuators together with a series of demos that use this library. Thus you can either take the factory firmware and directly modify its main, otherwise you can start a fresh new project by linking the factory firmware project as an external library.
You can also modify the library itself, but before digging into the details, try to contact us, maybe we're already working on that subject or we can help you.

Installation of the e-puck2 environment

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.

Installation for Windows

Java 8 32bits

This section can be ignored if Java version >= 8 32bits is already installed on your computer.
To verify you already installed Java, you can open Programs and Features from the control panel and search for a AdoptOpenJDK JDK with Hotspot xxx install. If this entry isn't present, then you need to install it:

  1. Go to OpenJDK download page and download the OpenJDK 8 (LTS) HotSpot for Windows x86 JDK (take the installer, aka. .msi file).
  2. Run the downloaded installer and follow its instructions to proceed with the installation of OpenJDK 32bits.

OpenJDK download page

Eclipse_e-puck2

  1. Download the Eclipse_e-puck2 package for windows.
  2. 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.
  3. You can now run the Eclipse_e-puck2.exe to launch Eclipse.
  4. You can create a shortcut to Eclipse_e-puck2.exe and place it anywhere if you want.

Eclipse_e-puck2 folder obtained after extraction

Important things to avoid :

1. The path to the Eclipse_e-puck2 folder must contain zero space.
Example :
C:\epfl_stuff\Eclipse_e-puck2 OK
C:\epfl stuff\Eclipse_e-puck2 NOT OK
2. You must not put Eclipse_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.

Configuring the PATH variable

The PATH variable is an environment variable used to store a list of the paths to the folders containing the executables we can then run in a terminal from any path.

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. To set the PATH variable you need to issue the following command:

set PATH=your_installation_path\Eclipse_e-puck2\Tools\gcc-arm-none-eabi-7-2017-q4-major-win32\bin;%PATH%

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.

If you want to set the PATH variable permanently, then go to Control panel => System => Advanced system settings => Environment variables. A list of variables defined for the user is shown, double click on the PATH variable (from the user variables list) and add at the end ;your_installation_path\Eclipse_e-puck2\Tools\gcc-arm-none-eabi-7-2017-q4-major-win32\bin, then click OK three times.

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.

Installation for Linux

Java 8

This section can be ignored if Java is already installed on your computer.
To verify whether it is installed or not you can type the following command into a terminal window: update-java-alternatives -l. If Java is installed, you will get some information about it, otherwise the command will be unknown.
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:

sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk-8-jre 

Eclipse_e-puck2

  1. Install make (probably you already have it installed) by issueing the command: sudo apt-get install make
  2. Download the Eclipse_e-puck2 package for Linux 32bits / 64bits. Pay attention to the 32bits or 64bits version. If unsure which Linux version you have, enter the following comand uname -a in the terminal window and look for i686 (32bit) or x86_64 (64 bit).
  3. Extract the downloaded file to the location you want (can take time): tar -zxvf package_name.tar.gz
  4. You can now run the Eclipse_e-puck2 executable to launch Eclipse.

Eclipse_e-puck2 folder obtained after extraction

Note : The icon of the Eclipse_e-puck2 executable will appear after the first launch of the program.

Important things to avoid :

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 resources located in the Eclipse_e-puck2 folder.
2. The path to the Eclipse_e-puck2 folder must contain zero space.
Example :
/home/student/epfl_stuff/Eclipse_e-puck2 OK
/home/student/epfl stuff/Eclipse_e-puck2 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.

Configuring the PATH variable

The PATH variable is an environment variable used to store a list of the paths to the folders containing the executables we can then run in a terminal from any path.

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. To set the PATH variable you need to issue the following command:

export PATH=your_installation_path/Eclipse_e-puck2/Tools/gcc-arm-none-eabi-7-2017-q4-major/bin:$PATH

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.

If you want to set the PATH variable permanently, then you need to set it in the .profile file by issuing the command:
echo 'export PATH=your_installation_path/Eclipse_e-puck2/Tools/gcc-arm-none-eabi-7-2017-q4-major/bin:$PATH' >> ~/.profile
Close and reopen the terminal before using your newly set environment 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.

Installation for Mac

Command Line Tools

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.
You can install it by typing the following command in a terminal window: xcode-select --install. It will then open a popup asking you if you want to install this bundle. Otherwise it will tell you it is already installed.

Java 8

This section can be ignored if Java is already installed on your computer.
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: /usr/libexec/java_home -V
You need to have AdoptOpenJDK 8 listed to be able to run Eclipse_e-puck2.

  1. Go to OpenJDK download page and download the OpenJDK 8 (LTS) HotSpot for MacOS x64 JDK (take the installer, aka. .pkg file).
  2. Open the .pkg file downloaded and follow the instructions to proceed with the installation of OpenJDK.

OpenJDK download page

Eclipse_e-puck2

1. Download the Eclipse_e-puck2 package for Mac.
2. Open the .dmg file downloaded (confirm opening if a warning message appear) and drag and drop the Eclipse_e-puck2.app into the Applications folder
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.
3. You can create an Alias to Eclipse_e-puck2.app and place it anywhere if you want.

First launch and Gatekeeper

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.
If you can’t run the program because of a warning of the system, press OK and try to launch it by right clicking on it and choosing open in the contextual menu (may be slow to open the first time).
If Unable to open "Eclipse_e-puck2.app" because this app comes from an unidentified developer. or if "Eclipse.app" is corrupted and cannot be opened. You should place this item in the Trash. appears after executing the app the first time, it is needed to disable temporarily Gatekeeper.

To do so :

1. Go to System Preferences->security and privacy->General and authorize downloaded application from Anywhere.

Security settings of Mac OS
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.
sudo spctl --master-disable
2. Now you can try to run the application and it should work.
3. If Eclipse opened successfully, it is time to reactivate Gatekeeper. Simply set back the setting of Gatekeeper.
For the ones who needed to type a command to disable Gatekeeper, here is the command to reactivate it.
sudo spctl --master-enable

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.

Important things to avoid :

1. The path to the Eclipse_e-puck2.app must contain zero space.
Example :
/home/student/epfl_stuff/Eclipse_e-puck2 OK
/home/student/epfl stuff/Eclipse_e-puck2 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.

Configuring the PATH variable

The PATH variable is an environment variable used to store a list of the paths to the folders containing the executables we can then run in a terminal from any path.

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. To set the PATH variable you need to issue the following command:

export PATH=your_installation_path/Eclipse_e-puck2.app/Contents/Eclipse_e-puck2/Tools/gcc-arm-none-eabi-7-2017-q4-major/bin:$PATH

If you put the Eclipse_e-puck2.app into the Applications folder then the exact command would be:

export PATH=/Applications/Eclipse_e-puck2.app/Contents/Eclipse_e-puck2/Tools/gcc-arm-none-eabi-7-2017-q4-major/bin:$PATH

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.

If you want to set the PATH variable permanently, then you need to set it in the .bash_profile file by issuing the command:
echo 'export PATH=your_installation_path/Eclipse_e-puck2.app/Contents/Eclipse_e-puck2/Tools/gcc-arm-none-eabi-7-2017-q4-major/bin:$PATH' >> ~/.bash_profile
Close and reopen the terminal before using your newly set environment 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.

Get the source code

The code of the e-puck2 is open source and is available as a git repository. To download the source code you need to install git on your system:

  • Windows: downlaod git from https://gitforwindows.org/ and follow the installation instructions (default configuration is ok)
  • Linux: issue the command sudo apt-get install git
  • Mac: issue the command brew install git

The source code can downloaded with the command: git clone --recursive https://github.com/e-puck2/e-puck2_main-processor.git
The command must be issued in Git bash on Windows, or in a terminal on Linux / Mac.

This repository contains the main microcontroller factory firmware together with the e-puck2 library. This library includes all the functions needed to interact with the robot's sensors and actuators; the factory firmware shows how to use these functions.

A snapshot of the repository can be downloaded from e-puck2_main-processor_snapshot_17.03.20.zip.

Creating a project

Main microcontroller factory firmware project

If you want to modify the code of the factory firmware running on the main microcontroller, or if you want to have a look at the implementation details, then you can add this project in Eclipse by following the next steps:

1 Run Eclipse and then select File->New->Makefile Project with Existing Code.

2 Next click on the Browse button and choose the project folder of the git repository downloaded previously (should be named e-puck2_main-processor) and set a project name (otherwise you can keep the one created by Eclipse). Choose None for the the toolchain.
3 Click on the Finish button and the project is added to Eclipse.

4 Build the project by selecting one directory of the project from the left panel and then Project->Build Project.

Project template

The main microcontroller factory firmware project can also be used as a library to build your own project on top of it.

To accomplish that, you have to copy the folder Project_template, contained in the e-puck2_main-processor project, and place it in the same directory of the e-puck2_main-processor project; you can of course rename the folder to the name you want (e.g. myproject). You must end up with the following directory tree:

  • e-puck2
    • e-puck2_main-processor
    • myproject

Then you can add this project in Eclipse by following the next steps:

  1. Run Eclipse and then select File->New->Makefile Project with Existing Code.
  2. Next click on the Browse button and choose the project folder of your project (e.g. myproject) and set a project name (otherwise you can keep the one created by Eclipse). Choose None for the the toolchain.
  3. Click on the Finish button and the project is added to Eclipse.
  4. Select the project root folder and go to Project->Properties->C/C++ General->Preprocessor Include Paths, Macros etc->Providers and check CDT Cross GCC Built-in Compiler Settings.
    Then in the textbox below, write arm-none-eabi-gcc ${FLAGS} -E -P -v -dD "${INPUTS}".
  5. 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.
    1. Select the project root folder and go to File->New->Folder.
    2. Check Advanced >> on the bottom.
    3. Choose Link to alternate location (Linked Folder).
    4. Type PROJECT_LOC/../e-puck2_main-processor and click the Finish button.
  6. Build the project by selecting one file of the project from the left panel and then Project->Build Project. The result of the compilation will appear in the build folder in your project folder.
  7. After you compile the project, 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).

Now you can write your own program. If you want to add source files (.c) to the project you need to add them also in the makefile, in the CSRC definition. All the headers files (.h) 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, in the INCDIR definition. The same is needed for any desired .h files from other external folders.
In the makefile you can also set the name of your project.
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.

Configuring the Debugger's settings

Eclipse_e-puck2 contains everything needed to compile, program and debug the e-puck2.
The only settings to configure with a new project are located under the Debug Configurations icon of Eclipse (you can also find it on Run->Debug Configurations).


Once in the settings, select Generic Blackmagic Probe preset on the left panel. Then you need to configure two things :

  1. In the main tab, select which project to debug and the path to the compiled file. If the project has already been compiled, Eclipse should have indexed the binaries and you can list the project and the compiled files using respectively the Browse... and Search Project... buttons.
    If nothing is appearing when you press Search Project... then you must enter the .elf file name by hand, which can be found in your project build folder (e.g. build/e-puck2_main-processor.elf).
  2. In the Startup tab, you need to replace the serial port name written on the first line of the text box by the one used by the GDB Server of your robot. 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.
    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.
    Using the variable COM_PORT instead of the real com port in a debug configuration is useful if for example you have multiple debug configurations. If for some reason you need to change the serial port to use, then you can simply edit the variable COM_PORT instead of editing the serial port for each debug configuration.

If you want to debug another project, you can duplicate this settings and change the relevant parts (project name and path to compiled file) in order to have one launch configuration for each project.


Now you should be able to use the debugger with Eclipse.

Notice that the settings are saved in the project folder in a file with extension .launch. If you want, you can rename this file (e.g. Debug_project_template.launch) with the name you want for the debug configuration of your project.

Running a debugging session

Once the debugger is configured, you can start a debugging session. When starting a session, the robot is programmed with the current developed program, thus starting a debugging session means also updating the main microcontroller firmware. This is in fact the way to update the firwmare via Eclipse; to do it manually refer to the section Main microcontroller: firmware update.

To start a session follow the next steps:

  1. Connect the robot to the computer and turn it on
  2. From Eclipse, launch the debug configuration previously set: from the menu Run->Debug configurations..., select the configuration and click on the Debug button.
    Alternatively you can directly select your configuration from the debugger drop-down menu.

  3. When the debugging session is started, Eclipse will change the view to the Debug perspective. Right-click on the main process and select Restart to restart the program from the beginning
  4. Click on the Resume button on top of the window to start your program. Now you can suspend and resume whenever you want, then when you want to modify your code again you click on the Terminate button and click on the C/C++ perspective button.

Adding breakpoints

Watch variables

Analyze microcontroller registers content

When a debugging session is started, the microcontroller's registers state can be inspected by clicking on the EmbSys Registers tab on the top right side of the Debug perspective.

Bluetooth debugging session

It is possible to run a debugging session remotely thorugh Bluetooth following these steps:

  1. change the programmer's mode to mode 1 with the command monitor select_mode 1, for more informations refer to e-puck2 programmer development, chapter Configuring the Programmer's settings
  2. pair the robot with the computer
  3. in the debugger's settings, setup the port with the Bluetooth channel 1, GDB port name, for more informations refer to Connecting to the Bluetooth
  4. start the debugging session and the Bluetooth connection will be established automatically; now you can program/debug the robot remotely

Beware that GDB over the Bluetooth connection of the e-puck2 is much slower than with USB and it doesn't work with Windows due to GDB limitations on this OS.

Local communication

Local range infrared communication between e-puck2 robots can be achieved using the infrared sensors of the robots to transmit and receive information. The communication system is multiplexed with the proximity sensing system commonly used on the robots, thus it is possible to both communicate and avoid obstacles.

The implementation is based on the libIrcom library developed for the e-puck version 1 robots and it keeps retro-compatibility. This means that an e-puck version 1 is able to communicate with an e-puck version 2, so you can still use your e-puck version 1 robots together with e-puck version 2 to form a bigger fleet of robots for your experiments. Moreover the API is the same, thus the code developed for the e-puck version 1 can be used easily also with the e-puck version 2.

Here are some details about the current implementation of the local communication module:

  • messages are encoded using a frequency modulation that permits usage in a wide range of light conditions
  • the module allows communications at a rate of up to 30 bytes per seconds (maximum theoretical throughput)
  • support half-duplex communication
  • use the infrared sensors to exchange data, thus during reception/transmission the proximity sensors cannot be used to avoid obstacles; the sensors update frequency is at most 5 Hz
  • messages can be detected at a distance of about 7 cm (good reception), and even up to 12-13 cm (sparse reception)
  • messages are stored in a queue (up to 20 messages) and can be retrieved at any time, unless they are overwritten when the queue is full

The local communication module is integrated in the factory firmware, so if you want to have a look at the code refer to section Get the source code.
A simple exmaple exploiting the local communication can be found in the factory firmware. Put the selector in position 9 and connect the USB cable to the robot: the messages received will be printed in the terminal while the robot continuously send messages to other robots (transceiver behavior). The body led is toggled at each message reception.

If an higher throughput and a longer communication distance are required, there is the range and bearing extension designed for this purpose.

Synchronize example

This is a more advanced example exploiting the local communication. Basically the robots programmed with this demo will eventually orient themselves in the same direction, this is accomplished by exchanging data locally between them.

The same example is also available for e-puck version 1 robots (see libIrcom), so you can test it with a mix of robots.

The pre-built firmware is available here e-puck2_example_synchronize.elf (10.12.19).

Usage

When the robot is turned on, it starts exchanging information with other robots and try to align with them.
Beware that the selector position is taken as the id of the robot, so you need to place the selector in a different position for each robot.
Basically you need to put the selector in an unused position, turn on the robot and place it near the others. The robots will eventually align in the same direction.

Building

First of all download the source code with the command: git clone https://github.com/e-puck2/e-puck2_example_synchronize.git
The command must be issued in Git bash on Windows, or in a terminal on Linux / Mac.
Place the cloned repo folder e-puck2_example_synchronize in the same directory of the e-puck2_main-processor project; you must end up with the following directory tree:

  • e-puck2
    • e-puck2_main-processor
    • e-puck2_example_synchronize

Then you can add this project in Eclipse by following the next steps:

  1. Run Eclipse and then select File->New->Makefile Project with Existing Code.
  2. Next click on the Browse button and choose the project folder e-puck2_example_synchronize. Choose None for the the toolchain.
  3. Click on the Finish button and the project is added to Eclipse.
  4. Select the project root folder and go to Project->Properties->C/C++ General->Preprocessor Include Paths, Macros etc->Providers and check CDT Cross GCC Built-in Compiler Settings.
    Then in the textbox below, write arm-none-eabi-gcc ${FLAGS} -E -P -v -dD "${INPUTS}".
  5. 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.
    1. Select the project root folder and go to File->New->Folder.
    2. Check Advanced >> on the bottom.
    3. Choose Link to alternate location (Linked Folder).
    4. Type PROJECT_LOC/../e-puck2_main-processor and click the Finish button.
  6. Build the project by selecting one file of the project from the left panel and then Project->Build Project. The result of the compilation will appear in the build folder in your project folder.
  7. After you compile the project, 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).

Master-slave example

For this example two robots equipped with the ground sensors extension are needed: one acts as a master (transmitter) and the other as a slave (receiver). The master send a command (1 byte) to the slave indicating the current color of its RGB LEDs and the slave when receives the command, interpret it and set its RGB LEDs color to the same color of the master. The ground sensors extension is used to move the robots along a black line in order to follow a desired path.

The pre-built firmware is available here e-puck2_example_master_slave.elf (03.03.20).

Usage

Program the two robots with this demo and set the selector to position 0 for one robot (master) and position 1 (any position but zero would be ok) for the other (slave).
Print this master-slave-path.pdf and place the master on one side and the slave in the other side.
Both robots will move back and forth and when they encounter each other, the master will send its RGB LEDs state to the slave that will reflect the same state on its own RGB LEDs.
You can try different paths and also add more robots with slighly modifications to the code, this is only a starting point.
Beware that the robots will detect each other thanks to the proximity sensors values and they start to exchange data only when they're facing each other. This behavior can be changed by continuously exchanging data, in this way you can play also with different distances between the robot's path.

Building

First of all download the source code with the command: git clone https://github.com/e-puck2/e-puck2_example_master_slave.git
The command must be issued in Git bash on Windows, or in a terminal on Linux / Mac.
Place the cloned repo folder e-puck2_example_master_slave in the same directory of the e-puck2_main-processor project; you must end up with the following directory tree:

  • e-puck2
    • e-puck2_main-processor
    • e-puck2_example_master_slave

Then you can add this project in Eclipse by following the next steps:

  1. Run Eclipse and then select File->New->Makefile Project with Existing Code.
  2. Next click on the Browse button and choose the project folder e-puck2_example_master_slave. Choose None for the the toolchain.
  3. Click on the Finish button and the project is added to Eclipse.
  4. Select the project root folder and go to Project->Properties->C/C++ General->Preprocessor Include Paths, Macros etc->Providers and check CDT Cross GCC Built-in Compiler Settings.
    Then in the textbox below, write arm-none-eabi-gcc ${FLAGS} -E -P -v -dD "${INPUTS}".
  5. 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.
    1. Select the project root folder and go to File->New->Folder.
    2. Check Advanced >> on the bottom.
    3. Choose Link to alternate location (Linked Folder).
    4. Type PROJECT_LOC/../e-puck2_main-processor and click the Finish button.
  6. Build the project by selecting one file of the project from the left panel and then Project->Build Project. The result of the compilation will appear in the build folder in your project folder.
  7. After you compile the project, 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).

Example projects

Digital Signal Processing (DSP) and wav playback

In this example the CMSIS-DSP library is used to compute the Fast Fourier Transform of the signal coming from the microphones. The processing power of the main microntroller let the signal to be processed continuously. Moreover this example shows how to play wav files stored in the micro sd.

The pre-built firmware is available here e-puck2_example_dsp.elf (05.10.18).

Usage

There are basically two demos in this example, one run on selector position 0 and the other in selector position 1.

When the selector is in position 0, then the resulting frequency (max amplitude bin) of the computed FFT is mapped to the RGB LEDs: LEDs will be blue when frequency detected is around 250..900 Hz, green when frequency is around 900..1500 Hz and red with 1500..2200 Hz. The brightness of the LEDs is also changed with the frequency.
The distance sensor (ToF) is also used to detect people in front of the robot. When someone is detected within 50 cm, then the measured distance is mapped to a frequency emitted through the speaker; the generated tone is between 260 Hz (far) and 2240 Hz (near). You can use your hand to play some melody, the robot in the meantime will detect the frequency and show it through the RGB.

When the selector is in position 1, the robot will play a wav file stored in the micro sd when one of the proximity sensors is "touched" (with your finger you go near the proximity and then you go away, like pressing a button). For each proximity there is a different wav file that will be played: for proximity 0 it will be played 0.wav, for proximity 1 it will be played 1.wav and so on till proximity 7 with 7.wav.

All the wav files you need are stored in the wav directory within the project, put all of them in a micro sd partitioned in FAT32 and you're ready to go. Alternatively you can play your own wav files, beware to name them from 0.wav to 7.wav and they must be 16 KHz, mono.

Building

First of all download the source code with the command: git clone https://github.com/e-puck2/e-puck2_example_dsp.git
The command must be issued in Git bash on Windows, or in a terminal on Linux / Mac.
Place the cloned repo folder e-puck2_example_dsp in the same directory of the e-puck2_main-processor project; you must end up with the following directory tree:

  • e-puck2
    • e-puck2_main-processor
    • e-puck2_example_dsp

Then you can add this project in Eclipse by following the next steps:

  1. Run Eclipse and then select File->New->Makefile Project with Existing Code.
  2. Next click on the Browse button and choose the project folder e-puck2_example_dsp. Choose None for the the toolchain.
  3. Click on the Finish button and the project is added to Eclipse.
  4. Select the project root folder and go to Project->Properties->C/C++ General->Preprocessor Include Paths, Macros etc->Providers and check CDT Cross GCC Built-in Compiler Settings.
    Then in the textbox below, write arm-none-eabi-gcc ${FLAGS} -E -P -v -dD "${INPUTS}".
  5. 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.
    1. Select the project root folder and go to File->New->Folder.
    2. Check Advanced >> on the bottom.
    3. Choose Link to alternate location (Linked Folder).
    4. Type PROJECT_LOC/../e-puck2_main-processor and click the Finish button.
  6. Build the project by selecting one file of the project from the left panel and then Project->Build Project. The result of the compilation will appear in the build folder in your project folder.
  7. After you compile the project, 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).

Microphones recording and pitch scaling

This example shows how to record the audio (voice) from the onboard microphones and save it in the micro SD.
Moreover it applies a pitch scaling algorithm to the data before playing it from the micro SD.
The pitch scale processing is based on the SOLA algorithm and a simple implementation is available from the following link https://www.surina.net/article/time-and-pitch-scaling.html. Have a look at this site bacause it has a good explanation of the algorithm.

The pre-built firmware is available here e-puck2_example_pitch_scale.elf (07.11.18).

Usage

The example requires a micro SD (FAT32) inserted in the robot.

When the robot is turned on, it waits for the button press that triggers the recording. The voice is recorded for about 2 seconds and saved into the micro SD as wav file. Once the recording is finished, the pitch scale is applied and then the modified voice is played.

You can choose whether to get an higher or lower pitch by changing the TIME_SCALE parameter in sola.c:

  • if you want to get an higher pitch, then change TIME_SCALE to a value > 1.0
  • if you want to get a lower pitch, then change the TIME_SCALE to a value < 1.0

Of course, if the parameter is changed, you need to rebuild the project and reflash the robot.

Building

First of all download the source code with the command: git clone https://github.com/e-puck2/e-puck2_example_pitch_scale.git
The command must be issued in Git bash on Windows, or in a terminal on Linux / Mac.
Place the cloned repo folder e-puck2_example_pitch_scale in the same directory of the e-puck2_main-processor project; you must end up with the following directory tree:

  • e-puck2
    • e-puck2_main-processor
    • e-puck2_example_pitch_scale

Then you can add this project in Eclipse by following the next steps:

  1. Run Eclipse and then select File->New->Makefile Project with Existing Code.
  2. Next click on the Browse button and choose the project folder e-puck2_example_pitch_scale. Choose None for the the toolchain.
  3. Click on the Finish button and the project is added to Eclipse.
  4. Select the project root folder and go to Project->Properties->C/C++ General->Preprocessor Include Paths, Macros etc->Providers and check CDT Cross GCC Built-in Compiler Settings.
    Then in the textbox below, write arm-none-eabi-gcc ${FLAGS} -E -P -v -dD "${INPUTS}".
  5. 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.
    1. Select the project root folder and go to File->New->Folder.
    2. Check Advanced >> on the bottom.
    3. Choose Link to alternate location (Linked Folder).
    4. Type PROJECT_LOC/../e-puck2_main-processor and click the Finish button.
  6. Build the project by selecting one file of the project from the left panel and then Project->Build Project. The result of the compilation will appear in the build folder in your project folder.
  7. After you compile the project, 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).

C++

A basic example showing how to integrate C++ code in your project is available in the following repository: https://github.com/e-puck2/e-puck2_cpp.
The example demonstrates simple usage of a class and for range loops.

Building

First of all download the source code with the command: git clone https://github.com/e-puck2/e-puck2_cpp.git
The command must be issued in Git bash on Windows, or in a terminal on Linux / Mac.
Place the cloned repo folder e-puck2_cpp in the same directory of the e-puck2_main-processor project; you must end up with the following directory tree:

  • e-puck2
    • e-puck2_main-processor
    • e-puck2_cpp

Then you can add this project in Eclipse by following the next steps:

  1. Run Eclipse and then select File->New->Makefile Project with Existing Code.
  2. Next click on the Browse button and choose the project folder e-puck2_cpp. Choose None for the the toolchain.
  3. Click on the Finish button and the project is added to Eclipse.
  4. Select the project root folder and go to Project->Properties->C/C++ General->Preprocessor Include Paths, Macros etc->Providers and check CDT Cross GCC Built-in Compiler Settings.
    Then in the textbox below, write arm-none-eabi-gcc ${FLAGS} -E -P -v -dD "${INPUTS}".
  5. 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.
    1. Select the project root folder and go to File->New->Folder.
    2. Check Advanced >> on the bottom.
    3. Choose Link to alternate location (Linked Folder).
    4. Type PROJECT_LOC/../e-puck2_main-processor and click the Finish button.
  6. Build the project by selecting one file of the project from the left panel and then Project->Build Project. The result of the compilation will appear in the build folder in your project folder.
  7. After you compile the project, 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).

Bluetooth echo

The aim of this example is to show how to exchange data between the robot and the computer through a Bluetooth connection. The project implements a simple echo behavior, that is what is received by the robot is sent back to the computer.

Building

First of all download the source code with the command: git clone https://github.com/e-puck2/e-puck2_example_bluetooth_echo.git
The command must be issued in Git bash on Windows, or in a terminal on Linux / Mac.
Place the cloned repo folder e-puck2_example_bluetooth_echo in the same directory of the e-puck2_main-processor project; you must end up with the following directory tree:

  • e-puck2
    • e-puck2_main-processor
    • e-puck2_example_bluetooth_echo

Then you can add this project in Eclipse by following the next steps:

  1. Run Eclipse and then select File->New->Makefile Project with Existing Code.
  2. Next click on the Browse button and choose the project folder e-puck2_example_bluetooth_echo. Choose None for the the toolchain.
  3. Click on the Finish button and the project is added to Eclipse.
  4. Select the project root folder and go to Project->Properties->C/C++ General->Preprocessor Include Paths, Macros etc->Providers and check CDT Cross GCC Built-in Compiler Settings.
    Then in the textbox below, write arm-none-eabi-gcc ${FLAGS} -E -P -v -dD "${INPUTS}".
  5. 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.
    1. Select the project root folder and go to File->New->Folder.
    2. Check Advanced >> on the bottom.
    3. Choose Link to alternate location (Linked Folder).
    4. Type PROJECT_LOC/../e-puck2_main-processor and click the Finish button.
  6. Build the project by selecting one file of the project from the left panel and then Project->Build Project. The result of the compilation will appear in the build folder in your project folder.
  7. After you compile the project, 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).

Ball detection

Pierre Oppliger and WIlliam Galand, during their semester project at EPFL, were able to let the e-puck2 robot reliably recognize a ball independently of light conditions. This is a step towards an e-puck2 football soccer player. For more information about the project (French) and source code, have a look at the repository https://github.com/e-puck2/e-puck-2-footy.

Firmware update using factory bootloader

Factory firmware

The pre-built firmware is available here main microcontroller factory firmware.bin (29.03.23); it is also available in dfu format here main microcontroller factory firmware.dfu (29.03.23).

Firmware update

This procedure should be used only if the normal firmware update steps described in the section Main microcontroller: firmware update don't work. This is a recovery procedure.

The main microcontroller features a factory bootloader that can be entered by acting on some special pins, the bootloader mode is called DFU (device firmware upgrade). You can enter DFU mode by first connecting the USB cable, then pressing the button called 407 boot while turning on the robot. The button is located near the left wheel, on the bottom side of the electronic board, see the photo below.


Location of the button to put the main microcontroller into DFU

The main microcontroller will be recognized as STM Device in DFU Mode device.

Note for Windows users: the device should be recognized automatically (in all Windows versions), but in case it won't be detected then you need to install a libusbK driver for the DFU device.
Follow the same procedure as explained in section Installing the USB drivers using libusbK driver instead of USB Serial (CDC).
If you still have problems, try to install the drivers you can find in C:\Program Files (x86)\STMicroelectronics\Software\DfuSe v3.0.6\Bin\Driver.

Linux/Mac

In order to update the main microcontroller firmware you need an utility called dfu-util, it should be already installed from section Installing the dependencies for firmwares updates.
To uplaod the firmware, issue the following command: sudo dfu-util -d 0483:df11 -a 0 -s 0x08000000 -D your_firmware.bin (the name of the bin file must be changed accordingly).

Windows

Start the DfuSe application (previously installed from section Installing the dependencies for firmwares updates). 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 choose and then locating the file with dfu extension, as shown in figure 2. Now click on the upgrade button, a warning message will be shown, confirm the action by clicking on yes 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.

[1] [2] [3] [4]