Cosmik42

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

Recommended Posts

This is an amazing program!  The more I play with it the more I remember the theme from Lord Of The Rings.  This could have been posted earlier; there's a lot of pages to read.  But I keep thinking:

One Ring to rule them all, One Ring to find them,
One Ring to bring them all, and in the darkness bind them.

I've been working slowly and have got some simple things to work, so thought I would share a simple example for other beginners.  It's an exercise with the LEGO 88009 Hub and the 88007 Color & Distance Sensor on port B

When the hub appears in BAP, click Configure and change the Trigger Cooldown to 100.  There's no "Apply" button; just close the dialog box.

Click Add Program.  Click Add Sequence.  Click Edit Code.

Note at the top of the Code Editor for Objects: it lists the hubs with a name and a number.  For beginner programmers, just use the Hub[n] in your program that corresponds to the name you gave your hub.

Enter this code in the editing area:

while (true)
{
    MainBoard.WriteLine(Hub[0].GetDistance("B").ToString());
    Wait(100);
}

Click the Run Code button.

Place an object in front of the distance sensor.  In the upper text area you should see the distance of that object from the sensor in centimeters.  It tops out at 15 centimeters.

Click File --> Save Current Proect As and give it a name like Distance Demo.

The only way I've found to stop the program within BAP is to click the "X" to the right of the Configure button.  That action shuts down the hub.  Pushing the start button on the hub reactivates the program and the distances are displayed again.  I want to use BAP at a convention and need to be able to isolate problems without interfering with other running programs so I'm going to be experimenting with that process.

Hope this helps.

Walt

Share this post


Link to post
Share on other sites
2 hours ago, TuxTown said:

 

I've gone through the whole tool. And through large portions of this thread. Not a clue as to why of how to set a default port ?! The train just rides, but doesn't change speed or stop for an occupied section.

 

Also still not clear what the power up colors are for. Al my hubs use green at te moment. What's the purpose of changing tot white or blue?

Color coding can help you differentiate between different hubs and states, for example - hub turns purple when it's about to go into a siding.

Or you can also use it as another flag, change color when a certain event triggers or a condition is met, and query the hub for it's color later on for some logic.

 

16 minutes ago, Walt White said:

.....

The only way I've found to stop the program within BAP is to click the "X" to the right of the Configure button.  That action shuts down the hub.  Pushing the start button on the hub reactivates the program and the distances are displayed again.  I want to use BAP at a convention and need to be able to isolate problems without interfering with other running programs so I'm going to be experimenting with that process.

Hope this helps.

Walt

Have you tried click the "Stop Listening" button at the top left of the program tab?

That will stop that branch.

Share this post


Link to post
Share on other sites
8 minutes ago, Nivst said:

Have you tried click the "Stop Listening" button at the top left of the program tab?

That will stop that branch.

That doesn't stop the code from running.  Same with the Stop All Hubs button.  It doesn't stop the code from running.  It looks like you have to click the "X" to the right of the Sequence #1 line to get the code to stop.  Lots of experimenting to do here!

Edited by Walt White
Clarify

Share this post


Link to post
Share on other sites
2 minutes ago, Walt White said:

That doesn't stop the code from running.  Same with the Stop All Hubs button.  It doesn't stop the code from running.  It looks like you have to click the "X" to the right of the Sequence #1 line to get the code to stop.  Lots of experimenting to do here!

Ah, yeah, you're right.

What's I've done in our last show was add a PoweredUp remote and assign some actions to several buttons, that way I didn't need to fiddle with the computer when I wanted small things to happen manually.

Share this post


Link to post
Share on other sites
11 hours ago, knotian said:

Can this app control both the sbrick and the control+ hubs?

If so, this sounds like a wonderful tool to operate an entire diorama with one program.

 

I'm not quite happy with names, Control+ is the LEGO-APP, the Hub calls itself (when starting) "technic Hub")

But yes, we're talking about the gray box with 4 Ports.....

BAP 1.5 works fine with it, I showed that on different exhibitions last year connecting:

SBrick
Smart Hub (2Port)
technic Hub (4Port)
Move Hub (from the Boost Set)

All at the same time.

Edited by Lok24

Share this post


Link to post
Share on other sites
11 hours ago, TuxTown said:

 

I've gone through the whole tool. And through large portions of this thread. Not a clue as to why of how to set a default port ?! The train just rides, but doesn't change speed or stop for an occupied section.

 

