Yes we can drive it !

MAC One Project
Meetech - We Love Tech
6 min readSep 7, 2020

In the first article, we introduced you to the different steps in the realization of the Mac Two project. In this article, we will strive to depict how we are going to achieve the second phase of the project: turn Mac Two into a remote-controlled vehicle.

The main purpose of this part is to precisely understand how the engines can be controlled which is a prerequisite to develop algorithms to have an autonomous robot car.

1) Components & assembly

a. Focus on the car electronic organization

Once the chassis was received, an inspection of its architecture was conducted to identify the links between the different components. By doing so, we got a better understanding of how we could connect the raspberry to control the motors.

To sum it up, this chassis has two servo motors and one motor:

  • One Electronic Speed Controller ( ³ESC) which determines the speed of the vehicle. It receives an electrical signal and delivers the right amount of tension to the engine.
  • One standard directional servo motor which determines the direction of the front wheels. This component is controlled through an electric signal which is going to be sent by the Raspberry Pi ¹.
  • One brushed motor that uses the tension delivered by the ESC to spin around and make the wheels move forward.

Our basic objective was to replace the remote control and its transmitter by a Raspberry. In order do to so, we needed to understand how the remote control interacted with the motor, so that we could reproduce it with python programs. This will be explained in the second part of this article.

b. Focus on the new car organization

Since we were going to add some new components in the car, we had to settle a new space organization. To do so, we decided to print a plastic board with a 3D printer. Once fixed to the car, this board would help us mount the Raspberry, a breadboard and a battery.

2) Control

To meet our objective to control the car with an application hosted on the Raspberry, we had to go through the following steps:

a. Raspberry software initialization

To set up the software environment, we first installed Raspbian. It is a light Linux distribution which has been purposely created for raspberry Pi devices. Second, we configured the connection interface for the raspberry to be able to connect automatically to a wifi access point. Finally, we downloaded MobaXterm, a software that allows users to access remotely the raspberry Pi using ssh protocol.

b. The servo hat welding

After some researches, we realized that it was neither safe nor convenient to directly connect the two servo motors to the ²GPIO of the Raspberry. Therefore, we welded an “Adafruit servo hat for Raspberry” that has been created to control multiple servo motors.

c. Transmission of information : focus on I2C protocol and PWM command

The “Adafruit servo hat for Raspberry” has been created to transfer information from the GPIO of the Raspberry to the servo-motors pins through the I2C bus. The I2C bus works with I2C protocol which has the strong benefit to allow multi-transmission of information. To say it differently, with this protocol, we use only 2 GPIO to send simultaneously information to both servo-motors.

After understanding how to transmit information to the servo-motors through I2C protocol, we then needed to determine what information we were going to send. The ESC and the directional servo-motor expect PWM orders. PWM stands for Pulse Width Modulation. Using PWM, you modulate the average amount of tension delivered to the servo-motors. The higher the tension, the faster the car.

d. Web app control : focus on joystick driving mode & web socket network protocol

Finally, after being able to send local orders to the servo-motors to control it, we wanted to drive the vehicle using a joystick embedded in a front-web application.

To create real-time communication between the web app and the server, we used a web-socket module (socket.io) based on the web-socket network protocol.

In other terms, when we move the joystick to one position, the front-app stores the position of the joystick in a variable and send it to the server through the web-socket network protocol. Then, the server converts this data into two PWM values : one for speed, one for direction.

In this article, the construction has been described as a calm and easy journey to achieve our goal but this was not the case! This project was more like a lord of the ring quest. We faced various obstacles. Here are 2 examples of them :

  • The minimum and maximum speed of the car were changing depending on the level of the battery. How could we configure a smooth driving with such a problem ? We had to introduce a new component : an INA219 to get the level of battery on real-time and have a little algorithm to adjust the PWM commands according to the current level of battery.
  • An other issue was the delay of the messages transmission from the app to the server. In other words, when we were moving left after moving forward, the vehicle was still moving forward for 5 more seconds… How could we pretend to participate to the Iron Car race with such an issue …The solution was to configure a Python thread on the server side to repetitively check the last message received by the web-socket.

Conclusion

As a good video is worth a thousand words, you will find below the result of our work:

PS : the two sliders : “PWM avant” and : “PWM arrière” on the screen of the app correspond to the speed regulation of the vehicle. Since we do not have access to the km/h speed of the vehicle, we adjust the PWM values to have a relative maximum speed for going forward (“PWM avant”) and backward (“PWM arrière”).

On next article, we will tell you more on how we used “supervised learning” method to have an autonomous robot car capable of taking 20 decisions every second !

Stay tuned !

Glossary

¹Raspberry : Micro-computer created mainly for computer science and robotic practical applications.

²GPIOs : they are inputs and outputs pins of the Raspberry. They allow us to have the Raspberry interact with all kinds of components (for example, with an ultrasound sensor).

³E.S.C. : electronic circuit that controls and regulates the speed of an electric motor.

--

--