Cosmik42

Lego Train - Full Layout Automation - A Break Down

Recommended Posts

Hi everyone,

I just released the V0.6 of The Lego Train Project which delivers the ultimate goal I set to myself: build a fully automated driving system for lego trains.
First you can watch this 3 minutes video to understand the high-level concept and see it in action:


Download V0.6 here: https://www.eurobricks.com/forum/index.php?/forums/topic/169318-automation-control-all-your-powered-up-power-function-sbrick-devices-with-a-single-software/&page=1

#1 Map out your section

The first thing that you need to do is to define your Sections.
Typically you need to define a new section everytime you have a Switch. 
Here is what I did on this simplified version of my layout:

36d38e62a230c7235f9013ecefd3ef622f663980


#2 Report your sections to the software. Note this is a one time setup!

8022b2894b543fcad3468ae4589f0935ac36d447

Note about Switches:
 - I use a very simple system with a motor like this one to motorize my switches

4ac4211c0be1140d8bd53046c476f74763a5a288

 You need to define that a Motor is a Switch for it to show up in the Switch drop-downs.

8d9bd4daff850f918a26a3d32a8bdcf389a3398b

 

Note about Sensors:
 - In this scenario I only use WeDo 2.0 distance detectors. They are easy to buy and cheaper than the Boost Color-Distance detector.

c494f6959c5b8c39ed718d292d19e245350a276c

Note:  WeDo 2.0 & Boost Sensor should show up automatically. SBrick Sensor have to be defined manually.

# 3 Define Train's Paths 

Once your network is setup, you need to create the different scenarios your trains will take!

79ef6c1b03393307077486c86538c00ac2437b45

 

#4 Some Important Verifications Before Starting:
 - 
Make sure each Train is attached to the section it is physically at. This is the only way for us to know constantly where is a train. A wrong section on start will break the automation.
 - Select a path which contains the section where this train is. Otherwise the automation won't start.

66a3903c0eb25f87159e3a88a2d1d5f856fc8651

#5 Enjoy!

And that's all Folks!
Hope you enjoy it. It was an incredible challenge to put it together and I hope it will be used beyond my own layout :)

Cheers!
Vincent.

Edited by Cosmik42

Share this post


Link to post
Share on other sites

I love what you have done here. It obviously works well and is easy to use. I am working on something similar but using a PICAXE for the train detection (using Light Dependent Resistor) and for the point control, all reporting back to an Arduino for train control. There is an Arduino library for the infra-red LEGO controller. The Arduino will control the movement of the trains and will command the PICAXE where to set the points, and it will receive location information back from the PICAXE to make decisions on next moves.

Do you think it would be possible to port the Bluetooth Hub code into an Arduino library? Then I can use all my trains not just the infra-red ones. What do you think?

Share this post


Link to post
Share on other sites
8 hours ago, SandraNZ said:

Do you think it would be possible to port the Bluetooth Hub code into an Arduino library?

Hi Sandra! It sounds like you are working on some great automation project too. I don't own any Arduino, so I can't help you there, but my own implementation was inspired by the work of Nathan who shared node.js library. Very clean and readable implementation that should help you get the protocol right! 

Share this post


Link to post
Share on other sites
On 1/21/2019 at 2:29 AM, SandraNZ said:

I love what you have done here. It obviously works well and is easy to use. I am working on something similar but using a PICAXE for the train detection (using Light Dependent Resistor) and for the point control, all reporting back to an Arduino for train control. There is an Arduino library for the infra-red LEGO controller. The Arduino will control the movement of the trains and will command the PICAXE where to set the points, and it will receive location information back from the PICAXE to make decisions on next moves.

Do you think it would be possible to port the Bluetooth Hub code into an Arduino library? Then I can use all my trains not just the infra-red ones. What do you think?

Hi Sandra, I'm working at the same topic (ok, ok, occasional ...). Cosmik42 was so nice and enabled the C# COM Port interface in the BAP software. I'm thinking about a comparable problem to retrieve information about which indiviual train occupies which sector or a track sector is free. From time to time I think at RFID identification or barcodes beneth my locos. Arduinos can read out the sector sensors and send the information to the BAP software via the COM interface. I prefer the Arduino Mega due to its large number of IO ports.

At the moment I've just tested the communication between Arduino and BAP. And not to forget to mention I got real help from Cosmik42 by PM. Thanks a lot!

Share this post


Link to post
Share on other sites

I've to add the code for the BAP editor:

Just write:

 

SerialPort ArduinoPort = new SerialPort( "Com3", 9600, Parity.None, 8, StopBits.One); // COM3 is the COM port for the connected Arduino in my computer, please look up your port

ArduinoPort.Open();

// Do some communication  like in the following sample:

string message = ArduinoPort.ReadLine();

MainBoard.WriteLine(message); // The input will be displayed in the message window in the BAP shell.

ArduinoPort.Close();

MainBoard.WriteLine( ""); // to print a line feed

 

Do not declare any interface by yourself in the BAP editor, Cosmik42 did for us in the BAP code.

 

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.