IR Speed Detector for model railway

Thread Starter

flashman99

Joined Mar 10, 2016
35
Indeed, an accelerometer to determine orientation going into a curve and IR LEDs to determine velocity. This is a perfect application for an Arduino, but.......

OO scale (popular in the UK) is very close to HO scale that I am more familiar with. And there is the rub. We are trying to cram 1 kg of excrement into a 100 gram container. A typical HO car or locomotive is roughly 51 mm high x 38 mm wide. OO gauge is slightly larger. An Arduino board measures 71 mm x 53 mm. Now add a shield for the accelerometer breakout board, and you can see where this is going. On the positive side, the APT and Pendolino vehicles were quite long, so that lends itself to long custom PC boards. That is why I selected the more clunky Picaxe system over Arduino. Adding the accelerometer also adds a requirement for a 3.3 volt on-board regulator.

Have a look at the attached for some ideas on tilting.
 

Thread Starter

flashman99

Joined Mar 10, 2016
35
There is quit a lot of space inside the model but the tilting mechanism will take up quite a bit of space. Anyway, early stages at the moment so if I can get the theory right I'm sure I can cram it all in.
 

crutschow

Joined Mar 14, 2008
34,452

bertz

Joined Nov 11, 2013
327
The motors require high power so it will need a driver and perhaps some other signal conditioning to get the accelerometer low power output to power the motor at the proper level.
What type of motor are you considering?
Servos, as commonly found in radio control models, are a very accurate motor/ gearbox assembly that can be repeatedly moved to the same position due to their internal position sensor. Generally servos require a pulse of 0.75 to 2.25ms every 20ms, and this pulse must be constantly repeated every 20ms. Once the pulse is lost the servo will lose its position. Micro servos consume very little power and don't require a separate driver.
The attached video shows how easy it is to mate the accelerometer board to the Arduino. The code is practically written for you. Just substitute the accelerometer for the pressure sensor in the video and voila - you have your control.

 

hp1729

Joined Nov 23, 2015
2,304
Hi,

I'm working on a project in OO gauge to build an active tilting train. In order to make it realistic I would like to build some form of on-board speed detector that will send information back to the tilt system to activate it when the locomotive reaches a designated speed. I thought about mounting two ir sensors lengthways in the bottom of the loco that pick up the ir signal emission from an ir LED placed in the track a short distance before the bend. The first detector would pick up the ir emission followed by the second further down the loco, the speed being determined by the difference in time between the two detections. The problem is I don't know where to begin or what sort of circuit sophistication would be required. I would like all the electronics to be on board the loco. Any advice would be appreciated.
For other readers ... OO scale is about 1:76 scale, 4 mm = 1 foot.
A "Tilting" rail road tilts the train on curves so it doesn't have to slow down so much,

Can somebody confirm my math, please. 100 mph on OO scale is about 1.93 feet per second.
 
Last edited:

Thread Starter

flashman99

Joined Mar 10, 2016
35
Servos, as commonly found in radio control models, are a very accurate motor/ gearbox assembly that can be repeatedly moved to the same position due to their internal position sensor. Generally servos require a pulse of 0.75 to 2.25ms every 20ms, and this pulse must be constantly repeated every 20ms. Once the pulse is lost the servo will lose its position. Micro servos consume very little power and don't require a separate driver.
The attached video shows how easy it is to mate the accelerometer board to the Arduino. The code is practically written for you. Just substitute the accelerometer for the pressure sensor in the video and voila - you have your control.

Excellent, it all looks very straightforward. The only problem is the size of the Arduino board. Ebay have smaller ones such as this: http://www.ebay.co.uk/itm/161861831569?_trksid=p2055119.m1438.l2649&ssPageName=STRK:MEBIDX:IT I suppose this would work too.
 

bertz

