rosserial communication too slow and not fixed
Hardware: Odroid XU4 and arduino Uno that communicate over the serial port using rosserial.
I'm testing the serial communication that seems to be very slow and variable.
Custom message sent:
float32 speed_dx
float32 speed_sx
The code I'm using on arduino is:
...
void loop()
{
while(micros() - loop_timer < 1000000) nh.spinOnce();
loop_timer = micros();
wheel_msg.speed_dx = loop_timer;
pub_speed.publish(&wheel_msg);
}
void callback(const car_msgs::wheel_speed &ref_msg){
wheel_msg.speed_sx = micros() - ref_msg.speed_dx;
}
I publish 1 msg/s and in the meanwhile I continuously call nh.spinOnce()
, in order to receive the message when ready.
On Odroid side I simply publish the message back:
...
void callback(const car_msgs::wheel_speed &input)
{
output.speed_dx = input.speed_dx;
output.speed_sx = input.speed_sx;
pub_ref.publish(output);
}
...
In this way I'm able to compute how many time pass from when I publish the message from arduino to when I get it back.
If I push the baud rate to 1Mbps (which seems to be the maximum supported on Arduino), it takes from 3.5 ms to 7.5 ms.
Why the communication is so slow and not fixed even if the message is always the same?