RC Viper ACR - Basic of RPI, Alpha Version
The second part of RC Viper ACR Technologies & Systems is focused on basics of RPI, communication between RPI and the client, and shows real codes from the Alpha version.
Install the software on RPI
As a first thing, OS has to be installed on RPI. The used operating system is a modified version of Linux, Raspbian Jessie. We can obtain this operating system on the RPI site in the download section, at https://www.raspberrypi.org/downloads/. Then we needed copy that downloaded system to an SD card, which was inserted into the device.
We used Win32imager to upload the operating system to the micro SD card. The operating system must be in the .IMG format. We downloaded the program from the original manufacturer’s site at: http://sourceforge.net/projects/win32diskimager/files/Archive/.
In the Win32 Disk Imager program, we chose the location of the .IMG file with the operating system in the top row and select, where we wanted to write this OS. After selecting, we pressed “write” and saw the progress bar as writing. Once it was complete, the program made a successful sign-up report and we could close it. We inserted the card into the RPI and connected it to the power supply.
A keyboard, a mouse and a screen are needed for setup the RPI, as you need to enable SSH for remote access and set up a wifi module. Raspbian Jessie has a graphical interface, so there is no problem connecting the wifi module to the network, just click on the wifi icon and select the network, the setting as the Access Point is more complicated, but in the final version it is not used, so we skip this step in the documentation.
When we connected wifi, we could activate SSH. We opened a command prompt and typed into it sudo raspi-config. We chose Interfacing options and found ssh, pressed enter and selected Enable ssh server.
Subsequently, we could download and install the necessary programs directly from RPI or from a PC via SSH, namely PubNub, Python and Apache 2. Libraries like RPI GPIO that we used in the programs are pre-installed in Raspbiane Jessie, so we needed to install the server and update python. (Be sure to use pip install ‘pubnub = 3, <4’ since 2017).
We did not program directly on RPI but on a computer in Sublime Text 2, so after installing, we could turn RPI off and put it in the car.
Communication between the model and end devices
PubNub, Alpha version of the program
Then we implemented these messages into a simple Alpha version that served to verify component functionality along with PubNub. We had several checkboxes, a slider, and a dropdown menu.
Let’s focus on the lights again. We have channel1 here defined as “lights”. This channel is subscribed and lights_callback starts when the message is received. The message is checked, depending on whether the checkbox has been checked or not, the GPIO pin 19 is set to output and then turns on or off the LEDs. GPIO pins can be used to either read or generate a stable or PWM signal. We now use GPIO pin 19 to supply LEDs, we set the logic 1 or 0 at the output, otherwise we control whether the current flows through the diode or not.
If we look at the servo slider, this is a little more complicated. Slider sends numbers even with decimal places, checks which mode we have selected, we can manually control the servos only in manual mode, it creates a variable pwm in which is defined that GPIO pin 22 is set to output, then calculates the angle of rotation, triggers the PWM on the GPIO 22 at 100Hz, changes the servo angle and turns off the PWM.
The last thing we look at here is reading the sensor. First, we define GPIO 18 as active input so that it better detects input drops, ie logic 0. If the value of GPIO 18 changes, the my_callback function will be triggered to check the state of the air brake, if it is on, outputs to the servo will be 150, which is an vertical spoiler position (airbrake up). If it is not, it detects the press, which we will use later in the MGU-K, when we want the recuperation to take place even without the activated air brake.
That is all for today, and little advice at the end - if you would build model like this, I recommend RPI ZERO W with built-in WIFI, I used ZERO v1.3.