Main Content

Line Follower with Arm and Claw Position Control Using Line Tracker and Potentiometer

This example shows you how to use Simulink® Coder™ Support Package for VEX® EDR V5 Robot Brain to create a line follower robot with a robotic arm and claw control using the VEX Clawbot. The robot, with an object manually placed between its claw, follows a black line on a white surface. When the end of the black line is reached, which is indicated by a wider black line, the robot stops, lowers the robotic arm and drops the object held between its claws. Three VEX Line Trackers will be used for the purpose of following a black line, a potentiometer for the control of robotic arm position, and the in-built encoder of V5 Smart Motor for the control of the claw opening.

Introduction

Simulink Coder Support Package for VEX EDR V5 Robot Brain enables you to create and run Simulink models on a VEX V5 Robot Brain.

In this example, you will learn how to use VEX Line Trackers to create a line follower robot, VEX Potentiometer to control the position of the robotic arm and in-built encoder of V5 Smart Motor to control the claw position. You will also learn about using the Analog Input block for interfacing analog sensors to the VEX V5 Robot Brain. In this application, the VEX Clawbot is placed on a black line track with an object placed between its claws. The robot moves along the black line path. When it encounters the end of line indicated by a wider black line, the robot stops, lowers the robotic arm and drops the object held between its claws. The figure below illustrates the application.

The algorithm used for the line following function of the robot is explained below:

The line trackers are mounted on the robot such that they face downwards towards the ground and the spacing between them is such that when the robot is placed on the black line, the center line tracker is above the black line and the other two line trackers are above the white surface. The VEX Line Tracker provides a value from 0 to 4095 based on the light intensity. The value increases with decrease in light intensity. As the line trackers are mounted facing downwards, the value returned by them depends on the light intensity reflected from the surface. When the robot is directly above the black line, the center line tracker reading will be higher than the left and right line tracker readings. In order to differentiate between the black and white surface using the line tracker readings, a cutoff value/threshold that lies approximately between the black and white surface readings is chosen. If the line tracker reading is above the threshold, the sensor is above the black surface and hence, the comparison output is 1. The comparison output will be 0 for the line trackers above the white surface. The comparison outputs are multiplied by weights to give a unique value for each combination of the outputs as illustrated in the figure below.

The product value obtained from the weight multiplication signifies the current status of the robot with respect to the black line and is used to take appropriate action as shown in the below table.

Prerequisites

  • If you are new to Simulink, watch the Simulink Quick Start video.

  • Complete the Getting Started with VEX EDR V5 Support Package example.

Required Hardware

To run this example, you need the following hardware:

  • VEX EDR V5 Robot Brain

  • V5 Smart Motors (4)

  • VEX Potentiometer

  • VEX Line Tracker (3)

  • Two-wheel robot platform

  • V5 Robot Battery

  • 600mm Smart Cable (4)

  • USB A to Micro Cable

  • Track drawing on A0 white sheet with ~ 1.5" wide black line.

Task 1 - Hardware Connections

1. The two V5 Smart Motors drive the left and right set of wheels on the robot platform. The motors are installed on the robot with the motor shafts facing outwards to enable connecting the wheels to the shafts. Connect the left Smart Motor and right Smart Motor to Smart ports 1 and 2 respectively on the VEX V5 Robot Brain.

2. Mount the three VEX Line Trackers on the front of the robot platform such that they face downwards as shown in the figure below. This enables the line trackers to sense white or black surface based on the infrared light reflected from the surface. Since the range for the VEX Line Tracker is approximately 0.02 to 0.25 inch from the ground, ensure that the line trackers are mounted within this range from the ground. The gap between the line trackers should be such that when the robot is placed on the center of a black line, the center line tracker is above the black line and left and right line trackers are above the white surface. Connect the Line Trackers beginning from left to right to analog ports A, B and C respectively on the VEX V5 Robot Brain, using 3-wire cables.

