Robot Web Control with the Vespa




Introduction

In this tutorial you'll see how to control the movement of the Rocket Tank from your smartphone, thanks to Vespa. To do this, you'll assemble the Rocket Tank with the Vespa, assemble the electrical circuit, and then see the connection steps to access the control page.

List of Materials

Warning: before proceeding, you must follow the steps in First Steps with the Vespa, as they teach you how to install the essential tools for using the board.

Mechanical Assembly

The first step in developing the project for this tutorial is to mechanically assemble the Rocket Tank and fix the Vespa and the battery holder on the structure. To do so, follow the Rocket Tank assembly manual using the button below.

Rocket Tank Assembly Guide

The Vespa has the same fixing hole pattern as the Arduino UNO platform boards, so it is simpler to use these holes to fix it. As for fixing the battery holder, you can fix it anywhere on the robot structure that you prefer. Below is an example of assembly.

exemplo_montagem_conjunto
Assembly Example

Electronic Assembly

With the mechanical part ready, assemble the circuit in the image below with your Vespa.

circuito_eletrico
Electric Circuit

To attach the motors and battery wires to the board, it is necessary to open and close the contacts of the removable terminal blocks on the board, as shown in the GIF below.

Fixing the Wires on the Terminal Block

Coding

Now that the robot is physically assembled, we have to write the code that will be used to control it.

Libraries

Before uploading the example code to the board, we have to install some libraries that are used by the code so that the board executes what we want. To do so, download the necessary libraries using the button below.

Library ArduinoJson Library AsyncTCP Library ESPAsyncWebServer

Once the files are downloaded, follow the image path below in the Arduino IDE to install the libraries from the compressed file.

caminho_instalacao_bibliotecas
Path to Library Installation

When selecting this option, a window will open with the directories of your computer. Navigate to the directory where the compressed (ZIP) files were saved and then double-click on one of the folders. This will cause the library contained in the selected file to be installed in your IDE.

As we need the three libraries available above for the code to work, it is necessary to repeat this procedure for the other two downloaded files as well.

Code

With the libraries installed, upload the following code to your Vespa. Remembering that it is necessary to follow the steps of initial settings of the board to install all the necessary tools for its functioning, as well as to understand how to upload codes in it.

Understanding the Code

In this code, Vespa is responsible for creating its own Wi-Fi network and an asynchronous web server. With this, we can connect martphones, tablets and even computers to the network created to access the board's server. After creating your network, the board also provides an IP address, which will be used to access the robot control web page.

The server's web page is entirely programmed in code, and it is thanks to it that the control interface is presented. On the page there is mainly a joystick that gives direction to the robot. When moving the joystick, data is sent in JSON format to Vespa, which, in turn, identifies them and acts according to what was commanded by the joystick.

Another interesting feature of the control interface is the battery meter, which is one of the Vespa's many features. The board measures battery voltage every 5 seconds and then updates the voltage displayed on the interface. This way, you'll always know when you need to change or recharge the robot's batteries.

The most important function of this code is to control the motors, since it is responsible for giving the robot direction. It checks the angle at which the joystick pointer is set (taking the angles shown in the image below as a reference), and then the motors are activated as expected. For example, when the pointer is up/forward, that is, with an angle between 80 and 100°, the motors are driven forward using commands from the board's library.

angulos_joystick
Joystick Angles

Most of the project's functions are monitored by the serial monitor, so you can, if you want, monitor the information on the board. To do so, just open the serial monitor on your board's serial port, with a speed of 115200 bps.

What Must Happen

After loading the code to the board, disconnect the USB cable, turn it on by the on/off switch of its circuit, and then open the list of Wi-Fi networks available on the device you will use for control (cell phone, tablet or computer ). After a few moments, a network with the name "Vespa-xx:xx" will be displayed, as in the image below, for example.

rede_wifi_encontrada_conectada
Wi-Fi Network Found and Connected

Note: Vespa Wi-Fi network suffix "xx:xx" is taken from the last characters of the board's ESP32 MAC Address to make the network unique, so don't worry if the name from the network is different from the image, as this is expected.

To establish the connection to the network, just use the password "rc-vespa", which is the code's default password.

Remember that you can, if you want, change the name and password of the Wi-Fi network created by the board, just change these parameters in the code configuration (function void setup()).

After connecting your device to the board's network, open the browser of your choice and then access the IP address "192.168.4.1". When accessing the IP address, the project control interface page will be opened, as shown in the following image.

interface_web_controle
Web Control Interface

Once the Vespa is ready to be controlled, its LED L will remain turned on and you can move the joystick to control the robot's movement, as in the GIF below.

Final Result

Conclusion

In this tutorial we saw how to take advantage of Vespa's functionalities to make a remote control of robots and now you can enjoy the project created for fun!

Going Beyond

In addition to the Rocket Tank remote control, it is also possible to use the same concepts to control robotic arms, as shown in Web Control of Robotic Arm with the Vespa.

Troubleshooting

The robot is not walking in the right direction

If the robot is not behaving as expected and as controlled by the joystick, it is likely that one of the motors has reversed polarity. Lift the robot and see which of the motors has the inverted spin when commanding the robot forward, for example. Then turn off the board, disconnect the motor terminal and invert the connection of the motor wires. This should resolve the issue.

The red LED is on

The red LED labeled R on the board is a reverse polarity indicator LED on the board, so if it is lit, it is expected that the board will not turn on as a protection. Disconnect the board power terminal and reverse the battery power supply polarity.

Unable to access IP address for control

If the control interface is not being displayed when accessing the server's IP address, check your connection to the board's network. It is common for more modern devices to automatically disconnect from Wi-Fi networks without internet (as is the case with the network created by Vespa) to try to connect to another network. If this is happening, disable your device's automatic disconnection.