microsoft / microbit-robot

Universal Robot blocks for MakeCode micro:bit - beta
https://makecode.microbit.org/pkg/microsoft/microbit-robot
MIT License
16 stars 19 forks source link
edu makecode microbit robot

Micro:bit Robot for MakeCode

This extension contains blocks for most 2 wheeled robots available for the micro:bit and Calliope mini and a web simulator. This library is compatible with micro:bit V2, V1 and Calliope mini V3. However, the code space in V1 is limited and you may need to remove some features to fit your program.

The library is still in beta and is subject to changes.

3 micro:bit robots

Hardware requirements

The firmware is designed for popular rover robots found in the micro:bit and Calliope mini ecosystem (and more can be added):

The following features are found often those robots:

Using this extension

Tutorials

Simulator

The simulator will load automatically in MakeCode once you use a robot block. It is designed to help programming this kind of robot.

Simulator

Blocks

Understanding the screen

The extension uses the 5x5 screen to show the state of the robot (you can turn off this behavior see configuration). This is particularly useful to debug your robot program.

Choosing the robot type

At the start of any robot program, you need add the block to select the robot model you will be using.

This should be done before using any other blocks.

robot.elecfreaksCuteBot.start()

This is the only code that is specific to the robot you are using. The rest of the blocks are the same for all robots.

Motors

There are two ways to control the motor: tank or steer.

Tank

The tank block takes the left and right motor speed between -100% and 100% and an optional duration in milliseconds. The block will pause for the duration before continuing to the next block (it does not stop at the end of the duration).

input.onButtonPressed(Button.A, () => {
    robot.motorTank(50, 50, 1000)
})

~hint

Hint Why can't we use angles?

Most micro:bit robots do not have sensors to measure the rotation of the wheels, so it is not possible to compute rotation angles or distances. The only known value is that amount of power sent to the robot.

~

Steer

The steer block takes a steering and speedparameters. Thesteeringcontrols how much "turn",speed controls the throttle on the motors. The optional duration is in milliseconds.

input.onButtonPressed(Button.A, () => {
    robot.motorSteer(0, 100, 1000)
})

Stop

This block stops the robot.

input.onButtonPressed(Button.B, () => {
    robot.motorStop()
})

Arms

Some robot support one or more servo attachments. These are called arms in the library. Open a claw/arm (some robots support one or more servos)

input.onButtonPressed(Button.B, () => {
    robot.armOpen(0, 50)
})

LEDS and music

input.onButtonPressed(Button.A, function () {
    robot.setColor(0xff0000)
})
input.onButtonPressed(Button.A, function () {
    robot.playTone(262, music.beat(BeatFraction.Whole))
})

Obstacle detection

let dist = 0
robot.onObstacleDistanceChanged(function () {
    dist = robot.obstacleDistance()
})

Line detection

let left = false
robot.onLineDetected(function () {
    left = robot.detectLine(RobotLineDetector.Left)
})

Configuration

robot.setAssist(RobotAssist.Display, false)
robot.setMotorDrift(10)
robot.setAssist(RobotAssist.LineFollowing, false)
robot.setAssist(RobotAssist.Speed, false)

Usage with MicroCode

Use micro:code to remote control a robot using this library.

Supported targets

Supported Robots

DFRobot Maqueen V2+

Photograph of the Maqueen

DFRobot Maqueen Plus V2

Photograph of the Maqueen plus

Elecfreaks Cutebot

Photograph of the Cutebot

Elecfreaks Cutebot PRO

Photograph of the Cutebot PRO

Forward Education Smart Vehicle Kit

Photograph of car made with Smart Vehicle Kit

InkSmith K8

Photograph of the K8

KeyStudio KS0426 Mini Smart Robot

KittenBot TabbyBot

Photo of the TabbyBot

KittenBot MiniLFR

Photo of the MiniLFR robot

KittenBot Robotbit

Photo of the Robotbit robot

KittenBot Nanobit

Photo of the Nanobit robot

TinySuperLab MotionKit V2

Photograph of the MotionKit v2

Yahboom Tiny:bit

Photograph of the Tiny:bit

Kitronik Motor Driver V2 RC Car

Photograph of the Kitronik MotorDriver V2 RC Car

Note that the Kitronik motor driver v2 is discontinued.

License

MIT

Acknoledgements

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

How to prepare a pull request

To add a new robot to the list, prepare a pull request in microsoft/microbit-robot with:

Make sure to test and tune the configuration options in the robot class for your particular chassis/motor/line detectors. You may want to tweak some of the constants in the robot class to optimize the behavior of the robot.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

Githubissues.
  • Githubissues is a development platform for aggregating issues.