Difference between revisions of "e-puck2"

From GCtronic wiki
Jump to: navigation, search
(Linux)
(Linux)
Line 362: Line 362:
 
Once paired with the Bluetooth manager, you need to create the port for communicating with the robot by issueing the command: <br/>
 
Once paired with the Bluetooth manager, you need to create the port for communicating with the robot by issueing the command: <br/>
 
<code>sudo rfcomm bind /dev/rfcomm0 MAC_ADDR 2</code><br/>
 
<code>sudo rfcomm bind /dev/rfcomm0 MAC_ADDR 2</code><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>).<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.
Now you can use <code>/dev/rfcomm0</code> to connect to the robot.
 
  
 
===Mac===
 
===Mac===

Revision as of 13:22, 13 March 2018

1 Hardware

1.1 Overview


1.2 Specifications

The e-puck2 robot maintains full compatibility with its predecessor e-puck (e-puck HWRev 1.3 is considered in the following table):

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 No e-jumper required
Battery, autonomy LiIPo rechargeable battery (external charger), 1800 mAh.
About 3 hours autonomy. Recharging time about 2-3h.
Same battery; USB charging, recharging time about 2.5h. 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 ~10 times faster
Memory RAM: 8 KB; Flash: 144 KB RAM: 192 KB; Flash: 1024 KB RAM: 24x more capable
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
Wheels Wheels diamater = 41 mm
Distance between wheels = 53 mm
Same wheels
Speed Max: 1000 steps/s (about 12.9 cm/s) Max: 1200 steps/s (about 15.4 cm/s) 20% faster
Mechanical structure Transparent plastic body supporting PCBs, battery and motors Same mechanics
Distance sensor 8 infra-red sensors measuring ambient light and proximity of objects up to 6 cm Same infra-red sensors
Front real distance sensor, Time of fight (ToF), up to 2 meter.
ToF sensor
IMU 3D accelerometer and 3D gyro 3D accelerometer, 3D gyro, 3D magnetometer 3D magnetometer
Camera VGA color camera; typical use: 52x39 or 480x1 Same camera; typical use: 160x120 Bigger images handling
Audio 3 omni-directional microphones for sound localization
speaker capable of playing WAV or tone sounds
4 omni-directional microhpones (digital) for sound localization
speaker capable of playing WAV or tone sounds
+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 4x RGB LEDs
Communication RS232 and Bluetooth 2.0 for connection and programming USB Full-speed, Bluetooth 2.0, BLE, WiFi WiFi, BLE
Storage Not available Micro SD slot Micro SD
Remote Control Infra-red receiver for standard remote control commands Same receiver
Switch / selector 16 position rotating switch Same selector
Extensions Ground sensors, range and bearing, RGB panel, Gumstix extension, omnivision, your own All extension supported
Programming Free C compiler and IDE, Webots simulator, external debugger Free C compiler and IDE, Webots simulator, onboard debugger (GDB) Onboard debugger

This is the overall communication schema:

2 Programming and Debugging

2.1 Installation of the e-puck2 environment

Some programs are needed to program the e-puck2.

  1. 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.
  2. Drivers must also be installed for Windows older than Windows 10.

2.1.1 Installation for Windows

2.1.1.1 Java 8 32bits

This section can be ignored if Java version 8 32bits is already installed on your computer.
To verify, you can open the Programs and Features panel and search for a Java 8 Update xxx install.

  1. Go to the Java download page and download "Windows offline" This is the 32bits version of Java.
  2. Run the downloaded installer and follow its instructions to proceed with the installation of Java 32bits.
  3. Close the internet browser if it opened at the end of the installation.

Java download page

2.1.1.2 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 Ellipse_e-puck2 folder into Program Files (x86). Otherwise the compilation when using Eclipse will not work.
3. The file’s structure in the Eclipse_e-puck2 folder must remain the same. It means no file inside this folder must be moved to another place.

2.1.1.3 Drivers

This part concerns only the users of a Windows version older than Windows 10. The drivers are automatically installed with Windows 10.

  1. Open zadig-2.3.exe located in the Eclipse_e-puck2\Tools\ folder you installed before.
  2. 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).
  3. For each of the three devices mentioned above, select the USB Serial (CDC) driver and click on the Install Driver 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 C:\Users\"your_user_name"\usb_driver

