Sumo robot for class.

Hi everyone. Im a student from one of the uk universities, and im currently enrolled in Mechatronics Engineering. One of my module deals with programming of the Sumo Robot for line following behaviour. We use C++ for the program, AVR Studio 5.0 for building the solution, and PonyProg to write the line behaviour hex file produced by AVR into the sumo robot. There is another program named 'Hyperterminal' to receive feedback from the sumo robot after the hex file is written into the robot.

The following is the C++ program i had investigated with:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "timerInterrupts.c" // timer interrupts function included
#include "peripherals.cpp" // peripherals attribute identified
#include "robot.cpp" // robot object identified

#define LHS 4 //left hand sensor
#define CS 5 // centre sensor
#define RHS 6 // right hand sensor

int main(void){

Robot robby; // declare a Robot object

unsigned char c; /*assign c variable to capture the data received by the bottom sensors*/

int D; // assign D variable to define signal feedback from bottom sensor

robby.initMotors(); // initialise motors

robby.setMotorSpeeds(187,187); // set motor speed to 0

robby.disableMotors(); // disable motor drive

robby.initialiseSerialPort9600(); // start serial port 9600

robby.initialiseADC(); //start Analog- Digital Convertor

robby.setDDR('A',0x00); // set PORT A data direction to inputs

robby.sendSerialByte('y'); // character output on Hyperterminal when robot receives written data from PonyProg

robby.sendSerialByte('o'); // 2nd character output on Hyperterminal when robot receives written data from PonyProg


	while(1){
		t1=10; // set timer to 200ms

		c=robby.getPIN('A'); // read the pins of port A

		if (c & (1<<LHS)) // if left hand sensor is on white line
		{
			D == -1;
		}		
		if(c & (1<<CS)) // if Centre Sensor is on white line
		{
				D == 0;
		}
			
		
		if(c & (1<<RHS)) // if Right hand line is on white line
		{
			D == 1;
		}

		robby.sendSerialByte('\n');
		robby.sendSerialByte('\r');
		
		if (D == -1)
		{
			robby.setMotorSpeeds(180,190);
			robby.enableMotors();		
			robby.sendSerialByte('L');			
		}			
		
		 if (D == 1)
		{
			robby.setMotorSpeeds(186,200);
			robby.enableMotors();	
			robby.sendSerialByte('R');
		}			
		
		if (D == 0)
		{
			robby.setMotorSpeeds(175,198);
			robby.enableMotors();
			robby.sendSerialByte('C');
		}		
		
		}		
				while(t1>0); // wait for timer to timeout
	              }


The snippets above in bold form are some of the important components which leads to the core of running the sumo robot, with values required to make the wheel rotations and sensor detecting.

The objective of the program above is to allow the sumo robot automated behaviour during a line following operation. A blavk line contrasted againest a white background.

The behaviour portrayed by the robot is, the robot wont spin its wheels at all after the on-off switch is on. There are sensor tests provided by the school to verify the functionality of the sensors, and the they performed flawlessly in the feedback. Another program which tests the robot's servo-wheels consists of a fail- safe remote controlled operation on the sumo robot. The motor testing program allows the sumo robot to defined with direction movements using keyboard values of W,S, A and D, going in direction of forward, backwards, left and right motion. This program worked flawlessly with the sumo robot.

My question here is, could it because the sumo robot program abused on the quantity of the if statements, thereby leading to a failure of the robot being unable to work properly?

would anyone guide me to a better design of the C++ program and anywhere else can be improved?

Cheers
Suan Ruey

1
2
3
#include "timerInterrupts.c" // timer interrupts function included
#include "peripherals.cpp" // peripherals attribute identified
#include "robot.cpp" // robot object identified 
You do know that you are never, ever, ever supposed to #include source files? (*.c, *.cc, *.cpp) You include headers... (*, *.h, *.hpp)

As for your question, I highly doubt such a small program as that could be too large and cause an error on the robot controller...does it have some way of sending output back to the computer screen while it is running so you can debug it?
Last edited on
Topic archived. No new replies allowed.