The Final!

The first iteration of the design.

Today saw the culmination of the RoboSumo competition. After 12 weeks of working with the Texas Instruments MSP430 and launchpad we were finally ready to compete in the competition. Things had looked doubtful at the start of the week as the laser cutter was not working. Although we already had parts, they would have required significant modification in order to be suitable. However at the 11th hour, Ted pulled through and the parts were cut elsewhere.

Liam designed the robots chassis as he had a unchallenged knowledge of AutoCad, and after several revisions the final design was fantastic. We made several modifications from our initial design, including moving the ultrasonic sensor down to detect lower robots, changing the positions of the motors to add a small wheel at the front and finally we added a hole in the roof for the switch. In the end however we decide to use the roof and this piece was used as a back piece instead.

Second iteration.

Second iteration.

Unfortunately, as the competition was starting our robot stopped working. After some analysis of the robot(using a multi-meter) we discovered that unknownst to us our 3.3v rail on the breadboard was being supplied with 9v from the battery. We don’t know how long this went on for but we suspect this may have damaged the robot.

Overall we came 13th, which is respectable considering the circumstances. Here is a video of our attempt in the arena.

Overall I thoroughly enjoyed this design projects module, i found it to be very worthwhile as a method for learning about both electronics and programming at the same time.

Niall.

Advertisements

RoboSumo Code Finalised

