NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » RC car

February 12, 2011
by derberp
derberp's Avatar

Hello! I am trying to modify a Morphibian RC car by taking out the motor driver and using the nerdkit, a new motor driver, and an infrared sensor for obstacle avoidance. What I would like to do is use the car's remote control to send a signal to the nerdkit, have the nerdkit pass that on to the motor. Eventually I want to add the sensor in to override the human signal if there is an obstacle, i.e. stop or swerve around it.

I have a (dim) understanding of interrupts so I have a fundamental question before I get too committed down one path. Is it better to simply poll the input pins repeatedly and modify the motor output, or is it better to use interrupts? Or will either work for this kind of application?

I haven't found much RC hacking going on with the nerdkits like with the Arduinos. The iphone controller was pretty cool. Any interest out there in making an autonomous vehicle or UAV or some such to wow us peons?

February 14, 2011
by hevans
(NerdKits Staff)

hevans's Avatar

Hi derberp,

The polling vs interrupt question is really a question of how you intend to architect your software. In general something that needs to immediately react to something should be in a interrupt handler, and things that can take their time should be in the main loop. You need to be careful when writing interrupt handlers though because if they take too much time to run you will be missing interrupts.

Humberto

February 15, 2011
by derberp
derberp's Avatar

Thanks for your response. I went the easier (for me) route and just polled the input pins repeatedly in the main loop and it works fine.

So, along the same line, if I use 3 or 4 infrared sensors which each produce an analog voltage, and I plug them into ADC ports, will polling them 100 times each and averaging still work or will that be too slow? I guess I don't have a clear idea of how long it takes to poll the ADC 100 times and average.

February 15, 2011
by Ralphxyz
Ralphxyz's Avatar

Hi derberp, "I guess I don't have a clear idea of how long it takes to poll the ADC 100 times and average."

Well that is what the tempsensor project does, averages hundred ADC samples could you use that as a reference?

Ralph

February 15, 2011
by derberp
derberp's Avatar

That is the code I am cribbing from, but I am not using any printf commands. How can I tell how long it takes to do the 100? Also, at what point does it make more sense to go the interrupt routine route, or is that just a stylistic choice?

February 22, 2011
by derberp
derberp's Avatar

Well, for those who may eventually try this, it ends up that the ADC and the polling do not slow things down too much. In fact, I ended up putting in about 1 second of motion for every computation of distance with 3 sensors, and I even used an average of 200 readings for the front sensor. So I think the interrupt vs polling question is moot.

Post a Reply

Please log in to post a reply.

Did you know that NerdKits believes in the importance of a mixture of meaningful topics, clear instruction, and engaging projects? Learn more...