IR Speed Detector for model railway

Reading this thread, I'm reminded of the saying:
"If the only tool you have is a hammer, everything looks like a nail",

or in this case "If the only tool you have is a MPU6050 with an integral digital motion processor with built-in low pass filters for the gyroscopes and accelerometers.........."
 

bertz

Joined Nov 11, 2013
327
Couple of points I would like to make.

Some of the posts on this thread have implied that an IMU is seriously overkill for this application. Well I agree, and at 40USD a pop I wouldn't give a second thought to using one. With that said, the board I have recommended has a myriad of applications, many of which are extremely sophisticated. The availability is nearly universal so that the cost is less than the servo used to impart tilt motion to the car body.
The other factor to recommend it is the number of Arduino libraries that support this particular sensor so that we don't have to go through an excruciating development ordeal. The heavy lifting has already been done. So is it overkill? Yes. Does it work in our application? Yes. Is it affordable? Yes. Are there software libraries to support it? Yes. Is it easy to hook up? Yes, only two wires to the Arduino!

Something that everyone seems to have overlooked is that the OP is a serious model railroader, something that I can relate to. What caught my attention is that he wants to model the APT-P instead of the APT-E. What that means to the un-initiated is that he wants to model a 14 car train instead of a 4 car train, and he wants it to replicate the prototype as closely as possible. My concern is supplying good clean power to all these devices.
Arduino - 25 mA (datasheet)
IMU - 4 mA (datasheet)
Servo - 30 mA (measured based on Futaba S-3114)
Total - 59 mA x 14 cars = 826 mA Holy milliamps batman! That's a lot of juice.

It seems to me the focus on this thread should be on how to power all this and cram it all into a 29 mm wide x 150 mm long footprint. Not sure about the length measurement. Perhaps the OP can give us a measurement between the bogies for driven and non- driven cars.
 

Thread Starter

flashman99

Joined Mar 10, 2016
35
G'day Peter

Before you go charging out and purchasing components, let's take a moment to summarize where we are at this point (at least as I understand it).

  1. You want to model the tilting action of the prototype APT-P by modifying the Hornby model APT-P. I assume this means the entire 14 car train.
  2. The Hornby model APT-P is already fitted with a rudimentary tilting device. Your goal is to improve on this device in order to more accurately reflect the prototype operation.
  3. Each car (driven or non-driven) has an independent tilt mechanism.
  4. The plan is to use a micro-servo (linear or rotary) to impart the tilting motion.
  5. An IMU (Inertial Measuring Unit) is the primary sensor for detection of the tilt angle and to provide an analog signal to the CPU. The MPU6050 is a proven device for this application. We should note (and this is very important as we shall see) that this is a 3.3 volt device.
  6. A miniaturized version of the popular Arduino is the preferred choice for a CPU. It can provide a proportional signal to the servo as a function of the analog input from the IMU. The Sparkfun Pro Micro-5V/16MHz appears to be the right tool for the job and it has an on-board USB connector for programming convenience.
  7. You will need a USB-A to Micro_B cable for programming the Arduino.
  8. The train operates off of track power which can vary from 0 to 12 VDC. Digital Command Control (DCC) presents its own set of problems due to the superimposed pulses. Now the CPU requires a clean, regulated 5 VDC supply. The IMU requires a clean, regulated 3.3 volt supply. Therefore a dual voltage regulated power supply is required. However, here is where we run into a bit of a sticky wicket.
  9. The input voltage for the regulator board is specified at 6.5 to 12 VDC. But track power can vary between 0 and 12 volts. So our tilt mechanism becomes inoperative if the track voltage drops below 6.5 volts. There is an additional problem; the regulator board has a reverse voltage protection diode. That means when our APT is operating in the reverse direction, the tilt mechanism is inoperative.
  10. Another problem we run into is how we transfer track power from the rails to the electronics. First the wheels have to contact the track, then typically a copper wiper picks up the voltage from one of the axles. All of this generates electrical noise which is not good for sensitive digital electronics.
  11. Finally, we have the issue of a 14 car train. Let's assume that each car has one servo to operate the tilt mechanism. I'm not sure which servo you will ultimately use, but for calculation purposes I measured the current draw of the Futaba S-3114. In normal operating mode it draws between 30 and 35 mA. Stall current is around 150 mA. This means the current draw just for servos alone is around 500 mA. The recommended current limit for the suggested power supply board is 500 mA.