After spending the last number of weeks working on our code for the robot, we have it finalised. The backbone of the code is from Ted’s statements example code which he wrote in one of the lectures. We also took inspiration from the roboslam website (https://roboslam.wordpress.com/), we used the method that they used to control the motors. Below is the finalised code, it is amazing to think that at the beginning of the semester we had very little knowledge of the C language. Now we have a much broader understanding of it.

13
//
// Revision Final of RoboSumo Code
// Written by Conor Byrne, Liam Whelan and Niall Keating - Last modified 04-12-2015
//
  
#include <msp430.h>

int Detected();
void Motors(int, int);
void change_state(int);

int state = 1;

int main (void)
{
    WDTCTL = WDTPW + WDTHOLD; // Disable watchdog timer

	motors(0,0);
	P1DIR = 0b10000000;   // 	IN:UltraEcho(P1.6) Colour1(P1.1),Colour2(P1.2),Colour3(P1.3) OUT:UltraTrig(P1.7)
	P2DIR = 0b00110110;   //	OUT:MotorOppCapSide(P2.1 and P2.2), MotorCapSide(P2.3 and P2.4)

	// Configure the Basic Clock Module
    DCOCTL  = CALDCO_1MHZ;
    BCSCTL1 = CALBC1_1MHZ;
	
	int D, colourSensor_Front_Left, colourSensor_Front_Right, colourSensor_Back;	//Create integers for sensors, D is deected, the rest are their respective colour sensors.
	
	while(1)
	{
		D  = detected();	// Making range finder detected function equal to D
		colourSensor_Back = ((P1IN & BIT3) > 0);  // Front left colour sensor, High ie White
		colourSensor_Front_Right = ((P1IN & BIT4) > 0);  // Front right colour sensor, High ie White
		colourSensor_Front_Left = ((P1IN & BIT6) > 0);  // Back colour sensor, High ie White
		

		if (state == 1) 
		{
			motors(1,0);	// One motor spinning(Left)
			
			if (colourSensor_Back == 1) 
			{
				change_state(4);  //Turn Left
			}

			if (colourSensor_Front_Right == 1) 
			{
				change_state(5);  //Turn Right
			}

			if (colourSensor_Front_Right == 1 & colourSensor_Back == 1) 
			{
				change_state(3);  //Reverse with both motors
			}

			if (colourSensor_Front_Left == 1) 
			{
				change_state(6);  //Drive straight for 2 seconds
			}

		    if (D == 1) 
		    {
		    	change_state(2);  //Drive staright until reach opponent
			}
		}

		else if (state == 2)
		{
			motors(1,1);
			
			if(colourSensor_Front_Left == 1) 
			{
				change_state(6);  //Drive straight for 2 seconds
			}

			if(colourSensor_Back == 1) 
			{
				change_state(4);  //Turn Left
			}

			if(colourSensor_Front_Right == 1)
			{
				change_state(5);  //Turn Right
			}

			if(D == 0) 
			{
				change_state(1);  //Spin
			}	
		}

		else if (state == 3)
		{
			motors(-1,-1);

			if (colourSensor_Front_Left == 1) 
			{	
				change_state(6);
			}

		}

		else if (state == 4)   // Turn Right for 2 seconds
		{
			motors(1,-1);
			__delay_cycles(2000000);			
			change_state(1);
		}

		else if (state == 5)     // Turn left for 2 seconds
		{
			motors(-1,1);
			__delay_cycles(2000000);
			change_state(1);
		}

		else if (state == 6)       // Drive straight for 3 seconds
		{
			motors(1,1);
			__delay_cycles(2000000);
			change_state(1);
		}
	}

	return 0;
}

void change_state(int n)
{
	state = n;
}

void motors(int left, int right)
{
	int p2val = 0b00000000;
	
	if (left > 0)  p2val = p2val + 0b00010000;
	if (left < 0) p2val = p2val + 0b00100000; if (right > 0) p2val = p2val + 0b00000010;
	if (right < 0) p2val = p2val + 0b00000100; P2OUT = p2val; } int detected() { P1OUT |= BIT7; // Start trigger pulse __delay_cycles(20); //20us P1OUT &= BIT7; // End trigger pulse // Check echo pin after 4.5ms to see if an object is detected __delay_cycles(4500); if ((P2IN & BIT0)>0)	// If the pin is still High 
	{	
		return 0;
	}

	else	// If the pin is no longer High
	{
		return 1;
	}
}

Using Git and GitHub to effectively manage code in group work

As mentioned in a previous post, we are now using Git to track all of changes made to the code. We are using it in conjunction with the github.com service, GitHub allows us to both store a copy of the code online and work in collaboration.

Installing Git was very straightforward, when completed all I had to do was right click on our Design Projects folder and click “Git Bash here”
Git1I then went online and created a GitHub repository, ensuring to tick the box that says “Initialize this repository with a README”
Going back to the bash window, I initialised the repository by entering the git init command.

git 2

The next command I entered was git clone “insert repository https clone address.”  Inserting the address of our repository. I then went about adding all of the files into the new RoboSumo folder which was created(Because this is what I named the repository). At this stage I also created a file called .gitignore, this file is used to stop certain files from being committed to the repository. I used this to prevent all our .pdf and .jpg files from being commited to the repository .

Once the files we all transferred over I once again went back to the bash window. Git can be quite a confusing piece of software. It took me a while to realise that even though the file is in the folder, it wont be added to the repository until you add it in the bash window. Adding files is simple, all you need to enter is git add “filename” or you can use git add . (This adds all of the files which are not in the .gitignore file.) The last step before the files were uploaded to Github, was to commit the. The command for this is git commit.git 5

Now, uploading the code is simple, the command is git push, this will open a prompt for you to insert your username and password. As long as you are a collaborator, your work will then be uploaded. Now that we have this setup, we have created a new workflow. Once I open up my text editor to begin coding, I also open the bash window and enter the git pull command. This pulls down any new code from the repository. I then continue working away on the code, ensuring to save my work add it and commit it every few steps. The add and commit commands can be amalgamated into one, git commit -a. Then every half hour I push the code up to GitHub. (Below is a picture of the workflow.)

git 6

Niall

 

RoboSumo Week 9 – Ultrasonic sensor

We decided that for the RoboSumo competition we would use an ultrasonic rangefinder to detect the other robot. We are using the HC-SR04 Ultrassonic sensor. This senor includes both the transmitter and receiver on the board.

One of the first hurdles to get over was to do with the voltage level of the sensor. The MSP340 runs at a 3.3v level, unfortunately the HC-SR04 runs at a 5v level. Our battery pack outputs 6v which is fine to power the sensor. However the output from the sensor is at 5v, if this were to be connected directly to the MSP it could cause damage to the chip. Therefore we need to use a pull up resistor.FullSizeRender 

The sensor will send a high signal on the echo pin for the duration of the time it takes for the sound wave to reach the object and return. As a result, if we divide the time the pin is high by 2 and then multiply the answer by the speed of sound(340ms-1). We will get the distance to the object.
Since we don’t need to know how far away the other robot is we will only be using values which are within a certain distance of the sensor.

RoboSumo Week 8 – Week 1 of final challenge(RoboSumo)

After taking a break during review week, our team returned with a renewed passion for the project. We all agreed that we were delighted with out ranking from the race to the well, we came 6th.

We leaned numerous important lessons from the race to the wall. Mainly in the areas of teamwork and project management. We decided that it was necessary to divide up the responsibilities between us.

  • Liam is going to focus on the design and construction of the robo.
  • Conor is going to focus on the wiring and soldering of the electronics. He will also be working on the design of the robot with Liam.
  • I am going to the the coding and help Conor with the electronics.

This does not mean that we are only going to know about our aspect of the robot. We also agreed that we will spend the first few minutes of our time together on Wednesdays explaining to each other what we have learned/done over the previous week.

Another lesson I learned from the race to the wall, is the importance of organisation. Particularly with the code. I was finding it difficult to keep track of various changes being made to the code. I did some research and discovered Git. Git is a program with creates a repository and tracks all the changes made to the code. There is a website called Github which allows each team member to contribute to the code without an organisational nightmare. The two work hand in hand and we are hoping they will greatly benefit the team.

RoboSumo Week 5 – Colour Sensor

This week team 6’s objective was firstly to get the colour sensor working and then to make the finishing touches to our robot. Once Ted explained how we would be using the colour sensor, it was easy to set up. Essentially, it works as a switch. The sensor uses an IR LED and a PhotoTransistor to detect colour, the PhotoTransistor is pulled down to ground using a 10K resistor, it is also connected to P1.4 on the MSP. When it the colour sensor reads a lighter colour, a higher voltage is detected by P1.4, when a dark colour(Black) is read the voltage detected by the MSP is negligible. Therefore, using an if statement we are able to turn off the motors if the the P1.4 is determined to be greater than zero.

IMG_1371

Once this was wired into the circuit correctly, I set about working on the code while my teammates worked on putting our robot together. The finally code can be seen below:

//
// Code for Testing Colour Sensor
// Team Members: Liam Whelan, Conor Byrne and Niall Keating - Last modified 14 -10-2015
// See https://robosumo.wordpress.com/msp430/
//
 
#include <msp430.h>
 
int main( void )
{
	int btn_pressed = 0;
	int colour_sensor = 0;
	
    WDTCTL = WDTPW + WDTHOLD; // Disable watchdog timer
     
    P1DIR = 0b00000011; // Port 1.0 is used for the motor. (P1.0 and P1.1)
    P2DIR = 0b00001000; // Port 2 for test LED. (P2.3)
    
    // Configure the Basic Clock Module
    // This sets the MSP430's clock to a factory calibrated 1 MHz,
    // which means that any delays we specify will be more accurate
    DCOCTL  = CALDCO_1MHZ; 
    BCSCTL1 = CALBC1_1MHZ;
 		
    // Main loop repeats forever
    while(1)
    {
		__delay_cycles(800000);
		if((P1IN & BIT3)>0){	// This if statement checks to see if Pin1.3 is High or Low.  			
			btn_pressed = 1;	// If the switch is High then set btn_pressed to 1		
		}
		
		if(btn_pressed == 0) {	// If btn_pressed is 0 then:
			P2OUT = 0b00001000; // Turn on the Led.
			P1OUT = 0b00000001;	// Set Pin1.0 High (Drive Forward)
		}
		
		else {					// If btn pressed is not 0 then:		
			P2OUT = 0b00000000; // Turn off the Led
			P1OUT = 0b00000010;	// Set Pin1.1 High (Drive Backwards)	
			
			if((P1IN & BIT4)>0) 
			{
			P2OUT = 0b00001000; // Turn on the Led
			P1OUT = 0b00000010;	// Turn motor on			
			}
			
			else
			{
			P2OUT = 0b00000000; // Turn on the Led
			P1OUT = 0b00000000;	// Turn motor on					
			}
			
			
		}
    }
     
    // The program never actually reaches this point
    return 0;
}