Joined Nov 11, 2013
327
Excellent, it all looks very straightforward. The only problem is the size of the Arduino board. Ebay have smaller ones such as this: http://www.ebay.co.uk/itm/161861831569?_trksid=p2055119.m1438.l2649&ssPageName=STRK:MEBIDX:IT I suppose this would work too.
Go back and look at post #30. Stay away from e-Bay! Buy from Sparkfun or Adafruit. Since you are working with OO gauge I am making the assumption that you're in the UK. I'm sure there are similar firms that market these kinds of electronic gear. You get what you pay for. By the way, the linear servo that you previously referenced is a Horizon Hobby product, but it is being shipped from Minsk, Russia. Probably hijacked by the Russian mafia. If you like I can put together a shopping list of components for you.

I'm curious how you intend to implement the tilt mechanism. It seems to me that the car frame not only has to pivot on the trucks in the X-Y plane, but also have rotational capability. I have some thoughts on how I would do it using a Futaba S3114, but I want to see your concept first. I'm sure you have plenty of room in the passenger cars for all this gear, but what about the locomotive?

Cheers
 

bertz

Joined Nov 11, 2013
327
I must ask this question. Are you scratch building this train based on the APT prototype or are you modifying an existing model? The reason I ask is that Rapido is producing a scale model complete with tilting, close-coupling and prototype sound effects (you gotta love the sound of those gas turbines spooling up).

Cheers
 

Thread Starter

flashman99

Joined Mar 10, 2016
35
Go back and look at post #30. Stay away from e-Bay! Buy from Sparkfun or Adafruit. Since you are working with OO gauge I am making the assumption that you're in the UK. I'm sure there are similar firms that market these kinds of electronic gear. You get what you pay for. By the way, the linear servo that you previously referenced is a Horizon Hobby product, but it is being shipped from Minsk, Russia. Probably hijacked by the Russian mafia. If you like I can put together a shopping list of components for you.

I'm curious how you intend to implement the tilt mechanism. It seems to me that the car frame not only has to pivot on the trucks in the X-Y plane, but also have rotational capability. I have some thoughts on how I would do it using a Futaba S3114, but I want to see your concept first. I'm sure you have plenty of room in the passenger cars for all this gear, but what about the locomotive?

Cheers
A shopping list would be great and very kind of you if you have the time.

This video shows the tilting mechanism on the Hornby APT-P, the model I would like to modify.

I think the major issue is that I will have to duplicate the tilt mechanism in both the driving, trailer, power car and coaches. That is a lot of electronics and motors plus the coaches don't have as much space as the other cars.
 

Thread Starter

flashman99

Joined Mar 10, 2016
35
I must ask this question. Are you scratch building this train based on the APT prototype or are you modifying an existing model? The reason I ask is that Rapido is producing a scale model complete with tilting, close-coupling and prototype sound effects (you gotta love the sound of those gas turbines spooling up).

Cheers
It is to be based on the Hornby APT-P. The Rapido model is the APT-E. I'm not sure how th Rapido tilts but it is supposed to be more sophisticated than the cams on the Hornby model.
 

bertz

Joined Nov 11, 2013
327
After consultation with some of my colleagues who are well versed in drones and multi-rotor aircraft, I have altered my approach somewhat regarding your application. The accelerometer will only report a proper measurement when it is standing still. If it is shaken, moved, or bumped, the acceleration measured is no longer purely gravity based. In fact, the vibration from the drive motors will throw the readings out of wack. What is required is a clean signal to the Arduino while the train is in motion. In order to achieve that we need a gyro and accelerometer working in combination. A gyro is great at measuring rotation, but has no understanding of orientation. An accelerometer is good at determining orientation, but has no ability to keep track during rotation. Enter the MPU6050.

The MPU6050 is a neat piece of gear which combines a 3-axis gyroscope and a 3-axis accelerometer. This device interfaces nicely with the Arduino in a footprint measuring 25.5 x 15.2 mm. As much as I like the folks at Sparkfun, I'm afraid they have obscenely overpriced this item. Check out this link - MPU6050 for a reasonably priced board.

Can it do the job? Check out this video.

 

Thread Starter

flashman99

