Wireless robot control old FIRST Robot - Conundrum

With a lot of help from some great people, I've managed to get my Android phone to control an old FIRST robotics chassis. The Android connects to modem on the robot into which my Ethernet shield equipped Arduino Mega 2560 is connected. Code written by Eric Barch (ttjcrew.com), another FIRST mentor, has been downloaded to the Arduino. Code (with a few of my modifications) is as follows:

/************************************
Arduino Based Robot Control System v0.1
by Eric Barch (ttjcrew.com)
************************************/
#include <SPI.h>
#include <Ethernet.h>
#include <Udp.h>
#include <Servo.h>

//Set the MAC address, static IP, gateway, and subnet of the network
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x50, 0xAD };
byte ip[] = { 10, 3, 46, 22 };

//UDP Stuff
const int PORT = 4444; //Port of incoming UDP data
const int PACKET_SIZE = 4; //Size of the joystick data packet
byte joystick_data[PACKET_SIZE]; //Byte array for incoming data - [0] = leftY, [1] = leftX, [2] = rightY, [3] = rightX
int wtf = 0;
const int led = 3;

//Robot specific stuff
boolean lastState = false; //Keeps track of when we go between enabled/disabled or vice versa
unsigned long lastUpdate = 0; //Keeps track of the last time (ms) we received data

//Define robot outputs
int pwm01 = 5; //Digital Pin 5
int pwm02 = 6; //Digital Pin 6
int pwm03 = 7; //Digital Pin 7
int pwm04 = 8; //Digital Pin 8

//Speed Controller/Servo Objects
Servo leftDriveFront;
Servo leftDriveRear;
Servo rightDriveFront;
Servo rightDriveRear;

void setup() {
Serial.begin(9600); //Setup serial comms for debugging

// Start Ethernet and UDP
Ethernet.begin(mac,ip);
Udp.begin(PORT);

Serial.println("Robot control system initialized.");
}

void loop() {
xferdata();

//Only allow robot to be enabled if we've received data in the last 100ms and robot is set to enabled
if (((millis() - lastUpdate) <= 100) && (millis() > 500)) //Robot is disabled for first 500ms of runtime
enabled();
else
disabled();
wtf = wtf++;

/* This function's sole purpose is to receive data and shove it into the joystick_data byte array */
void xferdata()
{
if (Udp.available()) {
Udp.readPacket(joystick_data,PACKET_SIZE);
lastUpdate = millis();
}
}

void enabled()
{
//If we were last disabled, we need to attach the PWM outputs
if (lastState == false)
{
leftDriveFront.attach(pwm01);
leftDriveRear.attach(pwm02);
rightDriveFront.attach(pwm03);
rightDriveRear.attach(pwm04);
}

//Output the left/right drive PWMs based on joystick input (0-180)

leftDriveFront.write(map((long)joystick_data[0], 0, 255, 0, 180));
leftDriveRear.write(map((long)joystick_data[0], 0, 255, 0, 180));
rightDriveFront.write(map((long)joystick_data[2], 0, 255,180, 0));
rightDriveRear.write(map((long)joystick_data[2], 0, 255, 180, 0));

analogWrite(led, map((long)joystick_data[0], 0, 255, 0, 180));

//We are enabled
lastState = true;

}

void disabled()
{
//Robot is disabled, detach PWM outputs
leftDriveFront.detach();
leftDriveRear.detach();
rightDriveFront.detach();
rightDriveRear.detach();

//We are disabled
lastState = false;
}

Here's the conundrum....if you leave out my line of wtf=wtf++ in the void loop ---- nothing happens on my system. I do have communication since I can see the transmit and receive lines blink and have put messages in to insure I'm getting to the right places. Keeping everything else the same, if I comment out that line, reload and run -- no motor movement. Uncomment, reload run --- robot runs --very quickly in fact.

I'm not sure what that one line accomplishes, except perhaps some stack overload when it hits the integer limit.

Can any one tell me why the addition of that one statement (delays or other non-incrementing statements don't work) makes things go?

I'm happy I've gotten Eric's program to run on my robot, but I'd like to know what the glitch is.
Thanks,
Doc

I'm not sure what that one line accomplishes, except perhaps some stack overload when it hits the integer limit.

That isn't it. The stack is not affected when a variable overflows.

However, if you look at the code you posted, there is no closing brace for the loop function. So, unless there was a cut/paste error, there is more code following the ; on that line, including the closing brace for loop(), and that code is critical.

When posting code, please use the # button first, and put your code between the ] and [.

wtf=wtf++;

You may need to have another look at your C language manual. The statement:

wtf++;

will increment the value in 'wtf'. There's no need to assign (using '=') the value back into 'wtf'. The '++' operator has the side effect of incrementing the variable that it is used with.

PS ---> Thank you that might be it. I must admit I'm still getting used to programming Arduino's and matching the brackets eludes me sometimes. I'll try that today.

Arach ---> Yes you are quite right, but once again, I was falling back on old programming knowledge and was a bit desperate at that time. My son, a C# and Java programmer pointed that out to me as well. I've since corrected it and tried it both ways. Both work.

Thanks for the input folks.

I just re-checked the code I used for the post. There was a closing brace after the loop function. It apparently did not survive my cut and paste.

I had my son check too, he has a lot of Java experience and is studying C in school now. He also checked the curly brackets to make sure they matched and said they did.

So if that was not the issue, what was?