There is also an issue with available I/O on the CPU as well as a work around for the power supply which I'll discuss in the next post. Meanwhile, give these points of consideration some thought. As I see it going forward, power is going to be our single biggest issue.

Cheers
I won't be building a 14 coach set as Hornby never made the additional coaches. Some modellers have done a 'cut and shut' version of the missing coaches but i could never bring myself to carve up what is a quite a rare model. The configuration I will be making employs a driving car/trailer, a passenger coach, a power car, a passenger coach and a driving car trailer. Most people don't have the space in the UK to make station platforms large enough to accommodate the 14 car prototype!
In order to minimise the power requirement I was thinking that maybe the power to each servo control could be switched on as the carriage reaches the bend and switched off on exit from the bend. I did consider reed relays in the bogies actuated by a magnet in the track but maybe this is a rather crude approach. I would like to enable the model to be easily convertible to DCC in the future. I have been away from the hobby for a good few years when only Zero 1 was available so have some catching up to do.
Would a re-chargable battery fir the bill for powering the electronics? Two sets could be used, one set charging from the track as the train is running and automatically switching over when the set needs re-charging.
One the point I am considering is that only the driver/trailers have active tilt, the others are tilted by strong neo magnets placed inside the corridor connections. So when the driving car tilts it causes the next carriage to tilt and so on. I don't know if this is feasible yet but would cut down on the electronics.
 

Thread Starter

flashman99

Joined Mar 10, 2016
35
Couple of points I would like to make.

Some of the posts on this thread have implied that an IMU is seriously overkill for this application. Well I agree, and at 40USD a pop I wouldn't give a second thought to using one. With that said, the board I have recommended has a myriad of applications, many of which are extremely sophisticated. The availability is nearly universal so that the cost is less than the servo used to impart tilt motion to the car body.
The other factor to recommend it is the number of Arduino libraries that support this particular sensor so that we don't have to go through an excruciating development ordeal. The heavy lifting has already been done. So is it overkill? Yes. Does it work in our application? Yes. Is it affordable? Yes. Are there software libraries to support it? Yes. Is it easy to hook up? Yes, only two wires to the Arduino!

Something that everyone seems to have overlooked is that the OP is a serious model railroader, something that I can relate to. What caught my attention is that he wants to model the APT-P instead of the APT-E. What that means to the un-initiated is that he wants to model a 14 car train instead of a 4 car train, and he wants it to replicate the prototype as closely as possible. My concern is supplying good clean power to all these devices.
Arduino - 25 mA (datasheet)
IMU - 4 mA (datasheet)
Servo - 30 mA (measured based on Futaba S-3114)
Total - 59 mA x 14 cars = 826 mA Holy milliamps batman! That's a lot of juice.

It seems to me the focus on this thread should be on how to power all this and cram it all into a 29 mm wide x 150 mm long footprint. Not sure about the length measurement. Perhaps the OP can give us a measurement between the bogies for driven and non- driven cars.
Bogie centres driving/trailer 210mm, Power car 190mm, coaches 210mm
 

bertz

