My robot can be controlled by Radio Control as well as being able to roam by itself.
In the following piece of program I grab copies of some values which are updated in interrupt routines.
I then print out those values ( statements in red) and the program then goes on and works fine.
If I comment out the print statements it does not work. It seems not to know the correct value of RC_ThrottleIn
which is the first value printed. The delay caused by the print statements seems to be necessary for the value to be updated.
If I put a delay of 100ms in instead of the print statements I get the same correct working.
What is happening?
bool getRC()
{
// check shared update flags to see if any channels have a new signal
noInterrupts(); // turn interrupts off quickly while we take local copies of the shared variables
if(RC_UpdateFlagsShared)
{
RC_UpdateFlags = RC_UpdateFlagsShared;
if(RC_UpdateFlags & RC_Throttle_FLAG)
{
RC_ThrottleIn = RC_ThrottleInShared;
}
if(RC_UpdateFlags & RC_Steering_FLAG)
{
RC_SteeringIn = RC_SteeringInShared;
}
if(RC_UpdateFlags & RC_OnOff_FLAG)
{
RC_OnOffIn = RC_OnOffInShared;
}
RC_UpdateFlagsShared = 0;
}
interrupts(); // we have local copies of the inputs, so now we can turn interrupts back on
Serial.print("RC_ThrottleIn ");Serial.print(RC_ThrottleIn);
Serial.print(" RC_SteeringIn ");Serial.print(RC_SteeringIn);
Serial.print(" RC_OnOff ");Serial.println(RC_OnOff);
......... program continues