Example of driver installation for e-puck2 STM32F407

2.1.2 Installation for Linux

2.1.2.1 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 

2.1.2.2 Eclipse_e-puck2

  1. Download the Eclipse_e-puck2 package for Linux 32bits / 64bits. Pay attention to the 32bits or 64bits version.
  2. Extract the downloaded file to the location you want (can take time).
  3. 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 resource 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.

2.1.2.3 Serial Port

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.

sudo adduser $USER dialout

2.1.3 Installation for Mac

2.1.3.1 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 Java SE 8 listed to be able to run Eclipse_e-puck2.

1. Go to the Java download page and download the Mac OS X Java 8 SE Development Kit. It is the .dmg file without the Demos and Samples.
For example: jdk-8uXXX-macosx-x64.dmg
2. Open the .dmg file downloaded, run the installer and follow the instructions to proceed with the installation of Java SDK.

Java download page

2.1.3.2 Eclipse_e-puck2

1. Download the Eclipse_e-puck2 package for Mac.
2. Open the .dmg file downloaded and DragAndDrop 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.

2.1.3.3 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.

3 Getting Started

3.1 Meaning of the LEDs

The e-puck2 has three groups of LEDs that are not controllable by the user.


Top view of the e-puck2
  • Charger : RED if charging, GREEN if charge complete and RED and GREEN if an error occurs
  • USB : Turned ON if the e-puck2 detects a USB connection with a computer
  • 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.

Battery level indications (STATUS RGB LED):

  • 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.

3.2 Finding the USB serial ports used

Two ports are created by the e-puck2's programmer when the USB cable is connected to the robot (even if the robot is turned off):

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.

3.2.1 Windows

  1. Open the Device Manager
  2. Under Ports (COM & LPT) you can see the virtual ports connected to your computer.
  3. Do a Right-click -> properties on the COM port you want to identify.
  4. Go under the details tab and select Bus reported device description in the properties list.
  5. The name of the port should be written in the text box below.
  6. Once you found the desired device, you can simply look at its port number (COMX).

3.2.2 Linux

1. Open a terminal window (ctrl+alt+t) and enter the following command.
ls /dev/ttyACM*
2. Look for ttyACM0 and ttyACM1 in the generated list, which are respectively e-puck2 GDB Server and e-puck2 Serial Monitor.

Note : Virtual serial port numbering on Linux is made by the connections order, thus it can be different if another device using virtual serial ports is already connected to your computer.

3.2.3 Mac

1. Open a terminal window and enter the following command.
ls /dev/cu.usbmodem*
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.

3.3 Creating a project

3.3.1 Project template

e-puck2_main-processor is a demo project containing all the libraries written for the e-puck2.
It shows how to use them and can be interfaced with e-puck2 monitor.
But this 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, where you want to place your project.

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 project, the .c files to include and the folder(s) to the .h files to include.
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. 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.

The result of the compilation will appear in a build folder in your project folder.

3.3.2 Adding to Eclipse_epuck2

  1. To add the project into Eclipse, you need to select File->New->Makefile Project with Existing Code.
  2. Next choose your project folder and set a project name. Choose the toolchain Cross GCC for the Indexer Setting if available. Choose None otherwise.(This choice only changes how the files are indexed).
  3. Click on the Finish button and the project is added to Eclipse. You should now be able to compile it.

3.4 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 tab of Eclipse (you can also find it on Run->Debug Configurations).


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

  1. 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.
  2. 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. 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.

If you want to debug another project, you can change the settings of the 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.

3.5 Connecting to the Bluetooth

