Cosmik42

[Automation] Control all your Powered Up & Power Function (SBrick) devices with a single software!

Recommended Posts

Hi everyone,

I am new here and loved reading many of your posts!
About a month ago, I decided to try to connect to my newly acquired Powered Up train via bluetooth on my own computer.
The goal was to be able to control all of my train at once, and better, program complex behaviors.

The forum was a huge source of inspiration, but if you are not a programer, just technical chat.
What I set myself to achieve is to create a program that would be user-friendly and capable of connecting to any number of Powered Up & SBrick devices!

1 month later, I am happy to report that I have built a complete custom solution to achieve just that with "The Lego Train Project".
Here is a video that shows you an example of how the software works:

Here is a screenshot of the software (Beta V0.6):

51038275_2446661958894289_44816780283923

With it you can:

 - Control as many hubs as you own at the same time, creating a centralize solution for your trains, switches and other sensors/motors.
 - Read color from color sensor mounted on each trains
 - Create (color or distance) sensor related events that can activate actions on any other hubs of the network
 - Create C# sequences that compile and run dynamicly!

I am building a fairly complex train automation project with it for my own layout, but would love if other would be interested to test it
 

Edit - V0.3 is out!

Major update with this version:
- New UI
- Improved Hub Detection
- Color In C# Editor
- Light Management
 
 
Edit - V0.3.1 is out - 01/08/19

Minor update includes:
- Code editor improvement
- Fix Hub not showing up on certain configurations
- Add 'State' variable to each hubs
 
 
Edit - V0.4 is out - 01/14/19

Major update includes:
- SBrick support
- Global code editor
 
 
Edit - V0.5 is out - 01/14/19

Major update includes:
- Full support of SBrick Plus and PF Sensors.
- Introducting an Anti-Collision system that works with simple distance detectors
- Bug fix: Code was executed twice on sensor event
- Bug fix: Better handling of faulty device connection
 
V0.6 is out - 01/20/19
 
- Self-Driving Trains!
- New UI
- More Robust Hub Detection
- Add Port Selection for Sensor Events
- Bug Fixes
 
 
Below is a demonstration of the new (V0.6) self-driving module!
 
 

Note: The app works only under Windows 10 and requires a Bluetooth 4.0 Connection! Sorry for the current limitation!

Edited by Cosmik42
Adding V0.6 details

Share this post


Link to post
Share on other sites
31 minutes ago, Cosmik42 said:

switches

How do you plan on automating those?

 

31 minutes ago, Cosmik42 said:

color or distance

How does the distance "sensing" works?

Looks so great anyway. What I see in the video is like...a room of my dreams ;D

Share this post


Link to post
Share on other sites
Just now, Bartosz said:

How do you plan on automating those?

 

How does the distance "sensing" works?

Looks so great anyway. What I see in the video is like...a room of my dreams ;D

Switches are nothing more than another Hub with a motor that automatize your switch.
Look at this video for an example:

https://www.facebook.com/groups/18854918656/permalink/10156184440253657/

Color sensing works with like this:

48425537_2428260980734387_55062453115315

Distance scenario is as follow: Put a distance sensor next to the track (not on the train) and when a train passes in front of it, it triggers and allows you to do activate something else.

 

Share this post


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

Distance scenario is as follow: Put a distance sensor next to the track (not on the train) and when a train passes in front of it, it triggers and allows you to do activate something else

Ah right, somehow I thought you mean distance made by train...

Share this post


Link to post
Share on other sites

Welcome to EB, @Cosmik42!

Wow, you have composed a wonderful piece of software!!! This is what I have been looking for quite some time now!

And thank you very much for sharing. It must have been an awful lot of work.

I tried to download the zip file, but that one appears to be empty. Is it me? What am I doing wrong?

All the best,
Thorsten  

Share this post


Link to post
Share on other sites

Thanks Toastie and nice to meet you!

Oh goodness, this is my bad!

Here is a working link: https://www.dropbox.com/sh/ux2r02l545zfyka/AAAbeRZMX5VTOTuQecHJLXewa?dl=1

It is not the latest version, but as I am not home this is the shortest path to giving you a working build! Will provide an updated link soon.

Thanks for the kind words. I hope this software is useful to you!

Vincent.

Share this post


Link to post
Share on other sites

@Cosmik42

First thank you a lot for your effort you share with the community. I am really happy, you make a real gift for us!

Your software is really promising: Installation was easy, just unpacking the zip file to a directory and starting the programm. Both BOOST hub and train hub connect to the software immediately, but before this it is neccesary at the moment to restart the program. Switching off a hub by pressing the button for a while and restarting it does not work.

At the moment I am not so familiar with your user interface but it seem easy to use after little training.

