Kolaf

Automated train -- extended

Recommended Posts

Hello again,

It is time for another update in my quest for automating a power functions Lego train layout, but without necessarily using power functions :). This time around I have switched to a smaller circuit board (Arduino mini pro), allowing me to embed almost everything into the new Lego passenger train. It still has a prototype feel that I have too resold on some wires in order to hide them inside the train. Nevertheless, it works brilliantly.

Here's what's happening in the video below. I have embedded some codes in the tracks around the station which are read by the reflex detector on the lead carriage on the train. These clothes will cause the train to as it approaches the station, before it stops when reaching the station. The trail then later the station for 10 seconds before it resumes its previous speed. This speed is kept until it passes the code to increase speed which is only upward slope following the station. On the other side of the bookshelf the speed is decreased again to account for the downhill towards the station. When reaching the station the channel against top 10 seconds, before it pulls out in the other direction. This time you will more easily see how it accelerates after passing the acceleration code embedded in the tracks.

To summarise, I only start the train, the rest is automatic.

Enjoy!

Share this post


Link to post
Share on other sites

I don't fully understand how it works, but it looks and works great. It's very nice that the codestrips are really legolike, and if I understand well, you can place them where you like, and program them with different task for the trains to perform? Am I right?

I am really looking forward to further details on the trains and the used electronics, and of course if this system allows to work with more trains on the same track.

Great work,

Jan

Share this post


Link to post
Share on other sites

I don't fully understand how it works, but it looks and works great. It's very nice that the codestrips are really legolike, and if I understand well, you can place them where you like, and program them with different task for the trains to perform? Am I right?

I am really looking forward to further details on the trains and the used electronics, and of course if this system allows to work with more trains on the same track.

Great work,

Jan

Since the train is based on power functions, there is nothing principally wrong with having multiple trains on the track simultaneously. The trick is stopping them from colliding ;)

As I said initially, the train is controlled by a microcontroller connected to a reflex detector mounted underneath the first carriage. It detects the passing of every white, four stud long flat (studless) brick mounted in the middle of the track. The distance between the bricks determines whether a zero or a one is encoded. Currently I use codes that are three bits long, initially supporting eight different commands. However, this is further limited by the fact that every code will be read in both directions depending on the direction of the train. Care must therefore be used when designing the codes and the commands they trigger.

Initially, I'm using the coach to slow down and speed up the train as it approaches curves/leaves curves, and passes stations/stopping points. They can also be used for other tasks such as sounding a horn etc.

The microcontroller interfaces with the train through a regular motor control and used in electric RC cars.

Please free to post some more specific questions if you have them :)

Share this post


Link to post
Share on other sites

Awesome stuff. Are you able to use 4 sensors in a row and then use 1x1 plates for your coding strips to maybe give more options?

Interesting. So you mean that I could encode four bits in parallel. I guess I could if I switch to a different sensor than what I'm using now. I'll definitely think about it. But what would you use a large number of commands for? There is stopping, different speeds, sounding the horn, but what else?

Share this post


Link to post
Share on other sites

Interesting. So you mean that I could encode four bits in parallel. I guess I could if I switch to a different sensor than what I'm using now. I'll definitely think about it. But what would you use a large number of commands for? There is stopping, different speeds, sounding the horn, but what else?

Uni-direction codes, which are only read in one direction. Or have a flag set on the train, to designate it as a Cargo, Intercity or Local train. So the CPU will only codes meant for that kind of train (like stopping at a station), but there are still global codes for intersection and speed-settings.

Share this post


Link to post
Share on other sites

This must've taken quite a while to make and program. This is just amazing how people like you can do things like this, keep up the great work!!

Share this post


Link to post
Share on other sites

Uni-direction codes, which are only read in one direction. Or have a flag set on the train, to designate it as a Cargo, Intercity or Local train. So the CPU will only codes meant for that kind of train (like stopping at a station), but there are still global codes for intersection and speed-settings.