Good to hear the hubs colors are only cosmetic and can be used for flagging. I was wondering if it was connection related, but understand you can change the color without losing the hub connection. Nice.

 

Remains the problem "Could not set Motor Speed to 40 for Green Train because no default port are setup". Anyone seen this as well using the self-driving module? The module is not usable without this being clarified.

Edited by TuxTown

Share this post


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

 

Good to hear the hubs colors are only cosmetic and can be used for flagging. I was wondering if it was connection related, but understand you can change the color without losing the hub connection. Nice.

 

Remains the problem "Could not set Motor Speed to 40 for Green Train because no default port are setup". Anyone seen this as well using the self-driving module? The module is not usable without this being clarified.

Did you configure your the hub of your Train? and set engine to port A?

Share this post


Link to post
Share on other sites

Yes, i've two trains configured, motors on port A. The trains are working. But they do not slow down for switches or stop in case of next section occupied. Because of "no default port are setup". I also have to start them via the hub slider because of this.

Share this post


Link to post
Share on other sites

The author send me this answer:

 

"Have you set one of your motor as 'Train Motor' inside the configuration of your train? If not, please do. If yes, then go back there, select something else, and then select again the Train Motor setting a the port issue should be fixed. "

 

I have the train motor configured. Flipping sounds like a fix, I will try this evening (CEST).

 

 

Share this post


Link to post
Share on other sites

Loc24,

Looks like what I need. Is there any documentation or instructions?

I downloaded the zip file but could not find any.

Thanks for your effort,

Ed

PS What about my question about a pc with bluetooth dongle - will it work?

Edited by knotian

Share this post


Link to post
Share on other sites
On 1/7/2020 at 1:29 PM, TuxTown said:

"Have you set one of your motor as 'Train Motor' inside the configuration of your train? If not, please do. If yes, then go back there, select something else, and then select again the Train Motor setting a the port issue should be fixed. "

I have the train motor configured. Flipping sounds like a fix, I will try this evening (CEST).

 

 

This was indeed the fix for this problem (for the record).

 

Edited by TuxTown
attachment quota.

Share this post


Link to post
Share on other sites
13 hours ago, knotian said:

PS What about my question about a pc with bluetooth dongle - will it work?

I've seen people here and on the Facebook page say they're using dongles, either for PC's without or with an old/weak onboard BT card.

Share this post


Link to post
Share on other sites

Yes, for me that works brilliant (no built in BT on PC, no drivers for BT on Laptop)

Share this post


Link to post
Share on other sites

Was wondering about this; I'm using python/bleak on windows... in my first test I was able to see the hub, then connect, then list it's available services.  A few moments later, I was able to see the hub, but then couldn't connect.

It doesn't seem like I should need a dongle if I was able to connect a couple of times before having problems.

Share this post


Link to post
Share on other sites
6 hours ago, fred67 said:

It doesn't seem like I should need a dongle if I was able to connect a couple of times before having problems.

No, certainly not. Which version of Windows are you running?

