Arduino UNO sync lost when serial with ros

I use ROS in virtualbox which install Ubuntun. And connect ROS to Arduino.
Here is my adruino code, which I receive command from ROS, and use this command to control a differential drive car.
Here is my arduino code with a loop 20 hz, and the ros node publish to arduino is 10 hz. Just publish float data not string. When I run, first it's ok but later it said

[ERROR] [WallTime: 1433956349.977347]
Lost sync with device, restarting..

When i change ros node publish rate to 1 hz, it works fine.
Is that problem running out of SRAM?

#include <ros.h>
    #include <std_msgs/Float32.h>
    #define DIR_R  7             //Right motor Direction control line
    #define DIR_L  8             //Left motor Direction control line
    #define PWM_R  9             //Right motor PWM control line
    #define PWM_L  10            //Left motor PWM control line
    #define LED    13
    #define SPEED  45
    ros::NodeHandle nh;

    int rightSpeed, leftSpeed;
    double relative_angle;

    void messageCb(const std_msgs::Float32& str){

            //int rightSpeed, leftSpeed;

            if(str.data == -1){                    //no free-space front Zumo robot, rotate to find another one
                     rightSpeed =SPEED;
                     leftSpeed  =SPEED;
                     rotatePort(rightSpeed, leftSpeed, 500, 1);
                     searchPort(200,200);
            }
            else
            {
                relative_angle=abs(90.0-str.data);

                if (relative_angle <= 2.0)         //optional direction in front of Zumo robot
                {
                     rightSpeed =SPEED;
                     leftSpeed  =SPEED;
                     forwardPort(rightSpeed, leftSpeed, 500, 1);
                }
                else
                {
                     if (str.data <90.0)
                     {
                         rightSpeed =SPEED - relative_angle/90.0*SPEED;
                         leftSpeed  =SPEED + relative_angle/90.0*SPEED;
                         turnPort(rightSpeed, leftSpeed, 500, 1);
                     }
                     else
                     {
                         rightSpeed =SPEED + relative_angle/90.0*SPEED;
                         leftSpeed  =SPEED - relative_angle/90.0*SPEED;
                         turnPort(rightSpeed, leftSpeed, 500, 1);                     
                     }     
                }


            }
    }

    ros::Subscriber<std_msgs::Float32> sub("/space1/move_zumo", &messageCb);

    void setup(){
      pinMode(LED, OUTPUT);
      pinMode(DIR_R, OUTPUT);
      pinMode(DIR_L, OUTPUT);
      pinMode(PWM_R, OUTPUT);
      pinMode(PWM_L, OUTPUT);      
      nh.initNode();
      nh.subscribe(sub);
    }

    void loop(){
      nh.spinOnce();
      delay(50);
    }

    void rotatePort  (int rs, int ls, int T1, int T2)
    {
        digitalWrite(DIR_R, LOW);
        digitalWrite(DIR_L, HIGH);
        analogWrite(PWM_R, rs);
        analogWrite(PWM_L, ls);
        delay(T1);
        analogWrite(PWM_R, 0);
        analogWrite(PWM_L, 0);
        delay(T2);
    }

    void forwardPort (int rs, int ls, int T1, int T2)
    {
        digitalWrite(DIR_R, LOW);
        digitalWrite(DIR_L, LOW);
        analogWrite(PWM_R, rs);
        analogWrite(PWM_L, ls);
        delay(T1);
        analogWrite(PWM_R, 0);
        analogWrite(PWM_L, 0);
        delay(T2);   
    }

    void turnPort(int rs, int ls, int T1, int T2)
    {
        digitalWrite(DIR_R, LOW);
        digitalWrite(DIR_L, LOW);
        analogWrite(PWM_R, rs);
        analogWrite(PWM_L, ls);
        delay(T1);
        analogWrite(PWM_R, 0);
        analogWrite(PWM_L, 0);
        delay(T2);      
    }

    void searchPort(int T1, int T2)
    {
        digitalWrite(LED,HIGH);
        delay(T1);
        digitalWrite(LED,LOW);
        delay(T2); 
    }

What is ROS ?

...R

@Crazymumu:

I also tried to use Arduino+ROS via a VM(running on Windows), but I had many problems with the connection of the Arduino (the Arduino IDE was connecting for about a second to the Arduino...the Arduino disappeared)..I lost many hours trying to fix this problem, but nothing was helping....so I installed a real Ubunut OS on my machine and it was working as it should.