Joined Nov 11, 2013
327
I won't be building a 14 coach set as Hornby never made the additional coaches. Some modellers have done a 'cut and shut' version of the missing coaches but i could never bring myself to carve up what is a quite a rare model. The configuration I will be making employs a driving car/trailer, a passenger coach, a power car, a passenger coach and a driving car trailer. Most people don't have the space in the UK to make station platforms large enough to accommodate the 14 car prototype!
In order to minimise the power requirement I was thinking that maybe the power to each servo control could be switched on as the carriage reaches the bend and switched off on exit from the bend. I did consider reed relays in the bogies actuated by a magnet in the track but maybe this is a rather crude approach. I would like to enable the model to be easily convertible to DCC in the future. I have been away from the hobby for a good few years when only Zero 1 was available so have some catching up to do.
Would a re-chargable battery fir the bill for powering the electronics? Two sets could be used, one set charging from the track as the train is running and automatically switching over when the set needs re-charging.
One the point I am considering is that only the driver/trailers have active tilt, the others are tilted by strong neo magnets placed inside the corridor connections. So when the driving car tilts it causes the next carriage to tilt and so on. I don't know if this is feasible yet but would cut down on the electronics.
Whew! You really had me worried for awhile. I thought you were going to construct your layout in Wembley Stadium. Although I have seen videos with 14 car trains in OO gauge.
A five car train changes the whole picture, and for the better I might add. Since the Sparkfun Pro Micro has 5 PWM outputs, it seems as though we only need one controller to handle the servos. Also, the IMUs talk to the controller via an I2C bus. So in theory we should be able to have the controller poll each IMU for a position and output a signal back to each servo. This is something we need to post up on the Arduino forum in order to get some feedback from those chaps as to the efficacy of this approach.
Assuming this is a viable approach, here is the order of battle as I see it:
5 ea. MPU6050 @ 4mA each 20 mA
1 ea. Sparkfun Pro Micro CPU 25 mA
5 ea. micro servos @ 30 mA each 300 mA
Total 345 mA
I considered LiPo batteries but they require special chargers and I'm not sure if there is off the shelf switching circuitry and whether or not its miniaturized. For now let's stick with scavenging track power to feed the dual voltage power supply that I previously recommended. I would use two of them. One would provide power when the train is going forward and the other would provide power when the train is reversed. Perhaps we can accomplish the same thing with one supply and a DPDT relay. I'll think about that.
There is still the issue of the electronics quiting if the track voltage falls below 6.5 volts; but at that voltage the train is traveling quite slow so the tilting action would not be necessary - or would it? If the contact between track, wheels, wipers and axles creates too much electrical noise we can cobble together a little L-C filter to deal with it if necessary.

So, what's next? I am leaving tomorrow for my Spring holiday and will be back in a week. First assemble the materials to do a proof of concept for the tilt mechanism. You only need a servo, a servo driver, and whatever mechanical components it takes. Work out the mechanical arrangement first.

Next, get on the Arduino website and familiarize yourself with this platform. There are a whole host of model RR applications using the Arduino. Subscribe to the Arduino forum. If you decide to implement the project as we have described, we will be moving this discussion to that forum.

Good luck and hope to hear from you soon.
 

withoutego

Joined Dec 22, 2015
26
Linear Hall transducer between ties and small rod magnet fixed under rolling stock or locomotive.
There will be two peaks when the magnet passes with a zero crossing being the mid point and
the order of the pole crossing peaks giving direction. North then south or south followed by north.
The time difference would be the speed and it would be accurate even for slow crossings. A small
micro controller with A/D channel and a few lines of code....You could also do it analog.
 

Thread Starter

flashman99

Joined Mar 10, 2016
35
Linear Hall transducer between ties and small rod magnet fixed under rolling stock or locomotive.
There will be two peaks when the magnet passes with a zero crossing being the mid point and
the order of the pole crossing peaks giving direction. North then south or south followed by north.
The time difference would be the speed and it would be accurate even for slow crossings. A small
micro controller with A/D channel and a few lines of code....You could also do it analog.
That sounds like an excellent solution but I would need the mount the transducer in the train and the magnets in the track. The speed fed back to the micro controller could then be used to determine the degree of tilt.
 

Thread Starter

flashman99

Joined Mar 10, 2016
35
Whew! You really had me worried for awhile. I thought you were going to construct your layout in Wembley Stadium. Although I have seen videos with 14 car trains in OO gauge.
A five car train changes the whole picture, and for the better I might add. Since the Sparkfun Pro Micro has 5 PWM outputs, it seems as though we only need one controller to handle the servos. Also, the IMUs talk to the controller via an I2C bus. So in theory we should be able to have the controller poll each IMU for a position and output a signal back to each servo. This is something we need to post up on the Arduino forum in order to get some feedback from those chaps as to the efficacy of this approach.
Assuming this is a viable approach, here is the order of battle as I see it:
5 ea. MPU6050 @ 4mA each 20 mA
1 ea. Sparkfun Pro Micro CPU 25 mA
5 ea. micro servos @ 30 mA each 300 mA
Total 345 mA
I considered LiPo batteries but they require special chargers and I'm not sure if there is off the shelf switching circuitry and whether or not its miniaturized. For now let's stick with scavenging track power to feed the dual voltage power supply that I previously recommended. I would use two of them. One would provide power when the train is going forward and the other would provide power when the train is reversed. Perhaps we can accomplish the same thing with one supply and a DPDT relay. I'll think about that.
There is still the issue of the electronics quiting if the track voltage falls below 6.5 volts; but at that voltage the train is traveling quite slow so the tilting action would not be necessary - or would it? If the contact between track, wheels, wipers and axles creates too much electrical noise we can cobble together a little L-C filter to deal with it if necessary.