You may want to try out (the free) "Bluetooth LE Explorer" form the Microsoft Store (https://www.microsoft.com/en-us/p/bluetooth-le-explorer/9n0ztkf1qd98?activetab=pivot:overviewtab

This allows you to test your systems BLE capabilities as well as interrogating LEGO BLE devices.

Best
Thorsten

Share this post


Link to post
Share on other sites

@Toastie Thanks, I'll give it a whirl.  I have Windows 10 Home 1903; should be pretty up to date.

 

Share this post


Link to post
Share on other sites
On 1/5/2020 at 8:47 PM, TuxTown said:

Exception while connecting Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at LegoTrainProject.MainBoard.<TryToConnect>d__18.MoveNext() in C:\Users\Cosmik\Dropbox (Lucky Duck Games)\Private\LuckyDuck\The Lego Project\Source\LTP.Desktop\Main UI\MainBoard.cs:line 186
New device found - Mac Address 90842B1012B6
Error opening communication:Unreachable
New device found - Mac Address 90842B1012B6

I' ve also got issues with a WeDo Hub endlessly trying to reconnect hanging the program.  I'll try another laptop now.

 

For the record: I fixed this on my original laptop. For some reasons things went wrong when using more than 2 hubs. This was related to the bluetooth driver version. It is HP Elitebook laptop and had 20.20.0.5 version the driver. After upgrading to 20.70.0.4 of the intel wireless bluetooth driver connection things were working oke.

Share this post


Link to post
Share on other sites

 

I'm still struggling to use the self-driving module. Using a single train I even can't get consistent behaviour. I see in the color and distance debug log that all my sensors are working fine, every time. However the sensors are not always triggering an event. Now why is that? Anyone using the self-driving module without issues like this?

What is also strange is that when starting a train in a self driving program, it logs cleared section before passing the end-sensor. Like this:

All Sensor Events for Self-Driving are active.
Anti-Collision is active over 6 sections!
Groene Trein self-driving path is set to Buitenom! Resuming from Section 0
Groene Trein - Switch already in position!
Groene Trein - Allowed to move to Section 1
Groene Trein has cleared section Section 0

-> We have not yet passed sensor end-section 0 !

 

Share this post


Link to post
Share on other sites
3 hours ago, TuxTown said:

 

I'm still struggling to use the self-driving module. Using a single train I even can't get consistent behaviour. I see in the color and distance debug log that all my sensors are working fine, every time. However the sensors are not always triggering an event. Now why is that? Anyone using the self-driving module without issues like this?

What is also strange is that when starting a train in a self driving program, it logs cleared section before passing the end-sensor. Like this:

All Sensor Events for Self-Driving are active.
Anti-Collision is active over 6 sections!
Groene Trein self-driving path is set to Buitenom! Resuming from Section 0
Groene Trein - Switch already in position!
Groene Trein - Allowed to move to Section 1
Groene Trein has cleared section Section 0

-> We have not yet passed sensor end-section 0 !

 

Can you show your layout?

Share this post


Link to post
Share on other sites
2 hours ago, Nivst said:

Can you show your layout?

Sure, here it is. Don' t know if or how one can add arrows or own objects to BlueBrick yet, so I hope it is clear.  Section 5 and 6 are not in use yet. I'm trying outer loops clockwise 0,1,4,0,1,4, for example. In the logging given above, the train started halfway section 0. HS means a Hub, terminating a section. It has the switch motor on A and the end-section sensor on B.

 

UVblqaU.png

WxK8mfG.png

 

Edited by TuxTown

Share this post


Link to post
Share on other sites

How much time does it take for the train to drive between end sections sensors? And what is your sensor cool down period. Might be in there. 

Share this post


Link to post
Share on other sites

Yes, I've been experimenting with this yesterday, as you wrote somewhere you changed this to 100ms. Didn´ t make a difference it seemed. Not sure what this cooldown period involves. I guessed it only means the time before that same trigger can fire again? In that case it shouldn' t effect a trigger for the next sensor.

 

In any case does this not explain why it logs "Groene Trein has cleared section Section 0" before this train leaves section 0.

Edited by TuxTown

Share this post


Link to post
Share on other sites

I thought lets try it one more time tonight. However now I didn 't succeed in having all hubs keep a stable connection. For some reason I had the situation back from before the bluetooth driver upgrade that one hub is disconnecting all the time. Swapping a hub moves the problem. Very frustrating that after a few weeks I still didn' t have a ride without issues. Not sure whether the connection problems tonight are due to the specific laptop or due to buggy BAP software. I also didn't hear on this forum from anyone who managed to use the self-driving module without problems with 5 to 10 hubs. Does anybody use it succesfully?

The fact that this is closed source and the author is also not reading along anymore, makes troubleshooting also a bit hard.

The coming few weeks I have almost no time to play with the gear, anyway.  The first week of februari I'll try the other laptop again.

Share this post


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

I thought lets try it one more time tonight. However now I didn 't succeed in having all hubs keep a stable connection. For some reason I had the situation back from before the bluetooth driver upgrade that one hub is disconnecting all the time. Swapping a hub moves the problem. Very frustrating that after a few weeks I still didn' t have a ride without issues. Not sure whether the connection problems tonight are due to the specific laptop or due to buggy BAP software. I also didn't hear on this forum from anyone who managed to use the self-driving module without problems with 5 to 10 hubs. Does anybody use it succesfully?

The fact that this is closed source and the author is also not reading along anymore, makes troubleshooting also a bit hard.

The coming few weeks I have almost no time to play with the gear, anyway.  The first week of februari I'll try the other laptop again.

There is an active BAP group on FB, including the author. You can check there if you need more help. I believe the group is called "The Brick Automation Project".

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.