The BOOST hub works fine with it. The internal motors and the external motor from the BOOSt set work flawless. On the first try he lights are recognized correctly but they do not react to any command. Instead there is a message like "Message unparsed 0x0a recieved". Ok, the train motor is not recognized by the first try but it is on the second together with the lights which are recognized as external motor on the second attempt. Then the train motor works together with the BOOST hub too but the software produced the unpased message in parallel. For me only a sign that there is still a lot of development work to be done.

And I tested the distance/color sensor. Yeah, this device works perfect with the BOOST hub.

My eldest train hub does not cooperate with this version. It is found by the software nealy immediately, but there are three instant error messages: Port 50, 59 and 60 not found. The result is no reaction neither for the train motor nor for the lights. Ok, explainable. One reason can be a buggy firmware on my train hub. It was updated once in november but afterwards LEGO introduced a new app which does not cooperate with my elder smartphone any more. At the moment I have no opportunity to update any firmware on my hubs. I have to buy a new one :(

Surprisingly the color/distance sensor works with the first train hub.

Short before christmas I bought three more hubs with probably another firmware version (I do not know which since my smartphone does not cooperate with the official LEGO app any more): At first attept the software and the hub firmware crashed but the second attempt was successfull: Both the train motor and the lights are recognized correct and do was they should despite a stream of violett messages ;-) The color/distance sensor works too.

Summary: I am deeply impressed by your intention to share your strenious work with our train community! I hope it is ok for you reporting the experieces? I am really happy with your software even at this early state: The user interface is wonderful straight forward and really easy to learn (Congratulations!) and it works together with the BOOST hub and my three newer train hubs. What do we want more?

Best wishes for the new year!

 

 

 

Edited by Giottist
Spelling, more tests

Share this post


Link to post
Share on other sites

@Giottist

Thank you so much for the kind words and complete report! I very much appreciate it. This kind of bug report and feedback is what I was hoping for sharing my work here so thank you!

I have an idea why your old train isn't working. I will work on it and provide a new build!

Let me know once you start digging in the events and procedures!

Also I do not own lights so I never tested them. Will buy a pair now and adapt the software to make them compatible with them!

Share this post


Link to post
Share on other sites
6 minutes ago, coinoperator said:

WOW
Now I start dreaming of such a program to control big cranes, bulldozers etc.
 

You can use it for such purpose too! All you need is using Bluetooth enabled hubs to control them.

Share this post


Link to post
Share on other sites
27 minutes ago, Dragunov2 said:

Would be great if u can make Android software for this :D

I thought about it. If usage of this really takes off I might take on the endeavor.

Share this post


Link to post
Share on other sites
1 hour ago, Cosmik42 said:

Let me know once you start digging in the events and procedures!

Also I do not own lights so I never tested them. Will buy a pair now and adapt the software to make them compatible with them!

Of course I will do!

I can add some information: The old, but once updated train hub is recognized as a BOOST hub, not as a train hub. The other train hubs are found as train hubs. Unfortunately at the moment I have no method to request the firmware version. Perhaps the just published docu from LEGO, JopieK or Treczoks know more ...

