Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Using interrupts with rosserial_arduino

Hi.

I am trying to accurately measure my wheel velocities by counting the pulses coming from my encoders. My idea was to run an Arduino dedicated to only this task, which counts the pulses in the loop() function then uses a timer (from the Timer1 library) to trigger an interrupt service routine at a specified frequency (I was using 50Hz). Inside this ISR I work out the wheel velocity from the number of pulses counted over the 50Hz period, then publish this out over ROS.

Unfortunately when I try to connect to the node using rosserial_python, I get an error saying that it was expecting a certain number of bits but has received less than that, and the connection fails. Apologies, I don't have the Arduino with me right now so can't paste the full error, but will add it tomorrow if it will help diagnose the problem.

My guess is that whilst the Arduino is communicating back over serial, the ISR gets triggered, which interrupts the process, and ROS doesn't like it. Is this the case, or is something else going on? Can interrupts be used on an Arduino with ROS, or is this a no-go? If not, can anyone recommend a different way to count wheel encoder pulses over a well-defined time period?

Thanks!

Using interrupts with rosserial_arduino

Hi.

I am trying to accurately measure my wheel velocities by counting the pulses coming from my encoders. My idea was to run an Arduino dedicated to only this task, which counts the pulses in the loop() function then uses a timer (from the Timer1 library) to trigger an interrupt service routine at a specified frequency (I was using 50Hz). Inside this ISR I work out the wheel velocity from the number of pulses counted over the 50Hz period, then publish this out over ROS.

Unfortunately when I try to connect to the node using rosserial_python, I get an error saying that it was expecting a certain number of bits but has received less than that, and the connection fails. Apologies, I don't have the Arduino with me right now so can't paste the full error, but will add it tomorrow if it will help diagnose the problem.

My guess is that whilst the Arduino is communicating back over serial, the ISR gets triggered, which interrupts the process, and ROS doesn't like it. Is this the case, or is something else going on? Can interrupts be used on an Arduino with ROS, or is this a no-go? If not, can anyone recommend a different way to count wheel encoder pulses over a well-defined time period?

Thanks!

Using interrupts with rosserial_arduinorosserial_arduino to count wheel encoder pulses

Hi.

I am trying to accurately measure my wheel velocities by counting the pulses coming from my encoders. My idea was to run an Arduino dedicated to only this task, which counts the pulses in the loop() function then uses a timer (from the Timer1 library) to trigger an interrupt service routine at a specified frequency (I was using 50Hz). Inside this ISR I work out the wheel velocity from the number of pulses counted over the 50Hz period, then publish this out over ROS.

Unfortunately when I try to connect to the node using rosserial_python, I get an error saying that it was expecting a certain number of bits but has received less than that, and the connection fails. Apologies, I don't have the Arduino with me right now so can't paste the full error, but will add it tomorrow if it will help diagnose the problem.

My guess is that whilst the Arduino is communicating back over serial, the ISR gets triggered, which interrupts the process, and ROS doesn't like it. Is this the case, or is something else going on? Can interrupts be used on an Arduino with ROS, or is this a no-go? If not, can anyone recommend a different way to count wheel encoder pulses over a well-defined time period?

Thanks!

Edit: the exact error I'm getting is

[WARN] [WallTime: 14839761.73.327399] Serial Port read returned short (expecting 81 bytes, received 24 instead).
[WARN] [WallTime: 14839761.73.328598] Serial Port read failure:
[INFO] [WallTime: 14839761.73.330119] Packet Failed : Failed to read msg data
[INFO] [WallTime: 14839761.73.331164] msg len is 8

Using interrupts with rosserial_arduino to count wheel encoder pulses

Hi.

I am trying to accurately measure my wheel velocities by counting the pulses coming from my encoders. My idea was to run an Arduino dedicated to only this task, which counts the pulses in the loop() function then uses a timer (from the Timer1 library) to trigger an interrupt service routine at a specified frequency (I was using 50Hz). Inside this ISR I work out the wheel velocity from the number of pulses counted over the 50Hz period, then publish this out over ROS.

Unfortunately when I try to connect to the node using rosserial_python, I get an error saying that it was expecting a certain number of bits but has received less than that, and the connection fails. Apologies, I don't have the Arduino with me right now so can't paste the full error, but will add it tomorrow if it will help diagnose the problem.

My guess is that whilst the Arduino is communicating back over serial, the ISR gets triggered, which interrupts the process, and ROS doesn't like it. Is this the case, or is something else going on? Can interrupts be used on an Arduino with ROS, or is this a no-go? If not, can anyone recommend a different way to count wheel encoder pulses over a well-defined time period?

Thanks!

Edit: the exact error I'm getting is

[WARN] [WallTime: 14839761.73.327399] Serial Port read returned short (expecting 81 bytes, received 24 instead).
[WARN] [WallTime: 14839761.73.328598] Serial Port read failure:
[INFO] [WallTime: 14839761.73.330119] Packet Failed : Failed to read msg data
[INFO] [WallTime: 14839761.73.331164] msg len is 8

My baud rate is left at the default 57600 and the data I'm sending is a custom msg containing two float32s.

Interestingly, the error goes away if I don't do the publishing from inside the ISR, but instead from inside loop(). I then just creating an "allow_publish" variable which gets set to true in the ISR, then use this to control when to publish in loop(). I'm getting a publish rate of 49.97 Hz using rostopic hz so it seemed to be working okay.

Using interrupts with rosserial_arduino to count wheel encoder pulses

Hi.

I am trying to accurately measure my wheel velocities by counting the pulses coming from my encoders. My idea was to run an Arduino dedicated to only this task, which counts the pulses in the loop() function then uses a timer (from the Timer1 library) to trigger an interrupt service routine at a specified frequency (I was using 50Hz). Inside this ISR I work out the wheel velocity from the number of pulses counted over the 50Hz period, then publish this out over ROS.

Unfortunately when I try to connect to the node using rosserial_python, I get an error saying that it was expecting a certain number of bits but has received less than that, and the connection fails. Apologies, I don't have the Arduino with me right now so can't paste the full error, but will add it tomorrow if it will help diagnose the problem.

My guess is that whilst the Arduino is communicating back over serial, the ISR gets triggered, which interrupts the process, and ROS doesn't like it. Is this the case, or is something else going on? Can interrupts be used on an Arduino with ROS, or is this a no-go? If not, can anyone recommend a different way to count wheel encoder pulses over a well-defined time period?

Thanks!

Edit: the exact error I'm getting is

[WARN] [WallTime: 14839761.73.327399] Serial Port read returned short (expecting 81 bytes, received 24 instead).
[WARN] [WallTime: 14839761.73.328598] Serial Port read failure:
[INFO] [WallTime: 14839761.73.330119] Packet Failed : Failed to read msg data
[INFO] [WallTime: 14839761.73.331164] msg len is 8

My baud rate is left at the default 57600 and the data I'm sending is a custom msg containing two float32s.

Interestingly, the error goes away if I don't do the publishing from inside the ISR, but instead from inside loop(). I then just creating an "allow_publish" variable which gets set to true in the ISR, then use this to control when to publish in loop(). I'm getting a publish rate of 49.97 Hz using rostopic hz so it seemed to be working okay.float32s.