Joined Mar 10, 2016
35
After consultation with some of my colleagues who are well versed in drones and multi-rotor aircraft, I have altered my approach somewhat regarding your application. The accelerometer will only report a proper measurement when it is standing still. If it is shaken, moved, or bumped, the acceleration measured is no longer purely gravity based. In fact, the vibration from the drive motors will throw the readings out of wack. What is required is a clean signal to the Arduino while the train is in motion. In order to achieve that we need a gyro and accelerometer working in combination. A gyro is great at measuring rotation, but has no understanding of orientation. An accelerometer is good at determining orientation, but has no ability to keep track during rotation. Enter the MPU6050.

The MPU6050 is a neat piece of gear which combines a 3-axis gyroscope and a 3-axis accelerometer. This device interfaces nicely with the Arduino in a footprint measuring 25.5 x 15.2 mm. As much as I like the folks at Sparkfun, I'm afraid they have obscenely overpriced this item. Check out this link - MPU6050 for a reasonably priced board.

Can it do the job? Check out this video.

That looks great and in fact it would seem to be the same method the real prototype used. I will order the parts today. I will need a 5v power supply too presumably, any recommendations on that? Thanks for all your help, it is much appreciated.
Thanks,

Peter
 

bertz

Joined Nov 11, 2013
327
That looks great and in fact it would seem to be the same method the real prototype used. I will order the parts today. I will need a 5v power supply too presumably, any recommendations on that? Thanks for all your help, it is much appreciated.
Thanks,

Peter
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
 

crutschow

Joined Mar 14, 2008
34,452
................ The accelerometer will only report a proper measurement when it is standing still. If it is shaken, moved, or bumped, the acceleration measured is no longer purely gravity based. In fact, the vibration from the drive motors will throw the readings out of wack. What is required is a clean signal to the Arduino while the train is in motion. In order to achieve that we need a gyro and accelerometer working in combination. A gyro is great at measuring rotation, but has no understanding of orientation. An accelerometer is good at determining orientation, but has no ability to keep track during rotation.
..............................
I think you perhaps are unduly complicating this.
I don't see how a gryo will help remove the noise from the side-force accelerometer signal. :confused:
And there is not a reason to know rotation or orientation, as a drone or helicopter requires, only side force.
So since we are only interested in keeping the side force to near zero, it would seem that you could low-pass filter the accelerometer side force signal to remove any higher frequency noise, leaving only the slowly changing side force signal due to rounding a corner.
I would think a LP corner of 1Hz or less would work.
A micro could easily do a running average of the signal for this filtering purpose if a micro is used for control.
 

bertz

Joined Nov 11, 2013
327
I think you perhaps are unduly complicating this.
I don't see how a gryo will help remove the noise from the side-force accelerometer signal. :confused:
And there is not a reason to know rotation or orientation, as a drone or helicopter requires, only side force.
So since we are only interested in keeping the side force to near zero, it would seem that you could low-pass filter the accelerometer side force signal to remove any higher frequency noise, leaving only the slowly changing side force signal due to rounding a corner.
I would think a LP corner of 1Hz or less would work.
A micro could easily do a running average of the signal for this filtering purpose if a micro is used for control.
Actually, I'm simplifying the problem. The MPU6050 does all the work for you so the only connection to the CPU are a two wire I2C connection. No mucking about with filters. Trust me, I've been down this road when experimenting with multi-copters and model airplane stabilization systems. We are aiming for plug and play.
 

crutschow

Joined Mar 14, 2008
34,452
Actually, I'm simplifying the problem. The MPU6050 does all the work for you so the only connection to the CPU are a two wire I2C connection. No mucking about with filters. Trust me, I've been down this road when experimenting with multi-copters and model airplane stabilization systems. We are aiming for plug and play.
I still don't see how you get rid of the vibration problem unless you filter the signal.
Perhaps the CPU program already does that?
 

bertz

Joined Nov 11, 2013
327
I still don't see how you get rid of the vibration problem unless you filter the signal.
Perhaps the CPU program already does that?
The MPU6050 has an integral digital motion processor with built-in low pass filters for the gyroscopes and accelerometers. Check out the data sheet for full details on this little beauty.
 
Top