Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Motor Blocks #17

Open
Amerlander opened this issue Apr 29, 2024 · 12 comments
Open

Add Motor Blocks #17

Amerlander opened this issue Apr 29, 2024 · 12 comments

Comments

@Amerlander
Copy link

We plan to have motor blocks for the Motor Board and for the Motion kit.

Current implementation in HEX File:

  • We receive CMD_MOTOR
  • Decide to control the Motorboard or Motion Kit by data[0]
  • Receive motor speed in data[1] and data[2]
if(command == MbitMoreCommand::CMD_MOTOR) {
    const int motorCommand = data[0] & 0b11111;
    // data[1] = Motor 1
    // data[2] = Motor 2
    if (motorCommand == MbitMoreMotorCommand::SET_M_SPEED) {
        // TODO
    } else if (motorCommand == MbitMoreMotorCommand::SET_MOTIONKIT_SPEED) {
        // TODO
    }
  }
declare const enum MbitMoreCommand
{
    CMD_MOTOR = 0x06,
}


declare const enum MbitMoreMotorCommand
{
    SET_M_SPEED = 0x01,
    SET_MOTIONKIT_SPEED = 0x02,
}
@Amerlander
Copy link
Author

@joernalraun can you specify what blocks we need?

@joernalraun
Copy link

joernalraun commented Apr 29, 2024

Views of motor block:
Bildschirmfoto 2024-04-29 um 17 36 34
Bildschirmfoto 2024-04-29 um 17 40 32

Bildschirmfoto 2024-04-29 um 17 36 28

Views of MotionKit block (should show MotionKit instead of Motor):
Bildschirmfoto 2024-04-29 um 17 38 25
Bildschirmfoto 2024-04-29 um 17 38 20
Bildschirmfoto 2024-04-29 um 17 38 08
Bildschirmfoto 2024-04-29 um 17 38 00

@joernalraun
Copy link

joernalraun commented Apr 29, 2024

@haithembelhaj as we cannot offer the MakeCode user add-on option for the labels, would it be possible to also add the previous two blocks at the end of all Calliope mini blocks for motors/cars? When everything else is done and there is still time/fun to do so? ;)

@Amerlander
Copy link
Author

Amerlander commented May 2, 2024

@haithembelhaj We created a HEX file today for the Motors: calliope-edu/pxt-calliope@0aa9368

Calliope-More-Motors.zip
(C17 is also included now)

It listens on data[0] >> 5 == MbitMoreCommand::CMD_MOTOR | 0x06

It then awaits in data[0] & 0b11111 either of:

  • SET_M0 | 0x01 // First Motor
  • SET_M1 | 0x02 // Second Motor
  • SET_M0_M1 | 0x03 // Both Motors, set same direction and speed for both

With values for direction and speed in:

  • data[1] = Direction: 0 | 1
  • data[2] = Speed: 0 - 100
  • if the user can input -100% to +100% as speed the speed value should always be positive.
  • The direction should be 1 for "backwards" and 0 for "fowards"
    Could be implemented in JS somehow like
unserInput = -50
direction = (unserInput < 0) ? 1 : 0
speed = Math.abs(unserInput)

The MakeCode implementation of the makecode blocks is here for refference: https://github.com/microsoft/pxt-calliope/blob/03e928aec8b7ac2f34738c95f8e8e75a0fa40bcc/libs/core-mini-codal/motors.ts#L45
Note, that we do not need the mapping, since it is different for DAL and CODAL. So the mapping is done in the HEX. But we always expect positive values from 0 to 100 for the speed.

@haithembelhaj
Copy link
Collaborator

@Amerlander I added the block following the specs but without success sadly :(
calliope-edu/scratch-vm@c7c4f5b
I'm I doing something wrong?

@Amerlander
Copy link
Author

Your code locks fine. I'll check if there is something going wrong with the hex file.

@Amerlander
Copy link
Author

The Motor should be part of the first command. I changed it in scsratch-vm: calliope-edu/scratch-vm@1aab934
@haithembelhaj Can you have a look?

@Amerlander
Copy link
Author

Amerlander commented May 3, 2024

There was an issue in the hex file too. It now works with the changes from above and this new hex file:

Calliope-More.zip

@haithembelhaj
Copy link
Collaborator

amazing! I updated the VM by removing the logs :)

@Amerlander
Copy link
Author

If you only updated the VM you could just re-run the Job by opening the last job and click on the re-run-button on the top right:
https://github.com/calliope-edu/scratch-gui/actions/runs/8942832422
image

That should rebuild the page with the current vm without having to commit to the gui repo.

@joernalraun joernalraun reopened this May 6, 2024
@joernalraun
Copy link

Right now the block is english, can this be translated as well and we need motor in it "set motor"...
In German it should be "setze Motor XX auf XX".

@haithembelhaj
Copy link
Collaborator

@joernalraun translated and deployed :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants