Robot Tank Car Starter Kit Lesson 4:Tracking Robot Tank Car

Byamber

Robot Tank Car Starter Kit Lesson 4:Tracking Robot Tank Car

Robot Tank Car Starter Kit Lesson 4: Control the motor

Objective:

In this lesson, we will use 2 black/white tracking sensors to the framework built in Lesson 1. If you have not completed installation in Lesson 1, please review Lesson 1

The software in this lesson will read data from these 2 black/white tracking sensors and automatically guide the smart car to move along the black track line in the white ground.

How It Work:

There are two probe on tracking sensor module,one is sender diode(IR LED) and the other one is receiver diode(Photo Diode).

If the tracking sensor is not on black track,the infrared ray from IR LED can be reflected and received by photo diode. The sensor will output low level.

If the tracking sensor is on black track,the infrared ray from IR LED can not be reflected and not received by photo diode. The sensor will output high level.

There are 2 tracking sensor on left and right. When the left tracking sensor on black line, the tank car will turn left. When the right tracking sensor on black line, the tank car will turn right. When the left and right tracking sensor on both sideways of black line, the tank car will go straight. When both tracking sensor are on black line,the tank car will stop.

Software Installation:

Step 1: Install latest Arduino IDE (If you have Arduino IDE version after 1.1.16, please skip this step)
Download Arduino IDE from https://www.arduino.cc/en/Main/Software?setlang=en , then install the software.

Step 2:Download Lesson 4 sample code from http://osoyoo.com/driver/tank_robot_lesson4.zip , unzip the download zip file tank_robot_lesson4.zip, you will see a folder called tank_robot_lesson4.

Step 3: Connect UNO R3 board to PC with USB cable, Open Arduino IDE -> click file -> click Open -> choose code “tank_robot_lesson4.ino” in tank_robot_lesson2 folder, load the code into arduino.

open

Step 4: Choose corresponding board and port for your project,upload the sketch to the board.

port

Understanding the Code:

Step 1: Define the pinout of left and right tracking sensor.

#define LFSensor_1 A0 //line follow sensor1
#define LFSensor_2 A1 //line follow sensor2

Step 2:Read the signal from tracking sensor and store the signal value.

void read_sensor_values()
{
  sensor[0]=digitalRead(LFSensor_1);
  sensor[1]=digitalRead(LFSensor_2);
}

Step 3:Control the tank car movement. The structure of auto_tarcking() can get the left and right sensor signal via call the structure of read_sensor_values(),then judge the signals via “if “control structure.

void auto_tarcking(){
  read_sensor_values();
  if((sensor[0]==LOW)&&(sensor[1]==HIGH)){ //The right sensor is on the black line.The left sensor is on the white line
    set_motorspeed(M_SPEED1,M_SPEED1);
    turn_right(250);
  }
  else if((sensor[0]==HIGH)&&(sensor[1]==LOW)){//The right sensor is on the white line.The left sensor is on the black line
    set_motorspeed(M_SPEED1,M_SPEED1);
    turn_left(250);
  }
  else if((sensor[0]==LOW)&&(sensor[1]==LOW)){//The left an right sensor are on the white line.
    set_motorspeed(M_SPEED2,M_SPEED2);
    go_ahead();
  }
  else if((sensor[0]==HIGH)&&(sensor[1]==HIGH)){//The left an right sensor are on the blac

Step 4: Testing. Press the OK button to make the tank car go along with black line.Press “o” to make the tank car stop.

注意:若无法循迹,请看考第一课调节循迹模块灵敏度,并检查接线。

About the Author

amber administrator

Comments Are Closed!!!