The Craftmans Shop > Radio Control Models

Bruder Manitou 2150 - RC conversion

<< < (8/19) > >>

ddmckee54:
I did a little more testing and debugging last night.  I've got the programming working correctly on all the LED functions except one, the rear turn signal.

The rear turn signal is a red LED that does double duty, it is on steady when braking, and it flashes when turning.  The turn signals flash on for 250 milli-seconds and then are off for 750 milli-seconds.  If we're still turning when this cycle is complete, then the cycle is repeated, and repeated, and repeated - just like that old guy you followed that had his turn signal on for 5 minutes. The brake lights are a cycle that is triggered by a speed set-point reduction.  They will be turned on for about 4 seconds and then turned off.

What about if you are turning and braking?  Funny you should ask, that's the one that isn't working correctly.  When braking and turning, the rear turn signal is flashed, off when the front turn signal is on and on when the front turn signal is off - so that the light is on more than it is off.  At the end of the braking cycle the rear turn signal is SUPPOSED to sync up with the action of the front turn signal.  Sometimes the rear turn signal will complete the braking cycle and sync up with the front turn signal - just like it's supposed to do.  Sometimes it stays in the braking cycle WAYYYY longer than it supposed to.  And sometimes it completes the braking cycle, syncs up, and then eventually resets itself and starts the whole thing over again.

Somewhere I did something stupid and I've got a race-condition/timing issue. I think what's happening is sometimes it's event A before event B, and sometimes it's event B before event A.  I just need to find my Boo-Boo and fix it.

Don

Pete.:
Isn't there some kind of gui that you can point and click and it will spill out code for the nano? That all seems like a whole lot of effort.

ddmckee54:
Pete:

GUI, not that I know of.  There's similar stuff out there that I could copy and paste, but where's the challenge in that?  Just yesterday I stumbled across a thread in rctruckandconstruction.com of a guy that was doing something similar with a Nano.  But I've always wanted to learn how to program an Arduino, and this gave me a perfect excuse reason to do it.

Don

AdeV:
Hi Don,

Interesting work with the Nanos... would you be prepared to show your code? I'd be interested in how you've achieved your various functions.

I've done a few bits and pieces with Arduinos (including Nano and Mini Pro sized boards, both with/without FTDI and/or USB interfaces); I'd probably work this one as a finite state machine, or more likely as a set of FSMs - one per function, or one per light, whichever worked out easier.

ddmckee54:
AdeV:

When I've got the code working, I plan on posting it.

This isn't my first programming rodeo, I've been programming PLC's for 30 years.  However this IS my first rodeo programming Arduinos.  Consequently, the programming will have more brute force than eloquence.  I find myself thinking of the programming in terms of a PLC's ladder logic programming, and then converting that in my head to something the Nano can understand.

Let me ask you this, what do know about the timing of the pulsein function?  I'm not sure, but from what I read it sounds like if I tell the Nano to do a pulsein on a particular digital pin, it's going to sit there and wait until it sees that pulse.  Program execution basically stops?  Does program execution also stop during a delay, like I think it does?

If that's what happens then I can see why everyone says you should use interrupts instead of the pulsein function.  At 2 milliseconds per channel, when you add in some time separation between channel pulses, and some time at the end so the receiver knows there's a new pulse string coming - then we're looking at a 20-30 millisecond time for a complete pulse string.  That's a longggg time for the Nano to be sitting there twiddling it's proverbial thumbs.

Don

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version