I have to confess, I have no medium motors as in the batman chunk. It seems they are identical to the WeDo 2.0 medium motors, but it is rather expensive to check it ... On the other hand I need some since a lot of my MOCs run with medium motors (or even L motors which aren't available yet for PUP).

The encoder motor from BOOST runs fine with the BOOST hub (as expected and tested) but shows no reaction anyway with the train hub. It is known that the train stuff tells the hub what is connected only by voltage levels on wire 5 and 6 but I do not know how the BOOST angle encoder tells his data to the BOOST hub.

Share this post


Link to post
Share on other sites
Just now, Giottist said:

I can add some information: The old, but once updated train hub is recognized as a BOOST hub, not as a train hub. 

This is extremely useful and clearly the heart of the issue as the protocol is different on Boost vs Train hub.

My method of identification is based on the name of the hub but there are better Technics for that. If I can't automatically detect the right type of hub, I could offer an option to override it manually.

Share this post


Link to post
Share on other sites
4 hours ago, Giottist said:

@Cosmik42

First thank you a lot for your effort you share with the community. I am really happy, you make a real gift for us!

 

4 hours ago, Giottist said:

Summary: I am deeply impressed by your intention to share your strenious work with our train community! I hope it is ok for you reporting the experieces? I am really happy with your software even at this early state: The user interface is wonderful straight forward and really easy to learn (Congratulations!) and it works together with the BOOST hub and my three newer train hubs. What do we want more?

@Cosmik42

I fully second what @Giottist has summed up. This is a wonderful piece of work. I already said that even without running the program, just judged from picture showing the UI. I unzipped the file, ran the program, turned on a PuP hub (the Hub No.4 thing) - and it worked like a charm. The acceleration and deceleration buttons are superb, as everything else is.

I am very happy to test this software in every regard. On the picture in the first post showing the UI, there are sliders for setting the motor power, I believe. I like these very much. Are they hidden somewhere or did you not like them anymore?

Also, you are saying that one can "Create C# sequences that compiled and run dynamicly!". Would you mind elaborating a bit on that?

Another question (excuse me, but I am totally overexcited …):

Spoiler

I am running a fairly complex VB6 program (from within VB6 that I migrated successfully from Win98 to Win10/64 bit with >a lot< of help from various places on the internet) to control my layout. There are RCX, RC, and PF controlled trains, all equipped with simple RF half duplex transceivers alleviating the IR line of sight limitation; same for light-, switch point- and bridge control. The layout is also fairly complex (about 30 switch points, 12 trains etc.). So far I could manage to run everything from my laptop - with the help of an NXT brick; that one translates my LEGO IR messages to RC and PF code. With the arrival of all that Bluetooth LE stuff, I got completely lost. 

Do you see any chance that I may "send" any kind of "messages" from my own control program (see spoiler, if you like) to you program, i.e., have your program taking care of all the new BLP stuff upon receiving and recognizing a message consisting of e.g. two bytes: first byte "ID" (for a train, switch point controller etc.) and second byte "data" (motor power, On/Off, etc.)?       

In any case: I am very, very happy. And all this still in 2018!!!

All the best and have a very happy New Year!

Thorsten      

Share this post


Link to post
Share on other sites

@Toastie, thank you for the kind words!

Quote

 On the picture in the first post showing the UI

This is coming up. Will be in the next version I share, probably around January 5th once I am back home and can test a lot of recent upgrades to the software

Quote

Also, you are saying that one can "Create C# sequences that compiled and run dynamicly!". Would you mind elaborating a bit on that?

You can create very complex scenario by programming directly in C#.

To do so:

 - Click 'Add a Program' (bottom right button)
 - Click 'Add a New Sequence'
 - Click 'Edit Code' 
 - It comes with some exemples of code. Basically every hub that you will plug to this project will be accessible. You can then call functions on them like SetMotorSpeed, Stop, Wait, etc.
 - Click 'Test Code' to check if it compiles and run as intended.
 - Then Close. You can then run that sequence in the future (if you save your project) by clicking 'Start'.

Here is an exemple of such code from my own layout:

if (!Hub[0].IsInAction && Hub[1].Speed == 0 && Hub[2].Speed == 0)
{
   Hub[0].IsInAction = true;

   // Activate Switch 1 (Double Cross) To The Right
   Hub[3].ActivateSwitchToRight("C");

   // Start Yellow Train
   Hub[0].SetMotorSpeed("A", 60);

   // Then Activate Switch 2 To The Left (To Welcome Yellow Train Back)
   Hub[4].ActivateSwitchToLeft("C");

   // Wait for the train to start and clear the way
   Hub[0].Wait(2000);

   // Activate Switch 1 (Double Cross) To The Left (So that red train takes the large route)
   Hub[3].ActivateSwitchToLeft("C");

   // Start Red Train
   Hub[1].SetMotorSpeed("A", 60);   

   // Release the lock
   Hub[0].IsInAction = false;
}            
Quote

Do you see any chance that I may "send" any kind of "messages" from my own control program to your program?

I guess this is possible, but it would require quite some work and I would rather not commit to it just yet.
Maybe we can take this discussion to PM as it will require a lot of synchronization.

Hope all of this helps!

Edited by Cosmik42

Share this post


Link to post
Share on other sites
1 hour ago, Cosmik42 said:

Hope all of this helps!

It helps a million!

Thank you very much again. I'll certainly PM you, when you don't mind.

We're off now to a New Years party. All the best.

Happy New Year - to all the wonderful EB members and all your families!

Sincerely yours
Thorsten

 

Share this post


Link to post
Share on other sites
Posted (edited)
34 minutes ago, mattmarsden said:

Would there be any way to get this to talk to the 4DBrix switch motors so this could control them as well?

I will need to buy some. How do you activate them today? I will need the protocol for this to be a reality. Will try to find them in Europe.

Edited by Cosmik42

Share this post


Link to post
Share on other sites

Theyve got a european Bricklink store and I believe the protocol is available on their website. Really appreciate your work. Would it be possible down the line to have a customisable GUI?

Share this post


Link to post
Share on other sites
Just now, mattmarsden said:

Would it be possible down the line to have a customisable GUI?

Sure! UI is still very rough. If you have any valuable inputs as of how this should look like, I take any feedback!

Share this post


Link to post
Share on other sites
43 minutes ago, mattmarsden said:

By the way - will this still be limited to using 5 hubs or can it control as many as you like?

If this code is ever ported to mobile, 7 I believe is what most Android phones can achieve. On my PC I believe I can connect up to 15 without issues as long as you have a Bluetooth 4.1

Share this post


Link to post
Share on other sites

That is really cool! I did not read all of the comments, so skip this one if it has already been answered, but if not, does the software have the ability to simultaneously turn on both ports on a hub in opposite directions so that a engine can have two motors facing in opposite directions?

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.