In the English magazine The Magpi, issue 114 Have I read something new for me again and interesting things about robot cars (Robot Car). The focus of the article was the relatively new accessories Raspberry Pi Build, an interface to the Lego engines. So, if you have a Lego fleet, you can now program and control your models with a Raspberry Pi.
One aspect of the control is also interesting for all other lovers of robot cars with the much used yellow electric motors: that of Martin O'Hanlon - employee of the Raspberry Pi Foundation - developed smartphone app Bluedot, a Bluetooth control that on the Raspberry Pi can be adjusted for your own purposes. This means that the appearance and functionality are programmed with Python. Obviously this app is only available for Android. Here is a screenshot from the app on my smartphone with the eponymous blue dot:
Raspberry Pi with Bluetooth, e.g. 3b+
You can find a detailed contribution to the Smart Robot Car Kit here.
As I said, appearance, i.e. number of buttons, shapes and colors of the points as well as the functions, can be designed according to your own wishes. More on that later.
On my Android smartphone I entered Blue Dot in the Play Store in the search window. The thick blue dot and the underline Martin O’Hanlon *tools led me to the right app from the large number of options displayed. So that the open app later finds the Raspberry Pi, it must first be linked to the smartphone under Settings/Bluetooth. Self-murmuring must be activated on both devices and selected on the Raspberry Pi with the left mouse click on the Bluetooth symbol "Make Discoverable".
The next two pictures show the basic coupling of the smartphone and Raspberry Pi, as well as the app before the actual connecting the app to the Raspi. With several coupled devices, several options can also be offered here. Simply click on the two lines with Raspberrypi and address, then the connection is established, provided that the program has also started on the Raspberry Pi.
The associated Python library must be installed on the Raspberry Pi. This is best done with the terminal command:
In the next step we are looking for "Github Bluedot" with Google in the browser and are on the side of Martin O’Hanlon guided. Here we find important information, such as the links to "Online documentation“As well as many Program examples (recipes). I quickly download everything as a zip file, unpack the file and postpone the examples to the Raspberry Pi to try everything out.
Here I recommend copying, because this way you get to know the diverse functionality of the program library the fastest. Because here, too, I repeat myself, the appearance of the app on the smartphone and the functionality are programmed on the Raspberry Pi.
The next picture of the smartphone with the JOOPAD can be obtained with the following Python code (sample program joypad.py):
With bd = bluedot (cols = 5, rows = 3) the Bluedot object is instantiated with 5 columns and 3 rows. Then the unwanted fields BD [0.0] .Visible = false made invisible. Color and shape of the buttons are e.g. Bd.Color = "Gray" and Vol.square = True Are defined. With commands like BD [1.0] .When_pressed = up are called up defined functions.
With regard to my Robot Car project, my attention is drawn to the programs simple_robot.py and source_robot.py. In both programs, only the large blue dot is displayed on the smartphone as in the first picture, but the functionality is different.
For my Robot Car with Raspberry Pi and the Motor Controller Phat Motozero from ThePihut, I only have to change the line with the GPIO pins of the Robot object. I use the outputs for Motor 3 LEFT = (23.16) and Motor 4 Right = (13.18). The Raspberry Pi previously coupled in the settings is displayed in the app after starting the program. After tapping, the blue dot appears. When typing onto the four "cardinal points", the wheels move at full throttle, but my left wheel turns in the wrong direction. The remedy would be exchanged of the GPIO numbers when instantiation of the Robot and restart of the program, or quickly overflow the engine on the motor controller.
But only full throttle before or back, or high speed spinning on the spot, are unsatisfactory. So next I try the demo program source_robot.py.
This means that the Robot Car can also drive slower because a coordinate system is stored for the blue dot. The values for X and Y are between -1.0 and +1.0. Alternatively, you can also determine angles and distance. Result: much better, but the cornering is still unsatisfactory, because the program only knows: one wheel turns forward, the other backwards, unfortunately not: one bike turns faster than the other for a quiet movement.
At this point I remembered that in spring 2021 we had a blog series on the subject of Robot Car, where we also developed code for cornering. This makes this blog post a continuation of the blog, so to speak Robot Car with Raspberry Pi of April 24, 2021.
At that time we developed a code, each with 5 speed levels per direction. Code 505 stood for standstill, the initial number 6 to 10 for forward trip, 4 to 0 for reverse ride, the rear number group for left or right curve. We were able to use this code both for keyboard input and radio transmission with HC-12 or NRF24L01. The advantages of the driving levels lies in the adapted pulse width modulation for the engines. For the lowest driving level, the motors already need 20% to 40% of the voltage. They just hum, but don't turn yet. And if necessary, the maximum voltage, e.g. two lithium batteries, is too much for the continuous operation of the engines, in my case only 60% to 70% of the maximum value.
In the next step, I would like to develop a (sub) program that captures the X, Y coordinates of the blue point and converted into the indices for my driving level list. As a starting point, I choose the sample program dot_single_Button_debug.py. All essential methods (functions) (hereinafter referred to bold) used as examples:
As usual with object -oriented programming, self -defined functions are called up by methods. Be recognized dot.when_client_connects and dot.When_client_disconnects For the connection Raspberry Pi and smartphone, as well as dot.when_pressed, dot.when_released, dot.When_moved, dot.When_swiped and dot.When_double_pressed for interaction with the blue point.
In the self-defined functions, only the type of interaction and the respective data are issued with the print command. Here I started to calculate my driving levels from the X and Y coordinates. So: The decimal values between -1.0 and +1.0 are to be converted between 0 and 10 in integer numbers. To do this, I multiply the values with 5, round without decimal places and add 5. These values are then the indices of my list of driving levels.
After a lot of trying out, I decided to only use the When_Pressed method. The Robot Car drives approximately in the direction that is typed on the blue dot. When tapping the middle or when the Bluetooth connection is interrupted by the back button (triangular icon) on the smartphone, the Robot Car stops.
Next I have to do these program sets with the program from the blog Robot Car with Raspberry Pi of April 24, 2021 associate. Last year I took keyboard commands for the control. This part can now be omitted, but I would like to take over the implementation of the Y and X values in driving stages.
Perfect, the driving levels and the corrections for the cornering fit for the few free square meters in our living room. This does not necessarily have to be the case with another voltage supply. Then please adjust the values for the driving levels and the corrections for the cornering. It is only important that the mean value of the eleven driving levels (index 5, because the count begins at 0!) Is always 0. For the autostart of the program and automatic shutdown of the Raspi at the end, I refer to the Blog Robot Car with Raspberry Pi of April 24, 2021.
Finally, I show a small video of my first driving attempts. Driving is not difficult. If you have typed incorrectly, just press again. It was difficult for me to drive and film at the same time and keep it as a smartphone and robot car in the picture. It is worth imitating, it's really fun. Thanks to Martin O’Hanlon for this easy -to -use Bluetooth app.