Skip to main content

What does it take to build a Line Follower Car? Part 2

I am currently having my internship with RS Components. One of my main functions is to work on a project that is related to the Renesas Micom Car Rally.

The aim is to simplify and improve on the procedure of assembling and programming of the Micom car kit. In the process provide related materials to the concepts for building a line following car that is easy to understand.

Overview

In this article, I will be focusing on, the creation of the Micom car kit plates using DesignSpark Mechanical, as well as improving on the car's program for achieving a better performance. If you have not seen my previous article, about the introduction to the Micom car kit, you can find it here.

Creating the car plates

In the previous article, I mention that I will be creating the various car plates for 3D printing. The car consist of the following parts which are required for assembly,

- Main Body Plate

- Driver Board Support Plate

- Front Shaft Support Plate

- Left Long Sensor Arm

- Left Short Sensor Arm

-Right Long Sensor Arm

- Right Short Sensor Arm

- Servo Back Reinforcing Plate(2)

- Servo Front Reinforcing Plate

- Servo Horn Support Plate

- Servo Support Plate

DifferentPlates21_d06e7e22bd8b83dc041c28e3b6aec4d8224f0e77.jpg

 

 

 

 

 

 

 

A total of 12 parts are required to form the car structure during assembly. By using DesignSpark Mechanical, I was able to create the car plates easily shown in the picture above. The various 3D models of the car plates can be downloaded at the end of this article. The 3D models of the car below illustrates the fully assembled car, which consist of the various car plates together with the remaining parts of the car.

3D_car_model_55728ee7cbf2f4c4f3cd83ebdf0912aa4d251ccd.jpg3D_car_top_view_e9822e07c22edea83d9c468839bd8ddfd9f062be.jpg

If you would like to create your own or custom car plates, you can follow the next few simple steps, which illustrates how I created one of the car plate. You can use these steps to create a model for your reference, practice or final design.

I will be showing how to create the main plate which is the largest plate, supporting most of the car components. With this knowledge, creating most of the remaining plates will be a piece of cake. The dimensions of the main plate is shown in the picture below followed by the steps to create it.mainplate2_3652200e98fdbfae9b0e12ea92b15f110a5bc0e1.jpg

 

 

 

 

 

 

 

 

 

 

STEP: 1 Download and installation

  • Download DesignSpark Mechanical HERE
  • Install and Run the application

 

STEP: 2 Creating a new sketch design

  • Click on File >> New >> Design
  • Click on View Plane on the top toolbar located in the “Orient” section
  • Then, press "L"  and click anywhere on the plane to create the start of a line
  • Move the mouse to the desired direction/angle
  • Then, press on the spacebar to change the length of the line
  • Draw the outline of the car's main plate as shown in the picture above using the line tool
  • Once the outline is completed, create circles by pressing "C"  
  • Then, click on "cartesian dimensions" on the sketch options located on the left pull down bar
  • Mouse over the bottom left corner of the car plate outline, and press on shift to set the base point of the circle
  • Use the base point as the reference to, locate the middle point of the circle by, moving the mouse or keying in the measurements of the respective dimensions
  • Draw circles of diameter 3mm, at the respective positions on the car plate outline as shown in the picture above

MainplateSketch_41e62d32409dda33a43bcb983d33015989c6e057.jpg

 

 

 

Note: Once the circles have been drawn on to the outline of the car's main plate, the sketch should look roughly like this picture on the left.

 

Step: 3 Creating the 3D model

  • Press "H" to display the design in a trimetric view 
  • Then, press "P" and click on the surface of the main car plate outline
  • Once the surface is selected, drag and hold the surface downwards for 3mm or just key in the height after pulling
  • Right click on "Surface" and delete it as shown in the picture below

StructureTree_709d15e1f55d59f303137f802ae91c37d682bca7.jpg

 

 

 

 