Exactly. Passenger trains stop at the station, cargo trains stop at the cargo depot. You could even do the reverse and embed a code on the bottom of a train which is read by a scanner on the track to activate points and send different trains down different lines or to stop a train in order for another one to pass. I reckon you could do some really cool stuff with this.

Share this post


Link to post
Share on other sites

i quite understand the method to modify the speed when approaching a station / point. awesome! but i wonder how would the switching track, switch the track automatically (when the train is making O turn, around the end of your video) ? is it using an arduino too? please explain it.

TIA :)

Share this post


Link to post
Share on other sites

Since the train is based on power functions, there is nothing principally wrong with having multiple trains on the track simultaneously. The trick is stopping them from colliding ;)

As I said initially, the train is controlled by a microcontroller connected to a reflex detector mounted underneath the first carriage. It detects the passing of every white, four stud long flat (studless) brick mounted in the middle of the track. The distance between the bricks determines whether a zero or a one is encoded. Currently I use codes that are three bits long, initially supporting eight different commands. However, this is further limited by the fact that every code will be read in both directions depending on the direction of the train. Care must therefore be used when designing the codes and the commands they trigger.

Initially, I'm using the coach to slow down and speed up the train as it approaches curves/leaves curves, and passes stations/stopping points. They can also be used for other tasks such as sounding a horn etc.

The microcontroller interfaces with the train through a regular motor control and used in electric RC cars.

Please free to post some more specific questions if you have them :)

Hi Kolaf,

this is awesome work! Really great. I guess the micro controller you are using is pretty smart. Did you see this though:

Masao is doing comparable things this with an RCX on board (and all the design restrictions that come with it ...). I have some experience with RCX controlled trains (http://www.eurobricks.com/forum/index.php?showtopic=45440) as well.

Now, do you think both approaches could be merged into one? In other words, you would "control" the train from a computer using some sort of messaging, but this could be "overridden" by the codes embedded in the track layout (and vice versa)? This would be cool! I am entertaining the idea of incorporating a light sensor into my trains ...

Question would be: How fast does the controller need to be to be able to recognize the coded track sections? Since the RCX' in the trains I have built are running RobotC firmware, the are pretty fast.

Do you think this could work?

All the best - I am looking forward to your updates!!!

Thorsten

Share this post


Link to post
Share on other sites

i quite understand the method to modify the speed when approaching a station / point. awesome! but i wonder how would the switching track, switch the track automatically (when the train is making O turn, around the end of your video) ? is it using an arduino too? please explain it.

TIA :)

Hi Sayid,

I'm pretty sure the points don't need to be set correctly coming from the other direction, they are spring loaded so the wheels will just push them out of the way.

Share this post


Link to post
Share on other sites

Hi Sayid,

I'm pretty sure the points don't need to be set correctly coming from the other direction, they are spring loaded so the wheels will just push them out of the way.

whoa.. that simple? haha.. fool me

Share this post


Link to post
Share on other sites

Exactly. Passenger trains stop at the station, cargo trains stop at the cargo depot. You could even do the reverse and embed a code on the bottom of a train which is read by a scanner on the track to activate points and send different trains down different lines or to stop a train in order for another one to pass. I reckon you could do some really cool stuff with this.

I agree, there are lots of possibilities. Hadn't thought about putting the sensor on the track, and the code on the train. This will be quite complex, so I will stick with the one sensor on the train for now. My immediate future plans involves adding the signals, that combine with an IR led which will cause the train to stop when it approaches a red signal. When the signal turns green, the train will start. Also try to automate the switches and interface them to the computer so that I can control them with a simple UI, which also will be made available on android phone :)

Hi Kolaf,

this is awesome work! Really great. I guess the micro controller you are using is pretty smart. Did you see this though:

