Author Archive:amber

Byamber

Rasberry Pi Tank Car Starter Kit Lesson 3:Line follow

Authorized Online Retailers

Buy from US Buy from UK Buy from DE Buy from IT Buy from FR Buy from ES

topObjective

In this lesson, we will use black/white tracking sensors to guide robot car to trace a black track in the white ground. If you have not completed installation in Lesson 1, please review Lesson 2.

Hardware Installation

Note: in lesson 1, 5 black/white tracking sensors have been installed and connected to Raspberry Pi to prepare for lesson 3.

Software Installation

Note:Please keep the raspberry Pi on power when using SSH to send command to Raspberry Pi terminal remotely.

Step 1:Download line-tracking sample code with following terminal command.

cd  osoyoo-robot/
wget   http://osoyoo.com/driver/lf-tank.tar.gz
Lesson3-step1

Note: Above commands will download sample code file to osoyoo-robot/lf directory
STEP2: Extract sample code file..
tar -zxvf lf-tank.tar.gz
cd lf

Lesson3-step2-1 Lesson3-step2-2

Step 3: Test Black/White Tracking sensors

There are 5 black/white tracking sensors in the forehead of the car. Each sensor has two LED lights . The red LED indicates power. The green LED indicates black/white. When black is detected, Green LED will turn off and a “1” will be sent to Raspberry Pi GPIO pin, otherwise LED will ON and a “0” will be sent.
* To make sensors working properly, you need use a screw driver to adjust the sensitivity screw on each sensor and make sure Green LED will ON when it is over White and Off when it is over Black.

Following python code and experiment will tell you if the sensors are installed correctly.
First, put a 2 cm black track on white ground, then put your car over the track and turn on battery.
Next, use SSH to connect your Raspberry Pi remotely from your PC(use Putty if you are using Windows), and type following terminal command:

sudo python test.py

Lesson3-step3

When your put the first sensor(from right) on the black track, the green LED will turn off and your will see Putty terminal window show 00001 as following:

Lesson3-step4-2

This means Raspberry Pi detected WHITE(0) from 4 sensors in the left and Black(1) from the right edge sensor. You can change the position of the black track from right to left sensors one by one and make the result change from 00001 to 00010,00100,01000,10000.If your result is not showed as above, you might need to double check if the sensor sensitivity and connection to the Pi is correct.

top

Testing line tracking

First, make a black track on white ground. The track can be round or curve , but the turning angle of each curve should not be too sharp. We suggest user use 2cm width black tape sticking on white ceramic tile and make a nice track.

Next put your car over the track and turn on the power switch on battery box.

Last, use SSH to connect Raspberry Pi through your PC and typing following commands:
cd ~/osoyoo-robot/lf
sudo python line_follow.py

Test

After above command is sent to raspberry Pi, your car will start moving along the black track automatically.

top

Byamber

Rasberry Pi Tank Car Starter Kit Lesson 2:Installation of Electronic Parts

Authorized Online Retailers

>

Buy from US Buy from UK Buy from DE Buy from IT Buy from FR Buy from ES

top

Objective

In this lesson, we will install the most important framework in the smart car and make car to do some simple movements as per our python sample code. If you have passed the test movement of this lesson, that means Arduino, voltage meter,motor drive module(Model-PI), motors, batteries,chassis and wire connections between these parts are all functioning well.
As your experiments in future lessons are all based on frame work of Lesson One, it is very important to test the installation and sample code in this Lesson properly.

top

Hardware Installation

Video intutorial for Hardware Installation

STEP1. Install raspberry pi board,model pi driver board and 16 Channel 12-bit PWM compatible module as follows.

STEP1

STEP2:Install the Voltage Meter,Webcam and 5 tracking sensors as follows.

STEP2

STEP3:Connect the electronic parts as follows:

(1)Connect right and left motors to K1 and K3 sockets in model pi driver board.

STEP3-1
(2)Connect voltage meter and battery box to model pi driver board as follows.

STEP3-2
(3)Connect 16 Channel 12-bit PWM compatible module to model pi driver board as follows.

STEP3-3
(4)Connect right and left LED ligth to 16 Channel 12-bit PWM compatible module as follows.