So, what's next? I am leaving tomorrow for my Spring holiday and will be back in a week. First assemble the materials to do a proof of concept for the tilt mechanism. You only need a servo, a servo driver, and whatever mechanical components it takes. Work out the mechanical arrangement first.

Next, get on the Arduino website and familiarize yourself with this platform. There are a whole host of model RR applications using the Arduino. Subscribe to the Arduino forum. If you decide to implement the project as we have described, we will be moving this discussion to that forum.

Good luck and hope to hear from you soon.
Thanks, I need to start work on the tilt mechanism, if I can't get that working then the rest is academic! Just need to find a scrap APT driving/trailer car that I can cut up.
 
Thanks for replying. I like the idea but I'm not sure I could make it small enough to fit in the space available. I think the next step is to design the tilting mechanism and see how much space I have left.
This is always going to be the problem whichever technology you opt for. However, there aren't really very many components and they are all quite small so it could be built on a fairly narrow piece of stripboard or split across 2 boards with the H-bridge separate from the rest. If you can design a PCB or ideally use surface mount components it could be built very small.

The big advantage is that there is no software or hardware to learn and no code to write, it also uses common, inexpensive parts. There is only one adjustment and with VR1 set in the middle position the motor will respond to around +/- 0.05G which should be sufficient to keep the carriage looking level when it's not cornering.

A micro-servo with the electronics removed would provide a suitable drive system.
 
Last edited:

Tonyr1084

Joined Sep 24, 2015
9,744
Interesting project. AND I think you've already been given some great options. My first though was to use an accelerometer (like cruschow recommended). With such a circuit it wouldn't matter WHAT speed the train was traveling. If lateral G forces were 0.05 the train would tilt until the lateral forces were neutralized. And if the train was traveling faster it might see 0.2 lateral G force and the train would automatically tilt until once again, the forces were neutralized.

Blocco offered an alternative, and after reading up on that I thought it was another great idea. Again, depending on lateral G forces the train would tilt accordingly to neutralize the force. BOTH great approaches.

Trying to sense the location of a curve, which direction the curve is, when the curve ends (or changes), sensing the speed of the train, all that seems like a very complicated approach. Not only are you seeking to determine the speed of the train, you're also trying to calculate the amount of tilt to negate the lateral forces. AND the timing of when such tilting is to occur. Sounds like a whole lot of sensing and processing work to me.

I can't offer you any more advice than what's already been posed. If this were my project I'd be opting for crutschow's approach or Bloccos approach. And being that this is 00 gauge, it's big enough to house a lot of electronics.

I didn't see where you were asking for a power source for the tilt mechanism. I suppose you could do it with batteries, or you could use rechargeable batteries and pick up power from the track. The whole reason for an on-board power supply would be so that when the train is traveling at lower speeds less power for tilting would be available, and thus, possibly delay the tilt.

I will be following this just to see where you end up going and why. AND how it turns out. MY model railroading has been limited to HO or N gauge on the kitchen floor in an oval with an old standard variable transformer power supply. 00 gauge WOULD be more fun - bigger but take up more space. As long as I had the room for it (and the money and time) maybe.
 

crutschow

Joined Mar 14, 2008
38,533
.................My first though was to use an accelerometer (like cruschow recommended). With such a circuit it wouldn't matter WHAT speed the train was traveling. If lateral G forces were 0.05 the train would tilt until the lateral forces were neutralized. And if the train was traveling faster it might see 0.2 lateral G force and the train would automatically tilt until once again, the forces were neutralized.

