0

I've been trying to use interrupts to control a quadrotor with a tx/rx to no success. I'm using an arduino mega as my control board. I have successfully read a singe channel using attach interrupt and PulseIn. I have also successfully read multiple channels with pulse but failed to do so with attach interrupt and pinchange int. Should I just go ahead and use PulseIn

  • Your referring to reading ppm signals from an RC radio with pulseIn? – BrettAM Mar 20 '15 at 19:53
  • Yes. I have been told to avoid it but nobody who tells me this explains why – Ozymandias Mar 20 '15 at 20:21
1

You should avoid pulseIn for a quadcopter, the main reason being that pulseIn takes too long to execute.

pulseIn waits for a pulse to start, then waits until that pulse finishes, and then returns how long it took to finish. Standard RC signals pulse at 50-60Hz, with the "high" part of the signals being between 1 and 2 milliseconds. 60Hz is one pulse per 16 milliseconds or so.

What that amounts to is pulseIn taking at most 18 milliseconds, but never less that 1 millisecond to execute per channel. lets say you want to measure 4 channels (throttle, pitch, yaw, roll); the average time would be around 40 milliseconds.

In general 40 milliseconds isn't so long, but your quad will need to read the accelerometer and gyroscope and stabilize itself more often then that in the air. A loop that takes 40 ms is running at 25Hz, but the stabilize loop in all the quadcopter implementations I'm familiar with is run at 100Hz or higher (thats areoquad, multiWii, and ardupilot).

You should use interrupts to read the values, because interrupts are non blocking, and give higher quality readings. Some specialized quadcopter boards have other processors read the actual RC signals and send the result back to the main processor to cut down on the number of interrupts they have to use.


FYI, The standard servo output library sends new signals at 50Hz. Those open source quadcopters use their own implementations that run at higher output frequencies, since brushless ESCs support that. There is a pull request with code to add support for different refresh intervals to the arduino servo library here that I have tested; You could try appling it as a patch to your installation if the output rate gives you trouble down the road.

  • Thanks for the servo library information. Great. I did try it on my quad and I got this error information stated below after refreshing my servo library. Any idea what causes this and how to correct this? C:\Program Files (x86)\Arduino\libraries\Servo\src\avr\Servo.cpp:40:69: error: 'usTOTicks' was not declared in this scope ^ exit status 1 Error compiling for board Arduino Nano. – Jesse Aug 21 '16 at 8:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.