3. Connect the Smart Motor on the robotic arm to Smart Port 3 on the VEX V5 Robot Brain. Insert the shaft of the VEX potentiometer through the motor shaft. Since the potentiometer has a limited rotation range of about 260 degrees, ensure that the potentiometer is not at its extreme position when inserting it through the motor shaft so that the robotic arm is not restricted from rotating due to the potentiometer's placement. Connect the potentiometer to analog port D on the VEX V5 Robot Brain.

4. Connect the Smart Motor on the claw to Smart Port 4 on the VEX V5 Robot Brain.

5. Connect the V5 Robot Battery to the VEX V5 Robot Brain.

Task 5 - Build and Download the Simulink Model for Line Follower Robot with Arm and Claw Position Control

In this task, you will learn how to use the line trackers to model the logic to control the motion of a 4-wheeled robot to follow the black line on a white surface and stop when it reaches the end of the black line. You will also learn how to use the potentiometer to control the movement of the robotic arm and in-built encoder of Smart Motor to control the claw movement. You will then build and download the model to the VEX V5 Robot Brain.

1. Open the vexv5_pot_linetrack pre-configured model.

2. Note the following points in the Simulink model:

  • The parameter values Port for the Analog Input blocks are chosen as per the Line Tracker and Potentiometer connections in Task 1. The parameter values Smart port for the Smart Motor blocks are chosen as per the motor connections in Task 1.

  • The light intensity is read by the three line trackers when the robot is placed on the line follower track. The light intensity read is compared against the threshold value specified using a Constant block. This Constant block is named as Threshold. If a line tracker reading is greater than the threshold, it means that the tracker is on the black line and the output of the comparison is 1. Similarly, if the line tracker reading is less than the threshold, it means that the tracker is on the white surface and the comparison output will be 0. Therefore, after the comparison, either 0 or 1 will be the output corresponding to each line tracker reading.

  • Each comparison output is multiplied by a weight specified by Gain block and the three products are added together to provide a number between 0 to 7. Each output value signifies a status of the robot on the track and appropriate action required as shown in the table in the Introduction section.

  • As the left and right motors are attached to the robot platform with their shafts facing outwards, providing speed input of opposite signs to the motors makes them rotate in the same direction, causing the robot to go straight. To make the robot turn, the two motors are provided with speed input of same sign so that the motors rotate in opposite direction. The left and right motors are provided with a speed input of '-20' and '20' respectively for straight motion. The motors are provided with a speed of '30' to turn the robot left and a speed of '-30' to turn the robot right.

  • The logic for motion control based on the line tracker readings is implemented in the Stateflow® chart as shown below. See Getting Started with Stateflow for an introduction to implementing states in Stateflow.

  • The logic for controlling the arm motor and claw motor is implemented in an Enabled Subsystem. Enabled Subsystem is a subsystem that executes at time steps for which the enable input has a positive value. When end of the black line is reached, the output StartRoboticArm of the Stateflow Chart changes to 1 enabling the subsystem to control the arm motor. Refer Create an Enabled Subsystem for more information on enabled subsystems.

  • The subsystem Enabled Subsystem for Arm Control shown below includes the implementation for driving the arm motor depending on the potentiometer reading. The potentiometer value is compared against the values in Constant blocks named as Potentiometer value when arm is vertical and Potentiometer value when arm is horizontal. The comparison outputs are ANDed using Logical Operator block and multiplied by a speed value of '25' from Constant block and provided as the speed input to the Arm motor. Therefore, when this subsystem is enabled, the arm motor is provided with a non-zero speed value as long as the potentiometer reading is between the limits of arm's vertical and horizontal positions.

  • When the potentiometer reading exceeds the value for the arm to reach a horizontal position, the subsystem Enabled Subsystem for Claw Control is enabled. This subsystem shown below implements the logic for driving the claw motor until the tick count is reached, similar to the logic in the subsystem to control arm motor.

3. In the Simulink model, go to the Modeling tab and click Model Settings.

4. When the Configuration Parameters page opens up, navigate to the Hardware Implementation pane.

  • Set the Hardware board to VEX V5 Robot Brain.

5. In the Configuration Parameters page, navigate to Solver pane and set the Solver to discrete (no continuous states).