Masao is doing comparable things this with an RCX on board (and all the design restrictions that come with it ...). I have some experience with RCX controlled trains (http://www.eurobricks.com/forum/index.php?showtopic=45440) as well.

Now, do you think both approaches could be merged into one? In other words, you would "control" the train from a computer using some sort of messaging, but this could be "overridden" by the codes embedded in the track layout (and vice versa)? This would be cool! I am entertaining the idea of incorporating a light sensor into my trains ...

Question would be: How fast does the controller need to be to be able to recognize the coded track sections? Since the RCX' in the trains I have built are running RobotC firmware, the are pretty fast.

Do you think this could work?

All the best - I am looking forward to your updates!!!

Thorsten

Thanks for the YouTube link, I hadn't seen that one. It looks like he's doing something similar, but without a direct relationship to "command words" of a certain bits length. I must admit I'm curious as to how he has implemented it. My main reason for using a regular microcontroller was price, and to a certain extent size. Lego stuff is expensive.

In the set up I have now I can turn the automatic control on and off by clicking a button on my remote control. This will determine whether the train reacts to the codes it passes. Furthermore, I can always override the train is doing using the remote control. In that sense I guess I already have combination you hint at.

The speed of the control does not have to be very fast, the speed has to be sufficient to detect every state at least two times. This means that every high must be sampled at least two times by the passing sensor. Given the width of one stud and the speed of the train, it should be a simple matter to calculate the minimum speed of your sampling code.

Share this post


Link to post
Share on other sites

Lego stuff is expensive.

Oh yes, agreed! Particularly when it comes to electronics (other than PF) they really want to see some money ... NXT (and RCX in the good old days) are/were insanely expensive.

In the set up I have now I can turn the automatic control on and off by clicking a button on my remote control. This will determine whether the train reacts to the codes it passes. Furthermore, I can always override the train is doing using the remote control. In that sense I guess I already have combination you hint at.

That is what I am really curious about - and I spent some time thinking about a solution: Masao's approach was simply "timing out" after the train stopped to start over. That would not work for me. Lets assume a train reads "go slow" and soon after "stop". The software running on my RCX trains does react with a delay function to requested speed changes - to reflect some realistic train behavior: A stop command should not result in "BangStopped" but slowly turn down power. The problem with that is of course that I don't really know where the train actually stops. When your came to a stop: How do they start again? Time-out, or do you tell them by the remote, or do they know where they are and tell them by some visual code? Since you said they do everything on their own, I doubt the remote.

Another question (sorry, but this is really good stuff you are doing ...): "Overriding with the remote", does that mean you are telling your train: "From now on, it is up to you" or do you use time-outs? (After x seconds, go back to auto ...)

The speed of the control does not have to be very fast, the speed has to be sufficient to detect every state at least two times. This means that every high must be sampled at least two times by the passing sensor. Given the width of one stud and the speed of the train, it should be a simple matter to calculate the minimum speed of your sampling code.

This is very encouraging. I would need to launch another task (something like "read light sensor") along with some motor commands. Hmm. Worth a try considering your comments.

Thank you very much, I really appreciate your input!

Best regards,

Thorsten

Share this post


Link to post
Share on other sites

That is what I am really curious about - and I spent some time thinking about a solution: Masao's approach was simply "timing out" after the train stopped to start over. That would not work for me. Lets assume a train reads "go slow" and soon after "stop". The software running on my RCX trains does react with a delay function to requested speed changes - to reflect some realistic train behavior: A stop command should not result in "BangStopped" but slowly turn down power. The problem with that is of course that I don't really know where the train actually stops. When your came to a stop: How do they start again? Time-out, or do you tell them by the remote, or do they know where they are and tell them by some visual code? Since you said they do everything on their own, I doubt the remote.

Another question (sorry, but this is really good stuff you are doing ...): "Overriding with the remote", does that mean you are telling your train: "From now on, it is up to you" or do you use time-outs? (After x seconds, go back to auto ...)

I see what you mean. My engine implements the functionality to accelerate and break smoothly after a control input, but given the speed and size of the setup, the rate of change is to be quite fast in order for the change to be visible. I therefore have a quite high rate of change on my setup now. When the train reached the signal, it will start running again 10 seconds later, i.e. I use a timeout. However, I can override this using the remote control to tell it to stay there longer, or start earlier.

The automatic running toggle simply turns the effects of the read codes on or off. If the automatics are turned on, the channel change at speed is based on input from the code, but I can also control that using the remote control to change its speed or stop. If the automatics are turned off, it is only the remote control controlling the train.

If not using a timeout or user input, how are you proposing to get the train started again after it has stopped?

Share this post


Link to post
Share on other sites

I see what you mean. My engine implements the functionality to accelerate and break smoothly after a control input, but given the speed and size of the setup, the rate of change is to be quite fast in order for the change to be visible. I therefore have a quite high rate of change on my setup now. When the train reached the signal, it will start running again 10 seconds later, i.e. I use a timeout. However, I can override this using the remote control to tell it to stay there longer, or start earlier.

The automatic running toggle simply turns the effects of the read codes on or off. If the automatics are turned on, the channel change at speed is based on input from the code, but I can also control that using the remote control to change its speed or stop. If the automatics are turned off, it is only the remote control controlling the train.

If not using a timeout or user input, how are you proposing to get the train started again after it has stopped?

Hi Kolaf,

sorry for not responding earlier, I missed the page two thing (still learning).

Well, that's exactly the thing I am thinking about - and maybe other people as well(? Are you reading this, Masao?). Sorry for bumping this up, but as far as I am concerned, Kolaf's approach is very exciting.

I am thinking about

1) When you'd slow down the train in a controlled way, as you do, a command "slow down to minimum" should always result in at least some known average range, where the train has reached final minimum speed.