Blocco offered an alternative, and after reading up on that I thought it was another great idea. Again, depending on lateral G forces the train would tilt accordingly to neutralize the force. BOTH great approaches.
................
I thought my approach and Blocco's were essentially the same.
How do you see them as different? :confused:
 

Tonyr1084

Joined Sep 24, 2015
9,744
Three axes accelerometer versus a swinging light bar and sensors (hope I didn't oversimplify that). The more the voltage goes positive the more the motor is driven to tilt against lateral forces until it's neutralized. Swing it the other way and the voltage reverses direction, either uprighting the car or swinging it against the changed lateral force.

Essentially both approaches are the same, but one uses an accelerometer while the other uses some kind of sensor. I'd have to go back to the post and read up on it again. Nevertheless, I like both approaches.

ME? However? I'd probably mount a pivot somewhere above the center of gravity and just put a bunch of lead weights in the lower section. When the car goes around the corner the weights swing outward tilting the car inward. No electronics, no batteries or motors, no Arduino, no code, just simple engineering. A SWING.
 
Three axes accelerometer versus a swinging light bar and sensors (hope I didn't oversimplify that). The more the voltage goes positive the more the motor is driven to tilt against lateral forces until it's neutralized. Swing it the other way and the voltage reverses direction, either uprighting the car or swinging it against the changed lateral force.

Essentially both approaches are the same, but one uses an accelerometer while the other uses some kind of sensor. I'd have to go back to the post and read up on it again. Nevertheless, I like both approaches.

ME? However? I'd probably mount a pivot somewhere above the center of gravity and just put a bunch of lead weights in the lower section. When the car goes around the corner the weights swing outward tilting the car inward. No electronics, no batteries or motors, no Arduino, no code, just simple engineering. A SWING.
Actually, I conceded to using the superior ADXL335 accelerometer module over the opto-mechanical arrangement I originally proposed and my schematic incorporates this device.

The problem with your proposed passive tilting system is that the centre of gravity swings to the outside of the bend de-stabilising the car which is the exact opposite of what is needed.
 

Tonyr1084

Joined Sep 24, 2015
9,744
The problem with your proposed passive tilting system is that the centre of gravity swings to the outside of the bend de-stabilising the car which is the exact opposite of what is needed.
I know. But if the weight is low enough it can be mostly mitigated. The APPEARANCE of a train that tilts over will be accomplished. I like simple. Will the car topple over and off the tracks? Possibly. But that's still possible even with a tilt mechanism. With all that workings at a higher center of gravity, despite the apparent tilt of the car, the centrifugal force will still want to topple the car off the track IF the train is moving too fast.

It would have to be something I'd want to build in order to be able to say for sure whether it would be a worth while venture. I'm just saying. But I think I've said all I'm qualified to say on this subject. I'll sit back and read the mail for a while (what others are saying here) and maybe change my point of view.
 

djsfantasi

Joined Apr 11, 2010
9,237
The entire point of tilting the car, is to shift the cog toward the center of the curve, allowing greater speed by counteracting the outward force. A 'swing' would amplify the outward force and in the case of a model, provide very little counterbalance. Unless there was a static weight in the car... But this would destablize the car on straightaways. If you look at how the prototype does it, there are linkages connecting the carriage to the bogeys, such that the car itself becomes the pendulum.
 

Bernard

Joined Aug 7, 2008
5,784
A strange tilt arrangement:
A - micro servo like Towerpro SG 50 or MG90S about 3 cm total length.
B & C- solenoid operated latches front & rear, release with power on. OO Scale train#2 00000.jpg OO Scale train 00000.jpg
 

Bernard

Joined Aug 7, 2008
5,784
For battery power LiFePO4 should work well, it is closer to NiCd as to charge requirements. & there is a
battery charge management control chip, MCP73223, 3mm X 3mm but there might be a breakout board available. 2 cells, 3.2 V, 1200 mAh, 18 mm dia. ,by 65 mm long. from onlybatteries.com.
I have ben using a similar set for about 9 months for my lighthouse, solar power home brew charger.
Might OR track power & battery into a buck convertor for 5 V, derive 3.3 V from 5V.
 
Top