Commit aa8578f4 authored by Jeffrey Cheng's avatar Jeffrey Cheng
Browse files

Added LOP and Game Info

parent 9a4f0cb2
Pipeline #313243717 passed with stage
if(receiver->getQueueLength() > 0) { // Check if receiver queue size is not empty
// Since the only message the robot controller will ever get will be lack of
// progress notifications, we don't really care about the contents of the message
cout << "Detected Lack of Progress!" << endl;
receiver->nextPacket(); // Discard the current data packet
if(receiver->getQueueLength() > 0) { // If receiver queue is not empty
char *message = (char *)receiver->getData(); // Grab data as a string
if (message[0] == 'L') { // 'L' means a lack of progress occurred
cout << "Detected Lack of Progress!" << endl;
receiver->nextPacket(); // Discard the current data packet
}
}
\ No newline at end of file
if receiver.getQueueLength() > 0: # Check if receiver queue size is not empty
# Since the only message the robot controller will ever get will be lack of
# progress notifications, we don't really care about the contents of the message
print("Detected Lack of Progress!")
if receiver.getQueueLength() > 0: # If receiver queue is not empty
receivedData = receiver.getData()
tup = struct.unpack('c', receivedData) # Parse data into character
if tup[0].decode("utf-8") == 'L': # 'L' means lack of progress occurred
print("Detected Lack of Progress!")
receiver.nextPacket() # Discard the current data packet
\ No newline at end of file
......@@ -32,6 +32,13 @@ X Pos <b>(integer),</b> Z Pos <b>(integer),</b> Victim Type <b>(character)</b>
{{< code-toggle file="scoring">}}
{{</code-toggle>}}
#### Signaling Lack of Progress
To call of lack of progress autonomously (using your program), send the character <b>'L'</b> using the emitter. The letter <b>'L'</b> will be sent back to the robot's receiver as per the <b>Lack of Progress</b> section below.
{{< code-toggle file="sendLOP">}}
{{</code-toggle>}}
#### Signaling End of Play
To signal to the Main Supervisor the end of play in order to receive an exit bonus, send the character <b>'E'</b> using the emitter:
......@@ -43,7 +50,12 @@ To signal to the Main Supervisor the end of play in order to receive an exit bon
The receiver can be used to detect lack of progress messages sent by the Main Supervisor, so that the robot controller can respond accordingly:
{{< code-toggle file="LOP">}}
{{</code-toggle>}}
#### Game Information
Your program can retrieve the robot's current game score and the time remaining in your run. Use the emitter to send the character <b>'G'</b> to the supervisor, and it will send back a package that starts with the letter <b>'G'</b> and is followed by the score and time remaining:
{{< code-toggle file="gameInfo">}}
{{</code-toggle>}}
\ No newline at end of file
char message[1] = { 'G' }; // message = 'G' for game information
emitter->send(message, sizeof(message)); // Send out the message array. Note that the 2nd parameter must be the size of the message
...
if(receiver->getQueueLength() > 0) { // If receiver queue is not empty
char *receivedData = (char *)receiver->getData(); // Grab data as a string
float score = 0.0;
int time = 0;
if (receivedData[0] == 'G') {
memcpy(&score, receivedData + 4, 4); // Score stored in bytes 4 to 7
memcpy(&time, receivedData + 8, 4); // Remaining time stored in bytes 8 to 11
cout << "Game Score: " << score << " Remaining time: " << time << endl;
receiver->nextPacket(); // Discard the current data packet
}
}
\ No newline at end of file
message = struct.pack('c', 'G'.encode()) # message = 'G' for game information
emitter.send(message) # send message
...
if receiver.getQueueLength() > 0: # If receiver queue is not empty
receivedData = receiver.getData()
tup = struct.unpack('c f i', receivedData) # Parse data into char, float, int
if tup[0].decode("utf-8") == 'G':
print(f'Game Score: {tup[1]} Remaining time: {tup[2]}')
receiver.nextPacket() # Discard the current data packet
\ No newline at end of file
char message[1] = { 'L' }; // message = 'L' to activate lack of progress
emitter->send(message, sizeof(message)); // Send out the message array. Note that the 2nd parameter must be the size of the message
\ No newline at end of file
message = struct.pack('c', 'L'.encode()) # message = 'L' to activate lack of progress
emitter.send(message) # Send message
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment