The Final Build

We came a very respectible 10th in the Robo-Sumo competition,

2014-05-08 11.41.36

Our circuit, very neat, was kept to its most simple.

2014-05-08 11.41.43

Using only one colour sensor, located near the front of the robot, as we saw no need for more as this would leave more to go wrong, and our robot had no reverse in the code.

2014-05-08 11.57.46

We fitted on our rather grippy wheels.

2014-05-08 11.57.552014-05-08 12.05.11

2014-05-08 16.28.482014-05-08 16.29.25

2014-05-08 16.29.302014-05-08 16.29.39

Our finished robot.

2014-05-08 16.30.461

Code used for the Robo-Sumo Fghts

Here is the final code we decide to use for the main competition:

 

//The Resistor
//08/05/2014
//Robo-Sumo
//Created By Andrew East

#include <xc.h>
#pragma config OSC=INTIO67,MCLRE=OFF,WDT=OFF,LVP=OFF,BOREN=OFF
int state = 0; // start in state 0
float distance; // distance in cm
float get_distance(); // function to measure distance

int main(void)
{
         TRISD = 0b11110000;
         TRISC = 0b11111111;

	while(state == 0) //state 0 is all motors switched off (delay before start), then change to state 1
	{
		LATDbits.LATD0 = 0;
		LATDbits.LATD1 = 0;
		LATDbits.LATD2 = 0;
		LATDbits.LATD3 = 0;
		Delay10KTCYx(225);
		Delay10KTCYx(225);
		state = 1;
	}
	while (state == 1) // state 1 is turn left while searching using ultrasonic sensor
	{
		LATDbits.LATD0 = 0;
		LATDbits.LATD1 = 1;
		LATDbits.LATD2 = 0;
		LATDbits.LATD3 = 1;

		distance = get_distance(); // check distance

		if(distance < 30) // if distance is less than 30 change to state 2
		{
			state = 2;
		}
	}

	while(state == 2) // state 2 is motors start off forward to push
	{
		LATDbits.LATD0 = 1;
		LATDbits.LATD1 = 0;
		LATDbits.LATD2 = 0;
		LATDbits.LATD3 = 1;

		if(PORTDbits.RD5 == 1) // if colour sensor reads white change to state 3
		{
			state = 3;
		}

		if(get_distance() > 30) // if distance greater than 30 change to state 1
		{
			state = 1;
		}
	}
	while(state == 3) // state 3Robot turns left for a certain amount of time using delay
	{
		LATDbits.LATD0 = 0;
		LATDbits.LATD1 = 1;
		LATDbits.LATD2 = 0;
		LATDbits.LATD3 = 1;
		Delay10TCYx(25); 

		if(PORTDbits.RD5 == 0) // if colour sensor reads black return to state 1
			{
				LATDbits.LATD0 = 0;
				LATDbits.LATD1 = 1;
				LATDbits.LATD2 = 0;
				LATDbits.LATD3 = 1;
				Delay10TCYx(25); 
				state = 1;
			}
	}

}

float get_distance() // function to measure distance using ultrasonic sensor
{
	float d = 0;

	// send pulse to trigger on ultra-sonic sensor
	LATDbits.LATD7 = 1; // send a signal out high
	Delay10TCYx(5); // 200us delay
	LATDbits.LATD7 = 0; // send a signal out low

	while(PORTCbits.RC0 == 0); // wait for start of echo pulse

	while(PORTCbits.RC0 == 1) // once echo returns high, enter loop, counting d
	{
		Delay10TCYx(5); // 200us delay
		d = d + 1; 
	}

	d = d * 3.4; // In air, sound travels 3.4cm in 200us (scaling factor)

	return d;
}
Video

HC-SR04 Ultra-sonic Distance Sensor

HC-SR04

The HC-SR04 Ultra-sonic distance sensor works by sending out an ultrasonic wave from trigger terminal and measuring the delay before the signal is measured from the echo terminal, while supplying vcc with a constant 5v and a ground wire connected also.

The longer the returning waveform the further the object is away.

2014-03-28 15.21.07

The Timing diagram is shown below. You only need to supply a short 10uS
pulse to the trigger input to start the ranging, and then the module will send out
an 8 cycle burst of ultrasound at 40 kHz and raise its echo. The Echo is a
distance object that is pulse width and the range in proportion .You can
calculate the range through the time interval between sending trigger signal and
receiving echo signal. Formula: uS / 58 = centimetres or uS / 148 =inch; or: the
range = high level time * velocity (340M/S) / ; it is suggested to use over 60ms
measurement cycle, in order to prevent trigger signal to the echo signal.

Untitled

Untitled1

 

HC-SR04 Ultra-sonic sensor wave-form output,
whilst sliding an object closer and further from the the sensor.

 

2014-03-28 15.20.11

Here the target is close,

 

 

2014-03-28 15.20.21

Whilst here it is further away

 

2014-03-28 15.24.48

2014-03-28 15.24.54

 

Coding the Robot

This is the code we used for our robot:

// The Resistor
// Code used for "The Race to the Wall"
// Andrew East

#include <xc.h>
#pragma config OSC=INTIO67,MCLRE=OFF,WDT=OFF,LVP=OFF,BOREN=OFF

int state = 0;
int main(void)
{
    // Make RD0, RD1, RD2 and RD3 outputs
    TRISD = 0b11110000;
	TRISC = 0b11111111;
	
	while(state == 0 )
	{
		LATDbits.LATD0 = 1;
		LATDbits.LATD1 = 0;
		
		if(PORTDbits.RD4 == 0 )
		{
			state = 1;
		}
	}
	while(state == 1 )
	{
		LATDbits.LATD0 = 0;
		LATDbits.LATD1 = 1;
	
		if(PORTDbits.RD5 == 1 )
			{
				state = 2;
			}
	}
	while (state == 2 )
	{
		LATDbits.LATD0 = 0;
		LATDbits.LATD1 = 0;
		
		if(PORTCbits.RC5 == 1)
		{
			state = 0;
		}
	}
}

 

The code includes:

  • a forward/reverse switch.
  • the OPB704 colour sensor.
  • a reset switch. (which is used to put the robot back into forwards once stopped.
Image

OPB704 Sensor

OPB704 Sensor

For our robot we are using the OPB704 infra-redrelective sensor.

This sensor has both an infra-red emitting diode and a infra-red detecting photo-transistor together in one plastic unit.

opb704cct

When the sensor is on a dark colour there will be a high voltage (5v) going to the controller, so when its on a light colour its produces a lower voltage (0-1v)

opb704w

For this reason we decide not to use the sensor on an analogue input but instead opted for a digit input.

Aside

Welcome

Hello and welcome to my blog, through-out the semester I will write in my blog recording how my team design and I build and programme a robot to enter in robosumo at the end of the semester. First we are to design a robot to run in a race to a wall and back to park on a black strip.

So far we have been researching for the design process of our robot for race to wall competition.