Cosmik42

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

Recommended Posts

6 hours ago, Lok24 said:

Hi @nuno2500,

sorry, my fault....

use:


Hub[0].SetLEDColor(Port.Colors.BLUE);
Hub[1].SetLEDColor(Port.Colors.LBLUE);

And here are the colors:

 

Thank you so much. That is great. Is there any list of all the BAP commands. I call command to something like: "Hub[0].Stop("A);". I need to Invert motors using "Edit Code".  Thanks once again.

Edited by nuno2500
Forget something important

Share this post


Link to post
Share on other sites
24 minutes ago, nuno2500 said:

Thank you so much. That is great. Is there any list of all the BAP commands. I call command to something like: "Hub[0].Stop("A);". I need to Invert motors using "Edit Code".  Thanks once again.

Take a loot at the help menu, there's at least a partial list there.

 

Share this post


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

Take a loot at the help menu, there's at least a partial list there.

 

Yes, i have been reading those topics but i can´t find an invert motor command :(

Share this post


Link to post
Share on other sites

Hi,

invert a second motor regarding the first?

Hub[0]. setmotorspeed("B", Hub[0]. getspeed("A")*-1)

"invert" relative to - what?

 

 

 

 

Share this post


Link to post
Share on other sites
On 12/3/2019 at 10:48 AM, Lok24 said:

Hi,

invert a second motor regarding the first?

Hub[0]. setmotorspeed("B", Hub[0]. getspeed("A")*-1)

"invert" relative to - what?

 

 

 

 

Hello Lok24. Thanks again for your patience :) I need to do this: stop (or wait) a train motor and reverse the motor. There is the "INVERT" option but does not stops before invert the motion (motor). It is a straight and single railroad so i need to go and go back but i want the train to stop at the trainstations on both ends. I have only one motor.

Edited by nuno2500
Forget something important

Share this post


Link to post
Share on other sites

Hi,

The invert option can have a drawback: the train passes the coloured plate, and when it comes back it inverts again. So I if you use setmotorspeed or equivalent, it will always go the right way.

 

Share this post


Link to post
Share on other sites
1 minute ago, lego3057 said:

Hi,

The invert option can have a drawback: the train passes the coloured plate, and when it comes back it inverts again. So I if you use setmotorspeed or equivalent, it will always go the right way.

 

You can get around that by using the hub states as flags.

Share this post


Link to post
Share on other sites

Ah, I see! A shuttle train!

in general SetMotorSpeed(50) is forward, and SetMotorSpeed(-50)  is backwards

Here is what you need if you have a sensor in the engine, you need two  events (detecting white and red ie.)

 

if (Hub[0].State[0] == 0)  
{
    Hub[0].State[0] = 1;       
    Hub[0].RampMotorSpeed("A",0,1000);
    Wait(3000);
    Hub[0].RampMotorSpeed("A",10,50,1000);
}


if (Hub[0].State[0] == 1)
{
    Hub[0].State[0] = 0;
    Hub[0].RampMotorSpeed("A",0,1000);
    Wait(3000);
    Hub[0].RampMotorSpeed("A",-10,-50,1000);
}

or without sensor, by time (3secs to run)

while (True)
{
    Hub[0].SetMotorSpeed("A",50);
    Wait(3000);
    Hub[0].Stop("A");
    Wait(1000);
    Hub[0].SetMotorSpeed("A",-50);
    Wait(3000);
    Hub[0].Stop("A");
    Wait(1000);
}

 

Edited by Lok24

Share this post


Link to post
Share on other sites

Eureka :) Eureka :) Thanks for all the help. I found a very easy way to do it. Just have so set up "trigger cooldown" on Hub Editor, higher than the time that take to get na unwanted sensor event.

Here is my code (trigger cooldown=20000):



if(Hub[0].GetSpeed("A")>0)

{Hub[0].Stop("A");

Wait(15000);

Hub[0].SetMotorSpeed("A",-75);}

else if(Hub[0].GetSpeed("A")<0)

{Hub[0].Stop("A");

Wait(15000);

Hub[0].SetMotorSpeed("A",75);}

Edited by nuno2500
missing text

Share this post


Link to post
Share on other sites

Does anyone know if it is possible (and how!) to access the rotation encoder of Control+ motors? I'm trying to create a movement sequence for the Liebherr...

Thanks in advance!

Share this post


Link to post
Share on other sites

Hello. How get raw value from color sensor? trigger value 5 is not suitable. I calculated the values for determining the blue and black color that I can set in the Powered Up application, but this is not possible here. 

Using C# reflection I find event "ColorTriggered" on Hub type, but it send result color. I find private field Characteristic - Windows.Devices.Bluetooth.GenericAttributeProfile.GattCharacteristic has event "ValueChanged", if i got it right here can get raw color value, but subscribe to this event imposible becouse dont using Windows.Devices namespace.

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.