Giter VIP home page Giter VIP logo

pxt-cutebot-pro's Introduction

Cute:bot Pro Car Package

This library is designed to drive Cutebot Pro, You can get Cutebot Pro here.

https://shop.elecfreaks.com/products/elecfreaks-smart-cutebot-pro-v2-programming-robot-car-for-micro-bit

You can refer to this wiki

Code Example

CutebotPro.irCallback(function () {
    if (CutebotPro.irButton(CutbotProIRButtons.Up)) {
        CutebotPro.distanceRunning(CutebotProOrientation.Advance, 10, CutebotProDistanceUnits.Cm)
    }
    if (CutebotPro.irButton(CutbotProIRButtons.Menu)) {
        CutebotPro.fullSpeedAhead()
    }
    if (CutebotPro.irButton(CutbotProIRButtons.Zero)) {
        led.plot(0, 0)
        k = 1
    }
})
// tests go here; this will not be compiled when this package is used as an extension.
input.onButtonPressed(Button.A, function () {
    i += 1
    if (i == 1) {
        CutebotPro.colorLight(CutebotProRGBLight.RGBA, 0xff0000)
    }
    if (i == 2) {
        CutebotPro.colorLight(CutebotProRGBLight.RGBA, 0x00ff00)
    }
    if (i == 3) {
        CutebotPro.colorLight(CutebotProRGBLight.RGBA, 0x0000ff)
        i = 0
    }
})
input.onButtonPressed(Button.B, function () {
    j += 1
    if (j == 1) {
        pins.digitalWritePin(DigitalPin.P1, 1)
        pins.digitalWritePin(DigitalPin.P2, 0)
        pins.digitalWritePin(DigitalPin.P13, 0)
        pins.digitalWritePin(DigitalPin.P14, 0)
    }
    if (j == 2) {
        pins.digitalWritePin(DigitalPin.P1, 0)
        pins.digitalWritePin(DigitalPin.P2, 1)
        pins.digitalWritePin(DigitalPin.P13, 0)
        pins.digitalWritePin(DigitalPin.P14, 0)
    }
    if (j == 3) {
        pins.digitalWritePin(DigitalPin.P1, 0)
        pins.digitalWritePin(DigitalPin.P2, 0)
        pins.digitalWritePin(DigitalPin.P13, 1)
        pins.digitalWritePin(DigitalPin.P14, 0)
    }
    if (j == 4) {
        pins.digitalWritePin(DigitalPin.P1, 0)
        pins.digitalWritePin(DigitalPin.P2, 0)
        pins.digitalWritePin(DigitalPin.P13, 0)
        pins.digitalWritePin(DigitalPin.P14, 1)
        j = 0
    }
})
let j = 0
let i = 0
let k = 0
music.setBuiltInSpeakerEnabled(false)
basic.pause(100)
CutebotPro.extendServoControl(ServoType.Servo180, CutebotProServoIndex.S1, 0)
CutebotPro.extendServoControl(ServoType.Servo180, CutebotProServoIndex.S2, 0)
CutebotPro.extendServoControl(ServoType.Servo180, CutebotProServoIndex.S3, 0)
CutebotPro.extendServoControl(ServoType.Servo180, CutebotProServoIndex.S4, 0)
basic.pause(500)
CutebotPro.extendServoControl(ServoType.Servo180, CutebotProServoIndex.S1, 180)
CutebotPro.extendServoControl(ServoType.Servo180, CutebotProServoIndex.S2, 180)
CutebotPro.extendServoControl(ServoType.Servo180, CutebotProServoIndex.S3, 180)
CutebotPro.extendServoControl(ServoType.Servo180, CutebotProServoIndex.S4, 180)
basic.pause(500)

k = 0
i = 0
j = 0
music.playTone(262, music.beat(BeatFraction.Half))
basic.forever(function () {
    if (CutebotPro.ultrasonic(SonarUnit.Centimeters) <= 5) {
        CutebotPro.pwmCruiseControl(0, 0)
    }
    if (k == 0) {
        CutebotPro.extendMotorControl(100)
    } else if (k == 1) {
        for (let index = 0; index < 10000; index++) {
            CutebotPro.trackbitStateValue()
            if (CutebotPro.getGrayscaleSensorState(TrackbitStateType.Tracking_State_7) || (CutebotPro.getGrayscaleSensorState(TrackbitStateType.Tracking_State_9) || (CutebotPro.getGrayscaleSensorState(TrackbitStateType.Tracking_State_11) || (CutebotPro.getGrayscaleSensorState(TrackbitStateType.Tracking_State_8) || CutebotPro.getGrayscaleSensorState(TrackbitStateType.Tracking_State_3))))) {
                CutebotPro.pwmCruiseControl(0, 70)
            } else if (CutebotPro.getGrayscaleSensorState(TrackbitStateType.Tracking_State_6) || (CutebotPro.getGrayscaleSensorState(TrackbitStateType.Tracking_State_13) || (CutebotPro.getGrayscaleSensorState(TrackbitStateType.Tracking_State_14) || (CutebotPro.getGrayscaleSensorState(TrackbitStateType.Tracking_State_12) || CutebotPro.getGrayscaleSensorState(TrackbitStateType.Tracking_State_2))))) {
                CutebotPro.pwmCruiseControl(70, 0)
            } else if (CutebotPro.getGrayscaleSensorState(TrackbitStateType.Tracking_State_5) || CutebotPro.getGrayscaleSensorState(TrackbitStateType.Tracking_State_1)) {
                CutebotPro.pwmCruiseControl(50, 50)
            }
        }
        CutebotPro.pwmCruiseControl(0, 0)
        k = 0
    }
})

Supported targets

for PXT/microbit

License

MIT

pxt-cutebot-pro's People

Contributors

elecfreaks1 avatar tan1033329899 avatar dexin64 avatar fareshan avatar

Stargazers

 avatar

Watchers

yichang avatar  avatar  avatar

pxt-cutebot-pro's Issues

Bug: Case 04 in the manual doesn't start cruising again

Using the code from Case 4 in the manual, the Automatic Obstacle avoidance, the robot appears to stop and turn at any obstacle (or anything in sensor range), but then does not start cruising again.

Screenshot 2023-12-26 at 14 19 48

Python code (based on the same makecode blocks as the manual):

basic.show_icon(IconNames.HEART)

def on_forever():
    sonar_reading = CutebotPro.ultrasonic(SonarUnit.CENTIMETERS)
    if sonar_reading > 2 and sonar_reading < 20:
        CutebotPro.trolley_steering(CutebotProTurn.LEFT_IN_PLACE, CutebotProAngle.ANGLE180)
    else:
        CutebotPro.cruise_control(30, 30, CutebotProSpeedUnits.CMS)
basic.forever(on_forever)

What I expected:

  • After the object is detected, and the "trolley steering" turn is made
  • The else will be active and the robot will start "cruising" at pwm 30 with both motors.

What happens:

  • After the object is detected, and the "trolley steering" turn is made
  • The robot does not start cruising again.
  • If I put an object in front of the sensor, it does make the turn again, so the loop is running.

I am happy to work with someone testing code on my CuteBot Pro and Microbit V2 setup to find out why it's doing this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.