Note: The unwanted surfaces of the circles can be found in the structure tree located on the left drop down bar.

 

 Step: 4 Smoothing out the edges

  • While on the pull tool, double click on the outline of the plate surface
  • Once the outline of the plate is highlighted, press on the spacebar and key in a value of 0.5mm
  • Repeat the above step for the underside of the plate
  • Then, select the remaining edges by, holding onto the ctrl key, and double click on the remaining edges of the plate as shown in the picture below
  • Finally press on the spacebar and key in a value of 2mmedges_f6b3d6e04f1151482ae8029c3474410e8eab3e70.jpg

 

 

 

 

 

The main plate of the car is now completed and should look like the model that is shown in the first picture.

You may export the models for 3D printing once you have completed designing all the car plates. After printing the car plates using a 3D printer with a PLA filament, the car is assembled with the various parts. The picture below illustrates the assembled car that consist of plates that is printed out from the 3D printer.

printedplate11_cdaa3d495626be9517cc4c9d18fb8187e34e1d6c.jpg

Additionally, if you would like to design your own driver or sensor board, you can accomplish it using DesignSpark PCB. The software, is able to support the full process from, schematic design till the PCB design with no size limitations. Not only does DesignSpark PCB consist of a wide range of component library, you can also create and implement your own component onto your design. Start designing your own custom PCB with DesignSpark PCB HERE for FREE.

Programming the car

A sample program and its explanation for the car, can be downloaded from the Renesas website. The website, also provides the programming software, as well as the device flashing application which is required, for the code to be loaded into the microcontroller.

The sample program for the car is just a basic program that allows to car to manoeuvre through a simple course. When the course’s difficulty increases, the sample program is unable to handle the complexity which causes the car to go off course.

After observing the car's behaviour, and looking through the program code, I have identified the problems that caused the car to go off course. I have improved the program by implementing various algorithms, and tuning of the car’s speed during certain phases, for faster completion of the course. The following table illustrates the improvement made to the various problems in the program.

 Problem

 Solution

 The car moves slowly and steers  vigorously during bends

 Added a new algorithm for manoeuvring  through bends

 The car moves slowly when approaching  a lane change or a 90° turn

 Increased the speed of the car for both  scenarios

 The car travels slowly or off course,  when  executing a lane change, or a  90°  turn

 Changed the algorithm and the speed  ratio of the L/R motors for both  scenarios


The implementation of the solutions to the program will be further explained in the next section.

 Solution 1: New turning algorithm

The following code is used to change the turning algorithm of the program. In order to reduce the vigorous steering of the servo motor, and improving the speed of turning, a new case is implemented for each direction of the turn. In each individual case, the different scenarios for the respective results obtained by the sensor, is assigned to different instructions, where the turning angle and the motor's speed have been configured to achieve optimum efficiency.

Add the following code into the program's main loop:

    case 6:
		/* Right turn */
            if( check_crossline() ) {   /* Cross line check            */
                pattern = 21;
                break;
            }
            if( check_rightline() ) {   /* Right half line detection check */
                pattern = 51;
                break;
            }
            if( check_leftline() ) {    /* Left half line detection check */
                pattern = 61;
                break;
            }
			switch( sensor_inp(MASK4_4) ) {
				
				case 0x0c:
				case 0x08:
				break;
				
				case 0x04:
				handle( 10 );
                motor( 100 ,88 );
				break;
				
				case 0x06:
				case 0x0e:
				handle( 20 );
                motor( 100 ,80 );
				break;
				
				case 0x02:
				case 0x03:
				case 0x83:
				handle( 30 );
                motor( 100 ,75 );
				break;
				

				case 0x01:
				case 0x81:
				handle( 38 );
                motor( 60 ,35 );
				break;
				
				case 0x18:	
				case 0x10:
				case 0x30:
				case 0x20:
				case 0x60:
				pattern = 11;
				
				break;
				
				default:
				handle(0);
				motor(0,0);
				break;
			}
			
		break;
		
	case 7:
		/* Left turn */
            if( check_crossline() ) {   /* Cross line check            */
                pattern = 21;
                break;
            }
            if( check_rightline() ) {   /* Right half line detection check */
                pattern = 51;
                break;
            }
            if( check_leftline() ) {    /* Left half line detection check */
                pattern = 61;
                break;
            }
			switch( sensor_inp(MASK4_4) ) {
				
				case 0x30:
				case 0x10:
				break;
				
				case 0x20:
				handle( -10 );
                motor( 100 ,88 );
				break;
				
				case 0x60:
				case 0x70:
				handle( -20 );
                motor( 100 ,80 );
				break;
				
				case 0x40:
				case 0xc0:
				case 0xc1:
				handle( -30 );
                motor( 100 ,75 );
				break;
				

				case 0x80:
				case 0x81:
				handle( -38 );
                motor( 60 ,35 );
				break;
				
				case 0x18:	
				case 0x08:
				case 0x0c:
				case 0x04:
				case 0x06:
				pattern = 11;
				
				break;
				
				default:
				handle(0);
				motor(0,0);
				break;
			}
			
		break;

 