The default firmware in the ESP32, the module which provides Bluetooth and Wi-Fi connectivity, creates 3 Bluetooth channels using the RFcomm protocol:

  1. Channel 1, GDB: port to connect with GDB if the programmer is in mode 1 or 3 (refer to chapter Configuring the Programmer's settings for more information about these modes)
  2. Channel 2, UART: port to connect to the UART port of the main processor
  3. Channel 3, SPI: port to connect to the SPI port of the main processor (not yet implemented. Just do an echo for now)

By default, the e-puck2 is not visible when you search for it in the Bluetooth utility of your computer.
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.
Then it will be discoverable and you will be able to pair with it.

3.5.1 Windows

When you pair your computer with the e-puck2, 3 com ports will automatically appear: e_puck2_xxxxx-GDB, e_puck2_xxxxx-UART, e_puck2_xxxxx-SPI. xxxxx is the ID number of your e-puck2.
Note that on certain Windows, a prompt will ask you to confirm that the number written on the screen is the same on the e-puck. just ignore this and accept.

3.5.2 Linux

Once paired with the Bluetooth manager, you need to create the port for communicating with the robot by issueing the command:
sudo rfcomm bind /dev/rfcomm0 MAC_ADDR 2
The MAC address is visible from the Bluetooth manager. The parameter 2 indicates the channel, in this case a port for the UART channel is created. If you want to connect to another service you need to change this parameter accordingly (e.g. 1 for GDB and 3 for SPI). Now you can use /dev/rfcomm0 to connect to the robot.

3.5.3 Mac

3.6 Configuring the PATH variable

The PATH variable is a environment variable used to store a list of the paths to the folders containing the executables we can run in a terminal with Windows, Mac and Linux.

If you want to use the arm-none-eabi toolchain provided inside the Eclipse_e-puck2 package, you have to add it to the PATH variable to be able to call it inside a terminal window.

Setting the PATH variable for Windows :

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

Setting the PATH variable for Linux :

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

Setting the PATH variable for Mac :

export PATH=your_installation_path/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.

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.

3.7 Configuring the Programmer's settings

The on-board programmer of the e-puck2 is based on the Blackmagic probe open source project firmware.
Some functionalities has been added on top of the original project to be able to control some functions of the robot, for example the power on or power off.

To access to the available commands of the programmer, it is needed to connect to the programmer with a GDB console.
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 :

arm-none-eabi-gdb 
target extended-remote your_gdb_com_port

Once connected to the programmer with GDB, you can type

monitor help
or
mon help
to print the available commands of the programmer.

One command in particular is useful, which is mon select_mode. It is used to select in which mode the e-puck2 Serial Monitor com port will work.
mode 1 = the serial monitor is connected to the UART port of the main processor
mode 2 = the serial monitor is connected to the UART of the ESP32
mode 3 = the serial monitor works as a Aseba CAN to USB translator

The choice made for the mode is the only setting that is stored in a flash zone of the programmer, which means the choice is remembered, even if the robot is completely turned off.

Note : in mode 1 and 3, GDB can be used over the bluetooth connection of the e-puck2. But is is much slower than with USB and it doesn't work with Windows due to GDB limitations on this OS.

By being connected with GDB, you can also use the standard GDB command to program and debug the main processor of the e-puck2.

3.8 Using the DFU

To put the e-puck2 into DFU, it is needed to turn it on while keeping pressed the "407 boot" button located under the electronic card on the left side of the robot.
The robot will appear as "STM32 BOOTLOADER" in the USB devices.

Once in DFU, you can program it with dfu-util using the following command :

dfu-util -d 0483:df11 -a 0 -s 0x08000000 -D your_firmware.bin

See the manual page of dfu-util for further information on how to use it.

Note : For windows, it is needed to install a libusbK driver for the DFU device.
You can use the Zadig program located in the Eclipse_e-puck2\Tools\ (if you installed Eclipse_e-puck2 package) to install it.
Follow the same procedure as explained above under the Installation drivers section using libusbK driver instead of USB Serial (CDC).

Note 2 : It is also possible to put the programmer in DFU by contacting two pinholes together while turning ON the robot.
It is used to update the firmware of the programmer.
The two pin holes are located near the USB connector of the e-puck2, see the photo below.


Location of the pin holes to put the programmer into DFU

4 Software

4.1 PC interface


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. Available executables:

4.2 Standard firmware

The robot is initially programmed with a firmware that includes many demos that could be started based on the selector position:

  • Selector position 0: Aseba
  • Selector position 1: Shell
  • Selector position 2: Read proximity sensors
  • Selector position 3: Asercom protocol v2 (BT)
  • Selector positoin 4: 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.
The pre-built firmware is available here e-puck2 firmware.

4.3 Library

A snapshot of the library can be donwloaded from e-puck2_main-processor_snapshot.zip.
The latest version can be downloaded with the command: git clone --recursive https://github.com/e-puck2/e-puck2_main-processor.git