The loop section of the code was modified just after the read_joystick() function was called, so that it looked like this.
read_joystick();
if(left_button == 1)
{
left_button = 0;
grabber_close_function();
}
if(top_button == 1)
{
top_button = 0;
arm_lift_function();
}
if(right_button == 1)
{
right_button = 0;
grabber_open_function();
}
if(bottom_button == 1)
{
bottom_button = 0;
arm_lower_function();
}
This required some changes to the case structure in the joystick read function.
switch(int(incoming_byte))
{
case 32:
left_button = 0;
top_button = 0;
right_button = 0;
bottom_button = 0;
select_button = 0;
break;
case 1:
left_button = 1;
top_button = 0;
right_button = 0;
bottom_button = 0;
select_button = 0;
break;
case 2:
left_button = 0;
top_button = 1;
right_button = 0;
bottom_button = 0;
select_button = 0;
break;
case 3:
left_button = 0;
top_button = 0;
right_button = 1;
bottom_button = 0;
select_button = 0;
break;
case 4:
left_button = 0;
top_button = 0;
right_button = 0;
bottom_button = 1;
select_button = 0;
break;
case 5:
left_button = 0;
top_button = 0;
right_button = 0;
bottom_button = 0;
select_button = 1;
break;
}
So calling functions have been replaced with variable value reassignment. Either way, these small changes produced a very discernable increase in cycle time. I'm baffled by it, figured a 16 Mhz clock would do these calculations before I could even ponder them.
In regards to the while(), that actually speeds it up. It keeps it stuck in the joystick function until a complete joystick reading has been performed. It requires around 4~7 iterations of that loop, depending on where it starts reading from in the data stream. Previously, it was escaping after every reading and checking our disable button logic. This resulted in a very large delay, so that's why we changed it.
The while(millis() < servo_enter_function_time + 1250) statement is deliberate. We have to do this because the Xbee fills the buffer up incredibly fast, which seems to interfere with the servo libraries. Thus we turn off the Xbee serial, engage our servo (which takes about 1250 ms to fully actuate), disengage it (as to not draw power), and turn the Xbee serial back on and then resume cycling through our loop. The delay it causes only occurs when call on this function, and the resulting delay is expected.
In regards to the floats, they are not actually used in our loop. We removed all code using them earlier for various reasons. We left the preallocation of those control variables in though, but because they are not involved in the looping section of the code or anything else, we assumed that a few preallocated variables wouldn't cause much harm.
Either way, I'll take a look through those resources you've provided. Thanks for the help thus far.