2021-05-09 - By Eduardo Campos, Leah Carinci, Daniela Diaz Tenorio
The purpose of this article is to document the progress on the 'Robot Tank Project' that was achieved by Eduardo Campos, Leah Carinci, and Daniela Diaz Tenorio during their Winter 2021 Capstone project at Conestoga college. This project builds upon several similar 'robot tank' projects that have been done by other students:
- Can You Build a Streaming Video Robot Tank for ~$100?
- A PCB For The Robot Tank
- A Cheaper PCB For The Robot Tank
- Improved Tilt Pan Camera Control For The Robot Tank
The primary objects of this project were as follows:
- To document and describe the existing design flaws in the robot tank design.
- To identify the source of power issues with the robot tank motors (they would power off randomly).
- To identify the cause of jitter in the servo that controls the camera mount.
- To improve the documentation and labels of the KiCad design files of the PCB that this project uses.
All major objectives were accomplished and the team produced the following project artifacts:
- Board_Bring-Up_Plan.pdf - A document that describes how to evaluate whether the robot is in good working order and that all components are connected properly and functioning correctly.
- CapstoneReport.pdf - A detailed document describing the analysis and improvements that were performed during this capstone project.
- robot-tank-kicad-files-2021-04-30.zip - An updated version of the KiCad project files with improved labels and corrections.
The team also published their code for this project at https://github.com/dandiaz10/robot_tank_capstone.
Battery Banks Powering Off
The team concluded that one of the issues with the previous design was related to the use of USB power banks to power the tank motors:
The conclusion was that these USB power banks contain circuitry to 'switch off' completely when the current draw drops below a certain value for an extended period of time. This conclusion is supported by other sources that describe how USB power banks commonly contain an internal battery with a voltage other than 5V. In order to deliver 5V this requires an internal DC converter circuit which requires power to operate. If this circuit were on all the time, it would continuously waste power causing the battery to drain even when there was no useful power being consumed. Therefore, many power bank designs include a feature that switches them off automatically. This is a problem for this remotely operated robot tank, since the operator of the tank may take a break of several seconds or minutes between successive use of the motors, thereby triggering the 'shut-off' of the batteries due to low current consumption.
The alternative that was chosen for this project was to power the motors using simple AA batteries which do not have the same limitation. For powering the Raspberry Pi, a USB power bank was still appropriate.
Voltage Drop Causing L298N Issues
Another potential issue that the team identified was related to powering the L298N motor driver. The previous design of the robot tank used only a single input power source to the L298N motor driver. In the default jumper mode, the L298N can use this single power source to both power itself and supply power to the robot tank motors. However, in situations where the tank motors begin consuming high current (for example when the tank gets stuck against a wall), this can cause a voltage sag that affects not only the power to the motors but also the powering of the L298N itself, thereby causing it to operate out of specification.
Therefore, the team changed the L298N jumper mode to use use two separate power sources: One to power the motors, and another separate 5V input to power the L298N motor driver itself from a separate power supply.
Improved KiCad Labels
The previous set of KiCad files for the PCB did not have descriptive labels, and several connections were labeled incorrectly. The team made the appropriate adjustments to the design files, and here is the result:
In addition to the updates to the KiCad design files, the team also created more documentation about the wiring configurations that are currently used by this robot tank design:
The above photo, along with more documentation, can be found in the section '7.1.3. Connect the L298N (Headers J2 and J3)' of CapstoneReport.pdf.
Camera Mount Servo Jitter Issues
Another problem with the previous design was that the Raspberry Pi camera servo mount would experience constant jitter and shake even when it was not in use. The team concluded that the root cause was the use of 'soft PWM' instead of 'hard PWM'. In section '188.8.131.52. Raspberry Pi – Hardware PWM' of CapstoneReport.pdf, the team documents this issue further and provides the following fix for enabling hard PWM:
# 1. Open the config.txt sudo nano /boot/config.txt # 2. Find the line below. # Enable audio (loads snd_bcm2835) dtparam=audio=on # 3. Comment out the audio line by including the character # # dtparam=audio=on # 4. Include a new line at the end of the file. dtoverlay=pwm-2chan # 5. Save the file and reboot the raspberry. sudo reboot # 6. Run the command below to verify if the procedure was successful: lsmod | grep pwm # 7. It should produce the following answer: pwm_bcm2835
As mentioned in 'CapstoneReport.pdf', this topic is further discussed at Using the Raspberry Pi Hardware PWM timers.
The team's git repo also contains the following piece of code in the file 'Raspberry/PWM.py' that was used for initializing the PWM signal to control the servos:
import time import os #https://www.raspberrypi.org/app/uploads/2012/02/BCM2835-ARM-Peripherals.pdf #https://jumpnowtek.com/rpi/Using-the-Raspberry-Pi-Hardware-PWM-timers.html #page 140 #PW0 -> GPIO18 (Using Alt Function 5), pin 12 #PW1 -> GPIO19 (Using Alt Function 5), pin 35 class PWM: #Both duty_cycle and period expect values in nanoseconds timeBase = 1e9 period= None dutySaved = None _Channel = None frequency=None def __init__(self, Channel): self._Channel=Channel def freq(self,Value): self.frequency=Value self.period = self.timeBase/Value os.system("echo " + str(int(self.period))+ " > /sys/class/pwm/pwmchip0/pwm"+str(self._Channel)+"/period") def Start(self,Freq): #https://jumpnowtek.com/rpi/Using-the-Raspberry-Pi-Hardware-PWM-timers.html #enable the PWM1 os.system("echo "+str(self._Channel)+" > /sys/class/pwm/pwmchip0/export") #wait for hardware initialization time.sleep(1) #setup the PWM frequency 1Khz self.frequency=Freq self.period = self.timeBase/self.frequency os.system("echo " + str(int(self.period))+ " > /sys/class/pwm/pwmchip0/pwm"+str(self._Channel)+"/period") #Set the initial duty cycle if(self.dutySaved !=None): self.Duty(self.dutySaved) #enable the hardware os.system("echo 1 > /sys/class/pwm/pwmchip0/pwm"+str(self._Channel)+"/enable") def Stop(self): os.system("echo 0 > /sys/class/pwm/pwmchip0/pwm"+str(self._Channel)+"/enable") os.system("echo "+str(self._Channel)+" > /sys/class/pwm/pwmchip0/unexport") def Duty(self,Value): self.dutySaved = Value if (self.period ==None): print("PWM not initialized") return if (Value > 100.0) or (Value < 0): print("Duty must be between 0.0 and 100.0") return os.system("echo "+ str(int( self.period*(Value/100.0) )) +" > /sys/class/pwm/pwmchip0/pwm"+str(self._Channel)+"/duty_cycle")
As discussed above, the students made a number of improvements and detailed descriptions that will improve the functioning of future versions of the robot tank.
Monitoring of Plant Growth on a Budget With Arduino
Can You Build a Streaming Video Robot Tank for ~$100?
All About SD Card Flash Memory Corruption in Cameras & Raspberry Pis
Automated Plant Watering With Arduino
A PCB For The Robot Tank
A Cheaper PCB For The Robot Tank
Improved Tilt Pan Camera Control For The Robot Tank
A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
Why Bother Subscribing?