2) Then a "Full stop" command appropriately positioned on the track should result in a rather "narrow position range" of the train.

3) Use a second light sensor facing forward (or where ever), which is looking for some bright light, coded of course. I'd propose a PF LED set as signal.

4) Shine the code PF LED at the train.

This way, a "program" could take care of multiple train control. (I know, I know, why on Earth do you want to do that? Where is the fun? And you are right: There is no fun anymore when it works. BUT: Making it work is the fun!!! And we are, I guess, far away from that ...)

Anyway, do you think this could work?

Regards,

Thorsten

Share this post


Link to post
Share on other sites

Hi Kolaf,

sorry for not responding earlier, I missed the page two thing (still learning).

Well, that's exactly the thing I am thinking about - and maybe other people as well(? Are you reading this, Masao?). Sorry for bumping this up, but as far as I am concerned, Kolaf's approach is very exciting.

I am thinking about

1) When you'd slow down the train in a controlled way, as you do, a command "slow down to minimum" should always result in at least some known average range, where the train has reached final minimum speed.

2) Then a "Full stop" command appropriately positioned on the track should result in a rather "narrow position range" of the train.

This is difficult to achieve, at least the first one if you do not know the speed in advance. Alternatively you could have the deceleration as a function of speed so that the train will always spend the same amount the track decelerating.

3) Use a second light sensor facing forward (or where ever), which is looking for some bright light, coded of course. I'd propose a PF LED set as signal.

4) Shine the code PF LED at the train.

This is somewhat similar to what I was proposing with the stop signals, except that I use IR signals instead of regular light. You could say that if I disable the 10 second start timer, I would have basically what you describe except that I would manually start the train with the remote control.

This way, a "program" could take care of multiple train control. (I know, I know, why on Earth do you want to do that? Where is the fun? And you are right: There is no fun anymore when it works. BUT: Making it work is the fun!!! And we are, I guess, far away from that ...)

Anyway, do you think this could work?

Regards,

Thorsten

In order to have the automatic control the trains (something which I also am aiming at) you will also need to sometimes detect which tracks the train is on. For instance, take the setup I show in the video, where the station is on the side track. The control needs know whether the train stopped on the side track, always just passing by on the main track in order to determine whether it is safe to allow a second train in the opposite direction onto the piece of track that is shared. I will either use micro switches on the track or some cheap proximity detectors to achieve this.

Share this post


Link to post
Share on other sites

Elicend, please do not bump old topics (in this case, 3 years old) without good reason. If you need help, try reaching the original poster by PM (personal messenger) -- however I see they haven't been active on EB in a long time.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.