Replace case 11 with the following code which leads the program to case 6 and 7 when the car is entering a turn:

        case 11:
            /* Normal trace */
            if( check_crossline() ) {   /* Cross line check            */
                pattern = 21;
                break;
            }
            if( check_rightline() ) {   /* Right half line detection check */
                pattern = 51;
                break;
            }
            if( check_leftline() ) {    /* Left half line detection check */
                pattern = 61;
                break;
            }
            switch( sensor_inp(MASK3_3) ) {
                case 0x00:
                    /* Center -> straight */
                    handle( 0 );
                    motor( 100 ,100 );
                    break;

                case 0x04:
                    /* Slight amount left of center -> slight turn to right */
                    handle( 5 );
                    motor( 100 ,100 );
                    break;

                case 0x06:
				case 0x07:
				case 0x03:
				case 0x02:
				case 0x01:
				case 0x0e:
                    /* entering a right turn */
					pattern=6;
                    break;
                case 0x20:
                    /* Slight amount right of center -> slight turn to left */
                    handle( -5 );
               		motor( 100 ,100 );
                    break;

                case 0x80:
				case 0xc0:
				case 0xe0:
				case 0x60:
				case 0x70:
				case 0x40:
				    /* entering a left turn */
					pattern=7;
					break;

                default:
                    break;
            }
            break;

 Delete case 12 and 13 as they have already been included in the case 6 and 7.

Solution 2: Increasing speed when approaching lane change and 90° turn

It was observed that, after the car passes the first 90° turn indicator, the car reduced its speed tremendously. It was also observed that, after the car passed the second lane change and 90° turn indicator, the car moves very slowly. The following changes should be made for the car to achieve a faster speed which results in a faster timing for completing the lane change, and the 90° turn.

Use the following code to change the car's speed after the first 90° turn indicator by changing the motor value in case 21 to values shown in the code below:

motor( 60 ,60 );

 

Use the following code to, change the car's speed after the second 90° turn indicator by changing the motor values in case 23 to the values shown in the code below:

switch( sensor_inp(MASK3_3) ) {
                case 0x00:
                    /* Center -> straight */
                    handle( 0 );
                    motor( 48 ,48 );        // Change this value
                    break;
                case 0x02: 
		        case 0x04:
                case 0x06:
                case 0x07:
                case 0x03:
                    /* Left of center -> turn to right */
                    handle( 8 );
                    motor( 50 ,45 );        // Change this value
                    break;
                case 0x20:
                case 0x60:
                case 0xe0:
                case 0xc0:
                    /* Right of center -> turn to left */
                    handle( -8 );
                    motor( 45 ,50 );        // Change this value
                    break;
            }
            break;

 

Use the following code to change the car's speed after the second lane change indicator by changing the motor value in case 53 to values shown in the code below:

