S2Bot lego boost: details on turn motor on for secs

laurent_c

Member
Hi,

I am using S2Bot for Lego Boost.
I use the "turn motor on for <s> secs" command (motorOnFor) in Scratch2.

According to Lego specification https://lego.github.io/lego-ble-wireless-protocol-docs/index.html#output-sub-command-startspeedfortime-time-speed-maxpower-endstate-useprofile-0x09
this command has 'speed' and 'power' parameters:
StartSpeedForTime (Time, Speed, MaxPower, EndState, UseProfile)

Question: what is the value for speed and power when the "turn motor on for <s> secs" command is used in Scratch2?

The s2bot.pdf document seems to mix-up the two parameters: (page 18/38)
> 6.5 Controlling motors
> For simple applications you can use the motor commands to switch individual motors on and off for various amounts of time.
> Power can be set between 0 and 100 to adjust the motor speed.

Thank you.
Best Regards,
Laurent
 

hippy

Technical Support
Staff member
My understanding is that S2Bot turns the motor on, delays, then turns the motor off, rather than uses any other commands, so motor speed / power is controlled by whatever the commands are for setting that, 0 to 100.
 

laurent_c

Member
It seems (according to Lego spec on lego.github.io) that 'speed' and 'power' are unrelated parameters.
Hence there are 2 ways to turns the motor on:
(1) StartSpeed (Speed, MaxPower, UseProfile) or StartSpeed (Speed1, Speed2, MaxPower, UseProfile) or StartSpeedForTime (Time, Speed, MaxPower, EndState, UseProfile)
(2) StartPower (Power) or StartPower (Power1, Power2)

The first category needs both 'speed' and 'power'.
Do you set a default value for one or the other in Scratch2 S2Bot?
 

hippy

Technical Support
Staff member
Do you set a default value for one or the other in Scratch2 S2Bot?
I would guess 100%. But the important thing is that we don't call every Lego API to action what the Scratch program does. Just because the Lego firmware has a particular API does not mean that Scratch with S2Bot uses it.

As I understand it one uses the Scratch "Set Power" command to set the power / speed desired, then one would use "Turn Motor On", "Wait For Some Seconds", "Turn Motor Off" to move for a number of seconds at that speed.

"Turn Motor On For Some Seconds", is simply "On, Wait, Off" combined.

So we implement the "Set Power", "Turn Motor On" and "Turn Motor Off" API, and implement a timed delay, so we can achieve "Turn Motor On For Some Seconds" without ever using other Lego API's.

I suppose the key thing is that what Scratch sends to S2Bot is not necessarily the same as what S2Bot will send to Lego hardware.
 

hippy

Technical Support
Staff member
According to Lego specification https://lego.github.io/lego-ble-wireless-protocol-docs/index.html#output-sub-command-startspeedfortime-time-speed-maxpower-endstate-useprofile-0x09
this command has 'speed' and 'power' parameters:
StartSpeedForTime (Time, Speed, MaxPower, EndState, UseProfile)
The use of 'Speed' and 'Power' is I recall rather confusing; are effectively synonymous. Speed being -100% to +100% with Power being 0%-100% which determines what the Actual Speed and direction is.

Actual Speed = Speed/100 * MaxPower/100 * 100

It's much like a resistive pot driven by another, like a channel volume fader on an audio mixing desk with a master volume fader.
Code:
+100V ---.
        .|. "Speed"
        | |
        | |<----.
        |_|    .|. "MaxPower"
         |     | |
         |     | |<----O Actual Speed
         |     |_|
         |      |
   0V ---|------^------O 0V
         |
-100V ---'
I believe we set MaxPower to 100% so actual speed is controlled solely by Speed. Or maybe it's the other way round but the end result is the same. So I would guess we send -

StartSpeed (Speed, MaxPower, UseProfile)

StartSpeed (1 to 100, 100, None) - Forward
StartSpeed (0, 100, None) - Stopped
StartSpeed (-1 to -100, 100, None) - Reverse

Or

StartSpeed (100, 1 to 100, None) - Forward
StartSpeed (any, 0, None) - Stopped
StartSpeed (-100, 1 to 100, None) - Reverse

I am not exactly sure what actual values represent -100 to +100.
 

Technical

Technical Support
Staff member
All the official lego apps always use 0x64 (100 decimal) for maxPower regardless, so so do we! You then set the 'speed' and 'direction' by using a number between -100 and +100
 
Top