6. Click OK.

7. Before building the model, make sure to connect the VEX V5 Robot Brain to your computer with a USB A to Micro Cable.

8. In the Simulink model, go to the Hardware tab and click Build, Deploy & Start. The model will now be deployed to the VEX V5 Robot Brain.

9. Disconnect the USB cable from the PC. Place the robot at the beginning of the black line, with an object held between its claws. Run the program (deployed model) by using the dashboard on the VEX V5 Robot Brain. The robot begins to move along the black line. When the end of line is reached, the robot stops and motors on the arm and claw are driven to lower the robotic arm and release the object.

Other Things to Try

In this Simulink model, the threshold values used are:

  • 2125 (for the three Line Trackers)

  • 390 (for the Potentiometer value when arm is vertical)

  • 1250 (for the Potentiometer value when arm is horizontal)

  • 60 (for the tick count of Smart Motor when the claw releases the object).

However, you can perform parameter tuning and correct these threshold values for better performance of the robot.

For example, you can create a simple Simulink model that uses the outputs of three Analog Input blocks, which are used for the three Line Trackers, and connect them to the inputs of three Display blocks.

You can then use the Monitor & Tune feature in Simulink to calculate the thresholds for Line Trackers.

1. While the model is running on the VEX V5 Robot Brain (for signal monitoring and parameter tuning as part of Monitor and Tune operation), place the robot on the white surface of the track. Note the left, center and right line tracker readings from the corresponding Display blocks in the Simulink model. Let us call these line tracker readings on the white surface as $White\ surface{_l}{_e}{_f}{_t}$, $White\ surface{_c}{_e}{_n}{_t}{_e}{_r}$ and $White\ surface{_r}{_i}{_g}{_h}{_t}$. Similarly, note the line tracker readings by placing the robot such that all the three sensors are directly below the black line. Let us call these line tracker readings on the black line as $Black\ line{_l}{_e}{_f}{_t}$, $Black\ line{_c}{_e}{_n}{_t}{_e}{_r}$ and $Black\ line{_r}{_i}{_g}{_h}{_t}$. Keep in mind that the line tracker readings are affected by the lighting conditions, position of the light source and shadows in the robot's environment. Therefore, it is good to take the readings in an environment which has lighting conditions similar to the place where you would like to drive the line follower robot.

2. Calculate the average $White\ surface{_a}{_v}{_g}$ of the left line tracker $White\ surface{_l}{_e}{_f}{_t}$, center line tracker $White\ surface{_c}{_e}{_n}{_t}{_e}{_r}$ and right line tracker $White\ surface{_r}{_i}{_g}{_h}{_t}$ readings using the formula below:

$$White\ surface{_a}{_v}{_g} = \frac{White\ surface{_l}{_e}{_f}{_t} + White\ surface{_c}{_e}{_n}{_t}{_e}{_r} + White\ surface{_r}{_i}{_g}{_h}{_t}}{3}$$

Similarly, calculate the average $Black\ line{_a}{_v}{_g}$ of the left line tracker $Black\ line{_l}{_e}{_f}{_t}$, center line tracker $Black\ line{_c}{_e}{_n}{_t}{_e}{_r}$ and right line tracker $Black\ line{_r}{_i}{_g}{_h}{_t}$ readings using the formula below:

$$Black\ line{_a}{_v}{_g} = \frac{Black\ line{_l}{_e}{_f}{_t} + Black\ line{_c}{_e}{_n}{_t}{_e}{_r} + Black\ line{_r}{_i}{_g}{_h}{_t}}{3}$$

3. Calculate the threshold value between the black and white surface by taking the average of white and black surface averages as shown below:

$$Threshold = \frac{White\ surface{_a}{_v}{_g} + Black\ line{_a}{_v}{_g}}{2}$$

The calculated threshold value gives a good indication of value range for black and white surfaces for a particular environment. Note that it may be required to vary the threshold slightly from the calculated value based on trials and observations on the line follower robot.

4. In the Hardware tab, click Stop to terminate signal monitoring and parameter tuning.