Ask Your Question
0

arduino rosserial with interrupt

asked 2016-12-28 12:20:57 -0500

jafar_abdi gravatar image

updated 2016-12-28 12:26:23 -0500

Hi all,

I'm now building a robot which uses interrupt to count up the number of ticks and do the calculations in arduino nano, after that I decided to use rosserial library to send the number of ticks to the raspberry pi, when I put the code which send the number of ticks inside the void loop function it works, but if I but the code inside the interrupt handler I doesn't work very well and when it work it send strange numbers for example "6074229997415956480" number of ticks .

ISR(TIMER1_COMPA_vect){

    RTicks_msg.data = EncoderR.GetTicks();
    LTicks_msg.data = EncoderL.GetTicks();
    RTicksPup.publish(&RTicks_msg);
    LTicksPup.publish(&LTicks_msg);
    nh.spinOnce();
}

any help ..?

thanks,

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2016-12-29 02:11:10 -0500

kartikmadhira1 gravatar image

updated 2016-12-29 02:14:09 -0500

Generally, it is advised to keep vector routines as small as possible and keep delay functions away from it to avoid computational clashes. Might be the case of priority too. The interrupt section says about the ISR's that:

Generally, an ISR should be as short and fast as possible. If your sketch uses multiple ISRs, only one can run at a time, other interrupts will be executed after the current one finishes in an order that depends on the priority they have. millis() relies on interrupts to count, so it will never increment inside an ISR. Since delay() requires interrupts to work, it will not work if called inside an ISR. micros() works initially, but will start behaving erratically after 1-2 ms. delayMicroseconds() does not use any counter, so it will work as normal.

Might just be a case of timing issue, since spinOnce(); is being called.

edit flag offensive delete link more

Comments

It seem like what you said, do you have any idea about how I can send the ticks or another approach ..?

jafar_abdi gravatar imagejafar_abdi ( 2016-12-29 03:46:37 -0500 )edit

Though I'm not an expert at this, you could declare a global volatile data type which both interrupts and the loop function can share. The basic idea is to just take in the ticks and use that ticks in the loop not in the ISR.

kartikmadhira1 gravatar imagekartikmadhira1 ( 2016-12-29 05:00:24 -0500 )edit

The problem is to calculate the odometry I need the little interval dt if I loop it I'll not be able to know it or calculate it, whereas by using ISR I fixed the time interval to be 10ms, is there any way to calculate it when using loop ..?

jafar_abdi gravatar imagejafar_abdi ( 2016-12-29 05:05:55 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-12-28 12:20:57 -0500

Seen: 583 times

Last updated: Dec 29 '16