STEP3-4
(5)Connect raspberry pi board to 16 Channel 12-bit PWM compatible module as follows.

STEP3-5
(6)Connect 5 tracking sensors to 16 Channel 12-bit PWM compatible module as follows.

II.Software Installation

Software Preparation:
Imager utility: Win32DiskImager utility
OS: Raspbian (Use OS Raspbian 2018-04-18 in the subsequent tutorials)
Format Tool: SDFormatter (Optional)
SSH Tool: PuTTY (for Windows users)

Step 1:Before connect to Raspberry Pi, you need to install Raspbian Operation System(OS) onto SD card.You can select the latest version of RASPBIAN system on the official website: https://downloads.raspberrypi.org/raspbian/images/. Write the image via Win32DiskImager utility into your microSD/TF card(minimum 16G), then plug the card into the slot on your Raspberry Pi.

write_raspbian

Step 1: Connect Wifi
Firstly, Connect Raspberry Pi to your HDMI monitor or TV. Put a keyboard and mouse into Raspberry Pi USB ports. Insert SD card into the slot on your Raspberry Pi.Click on the wireless icon top right on desktop, should give a list of access points, select your wifi ssid and connect it. Once your Pi is connect to Wifi, you can hover your mouse to the wifi icon to see the your IP address.

Or your can type sudo ifconfig wlan0 command in terminal. Your local ip address will show in wlan0 block(right side of the word inet addr:). It will look like 192.168……

Please remember above IP address, it will be used in our next steps.

Step 2: Open SSH connection

SSH enable user to type shell command remotely from internet so that we can control the car through wifi.In order to enable SSH function, we need type following command from terminal:

sudo raspi-config

Then select Interfacing Options->SSH->Yes->Ok->Finish

step2-1-advanced_option

step2-2-SSH

step2-3-SSH_Yes

step2-4-SSH-Yes

step2-5-SSH_finish

Step 3:Use SSH to connect Raspberry Pi terminal remotely

In order to make the car moving freely, we need disconnect Raspberry Pi from monitor, keyboard/mouse and use SSH to send command to Raspberry Pi terminal remotely.

If you are using Windows to send ssh command. you need download a free software called PuTTy to connect the Raspberry Pi local IP(you got from STEP 1).

If you are using MacBook or other linux computer, please type: ssh pi@192.168.50.7

(补一张苹果电脑终端的图片)

ssh your_raspberry_pi_local_ip_address

*your_raspberry_pi_local_ip_address means the wifi IP address you got from STEP 1

When connecting ssh, you need use default user name pi and default password raspberry to login to Raspberry Pi.

Step 4: Open I2C function

I2C is a protocol which will be used to exchange data with I2C device. In our project, I2C device is PCA9685 module.In order to use I2C function, we need type following command from terminal:

sudo raspi-config

Then select Interfacing Options->I2C->Yes->Ok->Finish

step3-1-advanced_option


Step 5: Install GPIO Library

  • (1)Update Rasbian Repository by typing following terminal command
cd ~ 
sudo apt-get update
  • (2)Install python-pip , python-sumbus and github
sudo apt-get install build-essential python-pip python-dev python-smbus git
  • (3)Install GPIO Library by typing following terminal command
git clone https://github.com/adafruit/Adafruit_Python_GPIO.git
cd Adafruit_Python_GPIO
sudo python setup.py install
  • (4)Typing following terminal command to remove installation files and save disk space
cd ~ 
sudo rm -fr Adafruit_Python_GPIO

Testing Previous Installation

  • (5)Download testing python code by typing following commands:
cd ~ 
mkdir -p osoyoo-robot/ 
cd osoyoo-robot/ 
wget http://osoyoo.com/driver/motor-test-tank.tar.gz
tar -zxvf motor-test-tank.tar.gz
cd motor-test

top

Testing

Step 6: Run Testing Python code

cd ~/osoyoo-robot/motor-test
python motor-test.py

After running above python sample code, your car should move forward for 2 seconds, then move backward for 2 seconds , then turn left for 2 seconds and finally turn right for 2 seconds.

If your car does not move as per above scenario, the installation should have some problem. You need double check the wire connection and software installation as per our previous steps.

Previous_Lesson