switch( sensor_inp(MASK3_3) ) {
                case 0x00:
                    /* Center -> straight */
                    handle( 0 );
                    motor( 80 ,80 );      //Change this value
                    break;
                case 0x04:
                case 0x06:
                case 0x07:
                case 0x03:
                    /* Left of center -> turn to right */
                    handle( 8 );
                    motor( 80 ,75 );      //Change this value
                    break;
                case 0x20:
                case 0x60:
                case 0xe0:
                case 0xc0:
                    /* Right of center -> turn to left */
                    handle( -8 );
                    motor( 75 ,80 );      //Change this value
                    break;
                default:
                    break;
            }
            break;

The above code is only for a right lane change that is found in case 53. Using the above code as reference, make the appropriate changes to the left lane change, which is found in case 63.

Solution 3: New algorithm during 90° turn and lane change

It was observed that during the 90° turn and lane change, the car was either unable to stay on the track or it turns very slowly. In order to cope with the problem, the algorithm for the respective cases have to be changed. In each individual case, the different scenarios for the respective results obtained by the sensor, is assigned to different instructions. These instructions consist of, the turning angle and the motor's speed, which have been configured to achieve optimum efficiency.

In order to achieve, a better turning efficiency during the 90° turn, locate the values of the motor and the steer angle in case 23, and change it to the values shown in the following code:

if( sensor_inp(MASK4_0)==0xf0 ) {             
                /* Left crank determined -> to left crank clearing processing */
                led_out( 0x1 );
                handle( -40 );              //Change this value
                motor( 20 ,100 );           //Change this value
                pattern = 31;
                cnt1 = 0;
                break;
            }
            if( sensor_inp(MASK0_4)==0x0f ) {
                /* Right crank determined -> to right crank clearing processing */
                led_out( 0x2 );
                handle( 40 );              //Change this value
                motor( 100 ,20 );          //Change this value
                pattern = 41;
                cnt1 = 0;
                break;
            }

 

Locate and delete the following unwanted code in case 32:

if( sensor_inp(MASK3_3) == 0x07 ) {
                pattern = 33;
                break;
            }

 

Locate and delete the following unwanted code in case 42:

if( sensor_inp(MASK3_3) == 0xe0 ) {
                pattern = 43;
                break;
            }

Delete the whole of case 33 and 43 as it is no longer required.

 In order to achieve a better turning efficiency during lane change, locate the values of the motor and the steer angle in case 53, and change it to the values shown in the following code:

if( sensor_inp(MASK4_4) == 0x00 ) {
                handle( 15 );
                motor( 70 ,55 );        //Change this value
                pattern = 54;
                cnt1 = 0;
                break;
            }

The above code is only for a right lane change that is found in case 53. Using the above code as reference, make the appropriate changes to the left lane change, which is found in case 63.

Testing of the Car's Performance

3 different courses were created for testing of the car’s performance.

Course 1A is a typical recommended course that consist of the following obstacles:

  • 90° turn
  • Sharp bend
  • Gradual bend
  • Lane change

Course 1B have the same obstacles as course 1A but in a different sequence.

Course 2 is a challenging course that includes the following:

  • 90° turn
  • “S” bend immediately after the consecutive lane change
  • Gradual bend immediately after the 90° turn
  • Gradual bend immediately after the “S” bend
  • Consecutive lane change
  • 10° up and down hill

The following videos shows the car that is loaded with the sample program, followed by the improved program, manoeuvring through the different courses.

The Micom car rally is a timed race competition and therefore, the timing in which the car completes a full course is the most important factor in determining the champion. From the video, the improved code only takes about half the time to complete course 1A, compared to the sample code. In course 1B, the improved code takes much lesser time to complete the course, and in course 2, the sample program cannot even be compared, as it causes the car to run off the course multiple times.

huijay has not written a bio yet…
DesignSpark Electrical Logolinkedin