Games Master GUI
Wednesday, 16 January 2013 Category : Comms, Design, Implementation, Phase Two 0
Home > Comms
Wednesday, 16 January 2013 Category : Comms, Design, Implementation, Phase Two 0
Sunday, 13 January 2013 Category : Comms, Implementation, Phase Two 0
![]() |
| TouchOSC configuration screen |
Monday, 7 January 2013 Category : Comms, Implementation, Phase Two 0
![]() |
| Circle Network Setup |
char instruction [10]; //instruction sent to arduinoNext, a String needs to be introduced so that a message can be resent on to robot 2.
//message to send on to Robot 2 String resendMessage = "";Inspecting the previous code for the robot, the first part of void loop() stays the same - while there is serial data available, read the data and store in the instruction array. Next, check to see if the instruction starts and ends with the characters '<' and '>' (remembering to change the index by one for the ending character).
//check that message is for robot 1 <1....>
if (instruction[j+1] == '1')
{
If the message is for the robot, the normal parsing takes place (parse the rest of the message to deal with lasers, servos and motors). Else, if the message is for robot 2, robot 1 needs to resend the message. The message is concatenated together and then printed out. Before being printed, however, the serial port is flushed. //else check is message is for robot 2 <2...>
else if (instruction[j+1] == '2')
{
//reset resend message to blank
resendMessage = "";
int k = 0;
//loop around the instruction message
for (k = j; k<(j+10); k++)
{
//concatenate all characters of message
resendMessage += instruction[k];
}
Serial.print(0); //flush the serial port
Serial.print(resendMessage); //send the message onto Robot 2
}
That is all the code that needs to be added/changed for robot 1 to parse the instruction message.
//string to print to contact games master - in the following form: //G (games master) 2 (robot 2's score) 10 (how much to increment score) String GMscoreLR = "[G210]"; String GMscoreB = "[G215]";
Serial.print(0);//flush the serial port
//print message to GM to increment Robot 2's score
Serial.println(GMscoreLR);
In the other interrupt, this code needs to be added: Serial.print(0);//flush the serial port
//print message to GM to increment Robot 2's score
Serial.println(GMscoreB);
These interrupts print the correct string which will then be sent on to robot 2. char instruction [10]; //instruction sent to arduinoNext, a String needs to be introduced so that a message can be resent on to the Games Master.
//message to send on to Games Master String resendMessage = "";Again, inspecting the previous code for the robot, the first part of void loop() stays the same - while there is serial data available, read the data and store in the instruction array. Next, check to see if the instruction starts and ends with the characters '<' and '>' (remembering to change the index by one for the ending character).
//check the message is for robot 2 <2...>
if (instruction[j+1] == '2')
{
//if message is score packet for the Games Master
else if ((instruction[j] == '[') && (instruction[j+5] == ']'))
{
//reset resend message to blank
resendMessage = "";
int k = 0;
//loop around the instruction message
for (k = j; k<(j+6); k++)
{
//concatenate all characters of message
resendMessage += instruction[k];
}
Serial.print(0); //flush the serial port
Serial.print(resendMessage); //send the message onto games master
}
In this else-if statement, the message is concatenated together and then sent on to the Games Master. Serial.print(0);//flush the serial port
//print message to GM to increment Robot 2's score
Serial.println(GMscoreLR);
And in the other interrupt, this code needs to be added: Serial.print(0);//flush the serial port
//print message to GM to increment Robot 2's score
Serial.println(GMscoreB);
That concludes all the code that needs to be updated on the robots. Please see post BLAH for the parsing of the Games Master packets in Processing.
Category : Comms, Implementation, Phase Two 1
After trying a point to point network, and a point to multipoint network, it was decided that a circle network would be implemented.
![]() |
| Circle network |
![]() |
| Coordinator and Router Setup for Circle Network |
Category : Comms, Implementation, Phase Two 0
| Broadcast configuration for an Xbee network |
Friday, 4 January 2013 Category : Comms, Implementation, Phase Two 2
![]() |
| Xbees in Unicast mode |
Wednesday, 12 December 2012 Category : Comms, Implementation, Phase Two 0
The offboard system uses the raspberry pi as the base station to send and receive signals from the iPads over the network interface and process the messages and send control packets to the game master Xbee.
Wednesday, 28 November 2012 Category : Comms, Implementation, Phase Two 1
![]() |
| iPad interface for control - note space at the top for future game messages |
Category : Comms, Implementation, Phase Two 0
while(Serial.available() > 0){//look for Serial data
int incoming = Serial.read();//read and store the value
instruction[i] = incoming; //store the instruction in the array
//loop round the instruction array (expecting 9 characters)
for (j = 0; j<9; j++)
{
//get the coordinates for the motor
if ((instruction[j] == '<') && (instruction[j+8] == '>'))
{
//concatenate the two strings for x coordinates together stringXCoord += instruction[j+2]; stringXCoord += instruction[j+3]; //make the string an integer intXCoord = stringXCoord.toInt(); servoX.write(intXCoord); //write to the servo //concatenate the two strings for y coordinates together stringYCoord += instruction[j+4]; stringYCoord += instruction[j+5]; //make the string an integer intYCoord = stringYCoord.toInt(); servoY.write(intYCoord); //write to the servo
//turn laser on
if (instruction[j+1] == 'F')
{
digitalWrite(laser, LOW);
}
//turn laser off
if (instruction[j+1] == 'f')
{
digitalWrite(laser, HIGH);
}
//control motors on robot - left motor forward
if (instruction[j+6] == 'F')
{
digitalWrite(leftMotor1, LOW);
digitalWrite(leftMotor2, HIGH);
}
//control motors on robot - left motor stop
if (instruction[j+6] == 'S')
{
digitalWrite(leftMotor1, LOW);
digitalWrite(leftMotor2, LOW);
}
//control motors on robot - left motor backward
if (instruction[j+6] == 'B')
{
digitalWrite(leftMotor1, HIGH);
digitalWrite(leftMotor2, LOW);
}
//control motors on robot - right motor forward
if (instruction[j+7] == 'F')
{
digitalWrite(rightMotor1, HIGH);
digitalWrite(rightMotor2, LOW);
}
//control motors on robot - right motor stop
if (instruction[j+7] == 'S')
{
digitalWrite(rightMotor1, LOW);
digitalWrite(rightMotor2, LOW);
}
//control motors on robot - right motor backward
if (instruction[j+7] == 'B')
{
digitalWrite(rightMotor1, LOW);
digitalWrite(rightMotor2, HIGH);
}
Finally, variables need to be reset. The variable i used for storing the incoming serial into an array is set to -1 and then incremented to get back to 0, as resetting back to 0 would not work. //reset variable for instruction array
i = -1;
}
}
//increment counter for instruction array
i++;
//reset variables used
stringXCoord = "";
stringYCoord = "";
intXCoord = 0;
intYCoord = 0;
}
}
All of the code given was in the void loop() method. For the code to work, all variables were stated at the start of the sketch and any libraries needed were included.#include <Servo.h> char instruction [9]; //instruction sent to arduino int i = 0; //index for instruction array int j = 0; //index for for loop String stringXCoord = ""; int intXCoord; //x coordinate for motor String stringYCoord = ""; int intYCoord; //y coordinate for motor Servo servoX; //servo x Servo servoY; //servo y //pin for laser and LDR int laser = 13; //pin numbers for the motor on the robot int leftMotor1 = 11; int leftMotor2 = 12; int rightMotor1 = 9; int rightMotor2 = 10;
void setup(){
//init Serial library (make sure Processing is sending data at the same baud rate)
Serial.begin(9600);
servoX.attach(5);
servoY.attach(6);
pinMode(sensor1, INPUT);
pinMode(laser, OUTPUT);
pinMode(leftMotor1, OUTPUT);
pinMode(leftMotor2, OUTPUT);
pinMode(rightMotor1, OUTPUT);
pinMode(rightMotor2, OUTPUT);
}
Tuesday, 30 October 2012 Category : Comms, Design, Phase One Report 0
![]() |
| OUTLINE OF COMMUNICATIONS LINKS REQUIRED |